コード例 #1
0
ファイル: ReportSettingsTest.java プロジェクト: ciukstar/eupp
  @Test
  public void shouldExpandDecreeSequenceGroupScope() {

    settings.expandDecreeSequenceGroupScope(group);

    assertTrue(settings.contains(group));
  }
コード例 #2
0
ファイル: ReportSettingsTest.java プロジェクト: ciukstar/eupp
  @Test
  public void lackOfKonvGroupSettings() {

    settings.shrinkKonvGroupScope(konvGroup);

    assertFalse(settings.hasKonvGroupSettings());
  }
コード例 #3
0
ファイル: ReportSettingsTest.java プロジェクト: ciukstar/eupp
  @Test
  public void expandKonvScope() {

    settings.expandKonvScope(konv);

    assertTrue(settings.contains(konv));
  }
コード例 #4
0
ファイル: ReportService.java プロジェクト: jcauthorn/pwm
 private void updateCacheFromLdap()
     throws ChaiUnavailableException, ChaiOperationException, PwmOperationalException,
         PwmUnrecoverableException {
   LOGGER.debug(
       PwmConstants.REPORTING_SESSION_LABEL,
       "beginning process to updating user cache records from ldap");
   if (status != STATUS.OPEN) {
     return;
   }
   cancelFlag = false;
   reportStatus = new ReportStatusInfo(settings.getSettingsHash());
   reportStatus.setInProgress(true);
   reportStatus.setStartDate(new Date());
   try {
     final Queue<UserIdentity> allUsers = new LinkedList<>(getListOfUsers());
     reportStatus.setTotal(allUsers.size());
     while (status == STATUS.OPEN && !allUsers.isEmpty() && !cancelFlag) {
       final Date startUpdateTime = new Date();
       final UserIdentity userIdentity = allUsers.poll();
       try {
         if (updateCachedRecordFromLdap(userIdentity)) {
           reportStatus.setUpdated(reportStatus.getUpdated() + 1);
         }
       } catch (Exception e) {
         String errorMsg =
             "error while updating report cache for " + userIdentity.toString() + ", cause: ";
         errorMsg +=
             e instanceof PwmException
                 ? ((PwmException) e).getErrorInformation().toDebugStr()
                 : e.getMessage();
         final ErrorInformation errorInformation;
         errorInformation = new ErrorInformation(PwmError.ERROR_REPORTING_ERROR, errorMsg);
         LOGGER.error(PwmConstants.REPORTING_SESSION_LABEL, errorInformation.toDebugStr());
         reportStatus.setLastError(errorInformation);
         reportStatus.setErrors(reportStatus.getErrors() + 1);
       }
       reportStatus.setCount(reportStatus.getCount() + 1);
       reportStatus.getEventRateMeter().markEvents(1);
       final TimeDuration totalUpdateTime = TimeDuration.fromCurrent(startUpdateTime);
       if (settings.isAutoCalcRest()) {
         avgTracker.addSample(totalUpdateTime.getTotalMilliseconds());
         Helper.pause(avgTracker.avgAsLong());
       } else {
         Helper.pause(settings.getRestTime().getTotalMilliseconds());
       }
     }
     if (cancelFlag) {
       reportStatus.setLastError(
           new ErrorInformation(
               PwmError.ERROR_SERVICE_NOT_AVAILABLE, "report cancelled by operator"));
     }
   } finally {
     reportStatus.setFinishDate(new Date());
     reportStatus.setInProgress(false);
   }
   LOGGER.debug(
       PwmConstants.REPORTING_SESSION_LABEL,
       "update user cache process completed: " + JsonUtil.serialize(reportStatus));
 }
コード例 #5
0
ファイル: ReportSettingsTest.java プロジェクト: ciukstar/eupp
  @Test
  public void shouldShrinkDecreeSequenceGroupScope() {

    settings.expandDecreeSequenceGroupScope(group);
    settings.shrinkDecreeSequenceGroupScope(group);

    assertFalse(settings.contains(group));
  }
