コード例 #1
0
  /**
   * Handle an account state warning produced by ldaptive account state machinery.
   *
   * <p>Override this method to provide custom warning message handling.
   *
   * @param warning the account state warning messages.
   * @param response Ldaptive authentication response.
   * @param configuration Password policy configuration.
   * @param messages Container for messages produced by account state warning handling.
   */
  protected void handleWarning(
      final AccountState.Warning warning,
      final AuthenticationResponse response,
      final LdapPasswordPolicyConfiguration configuration,
      final List<Message> messages) {

    logger.debug("Handling warning {}", warning);
    if (warning == null) {
      logger.debug("Account state warning not defined");
      return;
    }

    final Calendar expDate = warning.getExpiration();
    final Days ttl = Days.daysBetween(Instant.now(), new Instant(expDate));
    logger.debug(
        "Password expires in {} days. Expiration warning threshold is {} days.",
        ttl.getDays(),
        configuration.getPasswordWarningNumberOfDays());
    if (configuration.isAlwaysDisplayPasswordExpirationWarning()
        || ttl.getDays() < configuration.getPasswordWarningNumberOfDays()) {
      messages.add(
          new PasswordExpiringWarningMessage(
              "Password expires in {0} days. Please change your password at <href=\"{1}\">{1}</a>",
              ttl.getDays(), configuration.getPasswordPolicyUrl()));
    }
    if (warning.getLoginsRemaining() > 0) {
      messages.add(
          new Message(
              "password.expiration.loginsRemaining",
              "You have {0} logins remaining before you MUST change your password.",
              warning.getLoginsRemaining()));
    }
  }
コード例 #2
0
ファイル: JodaTimeDayTest.java プロジェクト: ccincd/exp
  public static void main(String[] args) {
    String dayStrBegin = "2016-03-14";
    String dayStrEnd = "2016-03-20";

    String datePattern = "yyyy-MM-dd";
    DateTimeFormatter dateFormatter = DateTimeFormat.forPattern(datePattern);

    LocalDate localDateStart = dateFormatter.parseLocalDate(dayStrBegin);
    LocalDate localDateEnd = dateFormatter.parseLocalDate(dayStrEnd);

    // 比较大小,不返回相差的天数
    // localDateStart.compareTo(localDateEnd);

    // 减去一个Period,不能应用于localDateEnd
    // localDateStart.minus(ReadablePeriod);

    // minus的入参是ReadablePeriod
    // Duration ninetyDays = new Duration(NINETY_DAYS_MILLI);

    /*
     * Period ninetyDays = new Period(NINETY_DAYS_MILLI); LocalDate limitStart = localDateEnd.minus(ninetyDays); if
     * (localDateStart.compareTo(limitStart) != -1) { System.out.println("Hi, there"); }
     */

    Days durationDays = Days.daysBetween(localDateStart, localDateEnd);
    if (durationDays.getDays() <= 90) {
      System.out.println("Hi, there");
    }
  }
コード例 #3
0
ファイル: CacheCleanerJob.java プロジェクト: edagan/verigreen
  private boolean isExceedThreashold(Date date) {

    Days daysBetweenCreationTimeAndNow = Days.daysBetween(new DateTime(date), DateTime.now());

    return daysBetweenCreationTimeAndNow.getDays()
        >= Integer.parseInt(VerigreenNeededLogic.VerigreenMap.get("daysThreashold"));
  }
コード例 #4
0
ファイル: TimeId.java プロジェクト: iDuduba/fcd
  public int gap(TimeId start) {
    Days days = Days.daysBetween(start.getDateTime().toLocalDate(), dateTime.toLocalDate());

    return days.getDays() * 288 + timeId - start.getTimeId();

    //        if(a >= 0) {
    //            return (a * 288) + timeId - start.getTimeId();
    //        } else {
    //            return (a * 288) + timeId - start.getTimeId();
    //        }
  }
コード例 #5
0
 private boolean isWebserviceInvocationAllowed(Calltype callType, Timestamp lastInvocation) {
   boolean oldEnough;
   if (lastInvocation == null) {
     oldEnough = true;
   } else if (lastInvocation.getTime() >> 32 == Integer.MAX_VALUE) {
     // checks if invocation_time is close enough to 'infinity'.
     oldEnough = false;
   } else {
     DateTime lastInvocationDateTime = new DateTime(lastInvocation.getTime());
     Days daysBetween = Days.daysBetween(lastInvocationDateTime, new DateTime());
     oldEnough = daysBetween.getDays() > callType.getDaysToCache();
   }
   return oldEnough;
 }
