コード例 #1
0
  /**
   * Gets the calculated values as a map of doubles.
   *
   * @param definitions the definitions
   * @param keyValue the key value
   * @return the calculated values
   */
  private static HashMap<Long, Double> getCalculatedValues(
      final List<Definition> definitions, final KeyValue keyValue) {

    HashMap<Long, Double> values = new HashMap<Long, Double>();

    for (Definition def : definitions) {
      double value = 0;

      KeyValue kv =
          KeyValue.findKeyValue(
              def,
              keyValue.getPrimaryRecordId(),
              keyValue.getSecondaryRecordId(),
              keyValue.getTertiaryRecordId());

      if (kv != null) {
        Object kvValue = getKeyValueAsObject(def, kv);

        if (kvValue instanceof Double) {
          value = (Double) kvValue;
        }
      }
      values.put(def.getId(), value);
    }
    return values;
  }
コード例 #2
0
  /**
   * Get the existing key value, or prepare a new key value for calculating.
   *
   * @param def the def
   * @param primaryRecordId the primary record id
   * @param secondaryRecordId the secondary record id
   * @param tertiaryRecordId the tertiary record id
   * @return the key value
   */
  private static KeyValue prepareKeyValue(
      final Definition def,
      final String primaryRecordId,
      final String secondaryRecordId,
      final String tertiaryRecordId) {

    MetahivePreferences preferences = MetahivePreferences.load();

    String primaryId = primaryRecordId;
    String secondaryId = "";
    String tertiaryId = "";

    if (StringUtils.isNotBlank(secondaryRecordId)) {
      secondaryId = parseRecordId(secondaryRecordId);
    }
    if (StringUtils.isNotBlank(tertiaryRecordId)) {
      tertiaryId = parseRecordId(tertiaryRecordId);
    }

    if (StringUtils.isBlank(secondaryId)
        && StringUtils.isNotBlank(preferences.getSecondaryRecordDefault())) {
      secondaryId = preferences.getSecondaryRecordDefault();
    }

    if (StringUtils.isBlank(tertiaryId)
        && StringUtils.isNotBlank(preferences.getTertiaryRecordDefault())) {
      tertiaryId = preferences.getTertiaryRecordDefault();
    }

    Record recd = Record.findRecordByRecordIdEquals(primaryId);

    if (recd == null) {
      throw new IllegalArgumentException("A valid primaryRecordId is required");
    }

    KeyValue kv = KeyValue.findKeyValue(def, primaryId, secondaryId, tertiaryId);

    if (kv != null) {
      logger.info("Key value id: " + kv.getId());
    } else {
      logger.info("Key value is null");
    }

    // If the key value is still null then this is a new record
    if (kv == null) {
      kv = new KeyValue();
      kv.setDefinition(def);
      kv.setRecord(recd);
      kv.setKeyValueType(KeyValueType.CALCULATED);
      kv.setPrimaryRecordId(primaryId);
      kv.setSecondaryRecordId(secondaryId);
      kv.setTertiaryRecordId(tertiaryId);
    }

    return kv;
  }
コード例 #3
0
  /**
   * Gets the summarised values as a list of objects.
   *
   * @param definitions the definitions
   * @param keyValue the key value
   * @return the summarised values
   */
  private static List<Object> getSummarisedValues(
      List<Definition> definitions, final KeyValue keyValue) {

    List<Object> values = new ArrayList<Object>();

    for (Definition def : definitions) {
      KeyValue kv =
          KeyValue.findKeyValue(
              def,
              keyValue.getPrimaryRecordId(),
              keyValue.getSecondaryRecordId(),
              keyValue.getTertiaryRecordId());

      if (kv != null) {
        values.add(getKeyValueAsObject(def, kv));
      }
    }
    return values;
  }