コード例 #6
0
ファイル: ReportSettingsTest.java プロジェクト: ciukstar/eupp
  @Test
  public void shrinkKonvScope() {
    settings.expandKonvScope(konv);

    settings.shrinkKonvScope(konv);

    assertFalse(settings.contains(konv));
  }
コード例 #7
0
ファイル: ReportSettingsTest.java プロジェクト: ciukstar/eupp
  @Test
  public void defineTheScopeOfReportInputParams() {

    List<DecreeSequence> decreeSequences = settings.getDecreeSequences();
    List<GeoArea> geoAreas = settings.getGeoAreas();
    List<KonvGroup> konvGroups = settings.getKonvGroups();

    assertThat(decreeSequences, hasItem(decreeSequence));
    assertThat(geoAreas, hasItem(geoArea));
    assertThat(konvGroups, hasItem(konvGroup));
  }
コード例 #8
0
ファイル: ReportService.java プロジェクト: jcauthorn/pwm
  @Override
  public void init(PwmApplication pwmApplication) throws PwmException {
    status = STATUS.OPENING;
    this.pwmApplication = pwmApplication;

    if (pwmApplication.getApplicationMode() == PwmApplication.MODE.READ_ONLY) {
      LOGGER.debug(
          PwmConstants.REPORTING_SESSION_LABEL,
          "application mode is read-only, will remain closed");
      status = STATUS.CLOSED;
      return;
    }

    if (pwmApplication.getLocalDB() == null
        || LocalDB.Status.OPEN != pwmApplication.getLocalDB().status()) {
      LOGGER.debug(PwmConstants.REPORTING_SESSION_LABEL, "LocalDB is not open, will remain closed");
      status = STATUS.CLOSED;
      return;
    }

    if (!pwmApplication.getConfig().readSettingAsBoolean(PwmSetting.REPORTING_ENABLE)) {
      LOGGER.debug(
          PwmConstants.REPORTING_SESSION_LABEL,
          "reporting module is not enabled, will remain closed");
      status = STATUS.CLOSED;
      clear();
      return;
    }

    try {
      userCacheService = new UserCacheService();
      userCacheService.init(pwmApplication);
    } catch (Exception e) {
      LOGGER.error(PwmConstants.REPORTING_SESSION_LABEL, "unable to init cache service");
      status = STATUS.CLOSED;
      return;
    }

    settings = ReportSettings.readSettingsFromConfig(pwmApplication.getConfig());
    summaryData = ReportSummaryData.newSummaryData(settings.getTrackDays());

    executorService =
        Executors.newSingleThreadScheduledExecutor(
            Helper.makePwmThreadFactory(
                Helper.makeThreadName(pwmApplication, this.getClass()) + "-", true));

    String startupMsg = "report service started";
    LOGGER.debug(startupMsg);

    executorService.submit(new InitializationTask());

    status = STATUS.OPEN;
  }
コード例 #9
0
ファイル: ReportSettingsTest.java プロジェクト: ciukstar/eupp
  @Test
  public void shouldReturnInputKonvGroupListWhenAnEmptyKonvGroupScopeIsFound() {

    settings.shrinkKonvGroupScope(konvGroup);
    assertThat(settings.hasKonvGroupSettings(), is(Boolean.FALSE));

    final KonvGroup inputKonvGroup = mock(KonvGroup.class);

    List<KonvGroup> selected = settings.chooseOver(Arrays.asList(inputKonvGroup));

    assertThat(selected, hasItems(inputKonvGroup));
    assertThat(selected, not(hasItems(konvGroup)));
  }
コード例 #10
0
ファイル: ReportService.java プロジェクト: jcauthorn/pwm
 public void clear() throws LocalDBException, PwmUnrecoverableException {
   final Date startTime = new Date();
   LOGGER.info(PwmConstants.REPORTING_SESSION_LABEL, "clearing cached report data");
   if (userCacheService != null) {
     userCacheService.clear();
   }
   summaryData = ReportSummaryData.newSummaryData(settings.getTrackDays());
   reportStatus = new ReportStatusInfo(settings.getSettingsHash());
   saveTempData();
   LOGGER.info(
       PwmConstants.REPORTING_SESSION_LABEL,
       "finished clearing report " + TimeDuration.fromCurrent(startTime).asCompactString());
 }
