+ private List<AttributeDefinition> addImplicitAttributeValues(Resource originResource, UploadComponentInstanceInfo uploadComponentInstanceInfo) {
+ List<String> origAttributes = originResource.getAttributes().stream().map(AttributeDefinition::getName).collect(toList());
+ Map<String, UploadAttributeInfo> uploadAttributes = uploadComponentInstanceInfo.getAttributes();
+ List<String> newAttributesToAdd =
+ uploadAttributes.keySet().stream().filter(newAttribute -> !origAttributes.contains(newAttribute))
+ .collect(toList());
+ List<PropertyDefinition> propsToAddAsAttributes =
+ originResource.getProperties().stream().filter(prop -> newAttributesToAdd.contains(prop.getName())).collect(toList());
+ propsToAddAsAttributes.stream().forEach(prop -> {
+ Object value = uploadAttributes.get(prop.getName()).getValue();
+ if (value instanceof Collection<?> || value instanceof Map<?, ?>) {
+ Gson gson = new Gson();
+ String json = gson.toJson(value);
+ prop.setValue(json);
+ } else {
+ prop.setValue(String.valueOf(value));
+ }
+ });
+ List<AttributeDefinition> attributesToAdd = new ArrayList<>();
+ for (PropertyDefinition prop: propsToAddAsAttributes) {
+ attributesToAdd.add(getPropertyAsAttribute(prop));
+ }
+ return attributesToAdd;
+ }
+
+ private AttributeDefinition getPropertyAsAttribute(PropertyDefinition property) {
+ AttributeDefinition attribute = new AttributeDefinition();
+ attribute.setName(property.getName());
+ attribute.setType(property.getType());
+ attribute.setSchema(property.getSchema());
+ attribute.setValue(property.getValue());
+ attribute.setDefaultValue(property.getDefaultValue());
+ return attribute;
+ }
+