Example usage for org.joda.time YearMonthDay fromCalendarFields

List of usage examples for org.joda.time YearMonthDay fromCalendarFields

Introduction

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

Prototype

public static YearMonthDay fromCalendarFields(Calendar calendar) 

Source Link

Document

Constructs a YearMonthDay from a java.util.Calendar using exactly the same field values avoiding any time zone effects.

Usage

From source file:net.sourceforge.fenixedu.applicationTier.Factory.RoomSiteComponentBuilder.java

License:Open Source License

private ISiteComponent getInfoSiteRoomTimeTable(InfoSiteRoomTimeTable component, Calendar day, Space room,
        ExecutionSemester executionSemester) throws Exception {

    List<InfoObject> infoShowOccupations = new ArrayList<InfoObject>();

    Calendar startDay = Calendar.getInstance();
    startDay.setTimeInMillis(day.getTimeInMillis());
    startDay.add(Calendar.DATE, Calendar.MONDAY - day.get(Calendar.DAY_OF_WEEK));

    Calendar endDay = Calendar.getInstance();
    endDay.setTimeInMillis(startDay.getTimeInMillis());
    endDay.add(Calendar.DATE, 6);

    // final boolean isCurrentUserRoomManager =
    // isCurrentUserRoomManager(room);

    final YearMonthDay weekStartYearMonthDay = YearMonthDay.fromCalendarFields(startDay);
    final YearMonthDay weekEndYearMonthDay = YearMonthDay.fromCalendarFields(endDay);

    final Interval search = new Interval(weekStartYearMonthDay.toDateTimeAtMidnight(),
            weekEndYearMonthDay.toDateTimeAtMidnight());

    for (final Occupation roomOccupation : room.getOccupationSet()) {

        if (roomOccupation instanceof WrittenEvaluationSpaceOccupation) {
            Collection<WrittenEvaluation> writtenEvaluations = ((WrittenEvaluationSpaceOccupation) roomOccupation)
                    .getWrittenEvaluationsSet();
            getWrittenEvaluationRoomOccupations(infoShowOccupations, weekStartYearMonthDay, weekEndYearMonthDay,
                    writtenEvaluations);
        } else if (roomOccupation instanceof LessonSpaceOccupation) {
            final Lesson lesson = ((LessonSpaceOccupation) roomOccupation).getLesson();
            getLessonOccupations(infoShowOccupations, weekStartYearMonthDay, weekEndYearMonthDay, lesson);
        } else if (roomOccupation instanceof LessonInstanceSpaceOccupation) {
            Collection<LessonInstance> lessonInstances = ((LessonInstanceSpaceOccupation) roomOccupation)
                    .getLessonInstancesSet();
            getLessonInstanceOccupations(infoShowOccupations, weekStartYearMonthDay, weekEndYearMonthDay,
                    lessonInstances);/*w  ww .j a v a  2s.  c  o  m*/
        } else {
            for (Interval interval : roomOccupation.getIntervals()) {
                if (search.overlaps(interval)) {
                    infoShowOccupations.add(new InfoOccupation(roomOccupation, interval));
                }
            }
        }
    }

    component.setInfoShowOccupation(infoShowOccupations);
    component.setInfoRoom(InfoRoom.newInfoFromDomain(room));

    return component;
}

From source file:net.sourceforge.fenixedu.applicationTier.Servico.manager.CreateExecutionDegreesForExecutionYear.java

License:Open Source License

private static OccupationPeriod getOccupationPeriod(final Calendar startDate, final Calendar endDate) {
    OccupationPeriod occupationPeriod = OccupationPeriod.readOccupationPeriod(
            YearMonthDay.fromCalendarFields(startDate), YearMonthDay.fromCalendarFields(endDate));
    if (occupationPeriod == null) {
        occupationPeriod = new OccupationPeriod(startDate.getTime(), endDate.getTime());
        occupationPeriod.setNextPeriod(null);
    }//  w w  w .  ja v  a 2  s. c o m
    return occupationPeriod;
}

From source file:net.sourceforge.fenixedu.domain.OccupationPeriod.java

License:Open Source License

/**
 * //from   www  . j a va2 s  .  co m
 * @param startDate
 * @param endDate
 * @param startDatePart2
 * @param endDatePart2
 * @return
 */
