Example usage for org.joda.time Interval Interval

List of usage examples for org.joda.time Interval Interval

Introduction

In this page you can find the example usage for org.joda.time Interval Interval.

Prototype

public Interval(Object interval, Chronology chronology) 

Source Link

Document

Constructs a time interval by converting or copying from another object, overriding the chronology.

Usage

From source file:com.yahoo.bard.webservice.web.DataApiRequest.java

License:Apache License

/**
 * Extracts the set of intervals from the api request.
 *
 * @param apiIntervalQuery  API string containing the intervals in ISO 8601 format, values separated by ','.
 * @param granularity  The granularity to generate the date based on period or macros.
 * @param dateTimeFormatter  The formatter to parse date time interval segments
 *
 * @return Set of jodatime interval objects.
 * @throws BadApiRequestException if the requested interval is not found.
 *//*from w w w. ja  v  a 2s . c  om*/
protected static Set<Interval> generateIntervals(String apiIntervalQuery, Granularity granularity,
        DateTimeFormatter dateTimeFormatter) throws BadApiRequestException {
    Set<Interval> generated = new LinkedHashSet<>();
    if (apiIntervalQuery == null || apiIntervalQuery.equals("")) {
        LOG.debug(INTERVAL_MISSING.logFormat());
        throw new BadApiRequestException(INTERVAL_MISSING.format());
    }
    List<String> apiIntervals = Arrays.asList(apiIntervalQuery.split(","));
    // Split each interval string into the start and stop instances, parse them, and add the interval to the list
    for (String apiInterval : apiIntervals) {
        String[] split = apiInterval.split("/");

        // Check for both a start and a stop
        if (split.length != 2) {
            String message = "Start and End dates are required.";
            LOG.debug(INTERVAL_INVALID.logFormat(apiIntervalQuery, message));
            throw new BadApiRequestException(INTERVAL_INVALID.format(apiIntervalQuery, message));
        }

        try {
            String start = split[0].toUpperCase(Locale.ENGLISH);
            String end = split[1].toUpperCase(Locale.ENGLISH);
            //If start & end intervals are period then marking as invalid interval.
            //Becacuse either one should be macro or actual date to generate an interval
            if (start.startsWith("P") && end.startsWith("P")) {
                LOG.debug(INTERVAL_INVALID.logFormat(start));
                throw new BadApiRequestException(INTERVAL_INVALID.format(apiInterval));
            }

            Interval interval;
            DateTime now = new DateTime();
            //If start interval is period, then create new interval with computed end date
            //possible end interval could be next,current, date
            if (start.startsWith("P")) {
                interval = new Interval(Period.parse(start),
                        getAsDateTime(now, granularity, split[1], dateTimeFormatter));
                //If end string is period, then create an interval with the computed start date
                //Possible start & end string could be a macro or an ISO 8601 DateTime
            } else if (end.startsWith("P")) {
                interval = new Interval(getAsDateTime(now, granularity, split[0], dateTimeFormatter),
                        Period.parse(end));
            } else {
                //start and end interval could be either macros or actual datetime
                interval = new Interval(getAsDateTime(now, granularity, split[0], dateTimeFormatter),
                        getAsDateTime(now, granularity, split[1], dateTimeFormatter));
            }

            // Zero length intervals are invalid
            if (interval.toDuration().equals(Duration.ZERO)) {
                LOG.debug(INTERVAL_ZERO_LENGTH.logFormat(apiInterval));
                throw new BadApiRequestException(INTERVAL_ZERO_LENGTH.format(apiInterval));
            }
            generated.add(interval);
        } catch (IllegalArgumentException iae) {
            LOG.debug(INTERVAL_INVALID.logFormat(apiIntervalQuery, iae.getMessage()), iae);
            throw new BadApiRequestException(INTERVAL_INVALID.format(apiIntervalQuery, iae.getMessage()), iae);
        }
    }
    return generated;
}

From source file:com.yahoo.wiki.webservice.data.config.auto.DruidNavigator.java

License:Apache License

/**
 * Find a valid timegrain from druid query to the {@link TableConfig}.
 *
 * {//from www.j av a2 s .c  om
 *      ...,
 *      "interval": "2015-09-12T00:00:00.000Z/2015-09-13T00:00:00.000Z",
 *      ...
 * }
 *
 * @param tableConfig The TableConfig to be loaded.
 * @param segmentJson The JsonNode containing a time interval.
 */