コード例 #6
0
 /**
  * Extends the CSV row
  *
  * @param row existing row
  * @return the extended row
  */
 public String[] extendRow(String[] row) {
   List<String> rowExt = new ArrayList<String>();
   for (int i = 0; i < dateColumnIndexes.size(); i++) {
     SourceColumn c = dates.get(i);
     int idx = dateColumnIndexes.get(i);
     int adjustedDataIndex =
         ((identityColumn >= 0) && (idx >= identityColumn)) ? (idx - 1) : (idx);
     String dateValue = row[idx];
     if (dateValue != null && dateValue.trim().length() > 0) {
       try {
         DateTimeFormatter formatter = dateColumnFormats.get(i);
         DateTime dt = formatter.parseDateTime(dateValue);
         Days ds = Days.daysBetween(base, dt);
         rowExt.add(Integer.toString(ds.getDays() + 1));
         if (c.isDatetime()) {
           int ts = dt.getSecondOfDay();
           rowExt.add(Integer.toString(ts));
           String scs = Integer.toString(ts);
           rowExt.add((scs.length() > 1) ? (scs) : ("0" + scs));
         }
       } catch (IllegalArgumentException e) {
         l.debug("Can't parse date " + dateValue);
         rowExt.add("");
         if (c.isDatetime()) {
           rowExt.add("");
           rowExt.add("00");
         }
       }
     } else {
       rowExt.add("");
       if (c.isDatetime()) {
         rowExt.add("");
         rowExt.add("00");
       }
     }
   }
   if (rowExt.size() > 0) return mergeArrays(row, rowExt.toArray(new String[] {}));
   else return row;
 }
コード例 #7
0
 @Override
 protected int toNumber(final Days object) {
   return object.getDays();
 }
コード例 #8
0
 @Override
 public String marshal(Days v) throws Exception {
   return String.valueOf(v.getDays());
 }
コード例 #9
0
ファイル: MetricsServer.java プロジェクト: Jiri-Kremser/rhq
 public int getRawDataAgeLimit() {
   return rawDataAgeLimit.getDays();
 }
コード例 #10
0
ファイル: MetricsServer.java プロジェクト: Jiri-Kremser/rhq
  public void addNumericData(
      final Set<MeasurementDataNumeric> dataSet, final RawDataInsertedCallback callback) {
    if (log.isDebugEnabled()) {
      log.debug("Inserting " + dataSet.size() + " raw metrics");
    }
    final Stopwatch stopwatch = new Stopwatch().start();
    final AtomicInteger remainingInserts = new AtomicInteger(dataSet.size());

    for (final MeasurementDataNumeric data : dataSet) {
      DateTime collectionTimeSlice =
          dateTimeService.getTimeSlice(
              new DateTime(data.getTimestamp()), configuration.getRawTimeSliceDuration());
      Days days = Days.daysBetween(collectionTimeSlice, dateTimeService.now());

      if (days.isGreaterThan(rawDataAgeLimit)) {
        log.info(
            data
                + " is older than the raw data age limit of "
                + rawDataAgeLimit.getDays()
                + " days. It will not be stored.");
      } else {
        StorageResultSetFuture rawFuture = dao.insertRawData(data);
        StorageResultSetFuture indexFuture =
            dao.updateIndex(IndexBucket.RAW, collectionTimeSlice.getMillis(), data.getScheduleId());
        ListenableFuture<List<ResultSet>> insertsFuture =
            Futures.successfulAsList(rawFuture, indexFuture);
        Futures.addCallback(
            insertsFuture,
            new FutureCallback<List<ResultSet>>() {
              @Override
              public void onSuccess(List<ResultSet> result) {
                callback.onSuccess(data);
                if (remainingInserts.decrementAndGet() == 0) {
                  stopwatch.stop();
                  if (log.isDebugEnabled()) {
                    log.debug(
                        "Finished inserting "
                            + dataSet.size()
                            + " raw metrics in "
                            + stopwatch.elapsed(TimeUnit.MILLISECONDS)
                            + " ms");
                  }
                  callback.onFinish();
                }
              }

              @Override
              public void onFailure(Throwable t) {
                if (log.isDebugEnabled()) {
                  log.debug(
                      "An error occurred while inserting raw data", ThrowableUtil.getRootCause(t));
                } else {
                  log.warn(
                      "An error occurred while inserting raw data: "
                          + ThrowableUtil.getRootMessage(t));
                }
                callback.onFailure(t);
              }
            },
            tasks);
      }
    }
  }
コード例 #11
0
ファイル: D.java プロジェクト: greenlaw110/play-app-base
 public static int daysBetween(Date start, Date end) {
   Days d = Days.daysBetween(new DateTime(start), new DateTime(end));
   return d.getDays();
 }