public static OccupationPeriod getOccupationPeriod(final Calendar startDate, final Calendar endDate,
        final Calendar startDatePart2, final Calendar endDatePart2) {
    OccupationPeriod occupationPeriod = OccupationPeriod.readOccupationPeriod(
            YearMonthDay.fromCalendarFields(startDate), YearMonthDay.fromCalendarFields(endDate),
            YearMonthDay.fromCalendarFields(startDatePart2), YearMonthDay.fromCalendarFields(endDatePart2));
    if (occupationPeriod == null) {
        final OccupationPeriod next = startDatePart2 == null ? null
                : new OccupationPeriod(startDatePart2.getTime(), endDatePart2.getTime());
        occupationPeriod = new OccupationPeriod(startDate.getTime(), endDate.getTime());
        occupationPeriod.setNextPeriod(next);
    }
    return occupationPeriod;
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.resourceAllocationManager.exams.RoomSearchDA.java

License:Open Source License

public ActionForward search(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    DynaValidatorForm roomSearchForm = (DynaValidatorForm) form;

    // date//w  w  w  . java  2s .c o  m
    Calendar searchDate = Calendar.getInstance();
    Integer day = new Integer((String) roomSearchForm.get("day"));
    Integer month = new Integer((String) roomSearchForm.get("month"));
    Integer year = new Integer((String) roomSearchForm.get("year"));
    request.setAttribute("day", day.toString());
    request.setAttribute("month", month.toString());
    request.setAttribute("year", year.toString());
    searchDate.set(Calendar.YEAR, year.intValue());
    searchDate.set(Calendar.MONTH, month.intValue() - 1);
    searchDate.set(Calendar.DAY_OF_MONTH, day.intValue());
    if (searchDate.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
        ActionError actionError = new ActionError("error.sunday");
        ActionErrors actionErrors = new ActionErrors();
        actionErrors.add("error.sunday", actionError);
        saveErrors(request, actionErrors);
        return prepare(mapping, form, request, response);
    }

    // exam start time
    Calendar searchStartTime = Calendar.getInstance();
    Integer startHour = new Integer((String) roomSearchForm.get("beginningHour"));
    Integer startMinute = new Integer((String) roomSearchForm.get("beginningMinute"));
    request.setAttribute("beginningHour", startHour.toString());
    request.setAttribute("beginningMinute", startMinute.toString());
    searchStartTime.set(Calendar.HOUR_OF_DAY, startHour.intValue());
    searchStartTime.set(Calendar.MINUTE, startMinute.intValue());
    searchStartTime.set(Calendar.SECOND, 0);

    // exam end time
    Calendar searchEndTime = Calendar.getInstance();
    Integer endHour = new Integer((String) roomSearchForm.get("endHour"));
    Integer endMinute = new Integer((String) roomSearchForm.get("endMinute"));
    request.setAttribute("endHour", endHour.toString());
    request.setAttribute("endMinute", endMinute.toString());
    searchEndTime.set(Calendar.HOUR_OF_DAY, endHour.intValue());
    searchEndTime.set(Calendar.MINUTE, endMinute.intValue());
    searchEndTime.set(Calendar.SECOND, 0);

    if (searchStartTime.after(searchEndTime)) {
        ActionError actionError = new ActionError("error.timeSwitched");
        ActionErrors actionErrors = new ActionErrors();
        actionErrors.add("error.timeSwitched", actionError);
        saveErrors(request, actionErrors);
        return prepare(mapping, form, request, response);
    }

    int dayOfWeekInt = searchDate.get(Calendar.DAY_OF_WEEK);
    DiaSemana dayOfWeek = new DiaSemana(dayOfWeekInt);

    List<InfoRoom> availableInfoRoom = null;
    availableInfoRoom = SpaceUtils.allocatableSpace(YearMonthDay.fromCalendarFields(searchDate),
            YearMonthDay.fromCalendarFields(searchDate), HourMinuteSecond.fromCalendarFields(searchStartTime),
            HourMinuteSecond.fromCalendarFields(searchEndTime), dayOfWeek, null, null, false);
    String sdate = roomSearchForm.get("day") + "/" + roomSearchForm.get("month") + "/"
            + roomSearchForm.get("year");
    String startTime = roomSearchForm.get("beginningHour") + ":" + roomSearchForm.get("beginningMinute");
    String endTime = roomSearchForm.get("endHour") + ":" + roomSearchForm.get("endMinute");
    request.setAttribute(PresentationConstants.DATE, sdate);
    request.setAttribute(PresentationConstants.START_TIME, startTime);
    request.setAttribute(PresentationConstants.END_TIME, endTime);

    Integer exam = null;
    Integer normal = null;
    List<InfoRoom> newAvailableInfoRoom = new ArrayList<InfoRoom>();
    if (availableInfoRoom != null && !availableInfoRoom.isEmpty()) {
        try {
            exam = new Integer((String) roomSearchForm.get("exam"));
        } catch (NumberFormatException ex) {
            // the user didn't speciefy a exam minimum capacity
        }
        try {
            normal = new Integer((String) roomSearchForm.get("normal"));
        } catch (NumberFormatException ex) {
            // the user didn't speciefy a normal minimum capacity
        }
        if (normal != null || exam != null) {
            Iterator<InfoRoom> iter = availableInfoRoom.iterator();
            while (iter.hasNext()) {
                InfoRoom elem = iter.next();
                if (!((normal != null && elem.getCapacidadeNormal().intValue() < normal.intValue())
                        || (exam != null && elem.getCapacidadeExame().intValue() < exam.intValue()))) {
                    newAvailableInfoRoom.add(elem);
                }
            }
        } else {
            newAvailableInfoRoom = availableInfoRoom;
        }
    }
    if (newAvailableInfoRoom != null && !newAvailableInfoRoom.isEmpty()) {
        Collections.sort(newAvailableInfoRoom, new BeanComparator("nome"));
        String[] availableRoomId = new String[newAvailableInfoRoom.size()];
        Iterator<InfoRoom> iter = newAvailableInfoRoom.iterator();
        int i = 0;
        while (iter.hasNext()) {
            InfoRoom elem = iter.next();
            availableRoomId[i] = elem.getExternalId().toString();
        }
        request.setAttribute(PresentationConstants.AVAILABLE_ROOMS_ID, availableRoomId);

    }

    request.setAttribute(PresentationConstants.AVAILABLE_ROOMS, newAvailableInfoRoom);
    return mapping.findForward("showRooms");
}

From source file:net.sourceforge.fenixedu.presentationTier.backBeans.sop.evaluation.SOPEvaluationManagementBackingBean.java

License:Open Source License

public List<SelectItem> getRoomsSelectItems() throws FenixServiceException {

    Calendar examDate = Calendar.getInstance();
    examDate.set(Calendar.YEAR, getYear());
    examDate.set(Calendar.MONTH, getMonth() - 1);
    examDate.set(Calendar.DAY_OF_MONTH, getDay());
    examDate.set(Calendar.SECOND, 0);
    examDate.set(Calendar.MILLISECOND, 0);

    DiaSemana dayOfWeek = new DiaSemana(examDate.get(Calendar.DAY_OF_WEEK));

    Calendar examStartTime = Calendar.getInstance();
    examStartTime.set(Calendar.HOUR_OF_DAY, getBeginHour());
    examStartTime.set(Calendar.MINUTE, getBeginMinute());
    examStartTime.set(Calendar.SECOND, 0);
    examStartTime.set(Calendar.MILLISECOND, 0);

    Calendar examEndTime = Calendar.getInstance();
    examEndTime.set(Calendar.HOUR_OF_DAY, getEndHour());
    examEndTime.set(Calendar.MINUTE, getEndMinute());
    examEndTime.set(Calendar.SECOND, 0);
    examEndTime.set(Calendar.MILLISECOND, 0);

    List<InfoRoom> availableInfoRoom = SpaceUtils.allocatableSpace(YearMonthDay.fromCalendarFields(examDate),
            YearMonthDay.fromCalendarFields(examDate), HourMinuteSecond.fromCalendarFields(examStartTime),
            HourMinuteSecond.fromCalendarFields(examEndTime), dayOfWeek, null, null, false);

    if (this.getEvaluationID() != null) {
        for (Space room : ((WrittenEvaluation) this.getEvaluation()).getAssociatedRooms()) {
            InfoRoom associatedRoom = InfoRoom.newInfoFromDomain(room);
            if (!availableInfoRoom.contains(associatedRoom)) {
                availableInfoRoom.add(associatedRoom);
            }/*from   ww  w .  j  a  v a  2 s .  c  o  m*/
        }
    }

    if (this.getOrderCriteria() == 0) {
        final ComparatorChain comparatorChain = new ComparatorChain();
        comparatorChain.addComparator(new ReverseComparator(new BeanComparator("capacidadeExame")));
        comparatorChain.addComparator(new BeanComparator("nome"));

        Collections.sort(availableInfoRoom, comparatorChain);
    } else if (this.getOrderCriteria() == 1) {
        final ComparatorChain comparatorChain = new ComparatorChain();
        comparatorChain.addComparator(new ReverseComparator(new BeanComparator("edificio")));
        comparatorChain.addComparator(new BeanComparator("nome"));

        Collections.sort(availableInfoRoom, comparatorChain);
    } else if (this.getOrderCriteria() == 2) {
        final ComparatorChain comparatorChain = new ComparatorChain();
        comparatorChain.addComparator(new ReverseComparator(new BeanComparator("tipo")));
        comparatorChain.addComparator(new BeanComparator("nome"));

        Collections.sort(availableInfoRoom, comparatorChain);
    }

    List<SelectItem> items = new ArrayList<SelectItem>(availableInfoRoom.size());
    for (InfoRoom infoRoom : availableInfoRoom) {
        StringBuilder label = new StringBuilder();
        label.append(infoRoom.getNome());
        label.append("  ( ");
        label.append(infoRoom.getCapacidadeExame());
        label.append(" ");
        label.append(this.labelVacancies);
        label.append(", ");
        label.append(infoRoom.getEdificio());
        label.append(", ");
        label.append(infoRoom.getTipo());
        label.append(" )");

        final String value = getRoomWithExamCapacityString(infoRoom);
        final SelectItem selectItem = new SelectItem(value, label.toString());
        items.add(selectItem);
    }

    return items;
}

From source file:org.fenixedu.academic.service.factory.RoomSiteComponentBuilder.java

License:Open Source License

public static InfoSiteRoomTimeTable getInfoSiteRoomTimeTable(Calendar day, Space room,
        ExecutionSemester executionSemester) {

    List<InfoObject> infoShowOccupations = new ArrayList<InfoObject>();

    Calendar startDay = Calendar.getInstance();
    startDay.setTimeInMillis(day.getTimeInMillis());
    startDay.add(Calendar.DATE, Calendar.MONDAY - day.get(Calendar.DAY_OF_WEEK));

    Calendar endDay = Calendar.getInstance();
    endDay.setTimeInMillis(startDay.getTimeInMillis());
    endDay.add(Calendar.DATE, 6);

    // final boolean isCurrentUserRoomManager =
    // isCurrentUserRoomManager(room);

    final YearMonthDay weekStartYearMonthDay = YearMonthDay.fromCalendarFields(startDay);
    final YearMonthDay weekEndYearMonthDay = YearMonthDay.fromCalendarFields(endDay);

    final Interval search = new Interval(weekStartYearMonthDay.toDateTimeAtMidnight(),
            weekEndYearMonthDay.toDateTimeAtMidnight());

    for (final Occupation roomOccupation : room.getOccupationSet()) {

        if (roomOccupation instanceof WrittenEvaluationSpaceOccupation) {
            Collection<WrittenEvaluation> writtenEvaluations = ((WrittenEvaluationSpaceOccupation) roomOccupation)
                    .getWrittenEvaluationsSet();
            getWrittenEvaluationRoomOccupations(infoShowOccupations, weekStartYearMonthDay, weekEndYearMonthDay,
                    writtenEvaluations);
        } else if (roomOccupation instanceof LessonSpaceOccupation) {
            final Lesson lesson = ((LessonSpaceOccupation) roomOccupation).getLesson();
            getLessonOccupations(infoShowOccupations, weekStartYearMonthDay, weekEndYearMonthDay, lesson);
        } else if (roomOccupation instanceof LessonInstanceSpaceOccupation) {
            Collection<LessonInstance> lessonInstances = ((LessonInstanceSpaceOccupation) roomOccupation)
                    .getLessonInstancesSet();
            getLessonInstanceOccupations(infoShowOccupations, weekStartYearMonthDay, weekEndYearMonthDay,
                    lessonInstances);/*w w  w  . j a  va2 s .co m*/
        } else {
            for (Interval interval : roomOccupation.getIntervals()) {
                if (search.overlaps(interval)) {
                    infoShowOccupations.add(new InfoOccupation(roomOccupation, interval));
                }
            }
        }
    }
    InfoSiteRoomTimeTable component = new InfoSiteRoomTimeTable();

    component.setInfoShowOccupation(infoShowOccupations);
    component.setInfoRoom(InfoRoom.newInfoFromDomain(room));

    return component;
}