List of usage examples for org.joda.time DateTime minusDays
public DateTime minusDays(int days)
From source file:org.apereo.portal.portlets.activity.ActivityController.java
License:Apache License
private List<SearchInfo> getPopularSearchTerms() { DateTime end = new DateTime(); DateTime begin = end.minusDays(1); final IEntityGroup everyone = GroupService.getRootGroup(IPerson.class); final AggregatedGroupMapping group = aggregatedGroupLookupDao.getGroupMapping(everyone.getKey()); List<SearchRequestAggregationImpl> aggregations = searchRequestAggregationDao.getAggregations(begin, end, AggregationInterval.FIVE_MINUTE, group); Map<String, SearchInfo> resultBuilder = new HashMap<String, SearchInfo>(); for (SearchRequestAggregationImpl aggregation : aggregations) { SearchInfo info = resultBuilder.get(aggregation.getSearchTerm()); if (info == null) { info = new SearchInfo(aggregation.getSearchTerm(), aggregation.getCount()); resultBuilder.put(aggregation.getSearchTerm(), info); } else {/*from w ww. j ava 2s .c o m*/ info.incrementCount(aggregation.getCount()); } } List<SearchInfo> results = new ArrayList<SearchInfo>(resultBuilder.values()); Collections.sort(results); Collections.reverse(results); return results.size() > 10 ? results.subList(0, 9) : results; }
From source file:org.apereo.portal.portlets.popular.PopularPortletsController.java
License:Apache License
private List<PortletUsage> buildEventCounts(Integer days, IPerson user, Locale locale) { final DateTime end = new DateTime(); final DateTime begin = end.minusDays(days); final IEntityGroup everyone = GroupService.getRootGroup(IPerson.class); final AggregatedGroupMapping group = aggregatedGroupLookupDao.getGroupMapping(everyone.getKey()); final List<PortletLayoutAggregation> aggregations = portletLayoutDao.getAggregationsForAllPortlets(begin, end, AGGREGATION_INTERVAL, group); final EntityIdentifier ei = user.getEntityIdentifier(); final AuthorizationService authService = AuthorizationService.instance(); final IAuthorizationPrincipal ap = authService.newPrincipal(ei.getKey(), ei.getType()); final Map<String, PortletUsage> resultBuilder = new HashMap<String, PortletUsage>(); for (final PortletLayoutAggregation aggregation : aggregations) { final AggregatedPortletMapping portlet = aggregation.getPortletMapping(); final String fname = portlet.getFname(); PortletUsage portletUsage = resultBuilder.get(fname); if (portletUsage == null) { final IPortletDefinition portletDefinition = this.portletDefinitionDao .getPortletDefinitionByFname(fname); if (portletDefinition == null || !ap.canSubscribe(portletDefinition.getPortletDefinitionId().getStringId())) { //Skip portlets that no longer exist or cannot be subscribed to continue; }// w ww . j a v a2 s . c om portletUsage = new PortletUsage(portletDefinition.getPortletDefinitionId().getLongId(), fname, portletDefinition.getTitle(locale.toString()), portletDefinition.getDescription(locale.toString())); resultBuilder.put(fname, portletUsage); } portletUsage.incrementCount(aggregation.getAddCount()); } final ArrayList<PortletUsage> results = new ArrayList<PortletUsage>(resultBuilder.values()); Collections.sort(results); return results; }
From source file:org.conqat.engine.bugzilla.lib.Bug.java
License:Apache License
/** Get milliseconds of an enumeration field that is holding a date. */ public long getMilliSeconds(EBugzillaField field) { // TODO (BH): Why variable here? long milliSeconds = 0; // TODO (BH): I would invert the condition and return/throw here to // reduce the nesting. if (fields.get(field) != null) { // TODO (BH): Why store value and overwrite in next line? You could // also move this outside of the if and use the variable in the if // expression. String bugzillaDate = StringUtils.EMPTY_STRING; bugzillaDate = fields.get(field); // TODO (BH): Make constants from these pattern Pattern todayPattern = Pattern.compile("[0-9]{2}:[0-9]{2}:[0-9]{2}"); Pattern lastWeekPattern = Pattern.compile("[A-Z][a-z][a-z] [0-9]{2}:[0-9]{2}"); Pattern anyDatePattern = Pattern.compile("[0-9]{4}-[0-9]{2}-[0-9]{2}"); // TODO (BH): Variables only used once. Inline? Matcher todayMatcher = todayPattern.matcher(bugzillaDate); Matcher lastWeekMatcher = lastWeekPattern.matcher(bugzillaDate); Matcher anyDateMatcher = anyDatePattern.matcher(bugzillaDate); if (anyDateMatcher.matches()) { // TODO (BH): Make this a constant? DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd"); // TODO (BH): Directly return? milliSeconds = dateTimeFormatter.parseDateTime(bugzillaDate).getMillis(); } else if (lastWeekMatcher.matches()) { DateTime lastWeekDate = new DateTime(Chronic.parse(bugzillaDate).getBeginCalendar().getTime()); // Since jchronic parses the Bugzilla format exactly seven days // to late, we need to subtract those 7 days. // TODO (BH): Directly return? milliSeconds = lastWeekDate.minusDays(7).getMillis(); } else if (todayMatcher.matches()) { DateTime todayDate = new DateTime(); // TODO (BH): Make this a constant? DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("HH:mm:ss"); DateTime fieldDate = dateTimeFormatter.parseDateTime(bugzillaDate); // TODO (BH): Directly return? milliSeconds = new DateTime(todayDate.getYear(), todayDate.getMonthOfYear(), todayDate.getDayOfMonth(), fieldDate.getHourOfDay(), fieldDate.getMinuteOfHour(), fieldDate.getSecondOfMinute()).getMillis(); } else {//from www.ja v a2s . c om // TODO (BH): I think this is not a good way of handling this // error as the argument might be valid, but the data is just // not good. Better use a checked exception, such as // ConQATException. throw new IllegalArgumentException("Field is not a Bugzilla date."); } } else { // TODO (BH): I think this is not a good way of handling this error // as the argument might be valid, but the data is just not present. // Better use a checked exception, such as ConQATException. throw new IllegalArgumentException("Argument is not a Bugzilla field."); } return milliSeconds; }
From source file:org.efaps.esjp.accounting.transaction.Action_Base.java
License:Apache License
/** * Eval action def4 incoming.// ww w . j a v a2s . c o m * * @param _parameter Parameter as passed by the eFaps API * @param _actionRelInst relation Instance * @return the incoming action def * @throws EFapsException on error */ protected IncomingActionDef evalActionDef4Incoming(final Parameter _parameter, final Instance _actionRelInst) throws EFapsException { final IncomingActionDef ret = getIncomingActionDef(_parameter); final PrintQuery print = new PrintQuery(_actionRelInst); final SelectBuilder selActionInst = SelectBuilder.get() .linkto(CIERP.ActionDefinition2DocumentAbstract.FromLinkAbstract).instance(); final SelectBuilder selDocInst = SelectBuilder.get() .linkto(CIERP.ActionDefinition2DocumentAbstract.ToLinkAbstract).instance(); final SelectBuilder selDocTypeInst = SelectBuilder.get() .linkto(CIERP.ActionDefinition2DocumentAbstract.ToLinkAbstract) .linkfrom(CIERP.Document2DocumentTypeAbstract.DocumentLinkAbstract) .linkto(CIERP.Document2DocumentTypeAbstract.DocumentTypeLinkAbstract).instance(); final SelectBuilder selDocDate = SelectBuilder.get() .linkto(CIERP.ActionDefinition2DocumentAbstract.ToLinkAbstract) .attribute(CIERP.DocumentAbstract.Date); print.addSelect(selActionInst, selDocInst, selDocTypeInst, selDocDate); print.addAttribute(CIERP.ActionDefinition2DocumentAbstract.Date); print.execute(); final DateTime acdDate = print.getAttribute(CIERP.ActionDefinition2DocumentAbstract.Date); if (acdDate != null) { ParameterUtil.setParameterValues(ret.getParameter(), "date", acdDate.toString()); } ret.setActionInst(print.<Instance>getSelect(selActionInst)); ret.setDocInst(print.<Instance>getSelect(selDocInst)); ret.setDocTypeInst(print.<Instance>getSelect(selDocTypeInst)); final QueryBuilder queryBldr = new QueryBuilder(CIAccounting.ActionDefinition2Case4IncomingAbstract); queryBldr.addWhereAttrEqValue(CIAccounting.ActionDefinition2Case4IncomingAbstract.FromLinkAbstract, ret.getActionInst()); final MultiPrintQuery multi = queryBldr.getPrint(); final SelectBuilder selCaseInst = SelectBuilder.get() .linkto(CIAccounting.ActionDefinition2Case4IncomingAbstract.ToLinkAbstract).instance(); final SelectBuilder selLabelInst = SelectBuilder.get() .linkto(CIAccounting.ActionDefinition2Case4IncomingAbstract.LabelLink).instance(); multi.addSelect(selCaseInst, selLabelInst); multi.addAttribute(CIAccounting.ActionDefinition2Case4IncomingAbstract.Config); multi.execute(); while (multi.next()) { final List<ActDef2Case4IncomingConfig> configs = multi .getAttribute(CIAccounting.ActionDefinition2Case4IncomingAbstract.Config); if (configs != null) { final Instance caseInst = multi.getSelect(selCaseInst); DateTime periodDate = null; if (multi.getInstanceList().size() > 1) { if (configs.contains(ActDef2Case4DocConfig.PERIOD4ACTIONDATE)) { periodDate = acdDate == null ? new DateTime() : acdDate; } else if (configs.contains(ActDef2Case4DocConfig.PERIOD4DOCDATE)) { periodDate = print.getSelect(selDocDate); } } final Instance periodInst = evalSelectedPeriod(_parameter, caseInst, periodDate); if (InstanceUtils.isValid(periodInst)) { boolean execute = true; // for pettyCash receipt evaluation if legal document or not if (ret.getDocInst().getType().isKindOf(CISales.PettyCashReceipt)) { if (ret.getDocTypeInst() == null) { execute = configs.contains(ActDef2Case4IncomingConfig.WITHOUTDOC); } else { execute = !configs.contains(ActDef2Case4IncomingConfig.WITHOUTDOC); } } else if (ret.getDocInst().getType().isKindOf(CISales.FundsToBeSettledReceipt)) { if (ret.getDocTypeInst() == null) { execute = configs.contains(ActDef2Case4IncomingConfig.WITHOUTDOC); } else { execute = !configs.contains(ActDef2Case4IncomingConfig.WITHOUTDOC); } } if (execute) { final Instance labelInst = multi.getSelect(selLabelInst); if (labelInst != null && labelInst.isValid()) { final List<Instance> labels = new Label().getLabelInst4Documents(_parameter, ret.getDocInst()); if (labels.contains(labelInst)) { ret.setConfigs(configs); ret.setCaseInst(caseInst); break; } } else { ret.setConfigs(configs); ret.setCaseInst(caseInst); } break; } } } } if (ret.getCaseInst() != null && ret.getCaseInst().isValid()) { ret.setExecute(true); if (ret.getConfigs().contains(ActDef2Case4IncomingConfig.PURCHASERECORD)) { final DateTime date = new DateTime(); final QueryBuilder prQueryBldr = new QueryBuilder(CIAccounting.PurchaseRecord); prQueryBldr.addWhereAttrLessValue(CIAccounting.PurchaseRecord.Date, date.plusDays(1)); prQueryBldr.addWhereAttrGreaterValue(CIAccounting.PurchaseRecord.DueDate, date.minusDays(1)); prQueryBldr.addWhereAttrEqValue(CIAccounting.PurchaseRecord.Status, Status.find(CIAccounting.PurchaseRecordStatus.Open)); final InstanceQuery prQuery = prQueryBldr.getQuery(); prQuery.execute(); if (prQuery.next()) { ParameterUtil.setParameterValues(ret.getParameter(), "purchaseRecord", prQuery.getCurrentValue().getOid()); } } if (ret.getConfigs().contains(ActDef2Case4IncomingConfig.TRANSACTION)) { ParameterUtil.setParameterValues(ret.getParameter(), "case", ret.getCaseInst().getOid()); ParameterUtil.setParameterValues(ret.getParameter(), "document", ret.getDocInst().getOid()); if (ret.getConfigs().contains(ActDef2Case4IncomingConfig.SUBJOURNAL)) { final QueryBuilder sjQueryBldr = new QueryBuilder(CIAccounting.Report2Case); sjQueryBldr.addWhereAttrEqValue(CIAccounting.Report2Case.ToLink, ret.getCaseInst()); final MultiPrintQuery sjMulti = sjQueryBldr.getPrint(); final SelectBuilder sel = new SelectBuilder().linkto(CIAccounting.Report2Case.FromLink).oid(); sjMulti.addSelect(sel); sjMulti.execute(); if (sjMulti.next()) { ParameterUtil.setParameterValues(ret.getParameter(), "subJournal", sjMulti.<String>getSelect(sel)); } } if (ret.getConfigs().contains(ActDef2Case4IncomingConfig.SETSTATUS)) { ParameterUtil.setParameterValues(ret.getParameter(), "archiveConfig", Integer.toString(ArchiveConfig.ARCHIVED.getInt())); } } } return ret; }
From source file:org.efaps.esjp.accounting.transaction.FieldValue_Base.java
License:Apache License
/** * @param _parameter Parameter as passed from the eFaps API * @return values for dropdown//from w ww . jav a2 s . com * @throws EFapsException on error */ public Return getPurchaseRecordFieldValue(final Parameter _parameter) throws EFapsException { final Field field = new Field() { @Override protected void add2QueryBuilder4List(final Parameter _parameter, final QueryBuilder _queryBldr) throws EFapsException { final DateTime[] dates = getDateMaxMin(_parameter); _queryBldr.addWhereAttrGreaterValue(CIAccounting.PurchaseRecord.Date, dates[0].minusDays(1)); } @Override protected void updatePositionList(final Parameter _parameter, final List<DropDownPosition> _values) throws EFapsException { super.updatePositionList(_parameter, _values); boolean select = true; final List<Instance> docInsts = getSelectedDocInst(_parameter); if (!docInsts.isEmpty()) { final QueryBuilder dtQueryBldr = new QueryBuilder(CISales.Document2DocumentType); dtQueryBldr.addWhereAttrEqValue(CISales.Document2DocumentType.DocumentLink, docInsts.toArray()); final MultiPrintQuery multi = dtQueryBldr.getPrint(); final SelectBuilder docTypeSel = new SelectBuilder() .linkto(CISales.Document2DocumentType.DocumentTypeLink) .attribute(CIERP.DocumentType.Configuration); multi.addSelect(docTypeSel); multi.executeWithoutAccessCheck(); while (multi.next()) { final List<DocTypeConfiguration> configs = multi.getSelect(docTypeSel); if (configs == null || configs != null && !configs.contains(DocTypeConfiguration.PURCHASERECORD)) { select = false; break; } } } if (select) { final DateTime date = new DateTime(); final QueryBuilder queryBldr = new QueryBuilder(CIAccounting.PurchaseRecord); queryBldr.addWhereAttrLessValue(CIAccounting.PurchaseRecord.Date, date.plusDays(1)); queryBldr.addWhereAttrGreaterValue(CIAccounting.PurchaseRecord.DueDate, date.minusDays(1)); queryBldr.addOrderByAttributeAsc(CIAccounting.PurchaseRecord.Date); final InstanceQuery query = queryBldr.getQuery(); boolean selected = false; for (final Instance inst : query.executeWithoutAccessCheck()) { for (final DropDownPosition dd : _values) { if (inst.getOid().equals(dd.getValue())) { dd.setSelected(true); selected = true; break; } } if (selected) { break; } } } } }; return field.getOptionListFieldValue(_parameter); }
From source file:org.efaps.esjp.bpm.listener.PotentialOwnerListener_Base.java
License:Apache License
@Override public Return execute(final Parameter _parameter) throws EFapsException { final Return ret = new Return(); final List<?> owners = (List<?>) _parameter.get(ParameterValues.BPM_VALUES); if (!owners.isEmpty()) { final List<String> uuids = new ArrayList<String>(); final List<AbstractUserObject> newOwners = new ArrayList<AbstractUserObject>(); for (final Object owner : owners) { newOwners.add((AbstractUserObject) owner); uuids.add(((AbstractUserObject) owner).getUUID().toString()); }//from w ww. j a v a 2s. c o m final DateTime date = new DateMidnight().toDateTime(); final QueryBuilder queryBldr = new QueryBuilder(CIBPM.DelegateAutomaticAbstract); queryBldr.addWhereAttrEqValue(CIBPM.DelegateAutomaticAbstract.FromUserUUID, uuids.toArray()); queryBldr.addWhereAttrGreaterValue(CIBPM.DelegateAutomaticAbstract.ValidFrom, date.minusDays(1).minusSeconds(1)); queryBldr.addWhereAttrLessValue(CIBPM.DelegateAutomaticAbstract.ValidUntil, date.plusDays(1).plusSeconds(1)); final CachedMultiPrintQuery multi = queryBldr.getCachedPrint(BPM.CACHEKEY4DELEGATE).setLifespan(8) .setLifespanUnit(TimeUnit.HOURS); multi.addAttribute(CIBPM.DelegateAutomaticAbstract.ToUserUUID, CIBPM.DelegateAutomaticAbstract.ValidFrom, CIBPM.DelegateAutomaticAbstract.ValidUntil); multi.executeWithoutAccessCheck(); while (multi.next()) { final DateTime validFrom = multi.<DateTime>getAttribute(CIBPM.DelegateAutomaticAbstract.ValidFrom); final DateTime validUntil = multi .<DateTime>getAttribute(CIBPM.DelegateAutomaticAbstract.ValidUntil); if (validFrom.toLocalDateTime().isBefore(new LocalDateTime()) && validUntil.toLocalDateTime().isAfter(new LocalDateTime())) { final String tuUserUUID = multi .<String>getAttribute(CIBPM.DelegateAutomaticAbstract.ToUserUUID); newOwners.add(AbstractUserObject.getUserObject(UUID.fromString(tuUserUUID))); } } ret.put(ReturnValues.VALUES, newOwners); } return ret; }
From source file:org.efaps.esjp.common.uitable.MultiPrint_Base.java
License:Apache License
/** * @param _field Field the date is wanted for * @return datetime array/*w ww.j a v a 2s .co m*/ * @throws EFapsException on error */ protected Object[] getFilter(final Field _field) throws EFapsException { Object[] ret = null; final String filter = _field.getFilter().getDefaultValue(); if (filter != null) { final String[] parts = filter.split(":"); final String range = parts[0]; final int fromSub = parts.length > 1 ? Integer.parseInt(parts[1]) : 0; final int rangeCount = parts.length > 2 ? Integer.parseInt(parts[2]) : 1; DateTime dateFrom = new DateTime(); DateTime dateTo = new DateTime(); if (range != null) { final FilterDefault def = FilterDefault.valueOf(range.toUpperCase()); // to get a timezone dependent DateTim DateTime tmp = DateTimeUtil.translateFromUI(new DateTime()).withTimeAtStartOfDay(); switch (def) { case TODAY: dateFrom = tmp.toDateTime().minusDays(fromSub).minusMinutes(1); dateTo = dateFrom.plusDays(rangeCount).plusSeconds(1); ret = new DateTime[] { dateFrom, dateTo }; break; case WEEK: // the first of the current week tmp = tmp.minusDays(tmp.getDayOfWeek() - 1); dateFrom = tmp.minusWeeks(fromSub).minusMinutes(1); dateTo = tmp.plusWeeks(rangeCount); ret = new DateTime[] { dateFrom, dateTo }; break; case MONTH: // the first of the current month tmp = tmp.minusDays(tmp.getDayOfMonth() - 1); // substract the month and a minute before dateFrom = tmp.minusMonths(fromSub).minusMinutes(1); // add the month dateTo = tmp.plusMonths(rangeCount); ret = new DateTime[] { dateFrom, dateTo }; break; case YEAR: tmp = tmp.minusDays(tmp.getDayOfYear() - 1); dateFrom = tmp.minusYears(fromSub).minusMinutes(1); dateTo = tmp.plusYears(rangeCount); ret = new DateTime[] { dateFrom, dateTo }; break; case ALL: ret = new String[] { "*" }; break; case NONE: break; default: ret = new String[] { range + "*" }; break; } } } return ret; }
From source file:org.egov.pgr.dashboard.repository.DashboardRepository.java
License:Open Source License
public List<Object[]> fetchWardwisePerformanceTill(final DateTime toDate) { final SQLQuery qry = getQuery("pgr.wardwiseperformance"); qry.setParameter("thirteenDaysBefore", endOfGivenDate(toDate.minusDays(13)).toDate()); qry.setParameter("fourteenDaysBefore", startOfGivenDate(toDate.minusDays(14)).toDate()); qry.setParameter("currentDate", endOfGivenDate(toDate).toDate()); return qry.list(); }
From source file:org.egov.pgr.dashboard.repository.DashboardRepository.java
License:Open Source License
public Object[] fetchComplaintAgeing(final String querykey, final String wardName) { final SQLQuery qry = getQuery(querykey); final DateTime currentDate = new DateTime(); qry.setParameter("grtthn90", endOfGivenDate(currentDate.minusDays(90)).toDate()); qry.setParameter("lsthn90", endOfGivenDate(currentDate.minusDays(90)).toDate()); qry.setParameter("grtthn45", endOfGivenDate(currentDate.minusDays(45)).toDate()); qry.setParameter("grtthn15", endOfGivenDate(currentDate.minusDays(15)).toDate()); qry.setParameter("lsthn45", endOfGivenDate(currentDate.minusDays(45)).toDate()); qry.setParameter("lsthn15", endOfGivenDate(currentDate.minusDays(15)).toDate()); qry.setParameter("currdate", endOfGivenDate(currentDate).toDate()); if (wardName != null) qry.setParameter("wardName", wardName); return (Object[]) qry.uniqueResult(); }
From source file:org.egov.pgr.dashboard.service.DashboardService.java
License:Open Source License
public Collection<Integer> getComplaintRegistrationTrend() { DateTime currentDate = new DateTime(); Map<String, Integer> currentYearTillDays = constructDatePlaceHolder(currentDate.minusDays(6), currentDate, "MM-dd"); for (Object[] compDtl : dashboardRepository.fetchComplaintRegistrationTrendBetween( startOfGivenDate(currentDate.minusDays(6)).toDate(), endOfGivenDate(currentDate).toDate())) currentYearTillDays.put(String.valueOf(compDtl[0]), Integer.valueOf(String.valueOf(compDtl[1]))); return currentYearTillDays.values(); }