private void loadTimeGrains(TableConfig tableConfig, JsonNode segmentJson) {
    String timeInterval = segmentJson.get("interval").asText();
    String[] utcTimes = timeInterval.split("/");
    Optional<TimeGrain> timeGrain = Optional.empty();
    try {
        if (utcTimes.length == 2) {
            DateTime start = new DateTime(utcTimes[0], DateTimeZone.UTC);
            DateTime end = new DateTime(utcTimes[1], DateTimeZone.UTC);
            Interval interval = new Interval(start.toInstant(), end.toInstant());
            timeGrain = IntervalUtils.getTimeGrain(interval);
        }
    } catch (IllegalArgumentException ignored) {
        LOG.warn("Unable to parse time intervals {} correctly", Arrays.toString(utcTimes));
    }

    if (!timeGrain.isPresent()) {
        LOG.warn("Couldn't detect timegrain for {}, defaulting to DAY TimeGrain.", timeInterval);
    }
    tableConfig.setTimeGrain(timeGrain.orElse(DefaultTimeGrain.DAY));
}

From source file:com.yard.stick.ImageAdapter.java

License:Apache License

public View getView(int position, View convertView, ViewGroup parent) {

    View inflatedView = convertView;

    if (!m_Loading & !m_Loaded)
        loadImageList();// ww  w . j  a v a  2s  .c  o  m

    if (position < m_NewestList.size()) {
        try {

            if (convertView == null)
                inflatedView = inflater.inflate(R.layout.newestitem, null);

            ImageView image = (ImageView) inflatedView.findViewById(R.id.newimg);
            TextView txt = (TextView) inflatedView.findViewById(R.id.newimgtxt);
            StringBuilder s = new StringBuilder();
            double age = new Interval(new DateTime(m_NewestList.get(position).getDate()), new DateTime())
                    .toPeriod().toStandardHours().getHours();

            s.append("Up Votes: ");
            s.append(m_NewestList.get(position).getUpVotes());
            s.append("\n");
            s.append("Down Votes: ");
            s.append(m_NewestList.get(position).getDownVotes());
            s.append("\n");
            s.append("Score: ");
            s.append(m_NewestList.get(position).getScore());
            s.append("\n");
            s.append("Age: ");
            s.append(age);
            s.append(" hours\n");
            txt.setText(s.toString());

            imageLoader.DisplayImage(m_NewestList.get(position).getImageURL(), image);
        } catch (Exception e) {
            System.out.println(m_NewestList.get(position).getCaption());
        }
    }
    return inflatedView;

}

From source file:controllers.ReportController.java

/**
 * Find all emergencies in a list that are within the given date range.
 * @param initialList list of emergencies to search through.
 * @param start start date of the interval.
 * @param end the end date of the interval.
 * @return /*from   ww  w  .  j  a va2 s. c  om*/
 */
private static ArrayList<Emergency> findBetweenDates(ArrayList<Emergency> initialList, DateTime start,
        DateTime end) {
    ArrayList<Emergency> emergencyList = new ArrayList<>();
    Interval interval = new Interval(start, end);
    for (Emergency instance : initialList) {
        if (interval.contains(instance.getDateCreated())) {
            emergencyList.add(instance);
        }
    }
    return emergencyList;
}

From source file:course_generator.SaxGPXHandler.java

License:Open Source License

