public String execute() {
    if (dataSetId != null) {
      dataSet = dataSetService.getDataSet(dataSetId);

      operands =
          new ArrayList<DataElementOperand>(
              dataElementCategoryService.getFullOperands(dataSet.getDataElements()));
    } else {
      operands = new ArrayList<DataElementOperand>();
    }

    if (key != null) {
      Iterator<DataElementOperand> iterator = operands.iterator();

      while (iterator.hasNext()) {
        DataElementOperand operand = iterator.next();

        if (operand.getOperandName().toLowerCase().indexOf(key.toLowerCase()) == -1) {
          iterator.remove();
        }
      }
    }

    Collections.sort(operands, new DataElementOperandNameComparator());

    if (usePaging) {
      this.paging = createPaging(operands.size());

      operands = operands.subList(paging.getStartPos(), paging.getEndPos());
    }

    return SUCCESS;
  }
Esempio n. 2
0
  @Override
  public Collection<DataElementOperand> filterOperands(
      final Collection<DataElementOperand> operands, final PeriodType periodType) {
    final Collection<DataElementOperand> filteredOperands = new HashSet<>();

    for (final DataElementOperand operand : operands) {
      if (operand.getValueType().equals(VALUE_TYPE_INT)
          && operand.getAggregationOperator().equals(AGGREGATION_OPERATOR_SUM)
          && operand.getFrequencyOrder() <= periodType.getFrequencyOrder()) // Ignore disaggregation
      {
        filteredOperands.add(operand);
      }
    }

    return filteredOperands;
  }
  protected void addDataValue(
      OrganisationUnit unit,
      Period period,
      String expression,
      String value,
      Set<DataValue> oldList,
      Set<DataValue> newList) {
    // value = value.replaceAll( "\\.", "" ).replace( ",", "." );

    DataElementOperand operand =
        expressionService.getOperandsInExpression(expression).iterator().next();

    DataElement dataElement = dataElementService.getDataElement(operand.getDataElementId());

    DataElementCategoryOptionCombo optionCombo =
        categoryService.getDataElementCategoryOptionCombo(operand.getOptionComboId());

    String storedBy = currentUserService.getCurrentUsername();

    DataValue dataValue = dataValueService.getDataValue(unit, dataElement, period, optionCombo);

    if (dataValue == null) {
      dataValue =
          new DataValue(dataElement, period, unit, value, storedBy, new Date(), null, optionCombo);
      dataValueService.addDataValue(dataValue);

      newList.add(dataValue);
    } else {
      DataValue backedUpDataValue =
          new DataValue(dataElement, period, unit, dataValue.getValue(), optionCombo);

      oldList.add(backedUpDataValue);

      dataValue.setValue(value);
      dataValue.setTimestamp(new Date());
      dataValue.setStoredBy(storedBy);

      dataValueService.updateDataValue(dataValue);
    }
  }