private Collection<OrganisationUnit> reloadOrganisationUnits(Collection<OrganisationUnit> units) {
    Set<OrganisationUnit> reloadedUnits = new HashSet<>();

    int noTotal = organisationUnitService.getNumberOfOrganisationUnits();

    int noSelected = units.size();

    if ((double) noSelected / noTotal
        > PERCENTAGE_OF_MULTIPLE_RELOADING_ORG_UNITS) // Select all at once
    {
      Collection<OrganisationUnit> allOrgUnits = organisationUnitService.getAllOrganisationUnits();

      for (OrganisationUnit unit : allOrgUnits) {
        if (units.contains(unit)) {
          reloadedUnits.add(unit);
        }
      }
    } else // Select one by one
    {
      for (OrganisationUnit unit : units) {
        OrganisationUnit reloadedUnit = reloadOrganisationUnit(unit);

        if (reloadedUnit != null) {
          reloadedUnits.add(reloadedUnit);
        }
      }
    }
    return reloadedUnits;
  }
  @Override
  public void scheduledRun() {
    log.info("Starting scheduled monitoring task");

    // Find all the rules belonging to groups that will send alerts to user roles.

    Set<ValidationRule> rules = getAlertRules();

    Collection<OrganisationUnit> sources = organisationUnitService.getAllOrganisationUnits();

    Set<Period> periods = getAlertPeriodsFromRules(rules);

    Date lastScheduledRun =
        (Date) systemSettingManager.getSystemSetting(SystemSettingManager.KEY_LAST_MONITORING_RUN);

    // Any database changes after this moment will contribute to the next run.

    Date thisRun = new Date();

    log.info(
        "Scheduled monitoring run sources: "
            + sources.size()
            + ", periods: "
            + periods.size()
            + ", rules:"
            + rules.size()
            + ", last run: "
            + (lastScheduledRun == null ? "[none]" : lastScheduledRun));

    Collection<ValidationResult> results =
        Validator.validate(
            sources,
            periods,
            rules,
            null,
            lastScheduledRun,
            constantService,
            expressionService,
            periodService,
            dataValueService,
            dataElementCategoryService,
            userService,
            currentUserService);

    log.info("Validation run result count: " + results.size());

    if (!results.isEmpty()) {
      postAlerts(results, thisRun);
    }

    log.info("Posted alerts, monitoring task done");

    systemSettingManager.saveSystemSetting(SystemSettingManager.KEY_LAST_MONITORING_RUN, thisRun);
  }
示例#3
0
  @Override
  public String execute() throws Exception {
    ExportParams params = new ExportParams();

    if (dataValue || dataValueDaily) {
      params.setCategories(null);
      params.setCategoryCombos(null);
      params.setCategoryOptions(null);
      params.setCategoryOptionCombos(null);
      /*
       * params.setDataElementGroups( null );
       * params.setDataElementGroupSets( null ); params.setIndicators(
       * null ); params.setIndicatorTypes( null );
       * params.setIndicatorGroups( null ); params.setIndicatorGroupSets(
       * null ); params.setDataDictionaries( null ); params.setDataSets(
       * null ); params.setOrganisationUnitGroups( null );
       * params.setOrganisationUnitGroupSets( null );
       * params.setOrganisationUnitLevels( null );
       * params.setValidationRules( null ); params.setReports( null );
       * params.setReportTables( null ); params.setPeriods( null ); //
       * TODO Include only relevant periods params.setCharts( null );
       * params.setPeriods( null );
       */

      Set<Integer> dataElementz = new HashSet<>();

      Collection<DataElement> children = dataElementService.getAllDataElements();

      for (DataElement child : children) {
        dataElementz.add(child.getId());
      }

      params.setDataElements(dataElementz);

      Set<Integer> orgUnits = new HashSet<>();

      Collection<OrganisationUnit> orgChildren = organisationUnitService.getAllOrganisationUnits();

      for (OrganisationUnit child : orgChildren) {
        orgUnits.add(child.getId());
      }

      params.setOrganisationUnits(orgUnits);
    }

    if (dataValue) {
      params.setMetaData(false);
    }

    if (dataValueDaily) {
      params.setMetaData(false);
    }

    // params.setMetaData( true );
    params.setIncludeDataValues(true);
    params.setCurrentUser(currentUserService.getCurrentUser());
    params.setDataValue(dataValue);
    params.setDataValueDaily(dataValueDaily);

    params.setI18n(i18n);
    params.setFormat(format);
    params.setStartDate(getMediumDate(startDate));
    params.setEndDate(getMediumDate(endDate));

    ExportService exportService = serviceProvider.provide(exportFormat);

    inputStream = exportService.exportData(params);

    fileName = FILENAME;

    return SUCCESS;
  }