@Override
  public String execute() {
    if (dataElementGroupId > 0) {
      DataElementGroup group =
          dataElementService.getDataElementGroup(dataElementGroupId.intValue());

      dataElements = new ArrayList<>(group.getMembers());
    } else {
      dataElements = new ArrayList<>(dataElementService.getAllDataElements());
    }

    Collections.sort(dataElements, new IdentifiableObjectNameComparator());

    for (DataElement dataElement : dataElements) {
      DataElementCategoryCombo categoryCombo = dataElement.getCategoryCombo();

      Set<DataElementCategoryOptionCombo> optionCombos = categoryCombo.getOptionCombos();

      if (optionCombos.size() > 1) {
        for (DataElementCategoryOptionCombo optionCombo : optionCombos) {
          DataElementOperand operand =
              new DataElementOperand(
                  dataElement.getUid(),
                  optionCombo.getUid(),
                  dataElement.getName() + optionCombo.getName());
          operands.add(operand);
        }
      } else {
        DataElementOperand operand =
            new DataElementOperand(
                dataElement.getUid(),
                optionCombos.iterator().next().getUid(),
                dataElement.getName());
        operands.add(operand);
      }
    }

    return SUCCESS;
  }
Exemple #2
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;
  }