Пример #1
0
  private void handleProperties(
      Map<String, Object> mapToFill,
      ArrayList<Map.Entry<String, JsonNode>> itProperties,
      Object returnedValue)
      throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {

    for (int k = 0; k < itProperties.size(); k++) {
      String titleBean = itProperties.get(k).getKey();

      FMDProperty objectProperty =
          fillObjectProperty(
              Lists.newArrayList(itProperties.get(k).getValue().fields()).listIterator());
      if (objectProperty.getTitleBean() == null) {
        objectProperty.setTitleBean(titleBean);
      }

      Object mdsdValue = getReturnedValueFromObject(objectProperty, returnedValue, titleBean);

      if (mdsdValue != null) {

        // if there is not a reference
        if (objectProperty.getReference() == null) {
          String orderObj = getOrderFromEntity(objectProperty.getOrder());
          if (isReadyToPut(objectProperty)) {
            Object valueToPut =
                ((((ValueNode) mdsdValue).getNodeType().toString()).equals("NUMBER"))
                    ? mdsdValue
                    : ((TextNode) mdsdValue).asText();
            mapToFill.put(
                orderObj,
                new FMDescriptor(
                    titleBean,
                    objectProperty.getTitleToVisualize(),
                    objectProperty.getDescription(),
                    valueToPut));
          } else if (objectProperty.getType() != null
              && objectProperty.getType().equals(ARRAY_TYPE)
              && objectProperty.getItems().get(TYPE_FIELD) != null
              && objectProperty.getItems().get(TYPE_FIELD).asText().equals(STRING_TYPE)) {
            ArrayNode values = ((ArrayNode) mdsdValue);
            for (int i = 0, size = values.size(); i < size; i++) {
              values.add(values.get(i).textValue());
            }
            mapToFill.put(
                orderObj,
                new FMDescriptor(
                    titleBean,
                    objectProperty.getTitleToVisualize(),
                    objectProperty.getDescription(),
                    values));
          } else {
            mapToFill.put(
                orderObj,
                new FMDescriptor(
                    titleBean,
                    objectProperty.getTitleToVisualize(),
                    objectProperty.getDescription(),
                    fillRecursive2(itProperties.get(k).getValue().fields(), mdsdValue)));
          }
        }
        // if it is a reference
        else {
          handleReferences(
              objectProperty.getReference(), objectProperty, mapToFill, mdsdValue, false);
        }
      }
    }
  }
Пример #2
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;
  }