@Override
public void endElement(String uri, String localname, String qName) throws SAXException {
    if (qName.equalsIgnoreCase("GPX")) {
        level--;/*  w  w w . j  a v  a2 s.  com*/
    } else if (qName.equalsIgnoreCase("TRK")) {
        level--;
    } else if (qName.equalsIgnoreCase("TRKSEG")) {
        level--;
    } else if ((level == LEVEL_TRK) && qName.equalsIgnoreCase("NAME")) {
        trk_name = characters;
        characters = "";
    } else if ((level == LEVEL_TRKPT) && qName.equalsIgnoreCase("NAME")) {
        trkpt_name = characters;
        characters = "";
    } else if ((level == LEVEL_TRKPT) && qName.equalsIgnoreCase("ELE")) {
        try {
            trkpt_ele = Double.parseDouble(characters);
            characters = "";
        } catch (NumberFormatException e) {
            trkpt_ele = 0.0;
            errcode = ERR_READ_ELE;
            errline = locator.getLineNumber();
            characters = "";
        }
    } else if ((level == LEVEL_TRKPT) && qName.equalsIgnoreCase("TIME")) {
        try {
            if (first) {
                first = false;
                trkpt_time = DateTime.parse(characters);
                StartTime = trkpt_time;
                old_time = StartTime;
                Time_s = 0;
                dTime_f = 0.0;
                characters = "";
            } else {
                trkpt_time = DateTime.parse(characters);
                Time_s = (int) ((new Interval(StartTime, trkpt_time)).toDurationMillis() / 1000);
                dTime_f = ((new Interval(old_time, trkpt_time)).toDurationMillis() / 1000.0);
                characters = "";
            }
            trkdata.isTimeLoaded = true;
        } catch (IllegalArgumentException e) {
            trkpt_time = new DateTime(1970, 1, 1, 0, 0, 0);
            errcode = ERR_READ_TIME;
            errline = locator.getLineNumber();
            characters = "";
        }
    } else if (((level == LEVEL_TRKPT)) && qName.equalsIgnoreCase("TRKPT")) {
        level--;

        if ((mLat != trkpt_lat) || (mLon != trkpt_lon) || (!trkdata.isTimeLoaded)) {
            if ((mode == 0) || (mode == 2)) {
                // Add data at the of the array
                Cmpt++;
                trkdata.data.add(new CgData(Cmpt, //double Num
                        trkpt_lat, //double Latitude
                        trkpt_lon, //double Longitude
                        trkpt_ele, //double Elevation
                        trkpt_ele, //double ElevationMemo
                        0, //int Tag
                        0.0, //double Dist
                        0.0, //double Total
                        100.0, //double Diff
                        100.0, //double Coeff
                        0.0, //double Recup
                        0.0, //double Slope
                        0.0, //double Speed
                        0.0, //double dElevation
                        Time_s, //int Time //Temps total en seconde
                        dTime_f, //double dTime_f  //temps de parcours du tronon en seconde (avec virgule)
                        0, //int TimeLimit //Barrire horaire
                        trkpt_time, //DateTime Hour //Contient la date et l'heure de passage
                        0, //int Station
                        "", //String Name
                        "", //String Comment
                        0.0, //double tmp1
                        0.0, //double tmp2
                        CgConst.DEFAULTMRBFORMAT, //String FmtLbMiniRoadbook
                        CgConst.MRBOPT_SEL | CgConst.MRBOPT_LEFT | CgConst.MRBOPT_SHOWTAGS, //int OptionMiniRoadbook
                        0, //int VPosMiniRoadbook
                        "", //String CommentMiniRoadbook
                        CgConst.DEFAULTMRBFONTSIZE //int FontSizeMiniRoadbook
                ));
            } else {
                trkdata.data.add(Cmpt, new CgData(Cmpt, //double Num
                        trkpt_lat, //double Latitude
                        trkpt_lon, //double Longitude
                        trkpt_ele, //double Elevation
                        trkpt_ele, //double ElevationMemo
                        0, //int Tag
                        0.0, //double Dist
                        0.0, //double Total
                        100.0, //double Diff
                        100.0, //double Coeff
                        0.0, //double Recup
                        0.0, //double Slope
                        0.0, //double Speed
                        0.0, //double dElevation
                        Time_s, //int Time
                        dTime_f, //double dTime_f
                        0, //int TimeLimit
                        trkpt_time, //DateTime Hour
                        0, //int Station
                        "", //String Name
                        "", //String Comment
                        0.0, //double tmp1
                        0.0, //double tmp2
                        CgConst.DEFAULTMRBFORMAT, //String FmtLbMiniRoadbook
                        CgConst.MRBOPT_SEL | CgConst.MRBOPT_LEFT | CgConst.MRBOPT_SHOWTAGS, //int OptionMiniRoadbook
                        0, //int VPosMiniRoadbook
                        "", //String CommentMiniRoadbook
                        CgConst.DEFAULTMRBFONTSIZE //int FontSizeMiniRoadbook
                ));
            } //else
            Cmpt++;
        }
        mLat = trkpt_lat;
        mLon = trkpt_lon;
        mEle = trkpt_ele;
        old_time = trkpt_time;
    }
}

From source file:cz.cesnet.shongo.client.web.controllers.ResourceController.java

