示例#1
0
  /**
   * Assembles a list of DimensionalObjects based on the concrete objects in this
   * BaseAnalyticalObject. Explodes the dx dimension into the in|de|dc|ds concrete objects and
   * returns them as separate DimensionalObjects.
   *
   * <p>Merges fixed and relative periods into the pe dimension, where the RelativePeriods object is
   * represented by enums (e.g. LAST_MONTH). Merges fixed and user organisation units into the ou
   * dimension, where user organisation units properties are represented by enums (e.g.
   * USER_ORG_UNIT).
   *
   * <p>This method is useful when serializing the AnalyticalObject.
   *
   * @param dimension the dimension identifier.
   * @return a list of DimensionalObjects.
   */
  protected List<DimensionalObject> getDimensionalObjectList(String dimension) {
    List<DimensionalObject> objects = new ArrayList<>();

    List<String> categoryDims = getCategoryDims();

    if (DATA_X_DIM_ID.equals(dimension)) {
      if (!indicators.isEmpty()) {
        objects.add(
            new BaseDimensionalObject(INDICATOR_DIM_ID, DimensionType.INDICATOR, indicators));
      }

      if (!dataElements.isEmpty()) {
        objects.add(
            new BaseDimensionalObject(DATAELEMENT_DIM_ID, DimensionType.DATAELEMENT, dataElements));
      }

      if (!dataElementOperands.isEmpty()) {
        objects.add(
            new BaseDimensionalObject(
                DATAELEMENT_OPERAND_ID, DimensionType.DATAELEMENT_OPERAND, dataElementOperands));
      }

      if (!dataSets.isEmpty()) {
        objects.add(new BaseDimensionalObject(DATASET_DIM_ID, DimensionType.DATASET, dataSets));
      }
    } else if (PERIOD_DIM_ID.equals(dimension) && (!periods.isEmpty() || hasRelativePeriods())) {
      List<Period> periodList = new ArrayList<>(periods);

      if (hasRelativePeriods()) {
        List<RelativePeriodEnum> list = relatives.getRelativePeriodEnums();

        for (RelativePeriodEnum periodEnum : list) {
          periodList.add(new ConfigurablePeriod(periodEnum.toString()));
        }
      }

      Collections.sort(periodList, new AscendingPeriodComparator());

      objects.add(new BaseDimensionalObject(dimension, DimensionType.PERIOD, periodList));
    } else if (ORGUNIT_DIM_ID.equals(dimension)
        && (!organisationUnits.isEmpty()
            || !transientOrganisationUnits.isEmpty()
            || hasUserOrgUnit())) {
      List<NameableObject> ouList = new ArrayList<>();
      ouList.addAll(organisationUnits);
      ouList.addAll(transientOrganisationUnits);

      if (userOrganisationUnit) {
        ouList.add(new BaseNameableObject(KEY_USER_ORGUNIT, KEY_USER_ORGUNIT, KEY_USER_ORGUNIT));
      }

      if (userOrganisationUnitChildren) {
        ouList.add(
            new BaseNameableObject(
                KEY_USER_ORGUNIT_CHILDREN, KEY_USER_ORGUNIT_CHILDREN, KEY_USER_ORGUNIT_CHILDREN));
      }

      if (userOrganisationUnitGrandChildren) {
        ouList.add(
            new BaseNameableObject(
                KEY_USER_ORGUNIT_GRANDCHILDREN,
                KEY_USER_ORGUNIT_GRANDCHILDREN,
                KEY_USER_ORGUNIT_GRANDCHILDREN));
      }

      if (organisationUnitLevels != null && !organisationUnitLevels.isEmpty()) {
        for (Integer level : organisationUnitLevels) {
          String id = KEY_LEVEL + level;

          ouList.add(new BaseNameableObject(id, id, id));
        }
      }

      if (itemOrganisationUnitGroups != null && !itemOrganisationUnitGroups.isEmpty()) {
        for (OrganisationUnitGroup group : itemOrganisationUnitGroups) {
          String id = KEY_ORGUNIT_GROUP + group.getUid();

          ouList.add(new BaseNameableObject(id, id, id));
        }
      }

      objects.add(new BaseDimensionalObject(dimension, DimensionType.ORGANISATIONUNIT, ouList));
    } else if (CATEGORYOPTIONCOMBO_DIM_ID.equals(dimension)) {
      objects.add(
          new BaseDimensionalObject(
              dimension, DimensionType.CATEGORY_OPTION_COMBO, new ArrayList<BaseNameableObject>()));
    } else if (categoryDims.contains(dimension)) {
      DataElementCategoryDimension categoryDimension =
          categoryDimensions.get(categoryDims.indexOf(dimension));

      objects.add(
          new BaseDimensionalObject(
              dimension, DimensionType.CATEGORY, categoryDimension.getItems()));
    } else if (DATA_COLLAPSED_DIM_ID.contains(dimension)) {
      objects.add(
          new BaseDimensionalObject(
              dimension, DimensionType.DATA_COLLAPSED, new ArrayList<NameableObject>()));
    } else if (STATIC_DIMS.contains(dimension)) {
      objects.add(
          new BaseDimensionalObject(
              dimension, DimensionType.STATIC, new ArrayList<NameableObject>()));
    } else {
      // Data element group set

      ListMap<String, NameableObject> deGroupMap = new ListMap<>();

      for (DataElementGroup group : dataElementGroups) {
        if (group.getGroupSet() != null) {
          deGroupMap.putValue(group.getGroupSet().getDimension(), group);
        }
      }

      if (deGroupMap.containsKey(dimension)) {
        objects.add(
            new BaseDimensionalObject(
                dimension, DimensionType.DATAELEMENT_GROUPSET, deGroupMap.get(dimension)));
      }

      // Organisation unit group set

      ListMap<String, NameableObject> ouGroupMap = new ListMap<>();

      for (OrganisationUnitGroup group : organisationUnitGroups) {
        if (group.getGroupSet() != null) {
          ouGroupMap.putValue(group.getGroupSet().getUid(), group);
        }
      }

      if (ouGroupMap.containsKey(dimension)) {
        objects.add(
            new BaseDimensionalObject(
                dimension, DimensionType.ORGANISATIONUNIT_GROUPSET, ouGroupMap.get(dimension)));
      }

      // Category option group set

      ListMap<String, NameableObject> coGroupMap = new ListMap<>();

      for (CategoryOptionGroup group : categoryOptionGroups) {
        if (group.getGroupSet() != null) {
          coGroupMap.putValue(group.getGroupSet().getUid(), group);
        }
      }

      if (coGroupMap.containsKey(dimension)) {
        objects.add(
            new BaseDimensionalObject(
                dimension, DimensionType.CATEGORYOPTION_GROUPSET, coGroupMap.get(dimension)));
      }

      // Tracked entity attribute

      Map<String, TrackedEntityAttributeDimension> attributes = new HashMap<>();

      for (TrackedEntityAttributeDimension attribute : attributeDimensions) {
        attributes.put(attribute.getUid(), attribute);
      }

      if (attributes.containsKey(dimension)) {
        TrackedEntityAttributeDimension tead = attributes.get(dimension);

        objects.add(
            new BaseDimensionalObject(
                dimension,
                DimensionType.TRACKED_ENTITY_ATTRIBUTE,
                null,
                tead.getDisplayName(),
                tead.getLegendSet(),
                tead.getFilter()));
      }

      // Tracked entity data element

      Map<String, TrackedEntityDataElementDimension> dataElements = new HashMap<>();

      for (TrackedEntityDataElementDimension dataElement : dataElementDimensions) {
        dataElements.put(dataElement.getUid(), dataElement);
      }

      if (dataElements.containsKey(dimension)) {
        TrackedEntityDataElementDimension tedd = dataElements.get(dimension);

        objects.add(
            new BaseDimensionalObject(
                dimension,
                DimensionType.TRACKED_ENTITY_DATAELEMENT,
                null,
                tedd.getDisplayName(),
                tedd.getLegendSet(),
                tedd.getFilter()));
      }
    }

    return objects;
  }
