List of usage examples for java.util Calendar compareTo
private int compareTo(long t)
From source file:org.finra.herd.dao.AbstractDaoTest.java
/** * Creates a list of expected partition value process dates for a specified range. Weekends are excluded. * * @param partitionKeyGroupName the partition key group name * @param startDate the start date of the range * @param endDate the end date of the range * * @return the list of expected partition value process dates *//*from w w w.j a v a2 s . c o m*/ protected List<ExpectedPartitionValueEntity> createExpectedPartitionValueProcessDates( String partitionKeyGroupName, Calendar startDate, Calendar endDate) { // Initialize the list of expected partition values. List<String> expectedPartitionValues = new ArrayList<>(); // Keep incrementing the start date until it is greater than the end date, or until we have 1000 dates to protect against having too many dates or an // infinite loop in case the end date is before the start date. for (int i = 0; i < 1000 && startDate.compareTo(endDate) <= 0; i++) { // Create and persist a new entity for the date if it does not fall on the weekend. if ((startDate.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY) && (startDate.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY)) { expectedPartitionValues.add( new SimpleDateFormat(HerdDao.DEFAULT_SINGLE_DAY_DATE_MASK).format(startDate.getTime())); } // Add one day to the calendar. startDate.add(Calendar.DAY_OF_MONTH, 1); } // Return the list of entities. return createExpectedPartitionValueEntities(partitionKeyGroupName, expectedPartitionValues); }
From source file:org.slc.sli.dashboard.client.LiveAPIClient.java
/** * Process sections to ensure section name and filter historical data if specified * * @param sections//w w w . j a va 2 s . com * @param filterHistoricalData * @return */ private List<GenericEntity> filterCurrentSections(List<GenericEntity> sections, boolean filterHistoricalData) { List<GenericEntity> filteredSections = sections; if (filterHistoricalData) { filteredSections = new ArrayList<GenericEntity>(); } if (sections != null) { // Setup grace period date Calendar gracePeriodCalendar = Calendar.getInstance(); gracePeriodCalendar.setTimeInMillis(System.currentTimeMillis()); try { if (gracePeriod != null && !gracePeriod.equals("")) { int daysToSubtract = Integer.parseInt(gracePeriod) * -1; gracePeriodCalendar.add(Calendar.DATE, daysToSubtract); } } catch (NumberFormatException exception) { LOGGER.warn("Invalid grace period: {}", exception.getMessage()); } for (GenericEntity section : sections) { // if no section name, fill in with section code if (section.get(Constants.ATTR_SECTION_NAME) == null) { section.put(Constants.ATTR_SECTION_NAME, section.get(Constants.ATTR_UNIQUE_SECTION_CODE)); } // Filter historical sections/sessions if necessary if (filterHistoricalData) { Map<String, Object> session = (Map<String, Object>) section.get(Constants.ATTR_SESSION); // Verify section has been enriched with session details if (session != null) { try { // Setup session end date String endDateAttribute = (String) session.get(Constants.ATTR_SESSION_END_DATE); DateFormat formatter = new SimpleDateFormat(Constants.ATTR_DATE_FORMAT); Date sessionEndDate = formatter.parse(endDateAttribute); Calendar sessionEndCalendar = Calendar.getInstance(); sessionEndCalendar.setTimeInMillis(sessionEndDate.getTime()); // Add filtered section if grace period adjusted date is before // or equal to session end date if (gracePeriodCalendar.compareTo(sessionEndCalendar) <= 0) { filteredSections.add(section); } } catch (IllegalArgumentException exception) { LOGGER.warn("Invalid session date formatter configuration: {}", exception.getMessage()); } catch (ParseException exception) { LOGGER.warn("Invalid session date format: {}", exception.getMessage()); } } } } } return filteredSections; }
From source file:org.kuali.ole.module.purap.document.service.impl.PaymentRequestServiceImpl.java
/** * @see org.kuali.ole.module.purap.document.service.PaymentRequestService#allowBackpost(org.kuali.ole.module.purap.document.PaymentRequestDocument) *//*from ww w . j a v a 2s .co m*/ @Override public boolean allowBackpost(PaymentRequestDocument paymentRequestDocument) { int allowBackpost = (Integer.parseInt(parameterService .getParameterValueAsString(PaymentRequestDocument.class, PurapRuleConstants.ALLOW_BACKPOST_DAYS))); Calendar today = dateTimeService.getCurrentCalendar(); Integer currentFY = universityDateService.getCurrentUniversityDate().getUniversityFiscalYear(); java.util.Date priorClosingDateTemp = universityDateService.getLastDateOfFiscalYear(currentFY - 1); Calendar priorClosingDate = Calendar.getInstance(); priorClosingDate.setTime(priorClosingDateTemp); // adding 1 to set the date to midnight the day after backpost is allowed so that preqs allow backpost on the last day Calendar allowBackpostDate = Calendar.getInstance(); allowBackpostDate.setTime(priorClosingDate.getTime()); allowBackpostDate.add(Calendar.DATE, allowBackpost + 1); Calendar preqInvoiceDate = Calendar.getInstance(); preqInvoiceDate.setTime(paymentRequestDocument.getInvoiceDate()); // if today is after the closing date but before/equal to the allowed backpost date and the invoice date is for the // prior year, set the year to prior year if ((today.compareTo(priorClosingDate) > 0) && (today.compareTo(allowBackpostDate) <= 0) && (preqInvoiceDate.compareTo(priorClosingDate) <= 0)) { LOG.debug("allowBackpost() within range to allow backpost; posting entry to period 12 of previous FY"); return true; } LOG.debug("allowBackpost() not within range to allow backpost; posting entry to current FY"); return false; }
From source file:com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.EngineServiceImpl.java
private boolean equals(Object obj1, Object obj2) { if (obj1 == obj2) return true; if ((obj1 == null) || (obj2 == null)) return false; if ((obj1 instanceof Date) && (obj2 instanceof Date)) { Calendar calendar1 = new GregorianCalendar(); calendar1.setTime((Date) obj1); calendar1.set(Calendar.SECOND, 0); calendar1.set(Calendar.MILLISECOND, 0); Calendar calendar2 = new GregorianCalendar(); calendar2.setTime((Date) obj2); calendar2.set(Calendar.SECOND, 0); calendar2.set(Calendar.MILLISECOND, 0); return (calendar1.compareTo(calendar2) == 0); } else if ((obj1 instanceof String) && (obj2 instanceof String)) { return ((String) obj1).equalsIgnoreCase((String) obj2); } else/*from w w w .jav a 2 s .c o m*/ return obj1.equals(obj2); }
From source file:edu.northwestern.jcr.adapter.xtf.query.SearchIndex.java
/** * Sorts the query results based on the value of the properties. * The ORDER BY clause is actually handled here. * * @param lines array of comma-separated full paths to the query results * @param valueMap maps pid to comma-separated values * @param orderSpecs true for ascending, false for descending * @return array of sorted results//from www.j a va 2 s . c om */ private String[] sort(String[] lines, final Map<String, String> valueMap, final boolean[] orderSpecs) { Comparator<String> result_order = new Comparator<String>() { public int compare(String line1, String line2) { String pid1, pid2; String valueList1, valueList2; String[] parts; String[] valueString1, valueString2; String value1, value2; Double double1, double2; Long long1, long2; Calendar calendar1, calendar2; Boolean boolean1, boolean2; int i; int compare = 0; // get pid of the last object in the list parts = line1.split(","); pid1 = parts[parts.length - 1]; parts = line2.split(","); pid2 = parts[parts.length - 1]; // get comma-separated the value list valueList1 = valueMap.get(pid1); valueList2 = valueMap.get(pid2); valueString1 = valueList1.split(","); valueString2 = valueList2.split(","); for (i = 0; i < valueString1.length; ++i) { // loop over the values value1 = valueString1[i]; parts = value1.split("%57"); value1 = parts[parts.length - 1]; value2 = valueString2[i]; parts = value2.split("%57"); value2 = parts[parts.length - 1]; switch (Integer.parseInt(parts[0])) { case PropertyType.STRING: if (orderSpecs[i]) { compare = value1.compareTo(value2); } else { compare = value2.compareTo(value1); } break; case PropertyType.DOUBLE: double1 = Double.parseDouble(value1); double2 = Double.parseDouble(value2); if (orderSpecs[i]) { compare = double1.compareTo(double2); } else { compare = double2.compareTo(double1); } break; case PropertyType.LONG: long1 = Long.parseLong(value1); long2 = Long.parseLong(value2); if (orderSpecs[i]) { compare = long1.compareTo(long2); } else { compare = long2.compareTo(long1); } break; case PropertyType.DATE: calendar1 = ISO8601.parse(value1); calendar2 = ISO8601.parse(value2); if (orderSpecs[i]) { compare = calendar1.compareTo(calendar2); } else { compare = calendar2.compareTo(calendar1); } break; case PropertyType.BOOLEAN: boolean1 = Boolean.valueOf(value1); boolean2 = Boolean.valueOf(value2); if (orderSpecs[i]) { compare = boolean1.compareTo(boolean2); } else { compare = boolean2.compareTo(boolean1); } break; // not supported case PropertyType.BINARY: case PropertyType.REFERENCE: case PropertyType.NAME: case PropertyType.PATH: compare = 0; } if (compare != 0) { return compare; } // more comparison } return compare; } }; List<String> resultList = Arrays.asList(lines); Collections.sort(resultList, result_order); return resultList.toArray(new String[0]); }
From source file:org.kuali.kfs.module.purap.document.service.impl.PaymentRequestServiceImpl.java
/** * @see org.kuali.kfs.module.purap.document.service.PaymentRequestService#allowBackpost(org.kuali.kfs.module.purap.document.PaymentRequestDocument) *///from ww w .ja v a 2 s .c o m @Override @NonTransactional public boolean allowBackpost(PaymentRequestDocument paymentRequestDocument) { int allowBackpost = (Integer.parseInt(parameterService .getParameterValueAsString(PaymentRequestDocument.class, PurapRuleConstants.ALLOW_BACKPOST_DAYS))); Calendar today = dateTimeService.getCurrentCalendar(); Integer currentFY = universityDateService.getCurrentUniversityDate().getUniversityFiscalYear(); java.util.Date priorClosingDateTemp = universityDateService.getLastDateOfFiscalYear(currentFY - 1); Calendar priorClosingDate = Calendar.getInstance(); priorClosingDate.setTime(priorClosingDateTemp); // adding 1 to set the date to midnight the day after backpost is allowed so that preqs allow backpost on the last day Calendar allowBackpostDate = Calendar.getInstance(); allowBackpostDate.setTime(priorClosingDate.getTime()); allowBackpostDate.add(Calendar.DATE, allowBackpost + 1); Calendar preqInvoiceDate = Calendar.getInstance(); preqInvoiceDate.setTime(paymentRequestDocument.getInvoiceDate()); // if today is after the closing date but before/equal to the allowed backpost date and the invoice date is for the // prior year, set the year to prior year if ((today.compareTo(priorClosingDate) > 0) && (today.compareTo(allowBackpostDate) <= 0) && (preqInvoiceDate.compareTo(priorClosingDate) <= 0)) { LOG.debug("allowBackpost() within range to allow backpost; posting entry to period 12 of previous FY"); return true; } LOG.debug("allowBackpost() not within range to allow backpost; posting entry to current FY"); return false; }
From source file:org.kuali.ole.module.purap.document.service.impl.InvoiceServiceImpl.java
/** * @see org.kuali.ole.module.purap.document.service.InvoiceService#allowBackpost(org.kuali.ole.module.purap.document.InvoiceDocument) *///from w w w . j a v a 2 s .co m @Override public boolean allowBackpost(InvoiceDocument invoiceDocument) { int allowBackpost = (Integer .parseInt(getParameter(OLEConstants.OptionalModuleNamespaces.PURCHASING_ACCOUNTS_PAYABLE, OLEConstants.InvoiceDocument.CMPNT_CD, PurapRuleConstants.ALLOW_BACKPOST_DAYS))); Calendar today = dateTimeService.getCurrentCalendar(); Integer currentFY = universityDateService.getCurrentUniversityDate().getUniversityFiscalYear(); java.util.Date priorClosingDateTemp = universityDateService.getLastDateOfFiscalYear(currentFY - 1); Calendar priorClosingDate = Calendar.getInstance(); priorClosingDate.setTime(priorClosingDateTemp); // adding 1 to set the date to midnight the day after backpost is allowed so that prqss allow backpost on the last day Calendar allowBackpostDate = Calendar.getInstance(); allowBackpostDate.setTime(priorClosingDate.getTime()); allowBackpostDate.add(Calendar.DATE, allowBackpost + 1); Calendar prqsInvoiceDate = Calendar.getInstance(); prqsInvoiceDate.setTime( invoiceDocument.getInvoiceDate() != null ? invoiceDocument.getInvoiceDate() : new java.util.Date()); // if today is after the closing date but before/equal to the allowed backpost date and the invoice date is for the // prior year, set the year to prior year if ((today.compareTo(priorClosingDate) > 0) && (today.compareTo(allowBackpostDate) <= 0) && (prqsInvoiceDate.compareTo(priorClosingDate) <= 0)) { LOG.debug("allowBackpost() within range to allow backpost; posting entry to period 12 of previous FY"); return true; } LOG.debug("allowBackpost() not within range to allow backpost; posting entry to current FY"); return false; }
From source file:org.slc.sli.dashboard.client.SDKAPIClient.java
/** * Process sections to ensure section name and filter historical data if * specified//from w w w. ja v a 2 s . c o m * * @param sections * @param filterHistoricalData * @return */ private List<GenericEntity> filterCurrentSections(List<GenericEntity> sections, boolean filterHistoricalData) { List<GenericEntity> filteredSections = sections; if (filterHistoricalData) { filteredSections = new ArrayList<GenericEntity>(); } if (sections != null && sections.size() > 0) { // Setup grace period date Calendar gracePeriodCalendar = Calendar.getInstance(); gracePeriodCalendar.setTimeInMillis(System.currentTimeMillis()); try { if (gracePeriod != null && !gracePeriod.equals("")) { int daysToSubtract = Integer.parseInt(gracePeriod) * -1; gracePeriodCalendar.add(Calendar.DATE, daysToSubtract); } } catch (NumberFormatException exception) { LOG.warn("Invalid grace period: {}", exception.getMessage()); } for (GenericEntity section : sections) { // Ensure section name ensureSectionName(section); // Filter historical sections/sessions if necessary if (filterHistoricalData) { Map<String, Object> session = (Map<String, Object>) section.get(Constants.ATTR_SESSION); // Verify section has been enriched with session details if (session != null) { try { // Setup session end date String endDateAttribute = (String) session.get(Constants.ATTR_SESSION_END_DATE); DateFormat formatter = new SimpleDateFormat(Constants.ATTR_DATE_FORMAT); Date sessionEndDate = formatter.parse(endDateAttribute); Calendar sessionEndCalendar = Calendar.getInstance(); sessionEndCalendar.setTimeInMillis(sessionEndDate.getTime()); // Add filtered section if grace period adjusted // date is before // or equal to session end date if (gracePeriodCalendar.compareTo(sessionEndCalendar) <= 0) { filteredSections.add(section); } } catch (IllegalArgumentException exception) { LOG.warn("Invalid session date formatter configuration: {}", exception.getMessage()); } catch (ParseException exception) { LOG.warn("Invalid session date format: {}", exception.getMessage()); } } } } } return filteredSections; }
From source file:net.sourceforge.fenixedu.presentationTier.Action.teacher.StudentGroupManagementDA.java
public ActionForward editGroupProperties(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws FenixActionException { DynaActionForm editGroupPropertiesForm = (DynaActionForm) form; String groupPropertiesString = request.getParameter("groupPropertiesCode"); String groupPropertiesCode = groupPropertiesString; String name = (String) editGroupPropertiesForm.get("name"); String projectDescription = (String) editGroupPropertiesForm.get("projectDescription"); String maximumCapacityString = (String) editGroupPropertiesForm.get("maximumCapacity"); String minimumCapacityString = (String) editGroupPropertiesForm.get("minimumCapacity"); String idealCapacityString = (String) editGroupPropertiesForm.get("idealCapacity"); String groupMaximumNumber = (String) editGroupPropertiesForm.get("groupMaximumNumber"); String enrolmentBeginDayString = (String) editGroupPropertiesForm.get("enrolmentBeginDayFormatted"); String enrolmentBeginHourString = (String) editGroupPropertiesForm.get("enrolmentBeginHourFormatted"); String enrolmentEndDayString = (String) editGroupPropertiesForm.get("enrolmentEndDayFormatted"); String enrolmentEndHourString = (String) editGroupPropertiesForm.get("enrolmentEndHourFormatted"); String shiftType = (String) editGroupPropertiesForm.get("shiftType"); String enrolmentPolicy = (String) editGroupPropertiesForm.get("enrolmentPolicy"); Boolean automaticEnrolment = getAutomaticEnrolment(editGroupPropertiesForm); Boolean differentiatedCapacity = getDifferentiatedCapacity(editGroupPropertiesForm); final ArrayList<InfoShift> infoShifts = getRenderedObject("shiftsTable"); if ("".equals(name)) { ActionMessages actionErrors = new ActionMessages(); ActionMessage error = new ActionMessage("error.groupProperties.missingName"); actionErrors.add("error.groupProperties.missingName", error); saveErrors(request, actionErrors); return prepareEditGroupProperties(mapping, form, request, response); }//from w w w . ja va2s . c om Calendar enrolmentBeginDay = null; if (!enrolmentBeginDayString.equals("")) { String[] beginDate = enrolmentBeginDayString.split("/"); enrolmentBeginDay = Calendar.getInstance(); enrolmentBeginDay.set(Calendar.DAY_OF_MONTH, (new Integer(beginDate[0])).intValue()); enrolmentBeginDay.set(Calendar.MONTH, (new Integer(beginDate[1])).intValue() - 1); enrolmentBeginDay.set(Calendar.YEAR, (new Integer(beginDate[2])).intValue()); if (!enrolmentBeginHourString.equals("")) { String[] beginHour = enrolmentBeginHourString.split(":"); enrolmentBeginDay.set(Calendar.HOUR_OF_DAY, (new Integer(beginHour[0])).intValue()); enrolmentBeginDay.set(Calendar.MINUTE, (new Integer(beginHour[1])).intValue()); enrolmentBeginDay.set(Calendar.SECOND, 0); } } Calendar enrolmentEndDay = null; if (!enrolmentEndDayString.equals("")) { String[] endDate = enrolmentEndDayString.split("/"); enrolmentEndDay = Calendar.getInstance(); enrolmentEndDay.set(Calendar.DAY_OF_MONTH, (new Integer(endDate[0])).intValue()); enrolmentEndDay.set(Calendar.MONTH, (new Integer(endDate[1])).intValue() - 1); enrolmentEndDay.set(Calendar.YEAR, (new Integer(endDate[2])).intValue()); if (!enrolmentEndHourString.equals("")) { String[] endHour = enrolmentEndHourString.split(":"); enrolmentEndDay.set(Calendar.HOUR_OF_DAY, (new Integer(endHour[0])).intValue()); enrolmentEndDay.set(Calendar.MINUTE, (new Integer(endHour[1])).intValue()); enrolmentEndDay.set(Calendar.SECOND, 0); } } float compareDate = enrolmentBeginDay.compareTo(enrolmentEndDay); if (compareDate >= 0.0) { ActionMessages actionErrors = new ActionMessages(); ActionMessage error = null; error = new ActionMessage("error.manager.wrongDates"); actionErrors.add("error.manager.wrongDates", error); saveErrors(request, actionErrors); return prepareEditGroupProperties(mapping, form, request, response); } InfoGrouping infoGroupProperties = new InfoGrouping(); infoGroupProperties.setExternalId(groupPropertiesCode); infoGroupProperties.setEnrolmentBeginDay(enrolmentBeginDay); infoGroupProperties.setEnrolmentEndDay(enrolmentEndDay); infoGroupProperties.setEnrolmentPolicy(new EnrolmentGroupPolicyType(new Integer(enrolmentPolicy))); infoGroupProperties.setAutomaticEnrolment(automaticEnrolment); infoGroupProperties.setDifferentiatedCapacity(differentiatedCapacity); if (differentiatedCapacity) { for (InfoShift info : infoShifts) { if (!maximumCapacityString.equals("") && info.getGroupCapacity() * Integer.parseInt(maximumCapacityString) > info.getLotacao()) { ActionMessages actionErrors = new ActionMessages(); ActionMessage error = null; error = new ActionMessage("error.groupProperties.capacityOverflow"); actionErrors.add("error.groupProperties.capacityOverflow", error); saveErrors(request, actionErrors); return prepareEditGroupProperties(mapping, form, request, response); } } infoGroupProperties.setInfoShifts(infoShifts); } infoGroupProperties.setDifferentiatedCapacity(differentiatedCapacity); if (!groupMaximumNumber.equals("")) { infoGroupProperties.setGroupMaximumNumber(new Integer(groupMaximumNumber)); } Integer maximumCapacity = null; Integer minimumCapacity = null; Integer idealCapacity = null; if (!maximumCapacityString.equals("")) { maximumCapacity = new Integer(maximumCapacityString); infoGroupProperties.setMaximumCapacity(maximumCapacity); } if (!minimumCapacityString.equals("")) { minimumCapacity = new Integer(minimumCapacityString); if (maximumCapacity != null) { if (minimumCapacity.compareTo(maximumCapacity) > 0) { ActionMessages actionErrors = new ActionMessages(); ActionMessage error = null; error = new ActionMessage("error.groupProperties.minimum"); actionErrors.add("error.groupProperties.minimum", error); saveErrors(request, actionErrors); return prepareEditGroupProperties(mapping, form, request, response); } } infoGroupProperties.setMinimumCapacity(minimumCapacity); } if (!idealCapacityString.equals("")) { idealCapacity = new Integer(idealCapacityString); if (!minimumCapacityString.equals("")) { if (idealCapacity.compareTo(minimumCapacity) < 0) { ActionMessages actionErrors = new ActionMessages(); ActionMessage error = null; error = new ActionMessage("error.groupProperties.ideal.minimum"); actionErrors.add("error.groupProperties.ideal.minimum", error); saveErrors(request, actionErrors); return prepareEditGroupProperties(mapping, form, request, response); } } if (!maximumCapacityString.equals("")) { if (idealCapacity.compareTo(maximumCapacity) > 0) { ActionMessages actionErrors = new ActionMessages(); ActionMessage error = null; error = new ActionMessage("error.groupProperties.ideal.maximum"); actionErrors.add("error.groupProperties.ideal.maximum", error); saveErrors(request, actionErrors); return prepareEditGroupProperties(mapping, form, request, response); } } infoGroupProperties.setIdealCapacity(idealCapacity); } infoGroupProperties.setName(name); infoGroupProperties.setProjectDescription(projectDescription); if (!shiftType.equalsIgnoreCase("Sem Turno")) { infoGroupProperties.setShiftType(ShiftType.valueOf(shiftType)); } String objectCode = getExecutionCourse(request).getExternalId(); List errors = new ArrayList(); try { errors = EditGrouping.runEditGrouping(objectCode, infoGroupProperties); } catch (InvalidSituationServiceException e) { ActionMessages actionErrors = new ActionMessages(); ActionMessage error = null; error = new ActionMessage("error.noGroupProperties"); actionErrors.add("error.noGroupProperties", error); saveErrors(request, actionErrors); return prepareViewExecutionCourseProjects(mapping, form, request, response); } catch (DomainException e) { ActionMessages actionErrors = new ActionMessages(); ActionMessage error = null; error = new ActionMessage(e.getArgs()[0]); actionErrors.add("error.noGroupProperties", error); saveErrors(request, actionErrors); return prepareViewExecutionCourseProjects(mapping, form, request, response); } catch (FenixServiceException e) { throw new FenixActionException(e); } if (errors.size() != 0) { ActionMessages actionErrors = new ActionMessages(); Iterator iterErrors = errors.iterator(); ActionMessage errorInt = null; errorInt = new ActionMessage("error.exception.editGroupProperties"); actionErrors.add("error.exception.editGroupProperties", errorInt); while (iterErrors.hasNext()) { Integer intError = (Integer) iterErrors.next(); if (intError.equals(Integer.valueOf(-1))) { ActionMessage error = null; error = new ActionMessage("error.exception.nrOfGroups.editGroupProperties"); actionErrors.add("error.exception.nrOfGroups.editGroupProperties", error); } if (intError.equals(Integer.valueOf(-2))) { ActionMessage error = null; error = new ActionMessage("error.exception.maximumCapacity.editGroupProperties"); actionErrors.add("error.exception.maximumCapacity.editGroupProperties", error); } if (intError.equals(Integer.valueOf(-3))) { ActionMessage error = null; error = new ActionMessage("error.exception.minimumCapacity.editGroupProperties"); actionErrors.add("error.exception.minimumCapacity.editGroupProperties", error); } } saveErrors(request, actionErrors); } return prepareViewExecutionCourseProjects(mapping, form, request, response); }
From source file:net.sourceforge.fenixedu.presentationTier.Action.teacher.StudentGroupManagementDA.java
public ActionForward createGroupProperties(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws FenixActionException { DynaActionForm insertGroupPropertiesForm = (DynaActionForm) form; String name = (String) insertGroupPropertiesForm.get("name"); String projectDescription = (String) insertGroupPropertiesForm.get("projectDescription"); String maximumCapacityString = (String) insertGroupPropertiesForm.get("maximumCapacity"); String minimumCapacityString = (String) insertGroupPropertiesForm.get("minimumCapacity"); String idealCapacityString = (String) insertGroupPropertiesForm.get("idealCapacity"); String groupMaximumNumber = (String) insertGroupPropertiesForm.get("groupMaximumNumber"); String enrolmentBeginDayString = (String) insertGroupPropertiesForm.get("enrolmentBeginDay"); String enrolmentBeginHourString = (String) insertGroupPropertiesForm.get("enrolmentBeginHour"); String enrolmentEndDayString = (String) insertGroupPropertiesForm.get("enrolmentEndDay"); String enrolmentEndHourString = (String) insertGroupPropertiesForm.get("enrolmentEndHour"); String shiftType = (String) insertGroupPropertiesForm.get("shiftType"); Boolean optional = new Boolean((String) insertGroupPropertiesForm.get("enrolmentPolicy")); Boolean automaticEnrolment = getAutomaticEnrolment(insertGroupPropertiesForm); Boolean differentiatedCapacity = getDifferentiatedCapacity(insertGroupPropertiesForm); final ArrayList<InfoShift> infoShifts = getRenderedObject("shiftsTable"); if ("".equals(name)) { ActionMessages actionErrors = new ActionMessages(); ActionMessage error = new ActionMessage("error.groupProperties.missingName"); actionErrors.add("error.groupProperties.missingName", error); saveErrors(request, actionErrors); return prepareCreateGroupProperties(mapping, form, request, response); }/*ww w .ja v a2 s . co m*/ InfoGrouping infoGroupProperties = new InfoGrouping(); infoGroupProperties.setName(name); infoGroupProperties.setProjectDescription(projectDescription); if (!shiftType.equalsIgnoreCase("Sem Turno")) { infoGroupProperties.setShiftType(ShiftType.valueOf(shiftType)); } if (differentiatedCapacity) { for (InfoShift info : infoShifts) { if (info.getLotacao() != 0) { //it means it was locked from students enrolment only if (!maximumCapacityString.equals("") && info.getGroupCapacity() * Integer.parseInt(maximumCapacityString) > info.getLotacao()) { ActionMessages actionErrors = new ActionMessages(); ActionMessage error = new ActionMessage("error.groupProperties.capacityOverflow"); actionErrors.add("error.groupProperties.capacityOverflow", error); saveErrors(request, actionErrors); return prepareCreateGroupProperties(mapping, form, request, response); } } } infoGroupProperties.setInfoShifts(infoShifts); } Integer maximumCapacity = null; Integer minimumCapacity = null; Integer idealCapacity = null; if (!maximumCapacityString.equals("")) { maximumCapacity = new Integer(maximumCapacityString); infoGroupProperties.setMaximumCapacity(maximumCapacity); } if (!minimumCapacityString.equals("")) { minimumCapacity = new Integer(minimumCapacityString); if (maximumCapacity != null) { if (minimumCapacity.compareTo(maximumCapacity) > 0) { ActionMessages actionErrors = new ActionMessages(); ActionMessage error = null; error = new ActionMessage("error.groupProperties.minimum"); actionErrors.add("error.groupProperties.minimum", error); saveErrors(request, actionErrors); return prepareCreateGroupProperties(mapping, form, request, response); } } infoGroupProperties.setMinimumCapacity(minimumCapacity); } if (!idealCapacityString.equals("")) { idealCapacity = new Integer(idealCapacityString); if (!minimumCapacityString.equals("")) { if (idealCapacity.compareTo(minimumCapacity) < 0) { ActionMessages actionErrors = new ActionMessages(); ActionMessage error = null; error = new ActionMessage("error.groupProperties.ideal.minimum"); actionErrors.add("error.groupProperties.ideal.minimum", error); saveErrors(request, actionErrors); return prepareCreateGroupProperties(mapping, form, request, response); } } if (!maximumCapacityString.equals("")) { if (idealCapacity.compareTo(maximumCapacity) > 0) { ActionMessages actionErrors = new ActionMessages(); ActionMessage error = null; error = new ActionMessage("error.groupProperties.ideal.maximum"); actionErrors.add("error.groupProperties.ideal.maximum", error); saveErrors(request, actionErrors); return prepareCreateGroupProperties(mapping, form, request, response); } } infoGroupProperties.setIdealCapacity(idealCapacity); } if (!groupMaximumNumber.equals("")) { infoGroupProperties.setGroupMaximumNumber(new Integer(groupMaximumNumber)); } infoGroupProperties.setDifferentiatedCapacity(differentiatedCapacity); EnrolmentGroupPolicyType enrolmentPolicy; if (optional.booleanValue()) { enrolmentPolicy = new EnrolmentGroupPolicyType(1); } else { enrolmentPolicy = new EnrolmentGroupPolicyType(2); } infoGroupProperties.setEnrolmentPolicy(enrolmentPolicy); infoGroupProperties.setAutomaticEnrolment(automaticEnrolment); Calendar enrolmentBeginDay = null; if (!enrolmentBeginDayString.equals("")) { String[] beginDate = enrolmentBeginDayString.split("/"); enrolmentBeginDay = Calendar.getInstance(); enrolmentBeginDay.set(Calendar.DAY_OF_MONTH, (new Integer(beginDate[0])).intValue()); enrolmentBeginDay.set(Calendar.MONTH, (new Integer(beginDate[1])).intValue() - 1); enrolmentBeginDay.set(Calendar.YEAR, (new Integer(beginDate[2])).intValue()); if (!enrolmentBeginHourString.equals("")) { String[] beginHour = enrolmentBeginHourString.split(":"); enrolmentBeginDay.set(Calendar.HOUR_OF_DAY, (new Integer(beginHour[0])).intValue()); enrolmentBeginDay.set(Calendar.MINUTE, (new Integer(beginHour[1])).intValue()); enrolmentBeginDay.set(Calendar.SECOND, 0); } } else { ActionMessages actionErrors = new ActionMessages(); ActionMessage error = new ActionMessage("error.groupProperties.missingEnrolmentBeginDay"); actionErrors.add("error.groupProperties.missingEnrolmentBeginDay", error); saveErrors(request, actionErrors); return prepareCreateGroupProperties(mapping, form, request, response); } infoGroupProperties.setEnrolmentBeginDay(enrolmentBeginDay); Calendar enrolmentEndDay = null; if (!enrolmentEndDayString.equals("")) { String[] endDate = enrolmentEndDayString.split("/"); enrolmentEndDay = Calendar.getInstance(); enrolmentEndDay.set(Calendar.DAY_OF_MONTH, (new Integer(endDate[0])).intValue()); enrolmentEndDay.set(Calendar.MONTH, (new Integer(endDate[1])).intValue() - 1); enrolmentEndDay.set(Calendar.YEAR, (new Integer(endDate[2])).intValue()); if (!enrolmentEndHourString.equals("")) { String[] endHour = enrolmentEndHourString.split(":"); enrolmentEndDay.set(Calendar.HOUR_OF_DAY, (new Integer(endHour[0])).intValue()); enrolmentEndDay.set(Calendar.MINUTE, (new Integer(endHour[1])).intValue()); enrolmentEndDay.set(Calendar.SECOND, 0); } } else { ActionMessages actionErrors = new ActionMessages(); ActionMessage error = new ActionMessage("error.groupProperties.missingEnrolmentEndDay"); actionErrors.add("error.groupProperties.missingEnrolmentEndDay", error); saveErrors(request, actionErrors); return prepareCreateGroupProperties(mapping, form, request, response); } float compareDate = enrolmentBeginDay.compareTo(enrolmentEndDay); if (compareDate >= 0.0) { ActionMessages actionErrors = new ActionMessages(); ActionMessage error = null; error = new ActionMessage("error.manager.wrongDates"); actionErrors.add("error.manager.wrongDates", error); saveErrors(request, actionErrors); return prepareCreateGroupProperties(mapping, form, request, response); } infoGroupProperties.setEnrolmentEndDay(enrolmentEndDay); String objectCode = getExecutionCourse(request).getExternalId(); try { CreateGrouping.runCreateGrouping(objectCode, infoGroupProperties); } catch (DomainException e) { ActionMessages actionErrors = new ActionMessages(); ActionMessage error = new ActionMessage("error.exception.existing.groupProperties"); actionErrors.add("error.exception.existing.groupProperties", error); saveErrors(request, actionErrors); return prepareCreateGroupProperties(mapping, form, request, response); } catch (FenixServiceException fenixServiceException) { throw new FenixActionException(fenixServiceException.getMessage()); } return prepareViewExecutionCourseProjects(mapping, form, request, response); }