Example usage for org.joda.time DateTime toYearMonthDay

List of usage examples for org.joda.time DateTime toYearMonthDay

Introduction

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

Prototype

@Deprecated
public YearMonthDay toYearMonthDay() 

Source Link

Document

Converts this object to a YearMonthDay using the same millis and chronology.

Usage

From source file:org.fenixedu.academic.domain.accounting.postingRules.InsurancePR.java

License:Open Source License

@Override
public YearMonthDay getAdministrativeOfficeFeePaymentLimitDate(DateTime startDate, DateTime endDate) {
    return endDate.toYearMonthDay();
}

From source file:org.fenixedu.academic.domain.accounting.postingRules.PastAdministrativeOfficeFeeAndInsurancePR.java

License:Open Source License

public YearMonthDay getAdministrativeOfficeFeePaymentLimitDate(DateTime startDate, DateTime endDate) {
    return endDate.toYearMonthDay();
}

From source file:org.fenixedu.academic.domain.student.Registration.java

License:Open Source License

private Registration(final Person person, final DateTime start, final Integer registrationNumber,
        final Degree degree) {
    this();/*  w ww. j ava  2 s .co  m*/
    setStudent(person.getStudent() != null ? person.getStudent() : new Student(person, registrationNumber));
    setNumber(registrationNumber == null ? getStudent().getNumber() : registrationNumber);
    setStartDate(start.toYearMonthDay());
    setDegree(degree);
    RegistrationState.createRegistrationState(this, AccessControl.getPerson(), start,
            RegistrationStateType.REGISTERED);
}

From source file:org.fenixedu.ulisboa.specifications.domain.student.access.importation.DgesStudentImportationProcess.java

License:Open Source License

protected void fillMainInformation(DegreeCandidateDTO degreeCandidateDTO, String line) {
    String[] fields = splitLine(line, MAIN_INFORMATION_LINE_FIELD_SPEC);
    degreeCandidateDTO.setDegreeCode(fields[1].trim());
    degreeCandidateDTO.setDocumentIdNumber(fields[2].trim());
    degreeCandidateDTO.setGender(parseGender(fields[4].trim()));

    DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyyMMdd");
    DateTime date = formatter.parseDateTime(fields[5].trim());
    degreeCandidateDTO.setDateOfBirth(date.toYearMonthDay());

    degreeCandidateDTO.setContigent(fields[6].trim());
    degreeCandidateDTO.setPlacingOption(Integer.valueOf(fields[7].trim()));
    degreeCandidateDTO.setIngression(getIngression(degreeCandidateDTO.getContigent()));
    BigDecimal entryGrade = new BigDecimal(fields[10].trim().replace(",", "."));
    degreeCandidateDTO.setEntryGrade(entryGrade.setScale(1, RoundingMode.HALF_EVEN).doubleValue());
    BigDecimal highSchoolEntryGrade = entryGrade.setScale(2, RoundingMode.HALF_EVEN);
    highSchoolEntryGrade = highSchoolEntryGrade.divide(new BigDecimal(10), RoundingMode.HALF_EVEN);
    degreeCandidateDTO/*w  w w .  j  a v a 2 s.  c  om*/
            .setHighSchoolFinalGrade(highSchoolEntryGrade.setScale(0, RoundingMode.HALF_EVEN).toString());
    degreeCandidateDTO.setName(fields[11].trim());
    Country nationality = Country.readByTwoLetterCode(fields[15].trim());
    if (nationality == null) {
        throw new RuntimeException("Cannot import student with unknown nationality: " + fields[15].trim());
    }
    degreeCandidateDTO.setNationality(nationality);
}

From source file:org.jadira.usertype.dateandtime.joda.columnmapper.DateColumnYearMonthDayMapper.java

License:Apache License

@Override
public YearMonthDay fromNonNullValue(Date value) {

    if (databaseZone == null) {
        return new YearMonthDay(value.toString());
    }//from   ww  w .j  a v  a2s . c  o m

    DateTime dateTime = new DateTime(value.getTime());
    YearMonthDay localDate = dateTime.toYearMonthDay();

    return localDate;
}

From source file:pt.ist.fenixedu.integration.api.FenixAPIv1.java

License:Open Source License