示例#2
0
  /**
   * Assembles a DimensionalObject based on the persisted properties of this AnalyticalObject.
   * Collapses indicators, data elements, data element operands and data sets into the dx dimension.
   *
   * <p>Collapses fixed and relative periods into the pe dimension. Collapses fixed and user
   * organisation units into the ou dimension.
   *
   * @param dimension the dimension identifier.
   * @param date the date used for generating relative periods.
   * @param user the current user.
   * @param dynamicNames whether to use dynamic or static names.
   * @param format the I18nFormat.
   * @return a DimensionalObject.
   */
  protected DimensionalObject getDimensionalObject(
      String dimension,
      Date date,
      User user,
      boolean dynamicNames,
      List<OrganisationUnit> organisationUnitsAtLevel,
      List<OrganisationUnit> organisationUnitsInGroups,
      I18nFormat format) {
    List<NameableObject> items = new ArrayList<>();

    DimensionType type = null;

    List<String> categoryDims = getCategoryDims();

    if (DATA_X_DIM_ID.equals(dimension)) {
      items.addAll(indicators);
      items.addAll(dataElements);
      items.addAll(dataElementOperands);
      items.addAll(dataSets);

      type = DimensionType.DATA_X;
    } else if (PERIOD_DIM_ID.equals(dimension)) {
      setPeriodNames(periods, dynamicNames, format);

      items.addAll(periods);

      if (hasRelativePeriods()) {
        if (rewindRelativePeriods) {
          items.addAll(relatives.getRewindedRelativePeriods(1, date, format, dynamicNames));
        } else {
          items.addAll(relatives.getRelativePeriods(date, format, dynamicNames));
        }
      }

      type = DimensionType.PERIOD;
    } else if (ORGUNIT_DIM_ID.equals(dimension)) {
      items.addAll(organisationUnits);
      items.addAll(transientOrganisationUnits);

      if (userOrganisationUnit && user != null && user.hasOrganisationUnit()) {
        items.add(user.getOrganisationUnit());
      }

      if (userOrganisationUnitChildren && user != null && user.hasOrganisationUnit()) {
        items.addAll(user.getOrganisationUnit().getSortedChildren());
      }

      if (userOrganisationUnitGrandChildren && user != null && user.hasOrganisationUnit()) {
        items.addAll(user.getOrganisationUnit().getSortedGrandChildren());
      }

      if (organisationUnitLevels != null
          && !organisationUnitLevels.isEmpty()
          && organisationUnitsAtLevel != null) {
        items.addAll(organisationUnitsAtLevel); // Must be set externally
      }

      if (itemOrganisationUnitGroups != null
          && !itemOrganisationUnitGroups.isEmpty()
          && organisationUnitsInGroups != null) {
        items.addAll(organisationUnitsInGroups); // Must be set externally
      }

      type = DimensionType.ORGANISATIONUNIT;
    } else if (CATEGORYOPTIONCOMBO_DIM_ID.equals(dimension)) {
      items.addAll(transientCategoryOptionCombos);

      type = DimensionType.CATEGORY_OPTION_COMBO;
    } else if (categoryDims.contains(dimension)) {
      DataElementCategoryDimension categoryDimension =
          categoryDimensions.get(categoryDims.indexOf(dimension));

      items.addAll(categoryDimension.getItems());

      type = DimensionType.CATEGORY;
    } else if (STATIC_DIMS.contains(dimension)) {
      type = DimensionType.STATIC;
    } else {
      // Data element group set

      ListMap<String, NameableObject> deGroupMap = new ListMap<>();

      for (DataElementGroup group : dataElementGroups) {
        if (group.getGroupSet() != null) {
          deGroupMap.putValue(group.getGroupSet().getDimension(), group);
        }
      }

      if (deGroupMap.containsKey(dimension)) {
        items.addAll(deGroupMap.get(dimension));

        type = DimensionType.DATAELEMENT_GROUPSET;
      }

      // Organisation unit group set

      ListMap<String, NameableObject> ouGroupMap = new ListMap<>();

      for (OrganisationUnitGroup group : organisationUnitGroups) {
        if (group.getGroupSet() != null) {
          ouGroupMap.putValue(group.getGroupSet().getUid(), group);
        }
      }

      if (ouGroupMap.containsKey(dimension)) {
        items.addAll(ouGroupMap.get(dimension));

        type = DimensionType.ORGANISATIONUNIT_GROUPSET;
      }

      // Category option group set

      ListMap<String, NameableObject> coGroupMap = new ListMap<>();

      for (CategoryOptionGroup group : categoryOptionGroups) {
        if (group.getGroupSet() != null) {
          coGroupMap.putValue(group.getGroupSet().getUid(), group);
        }
      }

      if (coGroupMap.containsKey(dimension)) {
        items.addAll(coGroupMap.get(dimension));

        type = DimensionType.CATEGORYOPTION_GROUPSET;
      }

      // Tracked entity attribute

      Map<String, TrackedEntityAttributeDimension> attributes = new HashMap<>();

      for (TrackedEntityAttributeDimension attribute : attributeDimensions) {
        attributes.put(attribute.getUid(), attribute);
      }

      if (attributes.containsKey(dimension)) {
        TrackedEntityAttributeDimension tead = attributes.get(dimension);

        return new BaseDimensionalObject(
            dimension,
            DimensionType.TRACKED_ENTITY_ATTRIBUTE,
            null,
            tead.getDisplayName(),
            tead.getLegendSet(),
            tead.getFilter());
      }

      // Tracked entity data element

      Map<String, TrackedEntityDataElementDimension> dataElements = new HashMap<>();

      for (TrackedEntityDataElementDimension dataElement : dataElementDimensions) {
        dataElements.put(dataElement.getUid(), dataElement);
      }

      if (dataElements.containsKey(dimension)) {
        TrackedEntityDataElementDimension tedd = dataElements.get(dimension);

        return new BaseDimensionalObject(
            dimension,
            DimensionType.TRACKED_ENTITY_DATAELEMENT,
            null,
            tedd.getDisplayName(),
            tedd.getLegendSet(),
            tedd.getFilter());
      }
    }

    IdentifiableObjectUtils.removeDuplicates(items);

    return new BaseDimensionalObject(dimension, type, items);
  }