List of usage examples for org.joda.time DateTime plusDays
public DateTime plusDays(int days)
From source file:org.egov.ptis.domain.service.notice.RecoveryNoticeService.java
License:Open Source License
private void validateInventoryNotice(final List<String> errors, final BasicProperty basicProperty) { validateDemandBill(basicProperty, errors); final PtNotice distressNotice = noticeService.getNoticeByTypeUpicNoAndFinYear(NOTICE_TYPE_DISTRESS, basicProperty.getUpicNo());//from w ww .jav a 2 s .com if (distressNotice != null) { final DateTime noticeDate = new DateTime(distressNotice.getNoticeDate()); final DateTime currDate = new DateTime(); if (!currDate.isAfter(noticeDate.plusDays(16))) errors.add("invntry.distress.notice.not.exists"); } else errors.add("invntry.distress.notice.not.exists"); }
From source file:org.egov.ptis.domain.service.notice.RecoveryNoticeService.java
License:Open Source License
private void prepareEsdReportParams(final BasicProperty basicProperty, final Map<String, Object> reportParams, final String noticeNo, final SimpleDateFormat formatter) { final Address ownerAddress = basicProperty.getAddress(); final DateTime noticeDate = new DateTime(new Date()); final AppConfigValues appConfigValues = appConfigValuesService.getAppConfigValueByDate(PTMODULENAME, APPCONFIG_CLIENT_SPECIFIC_DMD_BILL, new Date()); reportParams.put(DOOR_NO,//from ww w . ja v a2 s .c om StringUtils.isNotBlank(ownerAddress.getHouseNoBldgApt()) ? ownerAddress.getHouseNoBldgApt() : "N/A"); reportParams.put(FIN_YEAR, formatter.format(new Date())); reportParams.put(CONSUMER_ID, basicProperty.getUpicNo()); reportParams.put(TOTAL_TAX_DUE, getTotalPropertyTaxDueIncludingPenalty(basicProperty)); reportParams.put(FUTURE_DATE, DateUtils.getDefaultFormattedDate(noticeDate.plusDays(2).toDate())); reportParams.put(ESD_NOTICE_NUMBER, noticeNo); reportParams.put(ESD_NOTICE_DATE, DateUtils.getDefaultFormattedDate(new Date())); final String value = appConfigValues != null ? appConfigValues.getValue() : ""; if ("Y".equalsIgnoreCase(value)) { final DemandBillService demandBillService = (DemandBillService) beanProvider .getBean(DEMAND_BILL_SERVICE); reportParams.putAll(demandBillService.getDemandBillDetails(basicProperty)); } else { final EgBill egBill = getBillByAssessmentNumber(basicProperty); reportParams.put(BILL_DATE, DateUtils.getDefaultFormattedDate(egBill.getCreateDate())); reportParams.put(BILL_NUMBER, egBill.getBillNo()); } }
From source file:org.egov.ptis.domain.service.property.PropertyService.java
License:Open Source License
private Date getSlaEndDate(final String applictionType) { final DateTime dt = new DateTime(new Date()); return dt.plusDays(getSlaValue(applictionType)).toDate(); }
From source file:org.elasticsearch.xpack.core.ssl.CertGenUtils.java
License:Open Source License
/** * Generates a signed certificate//from w w w . j ava2 s . c om * * @param principal the principal of the certificate; commonly referred to as the * distinguished name (DN) * @param subjectAltNames the subject alternative names that should be added to the * certificate as an X509v3 extension. May be {@code null} * @param keyPair the key pair that will be associated with the certificate * @param caCert the CA certificate. If {@code null}, this results in a self signed * certificate * @param caPrivKey the CA private key. If {@code null}, this results in a self signed * certificate * @param isCa whether or not the generated certificate is a CA * @param days no of days certificate will be valid from now * @param signatureAlgorithm algorithm used for signing certificate. If {@code null} or * empty, then use default algorithm {@link CertGenUtils#getDefaultSignatureAlgorithm(PrivateKey)} * @return a signed {@link X509Certificate} */ private static X509Certificate generateSignedCertificate(X500Principal principal, GeneralNames subjectAltNames, KeyPair keyPair, X509Certificate caCert, PrivateKey caPrivKey, boolean isCa, int days, String signatureAlgorithm) throws NoSuchAlgorithmException, CertificateException, CertIOException, OperatorCreationException { Objects.requireNonNull(keyPair, "Key-Pair must not be null"); final DateTime notBefore = new DateTime(DateTimeZone.UTC); if (days < 1) { throw new IllegalArgumentException("the certificate must be valid for at least one day"); } final DateTime notAfter = notBefore.plusDays(days); final BigInteger serial = CertGenUtils.getSerial(); JcaX509ExtensionUtils extUtils = new JcaX509ExtensionUtils(); X500Name subject = X500Name.getInstance(principal.getEncoded()); final X500Name issuer; final AuthorityKeyIdentifier authorityKeyIdentifier; if (caCert != null) { if (caCert.getBasicConstraints() < 0) { throw new IllegalArgumentException("ca certificate is not a CA!"); } issuer = X500Name.getInstance(caCert.getIssuerX500Principal().getEncoded()); authorityKeyIdentifier = extUtils.createAuthorityKeyIdentifier(caCert.getPublicKey()); } else { issuer = subject; authorityKeyIdentifier = extUtils.createAuthorityKeyIdentifier(keyPair.getPublic()); } JcaX509v3CertificateBuilder builder = new JcaX509v3CertificateBuilder(issuer, serial, new Time(notBefore.toDate(), Locale.ROOT), new Time(notAfter.toDate(), Locale.ROOT), subject, keyPair.getPublic()); builder.addExtension(Extension.subjectKeyIdentifier, false, extUtils.createSubjectKeyIdentifier(keyPair.getPublic())); builder.addExtension(Extension.authorityKeyIdentifier, false, authorityKeyIdentifier); if (subjectAltNames != null) { builder.addExtension(Extension.subjectAlternativeName, false, subjectAltNames); } builder.addExtension(Extension.basicConstraints, isCa, new BasicConstraints(isCa)); PrivateKey signingKey = caPrivKey != null ? caPrivKey : keyPair.getPrivate(); ContentSigner signer = new JcaContentSignerBuilder( (Strings.isNullOrEmpty(signatureAlgorithm)) ? getDefaultSignatureAlgorithm(signingKey) : signatureAlgorithm).setProvider(CertGenUtils.BC_PROV).build(signingKey); X509CertificateHolder certificateHolder = builder.build(signer); return new JcaX509CertificateConverter().getCertificate(certificateHolder); }
From source file:org.elasticsearch.xpack.ml.MlDailyMaintenanceService.java
License:Open Source License
/** * Calculates the delay until the next time the maintenance should be triggered. * The next time is 30 minutes past midnight of the following day plus a random * offset. The random offset is added in order to avoid multiple clusters * running the maintenance tasks at the same time. A cluster with a given name * shall have the same offset throughout its life. * * @param clusterName the cluster name is used to seed the random offset * @return the delay to the next time the maintenance should be triggered *//*from ww w. jav a2s . c o m*/ private static TimeValue delayToNextTime(ClusterName clusterName) { Random random = new Random(clusterName.hashCode()); int minutesOffset = random.ints(0, MAX_TIME_OFFSET_MINUTES).findFirst().getAsInt(); DateTime now = DateTime.now(ISOChronology.getInstance()); DateTime next = now.plusDays(1).withTimeAtStartOfDay().plusMinutes(30).plusMinutes(minutesOffset); return TimeValue.timeValueMillis(next.getMillis() - now.getMillis()); }
From source file:org.elasticsearch.xpack.security.Security.java
License:Open Source License
static void validateAutoCreateIndex(Settings settings) { String value = settings.get("action.auto_create_index"); if (value == null) { return;//w w w. j av a 2s. c o m } final boolean indexAuditingEnabled = Security.indexAuditLoggingEnabled(settings); if (indexAuditingEnabled) { String auditIndex = IndexAuditTrailField.INDEX_NAME_PREFIX + "*"; String errorMessage = LoggerMessageFormat.format( "the [action.auto_create_index] setting value [{}] is too" + " restrictive. disable [action.auto_create_index] or set it to include " + "[{}]", (Object) value, auditIndex); if (Booleans.isFalse(value)) { throw new IllegalArgumentException(errorMessage); } if (Booleans.isTrue(value)) { return; } String[] matches = Strings.commaDelimitedListToStringArray(value); List<String> indices = new ArrayList<>(); DateTime now = new DateTime(DateTimeZone.UTC); // just use daily rollover indices.add(IndexNameResolver.resolve(IndexAuditTrailField.INDEX_NAME_PREFIX, now, IndexNameResolver.Rollover.DAILY)); indices.add(IndexNameResolver.resolve(IndexAuditTrailField.INDEX_NAME_PREFIX, now.plusDays(1), IndexNameResolver.Rollover.DAILY)); indices.add(IndexNameResolver.resolve(IndexAuditTrailField.INDEX_NAME_PREFIX, now.plusMonths(1), IndexNameResolver.Rollover.DAILY)); indices.add(IndexNameResolver.resolve(IndexAuditTrailField.INDEX_NAME_PREFIX, now.plusMonths(2), IndexNameResolver.Rollover.DAILY)); indices.add(IndexNameResolver.resolve(IndexAuditTrailField.INDEX_NAME_PREFIX, now.plusMonths(3), IndexNameResolver.Rollover.DAILY)); indices.add(IndexNameResolver.resolve(IndexAuditTrailField.INDEX_NAME_PREFIX, now.plusMonths(4), IndexNameResolver.Rollover.DAILY)); indices.add(IndexNameResolver.resolve(IndexAuditTrailField.INDEX_NAME_PREFIX, now.plusMonths(5), IndexNameResolver.Rollover.DAILY)); indices.add(IndexNameResolver.resolve(IndexAuditTrailField.INDEX_NAME_PREFIX, now.plusMonths(6), IndexNameResolver.Rollover.DAILY)); for (String index : indices) { boolean matched = false; for (String match : matches) { char c = match.charAt(0); if (c == '-') { if (Regex.simpleMatch(match.substring(1), index)) { throw new IllegalArgumentException(errorMessage); } } else if (c == '+') { if (Regex.simpleMatch(match.substring(1), index)) { matched = true; break; } } else { if (Regex.simpleMatch(match, index)) { matched = true; break; } } } if (!matched) { throw new IllegalArgumentException(errorMessage); } } logger.warn("the [action.auto_create_index] setting is configured to be restrictive [{}]. " + " for the next 6 months audit indices are allowed to be created, but please make sure" + " that any future history indices after 6 months with the pattern " + "[.security_audit_log*] are allowed to be created", value); } }
From source file:org.elasticsearch.xpack.watcher.Watcher.java
static void validAutoCreateIndex(final Settings settings) { final String value = settings.get("action.auto_create_index"); if (value == null) { return;/*w ww .j ava2 s .c o m*/ } final String errorMessage = LoggerMessageFormat.format( "the [action.auto_create_index] setting value [{}] is too restrictive. disable [action.auto_create_index] or set it to [{}, {}, {}*]", new Object[] { value, ".watches", ".triggered_watches", ".watcher-history-" }); if (Booleans.isExplicitFalse(value)) { throw new IllegalArgumentException(errorMessage); } if (Booleans.isExplicitTrue(value)) { return; } final String[] matches = Strings.commaDelimitedListToStringArray(value); final List<String> indices = new ArrayList<String>(); indices.add(".watches"); indices.add(".triggered_watches"); final DateTime now = new DateTime(DateTimeZone.UTC); indices.add(HistoryStore.getHistoryIndexNameForTime(now)); indices.add(HistoryStore.getHistoryIndexNameForTime(now.plusDays(1))); indices.add(HistoryStore.getHistoryIndexNameForTime(now.plusMonths(1))); indices.add(HistoryStore.getHistoryIndexNameForTime(now.plusMonths(2))); indices.add(HistoryStore.getHistoryIndexNameForTime(now.plusMonths(3))); indices.add(HistoryStore.getHistoryIndexNameForTime(now.plusMonths(4))); indices.add(HistoryStore.getHistoryIndexNameForTime(now.plusMonths(5))); indices.add(HistoryStore.getHistoryIndexNameForTime(now.plusMonths(6))); for (final String index : indices) { boolean matched = false; for (final String match : matches) { final char c = match.charAt(0); if (c == '-') { if (Regex.simpleMatch(match.substring(1), index)) { throw new IllegalArgumentException(errorMessage); } } else if (c == '+') { if (Regex.simpleMatch(match.substring(1), index)) { matched = true; break; } } else if (Regex.simpleMatch(match, index)) { matched = true; break; } } if (!matched) { throw new IllegalArgumentException(errorMessage); } } Watcher.logger.warn( "the [action.auto_create_index] setting is configured to be restrictive [{}]. for the next 6 months daily history indices are allowed to be created, but please make sure that any future history indices after 6 months with the pattern [.watcher-history-YYYY.MM.dd] are allowed to be created", (Object) value); }
From source file:org.emonocot.model.registry.Resource.java
License:Open Source License
public void updateNextAvailableDate() { if (getScheduled()) { DateTime nextAvailableDate = new DateTime(); switch (getSchedulingPeriod()) { case YEARLY: nextAvailableDate = nextAvailableDate.plusYears(1); break; case MONTHLY: nextAvailableDate = nextAvailableDate.plusMonths(1); break; case WEEKLY: nextAvailableDate = nextAvailableDate.plusWeeks(1); break; case DAILY: nextAvailableDate = nextAvailableDate.plusDays(1); break; default://from w ww. jav a2s.c om nextAvailableDate = null; } setNextAvailableDate(nextAvailableDate); } }
From source file:org.emonocot.portal.view.Functions.java
License:Open Source License
public static String formatDateRange(String dateRange) { Matcher matcher = pattern.matcher(dateRange); if (matcher.matches()) { String beginningString = matcher.group(1); String endString = matcher.group(2); DateTime beginning = solrDateTimeFormatter.parseDateTime(beginningString); DateTime end = solrDateTimeFormatter.parseDateTime(endString); Integer gap = Integer.parseInt(matcher.group(3)); String increment = matcher.group(4); DateTimeFormatter dateTimeFormatter = null; switch (increment) { case "DAY": end = end.plusDays(gap); dateTimeFormatter = DateTimeFormat.shortDate(); break; case "WEEK": end = end.plusWeeks(gap);//w ww . j a v a 2 s .c o m dateTimeFormatter = DateTimeFormat.shortDate(); break; case "MONTH": end = end.plusMonths(gap); dateTimeFormatter = DateTimeFormat.forPattern("yyyy/MM"); break; case "YEAR": end = end.plusYears(gap); dateTimeFormatter = DateTimeFormat.forPattern("yyyy"); break; } return dateTimeFormatter.print(beginning) + " - " + dateTimeFormatter.print(end); } else { return dateRange; } }
From source file:org.encuestame.utils.DateUtil.java
License:Apache License
/** * Retrieve next day mid night date.//from www .j a v a 2 s . c o m * @return {@link Date} */ public static Date getNextDayMidnightDate() { DateTime midNight = new DateTime(); midNight = midNight.plusDays(1); final DateMidnight midnightDate = midNight.toDateMidnight(); return midnightDate.toDate(); }