private FenixLessonSummary addOrUpdateSummary(String courseOid, JsonObject summaryInfo,
        Consumer<SummariesManagementBean> service) {
    final String room, shiftId, date;
    final Boolean taught;
    final int attendance;
    final JsonObject title, content;

    try {//from   w w  w.j a v  a2 s.  co m
        room = summaryInfo.get("room").getAsString();
        shiftId = summaryInfo.get("shift").getAsString();
        date = summaryInfo.get("date").getAsString();
    } catch (Exception ignored) {
        throw newApplicationError(Status.PRECONDITION_FAILED, "invalid parameters",
                "missing keys 'room', 'shift' or 'date'");
    }

    try {
        taught = summaryInfo.get("taught").getAsBoolean();
        attendance = summaryInfo.get("attendance").getAsInt();
    } catch (Exception ignored) {
        throw newApplicationError(Status.PRECONDITION_FAILED, "invalid parameters",
                "missing keys 'taught' or 'attendance'");
    }

    try {
        title = summaryInfo.getAsJsonObject("title");
        content = summaryInfo.getAsJsonObject("content");
    } catch (Exception ignored) {
        throw newApplicationError(Status.PRECONDITION_FAILED, "invalid parameters",
                "missing keys 'title' or 'content'");
    }

    final ExecutionCourse executionCourse = getDomainObject(courseOid, ExecutionCourse.class);
    final Space space = getDomainObject(room, Space.class);
    final Shift shift = getDomainObject(shiftId, Shift.class);

    if (!executionCourse.getAssociatedShifts().contains(shift)) {
        throw newApplicationError(Status.PRECONDITION_FAILED, "invalid parameters",
                "invalid shift for this execution course");
    }

    SummariesManagementBean bean = fillSummaryManagementBean(executionCourse, shift, space, date, title,
            content, taught, attendance);
    service.accept(bean);

    Lesson lesson = bean.getLesson();
    DateTime lessonDateTime = DateTimeFormat.forPattern(dayHourSecondPattern).parseDateTime(date);
    LessonInstance lessonInstance = lesson.getLessonInstanceFor(lessonDateTime.toYearMonthDay());
    return new FenixLessonSummary(shift, lessonDateTime, space, lessonInstance);
}

From source file:pt.ist.fenixedu.integration.api.FenixAPIv1.java

License:Open Source License

private SummariesManagementBean fillSummaryManagementBean(ExecutionCourse executionCourse, Shift shift,
        Space space, String date, JsonObject title, JsonObject content, Boolean taught, int attendance) {

    MultiLanguageString titleMLS, contentMLS;
    try {/*w  ww .  j  a  v a 2  s . com*/
        titleMLS = MultiLanguageString.fromLocalizedString(LocalizedString.fromJson(title));
        contentMLS = MultiLanguageString.fromLocalizedString(LocalizedString.fromJson(content));
    } catch (Exception e) {
        throw newApplicationError(Status.PRECONDITION_FAILED, "invalid parameters",
                "'title' or 'content' is not a valid multi-language string");
    }

    DateTime lessonDateTime = DateTimeFormat.forPattern(dayHourSecondPattern).parseDateTime(date);
    YearMonthDay lessonDate = lessonDateTime.toYearMonthDay();
    Partial lessonTime = new Partial().with(DateTimeFieldType.hourOfDay(), lessonDateTime.getHourOfDay())
            .with(DateTimeFieldType.minuteOfHour(), lessonDateTime.getMinuteOfHour())
            .with(DateTimeFieldType.secondOfDay(), lessonDateTime.getSecondOfMinute());

    Optional<Lesson> lesson = shift.getAssociatedLessonsSet().stream()
            .filter(l -> l.getAllLessonDates().stream().anyMatch(lessonDate::equals))
            .filter(l -> l.getSala().equals(space)).findFirst();

    if (!lesson.isPresent()) {
        throw newApplicationError(Status.PRECONDITION_FAILED, "invalid parameters",
                "invalid lesson date or room");
    }

    Person person = getPerson();
    Professorship professorship = executionCourse.getProfessorship(person);
    String teacherName = person.getName();
    LessonInstance lessonInstance = lesson.get().getLessonInstanceFor(lessonDate);
    Summary summary = lessonInstance != null ? lessonInstance.getSummary() : null;
    ShiftType shiftType = shift.getSortedTypes().first();

    return new SummariesManagementBean(titleMLS, contentMLS, attendance, NORMAL_SUMMARY, professorship,
            teacherName, null, shift, lesson.get(), lessonDate, space, lessonTime, summary, professorship,
            shiftType, taught);
}

From source file:pt.ist.fenixedu.integration.api.FenixAPIv1.java

License:Open Source License

/**
 * Deletes a summary in a lesson of a course by id
 *
        //from  w ww.  ja va  2s  . c  om
 * @param oid
 *            course id
 * @param summaryInfo
 *            JSON object containing the summary info:
 *              {
 *                  "shift": "shift_id",
 *                  "date": "yyyy-MM-dd HH:mm:ss",
 *                  "room": "room_id",
 *              }
 * @return
 */