/**
 * Handle resource reservations data/* ww w  .j a v a 2  s. co  m*/
 */
@RequestMapping(value = ClientWebUrl.RESOURCE_RESERVATIONS_DATA, method = RequestMethod.GET)
@ResponseBody
public Object handleReservationsData(SecurityToken securityToken,
        @RequestParam(value = "resource-id", required = false) String resourceId,
        @RequestParam(value = "type", required = false) ReservationSummary.Type type,
        @RequestParam(value = "start") DateTime start, @RequestParam(value = "end") DateTime end) {
    ReservationListRequest request = new ReservationListRequest(securityToken);
    request.setSort(ReservationListRequest.Sort.SLOT);
    if (resourceId != null) {
        request.addResourceId(resourceId);
    }
    if (type != null) {
        request.addReservationType(type);
    }
    request.setInterval(new Interval(start, end));
    ListResponse<ReservationSummary> listResponse = reservationService.listReservations(request);
    List<Map> reservations = new LinkedList<Map>();
    for (ReservationSummary reservationSummary : listResponse.getItems()) {
        Map<String, Object> reservation = new HashMap<String, Object>();
        reservation.put("id", reservationSummary.getId());
        reservation.put("type", reservationSummary.getType());
        reservation.put("slotStart", reservationSummary.getSlot().getStart().toString());
        reservation.put("slotEnd", reservationSummary.getSlot().getEnd().toString());
        reservation.put("resourceId", reservationSummary.getResourceId());
        reservation.put("roomLicenseCount", reservationSummary.getRoomLicenseCount());
        reservation.put("roomName", reservationSummary.getRoomName());
        reservation.put("aliasTypes", reservationSummary.getAliasTypesSet());
        reservation.put("value", reservationSummary.getValue());
        reservations.add(reservation);
    }
    return reservations;
}

From source file:cz.cesnet.shongo.client.web.controllers.ResourceController.java

/**
 * Handle table of {@link ResourceCapacityUtilization}s.
 *///from www  .java2s.co  m
@RequestMapping(value = ClientWebUrl.RESOURCE_CAPACITY_UTILIZATION_TABLE, method = RequestMethod.GET)
public ModelAndView handleCapacityUtilizationTable(SecurityToken securityToken,
        @RequestParam(value = "period") Period period, @RequestParam(value = "start") DateTime start,
        @RequestParam(value = "end") DateTime end,
        @RequestParam(value = "style") ResourceCapacity.FormatStyle style,
        @RequestParam(value = "refresh", required = false) boolean refresh) {
    ResourcesUtilization resourcesUtilization = cache.getResourcesUtilization(securityToken, refresh);

    Map<Interval, Map<ResourceCapacity, ResourceCapacityUtilization>> utilization = resourcesUtilization
            .getUtilization(new Interval(start, end), period);
    ModelAndView modelAndView = new ModelAndView("resourceCapacityUtilizationTable");
    modelAndView.addObject("resourceCapacitySet", resourcesUtilization.getResourceCapacities());
    modelAndView.addObject("resourceCapacityUtilization", utilization);
    modelAndView.addObject("style", style);
    return modelAndView;
}

From source file:cz.cesnet.shongo.controller.api.rpc.ExecutableServiceImpl.java

