Esempio n. 1
0
  /**
   * Creates a two-dimensional array of dimension items based on the list of DimensionalObjects.
   * I.e. the list of items of each DimensionalObject is converted to an array and inserted into the
   * outer array in the same order.
   *
   * @param dimensions the list of DimensionalObjects.
   * @return a two-dimensional array of NameableObjects.
   */
  public static NameableObject[][] getItemArray(List<DimensionalObject> dimensions) {
    List<NameableObject[]> arrays = new ArrayList<>();

    for (DimensionalObject dimension : dimensions) {
      arrays.add(dimension.getItems().toArray(new NameableObject[0]));
    }

    return arrays.toArray(new NameableObject[0][]);
  }
Esempio n. 2
0
  /**
   * Creates a list of dimension identifiers based on the given list of DimensionalObjects.
   *
   * @param dimensions the list of DimensionalObjects.
   * @return list of dimension identifiers.
   */
  public static List<String> getDimensions(List<DimensionalObject> dimensions) {
    List<String> dims = new ArrayList<>();

    if (dimensions != null) {
      for (DimensionalObject dimension : dimensions) {
        dims.add(dimension.getDimension());
      }
    }

    return dims;
  }
Esempio n. 3
0
  /** Indicates whether at least one of the given dimenions has at least one item. */
  public static boolean anyDimensionHasItems(Collection<DimensionalObject> dimensions) {
    if (dimensions == null || dimensions.isEmpty()) {
      return false;
    }

    for (DimensionalObject dim : dimensions) {
      if (dim.hasItems()) {
        return true;
      }
    }

    return false;
  }
Esempio n. 4
0
  @Override
  public List<NameableObject> series() {
    DimensionalObject object =
        getDimensionalObject(
            series,
            relativePeriodDate,
            user,
            true,
            organisationUnitsAtLevel,
            organisationUnitsInGroups,
            format);

    return object != null ? object.getItems() : null;
  }
Esempio n. 5
0
  /**
   * Creates a unique list of dimension identifiers based on the given list of DimensionalObjects.
   *
   * @param dimensions the list of DimensionalObjects.
   * @return list of dimension identifiers.
   */
  public static List<String> getUniqueDimensions(List<DimensionalObject> dimensions) {
    List<String> dims = new ArrayList<>();

    if (dimensions != null) {
      for (DimensionalObject dimension : dimensions) {
        String dim = toDimension(dimension.getDimension());

        if (dim != null && !dims.contains(dim)) {
          dims.add(dim);
        }
      }
    }

    return dims;
  }
Esempio n. 6
0
  /**
   * Sets items on the given dimension based on the unique values of the matching column in the
   * given grid. Items are BaseNameableObjects where the name, code and short name properties are
   * set to the column value. The dimension analytics type must be equal to EVENT.
   *
   * @param dimension the dimension.
   * @param naForNull indicates whether a [n/a] string should be used as replacement for null
   *     values.
   * @param grid the grid with data values.
   */
  public static void setDimensionItemsForFilters(
      DimensionalObject dimension, Grid grid, boolean naForNull) {
    if (dimension == null
        || grid == null
        || !AnalyticsType.EVENT.equals(dimension.getAnalyticsType())) {
      return;
    }

    BaseDimensionalObject dim = (BaseDimensionalObject) dimension;

    List<String> filterItems = dim.getFilterItemsAsList();

    List<Object> values = new ArrayList<>(grid.getUniqueValues(dim.getDimension()));

    Collections.sort(values, ObjectStringValueComparator.INSTANCE);

    // Use order of items in filter if specified

    List<?> itemList = filterItems != null ? ListUtils.retainAll(filterItems, values) : values;

    List<NameableObject> items = NameableObjectUtils.getNameableObjects(itemList, naForNull);

    dim.setItems(items);
  }