List of usage examples for org.apache.commons.lang.time DateUtils addMonths
public static Date addMonths(Date date, int amount)
From source file:org.apache.oozie.command.coord.TestAbandonedCoordChecker.java
public void testNoAbandoned() throws Exception { Date start = DateUtils.addMonths(new Date(), -1); Date end = DateUtils.addHours(new Date(), 4); // 4 hrs Date createdTime = start;//from w ww . j a v a2s . co m final CoordinatorJobBean job1 = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, createdTime, true, false, 6); addRecordToCoordActionTable(job1.getId(), 6, CoordinatorAction.Status.SUCCEEDED, CoordinatorAction.Status.FAILED); final CoordinatorJobBean job2 = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, start, end, createdTime, true, false, 6); addRecordToCoordActionTable(job2.getId(), 6, CoordinatorAction.Status.SUCCEEDED, CoordinatorAction.Status.FAILED); ExtendedAbandonedCoordCheckerRunnable coordChecked = new ExtendedAbandonedCoordCheckerRunnable(5); coordChecked.run(); assertNull(coordChecked.getMessage()); }
From source file:org.apache.oozie.command.coord.TestAbandonedCoordChecker.java
public void testMessage_withTimedout() throws Exception { Date start = DateUtils.addMonths(new Date(), -1); Date end = DateUtils.addHours(new Date(), 4); // 4 hrs Date createdTime = start;/*from w w w.j a v a 2 s. c o m*/ final CoordinatorJobBean job1 = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, createdTime, true, false, 12); addRecordToCoordActionTable(job1.getId(), 12, CoordinatorAction.Status.TIMEDOUT); final CoordinatorJobBean job2 = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, createdTime, true, false, 4); addRecordToCoordActionTable(job2.getId(), 4, CoordinatorAction.Status.TIMEDOUT); ExtendedAbandonedCoordCheckerRunnable coordChecked = new ExtendedAbandonedCoordCheckerRunnable(10); coordChecked.run(); String msg = coordChecked.getMessage(); assertTrue(msg.contains(job1.getId())); assertFalse(msg.contains(job2.getId())); }
From source file:org.apache.oozie.command.coord.TestAbandonedCoordChecker.java
public void testMessage_withMixedStatus() throws Exception { Date start = DateUtils.addMonths(new Date(), -1); Date end = DateUtils.addHours(new Date(), 4); // 4 hrs Date createdTime = start;//from ww w .j a v a 2s .c o m final CoordinatorJobBean job1 = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, createdTime, true, false, 5); addRecordToCoordActionTable(job1.getId(), 5, CoordinatorAction.Status.FAILED, CoordinatorAction.Status.SUSPENDED, CoordinatorAction.Status.TIMEDOUT); final CoordinatorJobBean job2 = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, createdTime, true, false, 5); addRecordToCoordActionTable(job2.getId(), 5, CoordinatorAction.Status.FAILED, CoordinatorAction.Status.SUSPENDED, CoordinatorAction.Status.TIMEDOUT); final CoordinatorJobBean job3 = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, start, end, createdTime, true, false, 5); addRecordToCoordActionTable(job3.getId(), 5, CoordinatorAction.Status.FAILED, CoordinatorAction.Status.SUSPENDED, CoordinatorAction.Status.TIMEDOUT); ExtendedAbandonedCoordCheckerRunnable coordChecked = new ExtendedAbandonedCoordCheckerRunnable(5); coordChecked.run(); String msg = coordChecked.getMessage(); assertTrue(msg.contains(job1.getId())); assertTrue(msg.contains(job2.getId())); assertFalse(msg.contains(job3.getId())); }
From source file:org.apache.oozie.command.coord.TestAbandonedCoordChecker.java
public void testKill() throws Exception { Date start = DateUtils.addMonths(new Date(), -1); Date end = DateUtils.addHours(new Date(), 4); // 4 hrs Date createdTime = start;//from w ww. j a va2 s .co m CoordinatorJobBean job1 = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, createdTime, true, false, 6); addRecordToCoordActionTable(job1.getId(), 6, CoordinatorAction.Status.FAILED); CoordinatorJobBean job2 = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, createdTime, true, false, 4); addRecordToCoordActionTable(job2.getId(), 4, CoordinatorAction.Status.FAILED); new AbandonedCoordCheckerRunnable(5, true).run(); assertEquals(CoordJobQueryExecutor.getInstance().get(CoordJobQuery.GET_COORD_JOB, job1.getId()).getStatus(), CoordinatorJob.Status.KILLED); assertEquals(CoordJobQueryExecutor.getInstance().get(CoordJobQuery.GET_COORD_JOB, job2.getId()).getStatus(), CoordinatorJob.Status.RUNNING); }
From source file:org.apache.oozie.command.coord.TestAbandonedCoordChecker.java
public void testCatchupJob() throws Exception { Date start = DateUtils.addMonths(new Date(), -1); Date end = DateUtils.addHours(new Date(), 4); // 4 hrs Date createdTime = DateUtils.addDays(new Date(), -1); CoordinatorJobBean job1 = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, createdTime, true, false, 6);//from w w w. java 2 s. c o m addRecordToCoordActionTable(job1.getId(), 6, CoordinatorAction.Status.FAILED); createdTime = DateUtils.addDays(new Date(), -3); CoordinatorJobBean job2 = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, createdTime, true, false, 4); addRecordToCoordActionTable(job2.getId(), 10, CoordinatorAction.Status.FAILED); new AbandonedCoordCheckerRunnable(5, true).run(); // Only one job should be running. assertEquals(CoordJobQueryExecutor.getInstance().get(CoordJobQuery.GET_COORD_JOB, job1.getId()).getStatus(), CoordinatorJob.Status.RUNNING); assertEquals(CoordJobQueryExecutor.getInstance().get(CoordJobQuery.GET_COORD_JOB, job2.getId()).getStatus(), CoordinatorJob.Status.KILLED); }
From source file:org.b3log.symphony.processor.AdminProcessor.java
/** * Shows admin orders./*from w w w . j a va 2 s. c o m*/ * * @param context the specified context * @param request the specified request * @param response the specified response * @throws Exception exception */ @RequestProcessing(value = "/admin/orders", method = HTTPRequestMethod.GET) @Before(adviceClass = { StopwatchStartAdvice.class, MallAdminCheck.class }) @After(adviceClass = { CSRFToken.class, StopwatchEndAdvice.class }) public void showOrders(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception { final AbstractFreeMarkerRenderer renderer = new SkinRenderer(); context.setRenderer(renderer); renderer.setTemplateName("admin/orders.ftl"); final Map<String, Object> dataModel = renderer.getDataModel(); String pageNumStr = request.getParameter("p"); if (Strings.isEmptyOrNull(pageNumStr) || !Strings.isNumeric(pageNumStr)) { pageNumStr = "1"; } final int pageNum = Integer.valueOf(pageNumStr); final int pageSize = Symphonys.PAGE_SIZE; final int windowSize = Symphonys.WINDOW_SIZE; final JSONObject requestJSONObject = new JSONObject(); requestJSONObject.put(Pagination.PAGINATION_CURRENT_PAGE_NUM, pageNum); requestJSONObject.put(Pagination.PAGINATION_PAGE_SIZE, pageSize); requestJSONObject.put(Pagination.PAGINATION_WINDOW_SIZE, windowSize); final String category = request.getParameter(Common.CATEGORY); if (!Strings.isEmptyOrNull(category)) { requestJSONObject.put(Order.ORDER_PRODUCT_CATEGORY, category); dataModel.put(Common.CATEGORY, category); } else { dataModel.put(Common.CATEGORY, ""); } final String status = request.getParameter(Common.STATUS); if (!Strings.isEmptyOrNull(status)) { requestJSONObject.put(Order.ORDER_STATUS, status); dataModel.put(Common.STATUS, status); } else { requestJSONObject.put(Order.ORDER_STATUS, Order.ORDER_STATUS_C_INIT); dataModel.put(Common.STATUS, String.valueOf(Order.ORDER_STATUS_C_INIT)); } final String from = request.getParameter(Common.FROM); if (!Strings.isEmptyOrNull(from)) { final Date date = DateUtils.parseDate(from, new String[] { "yyyy-MM-dd" }); requestJSONObject.put(Common.FROM, date.getTime()); dataModel.put(Common.FROM, DateFormatUtils.format(date, "yyyy-MM-dd")); } else { final Date date = DateUtils.addMonths(new Date(), -1); requestJSONObject.put(Common.FROM, date.getTime()); dataModel.put(Common.FROM, DateFormatUtils.format(date, "yyyy-MM-dd")); } final String to = request.getParameter(Common.TO); if (!Strings.isEmptyOrNull(to)) { final Date date = DateUtils.parseDate(to, new String[] { "yyyy-MM-dd" }); requestJSONObject.put(Common.TO, Times.getDayEndTime(date.getTime())); dataModel.put(Common.TO, DateFormatUtils.format(date, "yyyy-MM-dd")); } else { requestJSONObject.put(Common.TO, Times.getDayEndTime(System.currentTimeMillis())); dataModel.put(Common.TO, DateFormatUtils.format(new Date(), "yyyy-MM-dd")); } final Map<String, Class<?>> fields = new HashMap<String, Class<?>>(); fields.put(Keys.OBJECT_ID, String.class); fields.put(Order.ORDER_CONFIRM_TIME, Long.class); fields.put(Order.ORDER_CREATE_TIME, Long.class); fields.put(Order.ORDER_HANDLER_ID, String.class); fields.put(Order.ORDER_POINT, Integer.class); fields.put(Order.ORDER_PRICE, Double.class); fields.put(Order.ORDER_PRODUCT_NAME, String.class); fields.put(Order.ORDER_STATUS, Integer.class); fields.put(Order.ORDER_BUYER_ID, String.class); final JSONObject result = orderQueryService.getOrders(requestJSONObject, fields); dataModel.put(Order.ORDERS, CollectionUtils.jsonArrayToList(result.optJSONArray(Order.ORDERS))); final JSONObject pagination = result.optJSONObject(Pagination.PAGINATION); final int pageCount = pagination.optInt(Pagination.PAGINATION_PAGE_COUNT); final JSONArray pageNums = pagination.optJSONArray(Pagination.PAGINATION_PAGE_NUMS); dataModel.put(Pagination.PAGINATION_FIRST_PAGE_NUM, pageNums.opt(0)); dataModel.put(Pagination.PAGINATION_LAST_PAGE_NUM, pageNums.opt(pageNums.length() - 1)); dataModel.put(Pagination.PAGINATION_CURRENT_PAGE_NUM, pageNum); dataModel.put(Pagination.PAGINATION_PAGE_COUNT, pageCount); dataModel.put(Pagination.PAGINATION_PAGE_NUMS, CollectionUtils.jsonArrayToList(pageNums)); filler.fillHeaderAndFooter(request, response, dataModel); }
From source file:org.b3log.symphony.processor.StatisticProcessor.java
/** * Loads statistic data.//from w w w .j av a2 s .c om * * @param request the specified HTTP servlet request * @param response the specified HTTP servlet response * @param context the specified HTTP request context * @throws Exception exception */ @RequestProcessing(value = "/cron/stat", method = HTTPRequestMethod.GET) @Before(adviceClass = StopwatchStartAdvice.class) @After(adviceClass = StopwatchEndAdvice.class) public void loadStatData(final HttpServletRequest request, final HttpServletResponse response, final HTTPRequestContext context) throws Exception { final Date end = new Date(); final Date dayStart = DateUtils.addDays(end, -30); monthDays.clear(); userCnts.clear(); articleCnts.clear(); commentCnts.clear(); months.clear(); historyArticleCnts.clear(); historyCommentCnts.clear(); historyUserCnts.clear(); for (int i = 0; i < 31; i++) { final Date day = DateUtils.addDays(dayStart, i); monthDays.add(DateFormatUtils.format(day, "yyyy-MM-dd")); final int userCnt = userQueryService.getUserCntInDay(day); userCnts.add(userCnt); final int articleCnt = articleQueryService.getArticleCntInDay(day); articleCnts.add(articleCnt); final int commentCnt = commentQueryService.getCommentCntInDay(day); commentCnts.add(commentCnt); } final JSONObject firstAdmin = userQueryService.getAdmins().get(0); final long monthStartTime = Times.getMonthStartTime(firstAdmin.optLong(Keys.OBJECT_ID)); final Date monthStart = new Date(monthStartTime); int i = 1; while (true) { final Date month = DateUtils.addMonths(monthStart, i); if (month.after(end)) { break; } i++; months.add(DateFormatUtils.format(month, "yyyy-MM")); final int userCnt = userQueryService.getUserCntInMonth(month); historyUserCnts.add(userCnt); final int articleCnt = articleQueryService.getArticleCntInMonth(month); historyArticleCnts.add(articleCnt); final int commentCnt = commentQueryService.getCommentCntInMonth(month); historyCommentCnts.add(commentCnt); } }
From source file:org.gbif.portal.web.controller.dataset.DataProviderLogController.java
/** * Adds the drop down content.//w ww . j av a 2 s . c om * @param request * @param mav */ @SuppressWarnings("unchecked") private void addDropDownContent(HttpServletRequest request, ModelAndView mav) { //add today and a year from today Date today = new Date(System.currentTimeMillis()); mav.addObject("today", today); Date lastWeek = DateUtils.addDays(today, -6); mav.addObject("lastWeek", lastWeek); Date oneMonthAgo = DateUtils.addMonths(today, -1); mav.addObject("oneMonthAgo", oneMonthAgo); Date oneYearAgo = DateUtils.addYears(today, -1); mav.addObject("oneYearAgo", oneYearAgo); //add event enumerations Collection<LogEvent> logEvents = (Collection) LogEvent.getValueMap().values(); //split into 4 categories - Harvest, Extract, User and Other List<KeyValueDTO> harvestEvents = new ArrayList<KeyValueDTO>(); List<KeyValueDTO> extractEvents = new ArrayList<KeyValueDTO>(); List<KeyValueDTO> userEvents = new ArrayList<KeyValueDTO>(); List<KeyValueDTO> usageEvents = new ArrayList<KeyValueDTO>(); List<KeyValueDTO> otherEvents = new ArrayList<KeyValueDTO>(); Locale locale = RequestContextUtils.getLocale(request); for (LogEvent logEvent : logEvents) { String name = messageSource.getMessage(logEvent.getName(), null, logEvent.getName(), locale); KeyValueDTO keyValue = new KeyValueDTO(logEvent.getValue().toString(), name); if (logEvent.getValue() >= LogEvent.HARVEST_RANGE_START && logEvent.getValue() <= LogEvent.HARVEST_RANGE_END) harvestEvents.add(keyValue); else if (logEvent.getValue() >= LogEvent.EXTRACT_RANGE_START && logEvent.getValue() <= LogEvent.EXTRACT_RANGE_END) extractEvents.add(keyValue); else if (logEvent.getValue() >= LogEvent.USER_RANGE_START && logEvent.getValue() <= LogEvent.USER_RANGE_END) userEvents.add(keyValue); else if (logEvent.getValue() >= LogEvent.USAGE_RANGE_START && logEvent.getValue() <= LogEvent.USAGE_RANGE_END) usageEvents.add(keyValue); else otherEvents.add(keyValue); } //sort alphabetically Collections.sort(harvestEvents, new KeyValueDTO.ValueComparator()); Collections.sort(extractEvents, new KeyValueDTO.ValueComparator()); Collections.sort(userEvents, new KeyValueDTO.ValueComparator()); Collections.sort(otherEvents, new KeyValueDTO.ValueComparator()); if (!harvestEvents.isEmpty() && harvestEvents.size() > 1) { harvestEvents.add(0, new KeyValueDTO(allHarvestEventsRequestKey, messageSource.getMessage("harvestAll", null, "Harvest - all", locale))); } mav.addObject("harvestEvents", harvestEvents); if (!extractEvents.isEmpty() && extractEvents.size() > 1) { extractEvents.add(0, new KeyValueDTO(allExtractEventsRequestKey, messageSource.getMessage("extractAll", null, "Extract - all", locale))); extractEvents.add(1, new KeyValueDTO(allExtractIssuesEventsRequestKey, messageSource.getMessage("extractAllIssues", null, "Extract - all issues", locale))); } mav.addObject("extractEvents", extractEvents); if (!userEvents.isEmpty() && userEvents.size() > 1) { userEvents.add(0, new KeyValueDTO(allUserEventsRequestKey, messageSource.getMessage("userAll", null, "User - all", locale))); } mav.addObject("userEvents", userEvents); if (!usageEvents.isEmpty() && usageEvents.size() > 1) { usageEvents.add(0, new KeyValueDTO(allUsageEventsRequestKey, messageSource.getMessage("usageAll", null, "Usage - all", locale))); } mav.addObject("usageEvents", usageEvents); mav.addObject("otherEvents", otherEvents); }
From source file:org.gbif.portal.web.controller.occurrence.OccurrenceFilterWizardController.java
/** * @see org.springframework.web.servlet.mvc.Controller#handleRequest(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) *//*from ww w.ja v a 2 s.c om*/ public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { String filterId = request.getParameter("filterId"); String currValue = request.getParameter("currValue"); FilterDTO filterDTO = FilterUtils.getFilterById(filterMapWrapper.getFilters(), filterId); String viewName = filterDTO.getWizardView(); ModelAndView mav = new ModelAndView(viewName); mav.addObject("messageSource", messageSource); if (logger.isDebugEnabled()) { logger.debug("filter id:" + filterId); logger.debug("current value:" + currValue); logger.debug("wizard view name:" + viewName); } //check for bounding box filter if (filterId.equals(boundingBoxFilter.getId()) && StringUtils.isNotEmpty(currValue)) { LatLongBoundingBox llbb = BoundingBoxFilterHelper.getLatLongBoundingBox(currValue); if (llbb != null) mav.addObject("boundingBox", llbb); } //check for classification filter if (filterId.equals(classificationFilter.getId())) { DataProviderDTO dataProvider = dataResourceManager.getNubDataProvider(); List<BriefTaxonConceptDTO> concepts = null; if (StringUtils.isNotEmpty(currValue)) { concepts = taxonomyManager.getClassificationFor(currValue, false, null, true); List<BriefTaxonConceptDTO> childConcepts = taxonomyManager.getChildConceptsFor(currValue, true); BriefTaxonConceptDTO selectedConcept = taxonomyManager.getBriefTaxonConceptFor(currValue); taxonConceptUtils.organiseUnconfirmedNames(request, selectedConcept, concepts, childConcepts); mav.addObject("selectedConcept", selectedConcept); } else { // we always use the nub resource concepts = taxonomyManager.getRootTaxonConceptsForTaxonomy(null, "1"); } if (dataProvider != null) mav.addObject("dataProvider", dataProvider); if (concepts != null) mav.addObject("concepts", concepts); } //check for dataResource filter if (filterId.equals(dataResourceIdFilter.getId())) { List<KeyValueDTO> dataProviderList = dataResourceManager.getDataProviderList(); mav.addObject("dataProviders", dataProviderList); List<KeyValueDTO> resourceNetworkList = dataResourceManager.getResourceNetworkList(); mav.addObject("networks", resourceNetworkList); } //check for geoRegion filter if (filterId.equals(geoRegionFilter.getId())) { List<KeyValueDTO> countryList = geospatialManager.getCountryList(); mav.addObject("countries", countryList); } //check for occurrence date filter if (filterId.equals(occurrenceDateFilter.getId())) { Date today = new Date(System.currentTimeMillis()); mav.addObject("today", today); Date lastWeek = DateUtils.addDays(today, -6); mav.addObject("lastWeek", lastWeek); Date oneMonthAgo = DateUtils.addMonths(today, -1); mav.addObject("oneMonthAgo", oneMonthAgo); Date sixMonthsAgo = DateUtils.addMonths(today, -5); mav.addObject("sixMonthsAgo", sixMonthsAgo); Date oneYearAgo = DateUtils.addYears(today, -1); mav.addObject("oneYearAgo", oneYearAgo); Date fiveYearsAgo = DateUtils.addYears(today, -5); mav.addObject("fiveYearsAgo", fiveYearsAgo); Date tenYearsAgo = DateUtils.addYears(today, -10); mav.addObject("tenYearsAgo", tenYearsAgo); } //check for year range filter if (filterId.equals(yearRangeFilter.getId())) { Date today = new Date(System.currentTimeMillis()); Calendar calendar = GregorianCalendar.getInstance(); calendar.setTime(today); int thisYear = calendar.get(Calendar.YEAR); mav.addObject("thisYear", thisYear); } mav.addObject("filterId", filterId); return mav; }
From source file:org.motechproject.server.svc.impl.RegistrarBeanImplTest.java
public void testIsInvalid_IfTheOPDVisitEntryIsDuplicateInTheSameMonth() { Integer facilityId = 2;//from ww w. j av a 2s .c o m Date visitDate = new DateUtil().dateFor(15, 6, 2011); String serialNumber = "01/2010"; Gender sex = Gender.MALE; Date dob = new Date(); Integer diagnosis = 1; Boolean newCase = true; Date lastMonth = DateUtils.addMonths(visitDate, -1); GeneralOutpatientEncounter generalOutpatientEncounter = new GeneralOutpatientEncounter(); generalOutpatientEncounter.setVisitDate(lastMonth); expect(contextService.getMotechService()).andReturn(motechService); expect(motechService.getOutPatientVisitEntryBy(facilityId, serialNumber, sex, dob, newCase, diagnosis)) .andReturn(Arrays.asList(generalOutpatientEncounter)); replay(motechService, contextService); assertTrue(registrarBean.isValidOutPatientVisitEntry(facilityId, visitDate, serialNumber, sex, dob, newCase, diagnosis)); verify(motechService, contextService); }