@Override
public ListResponse<ExecutableSummary> listExecutables(ExecutableListRequest request) {
    checkNotNull("request", request);
    SecurityToken securityToken = request.getSecurityToken();
    authorization.validate(securityToken);

    EntityManager entityManager = entityManagerFactory.createEntityManager();
    try {//from w ww. ja  va 2s . co m
        QueryFilter queryFilter = new QueryFilter("executable_summary", true);

        String participantUserId = request.getParticipantUserId();
        if (participantUserId != null) {
            // Do not filter executables by permissions because they will be filtered by participation,
            // check only the existence of the participant user
            authorization.checkUserExistence(participantUserId);

            if (!participantUserId.equals(securityToken.getUserId())
                    && !authorization.isOperator(securityToken)) {
                throw new ControllerReportSet.SecurityNotAuthorizedException(
                        "read participation executables for user " + participantUserId);
            }
        } else {
            // List only executables which is current user permitted to read
            queryFilter.addFilterId(authorization, securityToken,
                    cz.cesnet.shongo.controller.booking.executable.Executable.class, ObjectPermission.READ);
        }

        // If history executables should not be included
        String filterExecutableId = "id IS NOT NULL";
        if (!request.isHistory()) {
            // List only executables which are allocated by any existing reservation
            filterExecutableId = "id IN(SELECT reservation.executable_id FROM reservation)";
        }

        // List only rooms with given user-id participant
        if (request.getParticipantUserId() != null) {
            queryFilter.addFilter("executable_summary.id IN(" + " SELECT room_endpoint.id"
                    + " FROM room_endpoint"
                    + " LEFT JOIN used_room_endpoint ON used_room_endpoint.id = room_endpoint.id"
                    + " LEFT JOIN room_endpoint_participants ON room_endpoint_participants.room_endpoint_id = room_endpoint.id OR room_endpoint_participants.room_endpoint_id = used_room_endpoint.room_endpoint_id"
                    + " LEFT JOIN person_participant ON person_participant.id = room_endpoint_participants.abstract_participant_id"
                    + " LEFT JOIN person ON person.id = person_participant.person_id"
                    + " WHERE person.user_id = :participantUserId" + ")");
            queryFilter.addFilterParameter("participantUserId", request.getParticipantUserId());
        }

        // List only executables of requested classes
        if (request.getTypes().size() > 0) {
            StringBuilder typeFilterBuilder = new StringBuilder();
            for (ExecutableSummary.Type type : request.getTypes()) {
                if (typeFilterBuilder.length() > 0) {
                    typeFilterBuilder.append(",");
                }
                typeFilterBuilder.append("'");
                typeFilterBuilder.append(type.toString());
                typeFilterBuilder.append("'");
            }
            typeFilterBuilder.insert(0, "executable_summary.type IN(");
            typeFilterBuilder.append(")");
            queryFilter.addFilter(typeFilterBuilder.toString());
        }

        // List only usages of specified room
        if (request.getRoomId() != null) {
            queryFilter.addFilter("executable_summary.room_id = :roomId");
            queryFilter.addFilterParameter("roomId",
                    ObjectIdentifier.parseId(request.getRoomId(), ObjectType.EXECUTABLE));
        }

        // Filter room license count
        String roomLicenseCount = request.getRoomLicenseCount();
        if (roomLicenseCount != null) {
            if (roomLicenseCount.equals(ExecutableListRequest.FILTER_NON_ZERO)) {
                queryFilter.addFilter("executable_summary.room_license_count > 0");
            } else {
                queryFilter.addFilter("executable_summary.room_license_count = :roomLicenseCount");
                queryFilter.addFilterParameter("roomLicenseCount", Long.parseLong(roomLicenseCount));
            }
        }

        // Sort query part
        String queryOrderBy;
        ExecutableListRequest.Sort sort = request.getSort();
        if (sort != null) {
            switch (sort) {
            case ROOM_NAME:
                queryOrderBy = "executable_summary.room_name";
                break;
            case SLOT:
                queryOrderBy = "executable_summary.slot_end";
                break;
            case STATE:
                queryOrderBy = "executable_summary.state";
                break;
            case ROOM_TECHNOLOGY:
                queryOrderBy = "executable_summary.room_technologies";
                break;
            case ROOM_LICENSE_COUNT:
                queryOrderBy = "executable_summary.room_license_count";
                break;
            default:
                throw new TodoImplementException(sort);
            }
        } else {
            queryOrderBy = "executable_summary.id";
        }
        Boolean sortDescending = request.getSortDescending();
        sortDescending = (sortDescending != null ? sortDescending : false);
        if (sortDescending) {
            queryOrderBy = queryOrderBy + " DESC";
        }

        Map<String, String> parameters = new HashMap<String, String>();
        parameters.put("filterExecutableId", filterExecutableId);
        parameters.put("filter", queryFilter.toQueryWhere());
        parameters.put("order", queryOrderBy);
        String query = NativeQuery.getNativeQuery(NativeQuery.EXECUTABLE_LIST, parameters);

        ListResponse<ExecutableSummary> response = new ListResponse<ExecutableSummary>();
        List<Object[]> records = performNativeListRequest(query, queryFilter, request, response, entityManager);
        for (Object[] record : records) {
            DateTime slotStart = new DateTime(record[2]);
            DateTime slotEnd = new DateTime(record[3]);
            ExecutableSummary executableSummary = new ExecutableSummary();
            executableSummary.setId(ObjectIdentifier.formatId(ObjectType.EXECUTABLE, record[0].toString()));
            executableSummary.setType(ExecutableSummary.Type.valueOf(record[1].toString().trim()));
            executableSummary
                    .setSlot(new Interval(slotStart, (slotEnd.isBefore(slotStart) ? slotStart : slotEnd)));
            executableSummary.setState(cz.cesnet.shongo.controller.booking.executable.Executable.State
                    .valueOf(record[4].toString()).toApi());
            executableSummary.setRoomDescription(record[8] != null ? (String) record[8] : null);

            switch (executableSummary.getType()) {
            case USED_ROOM:
                executableSummary
                        .setRoomId(ObjectIdentifier.formatId(ObjectType.EXECUTABLE, record[9].toString()));
            case ROOM:
                executableSummary.setRoomName(record[5] != null ? record[5].toString() : null);
                if (record[6] != null) {
                    String technologies = record[6].toString();
                    if (!technologies.isEmpty()) {
                        for (String technology : technologies.split(",")) {
                            executableSummary.addTechnology(Technology.valueOf(technology.trim()));
                        }
                    }
                }
                executableSummary.setRoomLicenseCount(((Number) record[7]).intValue());
                if (record[10] != null && record[11] != null) {
                    executableSummary
                            .setRoomUsageSlot(new Interval(new DateTime(record[10]), new DateTime(record[11])));
                }
                if (record[12] != null) {
                    executableSummary
                            .setRoomUsageState(cz.cesnet.shongo.controller.booking.executable.Executable.State
                                    .valueOf(record[12].toString()).toApi());
                }
                if (record[13] != null) {
                    executableSummary.setRoomUsageLicenseCount(((Number) record[13]).intValue());
                }
                executableSummary.setRoomUsageCount(((Number) record[14]).intValue());
                break;
            }

            response.addItem(executableSummary);
        }
        return response;
    } finally {
        entityManager.close();
    }
}