コード例 #11
0
ファイル: ReportSettingsTest.java プロジェクト: ciukstar/eupp
  @Test
  public void twoSettingsShouldBeEqualIfTheyShareSameCode() {

    ReportSettings other = new ReportSettings(settings.getCode());

    assertThat(other, is(equalTo(settings)));
  }
コード例 #12
0
ファイル: ReportSettingsTest.java プロジェクト: ciukstar/eupp
  @Test
  public void shouldReturnNonEmptyKonvGroupScopeWhenChoosingOverAnEmptyListOfInputKonvGroups() {

    List<KonvGroup> selected = settings.chooseOver(Collections.EMPTY_LIST);

    assertThat(selected, hasItems(konvGroup));
    assertThat(selected.size(), is(1));
  }
コード例 #13
0
ファイル: ReportSettingsTest.java プロジェクト: ciukstar/eupp
  @Test
  public void shouldReturnNonEmptyKonvGroupScopeWhenChoosingOverNonEmptyListOfInputKonvGroups() {
    final KonvGroup inputKonvGroup = mock(KonvGroup.class);

    List<KonvGroup> selected = settings.chooseOver(Arrays.asList(inputKonvGroup));

    assertThat(selected, hasItems(konvGroup));
    assertThat(selected, not(hasItems(inputKonvGroup)));
  }
コード例 #14
0
ファイル: ReportSettingsTest.java プロジェクト: ciukstar/eupp
  @Test
  public void aReportSettingsShouldNotContainAkonvWhenItIsNotPresentInItsKonvsCollection()
      throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException {

    Field konvsField = ReportSettings.class.getDeclaredField("konvs");
    konvsField.setAccessible(true);
    final ArrayList<Konv> konvs = new ArrayList<>();
    konvsField.set(settings, konvs);

    assertFalse(settings.contains(konv));
  }
コード例 #15
0
ファイル: ReportService.java プロジェクト: jcauthorn/pwm
  private void initTempData() throws LocalDBException, PwmUnrecoverableException {
    final String cleanFlag =
        pwmApplication.readAppAttribute(PwmApplication.AppAttribute.REPORT_CLEAN_FLAG);
    if (!"true".equals(cleanFlag)) {
      LOGGER.error(PwmConstants.REPORTING_SESSION_LABEL, "did not shut down cleanly");
      reportStatus = new ReportStatusInfo(settings.getSettingsHash());
      reportStatus.setTotal(userCacheService.size());
    } else {
      try {
        final String jsonInfo =
            pwmApplication.readAppAttribute(PwmApplication.AppAttribute.REPORT_STATUS);
        if (jsonInfo != null && !jsonInfo.isEmpty()) {
          reportStatus = JsonUtil.deserialize(jsonInfo, ReportStatusInfo.class);
        }
      } catch (Exception e) {
        LOGGER.error(
            PwmConstants.REPORTING_SESSION_LABEL,
            "error loading cached report status info into memory: " + e.getMessage());
      }
    }

    reportStatus =
        reportStatus == null
            ? new ReportStatusInfo(settings.getSettingsHash())
            : reportStatus; // safety

    final String currentSettingCache = settings.getSettingsHash();
    if (reportStatus.getSettingsHash() != null
        && !reportStatus.getSettingsHash().equals(currentSettingCache)) {
      LOGGER.error(
          PwmConstants.REPORTING_SESSION_LABEL,
          "configuration has changed, will clear cached report data");
      clear();
    }

    reportStatus.setInProgress(false);

    pwmApplication.writeAppAttribute(PwmApplication.AppAttribute.REPORT_CLEAN_FLAG, "false");
  }
