List of usage examples for org.joda.time DateTime plusDays
public DateTime plusDays(int days)
From source file:org.nekorp.workflow.backend.service.imp.ServicioMetadataFactoryImp.java
License:Apache License
@Override public ServicioMetadata calcularMetadata(Servicio servicio, List<Evento> eventos) { ServicioMetadata respuesta = new ServicioMetadata(); if (eventos == null) { eventos = new LinkedList<Evento>(); }// w w w. j a v a2s . co m Evento eventoInicio = null; Evento eventoEntradaAuto = null; Evento eventoSalidaAuto = null; Evento eventoCancelar = null; Evento eventoTermino = null; for (Evento x : eventos) { if (x.getEtiqueta().equals(EventoConstants.inicioServicio) && eventoInicio == null) { eventoInicio = x; respuesta.setFechaInicio(x.getFechaCreacion()); } if (x.getEtiqueta().equals(EventoConstants.entradaAuto) && eventoEntradaAuto == null) { eventoEntradaAuto = x; } if (x.getEtiqueta().equals(EventoConstants.salidaAuto) && eventoSalidaAuto == null) { eventoSalidaAuto = x; } if (x.getEtiqueta().equals(EventoConstants.cancelacion) && eventoCancelar == null) { eventoCancelar = x; } if (x.getEtiqueta().equals(EventoConstants.terminoServicio) && eventoTermino == null) { eventoTermino = x; } } if (eventoCancelar != null) { respuesta.setStatus(ServicioStatusConstants.cancelado); } if (eventoTermino != null && StringUtils.isEmpty(respuesta.getStatus())) { respuesta.setStatus(ServicioStatusConstants.terminado); } if (eventoSalidaAuto != null && StringUtils.isEmpty(respuesta.getStatus())) { DateTime fechaEntrega = new DateTime(eventoSalidaAuto.getFecha()); DateTime fechaCaducidad = fechaEntrega.plusDays(diasMaxCierre); if (fechaCaducidad.isBeforeNow()) { respuesta.setStatus(ServicioStatusConstants.sinCerrar); } } if (eventoEntradaAuto != null && StringUtils.isEmpty(respuesta.getStatus())) { respuesta.setStatus(ServicioStatusConstants.activo); } if (eventoInicio != null && StringUtils.isEmpty(respuesta.getStatus())) { DateTime fechaInicio = new DateTime(respuesta.getFechaInicio()); DateTime fechaCaducidad = fechaInicio.plusDays(diasCaducidad); if (fechaCaducidad.isBeforeNow()) { respuesta.setStatus(ServicioStatusConstants.vencido); } else { respuesta.setStatus(ServicioStatusConstants.activo); } } return respuesta; }
From source file:org.nekorp.workflow.desktop.servicio.imp.CobranzaMetadataCalculatorImp.java
License:Apache License
private void calculaWanrLevel(String status, MonedaVB saldo, CobranzaMetadata cobranzaMetadata, DatosCobranzaVB cobranza) {//from w w w . j a v a 2s . c o m CobranzaWarningLevel warningLevel = CobranzaWarningLevel.info; if (saldo.doubleValue() <= 0 || status.compareTo("Terminado") == 0) { cobranzaMetadata.setWarningLevel(warningLevel); cobranzaMetadata.setDiasUltimoPago(0); return; } DateTime ultimoPago = new DateTime(cobranza.getInicio()); for (PagoCobranzaVB pago : cobranza.getPagos()) { DateTime fechaPago = new DateTime(pago.getFecha()); if (ultimoPago.isBefore(fechaPago)) { ultimoPago = fechaPago; } } if (ultimoPago.plusDays(diasWarn).isBeforeNow()) { warningLevel = CobranzaWarningLevel.warn; } if (ultimoPago.plusDays(diasUrgent).isBeforeNow()) { warningLevel = CobranzaWarningLevel.urgent; } int dias = Days.daysBetween(ultimoPago.toLocalDate(), DateTime.now().toLocalDate()).getDays(); cobranzaMetadata.setDiasUltimoPago(dias); cobranzaMetadata.setWarningLevel(warningLevel); }
From source file:org.nfsdb.examples.iterate.IntervalExample.java
License:Apache License
public static void main(String[] args) throws JournalException { if (args.length != 1) { System.out.println("Usage: " + IntervalExample.class.getName() + " <path>"); System.exit(1);/*from www.j a v a 2 s.co m*/ } String journalLocation = args[0]; try (JournalFactory factory = new JournalFactory(new JournalConfigurationBuilder() { { $(Quote.class).recordCountHint(5000000) // hint that journal is going to be big .partitionBy(PartitionType.MONTH) // partition by MONTH .$ts() // tell factory that Quote has "timestamp" column. If column is called differently you can pass its name ; } }.build(journalLocation))) { // delete existing quote journal Files.delete(new File(factory.getConfiguration().getJournalBase(), Quote.class.getName())); // get some data in :) try (JournalWriter<Quote> w = factory.bulkWriter(Quote.class)) { QuoteGenerator.generateQuoteData(w, 10000000, 90); } // basic iteration try (Journal<Quote> journal = factory.reader(Quote.class)) { int count = 0; long t = System.nanoTime(); DateTime lo = Dates.utc().plusDays(10); DateTime hi = lo.plusDays(10); // iterate the interval between lo and hi millis. for (Quote q : journal.query().all().iterator(Dates.interval(lo, hi))) { assert q != null; count++; } System.out.println("Iterator read " + count + " quotes in " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - t) + "ms."); } } }
From source file:org.nfsdb.examples.query.QueryBuilderExample.java
License:Apache License
public static void main(String[] args) throws JournalException { if (args.length != 1) { System.out.println("Usage: " + QueryBuilderExample.class.getName() + " <path>"); System.exit(1);// w w w . j av a2s . c o m } String journalLocation = args[0]; try (JournalFactory factory = new JournalFactory(ModelConfiguration.CONFIG.build(journalLocation))) { // delete existing quote journal Files.delete(new File(factory.getConfiguration().getJournalBase(), "quote")); int count = 1000000; long t = System.nanoTime(); // get some data in :) try (JournalWriter<Quote> w = factory.bulkWriter(Quote.class)) { QuoteGenerator.generateQuoteData(w, count, 90); } System.out.println("Created " + count + " records in " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - t) + "ms"); try (Journal<Quote> journal = factory.reader(Quote.class)) { count = 0; t = System.nanoTime(); // create query builder to search for all records with key (sym) = "BP.L" QueryAllBuilder<Quote> builder = journal.query().all().withKeys("BP.L"); // execute query and consume result set for (Quote q : builder.asResultSet().bufferedIterator()) { assert q != null; count++; } System.out.println("Full read " + count + " records in " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - t) + "ms"); // // reuse builder to narrow down query interval // DateTime lo = Dates.utc().plusDays(10); DateTime hi = lo.plusDays(10); t = System.nanoTime(); count = 0; for (Quote q : builder.slice(Dates.interval(lo, hi)).asResultSet().bufferedIterator()) { assert q != null; count++; } System.out.println("Interval read " + count + " records in " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - t) + "ms"); } } }
From source file:org.nuxeo.ecm.core.repository.jcr.XPathBuilder.java
License:Open Source License
/** * Process special expressions.//from w ww .j a v a 2 s . c om * <p> * If the expression is not a special one, return false so that the * expression will be processed in the default way. Otherwise process it and * return true. */ private boolean specialExpression(Expression expr) throws QueryException { if (expr.lvalue instanceof Reference) { // TODO remove this String name = ((Reference) expr.lvalue).name; if (name.equals(NXQL.ECM_FULLTEXT)) { if (expr.rvalue.getClass() != StringLiteral.class) { throw new QueryException( "Invalid query: " + NXQL.ECM_FULLTEXT + " can only be compared against string values"); } xq.predicate.append("jcr:contains(., '").append(((StringLiteral) expr.rvalue).value).append("')"); return true; } else if (name.equals(NXQL.ECM_NAME)) { if (expr.rvalue.getClass() != StringLiteral.class) { throw new QueryException( "Invalid query: " + NXQL.ECM_NAME + "can only be compared against string values"); } xq.predicate.append("fn:name() ").append(operator(expr.operator)).append(" '") .append(((StringLiteral) expr.rvalue).value).append("'"); return true; } else if (name.equals(NXQL.ECM_MIXINTYPE)) { if (expr.operator.equals(Operator.NOTEQ)) { LiteralList rvalue = new LiteralList(); rvalue.add((Literal) expr.rvalue); xq.predicate.append(" not("); inclusion(xq.predicate, expr.lvalue, rvalue); xq.predicate.append(") "); return true; } } else if (expr.rvalue.getClass() == DateLiteral.class) { // dates // *[@dc:created > "2008-06-03T00:00:00.000+01:00" and // @dc:created < xs:dateTime("2008-06-04T00:00:00.000+01:00")] // xs:date seems to not be correctly handled in jackrabbit . // see // https://issues.apache.org/jira/browse/JCR-1386?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel DateLiteral dl = (DateLiteral) expr.rvalue; Reference ref = (Reference) expr.lvalue; if (dl.onlyDate) { if (expr.operator == Operator.EQ) { DateTime d0 = dl.value; DateTime d1 = d0.plusDays(1); int month = d0.getMonthOfYear(); int day = d0.getDayOfMonth(); xq.predicate.append("("); reference(xq.predicate, ref); xq.predicate.append(" >= xs:dateTime('").append(d0.getYear()).append("-"); if (month < 10) { xq.predicate.append("0").append(month); } else { xq.predicate.append(month); } xq.predicate.append("-"); if (day < 10) { xq.predicate.append("0").append(day); } else { xq.predicate.append(day); } xq.predicate.append("T00:00:00.000Z') and "); month = d1.getMonthOfYear(); day = d1.getDayOfMonth(); reference(xq.predicate, ref); xq.predicate.append(" < xs:dateTime('").append(d1.getYear()).append("-"); if (month < 10) { xq.predicate.append("0").append(month); } else { xq.predicate.append(month); } xq.predicate.append("-"); if (day < 10) { xq.predicate.append("0").append(day); } else { xq.predicate.append(day); } xq.predicate.append("T00:00:00.000Z'))"); } else if (expr.operator == Operator.GTEQ) { DateTime date = dl.value; compareDate(xq.predicate, ref, expr.operator, date); } else if (expr.operator == Operator.GT) { DateTime date = dl.value.plusDays(1); compareDate(xq.predicate, ref, Operator.GTEQ, date); } else if (expr.operator == Operator.LT) { DateTime date = dl.value; compareDate(xq.predicate, ref, expr.operator, date); } else if (expr.operator == Operator.LTEQ) { DateTime date = dl.value.plusDays(1); compareDate(xq.predicate, ref, Operator.LT, date); } } else { reference(xq.predicate, ref); operator(xq.predicate, expr.operator); xq.predicate.append("xs:dateTime('" + DateLiteral.dateTime(dl) + "')"); } return true; } } return false; }
From source file:org.nuxeo.elasticsearch.aggregate.DateHelper.java
License:Apache License
private static DateTime plusDurationAsExpression(DateTime origin, String duration) { int k = getFactor(duration); switch (duration.substring(duration.length() - 1, duration.length())) { case "s": return origin.plusSeconds(k); case "m": return origin.plusMinutes(k); case "h": return origin.plusHours(k); case "d": return origin.plusDays(k); case "w": return origin.plusWeeks(k); case "M": return origin.plusMonths(k); case "y": return origin.plusYears(k); }//from w w w.ja va 2 s . c o m return invalid(duration); }
From source file:org.nuxeo.elasticsearch.aggregate.DateHelper.java
License:Apache License
private static DateTime plusDurationAsNoun(DateTime origin, String duration) { switch (duration.toLowerCase()) { case "second": return origin.plusSeconds(1); case "minute": return origin.plusMinutes(1); case "hour": return origin.plusHours(1); case "day": return origin.plusDays(1); case "week": return origin.plusWeeks(1); case "month": return origin.plusMonths(1); case "quarter": return origin.plusMonths(3); case "year": return origin.plusYears(1); }/*from w ww . j ava 2s . c o m*/ return invalid(duration); }
From source file:org.obm.imap.archive.services.SchedulingDatesService.java
License:Open Source License
private DateTime dailyNextTreatmentDate(DateTime currentDateTime, DateTime currentDateWithScheduledTime) { if (currentDateWithScheduledTime.isAfter(currentDateTime)) { return currentDateWithScheduledTime; }/*from ww w .j ava 2s .c om*/ return currentDateWithScheduledTime.plusDays(1); }
From source file:org.ohmage.request.event.EventReadRequest.java
License:Apache License
/** * Creates an Event read request./*from w ww . j a va2s .c om*/ * * @param httpRequest The HttpServletRequest with the parameters for this * request. * * @throws InvalidRequestException Thrown if the parameters cannot be * parsed. * * @throws IOException There was an error reading from the request. */ public EventReadRequest(HttpServletRequest httpRequest) throws IOException, InvalidRequestException { super(httpRequest, null); LOGGER.info("Creating an Event read request."); String tUsername = null; DateTime tStartDate = null; StreamReadRequest tRegularReadRequest = null; StreamReadRequest tExtendedReadRequest = null; Collection<ColumnKey> tColumns = null; if (!isFailed()) { try { String[] t; getParameters().keySet().size(); t = getParameterValues(InputKeys.DATE); if (t.length == 0) { throw new ValidationException(ErrorCode.SERVER_INVALID_DATE, "The date value is missing: " + InputKeys.DATE); } else if (t.length == 1) { tStartDate = MobilityValidators.validateDate(t[0]); if (tStartDate == null) { throw new ValidationException(ErrorCode.SERVER_INVALID_DATE, "The date value is missing: " + InputKeys.DATE); } else { tStartDate = new DateTime(tStartDate.getYear(), tStartDate.getMonthOfYear(), tStartDate.getDayOfMonth(), 0, 0, DateTimeZone.UTC); } } else { throw new ValidationException(ErrorCode.SERVER_INVALID_DATE, "Multiple date values were given: " + InputKeys.DATE); } // tColumns = null; // // // t = getParameterValues(InputKeys.MOBILITY_WITH_SENSOR_DATA); // if(t.length > 1) { // throw new ValidationException( // ErrorCode.MOBILITY_INVALID_INCLUDE_SENSOR_DATA_VALUE, // "Multiple \"include sensor data\" values to query were given: " + // InputKeys.MOBILITY_WITH_SENSOR_DATA); // } // else if(t.length == 1) { // if(MobilityValidators.validateIncludeSensorDataValue(t[0])) { // tColumns = MobilityColumnKey.ALL_COLUMNS; // } // } // // t = getParameterValues(InputKeys.COLUMN_LIST); // if(t.length > 1) { // throw new ValidationException( // ErrorCode.MOBILITY_INVALID_COLUMN_LIST, // "Multiple column lists were given: " + // InputKeys.COLUMN_LIST); // } // else if(t.length == 1) { // if(! StringUtils.isEmptyOrWhitespaceOnly(t[0])) { // if(tColumns == null) { // tColumns = // MobilityValidators.validateColumns( // t[0], // true); // } // else { // throw new ValidationException( // ErrorCode.MOBILITY_INVALID_COLUMN_LIST, // "Both '" + // InputKeys.MOBILITY_WITH_SENSOR_DATA + // "' and '" + // InputKeys.COLUMN_LIST + // "' were present. Only one may be present."); // } // } // } // if(tColumns == null) { // tColumns = DEFAULT_COLUMNS; // } // Get the user. t = getParameterValues(InputKeys.USERNAME); if (t.length > 1) { throw new ValidationException(ErrorCode.USER_INVALID_USERNAME, "Multiple usernames to query were given: " + InputKeys.USERNAME); } else if (t.length == 1) { tUsername = UserValidators.validateUsername(t[0]); } // TODO forget all that stream nonsense, just call .NET from here // Always get all of the columns. try { tRegularReadRequest = new StreamReadRequest(httpRequest, getParameterMap(), false, TokenLocation.EITHER, false, tUsername, "edu.ucla.cens.Mobility", null, "regular", 2012050700, tStartDate.minusMinutes(10), tStartDate.plusDays(1), null, true, null, null); tExtendedReadRequest = new StreamReadRequest(httpRequest, getParameterMap(), false, TokenLocation.EITHER, false, tUsername, "edu.ucla.cens.Mobility", null, "extended", 2012050700, tStartDate.minusMinutes(10), tStartDate.plusDays(1), null, true, null, null); } catch (IllegalArgumentException e) { throw new ValidationException("There was an error creating the request.", e); } } catch (ValidationException e) { e.failRequest(this); e.logException(LOGGER); } } username = tUsername; startDate = tStartDate; regularReadRequest = tRegularReadRequest; extendedReadRequest = tExtendedReadRequest; columns = tColumns; points = new ArrayList<MobilityPoint>(); }
From source file:org.ohmage.request.mobility.MobilityReadRequest.java
License:Apache License
/** * Creates a Mobility read request.// w w w. ja va2s. c o m * * @param httpRequest The HttpServletRequest with the parameters for this * request. * * @throws InvalidRequestException Thrown if the parameters cannot be * parsed. * * @throws IOException There was an error reading from the request. */ public MobilityReadRequest(HttpServletRequest httpRequest) throws IOException, InvalidRequestException { super(httpRequest, null); LOGGER.info("Creating a Mobility read request."); String tUsername = null; DateTime tStartDate = null; StreamReadRequest tRegularReadRequest = null; StreamReadRequest tExtendedReadRequest = null; Collection<ColumnKey> tColumns = null; if (!isFailed()) { try { String[] t; t = getParameterValues(InputKeys.DATE); if (t.length == 0) { throw new ValidationException(ErrorCode.SERVER_INVALID_DATE, "The date value is missing: " + InputKeys.DATE); } else if (t.length == 1) { tStartDate = MobilityValidators.validateDate(t[0]); if (tStartDate == null) { throw new ValidationException(ErrorCode.SERVER_INVALID_DATE, "The date value is missing: " + InputKeys.DATE); } else { tStartDate = new DateTime(tStartDate.getYear(), tStartDate.getMonthOfYear(), tStartDate.getDayOfMonth(), 0, 0, DateTimeZone.UTC); } } else { throw new ValidationException(ErrorCode.SERVER_INVALID_DATE, "Multiple date values were given: " + InputKeys.DATE); } tColumns = null; t = getParameterValues(InputKeys.MOBILITY_WITH_SENSOR_DATA); if (t.length > 1) { throw new ValidationException(ErrorCode.MOBILITY_INVALID_INCLUDE_SENSOR_DATA_VALUE, "Multiple \"include sensor data\" values to query were given: " + InputKeys.MOBILITY_WITH_SENSOR_DATA); } else if (t.length == 1) { if (MobilityValidators.validateIncludeSensorDataValue(t[0])) { tColumns = MobilityColumnKey.ALL_COLUMNS; } } t = getParameterValues(InputKeys.COLUMN_LIST); if (t.length > 1) { throw new ValidationException(ErrorCode.MOBILITY_INVALID_COLUMN_LIST, "Multiple column lists were given: " + InputKeys.COLUMN_LIST); } else if (t.length == 1) { if (!StringUtils.isEmptyOrWhitespaceOnly(t[0])) { if (tColumns == null) { tColumns = MobilityValidators.validateColumns(t[0], true); } else { throw new ValidationException(ErrorCode.MOBILITY_INVALID_COLUMN_LIST, "Both '" + InputKeys.MOBILITY_WITH_SENSOR_DATA + "' and '" + InputKeys.COLUMN_LIST + "' were present. Only one may be present."); } } } if (tColumns == null) { tColumns = DEFAULT_COLUMNS; } // Get the user. t = getParameterValues(InputKeys.USERNAME); if (t.length > 1) { throw new ValidationException(ErrorCode.USER_INVALID_USERNAME, "Multiple usernames to query were given: " + InputKeys.USERNAME); } else if (t.length == 1) { tUsername = UserValidators.validateUsername(t[0]); } // Always get all of the columns. try { tRegularReadRequest = new StreamReadRequest(httpRequest, getParameterMap(), false, TokenLocation.EITHER, false, tUsername, "edu.ucla.cens.Mobility", null, "regular", 2012050700, tStartDate.minusMinutes(10), tStartDate.plusDays(1), null, true, null, null); tExtendedReadRequest = new StreamReadRequest(httpRequest, getParameterMap(), false, TokenLocation.EITHER, false, tUsername, "edu.ucla.cens.Mobility", null, "extended", 2012050700, tStartDate.minusMinutes(10), tStartDate.plusDays(1), null, true, null, null); } catch (IllegalArgumentException e) { throw new ValidationException("There was an error creating the request.", e); } } catch (ValidationException e) { e.failRequest(this); e.logException(LOGGER); } } username = tUsername; startDate = tStartDate; regularReadRequest = tRegularReadRequest; extendedReadRequest = tExtendedReadRequest; columns = tColumns; points = new ArrayList<MobilityPoint>(); }