From source file:cz.cesnet.shongo.controller.api.rpc.ReservationServiceImpl.java

/**
 * @param record//from   w w  w . j  a  va  2 s . co  m
 * @return {@link ReservationRequestSummary} from given {@code record}
 */
private ReservationRequestSummary getReservationRequestSummary(Object[] record) {
    ReservationRequestSummary reservationRequestSummary = new ReservationRequestSummary();
    reservationRequestSummary
            .setId(ObjectIdentifier.formatId(ObjectType.RESERVATION_REQUEST, record[0].toString()));
    if (record[1] != null) {
        reservationRequestSummary.setParentReservationRequestId(
                ObjectIdentifier.formatId(ObjectType.RESERVATION_REQUEST, record[1].toString()));
    }
    reservationRequestSummary.setType(ReservationRequestType.valueOf(record[2].toString().trim()));
    reservationRequestSummary.setDateTime(new DateTime(record[3]));
    reservationRequestSummary.setUserId(record[4].toString());
    reservationRequestSummary.setDescription(record[5] != null ? record[5].toString() : null);
    reservationRequestSummary.setPurpose(ReservationRequestPurpose.valueOf(record[6].toString().trim()));
    reservationRequestSummary.setEarliestSlot(new Interval(new DateTime(record[7]), new DateTime(record[8])));
    if (record[9] != null) {
        reservationRequestSummary.setAllocationState(
                ReservationRequest.AllocationState.valueOf(record[9].toString().trim()).toApi());
    }
    if (record[10] != null) {
        reservationRequestSummary
                .setExecutableState(Executable.State.valueOf(record[10].toString().trim()).toApi());
    }
    reservationRequestSummary.setReusedReservationRequestId(record[11] != null
            ? ObjectIdentifier.formatId(ObjectType.RESERVATION_REQUEST, record[11].toString())
            : null);
    if (record[12] != null) {
        reservationRequestSummary
                .setLastReservationId(ObjectIdentifier.formatId(ObjectType.RESERVATION, record[12].toString()));
    }
    String type = record[13].toString().trim();
    if (type.equals("ALIAS")) {
        reservationRequestSummary.setSpecificationType(ReservationRequestSummary.SpecificationType.ALIAS);
        reservationRequestSummary.setRoomName(record[16] != null ? record[16].toString() : null);
    } else if (type.equals("ROOM")) {
        reservationRequestSummary.setSpecificationType(ReservationRequestSummary.SpecificationType.ROOM);
        reservationRequestSummary
                .setRoomParticipantCount(record[15] != null ? ((Number) record[15]).intValue() : null);
        reservationRequestSummary.setRoomHasRecordingService(record[16] != null && (Boolean) record[16]);
        reservationRequestSummary.setRoomHasRecordings(record[17] != null && (Boolean) record[17]);
        reservationRequestSummary.setRoomName(record[18] != null ? record[18].toString() : null);
    } else if (type.equals("PERMANENT_ROOM")) {
        reservationRequestSummary
                .setSpecificationType(ReservationRequestSummary.SpecificationType.PERMANENT_ROOM);
        reservationRequestSummary.setRoomHasRecordingService(record[16] != null && (Boolean) record[16]);
        reservationRequestSummary.setRoomHasRecordings(record[17] != null && (Boolean) record[17]);
        reservationRequestSummary.setRoomName(record[18] != null ? record[18].toString() : null);
    } else if (type.equals("USED_ROOM")) {
        reservationRequestSummary.setSpecificationType(ReservationRequestSummary.SpecificationType.USED_ROOM);
        reservationRequestSummary
                .setRoomParticipantCount(record[15] != null ? ((Number) record[15]).intValue() : null);
        reservationRequestSummary.setRoomHasRecordingService(record[16] != null && (Boolean) record[16]);
        reservationRequestSummary.setRoomHasRecordings(record[17] != null && (Boolean) record[17]);
        reservationRequestSummary.setRoomName(record[18] != null ? record[18].toString() : null);
    } else if (type.equals("RESOURCE")) {
        reservationRequestSummary.setSpecificationType(ReservationRequestSummary.SpecificationType.RESOURCE);
        reservationRequestSummary.setResourceId(
                ObjectIdentifier.formatId(ObjectType.RESOURCE, ((Number) record[19]).longValue()));
    } else {
        reservationRequestSummary.setSpecificationType(ReservationRequestSummary.SpecificationType.OTHER);
    }
    if (record[14] != null) {
        String technologies = record[14].toString();
        if (!technologies.isEmpty()) {
            for (String technology : technologies.split(",")) {
                reservationRequestSummary.addSpecificationTechnology(Technology.valueOf(technology.trim()));
            }
        }
    }
    if (record[20] != null) {
        reservationRequestSummary
                .setUsageExecutableState(cz.cesnet.shongo.controller.booking.executable.Executable.State
                        .valueOf(record[20].toString().trim()).toApi());
    }
    if (record[21] != null) {
        reservationRequestSummary.setFutureSlotCount(((Number) record[21]).intValue());
    }
    return reservationRequestSummary;
}

