test_class.declarator: converter
test_class.modifier: private
test_class.original_string: private ToscaTypeConverter converter;
test_class.type: ToscaTypeConverter
test_class.var_name: converter
test_class.file: alien4cloud-core/src/test/java/org/alien4cloud/tosca/variable/ToscaTypeConverterTest.java
test_class.identifier: ToscaTypeConverterTest
test_case.body: @Test
      public void convert_time_to_property_value() throws Exception {
          PropertyDefinition propertyDefinition = new PropertyDefinition();
          propertyDefinition.setType(ToscaTypes.TIME);
  
          PropertyValue propertyValue = converter.toPropertyValue("2 d", propertyDefinition);
  
          Object time = ToscaTypes.fromYamlTypeName(propertyDefinition.getType()).parse(propertyValue.getValue().toString());
          assertThat(time).isInstanceOf(Time.class);
          assertThat(time).isEqualTo(new Time(2, TimeUnit.D));
      }
test_case.class_method_signature: ToscaTypeConverterTest.convert_time_to_property_value()
test_case.full_signature: @Test public void convert_time_to_property_value()
test_case.identifier: convert_time_to_property_value
test_case.invocations: setType toPropertyValue parse fromYamlTypeName getType toString getValue isInstanceOf assertThat isEqualTo assertThat
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void convert_time_to_property_value()
focal_class.declarator: dataTypeFinder
focal_class.modifier: private
focal_class.original_string: private DataTypesFetcher.DataTypeFinder dataTypeFinder;
focal_class.type: DataTypesFetcher.DataTypeFinder
focal_class.var_name: dataTypeFinder
focal_class.file: alien4cloud-core/src/main/java/org/alien4cloud/tosca/variable/ToscaTypeConverter.java
focal_class.identifier: ToscaTypeConverter
focal_class.class_method_signature: ToscaTypeConverter.ToscaTypeConverter(DataTypesFetcher.DataTypeFinder dataTypeFinder)
focal_class.full_signature: public  ToscaTypeConverter(DataTypesFetcher.DataTypeFinder dataTypeFinder)
focal_class.identifier: ToscaTypeConverter
focal_class.modifiers: public
focal_class.parameters: (DataTypesFetcher.DataTypeFinder dataTypeFinder)
focal_class.signature:  ToscaTypeConverter(DataTypesFetcher.DataTypeFinder dataTypeFinder)
focal_class.class_method_signature: ToscaTypeConverter.toPropertyValue(Object resolvedPropertyValue, PropertyDefinition propertyDefinition)
focal_class.full_signature: @SuppressWarnings("unchecked") public PropertyValue toPropertyValue(Object resolvedPropertyValue, PropertyDefinition propertyDefinition)
focal_class.identifier: toPropertyValue
focal_class.modifiers: @SuppressWarnings("unchecked") public
focal_class.parameters: (Object resolvedPropertyValue, PropertyDefinition propertyDefinition)
focal_class.return: PropertyValue
focal_class.signature: PropertyValue toPropertyValue(Object resolvedPropertyValue, PropertyDefinition propertyDefinition)
focal_class.class_method_signature: ToscaTypeConverter.findDataType(String type)
focal_class.full_signature: private DataType findDataType(String type)
focal_class.identifier: findDataType
focal_class.modifiers: private
focal_class.parameters: (String type)
focal_class.return: DataType
focal_class.signature: DataType findDataType(String type)
focal_method.body: @SuppressWarnings("unchecked")
      public PropertyValue toPropertyValue(Object resolvedPropertyValue, PropertyDefinition propertyDefinition) {
          if (resolvedPropertyValue == null) {
              return null;
          }
  
          if (ToscaTypes.isSimple(propertyDefinition.getType())) {
              return new ScalarPropertyValue(resolvedPropertyValue.toString());
          }
  
          switch (propertyDefinition.getType()) {
              case ToscaTypes.MAP:
                  if (resolvedPropertyValue instanceof Map) {
                      Map<String, Object> map = (Map<String, Object>) resolvedPropertyValue;
                      Map<String, Object> resultMap = Maps.newHashMap();
                      map.forEach((key, value) -> resultMap.put(key, toPropertyValue(value, propertyDefinition.getEntrySchema())));
                      return new ComplexPropertyValue(resultMap);
                  } else {
                  throw new IllegalStateException(
                          "Property value: expected type [" + Map.class.getSimpleName() + "] but got [" + resolvedPropertyValue.getClass().getName() + "]");
                  }
  
              case ToscaTypes.LIST:
                  if (resolvedPropertyValue instanceof Collection) {
                      List list = (List) resolvedPropertyValue;
                      List resultList = new LinkedList();
                      for (Object item : list) {
                          resultList.add(toPropertyValue(item, propertyDefinition.getEntrySchema()));
                      }
                      return new ListPropertyValue(resultList);
                  } else {
                  throw new IllegalStateException("Property value: expected type [" + Collection.class.getSimpleName() + "] but got ["
                          + resolvedPropertyValue.getClass().getName() + "]");
                  }
  
              default:
                  DataType dataType = findDataType(propertyDefinition.getType());
  
                  if (dataType == null) {
                  throw new NotFoundException("Data type  [" + propertyDefinition.getType() + "] cannot be found");
                  }
  
                  if (dataType.isDeriveFromSimpleType()) {
                      return new ScalarPropertyValue(resolvedPropertyValue.toString());
                  } else if (resolvedPropertyValue instanceof Map) {
                      Map<String, Object> map = (Map<String, Object>) resolvedPropertyValue;
                      /*
                   * Map<String, Object> resultMap = Maps.newHashMap();
                   * 
                   * map.forEach((key, value) -> {
                   * PropertyDefinition entryDefinition = dataType.getProperties().get(key);
                   * if(entryDefinition == null){
                   * throw new IllegalStateException("DataType [" + propertyDefinition.getType() + "] does not contains any definition for entry [" + key + "]");
                   * }
                   * resultMap.put(key, toPropertyValue(value, entryDefinition));
                   * });
                   * return new ComplexPropertyValue(resultMap);
                   */
                      return new ComplexPropertyValue(map);
                  } else {
                  throw new IllegalStateException(
                          "Property value: expected type [" + propertyDefinition.getType() + "] but got [" + resolvedPropertyValue.getClass().getName() + "]");
                  }
          }
  
      }
focal_method.class_method_signature: ToscaTypeConverter.toPropertyValue(Object resolvedPropertyValue, PropertyDefinition propertyDefinition)
focal_method.full_signature: @SuppressWarnings("unchecked") public PropertyValue toPropertyValue(Object resolvedPropertyValue, PropertyDefinition propertyDefinition)
focal_method.identifier: toPropertyValue
focal_method.invocations: isSimple getType toString getType newHashMap forEach put toPropertyValue getEntrySchema getSimpleName getName getClass add toPropertyValue getEntrySchema getSimpleName getName getClass findDataType getType getType isDeriveFromSimpleType toString getType getName getClass
focal_method.modifiers: @SuppressWarnings("unchecked") public
focal_method.parameters: (Object resolvedPropertyValue, PropertyDefinition propertyDefinition)
focal_method.return: PropertyValue
focal_method.signature: PropertyValue toPropertyValue(Object resolvedPropertyValue, PropertyDefinition propertyDefinition)