List of usage examples for org.joda.time Period getYears
public int getYears()
From source file:org.wso2.security.tools.advisorytool.builders.CustomerSecurityAdvisoryBuilder.java
License:Open Source License
/** * Creating a Version object with the required details from the released products list and * adding the given patch name as an applicable patch. * * @param productName/*from ww w.ja va 2 s . c o m*/ * @param versionNumber * @param patchName * @return */ private Version buildAffectedVersion(String productName, String versionNumber, String patchName) { DateTime dateTime = new DateTime(); boolean hasAMatchingProduct = false; boolean hasAMatchingVersion = false; boolean hasAnApplicableVersion = false; List<Product> releasedProductList = ProductDataHolder.getInstance().getProductList(); Version affectedVersion = new Version(); for (Product releasedProduct : releasedProductList) { if (releasedProduct.getName().equals(productName)) { hasAMatchingProduct = true; for (Version releasedVersion : releasedProduct.getVersionList()) { if (releasedVersion.getVersionNumber().equals(versionNumber)) { hasAMatchingVersion = true; DateTime productDate = new DateTime(releasedVersion.getReleasedDate()); Period period = new Period(productDate, dateTime); //check if the product is within the supported period or whether it is deprecated. if ((period.getYears() < Configuration.getInstance().getPatchSupportPeriod()) && !releasedVersion.isDeprecated()) { hasAnApplicableVersion = true; affectedVersion.getPatchNamesList().add(patchName); affectedVersion.setVersionNumber(releasedVersion.getVersionNumber()); affectedVersion.setPublicSupported(releasedVersion.isPublicSupported()); affectedVersion.setPatchSupported(releasedVersion.isPatchSupported()); affectedVersion.setWumSupported(releasedVersion.isWumSupported()); affectedVersion.setReleasedDate(releasedVersion.getReleasedDate()); affectedVersion.setKernelVersionNumber(releasedVersion.getKernelVersionNumber()); affectedVersion.setPlatformVersionNumber(releasedVersion.getPlatformVersionNumber()); } break; } } break; } } if (!hasAMatchingVersion) { logger.warn("Unable to find the version " + versionNumber + " for the product " + productName + " in the Products list"); } if (!hasAMatchingProduct) { logger.warn("Unable to find the product " + productName + " in the Products list"); } if (hasAnApplicableVersion) { //if the released product list contains a version with the given details and // within the supported period. return affectedVersion; } else { return null; } }
From source file:pt.ist.fenixedu.teacher.domain.reports.TeachersListFromGiafReportFile.java
License:Open Source License
private void listTeachers(Spreadsheet spreadsheet, final ExecutionYear executionYear) throws IOException { generateNameAndHeaders(spreadsheet, executionYear); for (final Teacher teacher : getRootDomainObject().getTeachersSet()) { PersonProfessionalData personProfessionalData = teacher.getPerson().getPersonProfessionalData(); if (personProfessionalData != null) { GiafProfessionalData giafProfessionalData = personProfessionalData.getGiafProfessionalData(); if (personProfessionalData != null && giafProfessionalData != null) { PersonContractSituation personContractSituation = personProfessionalData .getCurrentOrLastPersonContractSituationByCategoryType(CategoryType.TEACHER, executionYear.getBeginDateYearMonthDay().toLocalDate(), executionYear.getEndDateYearMonthDay().toLocalDate()); if (personContractSituation != null) { Unit unit = teacher.getPerson().getEmployee() != null ? teacher.getPerson().getEmployee() .getLastWorkingPlace(executionYear.getBeginDateYearMonthDay(), executionYear.getEndDateYearMonthDay()) : null;/*from w w w. j a va2s . c o m*/ ProfessionalCategory professionalCategory = personProfessionalData .getLastProfessionalCategoryByCategoryType(CategoryType.TEACHER, executionYear.getBeginDateYearMonthDay().toLocalDate(), executionYear.getEndDateYearMonthDay().toLocalDate()); ProfessionalRegime professionalRegime = personProfessionalData.getLastProfessionalRegime( giafProfessionalData, executionYear.getBeginDateYearMonthDay().toLocalDate(), executionYear.getEndDateYearMonthDay().toLocalDate()); ProfessionalRelation professionalRelation = personProfessionalData .getLastProfessionalRelation(giafProfessionalData, executionYear.getBeginDateYearMonthDay().toLocalDate(), executionYear.getEndDateYearMonthDay().toLocalDate()); Double mandatoryLessonHours = TeacherCredits.calculateMandatoryLessonHours(teacher, getLastSemester(personContractSituation, executionYear)); Period yearsInHouse = new Period(giafProfessionalData.getInstitutionEntryDate(), (personContractSituation.getEndDate() == null ? new LocalDate() : personContractSituation.getEndDate())); writePersonInformationRow(spreadsheet, executionYear, teacher, "CONTRATADO", unit, professionalCategory.getTeacherCategory(), professionalRegime, professionalRelation, personContractSituation.getBeginDate(), personContractSituation.getEndDate(), mandatoryLessonHours, yearsInHouse.getYears()); } } } } for (ExecutionSemester executionSemester : executionYear.getExecutionPeriodsSet()) { executionSemester.getTeacherAuthorizationStream().filter(a -> !a.isContracted()) .forEach((authorization) -> { writePersonInformationRow(spreadsheet, executionYear, authorization.getTeacher(), "AUTORIZADO", authorization.getDepartment().getDepartmentUnit(), authorization.getTeacherCategory(), null, null, authorization.getExecutionSemester().getBeginDateYearMonthDay().toLocalDate(), authorization.getExecutionSemester().getEndDateYearMonthDay().toLocalDate(), authorization.getLessonHours(), null); }); } }
From source file:pt.ist.fenixedu.teacher.evaluation.domain.reports.TeachersListFromGiafReportFile.java
License:Open Source License
private void listTeachers(Spreadsheet spreadsheet, final ExecutionYear executionYear) throws IOException { generateNameAndHeaders(spreadsheet, executionYear); for (final Teacher teacher : getRootDomainObject().getTeachersSet()) { PersonProfessionalData personProfessionalData = teacher.getPerson().getPersonProfessionalData(); if (personProfessionalData != null) { GiafProfessionalData giafProfessionalData = personProfessionalData.getGiafProfessionalData(); if (personProfessionalData != null && giafProfessionalData != null) { PersonContractSituation personContractSituation = personProfessionalData .getCurrentOrLastPersonContractSituationByCategoryType(CategoryType.TEACHER, executionYear.getBeginDateYearMonthDay().toLocalDate(), executionYear.getEndDateYearMonthDay().toLocalDate()); if (personContractSituation != null) { Unit unit = teacher.getPerson().getEmployee() != null ? teacher.getPerson().getEmployee() .getLastWorkingPlace(executionYear.getBeginDateYearMonthDay(), executionYear.getEndDateYearMonthDay()) : null;//from w w w. java 2 s. c om ProfessionalCategory professionalCategory = teacher .getLastCategory(executionYear.getAcademicInterval()) .map(tc -> tc.getProfessionalCategory()).orElse(null); ProfessionalRegime professionalRegime = personProfessionalData.getLastProfessionalRegime( giafProfessionalData, executionYear.getBeginDateYearMonthDay().toLocalDate(), executionYear.getEndDateYearMonthDay().toLocalDate()); ProfessionalRelation professionalRelation = personProfessionalData .getLastProfessionalRelation(giafProfessionalData, executionYear.getBeginDateYearMonthDay().toLocalDate(), executionYear.getEndDateYearMonthDay().toLocalDate()); Double mandatoryLessonHours = TeacherCredits.calculateMandatoryLessonHours(teacher, getLastSemester(personContractSituation, executionYear)); Period yearsInHouse = new Period(giafProfessionalData.getInstitutionEntryDate(), (personContractSituation.getEndDate() == null ? new LocalDate() : personContractSituation.getEndDate())); writePersonInformationRow(spreadsheet, executionYear, teacher, "CONTRATADO", unit, professionalCategory.getTeacherCategory(), professionalRegime, professionalRelation, personContractSituation.getBeginDate(), personContractSituation.getEndDate(), mandatoryLessonHours, yearsInHouse.getYears()); } } } } for (ExecutionSemester executionSemester : executionYear.getExecutionPeriodsSet()) { executionSemester.getTeacherAuthorizationStream().filter(a -> !a.isContracted()) .forEach((authorization) -> { writePersonInformationRow(spreadsheet, executionYear, authorization.getTeacher(), "AUTORIZADO", authorization.getDepartment().getDepartmentUnit(), authorization.getTeacherCategory(), null, null, authorization.getExecutionSemester().getBeginDateYearMonthDay().toLocalDate(), authorization.getExecutionSemester().getEndDateYearMonthDay().toLocalDate(), authorization.getLessonHours(), null); }); } }
From source file:uk.ac.ed.uportal.portlets.collaborateportlet.mvc.portlet.EditController.java
License:Apache License
/** * Perform manual model binding for Session start and end dates * * @param request The request to extract start and end dates from * @param session The session to add start and end dates to * @return Validation error messages generated by this binding. The list will be empty if binding was successful *//*from ww w . jav a 2 s .c o m*/ private List<String> addValidatedRequestDatesToSession(ActionRequest request, Session session) { List<String> errorMessage = new ArrayList<>(); Date startTime = null; Date endTime = null; try { String startTimeString = request.getParameter("startdate") + " " + request.getParameter("startHour") + ":" + request.getParameter("startMinute"); startTime = new SimpleDateFormat("dd-MM-yyyy HH:mm", Locale.ENGLISH).parse(startTimeString); session.setStartTime(startTime); } catch (Exception e) { errorMessage.add("error.startdateinvalid"); } try { String endTimeString = request.getParameter("enddate") + " " + request.getParameter("endHour") + ":" + request.getParameter("endMinute"); endTime = new SimpleDateFormat("dd-MM-yyyy HH:mm", Locale.ENGLISH).parse(endTimeString); session.setEndTime(endTime); } catch (Exception e) { errorMessage.add("error.enddateinvalid"); } if (startTime != null && endTime != null) { if (endTime.before(startTime)) { errorMessage.add("error.startdatebeforeenddate"); } Date now = new Date(); if (startTime.before(now)) { errorMessage.add("error.startdatebeforenow"); } Period sessionPeriod = new Period(new DateTime(startTime), new DateTime(endTime)); if (sessionPeriod.getYears() > 0) { errorMessage.add("error.dateyearapart"); } } return errorMessage; }
From source file:uk.org.rbc1b.roms.controller.volunteer.ldc.SubmitLDCFormVolunteerEmailGenerator.java
License:Open Source License
/** * Generate email for a volunteer with the correct message. * * @param volunteer the volunteer//from ww w . j a v a 2 s.co m * @return Email object * @throws IOException if we can't find the email template * @throws TemplateException if Freemarker's had enough */ public Email generateEmailForVolunteers(Volunteer volunteer) throws IOException, TemplateException { Configuration conf = emailFreemarkerConfigurer.getConfiguration(); Map<String, Object> model = new HashMap<>(); model.put("volunteer", volunteer); Date date = volunteer.getFormDate(); if (date == null) { model.put("message", SubmitLDCFormEmailMessageConstants.FORM_DATE_UNKNOWN.getMessage()); } else { DateTime formDate = DataConverterUtil.toDateTime(date); DateTime todayDate = new DateTime(); Period period = new Period(formDate, todayDate); if ((period.getYears() == 2) && (period.getMonths() >= 6)) { model.put("message", SubmitLDCFormEmailMessageConstants.FORM_DATE_TWO_HALF_YRS.getMessage()); } else if (period.getYears() >= 3) { model.put("message", SubmitLDCFormEmailMessageConstants.FORM_DATE_THREE_YRS.getMessage()); } } Email email = new Email(); email.setRecipient(volunteer.getPerson().getEmail()); email.setSubject(SUBJECT); email.setText(FreeMarkerTemplateUtils.processTemplateIntoString(conf.getTemplate(SUBMIT_LDC_FORM_TEMPLATE), model)); return email; }
From source file:utilities.time.DateAndTimes.java
License:Open Source License
/** * * This will calculate out and return a String the length of a period in easy to read format: Y * * @param duration/* w ww . j a va 2 s .c o m*/ * @param yearsSeparatorFormat * @param monthsSeparatorFormat * @param weeksSeparatorFormat * @param daysSeparatorFormat * @param hoursSeparatorFormat * @param minutesSeparatorFormat * @param secondsSeparatorFormat * @return */ public static String getPeriodFormattedFromMilliseconds(long duration, String yearsSeparatorFormat, String monthsSeparatorFormat, String weeksSeparatorFormat, String daysSeparatorFormat, String hoursSeparatorFormat, String minutesSeparatorFormat, String secondsSeparatorFormat) { Period period = new Period(duration); if (period.getYears() > 0) { return getPeriodFormat(period, yearsSeparatorFormat, monthsSeparatorFormat, weeksSeparatorFormat, daysSeparatorFormat, hoursSeparatorFormat, minutesSeparatorFormat, secondsSeparatorFormat); } else if (period.getMonths() > 0) { return getPeriodFormat(period, monthsSeparatorFormat, weeksSeparatorFormat, daysSeparatorFormat, hoursSeparatorFormat, minutesSeparatorFormat, secondsSeparatorFormat); } else if (period.getWeeks() > 0) { return getPeriodFormat(period, weeksSeparatorFormat, daysSeparatorFormat, hoursSeparatorFormat, minutesSeparatorFormat, secondsSeparatorFormat); } else if (period.getDays() > 0) { return getPeriodFormat(period, daysSeparatorFormat, hoursSeparatorFormat, minutesSeparatorFormat, secondsSeparatorFormat); } else if (period.getHours() > 0) { return getPeriodFormat(period, hoursSeparatorFormat, minutesSeparatorFormat, secondsSeparatorFormat); } else if (period.getMinutes() > 0) { return getPeriodFormat(period, minutesSeparatorFormat, secondsSeparatorFormat); } else if (period.getSeconds() > 0) { return getPeriodFormat(period, secondsSeparatorFormat); } else { return null; } }
From source file:webservice.CarInsurancePrice.java
private double checkAge(String dateNaissance, DateTime dateJour, double price) { DateTimeFormatter dft = DateTimeFormat.forPattern("dd/MM/yyyy"); DateTime dtNaissance = dft.parseDateTime(dateNaissance); Period period = new Period(dtNaissance.getMillis(), dateJour.getMillis()); int age = period.getYears(); if (age < JEUNE_AGE) { price *= JEUNE_TAUX;//from w w w . ja v a2 s . c om } return price; }