List of usage examples for org.apache.commons.lang.time DateUtils addDays
public static Date addDays(Date date, int amount)
From source file:org.kuali.kra.committee.web.CommitteeScheduleRuleSeleniumTest.java
/** * Test the warning message during date conflict. * /*w w w . j a v a 2 s . com*/ * @throws Exception */ @Test public void testDateWarnings() throws Exception { helper.createCommittee(); helper.clickCommitteeSchedulePage(); Date scheduleStartDate = DateUtils.addDays(new Date(), -1); Date scheduleEndDate = DateUtils.addDays(scheduleStartDate, 2); helper.set(HELPER_SCHEDULE_START_DATE_ID, fullFormatter.format(scheduleStartDate)); helper.set(HELPER_TIME_ID, TIME); helper.set(HELPER_PLACE_ID, PLACE); helper.set(HELPER_RECURRENCE_TYPE_ID, RECURRENCE_TYPE); helper.set(HELPER_DAILY_SCHEDULE_SCHEDULE_END_DATE_ID, fullFormatter.format(scheduleEndDate)); helper.click(ADD_EVENT_BUTTON); helper.assertNoPageErrors(); Date firstScheduleDate = DateUtils.addDays(scheduleStartDate, 0); Date firstDeadlineDate = DateUtils.addDays(firstScheduleDate, -1); Date secondScheduleDate = DateUtils.addDays(scheduleStartDate, 1); Date secondDeadlineDate = DateUtils.addDays(secondScheduleDate, -1); Date thirdScheduleDate = DateUtils.addDays(scheduleStartDate, 2); Date thirdDeadlineDate = DateUtils.addDays(thirdScheduleDate, -1); helper.assertTableRowCount(TABLE_ID, 6); helper.assertElementContains(String.format(LIST_SCHEDULE_DATE_ID, 0), fullFormatter.format(firstScheduleDate)); helper.assertTableCellValueContains(TABLE_ID, 2, 1, dayFormatter.format(firstScheduleDate).toUpperCase()); helper.assertElementContains(String.format(LIST_PROTOCOL_SUB_DEADLINE_ID, 0), fullFormatter.format(firstDeadlineDate)); helper.assertElementContains(String.format(LIST_SCHEDULE_DATE_ID, 1), fullFormatter.format(secondScheduleDate)); helper.assertTableCellValueContains(TABLE_ID, 3, 1, dayFormatter.format(secondScheduleDate).toUpperCase()); helper.assertElementContains(String.format(LIST_PROTOCOL_SUB_DEADLINE_ID, 1), fullFormatter.format(secondDeadlineDate)); helper.assertElementContains(String.format(LIST_SCHEDULE_DATE_ID, 2), fullFormatter.format(thirdScheduleDate)); helper.assertTableCellValueContains(TABLE_ID, 4, 1, dayFormatter.format(thirdScheduleDate).toUpperCase()); helper.assertElementContains(String.format(LIST_PROTOCOL_SUB_DEADLINE_ID, 2), fullFormatter.format(thirdDeadlineDate)); helper.click(ADD_EVENT_BUTTON); helper.assertNoPageErrors(); helper.assertWarning(ERROR_TAB_ID, errorFormatter.format(scheduleStartDate) + WARNING_SKIPPED); }
From source file:org.kuali.kra.common.committee.web.struts.form.CommitteeHelperBase.java
/** * This method prepares a view to filter dates between start and end date, sorted by the scheduled date. * @param startDate/*from w w w . ja v a 2 s.co m*/ * @param endDate */ public void prepareFilterDatesView(java.util.Date startDate, java.util.Date endDate) { startDate = DateUtils.addDays(startDate, -1); endDate = DateUtils.addDays(endDate, 1); java.util.Date scheduleDate = null; for (CommitteeScheduleBase committeeSchedule : getSortedCommitteeScheduleList()) { scheduleDate = committeeSchedule.getScheduledDate(); if ((scheduleDate != null) && scheduleDate.after(startDate) && scheduleDate.before(endDate)) { committeeSchedule.setFilter(true); } else { committeeSchedule.setFilter(false); } } }
From source file:org.kuali.ole.module.purap.document.service.impl.OlePurapServiceImpl.java
/** * This method is used to set the claimdate for Requisition * @param oleRequisitionItem//www. j a v a 2 s .c o m */ public void setClaimDateForReq(OleRequisitionItem oleRequisitionItem, VendorDetail vendorDetail) { if (vendorDetail != null) { String claimInterval = vendorDetail.getClaimInterval(); if (StringUtils.isNotBlank(claimInterval)) { Integer actIntvl = Integer.parseInt(claimInterval); oleRequisitionItem.setClaimDate( new java.sql.Date(DateUtils.addDays(new java.util.Date(), actIntvl).getTime())); } } }
From source file:org.kuali.ole.module.purap.document.service.impl.OlePurapServiceImpl.java
/** * This method is used to set the claimdate for Purchase Order * @param olePurchaseOrderItem/*from w ww. ja v a2s. co m*/ */ public void setClaimDateForPO(OlePurchaseOrderItem olePurchaseOrderItem, VendorDetail vendorDetail) { if (vendorDetail != null) { String claimInterval = vendorDetail.getClaimInterval(); if (StringUtils.isNotBlank(claimInterval)) { Integer actIntvl = Integer.parseInt(claimInterval); olePurchaseOrderItem.setClaimDate( new java.sql.Date(DateUtils.addDays(new java.util.Date(), actIntvl).getTime())); } } }
From source file:org.kuali.ole.module.purap.document.web.struts.OlePurchaseOrderAction.java
/** * @see org.kuali.ole.module.purap.document.web.struts.PurchaseOrderAction#addItem(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) *///from ww w.ja v a 2 s .co m @Override public ActionForward addItem(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { LOG.debug("###########Inside AddItem in olePurchaseOrderAction ###########"); PurchasingFormBase purchasingForm = (PurchasingFormBase) form; OlePurchaseOrderItem purchaseOrderItem = (OlePurchaseOrderItem) purchasingForm.getNewPurchasingItemLine(); purchaseOrderItem.getNewSourceLine().setAccountLinePercent(new BigDecimal(100)); //purchasingForm.getNewPurchasingItemLine().setItemDescription((purchaseOrderItem.getBibInfoBean().getTitle() != null ? purchaseOrderItem.getBibInfoBean().getTitle() : "") + (purchaseOrderItem.getBibInfoBean().getAuthor() != null ? "," + purchaseOrderItem.getBibInfoBean().getAuthor() : "") + (purchaseOrderItem.getBibInfoBean().getPublisher() != null ? "," + purchaseOrderItem.getBibInfoBean().getPublisher() : "") + (purchaseOrderItem.getBibInfoBean().getIsbn() != null ? "," + purchaseOrderItem.getBibInfoBean().getIsbn() : "")); PurchaseOrderDocument document = (PurchaseOrderDocument) purchasingForm.getDocument(); // changes done for BibEditor starts OlePurchaseOrderForm oleForm = (OlePurchaseOrderForm) form; PurchaseOrderDocument doc = (PurchaseOrderDocument) oleForm.getDocument(); Iterator itemIterator = doc.getItems().iterator(); int itemCounter = 0; while (itemIterator.hasNext()) { OlePurchaseOrderItem tempItem = (OlePurchaseOrderItem) itemIterator.next(); if (tempItem.getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_ITEM_CODE) || tempItem .getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_UNORDERED_ITEM_CODE)) { itemCounter++; } } String itemNo = String.valueOf(itemCounter); //String itemNo = String.valueOf(doc.getItems().size() - 4); HashMap<String, String> dataMap = new HashMap<String, String>(); BibInfoBean xmlBibInfoBean = new BibInfoBean(); if (purchaseOrderItem.getBibInfoBean() == null) { purchaseOrderItem.setBibInfoBean(xmlBibInfoBean); if (purchaseOrderItem.getBibInfoBean().getDocStoreOperation() == null) { purchaseOrderItem.getBibInfoBean().setDocStoreOperation(OleSelectConstant.DOCSTORE_OPERATION_STAFF); } } String fileName = document.getDocumentNumber() + "_" + itemNo; // Modified for jira OLE - 2437 starts setItemDescription(purchaseOrderItem, fileName); // purchaseOrderItem.setStartingCopyNumber(new KualiInteger(1)); // Modified for jira OLE - 2437 ends /* dataMap.put(OleSelectConstant.FILEPATH, fileProcessingService.getMarcXMLFileDirLocation()); dataMap.put(OleSelectConstant.FILENAME, fileName); if (fileProcessingService.isCreateFileExist(dataMap)) { isBibFileExist = true; } if (isBibFileExist) { titleId = docStore.getTitleIdByMarcXMLFileProcessing(purchaseOrderItem.getBibInfoBean(), dataMap); purchaseOrderItem.setItemTitleId(titleId); dataMap.put(OleSelectConstant.TITLE_ID, titleId); dataMap.put(OleSelectConstant.DOC_CATEGORY_TYPE, OleSelectConstant.DOC_CATEGORY_TYPE_ITEMLINKS); xmlBibInfoBean = docStore.getBibInfo(dataMap); purchaseOrderItem.setBibInfoBean(xmlBibInfoBean); purchasingForm.getNewPurchasingItemLine().setItemDescription((purchaseOrderItem.getBibInfoBean().getTitle() != null ? purchaseOrderItem.getBibInfoBean().getTitle() : "") + (purchaseOrderItem.getBibInfoBean().getAuthor() != null ? "," + purchaseOrderItem.getBibInfoBean().getAuthor() : "") + (purchaseOrderItem.getBibInfoBean().getPublisher() != null ? "," + purchaseOrderItem.getBibInfoBean().getPublisher() : "") + (purchaseOrderItem.getBibInfoBean().getIsbn() != null ? "," + purchaseOrderItem.getBibInfoBean().getIsbn() : "")); HashMap<String,String> queryMap = new HashMap<String,String>(); queryMap.put(OleSelectConstant.DocStoreDetails.ITEMLINKS_KEY, purchaseOrderItem.getItemTitleId()); List<DocInfoBean> docStoreResult = docStore.searchBibInfo(queryMap); Iterator bibIdIterator = docStoreResult.iterator(); if(bibIdIterator.hasNext()){ DocInfoBean docInfoBean = (DocInfoBean)bibIdIterator.next(); purchaseOrderItem.setBibUUID(docInfoBean.getUniqueId()); } }*/ // changes done for BibEditor ends if (document.getVendorDetail().getCurrencyType() != null) { if (document.getVendorDetail().getCurrencyType().getCurrencyType() .equalsIgnoreCase(OleSelectConstant.CURRENCY_TYPE_NAME)) { currencyTypeIndicator = true; } else { currencyTypeIndicator = false; } } boolean ruleFlag = getKualiRuleService() .applyRules(new OlePurchaseOrderDescEvent(document, purchaseOrderItem)); if (ruleFlag) { if ((document.getVendorDetail() == null) || (document.getVendorDetail().getVendorName() != null && currencyTypeIndicator)) { boolean rulePassed = getKualiRuleService() .applyRules(new DiscountPurchaseOrderEvent(document, purchaseOrderItem)); if (rulePassed) { purchasingForm.getNewPurchasingItemLine() .setItemUnitPrice(SpringContext.getBean(OlePurapService.class) .calculateDiscount(purchaseOrderItem).setScale(2, BigDecimal.ROUND_HALF_UP)); super.addItem(mapping, purchasingForm, request, response); } } else { boolean rulePassed = getKualiRuleService() .applyRules(new ForeignCurrencyPOEvent(document, purchaseOrderItem)); if (rulePassed) { LOG.debug("###########Foreign Currency Field additem for purchase Order ###########"); SpringContext.getBean(OlePurapService.class).calculateForeignCurrency(purchaseOrderItem); Long id = document.getVendorDetail().getCurrencyType().getCurrencyTypeId(); Map documentNumberMap = new HashMap(); documentNumberMap.put(OleSelectConstant.CURRENCY_TYPE_ID, id); BusinessObjectService businessObjectService = SpringContext .getBean(BusinessObjectService.class); List<OleExchangeRate> exchangeRateList = (List) businessObjectService.findMatchingOrderBy( OleExchangeRate.class, documentNumberMap, OleSelectConstant.EXCHANGE_RATE_DATE, false); Iterator iterator = exchangeRateList.iterator(); if (iterator.hasNext()) { OleExchangeRate tempOleExchangeRate = (OleExchangeRate) iterator.next(); purchaseOrderItem .setItemExchangeRate(new KualiDecimal(tempOleExchangeRate.getExchangeRate())); } if (purchaseOrderItem.getItemExchangeRate() != null && purchaseOrderItem.getItemForeignUnitCost() != null) { purchaseOrderItem.setItemUnitCostUSD( new KualiDecimal(purchaseOrderItem.getItemForeignUnitCost().bigDecimalValue() .divide(purchaseOrderItem.getItemExchangeRate().bigDecimalValue(), 4, RoundingMode.HALF_UP))); purchaseOrderItem.setItemUnitPrice(purchaseOrderItem.getItemUnitCostUSD().bigDecimalValue() .setScale(2, BigDecimal.ROUND_HALF_UP)); purchaseOrderItem.setItemListPrice(purchaseOrderItem.getItemUnitCostUSD()); } super.addItem(mapping, purchasingForm, request, response); } } } if (purchaseOrderItem.getClaimDate() == null) { VendorDetail vendorDetail = document.getVendorDetail(); if (vendorDetail != null) { String claimInterval = vendorDetail.getClaimInterval(); if (StringUtils.isNotBlank(claimInterval)) { Integer actIntvl = Integer.parseInt(claimInterval); purchaseOrderItem.setClaimDate( new java.sql.Date(DateUtils.addDays(new java.util.Date(), actIntvl).getTime())); } } } return mapping.findForward(OLEConstants.MAPPING_BASIC); }
From source file:org.kuali.ole.sys.batch.PurgeSessionDocumentsStep.java
/** * @see org.kuali.ole.sys.batch.Step#execute(java.lang.String, java.util.Date) *//*from ww w .ja va 2 s. co m*/ public boolean execute(String jobName, Date jobRunDate) { try { LOG.info("executing PurgeSessionDocumentsStep"); String maxAgeInDaysStr = parameterService.getParameterValueAsString(PurgeSessionDocumentsStep.class, OLEConstants.SystemGroupParameterNames.NUMBER_OF_DAYS_SINCE_LAST_UPDATE); int maxAgeInDays = Integer.parseInt(maxAgeInDaysStr); Timestamp expirationDate = new Timestamp( DateUtils.addDays(getDateTimeService().getCurrentDate(), -maxAgeInDays).getTime()); sessionDocumentService.purgeAllSessionDocuments(expirationDate); return true; } catch (Exception e) { LOG.error("error occured trying to purge session document from DB: ", e); } return false; }
From source file:org.mapbuilderfreq.FrequencyMapClient.java
public static void doAllProcessing(Date lastMapDate) { //Date today = new Date(); Date today = getSoonestDate(); Date nextDate = null;/*from ww w . j ava2 s .co m*/ boolean deleteLayerByLayer = true; if (lastMapDate == null) { nextDate = getEarliestDate(); //delete all old layers at once gsh.removeAllLayers(); //no need to delete again deleteLayerByLayer = false; } else { //nextDate = DateUtils.addDays(lastMapDate, 1); nextDate = lastMapDate; deleteLayerByLayer = true; } //Note: nextDate have no time component, therefore always nextDate > today even if they are referring to the same day while (nextDate.before(today)) { //process for the selected day List<MsgData> dayList = getMapDataForDate(nextDate, SCORE_TYPE, SCORE_THRESHOLD, ONLY_QUALIFIED); List<DataPoint> newList = new ArrayList<>(); if (!dayList.isEmpty()) { for (MsgData msgData : dayList) { //set the Lat, Lon point from the exact point, OR polygon OR user location float lon = msgData.Longitude; float lat = msgData.Latitude; String newOhioPlacePolygon = "POLYGON((-84.820309 38.403186,-84.820309 42.327133,-80.518626 42.327133,-80.518626 38.403186))"; //remove new Ohio place polygon for Ohio state, not it's diffrent if (msgData.PlacePolygon.equals(newOhioPlacePolygon)) { continue; } if (lon == 0 && lat == 0) { if (msgData.PlacePolygon != null && !msgData.PlacePolygon.isEmpty()) { Coordinate coordinate = GeoToolsHandler.getCentroid(msgData.PlacePolygon); lon = (float) coordinate.x; lat = (float) coordinate.y; } else { System.err.println("No Lat/Lon OR PlacePolygon data found, MsgId: " + msgData.MsgId); System.exit(0); } } //remove centroid for Ohio state if (lon == -82.66945f && lat == 40.365158f) { continue; } boolean pointAdded = false; for (int i = 0; i < newList.size(); i++) { DataPoint temp = newList.get(i); if (temp.Longitude == lon && temp.Latitude == lat) { temp.Score = temp.Score + 1; newList.set(i, temp); pointAdded = true; break; } } if (!pointAdded) { newList.add(new DataPoint(lon, lat, 1)); } } } else { //add no data points newList = getNoDataPointList(); } //genarte the map generateMap(nextDate, newList, deleteLayerByLayer); //increment the date nextDate = DateUtils.addDays(nextDate, 1); } if (nextDate.after(today)) { nextDate = DateUtils.addDays(nextDate, -1); } setLastMapDate(nextDate); }
From source file:org.mapbuilderfreq.FrequencyMapClient.java
public static List<MsgData> getMapDataForDate(Date mapDate, String scoreType, float scoreThreshold, boolean onlyQualified) { List<MsgData> msgList = new ArrayList<>(); //mapDate = DateUtils.addDays(mapDate, 1-NUM_DAYS_AGGREGATE);// add -(NUM_DAYS_AGGREGATE-1) days for (int i = 0; i < NUM_DAYS_AGGREGATE; i++) { List<MsgData> tempList = new ArrayList<>(); String lowerDate = DateFormatUtils.format(mapDate, "yyyy-MM-dd"); String upperDate = DateFormatUtils.format(DateUtils.addDays(mapDate, 1), "yyyy-MM-dd"); mapDate = DateUtils.addDays(mapDate, -1); float coefficient = (1 - (i * AGGREGATE_COEFFICIENT)); try {//www . j a v a 2s .co m String mapQuery = "SELECT \"Id\", \"Longitude\", \"Latitude\",\"PlacePolygon\",\"UserLocation\", \"NormalizedScore\", \"TagScore\", \"CombinedScore\" " + "FROM public.\"ScoredMsg\" WHERE \"CreatedTime\" < '" + upperDate + "' AND \"CreatedTime\" >= '" + lowerDate + "' "; String scoreClause = ""; switch (scoreType) { case "normal": scoreClause = "AND \"NormalizedScore\" >= " + scoreThreshold; break; case "tag": scoreClause = "AND \"TagScore\" >= " + scoreThreshold; break; case "combined": scoreClause = "AND \"CombinedScore\" >= " + scoreThreshold; break; } mapQuery = mapQuery + scoreClause; if (onlyQualified) { mapQuery = mapQuery + " AND \"IsQualified\" = true"; } mapQuery = mapQuery + ";"; Statement st = db.createStatement(); ResultSet rs = st.executeQuery(mapQuery); while (rs.next()) { MsgData d = new MsgData(); d.setMsgId(rs.getInt(1)); d.setLongitude(rs.getFloat(2)); d.setLatitude(rs.getFloat(3)); d.setPlacePolygon(rs.getString(4)); d.setUserLocation(rs.getString(5)); d.setNormalizedScore(rs.getFloat(6)); d.setTagScore(rs.getFloat(7)); d.setCombinedScore(rs.getFloat(8)); if (d.getNormalizedScore() <= 0) { d.setNormalizedScore(d.getNormalizedScore() * coefficient); } if (d.getTagScore() <= 0) { d.setTagScore(d.getTagScore() * coefficient); } if (d.getCombinedScore() <= 0) { d.setCombinedScore(d.getCombinedScore() * coefficient); } tempList.add(d); } } catch (SQLException ex) { System.err.println("Map Query failed...."); System.err.println(ex); System.exit(0); } msgList.addAll(tempList); } return msgList; }
From source file:org.motechproject.server.svc.impl.RegistrarBeanRecordOutpatientVistsTest.java
@Test @SkipBaseSetup/*from ww w .j a v a 2s . c o m*/ public void validateForDuplicateOPDVisitEntries() { MotechService motechService = Context.getService(MotechService.class); RegistrarBean registrarBean = motechService.getRegistrarBean(); OpenmrsBean openmrsBean = Mockito.mock(RegistrarBeanImpl.class); int facilityId = 11117; Date vistDate = new DateUtil().dateFor(15, 6, 2011); Date dob = new Date(); User staff = registrarBean.registerStaff("Nurse", "Betty", "7777777777", "CHO", null); staff.setSystemId("465"); when(openmrsBean.getStaffBySystemId("465")).thenReturn(staff); RegistrarWebService regService = new RegistrarWebService(); regService.setRegistrarBean(registrarBean); regService.setMessageBean((MessageSourceBean) applicationContext.getBean("messageSourceBean")); regService.setOpenmrsBean(openmrsBean); Gender sex = Gender.MALE; boolean insured = false; Integer diagnosis = 1; Integer secondDiagnosis = 2; boolean rdtGiven = true; boolean rdtPositive = true; boolean actTreated = true; boolean newCase = true; boolean newPatient = true; boolean referred = true; String comments = "comments for patient entry 1"; String serialNumber = "01/2011"; try { regService.recordGeneralVisit(Integer.parseInt(staff.getSystemId()), facilityId, vistDate, serialNumber, sex, dob, insured, diagnosis, secondDiagnosis, rdtGiven, rdtPositive, actTreated, newCase, newPatient, referred, comments); } catch (ValidationException e) { fail("Should not throw validation exception when registering a valid outpatient visit"); } try { regService.recordGeneralVisit(Integer.parseInt(staff.getSystemId()), facilityId, DateUtils.addDays(vistDate, 1), serialNumber, sex, dob, insured, diagnosis, secondDiagnosis, rdtGiven, rdtPositive, actTreated, newCase, newPatient, referred, comments); fail("should throw validation exception when a duplicate entry is registered"); } catch (ValidationException e) { String errorMessage = e.getFaultInfo().getErrors().get(0); assertEquals("OPDVistEntryForm=in error", errorMessage); } }
From source file:org.mule.module.fws.FWSTestDriver.java
@Test public void listUpdatedSupllyNoInventory() { assertFalse(connector.listUpdatedInventorySupply(DateUtils.addDays(new Date(), -10), null).iterator() .hasNext()); }