package org.openecomp.sdc.be.components.property;
-import static org.openecomp.sdc.common.api.Constants.GET_INPUT;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
-import java.util.stream.Collectors;
-
+import com.google.gson.Gson;
+import fj.data.Either;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.json.simple.JSONObject;
import org.openecomp.sdc.be.datatypes.elements.PropertiesOwner;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.model.Component;
-import org.openecomp.sdc.be.model.ComponentInstancePropInput;
-import org.openecomp.sdc.be.model.IComponentInstanceConnectedElement;
-import org.openecomp.sdc.be.model.InputDefinition;
-import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.*;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
+import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.exception.ResponseFormat;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.Yaml;
-import com.google.gson.Gson;
+import java.util.*;
+import java.util.stream.Collectors;
-import fj.data.Either;
+import static org.openecomp.sdc.common.api.Constants.GET_INPUT;
-public abstract class DefaultPropertyDecelerator<PROPERTYOWNER extends PropertiesOwner, PROPERTYTYPE extends PropertyDataDefinition> implements PropertyDecelerator {
+public abstract class DefaultPropertyDeclarator<PROPERTYOWNER extends PropertiesOwner, PROPERTYTYPE extends PropertyDataDefinition> implements PropertyDeclarator {
- private static final Logger log = LoggerFactory.getLogger(DefaultPropertyDecelerator.class);
+ private static final Logger log = Logger.getLogger(DefaultPropertyDeclarator.class);
private static final short LOOP_PROTECTION_LEVEL = 10;
private final Gson gson = new Gson();
private ComponentsUtils componentsUtils;
private PropertyOperation propertyOperation;
- public DefaultPropertyDecelerator(ComponentsUtils componentsUtils, PropertyOperation propertyOperation) {
+ public DefaultPropertyDeclarator(ComponentsUtils componentsUtils, PropertyOperation propertyOperation) {
this.componentsUtils = componentsUtils;
this.propertyOperation = propertyOperation;
}
abstract Optional<PROPERTYOWNER> resolvePropertiesOwner(Component component, String propertiesOwnerId);
- abstract void addPropertiesListToInput(PROPERTYTYPE declaredProp, PropertyDataDefinition originalProp, InputDefinition input);
+ abstract void addPropertiesListToInput(PROPERTYTYPE declaredProp, InputDefinition input);
private StorageOperationStatus onPropertiesOwnerNotFound(String componentId, String propertiesOwnerId) {
log.debug("#declarePropertiesAsInputs - properties owner {} was not found on component {}", propertiesOwnerId, componentId);
return StorageOperationStatus.NOT_FOUND;
}
- private Either<List<InputDefinition>, StorageOperationStatus> declarePropertiesAsInputs(Component component, PropertiesOwner propertiesOwner, List<ComponentInstancePropInput> propsToDeclare) {
+ private Either<List<InputDefinition>, StorageOperationStatus> declarePropertiesAsInputs(Component component, PROPERTYOWNER propertiesOwner, List<ComponentInstancePropInput> propsToDeclare) {
PropertiesDeclarationData inputsProperties = createInputsAndOverridePropertiesValues(component.getUniqueId(), propertiesOwner, propsToDeclare);
return updatePropertiesValues(component, propertiesOwner.getUniqueId(), inputsProperties.getPropertiesToUpdate())
.left()
.map(updatePropsRes -> inputsProperties.getInputsToCreate());
}
- private PropertiesDeclarationData createInputsAndOverridePropertiesValues(String componentId, PropertiesOwner propertiesOwner, List<ComponentInstancePropInput> propsToDeclare) {
+ private PropertiesDeclarationData createInputsAndOverridePropertiesValues(String componentId, PROPERTYOWNER propertiesOwner, List<ComponentInstancePropInput> propsToDeclare) {
List<PROPERTYTYPE> declaredProperties = new ArrayList<>();
List<InputDefinition> createdInputs = propsToDeclare.stream()
.map(propInput -> declarePropertyInput(componentId, propertiesOwner, declaredProperties, propInput))
return new PropertiesDeclarationData(createdInputs, declaredProperties);
}
- private InputDefinition declarePropertyInput(String componentId, PropertiesOwner propertiesOwner, List<PROPERTYTYPE> declaredProperties, ComponentInstancePropInput propInput) {
+ private InputDefinition declarePropertyInput(String componentId, PROPERTYOWNER propertiesOwner, List<PROPERTYTYPE> declaredProperties, ComponentInstancePropInput propInput) {
PropertyDataDefinition prop = resolveProperty(declaredProperties, propInput);
propInput.setOwnerId(null);
propInput.setParentUniqueId(null);
if(!declaredProperties.contains(declaredProperty)){
declaredProperties.add(declaredProperty);
}
- addPropertiesListToInput(declaredProperty, prop, inputDefinition);
+ addPropertiesListToInput(declaredProperty, inputDefinition);
return inputDefinition;
}
- private InputDefinition createInput(String componentId, PropertiesOwner propertiesOwner, ComponentInstancePropInput propInput, PropertyDataDefinition prop) {
+ private InputDefinition createInput(String componentId, PROPERTYOWNER propertiesOwner, ComponentInstancePropInput propInput, PropertyDataDefinition prop) {
String generatedInputName = generateInputName(propertiesOwner.getNormalizedName(), propInput);
return createInputFromProperty(componentId, propertiesOwner, generatedInputName, propInput, prop);
}
return resolvedProperty.isPresent() ? resolvedProperty.get() : propInput;
}
- private InputDefinition createInputFromProperty(String componentId, PropertiesOwner propertiesOwner, String inputName, ComponentInstancePropInput propInput, PropertyDataDefinition prop) {
+ InputDefinition createInputFromProperty(String componentId, PROPERTYOWNER propertiesOwner, String inputName, ComponentInstancePropInput propInput, PropertyDataDefinition prop) {
String propertiesName = propInput.getPropertiesName() ;
PropertyDefinition selectedProp = propInput.getInput();
String[] parsedPropNames = propInput.getParsedPropNames();
if(propertiesName != null && !propertiesName.isEmpty() && selectedProp != null){
complexProperty = true;
input = new InputDefinition(selectedProp);
+ input.setDefaultValue(selectedProp.getValue());
}else{
input = new InputDefinition(prop);
+ input.setDefaultValue(prop.getValue());
}
- input.setDefaultValue(prop.getValue());
input.setName(inputName);
input.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(componentId, input.getName()));
input.setInputPath(propertiesName);
input.setInstanceUniqueId(propertiesOwner.getUniqueId());
input.setPropertyId(propInput.getUniqueId());
+ input.setValue(null);
changePropertyValueToGetInputValue(inputName, parsedPropNames, input, prop, complexProperty);
((IComponentInstanceConnectedElement)prop).setComponentInstanceId(propertiesOwner.getUniqueId());
((IComponentInstanceConnectedElement)prop).setComponentInstanceName(propertiesOwner.getName());
* @return mutated @param toscaElement , where empty maps are deleted , return null for empty map.
**/
private Object cleanEmptyNestedValuesInMap(Object toscaElement , short loopProtectionLevel ){
- //region - Stop if map is empty
if (loopProtectionLevel<=0 || toscaElement==null || !(toscaElement instanceof Map))
return toscaElement;
- //endregion
- //region - Remove empty map entries & return null iff empty map
if ( MapUtils.isNotEmpty( (Map)toscaElement ) ) {
Object ret;
Set<Object> keysToRemove = new HashSet<>(); // use different set to avoid ConcurrentModificationException
if (CollectionUtils.isNotEmpty(set))
set.removeAll(keysToRemove);
- if ( isEmptyNestedMap(toscaElement) ) // similar to < if ( MapUtils.isEmpty( (Map)toscaElement ) ) > ,but adds nested map check
+ if ( isEmptyNestedMap(toscaElement) )
return null;
}
- //endregion
else
return null;
return toscaElement;