コード例 #16
0
ファイル: ReportSettingsTest.java プロジェクト: ciukstar/eupp
  @Test
  public void shrinkReportSettingsScopes() {

    settings.shrinkDecreeSequenceScope(decreeSequence);
    settings.shrinkGeoAreaScope(geoArea);
    settings.shrinkKonvGroupScope(konvGroup);

    assertThat(settings.getDecreeSequences(), not(hasItem(decreeSequence)));
    assertThat(settings.getGeoAreas(), not(hasItem(geoArea)));
    assertThat(settings.getKonvGroups(), not(hasItem(konvGroup)));
  }
コード例 #17
0
ファイル: ReportService.java プロジェクト: jcauthorn/pwm
  private boolean updateCachedRecordFromLdap(
      final UserIdentity userIdentity,
      final UserInfoBean userInfoBean,
      final UserCacheService.StorageKey storageKey)
      throws ChaiUnavailableException, PwmUnrecoverableException, LocalDBException {
    final UserCacheRecord userCacheRecord = userCacheService.readStorageKey(storageKey);
    TimeDuration cacheAge = null;
    if (userCacheRecord != null && userCacheRecord.getCacheTimestamp() != null) {
      cacheAge = TimeDuration.fromCurrent(userCacheRecord.getCacheTimestamp());
    }

    boolean updateCache = false;
    if (userInfoBean != null) {
      updateCache = true;
    } else {
      if (cacheAge == null) {
        LOGGER.trace(
            PwmConstants.REPORTING_SESSION_LABEL,
            "stored cache for "
                + userIdentity
                + " is missing cache storage timestamp, will update");
        updateCache = true;
      } else if (cacheAge.isLongerThan(settings.getMinCacheAge())) {
        LOGGER.trace(
            PwmConstants.REPORTING_SESSION_LABEL,
            "stored cache for "
                + userIdentity
                + " is "
                + cacheAge.asCompactString()
                + " old, will update");
        updateCache = true;
      }
    }

    if (updateCache) {
      if (userCacheRecord != null) {
        if (summaryData != null
            && summaryData.getEpoch() != null
            && summaryData.getEpoch().equals(userCacheRecord.getSummaryEpoch())) {
          summaryData.remove(userCacheRecord);
        }
      }
      final UserInfoBean newUserBean;
      if (userInfoBean != null) {
        newUserBean = userInfoBean;
      } else {
        newUserBean = new UserInfoBean();
        final UserStatusReader.Settings readerSettings = new UserStatusReader.Settings();
        readerSettings.setSkipReportUpdate(true);
        final ChaiProvider chaiProvider =
            pwmApplication.getProxyChaiProvider(userIdentity.getLdapProfileID());
        final UserStatusReader userStatusReader =
            new UserStatusReader(
                pwmApplication, PwmConstants.REPORTING_SESSION_LABEL, readerSettings);
        userStatusReader.populateUserInfoBean(
            newUserBean, PwmConstants.DEFAULT_LOCALE, userIdentity, chaiProvider);
      }
      final UserCacheRecord newUserCacheRecord = userCacheService.updateUserCache(newUserBean);

      if (summaryData != null && summaryData.getEpoch() != null && newUserCacheRecord != null) {
        if (!summaryData.getEpoch().equals(newUserCacheRecord.getSummaryEpoch())) {
          newUserCacheRecord.setSummaryEpoch(summaryData.getEpoch());
          userCacheService.store(newUserCacheRecord);
        }
        summaryData.update(newUserCacheRecord);
      }
    }

    return updateCache;
  }
コード例 #18
0
ファイル: ReportService.java プロジェクト: jcauthorn/pwm
 private List<UserIdentity> getListOfUsers()
     throws ChaiUnavailableException, ChaiOperationException, PwmUnrecoverableException,
         PwmOperationalException {
   return readAllUsersFromLdap(
       pwmApplication, settings.getSearchFilter(), settings.getMaxSearchSize());
 }
コード例 #19
0
ファイル: ReportSettingsTest.java プロジェクト: ciukstar/eupp
  @Test
  public void hasKonvGroupSettings() {

    assertTrue(settings.hasKonvGroupSettings());
  }