コード例 #1
0
  private void handleReferences(
      String reference,
      FMDProperty objectReference,
      Map<String, Object> mapToFill,
      Object returnedValue,
      boolean isArray)
      throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {

    JsonNode mdsdNode = getMdsdObjectFromReference(reference);
    if (mdsdNode.get(TYPE_FIELD) != null && mdsdNode.get(TYPE_FIELD).asText().equals(OBJECT_TYPE)) {
      if (mdsdNode.get(PROPERTIES_FIELD) != null) {
        ArrayList<Map.Entry<String, JsonNode>> itProperties =
            Lists.newArrayList(mdsdNode.get(PROPERTIES_FIELD).fields());

        if (isArray) {
          ArrayList<Object> values = (ArrayList<Object>) returnedValue;
          for (int z = 0; z < values.size(); z++) {
            handleProperties(mapToFill, itProperties, values.get(z));
          }
        } else {
          if (objectReference != null) {
            objectReference.setOrder(getOrderFromEntity(objectReference.getOrder()));
            Map<String, Object> mapToFill2 = new TreeMap<String, Object>();
            handleProperties(mapToFill2, itProperties, returnedValue);
            mapToFill.put(
                objectReference.getOrder(),
                new FMDescriptor(
                    objectReference.getTitleBean(),
                    objectReference.getTitleToVisualize(),
                    objectReference.getDescription(),
                    mapToFill2));
          }

          /*
                              handleProperties(mapToFill, itProperties, returnedValue);
          */
        }
      }
    } else if (mdsdNode.get(ENUM_FIELD) != null) {
      if (objectReference != null) {
        handleEnum(mapToFill, returnedValue, objectReference);
      } else {
        System.out.println("let's see");
      }
    }
  }
コード例 #2
0
  private ArrayList<String> fillOjCode(ArrayList<OjCode> values) {
    ArrayList<String> mapToFill = new ArrayList<String>();
    for (int h = 0; h < values.size(); h++) {
      String value =
          (values.get(h).getLabel() != null)
              ? values.get(h).getLabel().get(LANG.toUpperCase())
              : "";

      if (value == null) {
        value =
            (values.get(h).getLabel() != null)
                ? values.get(h).getLabel().get(DEFAULT_LANG.toUpperCase())
                : "";
      }
      mapToFill.add(values.get(h).getCode() + " - " + value);
    }
    return mapToFill;
  }
コード例 #3
0
  private Object fillRecursive2(Iterator<Map.Entry<String, JsonNode>> fields, Object returnedValue)
      throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {

    Map<String, Object> tempMap = new TreeMap<String, Object>();
    ListIterator<Map.Entry<String, JsonNode>> listBack = Lists.newArrayList(fields).listIterator();
    FMDProperty resultObj = fillObjectProperty(listBack);
    String type = resultObj.getType();

    if (type != null) {
      /** STRING OR NUMBER* */
      if (type.equals(STRING_TYPE) || type.equals(NUMBER_TYPE)) {
        Object valueStringType =
            invokeMethodByReflection(resultObj.getTitleBean(), returnedValue, false);
        if (valueStringType != null && !valueStringType.toString().equals("")) {
          tempMap.put(
              resultObj.getOrder(),
              new FMDescriptor(
                  resultObj.getTitleBean(),
                  resultObj.getTitleToVisualize(),
                  resultObj.getDescription(),
                  valueStringType));
          return tempMap;
        }
      }

      /** OBJECT * */
      else if (type.equals(OBJECT_TYPE)) {

        // 1) PROPERTIES
        if (resultObj.getProperties() != null) {
          ArrayList<Map.Entry<String, JsonNode>> itProperties =
              (ArrayList<Map.Entry<String, JsonNode>>) resultObj.getProperties();
          handleProperties(tempMap, itProperties, returnedValue);
        }

        // 2) PATTERN PROPERTIES
        else if (resultObj.getProperties() == null && resultObj.getPatternProperties() != null) {
          Object valueObjPatternType =
              invokeMethodByReflection(resultObj.getTitleBean(), returnedValue, true);
          if (valueObjPatternType != null) {

            if (resultObj.getPatternProperties().equals(STRING_TYPE)) {
              String orderObj = getOrderFromEntity(resultObj.getOrder());
              tempMap.put(
                  orderObj,
                  new FMDescriptor(
                      resultObj.getTitleBean(),
                      resultObj.getTitleToVisualize(),
                      resultObj.getDescription(),
                      valueObjPatternType));
            } else {
              // TODO(FREEZED): there is not a type different from string
              System.out.println("here!");
            }
          }
        }

        // 3) REF PROPERTY
        else if (resultObj.getProperties() == null
            && resultObj.getPatternProperties() == null
            && resultObj.getReference() != null) {
          handleReferences(resultObj.getReference(), resultObj, tempMap, returnedValue, false);
          return tempMap;
        }
      }

      /** ARRAY* */
      else if (type.equals(ARRAY_TYPE)) {

        ArrayList<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
        ArrayList<Object> values = (ArrayList<Object>) returnedValue;

        JsonNode items = ((ObjectNode) resultObj.getItems()).deepCopy();
        if (items.get(TYPE_FIELD) != null) {
          if (items.get(TYPE_FIELD).asText().equals(STRING_TYPE)) {
            String orderGlobal = getOrderFromEntity(resultObj.getOrder());

            for (int arrCounter = 0; arrCounter < values.size(); arrCounter++) {
              Map<String, Object> tmp = new TreeMap<String, Object>();
              String order = getOrderFromEntity(resultObj.getOrder());
              tmp.put(order, values.get(arrCounter));
              result.add(tmp);
            }
            tempMap.put(orderGlobal, result);
          }
        } else if (items.get(REF_FIELD) != null) {
          String orderGlobal = getOrderFromEntity(resultObj.getOrder());

          String ref = items.get(REF_FIELD).asText();
          String[] refSplitted = ref.substring(2).split("/");

          // OJCODE case
          if (refSplitted[refSplitted.length - 1].equals(OJCODE_TYPE)) {
            tempMap.put(
                orderGlobal,
                new FMDescriptor(
                    refSplitted[refSplitted.length - 1],
                    resultObj.getTitleToVisualize(),
                    resultObj.getDescription(),
                    fillOjCode((ArrayList<OjCode>) returnedValue)));
          } else {
            handleReferences(items.get(REF_FIELD).asText(), null, tempMap, returnedValue, true);
            return tempMap;
          }
        }
      }
    } else {
      if (resultObj.getReference() != null) {
        handleReferences(resultObj.getReference(), resultObj, tempMap, returnedValue, false);
      }
    }

    return tempMap;
  }