@DELETE
@Produces(JSON_UTF8)
@Path("courses/{id}/summaries")
@OAuthEndpoint(PERSONAL_SCOPE)
public Response deleteSummaryCourseByOid(@PathParam("id") String oid, JsonObject summaryInfo) {
    final String shiftId, date, room;
    try {
        shiftId = summaryInfo.get("shift").getAsString();
        date = summaryInfo.get("date").getAsString();
        room = summaryInfo.get("room").getAsString();
    } catch (Exception e) {
        throw newApplicationError(Status.PRECONDITION_FAILED, "invalid parameters",
                "missing keys 'shift', 'date' or 'room'");
    }

    final ExecutionCourse executionCourse = getDomainObject(oid, ExecutionCourse.class);
    final Space space = getDomainObject(room, Space.class);
    final Shift shift = getDomainObject(shiftId, Shift.class);

    DateTime lessonDateTime = DateTimeFormat.forPattern(dayHourSecondPattern).parseDateTime(date);
    YearMonthDay lessonDate = lessonDateTime.toYearMonthDay();

    Optional<LessonInstance> lessonInstance = shift.getAssociatedLessonsSet().stream()
            .map(l -> l.getLessonInstanceFor(lessonDate)).filter(l -> l != null && l.getRoom().equals(space))
            .findFirst();
    if (!lessonInstance.isPresent()) {
        throw newApplicationError(Status.PRECONDITION_FAILED, "invalid parameters",
                "invalid lesson date or room");
    }

    final Person person = getPerson();
    Summary summary = lessonInstance.get().getSummary();
    Professorship professorship = executionCourse.getProfessorship(person);

    try {
        DeleteSummary.runDeleteSummary(executionCourse, summary, professorship);
    } catch (Exception e) {
        throw newApplicationError(Status.PRECONDITION_FAILED, "validation error", e.getMessage());
    }

    return Response.noContent().build();
}

From source file:pt.utl.ist.codeGenerator.database.CreateTestData.java

License:Open Source License

private static void createWrittenEvaluation(final ExecutionSemester executionPeriod,
        final ExecutionCourse executionCourse, final String name) {
    final DateTime startDateTime = writtenTestsRoomManager.getNextDateTime(executionPeriod);
    final DateTime endDateTime = startDateTime.plusMinutes(120);
    // final OldRoom oldRoom =
    // writtenTestsRoomManager.getNextOldRoom(executionPeriod);
    final List<ExecutionCourse> executionCourses = new ArrayList<ExecutionCourse>();
    executionCourses.add(executionCourse);
    final List<DegreeModuleScope> degreeModuleScopes = new ArrayList<DegreeModuleScope>();
    for (final CurricularCourse curricularCourse : executionCourse.getAssociatedCurricularCoursesSet()) {
        degreeModuleScopes.addAll(curricularCourse.getDegreeModuleScopes());
    }//from www .j a  va 2  s .c o m
    // final List<OldRoom> oldRooms = new ArrayList<OldRoom>();
    // oldRooms.add(oldRoom);
    final OccupationPeriod occupationPeriod = new OccupationPeriod(startDateTime.toYearMonthDay(),
            endDateTime.toYearMonthDay());
    // final WrittenTest writtenTest = new
    // WrittenTest(startDateTime.toDate(), startDateTime.toDate(),
    // endDateTime.toDate(), executionCourses, degreeModuleScopes, oldRooms,
    // occupationPeriod, name);
    // createWrittenEvaluationEnrolmentPeriodAndVigilancies(executionPeriod,
    // writtenTest, executionCourse);
}

From source file:pt.utl.ist.codeGenerator.database.CreateTestData.java

License:Open Source License

private static void createExam(final ExecutionSemester executionPeriod, final ExecutionCourse executionCourse,
        final Season season) {
    final DateTime startDateTime = examRoomManager.getNextDateTime(executionPeriod);
    final DateTime endDateTime = startDateTime.plusMinutes(180);
    // final OldRoom oldRoom =
    // examRoomManager.getNextOldRoom(executionPeriod);
    final List<ExecutionCourse> executionCourses = new ArrayList<ExecutionCourse>();
    executionCourses.add(executionCourse);
    final List<DegreeModuleScope> degreeModuleScopes = new ArrayList<DegreeModuleScope>();
    for (final CurricularCourse curricularCourse : executionCourse.getAssociatedCurricularCoursesSet()) {
        degreeModuleScopes.addAll(curricularCourse.getDegreeModuleScopes());
    }/*from w w w. jav a2 s. c  om*/
    // final List<OldRoom> oldRooms = new ArrayList<OldRoom>();
    // oldRooms.add(oldRoom);
    final OccupationPeriod occupationPeriod = new OccupationPeriod(startDateTime.toYearMonthDay(),
            endDateTime.toYearMonthDay());
    // final Exam exam = new Exam(startDateTime.toDate(),
    // startDateTime.toDate(), endDateTime.toDate(), executionCourses,
    // degreeModuleScopes, oldRooms, occupationPeriod, season);
    // createWrittenEvaluationEnrolmentPeriodAndVigilancies(executionPeriod,
    // exam, executionCourse);
}