From source file:cz.cesnet.shongo.controller.api.rpc.ReservationServiceImpl.java

/**
 * @param record/*from  w  w w . ja  v  a 2s . c o  m*/
 * @return {@link ReservationSummary} from given {@code record}
 */
private ReservationSummary getReservationSummary(Object[] record) {
    ReservationSummary reservationSummary = new ReservationSummary();
    reservationSummary.setId(ObjectIdentifier.formatId(ObjectType.RESERVATION, record[0].toString()));
    reservationSummary.setUserId(record[1] != null ? record[1].toString() : null);
    reservationSummary.setReservationRequestId(
            record[2] != null ? ObjectIdentifier.formatId(ObjectType.RESERVATION_REQUEST, record[2].toString())
                    : null);
    reservationSummary.setType(ReservationSummary.Type.valueOf(record[3].toString().trim()));
    reservationSummary.setSlot(new Interval(new DateTime(record[4]), new DateTime(record[5])));
    if (record[6] != null) {
        reservationSummary.setResourceId(ObjectIdentifier.formatId(ObjectType.RESOURCE, record[6].toString()));
    }
    if (record[7] != null) {
        reservationSummary.setRoomLicenseCount(record[7] != null ? ((Number) record[7]).intValue() : null);
    }
    if (record[8] != null) {
        reservationSummary.setRoomName(record[8] != null ? record[8].toString() : null);
    }
    if (record[9] != null) {
        reservationSummary.setAliasTypes(record[9] != null ? record[9].toString() : null);
    }
    if (record[10] != null) {
        reservationSummary.setValue(record[10] != null ? record[10].toString() : null);
    }
    return reservationSummary;
}