aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--catalog-be/pom.xml5
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java169
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java93
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java41
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogic.java266
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java19
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/property/ComponentInstanceInputPropertyDeclarator.java28
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/property/ComponentInstancePropertyDeclarator.java15
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/property/ComponentPropertyDeclarator.java19
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/property/DefaultPropertyDeclarator.java118
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/property/GroupPropertyDeclarator.java23
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/property/PolicyPropertyDeclarator.java21
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/property/PropertyDeclarationOrchestrator.java64
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/property/PropertyDeclarator.java21
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/property/propertytopolicydeclarators/ComponentInstancePropertyToPolicyDeclarator.java81
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/property/propertytopolicydeclarators/ComponentPropertyToPolicyDeclarator.java137
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/PolicyUtils.java31
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java4
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java44
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/mixin/PolicyCompositionMixin.java11
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java30
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/BeGenericServlet.java114
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InputsServlet.java91
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/PolicyServlet.java76
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java683
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogicTest.java52
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyPropertiesBusinessLogicTest.java29
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentPropertyToPolicyDeclaratorTest.java137
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PropertyDecelerationOrchestratorTest.java2
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/property/propertytopolicydeclarators/ComponentInstancePropertyToPolicyDeclaratorTest.java149
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/servlets/JerseySpringBaseTest.java24
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/servlets/PolicyServletTest.java177
-rw-r--r--catalog-model/pom.xml13
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java82
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstInputsMap.java56
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentParametersView.java208
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/PolicyDefinition.java11
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/ToscaFunctions.java3
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/ToscaType.java4
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/ConstraintUtil.java4
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/DataTypePropertyConverter.java9
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/ToscaConverterUtils.java6
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/ToscaMapValueConverter.java24
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/ComponentInstInputsMapTest.java4
-rw-r--r--catalog-ui/src/app/models/graph/zones/policy-instance.ts2
-rw-r--r--catalog-ui/src/app/models/properties-inputs/property-be-model.ts15
-rw-r--r--catalog-ui/src/app/ng2/components/logic/policies-table/policies-table.component.html48
-rw-r--r--catalog-ui/src/app/ng2/components/logic/policies-table/policies-table.component.less169
-rw-r--r--catalog-ui/src/app/ng2/components/logic/policies-table/policies-table.component.ts100
-rw-r--r--catalog-ui/src/app/ng2/components/logic/policies-table/policies-table.module.ts41
-rw-r--r--catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.module.ts2
-rw-r--r--catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.html22
-rw-r--r--catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.less11
-rw-r--r--catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.ts73
-rw-r--r--catalog-ui/src/app/ng2/pages/properties-assignment/services/properties.utils.ts4
-rw-r--r--catalog-ui/src/app/ng2/services/component-services/component.service.ts26
-rw-r--r--catalog-ui/src/assets/languages/en_US.json4
-rw-r--r--common-app-api/src/main/java/org/openecomp/sdc/common/api/Constants.java1
-rw-r--r--common-be/pom.xml12
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/GetPolicyValueDataDefinition.java17
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/PolicyDataDefinition.java34
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/PropertyDataDefinition.java44
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/DeclarationTypeEnum.java6
-rw-r--r--pom.xml6
64 files changed, 2955 insertions, 880 deletions
diff --git a/catalog-be/pom.xml b/catalog-be/pom.xml
index 8586235b5b..8e5ed15155 100644
--- a/catalog-be/pom.xml
+++ b/catalog-be/pom.xml
@@ -611,6 +611,11 @@
<artifactId>commons-collections4</artifactId>
<version>${commons.collections.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.codehaus.jackson</groupId>
+ <artifactId>jackson-mapper-asl</artifactId>
+ <version>${jackson.mapper.version}</version>
+ </dependency>
</dependencies>
<build>
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java
index 65f1e4981a..49dd3d6c01 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java
@@ -21,17 +21,15 @@
package org.openecomp.sdc.be.components.impl;
import com.google.gson.JsonElement;
-
+import fj.data.Either;
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
-
-import fj.data.Either;
-import org.apache.commons.lang3.ArrayUtils;
-import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.validation.UserValidations;
@@ -46,8 +44,10 @@ import org.openecomp.sdc.be.datatypes.elements.PropertyRule;
import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstInputsMap;
import org.openecomp.sdc.be.model.ComponentParametersView;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.IComplexDefaultValue;
@@ -95,6 +95,7 @@ public abstract class BaseBusinessLogic {
private static final String SCHEMA_DOESN_T_EXISTS_FOR_PROPERTY_OF_TYPE = "Schema doesn't exists for property of type {}";
private static final String PROPERTY_IN_SCHEMA_DEFINITION_INSIDE_PROPERTY_OF_TYPE_DOESN_T_EXIST = "Property in Schema Definition inside property of type {} doesn't exist";
private static final String ADD_PROPERTY_VALUE = "Add property value";
+ private static final String THE_VALUE_OF_PROPERTY_FROM_TYPE_IS_INVALID = "The value {} of property from type {} is invalid";
@Autowired
protected ComponentsUtils componentsUtils;
@@ -147,6 +148,9 @@ public abstract class BaseBusinessLogic {
protected InterfaceOperation interfaceOperation;
@Autowired
+ protected InterfaceOperationBusinessLogic interfaceOperationBusinessLogic;
+
+ @Autowired
protected InterfaceLifecycleOperation interfaceLifecycleTypeOperation;
@javax.annotation.Resource
@@ -175,6 +179,10 @@ public abstract class BaseBusinessLogic {
this.toscaOperationFacade = toscaOperationFacade;
}
+ public void setPolicyTypeOperation(PolicyTypeOperation policyTypeOperation) {
+ this.policyTypeOperation = policyTypeOperation;
+ }
+
public void setDataTypeCache(ApplicationDataTypeCache dataTypeCache) {
this.dataTypeCache = dataTypeCache;
}
@@ -183,6 +191,14 @@ public abstract class BaseBusinessLogic {
this.propertyOperation = propertyOperation;
}
+ public void setInterfaceOperation(InterfaceOperation interfaceOperation) {
+ this.interfaceOperation = interfaceOperation;
+ }
+ public void setInterfaceOperationBusinessLogic(InterfaceOperationBusinessLogic interfaceOperationBusinessLogic) {
+ this.interfaceOperationBusinessLogic = interfaceOperationBusinessLogic;
+ }
+
+
User validateUserNotEmpty(User user, String ecompErrorContext) {
return userValidations.validateUserNotEmpty(user, ecompErrorContext);
}
@@ -191,10 +207,15 @@ public abstract class BaseBusinessLogic {
return userValidations.validateUserExists(user.getUserId(), ecompErrorContext, inTransaction);
}
- void validateUserExist(String userId, String ecompErrorContext) {
- userValidations.validateUserExist(userId, ecompErrorContext);
+ protected void validateUserExist(String userId, String ecompErrorContext) {
+ userValidations.validateUserExist(userId, ecompErrorContext);
}
+ public void setGroupTypeOperation(IGroupTypeOperation groupTypeOperation) {
+ this.groupTypeOperation = groupTypeOperation;
+ }
+
+
Either<User, ActionStatus> validateUserExistsActionStatus(String userId, String ecompErrorContext) {
return userValidations.validateUserExistsActionStatus(userId, ecompErrorContext);
}
@@ -326,7 +347,9 @@ public abstract class BaseBusinessLogic {
String propertyType = property.getType();
String innerType = getInnerType(property);
// Specific Update Logic
- Either<Object, Boolean> isValid = propertyOperation.validateAndUpdatePropertyValue(propertyType, property.getValue(), true, innerType, allDataTypes);
+ Either<Object, Boolean> isValid =
+ propertyOperation.validateAndUpdatePropertyValue(propertyType, (String) property.getValue(), true,
+ innerType, allDataTypes);
String newValue = property.getValue();
if (isValid.isRight()) {
Boolean res = isValid.right().value();
@@ -436,7 +459,7 @@ public abstract class BaseBusinessLogic {
ImmutablePair<String, Boolean> propertyInnerTypeValid = propertyOperation.isPropertyInnerTypeValid(property, dataTypes);
innerType = propertyInnerTypeValid.getLeft();
if (!propertyInnerTypeValid.getRight()) {
- log.info("Invalid inner type for property {} type {}", property.getName(), property.getType());
+ log.info("Invalid inner type for property {} type {}, dataTypeCount {}", property.getName(), property.getType(), dataTypes.size());
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_PROPERTY_INNER_TYPE, innerType, property.getName());
return Either.right(responseFormat);
}
@@ -445,9 +468,11 @@ public abstract class BaseBusinessLogic {
log.info("Invalid default value for property {} type {}", property.getName(), property.getType());
ResponseFormat responseFormat;
if (type.equals(ToscaPropertyType.LIST.getType()) || type.equals(ToscaPropertyType.MAP.getType())) {
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_COMPLEX_DEFAULT_VALUE, property.getName(), type, innerType, property.getDefaultValue());
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_COMPLEX_DEFAULT_VALUE, property.getName(), type, innerType,
+ property.getDefaultValue());
} else {
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_DEFAULT_VALUE, property.getName(), type, property.getDefaultValue());
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_DEFAULT_VALUE, property.getName(), type,
+ property.getDefaultValue());
}
return Either.right(responseFormat);
@@ -611,7 +636,7 @@ public abstract class BaseBusinessLogic {
DataTypeDefinition dataTypeDefinition = dataTypes.get(propertyType);
ImmutablePair<JsonElement, Boolean> validateResult = dataTypeValidatorConverter.validateAndUpdate(value, dataTypeDefinition, dataTypes);
if (Boolean.FALSE.equals(validateResult.right)) {
- log.debug("The value {} of property from type {} is invalid", value, propertyType);
+ log.debug(THE_VALUE_OF_PROPERTY_FROM_TYPE_IS_INVALID, value, propertyType);
return Either.right(false);
}
JsonElement jsonElement = validateResult.left;
@@ -621,7 +646,7 @@ public abstract class BaseBusinessLogic {
log.trace("before validating property type {}", propertyType);
boolean isValidProperty = isValidValue(type, value, innerType, dataTypes);
if (!isValidProperty) {
- log.debug("The value {} of property from type {} is invalid", value, type);
+ log.debug(THE_VALUE_OF_PROPERTY_FROM_TYPE_IS_INVALID, value, type);
return Either.right(false);
}
}
@@ -683,64 +708,70 @@ public abstract class BaseBusinessLogic {
}
return jsonElement.toString();
}
-
- void rollbackWithException(ActionStatus actionStatus, String... params) {
+
+ protected void rollbackWithException(ActionStatus actionStatus, String... params) {
titanDao.rollback();
throw new ComponentException(actionStatus, params);
}
- public <T extends PropertyDataDefinition> List<PropertyConstraint> setInputConstraint(T inputDefinition) {
- if (StringUtils.isNotBlank(inputDefinition.getParentPropertyType())
- && StringUtils.isNotBlank(inputDefinition.getSubPropertyInputPath())) {
- return setConstraint(inputDefinition);
- }
-
- return Collections.emptyList();
- }
-
- private <T extends PropertyDataDefinition> List<PropertyConstraint> setConstraint(T inputDefinition) {
- List<PropertyConstraint> constraints = new ArrayList<>();
- String[] inputPathArr = inputDefinition.getSubPropertyInputPath().split("#");
- if (inputPathArr.length > 1) {
- inputPathArr = ArrayUtils.remove(inputPathArr, 0);
- }
-
- Map<String, DataTypeDefinition> dataTypeDefinitionMap =
- applicationDataTypeCache.getAll().left().value();
-
- String propertyType = inputDefinition.getParentPropertyType();
-
- for (String anInputPathArr : inputPathArr) {
- if (ToscaType.isPrimitiveType(propertyType)) {
- constraints.addAll(
- dataTypeDefinitionMap.get(propertyType).getConstraints());
- } else if (!ToscaType.isCollectionType(propertyType)) {
- propertyType = setConstraintForComplexType(dataTypeDefinitionMap, propertyType, anInputPathArr,
- constraints);
- }
- }
-
- return constraints;
- }
-
- private String setConstraintForComplexType(Map<String, DataTypeDefinition> dataTypeDefinitionMap,
- String propertyType,
- String anInputPathArr,
- List<PropertyConstraint> constraints) {
- String type = null;
- List<PropertyDefinition> propertyDefinitions =
- dataTypeDefinitionMap.get(propertyType).getProperties();
- for (PropertyDefinition propertyDefinition : propertyDefinitions) {
- if (propertyDefinition.getName().equals(anInputPathArr)) {
- if (ToscaType.isPrimitiveType(propertyDefinition.getType())) {
- constraints.addAll(propertyDefinition.getConstraints());
- } else {
- type = propertyDefinition.getType();
- }
- break;
- }
- }
-
- return type;
- }
+ public <T extends ToscaDataDefinition> Either<List<T>, ResponseFormat> declareProperties(String userId, String componentId,
+ ComponentTypeEnum componentTypeEnum, ComponentInstInputsMap componentInstInputsMap) {
+
+ return Either.left(new ArrayList<>());
+ }
+
+ public <T extends PropertyDataDefinition> List<PropertyConstraint> setInputConstraint(T inputDefinition) {
+ if (StringUtils.isNotBlank(inputDefinition.getParentPropertyType())
+ && StringUtils.isNotBlank(inputDefinition.getSubPropertyInputPath())) {
+ return setConstraint(inputDefinition);
+ }
+
+ return Collections.emptyList();
+ }
+
+ private <T extends PropertyDataDefinition> List<PropertyConstraint> setConstraint(T inputDefinition) {
+ List<PropertyConstraint> constraints = new ArrayList<>();
+ String[] inputPathArr = inputDefinition.getSubPropertyInputPath().split("#");
+ if (inputPathArr.length > 1) {
+ inputPathArr = ArrayUtils.remove(inputPathArr, 0);
+ }
+
+ Map<String, DataTypeDefinition> dataTypeDefinitionMap =
+ applicationDataTypeCache.getAll().left().value();
+
+ String propertyType = inputDefinition.getParentPropertyType();
+
+ for (String anInputPathArr : inputPathArr) {
+ if (ToscaType.isPrimitiveType(propertyType)) {
+ constraints.addAll(
+ dataTypeDefinitionMap.get(propertyType).getConstraints());
+ } else if (!ToscaType.isCollectionType(propertyType)) {
+ propertyType = setConstraintForComplexType(dataTypeDefinitionMap, propertyType, anInputPathArr,
+ constraints);
+ }
+ }
+
+ return constraints;
+ }
+
+ private String setConstraintForComplexType(Map<String, DataTypeDefinition> dataTypeDefinitionMap,
+ String propertyType,
+ String anInputPathArr,
+ List<PropertyConstraint> constraints) {
+ String type = null;
+ List<PropertyDefinition> propertyDefinitions =
+ dataTypeDefinitionMap.get(propertyType).getProperties();
+ for (PropertyDefinition propertyDefinition : propertyDefinitions) {
+ if (propertyDefinition.getName().equals(anInputPathArr)) {
+ if (ToscaType.isPrimitiveType(propertyDefinition.getType())) {
+ constraints.addAll(propertyDefinition.getConstraints());
+ } else {
+ type = propertyDefinition.getType();
+ }
+ break;
+ }
+ }
+
+ return type;
+ }
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java
index 0c6735f8c1..3bae240a67 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java
@@ -62,6 +62,7 @@ import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.GetPolicyValueDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.RequirementDataDefinition;
@@ -93,7 +94,23 @@ import org.openecomp.sdc.be.model.RequirementDefinition;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.User;
-import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
+import org.openecomp.sdc.be.model.ComponentInstancePropInput;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.GroupDefinition;
+import org.openecomp.sdc.be.model.InputDefinition;
+import org.openecomp.sdc.be.model.InterfaceDefinition;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.PolicyDefinition;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.PropertyDefinition.PropertyNames;
+import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentInstanceInput;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.PropertyDefinition.PropertyNames;
import org.openecomp.sdc.be.model.jsontitan.operations.ForwardingPathOperation;
import org.openecomp.sdc.be.model.jsontitan.operations.NodeFilterOperation;
import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
@@ -134,9 +151,6 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
public static final String FAILED_TO_COPY_COMP_INSTANCE_TO_CANVAS = "Failed to copy the component instance to the canvas";
public static final String COPY_COMPONENT_INSTANCE_OK = "Copy component instance OK";
- @Autowired
- private ApplicationDataTypeCache applicationDataTypeCache;
-
@Autowired
private IComponentInstanceOperation componentInstanceOperation;
@@ -158,9 +172,10 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
public ComponentInstanceBusinessLogic() {
}
- public Either<ComponentInstance, ResponseFormat> createComponentInstance(
- String containerComponentParam, String containerComponentId, String userId, ComponentInstance resourceInstance) {
- return createComponentInstance(containerComponentParam, containerComponentId, userId, resourceInstance, false, true);
+ public Either<ComponentInstance, ResponseFormat> createComponentInstance(String containerComponentParam,
+ String containerComponentId, String userId, ComponentInstance resourceInstance) {
+ return createComponentInstance(containerComponentParam, containerComponentId, userId, resourceInstance, false,
+ true);
}
public List<ComponentInstanceProperty> getComponentInstancePropertiesByInputId(org.openecomp.sdc.be.model.Component component, String inputId){
@@ -196,7 +211,69 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
return resList;
}
- public List<ComponentInstanceInput> getComponentInstanceInputsByInputId(org.openecomp.sdc.be.model.Component component, String inputId){
+ public Optional<ComponentInstanceProperty> getComponentInstancePropertyByPolicyId(Component component,
+ PolicyDefinition policy) {
+
+ Optional<ComponentInstanceProperty> propertyCandidate = getComponentInstancePropertyByPolicy(component, policy);
+
+ if(propertyCandidate.isPresent()) {
+ ComponentInstanceProperty componentInstanceProperty = propertyCandidate.get();
+ Optional<GetPolicyValueDataDefinition> getPolicyCandidate =
+ getGetPolicyValueDataDefinition(policy, componentInstanceProperty);
+
+ getPolicyCandidate.ifPresent(getPolicyValue ->
+ updateComponentInstancePropertyAfterUndeclaration(componentInstanceProperty, getPolicyValue, policy));
+ return Optional.of(componentInstanceProperty);
+ }
+
+ return Optional.empty();
+
+ }
+
+ private void updateComponentInstancePropertyAfterUndeclaration(ComponentInstanceProperty componentInstanceProperty,
+ GetPolicyValueDataDefinition getPolicyValue, PolicyDefinition policyDefinition) {
+ componentInstanceProperty.setValue(getPolicyValue.getOrigPropertyValue());
+ List<GetPolicyValueDataDefinition> getPolicyValues = componentInstanceProperty.getGetPolicyValues();
+ if(CollectionUtils.isNotEmpty(getPolicyValues)) {
+ getPolicyValues.remove(getPolicyValue);
+ componentInstanceProperty.setGetPolicyValues(getPolicyValues);
+ policyDefinition.setGetPolicyValues(getPolicyValues);
+ }
+ }
+
+ private Optional<GetPolicyValueDataDefinition> getGetPolicyValueDataDefinition(PolicyDefinition policy,
+ ComponentInstanceProperty componentInstanceProperty) {
+ List<GetPolicyValueDataDefinition> getPolicyValues = policy.getGetPolicyValues();
+ return getPolicyValues.stream()
+ .filter(getPolicyValue -> getPolicyValue
+ .getPropertyName()
+ .equals(componentInstanceProperty
+ .getName()))
+ .findAny();
+ }
+
+ private Optional<ComponentInstanceProperty> getComponentInstancePropertyByPolicy(Component component,
+ PolicyDefinition policy) {
+ Map<String, List<ComponentInstanceProperty>> componentInstancesProperties =
+ component.getComponentInstancesProperties();
+
+ if(MapUtils.isEmpty(componentInstancesProperties)) {
+ return Optional.empty();
+ }
+
+ String instanceUniqueId = policy.getInstanceUniqueId();
+
+ List<ComponentInstanceProperty> componentInstanceProperties =
+ componentInstancesProperties.containsKey(instanceUniqueId)
+ ? componentInstancesProperties.get(instanceUniqueId)
+ : new ArrayList<>();
+
+ return componentInstanceProperties
+ .stream().filter(property -> property.getName().equals(policy.getName())).findAny();
+ }
+
+ public List<ComponentInstanceInput> getComponentInstanceInputsByInputId(
+ org.openecomp.sdc.be.model.Component component, String inputId) {
List<ComponentInstanceInput> resList = new ArrayList<>();
Map<String, List<ComponentInstanceInput>> ciInputsMap = component.getComponentInstancesInputs();
if(ciInputsMap != null && !ciInputsMap.isEmpty()){
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java
index f3b1b14652..214b5df4e1 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java
@@ -20,6 +20,7 @@
package org.openecomp.sdc.be.components.impl;
+import fj.data.Either;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -27,9 +28,7 @@ import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
-
-import fj.data.Either;
-import org.apache.commons.collections4.CollectionUtils;
+import javax.inject.Inject;
import org.apache.commons.collections4.ListUtils;
import org.apache.commons.collections4.MapUtils;
import org.openecomp.sdc.be.components.property.PropertyDeclarationOrchestrator;
@@ -49,19 +48,14 @@ import org.openecomp.sdc.be.model.ComponentInstanceProperty;
import org.openecomp.sdc.be.model.ComponentParametersView;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.InputDefinition;
-import org.openecomp.sdc.be.model.PropertyDefinition;
-import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
import org.openecomp.sdc.be.model.tosca.converters.PropertyValueConverter;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.exception.ResponseFormat;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import javax.inject.Inject;
-
@Component("inputsBusinessLogic")
public class InputsBusinessLogic extends BaseBusinessLogic {
@@ -399,6 +393,13 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
}
+ @Override
+ public Either<List<InputDefinition>, ResponseFormat> declareProperties(String userId, String componentId,
+ ComponentTypeEnum componentTypeEnum, ComponentInstInputsMap componentInstInputsMap) {
+
+ return createMultipleInputs(userId, componentId, componentTypeEnum, componentInstInputsMap, true, false);
+ }
+
public Either<List<InputDefinition>, ResponseFormat> createMultipleInputs(String userId, String componentId, ComponentTypeEnum componentType, ComponentInstInputsMap componentInstInputsMapUi, boolean shouldLockComp, boolean inTransaction) {
Either<List<InputDefinition>, ResponseFormat> result = null;
@@ -544,6 +545,8 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
componentParametersView.setIgnorePolicies(false);
componentParametersView.setIgnoreGroups(false);
componentParametersView.setIgnoreUsers(false);
+ componentParametersView.setIgnoreInterfaces(false);
+ componentParametersView.setIgnoreProperties(false);
Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> componentEither = toscaOperationFacade.getToscaElement(componentId, componentParametersView);
if (componentEither.isRight()) {
@@ -614,17 +617,19 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
PropertyValueConverter converter = type.getConverter();
// get inner type
String innerType = null;
- SchemaDefinition schema = newInputDefinition.getSchema();
- if (schema != null) {
- PropertyDataDefinition prop = schema.getProperty();
- if (prop != null) {
- innerType = prop.getType();
+ if (newInputDefinition != null) {
+ SchemaDefinition schema = newInputDefinition.getSchema();
+ if (schema != null) {
+ PropertyDataDefinition prop = schema.getProperty();
+ if (prop != null) {
+ innerType = prop.getType();
+ }
+ }
+ String convertedValue;
+ if (newInputDefinition.getDefaultValue() != null) {
+ convertedValue = converter.convert(newInputDefinition.getDefaultValue(), innerType, dataTypes);
+ newInputDefinition.setDefaultValue(convertedValue);
}
- }
- String convertedValue;
- if (newInputDefinition.getDefaultValue() != null) {
- convertedValue = converter.convert(newInputDefinition.getDefaultValue(), innerType, dataTypes);
- newInputDefinition.setDefaultValue(convertedValue);
}
}
return Either.left(newInputDefinition);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogic.java
index 6b37318171..752ec4098a 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogic.java
@@ -1,28 +1,42 @@
package org.openecomp.sdc.be.components.impl;
+import static java.util.stream.Collectors.toMap;
+import static org.openecomp.sdc.be.components.validation.PolicyUtils.getExcludedPolicyTypesByComponent;
+import static org.openecomp.sdc.be.components.validation.PolicyUtils.getNextPolicyCounter;
+import static org.openecomp.sdc.be.components.validation.PolicyUtils.validatePolicyFields;
+
import fj.data.Either;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import javax.inject.Inject;
import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.MapUtils;
+import org.openecomp.sdc.be.components.property.PropertyDeclarationOrchestrator;
+import org.openecomp.sdc.be.components.validation.PolicyUtils;
import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.elements.GetPolicyValueDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PolicyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PolicyTargetType;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.openecomp.sdc.be.model.*;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstInputsMap;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.ComponentParametersView;
+import org.openecomp.sdc.be.model.PolicyDefinition;
+import org.openecomp.sdc.be.model.PolicyTypeDefinition;
+import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.common.datastructure.Wrapper;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.exception.ResponseFormat;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.function.Function;
-import java.util.stream.Collectors;
-
-import static java.util.stream.Collectors.toMap;
-import static org.openecomp.sdc.be.components.validation.PolicyUtils.*;
-
/**
* Provides specified business logic to create, retrieve, update, delete a policy
*/
@@ -30,8 +44,25 @@ import static org.openecomp.sdc.be.components.validation.PolicyUtils.*;
public class PolicyBusinessLogic extends BaseBusinessLogic {
private static final String FAILED_TO_VALIDATE_COMPONENT = "#{} - failed to validate the component {} before policy processing. ";
+ private static final String DECLARE_PROPERTIES_TO_POLICIES = "declare properties to policies";
+ private static final String EXECUTE_ROLLBACK = "execute rollback";
+ private static final String EXECUTE_COMMIT = "execute commit";
private static final Logger log = Logger.getLogger(PolicyBusinessLogic.class);
+ @Inject
+ private PropertyDeclarationOrchestrator propertyDeclarationOrchestrator;
+
+ public PolicyBusinessLogic() {
+ }
+
+ public PolicyBusinessLogic(PropertyDeclarationOrchestrator propertyDeclarationOrchestrator) {
+ this.propertyDeclarationOrchestrator = propertyDeclarationOrchestrator;
+ }
+
+ public void setPropertyDeclarationOrchestrator(PropertyDeclarationOrchestrator propertyDeclarationOrchestrator) {
+ this.propertyDeclarationOrchestrator = propertyDeclarationOrchestrator;
+ }
+
/**
* Adds the newly created policy of the specified type to the component
*
@@ -65,6 +96,20 @@ public class PolicyBusinessLogic extends BaseBusinessLogic {
return result;
}
+ public Either<List<PolicyDefinition>, ResponseFormat> getPoliciesList(ComponentTypeEnum componentType, String componentId, String userId) {
+ Either<List<PolicyDefinition>, ResponseFormat> result;
+ log.trace("#getPolicies - starting to retrieve policies of component {}. ", componentId);
+ try {
+ result = validateContainerComponentAndUserBeforeReadOperation(componentType, componentId, userId)
+ .left()
+ .bind(c -> Either.left(c.resolvePoliciesList()));
+ } catch (Exception e) {
+ log.error("#getPolicy - the exception occurred upon retrieving policies list of component {}: ", componentId, e);
+ result = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ return result;
+ }
+
/**
* Retrieves the policy of the component by UniqueId
*
@@ -133,18 +178,138 @@ public class PolicyBusinessLogic extends BaseBusinessLogic {
log.trace("#deletePolicy - starting to update the policy {} on the component {}. ", policyId, componentId);
Wrapper<Component> component = new Wrapper<>();
try {
- result = validateAndLockComponentAndUserBeforeWriteOperation(componentType, componentId, userId, shouldLock)
- .left()
- .bind(c -> {
- component.setInnerElement(c);
- return deletePolicy(c, policyId);
- });
+ Either<Component, ResponseFormat> componentEither =
+ validateAndLockComponentAndUserBeforeWriteOperation(componentType, componentId, userId, shouldLock);
+ if (componentEither.isRight()) {
+ return Either.right(componentEither.right().value());
+ }
+
+ ComponentParametersView componentParametersView = new ComponentParametersView();
+ componentParametersView.disableAll();
+ componentParametersView.setIgnoreComponentInstances(false);
+ componentParametersView.setIgnoreComponentInstancesProperties(false);
+ componentParametersView.setIgnorePolicies(false);
+ componentParametersView.setIgnoreProperties(false);
+
+ Either<Component, StorageOperationStatus> componentWithFilters =
+ toscaOperationFacade.getToscaElement(componentId, componentParametersView);
+ if (componentWithFilters.isRight()) {
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(componentWithFilters.right().value())));
+ }
+
+ Component containerComponent = componentWithFilters.left().value();
+ component.setInnerElement(containerComponent);
+ result = deletePolicy(containerComponent, policyId);
+
+ if(result.isRight()) {
+ log.error("#deletePolicy - could not delete policy of the type {} for the component {}: ", policyId, componentId);
+ return result;
+ }
+
+ PolicyDefinition policyToDelete = result.left().value();
+
+ StorageOperationStatus storageOperationStatus = propertyDeclarationOrchestrator.unDeclarePropertiesAsPolicies(
+ containerComponent, policyToDelete);
+ if (storageOperationStatus != StorageOperationStatus.OK) {
+ log.debug("Component id: {} update properties declared as policy for policy id: {} failed", componentId, policyId);
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils
+ .convertFromStorageResponse(storageOperationStatus), containerComponent.getName()));
+ }
+
+ return result;
} catch (Exception e) {
log.error("#deletePolicy - the exception occurred upon update of a policy of the type {} for the component {}: ", policyId, componentId, e);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR, e.getMessage()));
+ } finally {
+ unlockComponent(shouldLock, result, component);
+ }
+ }
+
+ public Either<PolicyDefinition, ResponseFormat> undeclarePolicy(ComponentTypeEnum componentType, String componentId, String policyId, String userId, boolean shouldLock) {
+ Either<PolicyDefinition, ResponseFormat> result = null;
+ log.trace("#undeclarePolicy - starting to undeclare policy {} on component {}. ", policyId, componentId);
+ Wrapper<Component> component = new Wrapper<>();
+ try {
+ Either<Component, ResponseFormat> componentEither =
+ validateAndLockComponentAndUserBeforeWriteOperation(componentType, componentId, userId, shouldLock);
+ if (componentEither.isRight()) {
+ return Either.right(componentEither.right().value());
+ }
+
+ ComponentParametersView componentParametersView = new ComponentParametersView();
+ componentParametersView.disableAll();
+ componentParametersView.setIgnoreComponentInstances(false);
+ componentParametersView.setIgnoreComponentInstancesProperties(false);
+ componentParametersView.setIgnorePolicies(false);
+
+ Either<Component, StorageOperationStatus> componentWithFilters =
+ toscaOperationFacade.getToscaElement(componentId, componentParametersView);
+ if (componentWithFilters.isRight()) {
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(componentWithFilters.right().value())));
+ }
+
+ Component containerComponent = componentWithFilters.left().value();
+
+ Optional<PolicyDefinition> policyCandidate = getPolicyForUndeclaration(policyId, containerComponent);
+ if(policyCandidate.isPresent()) {
+ result = undeclarePolicy(policyCandidate.get(), containerComponent);
+ }
+
+ return result;
+ } catch (Exception e) {
+ log.error("#undeclarePolicy - the exception occurred upon update of a policy of type {} for component {}: ", policyId, componentId, e);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR, e.getMessage()));
} finally {
unlockComponent(shouldLock, result, component);
}
- return result;
+ }
+
+
+ private Either<PolicyDefinition, ResponseFormat> undeclarePolicy(PolicyDefinition policyDefinition, Component containerComponent) {
+ StorageOperationStatus undeclareStatus = propertyDeclarationOrchestrator
+ .unDeclarePropertiesAsPolicies(containerComponent, policyDefinition);
+ if(undeclareStatus != StorageOperationStatus.OK){
+ return Either.right(componentsUtils.getResponseFormat(undeclareStatus));
+ } else {
+ return Either.left(policyDefinition);
+ }
+ }
+
+
+ private Optional<PolicyDefinition> getPolicyForUndeclaration(String policyId, Component component) {
+ Map<String, PolicyDefinition> policies = component.getPolicies();
+ if(MapUtils.isNotEmpty(policies) && policies.containsKey(policyId)) {
+ return Optional.of(policies.get(policyId));
+ }
+
+ Map<String, List<ComponentInstanceProperty>> componentInstancesProperties =
+ MapUtils.isEmpty(component.getComponentInstancesProperties()) ? new HashMap<>() : component.getComponentInstancesProperties();
+
+ for(Map.Entry<String, List<ComponentInstanceProperty>> instancePropertyEntry : componentInstancesProperties.entrySet()) {
+ Optional<ComponentInstanceProperty> propertyCandidate = getPropertyForDeclaredPolicy(policyId, instancePropertyEntry.getValue());
+
+ if(propertyCandidate.isPresent()) {
+ return Optional.of(
+ PolicyUtils.getDeclaredPolicyDefinition(instancePropertyEntry.getKey(), propertyCandidate.get()));
+ }
+ }
+
+ return Optional.empty();
+ }
+
+ private Optional<ComponentInstanceProperty> getPropertyForDeclaredPolicy(String policyId, List<ComponentInstanceProperty> componentInstanceProperties) {
+ for(ComponentInstanceProperty property : componentInstanceProperties) {
+ Optional<GetPolicyValueDataDefinition> getPolicyCandidate = property.safeGetGetPolicyValues().stream()
+ .filter(getPolicyValue -> getPolicyValue.getPolicyId()
+ .equals(policyId))
+ .findAny();
+
+ if(getPolicyCandidate.isPresent()) {
+ return Optional.of(property);
+ }
+ }
+
+ return Optional.empty();
}
public Either<PolicyDefinition, ResponseFormat> updatePolicyTargets(ComponentTypeEnum componentTypeEnum, String componentId, String policyId, Map<PolicyTargetType, List<String>> targets, String userId) {
@@ -266,6 +431,71 @@ public class PolicyBusinessLogic extends BaseBusinessLogic {
return result;
}
+ @Override
+ public Either<List<PolicyDefinition>, ResponseFormat> declareProperties(String userId, String componentId,
+ ComponentTypeEnum componentTypeEnum, ComponentInstInputsMap componentInstInputsMap) {
+ return declarePropertiesToPolicies(userId, componentId, componentTypeEnum, componentInstInputsMap, true, false);
+
+ }
+
+ private Either<List<PolicyDefinition>, ResponseFormat> declarePropertiesToPolicies(String userId, String componentId,
+ ComponentTypeEnum componentTypeEnum, ComponentInstInputsMap componentInstInputsMap, boolean shouldLock,
+ boolean inTransaction) {
+ Either<List<PolicyDefinition>, ResponseFormat> result = null;
+ org.openecomp.sdc.be.model.Component component = null;
+
+ try {
+ validateUserExists(userId, DECLARE_PROPERTIES_TO_POLICIES, false);
+
+ ComponentParametersView componentParametersView = new ComponentParametersView();
+ componentParametersView.disableAll();
+ componentParametersView.setIgnoreComponentInstances(false);
+ componentParametersView.setIgnoreComponentInstancesProperties(false);
+ componentParametersView.setIgnorePolicies(false);
+ componentParametersView.setIgnoreUsers(false);
+
+ Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponent = validateComponentExists(componentId, componentTypeEnum, componentParametersView);
+
+ if (validateComponent.isRight()) {
+ result = Either.right(validateComponent.right().value());
+ return result;
+ }
+ component = validateComponent.left().value();
+
+ if (shouldLock) {
+ Either<Boolean, ResponseFormat> lockComponent = lockComponent(component, DECLARE_PROPERTIES_TO_POLICIES);
+ if (lockComponent.isRight()) {
+ result = Either.right(lockComponent.right().value());
+ return result;
+ }
+ }
+
+ Either<Boolean, ResponseFormat> canWork = validateCanWorkOnComponent(component, userId);
+ if (canWork.isRight()) {
+ result = Either.right(canWork.right().value());
+ return result;
+ }
+
+ Either<List<PolicyDefinition>, StorageOperationStatus> declarePropertiesEither =
+ propertyDeclarationOrchestrator.declarePropertiesToPolicies(component, componentInstInputsMap);
+
+ if(declarePropertiesEither.isRight()) {
+ return Either.right(componentsUtils.getResponseFormat(declarePropertiesEither.right().value()));
+ }
+
+ result = Either.left(declarePropertiesEither.left().value());
+ return result;
+ } finally {
+ if(!inTransaction) {
+ commitOrRollback(result);
+ }
+ // unlock resource
+ if (shouldLock && component != null) {
+ graphLockOperation.unlockComponent(componentId, componentTypeEnum.getNodeType());
+ }
+ }
+ }
+
private Either<List<PropertyDataDefinition>, ResponseFormat> setComponentValidateUpdatePolicyProperties(String policyId, PropertyDataDefinition[] properties, Wrapper<Component> component, Component c) {
component.setInnerElement(c);
Set<String> updatedPropertyNames = Arrays.stream(properties).map(PropertyDataDefinition::getName).collect(Collectors.toSet());
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java
index 83d6730534..d1bfcc8bba 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java
@@ -475,14 +475,6 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
ServiceConsumptionSource sourceValue = ServiceConsumptionSource.getSourceValue(source);
if(STATIC.equals(sourceValue)) {
- // Validate constraint on input value
- /*Either<Boolean, ResponseFormat> constraintValidationResult =
- validateOperationInputConstraint(operationInputDefinition, serviceConsumptionData);
-
- if (constraintValidationResult.isRight()) {
- return Either.right(constraintValidationResult.right().value());
- }*/
-
return handleConsumptionStaticValue(consumptionValue, type, operation,
operationInputDefinition);
}
@@ -958,10 +950,10 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
service.setInvariantUUID(invariantUUID);
return Either.left(service);
- }
-
-
-
+ }
+
+
+
private Either<Boolean, ResponseFormat> validateServiceFieldsBeforeCreate(User user, Service service, AuditingActionEnum actionEnum) {
try {
validateComponentFieldsBeforeCreate(user, service, actionEnum);
@@ -1547,7 +1539,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
}
return Either.left(true);
}
-
+
private Either<Boolean, ResponseFormat> validateServiceRole(String serviceRole) {
if (serviceRole.equals("")){
return Either.left(true);
@@ -2636,6 +2628,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
public Either<UiComponentDataTransfer, ResponseFormat> getUiComponentDataTransferByComponentId(String serviceId, List<String> dataParamsToReturn) {
ComponentParametersView paramsToReturn = new ComponentParametersView(dataParamsToReturn);
+ paramsToReturn.setIgnoreComponentInstancesProperties(false);
Either<Service, StorageOperationStatus> serviceResultEither = toscaOperationFacade.getToscaElement(serviceId, paramsToReturn);
if (serviceResultEither.isRight()) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/ComponentInstanceInputPropertyDeclarator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/ComponentInstanceInputPropertyDeclarator.java
index 9bf462a186..faeca88d60 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/ComponentInstanceInputPropertyDeclarator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/ComponentInstanceInputPropertyDeclarator.java
@@ -1,22 +1,30 @@
package org.openecomp.sdc.be.components.property;
+import static org.apache.commons.collections.CollectionUtils.isEmpty;
+import static org.openecomp.sdc.be.model.utils.ComponentUtilities.getInputAnnotations;
+
import fj.data.Either;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
import org.openecomp.sdc.be.components.impl.utils.ExceptionUtils;
import org.openecomp.sdc.be.datatypes.elements.Annotation;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.model.*;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentInstanceInput;
+import org.openecomp.sdc.be.model.ComponentInstancePropInput;
+import org.openecomp.sdc.be.model.ComponentParametersView;
+import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
import org.openecomp.sdc.common.log.wrappers.Logger;
-import java.util.*;
-
-import static org.apache.commons.collections.CollectionUtils.isEmpty;
-import static org.openecomp.sdc.be.model.utils.ComponentUtilities.getInputAnnotations;
-
@org.springframework.stereotype.Component
public class ComponentInstanceInputPropertyDeclarator extends DefaultPropertyDeclarator<ComponentInstance, ComponentInstanceInput> {
@@ -33,25 +41,25 @@ public class ComponentInstanceInputPropertyDeclarator extends DefaultPropertyDec
}
@Override
- ComponentInstanceInput createDeclaredProperty(PropertyDataDefinition prop) {
+ public ComponentInstanceInput createDeclaredProperty(PropertyDataDefinition prop) {
return new ComponentInstanceInput(prop);
}
@Override
- Either<?, StorageOperationStatus> updatePropertiesValues(Component component, String cmptInstanceId, List<ComponentInstanceInput> properties) {
+ public Either<?, StorageOperationStatus> updatePropertiesValues(Component component, String cmptInstanceId, List<ComponentInstanceInput> properties) {
log.debug("#updatePropertiesValues - updating component instance inputs for instance {} on component {}", cmptInstanceId, component.getUniqueId());
Map<String, List<ComponentInstanceInput>> instProperties = Collections.singletonMap(cmptInstanceId, properties);
return toscaOperationFacade.addComponentInstanceInputsToComponent(component, instProperties);
}
@Override
- Optional<ComponentInstance> resolvePropertiesOwner(Component component, String propertiesOwnerId) {
+ public Optional<ComponentInstance> resolvePropertiesOwner(Component component, String propertiesOwnerId) {
log.debug("#resolvePropertiesOwner - fetching component instance {} of component {}", propertiesOwnerId, component.getUniqueId());
return component.getComponentInstanceById(propertiesOwnerId);
}
@Override
- void addPropertiesListToInput(ComponentInstanceInput declaredProp, InputDefinition input) {
+ public void addPropertiesListToInput(ComponentInstanceInput declaredProp, InputDefinition input) {
List<ComponentInstanceInput> inputsValueList = input.getInputs();
if(inputsValueList == null) {
inputsValueList = new ArrayList<>(); // adding the property with the new value for UI
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/ComponentInstancePropertyDeclarator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/ComponentInstancePropertyDeclarator.java
index 160bf890b7..c716e24440 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/ComponentInstancePropertyDeclarator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/ComponentInstancePropertyDeclarator.java
@@ -1,6 +1,11 @@
package org.openecomp.sdc.be.components.property;
import fj.data.Either;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
import org.apache.commons.collections.CollectionUtils;
import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
@@ -14,8 +19,6 @@ import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
import org.openecomp.sdc.common.log.wrappers.Logger;
-import java.util.*;
-
@org.springframework.stereotype.Component
public class ComponentInstancePropertyDeclarator extends DefaultPropertyDeclarator<ComponentInstance, ComponentInstanceProperty> {
@@ -30,25 +33,25 @@ public class ComponentInstancePropertyDeclarator extends DefaultPropertyDeclarat
}
@Override
- ComponentInstanceProperty createDeclaredProperty(PropertyDataDefinition prop) {
+ public ComponentInstanceProperty createDeclaredProperty(PropertyDataDefinition prop) {
return new ComponentInstanceProperty(prop);
}
@Override
- Either<?, StorageOperationStatus> updatePropertiesValues(Component component, String cmptInstanceId, List<ComponentInstanceProperty> properties) {
+ public Either<?, StorageOperationStatus> updatePropertiesValues(Component component, String cmptInstanceId, List<ComponentInstanceProperty> properties) {
log.debug("#updatePropertiesValues - updating component instance properties for instance {} on component {}", cmptInstanceId, component.getUniqueId());
Map<String, List<ComponentInstanceProperty>> instProperties = Collections.singletonMap(cmptInstanceId, properties);
return toscaOperationFacade.addComponentInstancePropertiesToComponent(component, instProperties);
}
@Override
- Optional<ComponentInstance> resolvePropertiesOwner(Component component, String propertiesOwnerId) {
+ public Optional<ComponentInstance> resolvePropertiesOwner(Component component, String propertiesOwnerId) {
log.debug("#resolvePropertiesOwner - fetching component instance {} of component {}", propertiesOwnerId, component.getUniqueId());
return component.getComponentInstanceById(propertiesOwnerId);
}
@Override
- void addPropertiesListToInput(ComponentInstanceProperty declaredProp, InputDefinition input) {
+ public void addPropertiesListToInput(ComponentInstanceProperty declaredProp, InputDefinition input) {
List<ComponentInstanceProperty> propertiesList = input.getProperties();
if(propertiesList == null) {
propertiesList = new ArrayList<>(); // adding the property with the new value for UI
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/ComponentPropertyDeclarator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/ComponentPropertyDeclarator.java
index 7f49e389ef..d382499172 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/ComponentPropertyDeclarator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/ComponentPropertyDeclarator.java
@@ -18,6 +18,10 @@ package org.openecomp.sdc.be.components.property;
import fj.data.Either;
import org.apache.commons.collections.CollectionUtils;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
import org.openecomp.sdc.be.components.impl.PropertyBusinessLogic;
import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
@@ -30,11 +34,6 @@ import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Optional;
-
@org.springframework.stereotype.Component
public class ComponentPropertyDeclarator extends DefaultPropertyDeclarator<Component, PropertyDataDefinition> {
@@ -52,12 +51,12 @@ public class ComponentPropertyDeclarator extends DefaultPropertyDeclarator<Compo
}
@Override
- PropertyDataDefinition createDeclaredProperty(PropertyDataDefinition prop) {
+ public PropertyDataDefinition createDeclaredProperty(PropertyDataDefinition prop) {
return new PropertyDataDefinition(prop);
}
@Override
- Either<?, StorageOperationStatus> updatePropertiesValues(Component component,
+ public Either<?, StorageOperationStatus> updatePropertiesValues(Component component,
String propertiesOwnerId,
List<PropertyDataDefinition> properties) {
if(CollectionUtils.isNotEmpty(properties)) {
@@ -74,12 +73,12 @@ public class ComponentPropertyDeclarator extends DefaultPropertyDeclarator<Compo
}
@Override
- Optional<Component> resolvePropertiesOwner(Component component, String propertiesOwnerId) {
- return Optional.of( component);
+ public Optional<Component> resolvePropertiesOwner(Component component, String propertiesOwnerId) {
+ return Optional.of(component);
}
@Override
- void addPropertiesListToInput(PropertyDataDefinition declaredProp,
+ public void addPropertiesListToInput(PropertyDataDefinition declaredProp,
InputDefinition input) {
List<ComponentInstanceProperty> propertiesList = input.getProperties();
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/DefaultPropertyDeclarator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/DefaultPropertyDeclarator.java
index 0f76210a1a..02b261b132 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/DefaultPropertyDeclarator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/DefaultPropertyDeclarator.java
@@ -1,16 +1,35 @@
package org.openecomp.sdc.be.components.property;
+import static org.openecomp.sdc.common.api.Constants.GET_INPUT;
+import static org.openecomp.sdc.common.api.Constants.GET_POLICY;
+
import com.google.gson.Gson;
import fj.data.Either;
+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.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.json.simple.JSONObject;
import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.GetPolicyValueDataDefinition;
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.*;
+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.PolicyDefinition;
+import org.openecomp.sdc.be.model.PropertyDefinition;
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;
@@ -19,11 +38,6 @@ import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.exception.ResponseFormat;
import org.yaml.snakeyaml.Yaml;
-import java.util.*;
-import java.util.stream.Collectors;
-
-import static org.openecomp.sdc.common.api.Constants.GET_INPUT;
-
public abstract class DefaultPropertyDeclarator<PROPERTYOWNER extends PropertiesOwner, PROPERTYTYPE extends PropertyDataDefinition> implements PropertyDeclarator {
private static final Logger log = Logger.getLogger(DefaultPropertyDeclarator.class);
@@ -45,13 +59,35 @@ public abstract class DefaultPropertyDeclarator<PROPERTYOWNER extends Properties
.orElse(Either.right(onPropertiesOwnerNotFound(component.getUniqueId(), propertiesOwnerId)));
}
- abstract PROPERTYTYPE createDeclaredProperty(PropertyDataDefinition prop);
+ protected abstract PROPERTYTYPE createDeclaredProperty(PropertyDataDefinition prop);
+
+ protected abstract Either<?, StorageOperationStatus> updatePropertiesValues(Component component, String propertiesOwnerId, List<PROPERTYTYPE> properties);
+
+ protected abstract Optional<PROPERTYOWNER> resolvePropertiesOwner(Component component, String propertiesOwnerId);
+
+ protected abstract void addPropertiesListToInput(PROPERTYTYPE declaredProp, InputDefinition input);
+
+ @Override
+ public Either<List<PolicyDefinition>, StorageOperationStatus> declarePropertiesAsPolicies(Component component,
+ String propertiesOwnerId,
+ List<ComponentInstancePropInput> propsToDeclare) {
+ log.debug("#declarePropertiesAsPolicies - declaring properties as policies for component {} from properties owner {}", component.getUniqueId(), propertiesOwnerId);
+ return resolvePropertiesOwner(component, propertiesOwnerId)
+ .map(propertyOwner -> declarePropertiesAsPolicies(component, propertyOwner, propsToDeclare))
+ .orElse(Either.right(onPropertiesOwnerNotFound(component.getUniqueId(), propertiesOwnerId)));
- abstract Either<?, StorageOperationStatus> updatePropertiesValues(Component component, String propertiesOwnerId, List<PROPERTYTYPE> properties);
+ }
- abstract Optional<PROPERTYOWNER> resolvePropertiesOwner(Component component, String propertiesOwnerId);
+ public StorageOperationStatus unDeclarePropertiesAsPolicies(Component component, PolicyDefinition policy) {
+ return StorageOperationStatus.OK;
+ }
- abstract void addPropertiesListToInput(PROPERTYTYPE declaredProp, InputDefinition input);
+ private Either<List<PolicyDefinition>, StorageOperationStatus> declarePropertiesAsPolicies(Component component, PROPERTYOWNER propertiesOwner, List<ComponentInstancePropInput> propsToDeclare) {
+ PropertiesDeclarationData policyProperties = createPoliciesAndOverridePropertiesValues(propertiesOwner.getUniqueId(), propertiesOwner, propsToDeclare);
+ return updatePropertiesValues(component, propertiesOwner.getUniqueId(), policyProperties.getPropertiesToUpdate())
+ .left()
+ .map(updatePropsRes -> policyProperties.getPoliciesToCreate());
+ }
private StorageOperationStatus onPropertiesOwnerNotFound(String componentId, String propertiesOwnerId) {
log.debug("#declarePropertiesAsInputs - properties owner {} was not found on component {}", propertiesOwnerId, componentId);
@@ -64,13 +100,67 @@ public abstract class DefaultPropertyDeclarator<PROPERTYOWNER extends Properties
.left()
.map(updatePropsRes -> inputsProperties.getInputsToCreate());
}
+ private PropertiesDeclarationData createPoliciesAndOverridePropertiesValues(String componentId, PROPERTYOWNER propertiesOwner, List<ComponentInstancePropInput> propsToDeclare) {
+ List<PROPERTYTYPE> declaredProperties = new ArrayList<>();
+ List<PolicyDefinition> policies = new ArrayList<>();
+ propsToDeclare.forEach(property -> policies.add(declarePropertyPolicy(componentId, declaredProperties, property)));
+ return new PropertiesDeclarationData(null, policies, declaredProperties);
+ }
+
+ private PolicyDefinition declarePropertyPolicy(String componentId, List<PROPERTYTYPE> declaredProperties,
+ ComponentInstancePropInput propInput) {
+ PropertyDataDefinition prop = resolveProperty(declaredProperties, propInput);
+ propInput.setOwnerId(null);
+ propInput.setParentUniqueId(null);
+
+ PolicyDefinition policyDefinition = new PolicyDefinition(prop);
+ policyDefinition.setUniqueId(UniqueIdBuilder.buildPolicyUniqueId(componentId, prop.getName()));
+ policyDefinition.setInputPath(prop.getName());
+ policyDefinition.setInstanceUniqueId(componentId);
+
+ changePropertyValueToGetPolicy(prop, policyDefinition);
+ PROPERTYTYPE declaredProperty = createDeclaredProperty(prop);
+
+
+ if(!declaredProperties.contains(declaredProperty)){
+ declaredProperties.add(declaredProperty);
+ }
+
+ return policyDefinition;
+ }
+
+ private void changePropertyValueToGetPolicy(PropertyDataDefinition prop, PolicyDefinition policyDefinition) {
+ JSONObject jobject = new JSONObject();
+
+ String origValue = Objects.isNull(prop.getValue()) ? prop.getDefaultValue() : prop.getValue();
+ jobject.put(GET_POLICY, null);
+ prop.setValue(jobject.toJSONString());
+ policyDefinition.setValue(jobject.toJSONString());
+
+ if(CollectionUtils.isEmpty(prop.getGetPolicyValues())){
+ prop.setGetPolicyValues(new ArrayList<>());
+ }
+ List<GetPolicyValueDataDefinition> getPolicyValues = prop.getGetPolicyValues();
+
+ GetPolicyValueDataDefinition getPolicyValueDataDefinition = new GetPolicyValueDataDefinition();
+ getPolicyValueDataDefinition.setPolicyId(policyDefinition.getUniqueId());
+ getPolicyValueDataDefinition.setPropertyName(prop.getName());
+
+ getPolicyValueDataDefinition.setOrigPropertyValue(origValue);
+
+ getPolicyValues.add(getPolicyValueDataDefinition);
+
+ policyDefinition.setGetPolicyValues(getPolicyValues);
+
+ }
+
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))
.collect(Collectors.toList());
- return new PropertiesDeclarationData(createdInputs, declaredProperties);
+ return new PropertiesDeclarationData(createdInputs, null, declaredProperties);
}
private InputDefinition declarePropertyInput(String componentId, PROPERTYOWNER propertiesOwner, List<PROPERTYTYPE> declaredProperties, ComponentInstancePropInput propInput) {
@@ -292,10 +382,12 @@ public abstract class DefaultPropertyDeclarator<PROPERTYOWNER extends Properties
private class PropertiesDeclarationData {
private List<InputDefinition> inputsToCreate;
+ private List<PolicyDefinition> policiesToCreate;
private List<PROPERTYTYPE> propertiesToUpdate;
- PropertiesDeclarationData(List<InputDefinition> inputsToCreate, List<PROPERTYTYPE> propertiesToUpdate) {
+ PropertiesDeclarationData(List<InputDefinition> inputsToCreate, List<PolicyDefinition> policiesToCreate, List<PROPERTYTYPE> propertiesToUpdate) {
this.inputsToCreate = inputsToCreate;
+ this.policiesToCreate = policiesToCreate;
this.propertiesToUpdate = propertiesToUpdate;
}
@@ -303,6 +395,8 @@ public abstract class DefaultPropertyDeclarator<PROPERTYOWNER extends Properties
return inputsToCreate;
}
+ public List<PolicyDefinition> getPoliciesToCreate() { return policiesToCreate; }
+
List<PROPERTYTYPE> getPropertiesToUpdate() {
return propertiesToUpdate;
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/GroupPropertyDeclarator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/GroupPropertyDeclarator.java
index 7817d51658..46ca85c585 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/GroupPropertyDeclarator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/GroupPropertyDeclarator.java
@@ -20,7 +20,16 @@
package org.openecomp.sdc.be.components.property;
+import static java.util.stream.Collectors.toList;
+import static org.apache.commons.collections.CollectionUtils.isEmpty;
+import static org.openecomp.sdc.be.components.property.GetInputUtils.isGetInputValueForInput;
+
import fj.data.Either;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
import org.apache.commons.collections.CollectionUtils;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.impl.ComponentsUtils;
@@ -33,12 +42,6 @@ import org.openecomp.sdc.be.model.operations.impl.GroupOperation;
import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
import org.openecomp.sdc.common.log.wrappers.Logger;
-import java.util.*;
-
-import static java.util.stream.Collectors.toList;
-import static org.apache.commons.collections.CollectionUtils.isEmpty;
-import static org.openecomp.sdc.be.components.property.GetInputUtils.isGetInputValueForInput;
-
@org.springframework.stereotype.Component
public class GroupPropertyDeclarator extends DefaultPropertyDeclarator<GroupDefinition, PropertyDataDefinition> {
@@ -51,25 +54,25 @@ public class GroupPropertyDeclarator extends DefaultPropertyDeclarator<GroupDefi
}
@Override
- PropertyDataDefinition createDeclaredProperty(PropertyDataDefinition prop) {
+ public PropertyDataDefinition createDeclaredProperty(PropertyDataDefinition prop) {
return new PropertyDataDefinition(prop);
}
@Override
- Either<?, StorageOperationStatus> updatePropertiesValues(Component component, String groupId, List<PropertyDataDefinition> properties) {
+ public Either<?, StorageOperationStatus> updatePropertiesValues(Component component, String groupId, List<PropertyDataDefinition> properties) {
log.debug("#updatePropertiesValues - updating group properties for group {} on component {}", groupId, component.getUniqueId());
StorageOperationStatus updateStatus = groupOperation.updateGroupProperties(component, groupId, properties);
return updateStatus == StorageOperationStatus.OK ? Either.left(updateStatus) : Either.right(updateStatus);
}
@Override
- Optional<GroupDefinition> resolvePropertiesOwner(Component component, String groupId) {
+ public Optional<GroupDefinition> resolvePropertiesOwner(Component component, String groupId) {
log.debug("#resolvePropertiesOwner - fetching group {} of component {}", groupId, component.getUniqueId());
return component.getGroupById(groupId);
}
@Override
- void addPropertiesListToInput(PropertyDataDefinition declaredProp, InputDefinition input) {
+ public void addPropertiesListToInput(PropertyDataDefinition declaredProp, InputDefinition input) {
List<ComponentInstanceProperty> propertiesList = input.getProperties();
if(propertiesList == null) {
propertiesList = new ArrayList<>(); // adding the property with the new value for UI
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/PolicyPropertyDeclarator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/PolicyPropertyDeclarator.java
index 9f150aa336..f7f4a75be1 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/PolicyPropertyDeclarator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/PolicyPropertyDeclarator.java
@@ -19,7 +19,15 @@
*/
package org.openecomp.sdc.be.components.property;
+import static org.openecomp.sdc.be.components.property.GetInputUtils.isGetInputValueForInput;
+
import fj.data.Either;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.impl.ComponentsUtils;
@@ -32,11 +40,6 @@ import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
import org.openecomp.sdc.common.log.wrappers.Logger;
-import java.util.*;
-import java.util.stream.Collectors;
-
-import static org.openecomp.sdc.be.components.property.GetInputUtils.isGetInputValueForInput;
-
@org.springframework.stereotype.Component
public class PolicyPropertyDeclarator extends DefaultPropertyDeclarator<PolicyDefinition, PropertyDataDefinition> {
@@ -49,25 +52,25 @@ public class PolicyPropertyDeclarator extends DefaultPropertyDeclarator<PolicyDe
}
@Override
- PropertyDataDefinition createDeclaredProperty(PropertyDataDefinition prop) {
+ public PropertyDataDefinition createDeclaredProperty(PropertyDataDefinition prop) {
return new PropertyDataDefinition(prop);
}
@Override
- Either<?, StorageOperationStatus> updatePropertiesValues(Component component, String policyId, List<PropertyDataDefinition> properties) {
+ public Either<?, StorageOperationStatus> updatePropertiesValues(Component component, String policyId, List<PropertyDataDefinition> properties) {
log.debug("#updatePropertiesValues - updating policies properties for policy {} on component {}", policyId, component.getUniqueId());
StorageOperationStatus updateStatus = policyOperation.updatePolicyProperties(component, policyId, properties);
return updateStatus == StorageOperationStatus.OK ? Either.left(updateStatus) : Either.right(updateStatus);
}
@Override
- Optional<PolicyDefinition> resolvePropertiesOwner(Component component, String policyId) {
+ public Optional<PolicyDefinition> resolvePropertiesOwner(Component component, String policyId) {
log.debug("#resolvePropertiesOwner - fetching policy {} of component {}", policyId, component.getUniqueId());
return Optional.ofNullable(component.getPolicyById(policyId));
}
@Override
- void addPropertiesListToInput(PropertyDataDefinition declaredProp, InputDefinition input) {
+ public void addPropertiesListToInput(PropertyDataDefinition declaredProp, InputDefinition input) {
List<ComponentInstanceProperty> propertiesList = input.getProperties();
if(propertiesList == null) {
propertiesList = new ArrayList<>(); // adding the property with the new value for UI
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/PropertyDeclarationOrchestrator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/PropertyDeclarationOrchestrator.java
index babddc4da1..3a32559dda 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/PropertyDeclarationOrchestrator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/PropertyDeclarationOrchestrator.java
@@ -1,19 +1,21 @@
package org.openecomp.sdc.be.components.property;
+import static org.apache.commons.collections.MapUtils.isNotEmpty;
+
import fj.data.Either;
+import java.util.Arrays;
+import java.util.List;
import org.apache.commons.lang3.tuple.Pair;
+import org.openecomp.sdc.be.components.property.propertytopolicydeclarators.ComponentInstancePropertyToPolicyDeclarator;
+import org.openecomp.sdc.be.components.property.propertytopolicydeclarators.ComponentPropertyToPolicyDeclarator;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstInputsMap;
import org.openecomp.sdc.be.model.ComponentInstancePropInput;
import org.openecomp.sdc.be.model.InputDefinition;
+import org.openecomp.sdc.be.model.PolicyDefinition;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.common.log.wrappers.Logger;
-import java.util.Arrays;
-import java.util.List;
-
-import static org.apache.commons.collections.MapUtils.isNotEmpty;
-
@org.springframework.stereotype.Component
public class PropertyDeclarationOrchestrator {
@@ -23,20 +25,25 @@ public class PropertyDeclarationOrchestrator {
private PolicyPropertyDeclarator policyPropertyDeclarator;
private GroupPropertyDeclarator groupPropertyDeclarator;
private ComponentPropertyDeclarator servicePropertyDeclarator;
- private List<PropertyDeclarator> propertyDeclarators;
+ private List<PropertyDeclarator> propertyDeclaratorsToInput;
+ private List<PropertyDeclarator> propertyDeclaratorsToPolicy;
+ private ComponentPropertyToPolicyDeclarator componentPropertyToPolicyDeclarator;
+ private ComponentInstancePropertyToPolicyDeclarator componentInstancePropertyToPolicyDeclarator;
- public PropertyDeclarationOrchestrator(
- ComponentInstanceInputPropertyDeclarator componentInstanceInputPropertyDeclarator,
- ComponentInstancePropertyDeclarator componentInstancePropertyDeclarator,
- PolicyPropertyDeclarator policyPropertyDeclarator,
- GroupPropertyDeclarator groupPropertyDeclarator,
- ComponentPropertyDeclarator servicePropertyDeclarator) {
+ public PropertyDeclarationOrchestrator(ComponentInstanceInputPropertyDeclarator componentInstanceInputPropertyDeclarator,
+ ComponentInstancePropertyDeclarator componentInstancePropertyDeclarator, PolicyPropertyDeclarator policyPropertyDeclarator,
+ GroupPropertyDeclarator groupPropertyDeclarator, ComponentPropertyDeclarator servicePropertyDeclarator,
+ ComponentPropertyToPolicyDeclarator componentPropertyToPolicyDeclarator,
+ ComponentInstancePropertyToPolicyDeclarator componentInstancePropertyToPolicyDeclarator) {
this.componentInstanceInputPropertyDeclarator = componentInstanceInputPropertyDeclarator;
this.componentInstancePropertyDeclarator = componentInstancePropertyDeclarator;
this.policyPropertyDeclarator = policyPropertyDeclarator;
this.groupPropertyDeclarator = groupPropertyDeclarator;
this.servicePropertyDeclarator = servicePropertyDeclarator;
- propertyDeclarators = Arrays.asList(componentInstanceInputPropertyDeclarator, componentInstancePropertyDeclarator, policyPropertyDeclarator, groupPropertyDeclarator, servicePropertyDeclarator);
+ this.componentPropertyToPolicyDeclarator = componentPropertyToPolicyDeclarator;
+ this.componentInstancePropertyToPolicyDeclarator = componentInstancePropertyToPolicyDeclarator;
+ propertyDeclaratorsToInput = Arrays.asList(componentInstanceInputPropertyDeclarator, componentInstancePropertyDeclarator, policyPropertyDeclarator, groupPropertyDeclarator, servicePropertyDeclarator);
+ propertyDeclaratorsToPolicy = Arrays.asList(componentPropertyToPolicyDeclarator, componentInstancePropertyToPolicyDeclarator);
}
public Either<List<InputDefinition>, StorageOperationStatus> declarePropertiesToInputs(Component component, ComponentInstInputsMap componentInstInputsMap) {
@@ -45,9 +52,15 @@ public class PropertyDeclarationOrchestrator {
return propertyDeclarator.declarePropertiesAsInputs(component, propsToDeclare.getLeft(), propsToDeclare.getRight());
}
+ public Either<List<PolicyDefinition>, StorageOperationStatus> declarePropertiesToPolicies(Component component, ComponentInstInputsMap componentInstInputsMap) {
+ PropertyDeclarator propertyDeclarator = getPropertyDeclarator(componentInstInputsMap);
+ Pair<String, List<ComponentInstancePropInput>> propsToDeclare = componentInstInputsMap.resolvePropertiesToDeclare();
+ return propertyDeclarator.declarePropertiesAsPolicies(component, propsToDeclare.getLeft(), propsToDeclare.getRight());
+ }
+
public StorageOperationStatus unDeclarePropertiesAsInputs(Component component, InputDefinition inputToDelete) {
log.debug("#unDeclarePropertiesAsInputs - removing input declaration for input {} on component {}", inputToDelete.getName(), component.getUniqueId());
- for (PropertyDeclarator propertyDeclarator : propertyDeclarators) {
+ for (PropertyDeclarator propertyDeclarator : propertyDeclaratorsToInput) {
StorageOperationStatus storageOperationStatus = propertyDeclarator.unDeclarePropertiesAsInputs(component, inputToDelete);
if (StorageOperationStatus.OK != storageOperationStatus) {
log.debug("#unDeclarePropertiesAsInputs - failed to remove input declaration for input {} on component {}. reason {}", inputToDelete.getName(), component.getUniqueId(), storageOperationStatus);
@@ -58,6 +71,23 @@ public class PropertyDeclarationOrchestrator {
}
+ public StorageOperationStatus unDeclarePropertiesAsPolicies(Component component, PolicyDefinition policyToDelete) {
+ log.debug("#unDeclarePropertiesAsInputs - removing policy declaration for input {} on component {}", policyToDelete
+ .getName(), component.getUniqueId());
+ for(PropertyDeclarator propertyDeclarator : propertyDeclaratorsToPolicy) {
+ StorageOperationStatus storageOperationStatus =
+ propertyDeclarator.unDeclarePropertiesAsPolicies(component, policyToDelete);
+ if (StorageOperationStatus.OK != storageOperationStatus) {
+ log.debug("#unDeclarePropertiesAsInputs - failed to remove policy declaration for policy {} on component {}. reason {}", policyToDelete
+ .getName(), component.getUniqueId(), storageOperationStatus);
+ return storageOperationStatus;
+ }
+ }
+
+ return StorageOperationStatus.OK;
+
+ }
+
private PropertyDeclarator getPropertyDeclarator(ComponentInstInputsMap componentInstInputsMap) {
if (isNotEmpty(componentInstInputsMap.getComponentInstanceInputsMap())) {
return componentInstanceInputPropertyDeclarator;
@@ -74,6 +104,12 @@ public class PropertyDeclarationOrchestrator {
if(isNotEmpty(componentInstInputsMap.getServiceProperties())) {
return servicePropertyDeclarator;
}
+ if(isNotEmpty(componentInstInputsMap.getComponentPropertiesToPolicies())) {
+ return componentPropertyToPolicyDeclarator;
+ }
+ if(isNotEmpty(componentInstInputsMap.getComponentInstancePropertiesToPolicies())) {
+ return componentInstancePropertyToPolicyDeclarator;
+ }
throw new IllegalStateException("there are no properties selected for declaration");
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/PropertyDeclarator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/PropertyDeclarator.java
index a5add358d7..c0f76288b2 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/PropertyDeclarator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/PropertyDeclarator.java
@@ -1,13 +1,13 @@
package org.openecomp.sdc.be.components.property;
import fj.data.Either;
+import java.util.List;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstancePropInput;
import org.openecomp.sdc.be.model.InputDefinition;
+import org.openecomp.sdc.be.model.PolicyDefinition;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-import java.util.List;
-
public interface PropertyDeclarator {
/**
@@ -27,4 +27,21 @@ public interface PropertyDeclarator {
*/
StorageOperationStatus unDeclarePropertiesAsInputs(Component component, InputDefinition input);
+ /**
+ * creates a list of policies from the given list of properties and updates the properties accordingly
+ * @param component the container
+ * @param propertiesOwnerId the id of the owner of the properties to declare (e.g ComponentInstance, Policy, Group etc)
+ * @param propsToDeclare the list of properties that are being declared as inputs
+ * @return the list of policies that were created from the given properties
+ */
+ Either<List<PolicyDefinition>, StorageOperationStatus> declarePropertiesAsPolicies(Component component, String propertiesOwnerId, List<ComponentInstancePropInput> propsToDeclare);
+
+ /**
+ * returns the values of declared properties to each original state before it was declared as an policy.
+ * this function is to be called when an policy, that was created by declaring a property, is deleted.
+ * @param component the container of the input to be deleted
+ * @param policy the policy to be deleted
+ */
+ StorageOperationStatus unDeclarePropertiesAsPolicies(Component component, PolicyDefinition policy);
+
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/propertytopolicydeclarators/ComponentInstancePropertyToPolicyDeclarator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/propertytopolicydeclarators/ComponentInstancePropertyToPolicyDeclarator.java
new file mode 100644
index 0000000000..bbbdf6f105
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/propertytopolicydeclarators/ComponentInstancePropertyToPolicyDeclarator.java
@@ -0,0 +1,81 @@
+package org.openecomp.sdc.be.components.property.propertytopolicydeclarators;
+
+import fj.data.Either;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.PropertyBusinessLogic;
+import org.openecomp.sdc.be.components.property.DefaultPropertyDeclarator;
+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.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.InputDefinition;
+import org.openecomp.sdc.be.model.PolicyDefinition;
+import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
+
+@org.springframework.stereotype.Component
+public class ComponentInstancePropertyToPolicyDeclarator extends
+ DefaultPropertyDeclarator<ComponentInstance, ComponentInstanceProperty> {
+
+ private ToscaOperationFacade toscaOperationFacade;
+ PropertyBusinessLogic propertyBl;
+ private ComponentInstanceBusinessLogic componentInstanceBl;
+
+ public ComponentInstancePropertyToPolicyDeclarator(ComponentsUtils componentsUtils,
+ PropertyOperation propertyOperation, ToscaOperationFacade toscaOperationFacade,
+ PropertyBusinessLogic propertyBl, ComponentInstanceBusinessLogic componentInstanceBl) {
+ super(componentsUtils, propertyOperation);
+ this.toscaOperationFacade = toscaOperationFacade;
+ this.propertyBl = propertyBl;
+ this.componentInstanceBl = componentInstanceBl;
+ }
+
+ @Override
+ protected ComponentInstanceProperty createDeclaredProperty(PropertyDataDefinition prop) {
+ return new ComponentInstanceProperty(prop);
+ }
+
+ @Override
+ protected Either<?, StorageOperationStatus> updatePropertiesValues(Component component, String componentInstanceId,
+ List<ComponentInstanceProperty> properties) {
+ Map<String, List<ComponentInstanceProperty>>
+ instProperties = Collections.singletonMap(componentInstanceId, properties);
+ return toscaOperationFacade.addComponentInstancePropertiesToComponent(component, instProperties);
+ }
+
+ @Override
+ protected Optional<ComponentInstance> resolvePropertiesOwner(Component component, String componentInstanceId) {
+ return component.getComponentInstanceById(componentInstanceId);
+ }
+
+ @Override
+ protected void addPropertiesListToInput(ComponentInstanceProperty declaredProp, InputDefinition input) {
+ return;
+ }
+
+ @Override
+ public StorageOperationStatus unDeclarePropertiesAsInputs(Component component, InputDefinition input) {
+ return StorageOperationStatus.OK;
+ }
+
+ @Override
+ public StorageOperationStatus unDeclarePropertiesAsPolicies(Component component, PolicyDefinition policy) {
+
+ Optional<ComponentInstanceProperty> propertyCandidate =
+ componentInstanceBl.getComponentInstancePropertyByPolicyId(component, policy);
+
+
+ if(propertyCandidate.isPresent()) {
+ return toscaOperationFacade
+ .updateComponentInstanceProperty(component, policy.getInstanceUniqueId(), propertyCandidate.get());
+ }
+
+ return StorageOperationStatus.OK;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/propertytopolicydeclarators/ComponentPropertyToPolicyDeclarator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/propertytopolicydeclarators/ComponentPropertyToPolicyDeclarator.java
new file mode 100644
index 0000000000..1d73786938
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/propertytopolicydeclarators/ComponentPropertyToPolicyDeclarator.java
@@ -0,0 +1,137 @@
+package org.openecomp.sdc.be.components.property.propertytopolicydeclarators;
+
+import fj.data.Either;
+import java.util.List;
+import java.util.Optional;
+import org.apache.commons.collections4.CollectionUtils;
+import org.openecomp.sdc.be.components.impl.PropertyBusinessLogic;
+import org.openecomp.sdc.be.components.property.DefaultPropertyDeclarator;
+import org.openecomp.sdc.be.datatypes.elements.GetPolicyValueDataDefinition;
+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.InputDefinition;
+import org.openecomp.sdc.be.model.PolicyDefinition;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
+
+@org.springframework.stereotype.Component
+public class ComponentPropertyToPolicyDeclarator extends DefaultPropertyDeclarator<Component, PropertyDataDefinition> {
+
+ private ToscaOperationFacade toscaOperationFacade;
+ PropertyBusinessLogic propertyBL;
+
+
+ public ComponentPropertyToPolicyDeclarator(ComponentsUtils componentsUtils, PropertyOperation propertyOperation,
+ ToscaOperationFacade toscaOperationFacade, PropertyBusinessLogic propertyBusinessLogic) {
+ super(componentsUtils, propertyOperation);
+ this.toscaOperationFacade = toscaOperationFacade;
+ this.propertyBL = propertyBusinessLogic;
+ }
+
+ @Override
+ public PropertyDataDefinition createDeclaredProperty(PropertyDataDefinition prop) {
+ return new PropertyDataDefinition(prop);
+ }
+
+ @Override
+ public Either<?, StorageOperationStatus> updatePropertiesValues(Component component, String policyId,
+ List<PropertyDataDefinition> properties) {
+ if(CollectionUtils.isNotEmpty(properties)) {
+ for(PropertyDataDefinition property : properties) {
+ Either<PropertyDefinition, StorageOperationStatus>
+ storageStatus = toscaOperationFacade
+ .updatePropertyOfComponent(component, new PropertyDefinition(property));
+ if(storageStatus.isRight()) {
+ return Either.right(storageStatus.right().value());
+ }
+ }
+ }
+ return Either.left(properties);
+
+ }
+
+ @Override
+ public Optional<Component> resolvePropertiesOwner(Component component, String propertyId) {
+ return Optional.of(component);
+ }
+
+ @Override
+ public StorageOperationStatus unDeclarePropertiesAsInputs(Component component, InputDefinition input) {
+ // no need for implementation since we are in a policy scenario
+ return StorageOperationStatus.OK;
+ }
+
+ @Override
+ public void addPropertiesListToInput(PropertyDataDefinition declaredProp, InputDefinition input) {
+ // no need for implementation since we are in a policy scenario
+ return;
+ }
+
+ @Override
+ public StorageOperationStatus unDeclarePropertiesAsPolicies(Component component, PolicyDefinition policy) {
+ Optional<PropertyDefinition> propertyToUpdateCandidate =
+ getDeclaredPropertyByPolicyId(component, policy.getUniqueId());
+
+ if(propertyToUpdateCandidate.isPresent()) {
+ return unDeclarePolicy(component, propertyToUpdateCandidate.get(), policy);
+ }
+
+ return StorageOperationStatus.OK;
+ }
+
+ private StorageOperationStatus unDeclarePolicy(Component component, PropertyDefinition propertyToUpdate, PolicyDefinition policy) {
+ updatePropertyAfterUndeclaration(propertyToUpdate, policy);
+
+ Either<PropertyDefinition, StorageOperationStatus> status = toscaOperationFacade
+ .updatePropertyOfComponent(component, propertyToUpdate);
+ if(status.isRight()) {
+ return status.right().value();
+ }
+
+ return StorageOperationStatus.OK;
+ }
+
+ private void updatePropertyAfterUndeclaration(PropertyDefinition propertyToUpdate, PolicyDefinition policy) {
+ List<GetPolicyValueDataDefinition> getPolicyValues = propertyToUpdate.getGetPolicyValues();
+ Optional<GetPolicyValueDataDefinition> getPolicyCandidateToRemove = getPolicyValues.stream()
+ .filter(getPolicyValue -> getPolicyValue.getPolicyId()
+ .equals(policy.getUniqueId()))
+ .findAny();
+
+ getPolicyCandidateToRemove.ifPresent(getPolicyValue -> {
+ getPolicyValues.remove(getPolicyValue);
+ propertyToUpdate.setValue(getPolicyValue.getOrigPropertyValue());
+ });
+ }
+
+ private Optional<PropertyDefinition> getDeclaredPropertyByPolicyId(Component component,
+ String policyId) {
+ List<PropertyDefinition> properties = component.getProperties();
+
+ if(CollectionUtils.isEmpty(properties)) {
+ return Optional.empty();
+ }
+
+ for(PropertyDefinition propertyDefinition : properties) {
+ List<GetPolicyValueDataDefinition> getPolicyValues = propertyDefinition.getGetPolicyValues();
+ if(CollectionUtils.isEmpty(getPolicyValues)) {
+ continue;
+ }
+
+
+ Optional<GetPolicyValueDataDefinition> getPolicyCandidate =
+ getPolicyValues.stream().filter(getPolicy -> getPolicy.getPolicyId().equals(policyId)).findAny();
+
+ if(getPolicyCandidate.isPresent()) {
+ propertyDefinition.setValue(getPolicyCandidate.get().getOrigPropertyValue());
+ return Optional.of(propertyDefinition);
+ }
+ }
+
+ return Optional.empty();
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/PolicyUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/PolicyUtils.java
index 80747b5991..e9d96983aa 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/PolicyUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/PolicyUtils.java
@@ -1,28 +1,29 @@
package org.openecomp.sdc.be.components.validation;
+import static org.apache.commons.collections.MapUtils.isEmpty;
+import static org.apache.commons.collections.MapUtils.isNotEmpty;
+import static org.apache.commons.lang3.StringUtils.isEmpty;
+import static org.apache.commons.lang3.StringUtils.isNotEmpty;
+import static org.openecomp.sdc.common.api.Constants.GROUP_POLICY_NAME_DELIMETER;
+
import fj.data.Either;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
import org.openecomp.sdc.be.model.PolicyDefinition;
import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.common.util.ValidationUtils;
-import java.util.Collections;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
-
-import static org.apache.commons.collections.MapUtils.isEmpty;
-import static org.apache.commons.collections.MapUtils.isNotEmpty;
-import static org.apache.commons.lang3.StringUtils.isEmpty;
-import static org.apache.commons.lang3.StringUtils.isNotEmpty;
-import static org.openecomp.sdc.common.api.Constants.GROUP_POLICY_NAME_DELIMETER;
-
/**
* Provides specific functionality for policy
*/
@@ -94,6 +95,14 @@ public class PolicyUtils {
.get(((Resource) component).getResourceType().getValue());
}
+ public static PolicyDefinition getDeclaredPolicyDefinition(String componentInstanceId, ComponentInstanceProperty property) {
+ PolicyDefinition policyDefinition = new PolicyDefinition(property);
+ policyDefinition.setUniqueId(UniqueIdBuilder.buildPolicyUniqueId(componentInstanceId, property.getName()));
+ policyDefinition.setInstanceUniqueId(componentInstanceId);
+
+ return policyDefinition;
+ }
+
private static int extractNextPolicyCounterFromUniqueId(String uniqueId) {
int counter = 0;
if (isNotEmpty(uniqueId)) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java
index f2cdcc3a6d..073e469c1e 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java
@@ -16,6 +16,8 @@
package org.openecomp.sdc.be.datamodel.utils;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
@@ -30,8 +32,6 @@ import org.apache.commons.collections4.ListUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.codehaus.jackson.type.TypeReference;
import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.model.DataTypeDefinition;
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java
index 0dddfe5c13..858d15ab9e 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java
@@ -26,12 +26,17 @@ import static java.util.stream.Collectors.toList;
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.Set;
+import java.util.stream.Collectors;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.MapUtils;
import org.openecomp.sdc.be.components.impl.GroupTypeBusinessLogic;
import org.openecomp.sdc.be.components.impl.PolicyTypeBusinessLogic;
+import org.openecomp.sdc.be.components.validation.PolicyUtils;
import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
import org.openecomp.sdc.be.datatypes.components.ServiceMetadataDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition;
@@ -39,6 +44,7 @@ import org.openecomp.sdc.be.datatypes.enums.ComponentFieldsEnum;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.model.CapabilityDefinition;
import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
import org.openecomp.sdc.be.model.GroupDefinition;
import org.openecomp.sdc.be.model.PolicyDefinition;
import org.openecomp.sdc.be.model.Resource;
@@ -94,7 +100,7 @@ public class UiComponentDataConverter {
setCapabilities(dataTransfer, component);
break;
case POLICIES:
- dataTransfer.setPolicies(component.resolvePoliciesList());
+ setPolicies(dataTransfer, component);
break;
case NON_EXCLUDED_POLICIES:
setNonExcludedPolicies(dataTransfer, component);
@@ -139,6 +145,33 @@ public class UiComponentDataConverter {
}
}
+ private void setPolicies(UiComponentDataTransfer dataTransfer, Component component) {
+ Map<String, PolicyDefinition> policies = component.getPolicies();
+ Set<PolicyDefinition> policyDefinitions =
+ MapUtils.isEmpty(policies) ? new HashSet<>() : new HashSet<>(policies.values());
+
+ policyDefinitions.addAll(getDeclaredPolicies(component.getComponentInstancesProperties()));
+
+ dataTransfer.setPolicies(new ArrayList<>(policyDefinitions));
+ }
+
+ private Set<PolicyDefinition> getDeclaredPolicies(Map<String, List<ComponentInstanceProperty>> componentInstanceProperties) {
+ if(MapUtils.isEmpty(componentInstanceProperties)) {
+ return new HashSet<>();
+ }
+
+ Set<PolicyDefinition> declaredPolicies = new HashSet<>();
+ for(Map.Entry<String, List<ComponentInstanceProperty>> instancePropertyEntry : componentInstanceProperties.entrySet()) {
+ declaredPolicies.addAll(instancePropertyEntry.getValue().stream()
+ .filter(property -> CollectionUtils.isNotEmpty(property.getGetPolicyValues()))
+ .map(instanceProperty -> PolicyUtils.getDeclaredPolicyDefinition(instancePropertyEntry.getKey(), instanceProperty))
+ .collect(Collectors.toSet()));
+ }
+
+ return declaredPolicies;
+ }
+
+
private void setComponentInstanceRelation(UiComponentDataTransfer dataTransfer, Component component) {
if (component.getComponentInstancesRelations() == null) {
dataTransfer.setComponentInstancesRelations(new ArrayList<>());
@@ -367,6 +400,15 @@ public class UiComponentDataConverter {
UiServiceMetadata metadata = new UiServiceMetadata(service.getCategories(), (ServiceMetadataDataDefinition) service.getComponentMetadataDefinition().getMetadataDataDefinition());
dataTransfer.setMetadata(metadata);
break;
+ case NODE_FILTER:
+ if(service.getNodeFilterComponents() == null) {
+ dataTransfer.setNodeFilterData(null);
+ } else {
+ NodeFilterConverter nodeFilterConverter = new NodeFilterConverter();
+ dataTransfer.setNodeFilterData(nodeFilterConverter.convertDataMapToUI(service.getNodeFilterComponents()));
+ }
+
+ break;
default:
setUiTranferDataByFieldName(dataTransfer, service, fieldName);
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/mixin/PolicyCompositionMixin.java b/catalog-be/src/main/java/org/openecomp/sdc/be/mixin/PolicyCompositionMixin.java
index 7e479eadfe..775a7d9f78 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/mixin/PolicyCompositionMixin.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/mixin/PolicyCompositionMixin.java
@@ -1,14 +1,13 @@
package org.openecomp.sdc.be.mixin;
import com.fasterxml.jackson.annotation.JsonProperty;
+import java.util.List;
+import java.util.Map;
import org.openecomp.sdc.be.datatypes.elements.PolicyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PolicyTargetType;
import org.openecomp.sdc.be.view.Mixin;
import org.openecomp.sdc.be.view.MixinTarget;
-import java.util.List;
-import java.util.Map;
-
@MixinTarget(target = PolicyDataDefinition.class)
public abstract class PolicyCompositionMixin extends Mixin {
@JsonProperty
@@ -19,6 +18,12 @@ public abstract class PolicyCompositionMixin extends Mixin {
abstract String getUniqueId();
@JsonProperty("type")
abstract String getPolicyTypeName();
+ @JsonProperty
+ abstract String getInputPath();
+ @JsonProperty
+ abstract String getValue();
+ @JsonProperty
+ abstract String getInstanceUniqueId();
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java
index 14fc77acd5..3d7dd8c622 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java
@@ -24,6 +24,21 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import fj.data.Either;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Type;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Supplier;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.core.Response;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
@@ -62,19 +77,6 @@ import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.web.context.WebApplicationContext;
import org.yaml.snakeyaml.Yaml;
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.core.Response;
-import java.io.*;
-import java.lang.reflect.Type;
-import java.nio.charset.StandardCharsets;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.function.Supplier;
-import java.util.zip.ZipInputStream;
-
public abstract class AbstractValidationsServlet extends BeGenericServlet {
private static final Logger log = Logger.getLogger(AbstractValidationsServlet.class);
@@ -786,8 +788,6 @@ public abstract class AbstractValidationsServlet extends BeGenericServlet {
protected void validateComponentInstanceBusinessLogic(HttpServletRequest request, String containerComponentType, Wrapper<ComponentInstanceBusinessLogic> blWrapper, Wrapper<ResponseFormat> errorWrapper) {
ServletContext context = request.getSession().getServletContext();
-
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context);
if (componentInstanceLogic == null) {
log.debug("Unsupported component type {}", containerComponentType);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/BeGenericServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/BeGenericServlet.java
index 94431f6b48..b397439a99 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/BeGenericServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/BeGenericServlet.java
@@ -27,20 +27,53 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import fj.data.Either;
+import java.lang.reflect.Type;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.function.Supplier;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
-import org.openecomp.sdc.be.components.impl.*;
+import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
+import org.openecomp.sdc.be.components.impl.BaseBusinessLogic;
+import org.openecomp.sdc.be.components.impl.CapabilitiesBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ElementBusinessLogic;
+import org.openecomp.sdc.be.components.impl.GenericArtifactBrowserBusinessLogic;
+import org.openecomp.sdc.be.components.impl.GroupBusinessLogic;
+import org.openecomp.sdc.be.components.impl.InputsBusinessLogic;
+import org.openecomp.sdc.be.components.impl.InterfaceOperationBusinessLogic;
+import org.openecomp.sdc.be.components.impl.MonitoringBusinessLogic;
+import org.openecomp.sdc.be.components.impl.PolicyBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ProductBusinessLogic;
+import org.openecomp.sdc.be.components.impl.PropertyBusinessLogic;
+import org.openecomp.sdc.be.components.impl.RelationshipTypeBusinessLogic;
+import org.openecomp.sdc.be.components.impl.RequirementBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
import org.openecomp.sdc.be.components.scheduledtasks.ComponentsCleanBusinessLogic;
import org.openecomp.sdc.be.components.upgrade.UpgradeBusinessLogic;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.DeclarationTypeEnum;
+import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
import org.openecomp.sdc.be.ecomp.converters.AssetMetadataConverter;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.impl.WebAppContextWrapper;
+import org.openecomp.sdc.be.model.ComponentInstInputsMap;
import org.openecomp.sdc.be.model.PropertyConstraint;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.User;
@@ -56,19 +89,6 @@ import org.openecomp.sdc.common.servlets.BasicServlet;
import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.web.context.WebApplicationContext;
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.ResponseBuilder;
-import java.lang.reflect.Type;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.function.Supplier;
-
public class BeGenericServlet extends BasicServlet {
@Context
@@ -433,4 +453,70 @@ public class BeGenericServlet extends BasicServlet {
PropertyBusinessLogic propertytBl = webApplicationContext.getBean(PropertyBusinessLogic.class);
return propertytBl;
}
+
+ protected InputsBusinessLogic getInputBL(ServletContext context) {
+ WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
+ WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
+ return webApplicationContext.getBean(InputsBusinessLogic.class);
+ }
+
+ protected PolicyBusinessLogic getPolicyBL(ServletContext context) {
+ WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
+ WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
+ return webApplicationContext.getBean(PolicyBusinessLogic.class);
+ }
+
+ protected Either<ComponentInstInputsMap, ResponseFormat> parseToComponentInstanceMap(String componentJson, User user, ComponentTypeEnum componentType) {
+ return getComponentsUtils().convertJsonToObjectUsingObjectMapper(componentJson, user, ComponentInstInputsMap.class, AuditingActionEnum.CREATE_RESOURCE, componentType);
+ }
+
+ protected Response declareProperties(String userId, String componentId, String componentType,
+ String componentInstInputsMapObj, DeclarationTypeEnum typeEnum, HttpServletRequest request) {
+ ServletContext context = request.getSession().getServletContext();
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("(get) Start handle request of {}", url);
+ Response response = null;
+
+ try {
+ BaseBusinessLogic businessLogic = getBlForPropertyDeclaration(typeEnum, context);
+
+ // get modifier id
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug("modifier id is {}", userId);
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
+ Either<ComponentInstInputsMap, ResponseFormat> componentInstInputsMapRes = parseToComponentInstanceMap(componentInstInputsMapObj, modifier, componentTypeEnum);
+ if (componentInstInputsMapRes.isRight()) {
+ log.debug("failed to parse componentInstInputsMap");
+ response = buildErrorResponse(componentInstInputsMapRes.right().value());
+ return response;
+ }
+
+ Either<List<ToscaDataDefinition>, ResponseFormat> propertiesAfterDeclaration = businessLogic
+ .declareProperties(userId, componentId,
+ componentTypeEnum,
+ componentInstInputsMapRes.left().value());
+ if (propertiesAfterDeclaration.isRight()) {
+ log.debug("failed to create inputs for service: {}", componentId);
+ return buildErrorResponse(propertiesAfterDeclaration.right().value());
+ }
+ Object properties = RepresentationUtils.toRepresentation(propertiesAfterDeclaration.left().value());
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), properties);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create inputs for service with id: " + componentId);
+ log.debug("Properties declaration failed with exception", e);
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return response;
+ }
+ }
+
+ public BaseBusinessLogic getBlForPropertyDeclaration(DeclarationTypeEnum typeEnum,
+ ServletContext context) {
+ if(typeEnum.equals(DeclarationTypeEnum.POLICY)) {
+ return getPolicyBL(context);
+ }
+
+ return getInputBL(context);
+ }
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InputsServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InputsServlet.java
index d55f3e9cc3..7da6533570 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InputsServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InputsServlet.java
@@ -23,28 +23,42 @@ package org.openecomp.sdc.be.servlets;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.jcabi.aspects.Loggable;
import fj.data.Either;
-import io.swagger.annotations.*;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+import java.util.Arrays;
+import java.util.List;
+import javax.inject.Singleton;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
import org.openecomp.sdc.be.components.impl.InputsBusinessLogic;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.openecomp.sdc.be.impl.WebAppContextWrapper;
-import org.openecomp.sdc.be.model.*;
+import org.openecomp.sdc.be.datatypes.enums.DeclarationTypeEnum;
+import org.openecomp.sdc.be.model.ComponentInstInputsMap;
+import org.openecomp.sdc.be.model.ComponentInstanceInput;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.InputDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.exception.ResponseFormat;
-import org.springframework.web.context.WebApplicationContext;
-
-import javax.inject.Singleton;
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.*;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import java.util.Arrays;
-import java.util.List;
@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
@Api(value = "Input Catalog", description = "Input Servlet")
@@ -242,10 +256,6 @@ public class InputsServlet extends AbstractValidationsServlet {
}
}
- private Either<ComponentInstInputsMap, ResponseFormat> parseToComponentInstanceMap(String serviceJson, User user) {
- return getComponentsUtils().convertJsonToObjectUsingObjectMapper(serviceJson, user, ComponentInstInputsMap.class, AuditingActionEnum.CREATE_RESOURCE, ComponentTypeEnum.SERVICE);
- }
-
@POST
@Path("/{componentType}/{componentId}/create/inputs")
@ApiOperation(value = "Create inputs on service", httpMethod = "POST", notes = "Return inputs list", response = Resource.class)
@@ -253,43 +263,8 @@ public class InputsServlet extends AbstractValidationsServlet {
public Response createMultipleInputs(@PathParam("componentType") final String componentType, @PathParam("componentId") final String componentId, @Context final HttpServletRequest request,
@HeaderParam(value = Constants.USER_ID_HEADER) String userId, @ApiParam(value = "ComponentIns Inputs Object to be created", required = true) String componentInstInputsMapObj) {
- ServletContext context = request.getSession().getServletContext();
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("(get) Start handle request of {}", url);
- Response response = null;
-
- try {
- InputsBusinessLogic businessLogic = getInputBL(context);
-
- // get modifier id
- User modifier = new User();
- modifier.setUserId(userId);
- log.debug("modifier id is {}", userId);
-
- Either<ComponentInstInputsMap, ResponseFormat> componentInstInputsMapRes = parseToComponentInstanceMap(componentInstInputsMapObj, modifier);
- if (componentInstInputsMapRes.isRight()) {
- log.debug("failed to parse componentInstInputsMap");
- response = buildErrorResponse(componentInstInputsMapRes.right().value());
- return response;
- }
-
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
- ComponentInstInputsMap componentInstInputsMap = componentInstInputsMapRes.left().value();
-
- Either<List<InputDefinition>, ResponseFormat> inputPropertiesRes = businessLogic.createMultipleInputs(userId, componentId, componentTypeEnum, componentInstInputsMap, true, false);
- if (inputPropertiesRes.isRight()) {
- log.debug("failed to create inputs for service: {}", componentId);
- return buildErrorResponse(inputPropertiesRes.right().value());
- }
- Object properties = RepresentationUtils.toRepresentation(inputPropertiesRes.left().value());
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), properties);
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create inputs for service with id: " + componentId);
- log.debug("createMultipleInputs failed with exception", e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
- }
+ return super.declareProperties(userId, componentId, componentType, componentInstInputsMapObj,
+ DeclarationTypeEnum.INPUT, request);
}
@@ -329,10 +304,4 @@ public class InputsServlet extends AbstractValidationsServlet {
}
}
- private InputsBusinessLogic getInputBL(ServletContext context) {
- WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
- WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
- return webApplicationContext.getBean(InputsBusinessLogic.class);
- }
-
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/PolicyServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/PolicyServlet.java
index 49a827ebec..3208102d1c 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/PolicyServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/PolicyServlet.java
@@ -2,7 +2,28 @@ package org.openecomp.sdc.be.servlets;
import com.jcabi.aspects.Loggable;
import fj.data.Either;
-import io.swagger.annotations.*;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
import org.apache.commons.lang3.StringUtils;
import org.openecomp.sdc.be.components.impl.PolicyBusinessLogic;
import org.openecomp.sdc.be.components.impl.ResourceImportManager;
@@ -11,26 +32,18 @@ import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.elements.PolicyTargetType;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.DeclarationTypeEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.impl.ServletUtils;
import org.openecomp.sdc.be.model.PolicyDefinition;
import org.openecomp.sdc.be.model.PolicyTargetDTO;
+import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.datastructure.Wrapper;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.stereotype.Controller;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.*;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-
/**
* Provides REST API to create, retrieve, update, delete a policy
*/
@@ -160,7 +173,7 @@ public class PolicyServlet extends AbstractValidationsServlet {
Wrapper<ComponentTypeEnum> componentTypeWrapper = validateComponentTypeAndUserId(containerComponentType, userId, responseWrapper);
if (responseWrapper.isEmpty()) {
responseWrapper.setInnerElement(policyBusinessLogic.deletePolicy(componentTypeWrapper.getInnerElement(), containerComponentId, policyId, userId, true)
- .either(l -> buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT), null),
+ .either(this::buildOkResponse,
this::buildErrorResponse));
}
@@ -172,6 +185,34 @@ public class PolicyServlet extends AbstractValidationsServlet {
return responseWrapper.getInnerElement();
}
+ @PUT
+ @Path("/{containerComponentType}/{componentId}/policies/{policyId}/undeclare")
+ @ApiOperation(value = "undeclare Policy", httpMethod = "PUT", notes = "No body", response = Response.class)
+ @ApiResponses(value = {@ApiResponse(code = 204, message = "Policy was undeclared"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
+ @ApiResponse(code = 404, message = "component / policy Not found")})
+ public Response undeclarePolicy(@PathParam("componentId") final String containerComponentId,
+ @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
+ @PathParam("policyId") final String policyId, @HeaderParam(value = Constants.USER_ID_HEADER) @ApiParam(value = "USER_ID of modifier user", required = true) String userId,
+ @Context final HttpServletRequest request) {
+ init();
+
+ Wrapper<Response> responseWrapper = new Wrapper<>();
+ try {
+ Wrapper<ComponentTypeEnum> componentTypeWrapper = validateComponentTypeAndUserId(containerComponentType, userId, responseWrapper);
+ if (responseWrapper.isEmpty()) {
+ responseWrapper.setInnerElement(policyBusinessLogic.undeclarePolicy(componentTypeWrapper.getInnerElement(), containerComponentId, policyId, userId, true)
+ .either(this::buildOkResponse,
+ this::buildErrorResponse));
+ }
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Undeclare Policy");
+ log.error("Failed to undeclare policy. The exception {} occurred. ", e);
+ responseWrapper.setInnerElement(buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)));
+ }
+ return responseWrapper.getInnerElement();
+ }
+
@GET
@Path("/{containerComponentType}/{componentId}/policies/{policyId}/properties")
@ApiOperation(value = "Get component policy properties", httpMethod = "GET", notes = "Returns component policy properties", response = PropertyDataDefinition.class, responseContainer="List")
@@ -268,6 +309,17 @@ public class PolicyServlet extends AbstractValidationsServlet {
}
}
+ @POST
+ @Path("/{componentType}/{componentId}/create/policies")
+ @ApiOperation(value = "Create policies on service", httpMethod = "POST", notes = "Return policies list", response = Resource.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Component found"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Component not found") })
+ public Response declareProperties(@PathParam("componentType") final String componentType, @PathParam("componentId") final String componentId, @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @ApiParam(value = "ComponentIns policies Object to be created", required = true) String componentInstPoliciesMapObj) {
+
+ return super.declareProperties(userId, componentId, componentType, componentInstPoliciesMapObj,
+ DeclarationTypeEnum.POLICY, request);
+ }
+
private Either<PolicyDefinition, ResponseFormat> updatePolicyTargetsFromMap(Map<PolicyTargetType, List<String>> policyTarget, String containerComponentType, String containerComponentId, String policyId, String userId) {
return convertToComponentType(containerComponentType)
.left()
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java
index 360f12579a..32a2334669 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java
@@ -17,13 +17,20 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.openecomp.sdc.be.components.impl;
import static org.assertj.core.api.Assertions.assertThat;
import fj.data.Either;
-
-import java.util.*;
-
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+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 mockit.Deencapsulation;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.assertj.core.util.Lists;
@@ -49,8 +56,24 @@ import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.impl.ServletUtils;
import org.openecomp.sdc.be.info.CreateAndAssotiateInfo;
-import org.openecomp.sdc.be.model.*;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.CapabilityDefinition;
+import org.openecomp.sdc.be.model.CapabilityRequirementRelationship;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentInstanceInput;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.ComponentParametersView;
+import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.PolicyDefinition;
+import org.openecomp.sdc.be.model.RelationshipImpl;
+import org.openecomp.sdc.be.model.RelationshipInfo;
+import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
+import org.openecomp.sdc.be.model.RequirementDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.jsontitan.operations.ForwardingPathOperation;
import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
@@ -71,6 +94,7 @@ import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;
import static org.mockito.ArgumentMatchers.*;
+import static org.mockito.Mockito.when;
/**
* The test suite designed for test functionality of ComponentInstanceBusinessLogic class
@@ -81,6 +105,7 @@ public class ComponentInstanceBusinessLogicTest {
private final static String USER_ID = "jh0003";
private final static String COMPONENT_ID = "componentId";
+ private final static String COMPONENT_INST_ID = "componentInstId";
private final static String TO_INSTANCE_ID = "toInstanceId";
private final static String FROM_INSTANCE_ID = "fromInstanceId";
private final static String RELATION_ID = "relationId";
@@ -96,6 +121,8 @@ public class ComponentInstanceBusinessLogicTest {
private final static String ARTIFACT_3 = "cloudtech_aws_configtemplate.zip";
private final static String ARTIFACT_4 = "k8s_charts.zip";
private final static String ARTIFACT_5 = "cloudtech_openstack_configtemplate.zip";
+ private final static String PROP_NAME = "propName";
+ private final static String NON_EXIST_NAME = "nonExistName";
@InjectMocks
private static ComponentInstanceBusinessLogic componentInstanceBusinessLogic;
@@ -132,31 +159,31 @@ public class ComponentInstanceBusinessLogicTest {
@Before
- public void init(){
+ public void init() {
stubMethods();
createComponents();
}
@Test
- public void testGetRelationByIdSuccess(){
+ public void testGetRelationByIdSuccess() {
getServiceRelationByIdSuccess(service);
getServiceRelationByIdSuccess(resource);
}
@Test
- public void testGetRelationByIdUserValidationFailure(){
+ public void testGetRelationByIdUserValidationFailure() {
getServiceRelationByIdUserValidationFailure(service);
getServiceRelationByIdUserValidationFailure(resource);
}
@Test
- public void testGetRelationByIdComponentNotFoundFailure(){
+ public void testGetRelationByIdComponentNotFoundFailure() {
getRelationByIdComponentNotFoundFailure(service);
getRelationByIdComponentNotFoundFailure(resource);
}
@Test
- public void testForwardingPathOnVersionChange(){
+ public void testForwardingPathOnVersionChange() {
getforwardingPathOnVersionChange();
}
@@ -170,60 +197,66 @@ public class ComponentInstanceBusinessLogicTest {
}
private void getforwardingPathOnVersionChange(){
- String containerComponentParam="services";
- String containerComponentID="121-cont";
- String componentInstanceID="121-cont-1-comp";
- Service component=new Service();
+ String containerComponentParam = "services";
+ String containerComponentID = "121-cont";
+ String componentInstanceID = "121-cont-1-comp";
+ Service component = new Service();
Map<String, ForwardingPathDataDefinition> forwardingPaths = generateForwardingPath(componentInstanceID);
//Add existing componentInstance to component
- List<ComponentInstance> componentInstanceList=new ArrayList<>();
- ComponentInstance oldComponentInstance=new ComponentInstance();
+ List<ComponentInstance> componentInstanceList = new ArrayList<>();
+ ComponentInstance oldComponentInstance = new ComponentInstance();
oldComponentInstance.setName("OLD_COMP_INSTANCE");
oldComponentInstance.setUniqueId(componentInstanceID);
oldComponentInstance.setName(componentInstanceID);
- oldComponentInstance.setToscaPresentationValue(JsonPresentationFields.CI_COMPONENT_UID,"1-comp");
+ oldComponentInstance.setToscaPresentationValue(JsonPresentationFields.CI_COMPONENT_UID, "1-comp");
componentInstanceList.add(oldComponentInstance);
component.setComponentInstances(componentInstanceList);
component.setForwardingPaths(forwardingPaths);
- List<ComponentInstance> componentInstanceListNew=new ArrayList<>();
- ComponentInstance newComponentInstance=new ComponentInstance();
- String new_Comp_UID="2-comp";
- newComponentInstance.setToscaPresentationValue(JsonPresentationFields.CI_COMPONENT_UID,new_Comp_UID);
+ List<ComponentInstance> componentInstanceListNew = new ArrayList<>();
+ ComponentInstance newComponentInstance = new ComponentInstance();
+ String new_Comp_UID = "2-comp";
+ newComponentInstance.setToscaPresentationValue(JsonPresentationFields.CI_COMPONENT_UID, new_Comp_UID);
newComponentInstance.setUniqueId(new_Comp_UID);
componentInstanceListNew.add(newComponentInstance);
- Component component2=new Service();
+ Component component2 = new Service();
component2.setComponentInstances(componentInstanceListNew);
//Mock for getting component
- when(toscaOperationFacade.getToscaElement(eq(containerComponentID),any(ComponentParametersView.class))).thenReturn(Either.left(component));
+ when(toscaOperationFacade.getToscaElement(eq(containerComponentID), any(ComponentParametersView.class)))
+ .thenReturn(Either.left(component));
when(toscaOperationFacade.validateComponentExists(any(String.class))).thenReturn(Either.left(Boolean.TRUE));
when(toscaOperationFacade.getToscaFullElement(eq(new_Comp_UID))).thenReturn(Either.left(component2));
- Either<Set<String>, ResponseFormat> resultOp = componentInstanceBusinessLogic.forwardingPathOnVersionChange
- (containerComponentParam,containerComponentID,componentInstanceID,newComponentInstance);
- assertEquals(1,resultOp.left().value().size());
- assertEquals("FP-ID-1",resultOp.left().value().iterator().next());
+ Either<Set<String>, ResponseFormat> resultOp = componentInstanceBusinessLogic
+ .forwardingPathOnVersionChange(containerComponentParam,
+ containerComponentID, componentInstanceID,
+ newComponentInstance);
+ assertEquals(1, resultOp.left().value().size());
+ assertEquals("FP-ID-1", resultOp.left().value().iterator().next());
}
@Test
- public void testDeleteForwardingPathsWhenComponentinstanceDeleted(){
+ public void testDeleteForwardingPathsWhenComponentinstanceDeleted() {
ComponentTypeEnum containerComponentType = ComponentTypeEnum.findByParamName("services");
String containerComponentID = "Service-comp";
String componentInstanceID = "NodeA1";
Service component = new Service();
- component.setComponentInstances(Arrays.asList(createComponentIstance("NodeA2"),createComponentIstance("NodeB2"),
- createComponentIstance(componentInstanceID)));
-
- component.addForwardingPath(createPath("path1", componentInstanceID, "NodeB1", "1"));
- component.addForwardingPath(createPath("Path2", "NodeA2","NodeB2", "2"));
- when(toscaOperationFacade.getToscaElement(eq(containerComponentID),any(ComponentParametersView.class))).thenReturn(Either.left(component));
+ component.setComponentInstances(
+ Arrays.asList(createComponentIstance("NodeA2"), createComponentIstance("NodeB2"),
+ createComponentIstance(componentInstanceID)));
+
+ component.addForwardingPath(createPath("path1", componentInstanceID, "NodeB1", "1"));
+ component.addForwardingPath(createPath("Path2", "NodeA2", "NodeB2", "2"));
+ when(toscaOperationFacade.getToscaElement(eq(containerComponentID), any(ComponentParametersView.class)))
+ .thenReturn(Either.left(component));
when(toscaOperationFacade.getToscaElement(eq(containerComponentID))).thenReturn(Either.left(component));
- when(forwardingPathOperation.deleteForwardingPath(any(Service.class), anySet())).thenReturn(Either.left(new HashSet<>()));
+ when(forwardingPathOperation.deleteForwardingPath(any(Service.class), anySet()))
+ .thenReturn(Either.left(new HashSet<>()));
final ComponentInstance ci = new ComponentInstance();
ci.setName(componentInstanceID);
Either<ComponentInstance, ResponseFormat> responseFormatEither = componentInstanceBusinessLogic.deleteForwardingPathsRelatedTobeDeletedComponentInstance(
@@ -238,21 +271,22 @@ public class ComponentInstanceBusinessLogicTest {
return componentInstance;
}
- private ForwardingPathDataDefinition createPath(String pathName, String fromNode, String toNode , String uniqueId){
+ private ForwardingPathDataDefinition createPath(String pathName, String fromNode, String toNode, String uniqueId) {
ForwardingPathDataDefinition forwardingPath = new ForwardingPathDataDefinition(pathName);
forwardingPath.setProtocol("protocol");
forwardingPath.setDestinationPortNumber("port");
forwardingPath.setUniqueId(uniqueId);
- ListDataDefinition<ForwardingPathElementDataDefinition> forwardingPathElementListDataDefinition = new ListDataDefinition<>();
- forwardingPathElementListDataDefinition.add(new ForwardingPathElementDataDefinition(fromNode, toNode,
- "nodeAcpType", "nodeBcpType", "nodeDcpName", "nodeBcpName"));
+ ListDataDefinition<ForwardingPathElementDataDefinition> forwardingPathElementListDataDefinition =
+ new ListDataDefinition<>();
+ forwardingPathElementListDataDefinition
+ .add(new ForwardingPathElementDataDefinition(fromNode, toNode, "nodeAcpType", "nodeBcpType",
+ "nodeDcpName", "nodeBcpName"));
forwardingPath.setPathElements(forwardingPathElementListDataDefinition);
return forwardingPath;
}
-
private Map<String, ForwardingPathDataDefinition> generateForwardingPath(String componentInstanceID) {
ForwardingPathDataDefinition forwardingPath = new ForwardingPathDataDefinition("fpName");
String protocol = "protocol";
@@ -261,10 +295,9 @@ public class ComponentInstanceBusinessLogicTest {
forwardingPath.setUniqueId("FP-ID-1");
ListDataDefinition<ForwardingPathElementDataDefinition> forwardingPathElementListDataDefinition =
new ListDataDefinition<>();
- forwardingPathElementListDataDefinition.add(
- new ForwardingPathElementDataDefinition(componentInstanceID, "nodeB", "nodeA_FORWARDER_CAPABILITY",
- "nodeBcpType" , "nodeDcpName",
- "nodeBcpName"));
+ forwardingPathElementListDataDefinition
+ .add(new ForwardingPathElementDataDefinition(componentInstanceID, "nodeB", "nodeA_FORWARDER_CAPABILITY",
+ "nodeBcpType", "nodeDcpName", "nodeBcpName"));
forwardingPath.setPathElements(forwardingPathElementListDataDefinition);
Map<String, ForwardingPathDataDefinition> forwardingPaths = new HashMap<>();
forwardingPaths.put("1122", forwardingPath);
@@ -272,28 +305,38 @@ public class ComponentInstanceBusinessLogicTest {
}
@SuppressWarnings("unchecked")
- private void getServiceRelationByIdSuccess(Component component){
+ private void getServiceRelationByIdSuccess(Component component) {
Either<Component, StorageOperationStatus> getComponentRes = Either.left(component);
- when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class))).thenReturn(getComponentRes);
- Either<RequirementCapabilityRelDef, ResponseFormat> response = componentInstanceBusinessLogic.getRelationById(COMPONENT_ID, RELATION_ID, USER_ID, component.getComponentType());
+ when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class)))
+ .thenReturn(getComponentRes);
+ Either<RequirementCapabilityRelDef, ResponseFormat> response = componentInstanceBusinessLogic
+ .getRelationById(COMPONENT_ID,
+ RELATION_ID, USER_ID,
+ component.getComponentType());
assertTrue(response.isLeft());
}
- private void getServiceRelationByIdUserValidationFailure(Component component){
- when(userValidations.validateUserExists(eq(USER_ID), eq("get relation by Id"), eq(false))).thenThrow(new ComponentException(ActionStatus.USER_NOT_FOUND));
- try{
- componentInstanceBusinessLogic.getRelationById(COMPONENT_ID, RELATION_ID, USER_ID, component.getComponentType());
- } catch(ComponentException e){
+ private void getServiceRelationByIdUserValidationFailure(Component component) {
+ when(userValidations.validateUserExists(eq(USER_ID), eq("get relation by Id"), eq(false)))
+ .thenThrow(new ComponentException(ActionStatus.USER_NOT_FOUND));
+ try {
+ componentInstanceBusinessLogic
+ .getRelationById(COMPONENT_ID, RELATION_ID, USER_ID, component.getComponentType());
+ } catch (ComponentException e) {
assertSame(e.getActionStatus(), ActionStatus.USER_NOT_FOUND);
}
}
- private void getRelationByIdComponentNotFoundFailure(Component component){
+ private void getRelationByIdComponentNotFoundFailure(Component component) {
Either<User, ActionStatus> eitherCreator = Either.left(user);
Either<Component, StorageOperationStatus> getComponentRes = Either.right(StorageOperationStatus.NOT_FOUND);
- when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class))).thenReturn(getComponentRes);
+ when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class)))
+ .thenReturn(getComponentRes);
- Either<RequirementCapabilityRelDef, ResponseFormat> response = componentInstanceBusinessLogic.getRelationById(COMPONENT_ID, RELATION_ID, USER_ID, component.getComponentType());
+ Either<RequirementCapabilityRelDef, ResponseFormat> response = componentInstanceBusinessLogic
+ .getRelationById(COMPONENT_ID,
+ RELATION_ID, USER_ID,
+ component.getComponentType());
assertTrue(response.isRight());
}
@@ -312,7 +355,7 @@ public class ComponentInstanceBusinessLogicTest {
resource = new Resource();
resource.setUniqueId(COMPONENT_ID);
resource.setComponentInstancesRelations(Lists.newArrayList(relation));
- resource.setComponentInstances(Lists.newArrayList(toInstance,fromInstance));
+ resource.setComponentInstances(Lists.newArrayList(toInstance, fromInstance));
resource.setCapabilities(toInstance.getCapabilities());
resource.setRequirements(fromInstance.getRequirements());
resource.setComponentType(ComponentTypeEnum.RESOURCE);
@@ -324,7 +367,7 @@ public class ComponentInstanceBusinessLogicTest {
service = new Service();
service.setUniqueId(COMPONENT_ID);
service.setComponentInstancesRelations(Lists.newArrayList(relation));
- service.setComponentInstances(Lists.newArrayList(toInstance,fromInstance));
+ service.setComponentInstances(Lists.newArrayList(toInstance, fromInstance));
service.setCapabilities(toInstance.getCapabilities());
service.setRequirements(fromInstance.getRequirements());
service.setComponentType(ComponentTypeEnum.SERVICE);
@@ -380,7 +423,7 @@ public class ComponentInstanceBusinessLogicTest {
relationInfo.setRequirementOwnerId(REQUIREMENT_OWNER_ID);
relationInfo.setRequirementUid(REQUIREMENT_UID);
relationInfo.setRequirement(REQUIREMENT_NAME);
- RelationshipImpl relationshipImpl = new RelationshipImpl();
+ RelationshipImpl relationshipImpl = new RelationshipImpl();
relationshipImpl.setType(RELATIONSHIP_TYPE);
relationInfo.setRelationships(relationshipImpl);
}
@@ -390,11 +433,8 @@ public class ComponentInstanceBusinessLogicTest {
}
-
-
-
@Test
- public void testChangeServiceProxyVersion(){
+ public void testChangeServiceProxyVersion() {
ComponentInstanceBusinessLogic componentInstanceBusinessLogic;
Either<ComponentInstance, ResponseFormat> result;
@@ -405,13 +445,8 @@ public class ComponentInstanceBusinessLogicTest {
}
-
-
-
-
-
@Test
- public void testCreateServiceProxy() {
+ public void testCreateServiceProxy() {
ComponentInstanceBusinessLogic testSubject;
Either<ComponentInstance, ResponseFormat> result;
@@ -421,11 +456,8 @@ public class ComponentInstanceBusinessLogicTest {
}
-
-
-
@Test
- public void testDeleteForwardingPathsRelatedTobeDeletedComponentInstance() {
+ public void testDeleteForwardingPathsRelatedTobeDeletedComponentInstance() {
ComponentInstanceBusinessLogic testSubject;
String containerComponentId = "";
String componentInstanceId = "";
@@ -452,12 +484,8 @@ public class ComponentInstanceBusinessLogicTest {
}
-
-
-
-
@Test
- public void testGetComponentInstanceInputsByInputId() {
+ public void testGetComponentInstanceInputsByInputId() {
ComponentInstanceBusinessLogic testSubject;
Component component = new Service();
String inputId = "";
@@ -469,9 +497,8 @@ public class ComponentInstanceBusinessLogicTest {
}
-
@Test
- public void testGetComponentInstancePropertiesByInputId() {
+ public void testGetComponentInstancePropertiesByInputId() {
ComponentInstanceBusinessLogic testSubject;
Component component = new Service();
String inputId = "";
@@ -484,7 +511,7 @@ public class ComponentInstanceBusinessLogicTest {
@Test
- public void testGetRelationById() {
+ public void testGetRelationById() {
ComponentInstanceBusinessLogic testSubject;
String componentId = "";
String relationId = "";
@@ -498,112 +525,115 @@ public class ComponentInstanceBusinessLogicTest {
}
-
-
-
@Test
- public void testCreateComponentInstance_1() {
- ComponentInstanceBusinessLogic testSubject;String containerComponentParam = "";
+ public void testCreateComponentInstance_1() {
+ ComponentInstanceBusinessLogic testSubject;
+ String containerComponentParam = "";
String containerComponentId = "";
String userId = user.getUserId();
ComponentInstance resourceInstance = null;
boolean inTransaction = false;
boolean needLock = false;
- Either<ComponentInstance,ResponseFormat> result;
+ Either<ComponentInstance, ResponseFormat> result;
// default test
- testSubject=createTestSubject();result=testSubject.createComponentInstance(containerComponentParam, containerComponentId, userId, resourceInstance, inTransaction, needLock);
+ testSubject = createTestSubject();
+ result = testSubject.createComponentInstance(containerComponentParam, containerComponentId, userId,
+ resourceInstance, inTransaction, needLock);
}
-
-
-
@Test
- public void testCreateAndAssociateRIToRI() {
+ public void testCreateAndAssociateRIToRI() {
ComponentInstanceBusinessLogic testSubject;
String containerComponentParam = "";
String containerComponentId = "";
String userId = user.getUserId();
CreateAndAssotiateInfo createAndAssotiateInfo = new CreateAndAssotiateInfo(null, null);
- Either<CreateAndAssotiateInfo,ResponseFormat> result;
+ Either<CreateAndAssotiateInfo, ResponseFormat> result;
// default test
- testSubject=createTestSubject();
- result=testSubject.createAndAssociateRIToRI(containerComponentParam, containerComponentId, userId, createAndAssotiateInfo);
+ testSubject = createTestSubject();
+ result = testSubject.createAndAssociateRIToRI(containerComponentParam, containerComponentId, userId,
+ createAndAssotiateInfo);
}
@Test
- public void testGetOriginComponentFromComponentInstance_1() {
+ public void testGetOriginComponentFromComponentInstance_1() {
ComponentInstanceBusinessLogic testSubject;
createResource();
String componentInstanceName = "";
String origComponetId = resource.getUniqueId();
Either<Component, StorageOperationStatus> oldResourceRes = Either.left(resource);
when(toscaOperationFacade.getToscaFullElement(resource.getUniqueId())).thenReturn(oldResourceRes);
- Either<Component,ResponseFormat> result;
+ Either<Component, ResponseFormat> result;
// default test
- testSubject=createTestSubject();
- result=Deencapsulation.invoke(testSubject, "getOriginComponentFromComponentInstance", new Object[]{componentInstanceName, origComponetId});
+ testSubject = createTestSubject();
+ result = Deencapsulation.invoke(testSubject, "getOriginComponentFromComponentInstance",
+ new Object[] {componentInstanceName, origComponetId});
}
@Test
- public void testCreateComponentInstanceOnGraph() {
+ public void testCreateComponentInstanceOnGraph() {
ComponentInstanceBusinessLogic testSubject;
createResource();
createInstances();
- Either<ComponentInstance,ResponseFormat> result;
+ Either<ComponentInstance, ResponseFormat> result;
- Either<ImmutablePair<Component, String>, StorageOperationStatus> result2 = Either.right(StorageOperationStatus.ARTIFACT_NOT_FOUND);
- when(toscaOperationFacade.addComponentInstanceToTopologyTemplate(resource, resource,toInstance, false, user)).thenReturn(result2);
+ Either<ImmutablePair<Component, String>, StorageOperationStatus> result2 =
+ Either.right(StorageOperationStatus.ARTIFACT_NOT_FOUND);
+ when(toscaOperationFacade.addComponentInstanceToTopologyTemplate(resource, resource, toInstance, false, user))
+ .thenReturn(result2);
// default test
- testSubject=createTestSubject();
- result=Deencapsulation.invoke(testSubject, "createComponentInstanceOnGraph", new Object[]{resource, resource, toInstance, user});
+ testSubject = createTestSubject();
+ result = Deencapsulation.invoke(testSubject, "createComponentInstanceOnGraph",
+ new Object[] {resource, resource, toInstance, user});
}
@Ignore("test failing skipping for now")
@Test
- public void testCreateComponentInstanceOnGraph2() {
+ public void testCreateComponentInstanceOnGraph2() {
ComponentInstanceBusinessLogic testSubject;
createResource();
resource.setName("name");
createInstances();
- Either<ComponentInstance,ResponseFormat> result;
- ImmutablePair<Component, String> pair = new ImmutablePair<>(resource,"");
-
-
+ Either<ComponentInstance, ResponseFormat> result;
+ ImmutablePair<Component, String> pair = new ImmutablePair<>(resource, "");
Either<ImmutablePair<Component, String>, StorageOperationStatus> result2 = Either.left(pair);
- when(toscaOperationFacade.addComponentInstanceToTopologyTemplate(resource, resource,toInstance, false, user)).thenReturn(result2);
+ when(toscaOperationFacade.addComponentInstanceToTopologyTemplate(resource, resource, toInstance, false, user))
+ .thenReturn(result2);
// default test
- testSubject=createTestSubject();
- result=Deencapsulation.invoke(testSubject, "createComponentInstanceOnGraph", new Object[]{resource, resource, toInstance, user});
+ testSubject = createTestSubject();
+ result = Deencapsulation.invoke(testSubject, "createComponentInstanceOnGraph",
+ new Object[] {resource, resource, toInstance, user});
}
@Test
- public void testUpdateComponentInstanceMetadata() {
+ public void testUpdateComponentInstanceMetadata() {
ComponentInstanceBusinessLogic testSubject;
String containerComponentParam = "";
String containerComponentId = "";
String componentInstanceId = "";
String userId = user.getUserId();
createInstances();
- Either<ComponentInstance,ResponseFormat> result;
+ Either<ComponentInstance, ResponseFormat> result;
// default test
- testSubject=createTestSubject();
- result=testSubject.updateComponentInstanceMetadata(containerComponentParam, containerComponentId, componentInstanceId, userId, toInstance);
+ testSubject = createTestSubject();
+ result = testSubject.updateComponentInstanceMetadata(containerComponentParam, containerComponentId,
+ componentInstanceId, userId, toInstance);
}
@Test
- public void testUpdateComponentInstanceMetadata_1() {
+ public void testUpdateComponentInstanceMetadata_1() {
ComponentInstanceBusinessLogic testSubject;
String containerComponentParam = "";
String containerComponentId = "";
@@ -613,27 +643,25 @@ public class ComponentInstanceBusinessLogicTest {
boolean inTransaction = false;
boolean needLock = false;
boolean createNewTransaction = false;
- Either<ComponentInstance,ResponseFormat> result;
+ Either<ComponentInstance, ResponseFormat> result;
// default test
- testSubject=createTestSubject();
- result=testSubject.updateComponentInstanceMetadata(containerComponentParam, containerComponentId, componentInstanceId, userId, toInstance, inTransaction, needLock, createNewTransaction);
+ testSubject = createTestSubject();
+ result = testSubject.updateComponentInstanceMetadata(containerComponentParam, containerComponentId,
+ componentInstanceId, userId, toInstance, inTransaction, needLock, createNewTransaction);
}
-
-
-
@Test
- public void testValidateParent() {
+ public void testValidateParent() {
ComponentInstanceBusinessLogic testSubject;
createResource();
String nodeTemplateId = "";
boolean result;
// default test
- testSubject=createTestSubject();
- result=Deencapsulation.invoke(testSubject, "validateParent", new Object[]{resource, nodeTemplateId});
+ testSubject = createTestSubject();
+ result = Deencapsulation.invoke(testSubject, "validateParent", new Object[] {resource, nodeTemplateId});
}
@@ -643,66 +671,74 @@ public class ComponentInstanceBusinessLogicTest {
ComponentTypeEnum result;
// default test
- testSubject=createTestSubject();
- result=Deencapsulation.invoke(testSubject, "getComponentType", new Object[]{ComponentTypeEnum.class});
+ testSubject = createTestSubject();
+ result = Deencapsulation.invoke(testSubject, "getComponentType", new Object[] {ComponentTypeEnum.class});
}
-
@Test
- public void testGetNewGroupName() {
- ComponentInstanceBusinessLogic testSubject;String oldPrefix = "";
+ public void testGetNewGroupName() {
+ ComponentInstanceBusinessLogic testSubject;
+ String oldPrefix = "";
String newNormailzedPrefix = "";
String qualifiedGroupInstanceName = "";
String result;
// test 1
- testSubject=createTestSubject();
- result=Deencapsulation.invoke(testSubject, "getNewGroupName", new Object[]{oldPrefix, newNormailzedPrefix, qualifiedGroupInstanceName});
+ testSubject = createTestSubject();
+ result = Deencapsulation.invoke(testSubject, "getNewGroupName",
+ new Object[] {oldPrefix, newNormailzedPrefix, qualifiedGroupInstanceName});
}
@Test
- public void testUpdateComponentInstanceMetadata_3() {
+ public void testUpdateComponentInstanceMetadata_3() {
ComponentInstanceBusinessLogic testSubject;
createInstances();
ComponentInstance newComponentInstance = null;
ComponentInstance result;
// default test
- testSubject=createTestSubject();
- result=Deencapsulation.invoke(testSubject, "updateComponentInstanceMetadata", new Object[]{toInstance, toInstance});
+ testSubject = createTestSubject();
+ result = Deencapsulation
+ .invoke(testSubject, "updateComponentInstanceMetadata", new Object[] {toInstance, toInstance});
}
@Test
- public void testDeleteComponentInstance() {
- ComponentInstanceBusinessLogic testSubject;String containerComponentParam = "";
+ public void testDeleteComponentInstance() throws Exception {
+ ComponentInstanceBusinessLogic testSubject;
+ String containerComponentParam = "";
String containerComponentId = "";
String componentInstanceId = "";
String userId = user.getUserId();
- Either<ComponentInstance,ResponseFormat> result;
+ Either<ComponentInstance, ResponseFormat> result;
// default test
- testSubject=createTestSubject();
- result=testSubject.deleteComponentInstance(containerComponentParam, containerComponentId, componentInstanceId, userId);
+ testSubject = createTestSubject();
+ TitanDao mock = Mockito.mock(TitanDao.class);
+ testSubject.setTitanGenericDao(mock);
+ result = testSubject.deleteComponentInstance(containerComponentParam, containerComponentId, componentInstanceId,
+ userId);
}
@Test
- public void testDeleteForwardingPaths() {
+ public void testDeleteForwardingPaths() {
ComponentInstanceBusinessLogic testSubject;
createService();
String serviceId = service.getUniqueId();
List<String> pathIdsToDelete = new ArrayList<>();
- Either<Set<String>,ResponseFormat> result;
+ Either<Set<String>, ResponseFormat> result;
// Either<Service, StorageOperationStatus> storageStatus = toscaOperationFacade.getToscaElement(serviceId);
- when(toscaOperationFacade.getToscaElement(serviceId)).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
+ when(toscaOperationFacade.getToscaElement(serviceId))
+ .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
// default test
- testSubject=createTestSubject();
- result=Deencapsulation.invoke(testSubject, "deleteForwardingPaths", new Object[]{serviceId, pathIdsToDelete});
+ testSubject = createTestSubject();
+ result =
+ Deencapsulation.invoke(testSubject, "deleteForwardingPaths", new Object[] {serviceId, pathIdsToDelete});
}
@@ -713,20 +749,19 @@ public class ComponentInstanceBusinessLogicTest {
RequirementCapabilityRelDef requirementDef = new RequirementCapabilityRelDef();
ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE;
boolean inTransaction = false;
- Either<RequirementCapabilityRelDef,ResponseFormat> result;
-
+ Either<RequirementCapabilityRelDef, ResponseFormat> result;
Either<RequirementCapabilityRelDef, StorageOperationStatus> getResourceResult = Either.left(requirementDef);
- when(toscaOperationFacade.associateResourceInstances(resource.getUniqueId(), requirementDef)).thenReturn(getResourceResult);
+ when(toscaOperationFacade.associateResourceInstances(resource.getUniqueId(), requirementDef))
+ .thenReturn(getResourceResult);
// default test
- testSubject=createTestSubject();
- result=testSubject.associateRIToRIOnGraph(resource, requirementDef, componentTypeEnum, inTransaction);
+ testSubject = createTestSubject();
+ result = testSubject.associateRIToRIOnGraph(resource, requirementDef, componentTypeEnum, inTransaction);
}
-
@Test
public void testFindRelation() throws Exception {
ComponentInstanceBusinessLogic testSubject;
@@ -735,8 +770,9 @@ public class ComponentInstanceBusinessLogicTest {
RequirementCapabilityRelDef result;
// default test
- testSubject=createTestSubject();
- result=Deencapsulation.invoke(testSubject, "findRelation", new Object[]{relationId, requirementCapabilityRelations});
+ testSubject = createTestSubject();
+ result = Deencapsulation.invoke(testSubject, "findRelation",
+ new Object[] {relationId, requirementCapabilityRelations});
}
@@ -748,8 +784,9 @@ public class ComponentInstanceBusinessLogicTest {
boolean result;
// default test
- testSubject=createTestSubject();
- result=Deencapsulation.invoke(testSubject, "isNetworkRoleServiceProperty", new Object[]{property, componentTypeEnum});
+ testSubject = createTestSubject();
+ result = Deencapsulation.invoke(testSubject, "isNetworkRoleServiceProperty",
+ new Object[] {property, componentTypeEnum});
}
@@ -764,8 +801,9 @@ public class ComponentInstanceBusinessLogicTest {
StorageOperationStatus result;
// default test
- testSubject=createTestSubject();
- result=Deencapsulation.invoke(testSubject, "concatServiceNameToVLINetworkRolePropertiesValues", new Object[]{toscaOperationFacade, componentTypeEnum, componentId, resourceInstanceId, properties});
+ testSubject = createTestSubject();
+ result = Deencapsulation.invoke(testSubject, "concatServiceNameToVLINetworkRolePropertiesValues",
+ new Object[] {toscaOperationFacade, componentTypeEnum, componentId, resourceInstanceId, properties});
}
@@ -778,20 +816,27 @@ public class ComponentInstanceBusinessLogicTest {
String resourceInstanceId = "";
List<ComponentInstanceProperty> properties = new ArrayList<>();
String userId = user.getUserId();
- Either<List<ComponentInstanceProperty>,ResponseFormat> result;
+ Either<List<ComponentInstanceProperty>, ResponseFormat> result;
- when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseAll)).thenReturn(Either.left(resource));
+ when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseAll))
+ .thenReturn(Either.left(resource));
// test 1
- testSubject=createTestSubject();
- result=testSubject.createOrUpdatePropertiesValues(componentTypeEnum, componentId, resourceInstanceId, properties, userId);
+ testSubject = createTestSubject();
+ result = testSubject
+ .createOrUpdatePropertiesValues(componentTypeEnum, componentId, resourceInstanceId, properties,
+ userId);
- componentTypeEnum =null;
- result=testSubject.createOrUpdatePropertiesValues(componentTypeEnum, componentId, resourceInstanceId, properties, userId);
+ componentTypeEnum = null;
+ result = testSubject
+ .createOrUpdatePropertiesValues(componentTypeEnum, componentId, resourceInstanceId, properties,
+ userId);
-// when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseAll)).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
- result=testSubject.createOrUpdatePropertiesValues(componentTypeEnum, componentId, resourceInstanceId, properties, userId);
+ // when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseAll)).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
+ result = testSubject
+ .createOrUpdatePropertiesValues(componentTypeEnum, componentId, resourceInstanceId, properties,
+ userId);
}
@@ -808,12 +853,12 @@ public class ComponentInstanceBusinessLogicTest {
ResponseFormat result;
// default test
- testSubject=createTestSubject();
- result=Deencapsulation.invoke(testSubject, "updateCapabilityPropertyOnContainerComponent", new Object[]{property, newValue, resource, toInstance, capabilityType, capabilityName});
+ testSubject = createTestSubject();
+ result = Deencapsulation.invoke(testSubject, "updateCapabilityPropertyOnContainerComponent",
+ new Object[] {property, newValue, resource, toInstance, capabilityType, capabilityName});
}
-
@Test
public void testCreateOrUpdateInstanceInputValues() throws Exception {
ComponentInstanceBusinessLogic testSubject;
@@ -823,19 +868,26 @@ public class ComponentInstanceBusinessLogicTest {
String resourceInstanceId = "";
List<ComponentInstanceInput> inputs = new ArrayList<>();
String userId = user.getUserId();
- Either<List<ComponentInstanceInput>,ResponseFormat> result;
+ Either<List<ComponentInstanceInput>, ResponseFormat> result;
- when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseAll)).thenReturn(Either.left(resource));
+ when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseAll))
+ .thenReturn(Either.left(resource));
// test 1
- testSubject=createTestSubject();
- result=testSubject.createOrUpdateInstanceInputValues(componentTypeEnum, componentId, resourceInstanceId, inputs, userId);
- componentTypeEnum =null;
- result=testSubject.createOrUpdateInstanceInputValues(componentTypeEnum, componentId, resourceInstanceId, inputs, userId);
+ testSubject = createTestSubject();
+ result = testSubject
+ .createOrUpdateInstanceInputValues(componentTypeEnum, componentId, resourceInstanceId, inputs,
+ userId);
+ componentTypeEnum = null;
+ result = testSubject
+ .createOrUpdateInstanceInputValues(componentTypeEnum, componentId, resourceInstanceId, inputs,
+ userId);
-// when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseAll)).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
- result=testSubject.createOrUpdateInstanceInputValues(componentTypeEnum, componentId, resourceInstanceId, inputs, userId);
+ // when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseAll)).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
+ result = testSubject
+ .createOrUpdateInstanceInputValues(componentTypeEnum, componentId, resourceInstanceId, inputs,
+ userId);
}
@@ -850,19 +902,26 @@ public class ComponentInstanceBusinessLogicTest {
String groupInstanceId = "";
ComponentInstanceProperty property = new ComponentInstanceProperty();
String userId = user.getUserId();
- Either<ComponentInstanceProperty,ResponseFormat> result;
+ Either<ComponentInstanceProperty, ResponseFormat> result;
- when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseMetadata)).thenReturn(Either.left(resource));
+ when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseMetadata))
+ .thenReturn(Either.left(resource));
// test 1
- testSubject=createTestSubject();
- result=testSubject.createOrUpdateGroupInstancePropertyValue(componentTypeEnum, componentId, resourceInstanceId, groupInstanceId, property, userId);
+ testSubject = createTestSubject();
+ result = testSubject
+ .createOrUpdateGroupInstancePropertyValue(componentTypeEnum, componentId, resourceInstanceId,
+ groupInstanceId, property, userId);
componentTypeEnum = null;
- result=testSubject.createOrUpdateGroupInstancePropertyValue(componentTypeEnum, componentId, resourceInstanceId, groupInstanceId, property, userId);
+ result = testSubject
+ .createOrUpdateGroupInstancePropertyValue(componentTypeEnum, componentId, resourceInstanceId,
+ groupInstanceId, property, userId);
-// when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseMetadata)).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
- result=testSubject.createOrUpdateGroupInstancePropertyValue(componentTypeEnum, componentId, resourceInstanceId, groupInstanceId, property, userId);
+ // when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseMetadata)).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
+ result = testSubject
+ .createOrUpdateGroupInstancePropertyValue(componentTypeEnum, componentId, resourceInstanceId,
+ groupInstanceId, property, userId);
}
@@ -875,21 +934,25 @@ public class ComponentInstanceBusinessLogicTest {
String resourceInstanceId = resource.getUniqueId();
ComponentInstanceInput inputProperty = new ComponentInstanceInput();
String userId = user.getUserId();
- Either<ComponentInstanceInput,ResponseFormat> result;
+ Either<ComponentInstanceInput, ResponseFormat> result;
Either<Component, StorageOperationStatus> getResourceResult = Either.left(resource);
- when(toscaOperationFacade.getToscaElement(resource.getUniqueId(), JsonParseFlagEnum.ParseMetadata)).thenReturn(getResourceResult);
+ when(toscaOperationFacade.getToscaElement(resource.getUniqueId(), JsonParseFlagEnum.ParseMetadata))
+ .thenReturn(getResourceResult);
// test 1
- testSubject=createTestSubject();
- result=testSubject.createOrUpdateInputValue(componentTypeEnum, componentId, resourceInstanceId, inputProperty, userId);
+ testSubject = createTestSubject();
+ result = testSubject.createOrUpdateInputValue(componentTypeEnum, componentId, resourceInstanceId, inputProperty,
+ userId);
componentTypeEnum = null;
- result=testSubject.createOrUpdateInputValue(componentTypeEnum, componentId, resourceInstanceId, inputProperty, userId);
+ result = testSubject.createOrUpdateInputValue(componentTypeEnum, componentId, resourceInstanceId, inputProperty,
+ userId);
-// when(toscaOperationFacade.getToscaElement(resource.getUniqueId(), JsonParseFlagEnum.ParseMetadata)).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
- result=testSubject.createOrUpdateInputValue(componentTypeEnum, componentId, resourceInstanceId, inputProperty, userId);
+ // when(toscaOperationFacade.getToscaElement(resource.getUniqueId(), JsonParseFlagEnum.ParseMetadata)).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
+ result = testSubject.createOrUpdateInputValue(componentTypeEnum, componentId, resourceInstanceId, inputProperty,
+ userId);
}
@@ -902,18 +965,22 @@ public class ComponentInstanceBusinessLogicTest {
String resourceInstanceId = "";
String propertyValueId = "";
String userId = user.getUserId();
- Either<ComponentInstanceProperty,ResponseFormat> result;
+ Either<ComponentInstanceProperty, ResponseFormat> result;
- when(toscaOperationFacade.getToscaElement(serviceId, JsonParseFlagEnum.ParseMetadata)).thenReturn(Either.left(service));
+ when(toscaOperationFacade.getToscaElement(serviceId, JsonParseFlagEnum.ParseMetadata))
+ .thenReturn(Either.left(service));
// test 1
- testSubject=createTestSubject();
- result=testSubject.deletePropertyValue(componentTypeEnum, serviceId, resourceInstanceId, propertyValueId, userId);
- componentTypeEnum= null;
- result=testSubject.deletePropertyValue(componentTypeEnum, serviceId, resourceInstanceId, propertyValueId, userId);
+ testSubject = createTestSubject();
+ result = testSubject.deletePropertyValue(componentTypeEnum, serviceId, resourceInstanceId, propertyValueId,
+ userId);
+ componentTypeEnum = null;
+ result = testSubject.deletePropertyValue(componentTypeEnum, serviceId, resourceInstanceId, propertyValueId,
+ userId);
-// when(toscaOperationFacade.getToscaElement(serviceId, JsonParseFlagEnum.ParseMetadata)).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
- result=testSubject.deletePropertyValue(componentTypeEnum, serviceId, resourceInstanceId, propertyValueId, userId);
+ // when(toscaOperationFacade.getToscaElement(serviceId, JsonParseFlagEnum.ParseMetadata)).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
+ result = testSubject.deletePropertyValue(componentTypeEnum, serviceId, resourceInstanceId, propertyValueId,
+ userId);
}
@@ -923,27 +990,25 @@ public class ComponentInstanceBusinessLogicTest {
ComponentTypeEnum containerComponentType = ComponentTypeEnum.RESOURCE;
createResource();
createInstances();
- Either<Component,ResponseFormat> result;
+ Either<Component, ResponseFormat> result;
when(toscaOperationFacade.getToscaFullElement(toInstance.getComponentUid())).thenReturn(Either.left(resource));
// default test
- testSubject=createTestSubject();
- result=Deencapsulation.invoke(testSubject, "getAndValidateOriginComponentOfComponentInstance", new Object[]{containerComponentType, toInstance});
+ testSubject = createTestSubject();
+ result = Deencapsulation.invoke(testSubject, "getAndValidateOriginComponentOfComponentInstance",
+ new Object[] {containerComponentType, toInstance});
}
-
-
-
@Test
public void testGetComponentParametersViewForForwardingPath() throws Exception {
ComponentInstanceBusinessLogic testSubject;
ComponentParametersView result;
// default test
- testSubject=createTestSubject();
- result=Deencapsulation.invoke(testSubject, "getComponentParametersViewForForwardingPath");
+ testSubject = createTestSubject();
+ result = Deencapsulation.invoke(testSubject, "getComponentParametersViewForForwardingPath");
}
@@ -955,15 +1020,17 @@ public class ComponentInstanceBusinessLogicTest {
String componentInstanceId = "";
String userId = user.getUserId();
createInstances();
- ComponentInstance newComponentInstance =toInstance;
- Either<ComponentInstance,ResponseFormat> result;
+ ComponentInstance newComponentInstance = toInstance;
+ Either<ComponentInstance, ResponseFormat> result;
// default test
- testSubject=createTestSubject();
- result=testSubject.changeComponentInstanceVersion(containerComponentParam, containerComponentId, componentInstanceId, userId, newComponentInstance);
+ testSubject = createTestSubject();
+ result = testSubject.changeComponentInstanceVersion(containerComponentParam, containerComponentId,
+ componentInstanceId, userId, newComponentInstance);
newComponentInstance = null;
- testSubject=createTestSubject();
- result=testSubject.changeComponentInstanceVersion(containerComponentParam, containerComponentId, componentInstanceId, userId, newComponentInstance);
+ testSubject = createTestSubject();
+ result = testSubject.changeComponentInstanceVersion(containerComponentParam, containerComponentId,
+ componentInstanceId, userId, newComponentInstance);
}
@@ -977,8 +1044,9 @@ public class ComponentInstanceBusinessLogicTest {
Boolean result;
// default test
- testSubject=createTestSubject();
- result=Deencapsulation.invoke(testSubject, "validateInstanceNameUniquenessUponUpdate", new Object[]{resource, toInstance, newInstanceName});
+ testSubject = createTestSubject();
+ result = Deencapsulation.invoke(testSubject, "validateInstanceNameUniquenessUponUpdate",
+ new Object[] {resource, toInstance, newInstanceName});
}
@@ -987,11 +1055,11 @@ public class ComponentInstanceBusinessLogicTest {
ComponentInstanceBusinessLogic testSubject;
createResource();
String instanceId = "";
- Either<ComponentInstance,StorageOperationStatus> result;
+ Either<ComponentInstance, StorageOperationStatus> result;
// default test
- testSubject=createTestSubject();
- result=Deencapsulation.invoke(testSubject, "getResourceInstanceById", new Object[]{resource, instanceId});
+ testSubject = createTestSubject();
+ result = Deencapsulation.invoke(testSubject, "getResourceInstanceById", new Object[] {resource, instanceId});
}
@Ignore("test failing skipping for now")
@@ -1003,42 +1071,43 @@ public class ComponentInstanceBusinessLogicTest {
ComponentInstance result;
// default test
- testSubject=createTestSubject();
- result=Deencapsulation.invoke(testSubject, "buildComponentInstance", new Object[]{toInstance, toInstance});
+ testSubject = createTestSubject();
+ result = Deencapsulation.invoke(testSubject, "buildComponentInstance", new Object[] {toInstance, toInstance});
}
-
-
-
@Test
public void testFindCapabilityOfInstance() throws Exception {
- ComponentInstanceBusinessLogic testSubject;String componentId = "";
+ ComponentInstanceBusinessLogic testSubject;
+ String componentId = "";
String instanceId = "";
String capabilityType = "";
String capabilityName = "";
String ownerId = "";
- Map<String,List<CapabilityDefinition>> instanceCapabilities = new HashMap<>();
- Either<List<ComponentInstanceProperty>,ResponseFormat> result;
+ Map<String, List<CapabilityDefinition>> instanceCapabilities = new HashMap<>();
+ Either<List<ComponentInstanceProperty>, ResponseFormat> result;
// default test
- testSubject=createTestSubject();
- result=Deencapsulation.invoke(testSubject, "findCapabilityOfInstance", new Object[]{componentId, instanceId, capabilityType, capabilityName, ownerId, instanceCapabilities});
+ testSubject = createTestSubject();
+ result = Deencapsulation.invoke(testSubject, "findCapabilityOfInstance",
+ new Object[] {componentId, instanceId, capabilityType, capabilityName, ownerId, instanceCapabilities});
}
@Test
public void testFetchComponentInstanceCapabilityProperties() throws Exception {
- ComponentInstanceBusinessLogic testSubject;String componentId = "";
+ ComponentInstanceBusinessLogic testSubject;
+ String componentId = "";
String instanceId = "";
String capabilityType = "";
String capabilityName = "";
String ownerId = "";
- Either<List<ComponentInstanceProperty>,ResponseFormat> result;
+ Either<List<ComponentInstanceProperty>, ResponseFormat> result;
// default test
- testSubject=createTestSubject();
- result=Deencapsulation.invoke(testSubject, "fetchComponentInstanceCapabilityProperties", new Object[]{componentId, instanceId, capabilityType, capabilityName, ownerId});
+ testSubject = createTestSubject();
+ result = Deencapsulation.invoke(testSubject, "fetchComponentInstanceCapabilityProperties",
+ new Object[] {componentId, instanceId, capabilityType, capabilityName, ownerId});
}
@@ -1055,8 +1124,9 @@ public class ComponentInstanceBusinessLogicTest {
ResponseFormat result;
// default test
- testSubject=createTestSubject();
- result=Deencapsulation.invoke(testSubject, "updateCapabilityPropertyOnContainerComponent", new Object[]{property, newValue, resource, toInstance, capabilityType, capabilityName, ownerId});
+ testSubject = createTestSubject();
+ result = Deencapsulation.invoke(testSubject, "updateCapabilityPropertyOnContainerComponent",
+ new Object[] {property, newValue, resource, toInstance, capabilityType, capabilityName, ownerId});
}
@@ -1072,20 +1142,23 @@ public class ComponentInstanceBusinessLogicTest {
String ownerId = "";
List<ComponentInstanceProperty> properties = new ArrayList<>();
String userId = user.getUserId();
- Either<List<ComponentInstanceProperty>,ResponseFormat> result;
+ Either<List<ComponentInstanceProperty>, ResponseFormat> result;
when(toscaOperationFacade.getToscaFullElement(containerComponentId)).thenReturn(Either.left(resource));
-
// test 1
- testSubject=createTestSubject();
- result=testSubject.updateInstanceCapabilityProperties(componentTypeEnum, containerComponentId, componentInstanceUniqueId, capabilityType, capabilityName, ownerId, properties, userId);
- when(toscaOperationFacade.getToscaFullElement(containerComponentId)).thenReturn(Either.right(StorageOperationStatus.ARTIFACT_NOT_FOUND));
- result=testSubject.updateInstanceCapabilityProperties(componentTypeEnum, containerComponentId, componentInstanceUniqueId, capabilityType, capabilityName, ownerId, properties, userId);
+ testSubject = createTestSubject();
+ result = testSubject.updateInstanceCapabilityProperties(componentTypeEnum, containerComponentId,
+ componentInstanceUniqueId, capabilityType, capabilityName, ownerId, properties, userId);
+ when(toscaOperationFacade.getToscaFullElement(containerComponentId))
+ .thenReturn(Either.right(StorageOperationStatus.ARTIFACT_NOT_FOUND));
+ result = testSubject.updateInstanceCapabilityProperties(componentTypeEnum, containerComponentId,
+ componentInstanceUniqueId, capabilityType, capabilityName, ownerId, properties, userId);
componentTypeEnum = null;
- result=testSubject.updateInstanceCapabilityProperties(componentTypeEnum, containerComponentId, componentInstanceUniqueId, capabilityType, capabilityName, ownerId, properties, userId);
+ result = testSubject.updateInstanceCapabilityProperties(componentTypeEnum, containerComponentId,
+ componentInstanceUniqueId, capabilityType, capabilityName, ownerId, properties, userId);
}
@@ -1102,15 +1175,18 @@ public class ComponentInstanceBusinessLogicTest {
String capabilityName = "";
List<ComponentInstanceProperty> properties = new ArrayList<>();
String userId = user.getUserId();
- Either<List<ComponentInstanceProperty>,ResponseFormat> result;
+ Either<List<ComponentInstanceProperty>, ResponseFormat> result;
- when(toscaOperationFacade.getToscaFullElement(containerComponentId)).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
+ when(toscaOperationFacade.getToscaFullElement(containerComponentId))
+ .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
// test 1
- testSubject=createTestSubject();
- result=testSubject.updateInstanceCapabilityProperties(componentTypeEnum, containerComponentId, componentInstanceUniqueId, capabilityType, capabilityName, properties, userId);
+ testSubject = createTestSubject();
+ result = testSubject.updateInstanceCapabilityProperties(componentTypeEnum, containerComponentId,
+ componentInstanceUniqueId, capabilityType, capabilityName, properties, userId);
when(toscaOperationFacade.getToscaFullElement(containerComponentId)).thenReturn(Either.left(resource));
- result=testSubject.updateInstanceCapabilityProperties(componentTypeEnum, containerComponentId, componentInstanceUniqueId, capabilityType, capabilityName, properties, userId);
+ result = testSubject.updateInstanceCapabilityProperties(componentTypeEnum, containerComponentId,
+ componentInstanceUniqueId, capabilityType, capabilityName, properties, userId);
}
@Test
@@ -1134,7 +1210,8 @@ public class ComponentInstanceBusinessLogicTest {
.thenReturn(StorageOperationStatus.OK);
result = componentInstanceBusinessLogic
- .copyComponentInstance(inputComponentInstance, containerComponentId, componentInstanceId, USER_ID);
+ .copyComponentInstance(inputComponentInstance, containerComponentId, componentInstanceId,
+ USER_ID);
service.setLastUpdaterUserId(oldLastUpdatedUserId);
@@ -1164,7 +1241,8 @@ public class ComponentInstanceBusinessLogicTest {
.thenReturn(getComponentRes);
result = componentInstanceBusinessLogic
- .copyComponentInstance(inputComponentInstance, containerComponentId, componentInstanceId, USER_ID);
+ .copyComponentInstance(inputComponentInstance, containerComponentId, componentInstanceId,
+ USER_ID);
service.setLastUpdaterUserId(oldServiceLastUpdatedUserId);
@@ -1196,19 +1274,20 @@ public class ComponentInstanceBusinessLogicTest {
ImmutablePair<Component, String> pair = new ImmutablePair<>(resource, TO_INSTANCE_ID);
Either<ImmutablePair<Component, String>, StorageOperationStatus> result2 = Either.left(pair);
when(toscaOperationFacade
- .addComponentInstanceToTopologyTemplate(eq(service), eq(resource), eq(inputComponentInstance), eq(false),
- isNull(User.class))).thenReturn(result2);
- Either<Map<String, ArtifactDefinition>, StorageOperationStatus> getResourceDeploymentArtifacts = Either
- .left(new HashMap<String, ArtifactDefinition>());
+ .addComponentInstanceToTopologyTemplate(eq(service), eq(resource), eq(inputComponentInstance),
+ eq(false), isNull(User.class))).thenReturn(result2);
+ Either<Map<String, ArtifactDefinition>, StorageOperationStatus> getResourceDeploymentArtifacts =
+ Either.left(new HashMap<String, ArtifactDefinition>());
when(artifactBusinessLogic.getArtifacts(eq(inputComponentInstance.getComponentUid()), eq(NodeTypeEnum.Resource),
eq(ArtifactGroupTypeEnum.DEPLOYMENT), isNull(String.class))).thenReturn(getResourceDeploymentArtifacts);
StorageOperationStatus artStatus = StorageOperationStatus.OK;
when(toscaOperationFacade
- .addInformationalArtifactsToInstance(eq(resource.getUniqueId()), eq(inputComponentInstance),
- isNull(Map.class))).thenReturn(artStatus);
+ .addInformationalArtifactsToInstance(eq(resource.getUniqueId()), eq(inputComponentInstance),
+ isNull(Map.class))).thenReturn(artStatus);
result = componentInstanceBusinessLogic
- .copyComponentInstance(inputComponentInstance, containerComponentId, componentInstanceId, USER_ID);
+ .copyComponentInstance(inputComponentInstance, containerComponentId, componentInstanceId,
+ USER_ID);
service.setLastUpdaterUserId(oldServiceLastUpdatedUserId);
resource.setLifecycleState(oldResourceLifeCycle);
@@ -1229,7 +1308,8 @@ public class ComponentInstanceBusinessLogicTest {
service.setLastUpdaterUserId(USER_ID);
service.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
- Map<String, List<ComponentInstanceProperty>> instAttrsMap = new HashMap<String, List<ComponentInstanceProperty>>();
+ Map<String, List<ComponentInstanceProperty>> instAttrsMap =
+ new HashMap<String, List<ComponentInstanceProperty>>();
List<ComponentInstanceProperty> instAttrsList = new ArrayList<ComponentInstanceProperty>();
ComponentInstanceProperty prop = new ComponentInstanceProperty();
prop.setUniqueId(attribute.getUniqueId());
@@ -1238,15 +1318,21 @@ public class ComponentInstanceBusinessLogicTest {
service.setComponentInstancesAttributes(instAttrsMap);
Either<Component, StorageOperationStatus> serviceEitherLeft = Either.left(service);
- when(toscaOperationFacade.getToscaElement(serviceComponentInstance.getUniqueId(), JsonParseFlagEnum.ParseAll)).thenReturn(serviceEitherLeft);
- when(toscaOperationFacade.updateComponentInstanceAttribute(service, toInstance.getUniqueId(), attribute)).thenReturn(StorageOperationStatus.OK);
- when(toscaOperationFacade.updateComponentInstanceMetadataOfTopologyTemplate(service)).thenReturn(serviceEitherLeft);
+ when(toscaOperationFacade.getToscaElement(serviceComponentInstance.getUniqueId(), JsonParseFlagEnum.ParseAll))
+ .thenReturn(serviceEitherLeft);
+ when(toscaOperationFacade.updateComponentInstanceAttribute(service, toInstance.getUniqueId(), attribute))
+ .thenReturn(StorageOperationStatus.OK);
+ when(toscaOperationFacade.updateComponentInstanceMetadataOfTopologyTemplate(service))
+ .thenReturn(serviceEitherLeft);
- Either<ComponentInstanceProperty, ResponseFormat> result = Deencapsulation.invoke(componentInstanceBusinessLogic, "createOrUpdateAttributeValueForCopyPaste", ComponentTypeEnum.SERVICE,
- serviceComponentInstance.getUniqueId(),
- toInstance.getUniqueId(),
- attribute,
- USER_ID);
+ Either<ComponentInstanceProperty, ResponseFormat> result = Deencapsulation
+ .invoke(componentInstanceBusinessLogic,
+ "createOrUpdateAttributeValueForCopyPaste",
+ ComponentTypeEnum.SERVICE,
+ serviceComponentInstance
+ .getUniqueId(),
+ toInstance.getUniqueId(), attribute,
+ USER_ID);
service.setLastUpdaterUserId(oldLastUpdatedUserId);
service.setLifecycleState(oldLifeCycleState);
@@ -1273,9 +1359,8 @@ public class ComponentInstanceBusinessLogicTest {
when(toscaOperationFacade.updateComponentInstanceMetadataOfTopologyTemplate(service))
.thenReturn(updateContainerRes);
- Either<String, ResponseFormat> result = Deencapsulation
- .invoke(componentInstanceBusinessLogic, "updateComponentInstanceProperty", containerComponentId,
- componentInstanceId, property);
+ Either<String, ResponseFormat> result = Deencapsulation.invoke(componentInstanceBusinessLogic,
+ "updateComponentInstanceProperty", containerComponentId, componentInstanceId, property);
assertTrue(result.isLeft());
}
@@ -1293,8 +1378,8 @@ public class ComponentInstanceBusinessLogicTest {
List<InputDefinition> oldInputs = service.getInputs();
service.setInputs(newInputs);
- Either<String, ResponseFormat> result = Deencapsulation
- .invoke(componentInstanceBusinessLogic, "getInputListDefaultValue", component, inputId);
+ Either<String, ResponseFormat> result =
+ Deencapsulation.invoke(componentInstanceBusinessLogic, "getInputListDefaultValue", component, inputId);
service.setInputs(oldInputs);
@@ -1316,8 +1401,8 @@ public class ComponentInstanceBusinessLogicTest {
deleteErrorMap.put("deleteFailedIds", deleteErrorIds);
result = componentInstanceBusinessLogic
- .batchDeleteComponentInstance(containerComponentParam, containerComponentId, componentInstanceIdList,
- userId);
+ .batchDeleteComponentInstance(containerComponentParam, containerComponentId,
+ componentInstanceIdList, userId);
assertEquals(deleteErrorMap, result);
}
@@ -1341,8 +1426,8 @@ public class ComponentInstanceBusinessLogicTest {
.thenReturn(err);
result = componentInstanceBusinessLogic
- .batchDeleteComponentInstance(containerComponentParam, containerComponentId, componentInstanceIdList,
- userId);
+ .batchDeleteComponentInstance(containerComponentParam, containerComponentId,
+ componentInstanceIdList, userId);
assertEquals(deleteErrorMap, result);
}
@@ -1378,11 +1463,12 @@ public class ComponentInstanceBusinessLogicTest {
when(titanDao.commit()).thenReturn(TitanOperationStatus.OK);
result = componentInstanceBusinessLogic
- .batchDeleteComponentInstance(containerComponentParam, containerComponentId, componentInstanceIdList, userId);
+ .batchDeleteComponentInstance(containerComponentParam, containerComponentId,
+ componentInstanceIdList, userId);
service.setLastUpdaterUserId(oldLastUpdatedUserId);
service.setLifecycleState(oldLifeCycleState);
- assertEquals(deleteErrorMap,result);
+ assertEquals(deleteErrorMap, result);
}
@Test
@@ -1421,7 +1507,7 @@ public class ComponentInstanceBusinessLogicTest {
when(toscaOperationFacade.dissociateResourceInstances(componentId, ref)).thenReturn(resultEither);
result = componentInstanceBusinessLogic
- .batchDissociateRIFromRI(componentId, userId, requirementDefList, componentTypeEnum);
+ .batchDissociateRIFromRI(componentId, userId, requirementDefList, componentTypeEnum);
service.setLastUpdaterUserId(oldLastUpdatedUserId);
service.setLifecycleState(oldLifeCycleState);
@@ -1456,7 +1542,7 @@ public class ComponentInstanceBusinessLogicTest {
when(toscaOperationFacade.dissociateResourceInstances(componentId, ref)).thenReturn(resultEither);
result = componentInstanceBusinessLogic
- .batchDissociateRIFromRI(componentId, userId, requirementDefList, componentTypeEnum);
+ .batchDissociateRIFromRI(componentId, userId, requirementDefList, componentTypeEnum);
service.setLastUpdaterUserId(oldLastUpdatedUserId);
service.setLifecycleState(oldLifeCycleState);
@@ -1464,6 +1550,51 @@ public class ComponentInstanceBusinessLogicTest {
assertEquals(requirementDefList, result);
}
+ @Test
+ public void testGetComponentInstancePropertyByPolicyId_success() {
+ Optional<ComponentInstanceProperty> propertyCandidate =
+ getComponentInstanceProperty(PROP_NAME);
+
+ Assert.assertTrue(propertyCandidate.isPresent());
+ Assert.assertEquals(propertyCandidate.get().getName(), PROP_NAME);
+ }
+
+ @Test
+ public void testGetComponentInstancePropertyByPolicyId_failure() {
+ Optional<ComponentInstanceProperty> propertyCandidate =
+ getComponentInstanceProperty(NON_EXIST_NAME);
+
+ Assert.assertEquals(propertyCandidate, Optional.empty());
+ }
+
+ private Optional<ComponentInstanceProperty> getComponentInstanceProperty(String propertyName) {
+ ComponentInstanceProperty componentInstanceProperty = new ComponentInstanceProperty();
+ componentInstanceProperty.setName(propertyName);
+
+ PolicyDefinition policyDefinition = getPolicyDefinition();
+ componentInstanceProperty.setGetPolicyValues(policyDefinition.getGetPolicyValues());
+
+ service.setComponentInstancesProperties(
+ Collections.singletonMap(COMPONENT_INST_ID, Collections.singletonList(componentInstanceProperty)));
+
+ return componentInstanceBusinessLogic.getComponentInstancePropertyByPolicyId(service, policyDefinition);
+ }
+
+ private PolicyDefinition getPolicyDefinition() {
+ PolicyDefinition policyDefinition = new PolicyDefinition();
+ policyDefinition.setInstanceUniqueId(COMPONENT_INST_ID);
+ policyDefinition.setName(PROP_NAME);
+
+ GetPolicyValueDataDefinition getPolicy = new GetPolicyValueDataDefinition();
+ getPolicy.setPropertyName(PROP_NAME);
+
+ List<GetPolicyValueDataDefinition> getPolicies = new ArrayList<>();
+ getPolicies.add(getPolicy);
+ policyDefinition.setGetPolicyValues(getPolicies);
+
+ return policyDefinition;
+ }
+
private ComponentInstance createComponetInstanceFromComponent(Component component) {
ComponentInstance componentInst = new ComponentInstance();
componentInst.setUniqueId(component.getUniqueId());
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogicTest.java
index 0817cbc6e4..c8d95bc2cb 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogicTest.java
@@ -1,8 +1,24 @@
package org.openecomp.sdc.be.components.impl;
+import static org.assertj.core.api.Java6Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyMap;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.when;
+
import fj.data.Either;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -10,6 +26,7 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.components.property.PropertyDeclarationOrchestrator;
import org.openecomp.sdc.be.components.utils.ComponentInstanceBuilder;
import org.openecomp.sdc.be.components.utils.GroupDefinitionBuilder;
import org.openecomp.sdc.be.components.utils.ResourceBuilder;
@@ -24,7 +41,15 @@ import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.model.*;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentParametersView;
+import org.openecomp.sdc.be.model.GroupDefinition;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.PolicyDefinition;
+import org.openecomp.sdc.be.model.PolicyTypeDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElementTypeEnum;
import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
@@ -36,14 +61,6 @@ import org.openecomp.sdc.common.impl.ExternalConfiguration;
import org.openecomp.sdc.common.impl.FSConfigurationSource;
import org.openecomp.sdc.exception.ResponseFormat;
-import java.util.*;
-
-import static org.assertj.core.api.Java6Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.*;
-import static org.mockito.Mockito.when;
-
@RunWith(MockitoJUnitRunner.class)
public class PolicyBusinessLogicTest {
@@ -65,6 +82,8 @@ public class PolicyBusinessLogicTest {
private ApplicationDataTypeCache dataTypeCache;
@Mock
private PropertyOperation propertyOperation;
+ @Mock
+ PropertyDeclarationOrchestrator propertyDeclarationOrchestrator;
private final static String COMPONENT_ID = "componentId";
private final static String COMPONENT_NAME = "componentName";
@@ -98,6 +117,20 @@ public class PolicyBusinessLogicTest {
new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir));
}
+ @Before
+ public void initBl() {
+ businessLogic.setComponentsUtils(componentsUtils);
+ businessLogic.setToscaOperationFacade(toscaOperationFacade);
+ businessLogic.setTitanGenericDao(titanDao);
+ businessLogic.setUserValidations(userValidations);
+ businessLogic.setGraphLockOperation(graphLockOperation);
+ businessLogic.setPolicyTypeOperation(policyTypeOperation);
+ businessLogic.setDataTypeCache(dataTypeCache);
+ businessLogic.setPropertyOperation(propertyOperation);
+ businessLogic.setPropertyDeclarationOrchestrator(propertyDeclarationOrchestrator);
+ }
+
+
private static void createResponses() {
componentSuccessEither = Either.left(resource);
getPolicyTypeSuccessEither = Either.left(policyType);
@@ -213,6 +246,7 @@ public class PolicyBusinessLogicTest {
stubValidateAndLockSuccess(CREATE_POLICY);
stubCommit();
when(toscaOperationFacade.removePolicyFromComponent(eq(COMPONENT_ID),eq(POLICY_ID))).thenReturn(StorageOperationStatus.OK);
+ when(propertyDeclarationOrchestrator.unDeclarePropertiesAsPolicies(any(), any())).thenReturn(StorageOperationStatus.OK);
Either<PolicyDefinition, ResponseFormat> response = businessLogic.deletePolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, USER_ID, true);
assertTrue(response.isLeft());
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyPropertiesBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyPropertiesBusinessLogicTest.java
index 9be3fa00ee..928a576f98 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyPropertiesBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyPropertiesBusinessLogicTest.java
@@ -1,6 +1,14 @@
package org.openecomp.sdc.be.components.impl;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
import fj.data.Either;
+import java.util.List;
+import javax.ws.rs.core.Response;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -19,20 +27,16 @@ import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.model.*;
+import org.openecomp.sdc.be.model.ComponentParametersView;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.PolicyDefinition;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.exception.ResponseFormat;
-import javax.ws.rs.core.Response;
-import java.util.List;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
@RunWith(MockitoJUnitRunner.class)
public class PolicyPropertiesBusinessLogicTest {
@@ -63,6 +67,11 @@ public class PolicyPropertiesBusinessLogicTest {
@Before
public void setUp() throws Exception {
+ testInstance.setUserValidations(userValidations);
+ testInstance.setTitanGenericDao(titanDao);
+ testInstance.setToscaOperationFacade(toscaOperationFacade);
+ testInstance.setComponentsUtils(componentsUtils);
+
componentFilter = new ComponentParametersView(true);
componentFilter.setIgnorePolicies(false);
componentFilter.setIgnoreUsers(false);
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentPropertyToPolicyDeclaratorTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentPropertyToPolicyDeclaratorTest.java
new file mode 100644
index 0000000000..11292dc0e1
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentPropertyToPolicyDeclaratorTest.java
@@ -0,0 +1,137 @@
+package org.openecomp.sdc.be.components.property;
+
+
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.when;
+
+import fj.data.Either;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.openecomp.sdc.be.components.property.propertytopolicydeclarators.ComponentPropertyToPolicyDeclarator;
+import org.openecomp.sdc.be.datatypes.elements.GetPolicyValueDataDefinition;
+import org.openecomp.sdc.be.model.PolicyDefinition;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ComponentPropertyToPolicyDeclaratorTest extends PropertyDeclaratorTestBase {
+
+ @InjectMocks
+ ComponentPropertyToPolicyDeclarator declarator;
+ @Mock
+ private ToscaOperationFacade toscaOperationFacade;
+ @Captor
+ ArgumentCaptor<PropertyDefinition> propertyCaptor;
+
+ private static final String OWNER_ID = "ownerId";
+ private static final String SERVICE_ID = "serviceId";
+ private static final String PROPERTY_ID = "propertyId";
+ private static final String POLICY = "policy";
+ private static final String TEST_VALUE = "testValue";
+
+
+ @Test
+ public void testDeclarePropertyToPolicy_success() {
+ Service service = new Service();
+ service.setUniqueId(SERVICE_ID);
+
+ when(toscaOperationFacade.updatePropertyOfComponent(eq(service), Mockito.any())).thenReturn(Either.left(new PropertyDefinition()));
+ Either<List<PolicyDefinition>, StorageOperationStatus> declareEither = declarator.declarePropertiesAsPolicies(
+ service, OWNER_ID, createInstancePropInputList(Collections.singletonList(prop1)));
+
+ Assert.assertTrue(declareEither.isLeft());
+ }
+
+ @Test
+ public void testUndeclarePolicy_success() {
+ Service service = new Service();
+ service.setUniqueId(SERVICE_ID);
+
+ PolicyDefinition policyDefinition = createPolicyDefinition(PROPERTY_ID);
+
+ PropertyDefinition expectedProperty = createPropertyWithDeclaredPolicy(getPolicyId(PROPERTY_ID));
+ service.addProperty(expectedProperty);
+
+ when(toscaOperationFacade.updatePropertyOfComponent(eq(service), propertyCaptor.capture())).thenReturn(Either.left(new PropertyDefinition()));
+
+ StorageOperationStatus storageOperationStatus =
+ declarator.unDeclarePropertiesAsPolicies(service, policyDefinition);
+
+ PropertyDefinition actualProperty = propertyCaptor.getValue();
+
+ Assert.assertEquals(storageOperationStatus, storageOperationStatus.OK);
+ Assert.assertEquals(expectedProperty, actualProperty);
+
+ }
+
+ @Test
+ public void shouldReturnOriginalPropertyValueAfterUndeclaring() {
+ Service service = new Service();
+ service.setUniqueId(SERVICE_ID);
+
+ PropertyDefinition expectedProperty = new PropertyDefinition(prop1);
+ addGetPolicyValueToProperty(getPolicyId(prop1.getUniqueId()), expectedProperty);
+ service.addProperty(expectedProperty);
+
+ when(toscaOperationFacade.updatePropertyOfComponent(eq(service), propertyCaptor.capture())).thenReturn(Either.left(new PropertyDefinition()));
+
+ Either<List<PolicyDefinition>, StorageOperationStatus> declareEither = declarator.declarePropertiesAsPolicies(
+ service, OWNER_ID, createInstancePropInputList(Collections.singletonList(prop1)));
+
+ Assert.assertTrue(declareEither.isLeft());
+
+ PolicyDefinition policyDefinition = createPolicyDefinition(prop1.getUniqueId());
+ StorageOperationStatus storageOperationStatus =
+ declarator.unDeclarePropertiesAsPolicies(service, policyDefinition);
+
+ List<PropertyDefinition> actualProperties = propertyCaptor.getAllValues();
+
+ Assert.assertEquals(storageOperationStatus, storageOperationStatus.OK);
+ Assert.assertEquals(actualProperties.size(), 2);
+ Assert.assertEquals(prop1.getValue(), actualProperties.get(1).getValue());
+ }
+
+ private PropertyDefinition createPropertyWithDeclaredPolicy(String policyId) {
+ PropertyDefinition propertyDefinition = new PropertyDefinition();
+ propertyDefinition.setUniqueId(PROPERTY_ID);
+
+ addGetPolicyValueToProperty(policyId, propertyDefinition);
+ return propertyDefinition;
+ }
+
+ private void addGetPolicyValueToProperty(String policyId, PropertyDefinition propertyDefinition) {
+ GetPolicyValueDataDefinition getPolicyValueDataDefinition = new GetPolicyValueDataDefinition();
+ getPolicyValueDataDefinition.setPolicyId(policyId);
+ getPolicyValueDataDefinition.setPropertyName(propertyDefinition.getUniqueId());
+ getPolicyValueDataDefinition.setOrigPropertyValue(propertyDefinition.getValue());
+
+ List<GetPolicyValueDataDefinition> getPolicyList = new ArrayList<>();
+ getPolicyList.add(getPolicyValueDataDefinition);
+ propertyDefinition.setGetPolicyValues(getPolicyList);
+ }
+
+ private PolicyDefinition createPolicyDefinition(String propertyId) {
+ PolicyDefinition policyDefinition = new PolicyDefinition();
+ String policyId = getPolicyId(propertyId);
+ policyDefinition.setUniqueId(policyId);
+
+ return policyDefinition;
+ }
+
+ private String getPolicyId(String propertyId) {
+ return SERVICE_ID + "." + propertyId + "." + POLICY;
+ }
+
+} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PropertyDecelerationOrchestratorTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PropertyDecelerationOrchestratorTest.java
index bb40d46274..1a2a76e433 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PropertyDecelerationOrchestratorTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PropertyDecelerationOrchestratorTest.java
@@ -86,7 +86,7 @@ public class PropertyDecelerationOrchestratorTest {
Map<String, List<ComponentInstancePropInput>> componentInstanceProperties = new HashMap<>();
List<ComponentInstancePropInput> value = new LinkedList<>();
componentInstanceProperties.put("mock", value);
- componentInstInputsMap.setComponentInstancePropInput(componentInstanceProperties);
+ componentInstInputsMap.setComponentInstanceProperties(componentInstanceProperties);
PropertyDeclarator result;
// default test
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/propertytopolicydeclarators/ComponentInstancePropertyToPolicyDeclaratorTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/propertytopolicydeclarators/ComponentInstancePropertyToPolicyDeclaratorTest.java
new file mode 100644
index 0000000000..c44b907344
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/propertytopolicydeclarators/ComponentInstancePropertyToPolicyDeclaratorTest.java
@@ -0,0 +1,149 @@
+package org.openecomp.sdc.be.components.property.propertytopolicydeclarators;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import fj.data.Either;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.mockito.Spy;
+import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.PropertyBusinessLogic;
+import org.openecomp.sdc.be.datatypes.elements.PolicyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.PolicyDefinition;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+
+public class ComponentInstancePropertyToPolicyDeclaratorTest {
+
+ @Mock
+ private ToscaOperationFacade toscaOperationFacade;
+ @Mock
+ private PropertyBusinessLogic propertyBl;
+ @Mock
+ private ComponentInstanceBusinessLogic componentInstanceBl;
+ @InjectMocks
+ private ComponentInstancePropertyToPolicyDeclarator declarator;
+ @Captor
+ private ArgumentCaptor<ComponentInstanceProperty> captor;
+
+ private static Service service;
+ private static ComponentInstance componentInstance;
+ private static PropertyDataDefinition prop1;
+ private static final String PROP_1_NAME = "prop1";
+ private static final String NON_EXIST_PROP_NAME = "prop1";
+ private static final String COMPONENT_INSTANCE_ID = "ciId";
+ private static final String NON_EXIST_ID = "nonExistId";
+
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ service = new Service();
+ componentInstance = new ComponentInstance();
+ componentInstance.setUniqueId(COMPONENT_INSTANCE_ID);
+ service.setComponentInstances(Collections.singletonList(componentInstance));
+
+ prop1 = new PolicyDataDefinition();
+ prop1.setName(PROP_1_NAME);
+ }
+
+ @Test
+ public void testCreateDeclaredProperty_success() {
+ ComponentInstanceProperty declaredProperty = declarator.createDeclaredProperty(prop1);
+ Assert.assertEquals(prop1.getName(), declaredProperty.getName());
+ }
+
+ @Test
+ public void testUpdatePropertiesValues_success() {
+ List<ComponentInstanceProperty> properties = Arrays.asList(new ComponentInstanceProperty(prop1));
+ Map<String, List<ComponentInstanceProperty>> expectedInstanceProperties =
+ Collections.singletonMap(COMPONENT_INSTANCE_ID, properties);
+
+ when(toscaOperationFacade
+ .addComponentInstancePropertiesToComponent(eq(service), eq(expectedInstanceProperties)))
+ .thenReturn(Either.left(expectedInstanceProperties));
+
+
+ Either<Map<String, List<ComponentInstanceProperty>>, StorageOperationStatus> updateEither =
+ (Either<Map<String, List<ComponentInstanceProperty>>, StorageOperationStatus>) declarator
+ .updatePropertiesValues(
+ service,
+ COMPONENT_INSTANCE_ID,
+ properties);
+
+ Assert.assertTrue(updateEither.isLeft());
+ Map<String, List<ComponentInstanceProperty>> actualInstanceProperties = updateEither.left().value();
+ validateUpdateResult(properties, expectedInstanceProperties, actualInstanceProperties);
+ }
+
+ @Test
+ public void testResolvePropertiesOwner_success() {
+ Optional<ComponentInstance> componentInstanceCandidate =
+ declarator.resolvePropertiesOwner(service, COMPONENT_INSTANCE_ID);
+
+ Assert.assertTrue(componentInstanceCandidate.isPresent());
+ Assert.assertEquals(componentInstanceCandidate.get(), componentInstance);
+ }
+
+ @Test
+ public void testResolvePropertiesOwner_failure() {
+ Optional<ComponentInstance> componentInstanceCandidate =
+ declarator.resolvePropertiesOwner(service, NON_EXIST_ID);
+
+ Assert.assertFalse(componentInstanceCandidate.isPresent());
+ }
+
+ @Test
+ public void testUnDeclarePropertiesAsPolicies_success() {
+ PolicyDefinition policyDefinition = new PolicyDefinition();
+ policyDefinition.setName(PROP_1_NAME);
+
+ when(componentInstanceBl.getComponentInstancePropertyByPolicyId(eq(service), eq(policyDefinition)))
+ .thenReturn(Optional.of(new ComponentInstanceProperty(prop1)));
+ when(toscaOperationFacade
+ .updateComponentInstanceProperty(any(), any(), captor.capture()))
+ .thenReturn(StorageOperationStatus.OK);
+
+ StorageOperationStatus status =
+ declarator.unDeclarePropertiesAsPolicies(service, policyDefinition);
+
+ Assert.assertEquals(status, StorageOperationStatus.OK);
+
+ ComponentInstanceProperty actualProperty = captor.getValue();
+ Assert.assertEquals(prop1.getName(), actualProperty.getName());
+ }
+
+ private void validateUpdateResult(List<ComponentInstanceProperty> properties,
+ Map<String, List<ComponentInstanceProperty>> expectedInstanceProperties,
+ Map<String, List<ComponentInstanceProperty>> actualInstanceProperties) {
+ Assert.assertEquals(expectedInstanceProperties.size(), actualInstanceProperties.size());
+ Assert.assertEquals(1, actualInstanceProperties.size());
+ Assert.assertEquals(expectedInstanceProperties.keySet(), actualInstanceProperties.keySet());
+
+ List<ComponentInstanceProperty> actualComponentInstanceProperties =
+ actualInstanceProperties.get(COMPONENT_INSTANCE_ID);
+
+ Assert.assertEquals(properties, actualComponentInstanceProperties);
+ }
+} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/JerseySpringBaseTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/JerseySpringBaseTest.java
index 0c02ab02cb..2742e4b5ff 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/JerseySpringBaseTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/JerseySpringBaseTest.java
@@ -1,6 +1,14 @@
package org.openecomp.sdc.be.servlets;
+import static org.mockito.Mockito.mock;
+
import com.fasterxml.jackson.databind.DeserializationFeature;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.core.Feature;
+import org.glassfish.grizzly.servlet.HttpSessionImpl;
+import org.glassfish.grizzly.servlet.WebappContext;
import org.glassfish.hk2.utilities.binding.AbstractBinder;
import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.jackson.internal.jackson.jaxrs.json.JacksonJaxbJsonProvider;
@@ -11,28 +19,32 @@ import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.glassfish.jersey.test.TestProperties;
import org.junit.BeforeClass;
+import org.openecomp.sdc.be.impl.WebAppContextWrapper;
import org.openecomp.sdc.be.servlets.exception.ComponentExceptionMapper;
import org.openecomp.sdc.be.servlets.exception.DefaultExceptionMapper;
import org.openecomp.sdc.be.servlets.exception.StorageExceptionMapper;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
+import org.springframework.web.context.WebApplicationContext;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.core.Feature;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import static org.mockito.Mockito.mock;
public abstract class JerseySpringBaseTest extends JerseyTest {
private static final Logger log = Logger.getLogger(JerseySpringBaseTest.class.getName());
protected static HttpServletRequest request;
+ protected static HttpSessionImpl session;
+ protected static WebappContext context;
+ protected static WebAppContextWrapper contextWrapper;
+ protected static WebApplicationContext applicationContext;
private final static JacksonJsonProvider jacksonJsonProvider = new JacksonJaxbJsonProvider().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
private final static Feature loggingFeature = new LoggingFeature(log, Level.INFO, LoggingFeature.Verbosity.PAYLOAD_ANY, null);
@BeforeClass
public static void initBaseClass() {
request = mock(HttpServletRequest.class);
+ session = mock(HttpSessionImpl.class);
+ context = mock(WebappContext.class);
+ contextWrapper = mock(WebAppContextWrapper.class);
+ applicationContext = mock(WebApplicationContext.class);
}
@Override
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/PolicyServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/PolicyServletTest.java
index 8677194d26..d542088763 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/PolicyServletTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/PolicyServletTest.java
@@ -1,45 +1,64 @@
package org.openecomp.sdc.be.servlets;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyMap;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.when;
+import static org.openecomp.sdc.common.api.Constants.GET_POLICY;
+
import com.fasterxml.jackson.databind.DeserializationFeature;
import fj.data.Either;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Objects;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.Invocation;
+import javax.ws.rs.core.GenericType;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
import org.glassfish.grizzly.http.util.HttpStatus;
import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.jackson.internal.jackson.jaxrs.json.JacksonJaxbJsonProvider;
import org.glassfish.jersey.jackson.internal.jackson.jaxrs.json.JacksonJsonProvider;
import org.glassfish.jersey.server.ResourceConfig;
+import org.json.simple.JSONObject;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
import org.mockito.Mockito;
+import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.openecomp.sdc.be.components.impl.BaseBusinessLogic;
import org.openecomp.sdc.be.components.impl.PolicyBusinessLogic;
+import org.openecomp.sdc.be.components.property.PropertyDeclarationOrchestrator;
import org.openecomp.sdc.be.components.utils.PropertyDataDefinitionBuilder;
import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.elements.GetPolicyValueDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.impl.ServletUtils;
+import org.openecomp.sdc.be.model.ComponentInstInputsMap;
+import org.openecomp.sdc.be.model.ComponentInstancePropInput;
import org.openecomp.sdc.be.model.PolicyDefinition;
import org.openecomp.sdc.be.model.PolicyTargetDTO;
import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
+import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.exception.ResponseFormat;
-import javax.ws.rs.client.ClientBuilder;
-import javax.ws.rs.client.Entity;
-import javax.ws.rs.client.Invocation;
-import javax.ws.rs.core.GenericType;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.*;
-import static org.mockito.Mockito.when;
-
+@RunWith(MockitoJUnitRunner.class)
public class PolicyServletTest extends JerseySpringBaseTest{
private final static String USER_ID = "jh0003";
@@ -47,7 +66,13 @@ public class PolicyServletTest extends JerseySpringBaseTest{
private static PolicyBusinessLogic businessLogic;
private static ComponentsUtils componentsUtils;
private static ServletUtils servletUtils;
+ private static PropertyDeclarationOrchestrator propertyDeclarationOrchestrator;
+ private static ToscaOperationFacade toscaOperationFacade;
private static ResponseFormat responseFormat;
+ @Captor
+ private static ArgumentCaptor<PolicyDefinition> policyCaptor;
+ @Spy
+ private static BaseBusinessLogic baseBusinessLogic;
private static String validComponentType = "resources";
private static String unsupportedComponentType = "unsupported";
@@ -55,8 +80,11 @@ public class PolicyServletTest extends JerseySpringBaseTest{
private static String policyTypeName = "policyTypeName";
private static final String PROPS_URL = "/v1/catalog/{componentType}/{serviceId}/policies/{policyId}/properties";
+ private static final String DECLARE_URL = "v1/catalog/{componentType}/{serviceId}/create/policies";
+ private static final String DELETE_URL = "v1/catalog/{containerComponentType}/{componentId}/policies/{policyId}";
private static final String SERVICE_ID = "serviceId";
private static final String POLICY_ID = "policyId";
+ private static final String PROP_1 = "prop1";
private static final String UPDATE_TARGETS_URL = "/v1/catalog/{componentType}/{componentId}/policies/{policyId}/targets";
@@ -78,7 +106,6 @@ public class PolicyServletTest extends JerseySpringBaseTest{
Either<PolicyDefinition, ResponseFormat> successResponse = Either.left(new PolicyDefinition());
when(businessLogic.getPolicy(eq(ComponentTypeEnum.RESOURCE), eq(componentId), eq(POLICY_ID), eq(USER_ID))).thenReturn(successResponse);
when(responseFormat.getStatus()).thenReturn(HttpStatus.OK_200.getStatusCode());
- when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
Response response = target()
.path(path)
.request(MediaType.APPLICATION_JSON)
@@ -142,7 +169,6 @@ public class PolicyServletTest extends JerseySpringBaseTest{
Either<PolicyDefinition, ResponseFormat> successResponse = Either.left(policy);
when(businessLogic.updatePolicy(eq(ComponentTypeEnum.RESOURCE), eq(componentId), any(PolicyDefinition.class), eq(USER_ID), eq(true))).thenReturn(successResponse);
when(responseFormat.getStatus()).thenReturn(HttpStatus.OK_200.getStatusCode());
- when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
Response response = target()
.path(path)
.request(MediaType.APPLICATION_JSON)
@@ -172,15 +198,14 @@ public class PolicyServletTest extends JerseySpringBaseTest{
String path = "/v1/catalog/" + validComponentType + "/" + componentId + "/policies/" + POLICY_ID;
Either<PolicyDefinition, ResponseFormat> successResponse = Either.left(new PolicyDefinition());
when(businessLogic.deletePolicy(eq(ComponentTypeEnum.RESOURCE), eq(componentId), eq(POLICY_ID), eq(USER_ID), eq(true))).thenReturn(successResponse);
- when(responseFormat.getStatus()).thenReturn(HttpStatus.NO_CONTENT_204.getStatusCode());
- when(componentsUtils.getResponseFormat(ActionStatus.NO_CONTENT)).thenReturn(responseFormat);
+ when(responseFormat.getStatus()).thenReturn(HttpStatus.OK_200.getStatusCode());
Response response = target()
.path(path)
.request(MediaType.APPLICATION_JSON)
.header("USER_ID", USER_ID)
.delete(Response.class);
- assertEquals(response.getStatus(), HttpStatus.NO_CONTENT_204.getStatusCode());
+ assertEquals(response.getStatus(), HttpStatus.OK_200.getStatusCode());
}
@Test
@@ -255,6 +280,73 @@ public class PolicyServletTest extends JerseySpringBaseTest{
assertEquals(HttpStatus.NOT_FOUND_404.getStatusCode(), policyProps.getStatus());
}
+ @Test
+ public void testDeclarePropertyToPolicySuccess() {
+ Service service = new Service();
+ service.setUniqueId(SERVICE_ID);
+ service.addProperty(new PropertyDataDefinitionBuilder().setUniqueId(PROP_1).build());
+
+ PolicyDefinition policyDefinition = new PolicyDefinition();
+ policyDefinition.setUniqueId(UniqueIdBuilder.buildPolicyUniqueId(SERVICE_ID, PROP_1));
+
+ setMocksForPropertyDeclaration(policyDefinition);
+
+ when(componentsUtils.getResponseFormat(eq(ActionStatus.OK))).thenReturn(new ResponseFormat(HttpStatus.OK_200.getStatusCode()));
+
+ Response declareResponse = buildDeclarePropertiesRequest(PROP_1).invoke();
+ assertEquals(HttpStatus.OK_200.getStatusCode(), declareResponse.getStatus());
+ }
+
+ @Test
+ public void testUndeclarePolicySuccess() {
+ Service service = new Service();
+ service.setUniqueId(SERVICE_ID);
+ PropertyDefinition origProperty = new PropertyDataDefinitionBuilder().setUniqueId(PROP_1).build();
+
+ service.addProperty(origProperty);
+
+ PolicyDefinition policyDefinition = new PolicyDefinition();
+ policyDefinition.setUniqueId(UniqueIdBuilder.buildPolicyUniqueId(SERVICE_ID, PROP_1));
+ service.addPolicy(policyDefinition);
+
+ addGetPolicyValueToProperty(origProperty, policyDefinition);
+
+ when(businessLogic.deletePolicy(eq(ComponentTypeEnum.SERVICE), eq(SERVICE_ID), eq(policyDefinition.getUniqueId()), eq(USER_ID), eq(true))).thenReturn(Either.left(policyDefinition));
+
+ Response deleteResponse = buildDeletePolicyRequest(policyDefinition).invoke();
+ assertEquals(HttpStatus.OK_200.getStatusCode(), deleteResponse.getStatus());
+ }
+
+ private void addGetPolicyValueToProperty(PropertyDefinition propertyDefinition,
+ PolicyDefinition policyDefinition) {
+ JSONObject jobject = new JSONObject();
+ String origValue = Objects.isNull(propertyDefinition.getValue()) ? propertyDefinition.getDefaultValue() : propertyDefinition.getValue();
+ jobject.put(GET_POLICY, null);
+ propertyDefinition.setValue(jobject.toJSONString());
+
+ GetPolicyValueDataDefinition getPolicyValueDataDefinition = new GetPolicyValueDataDefinition();
+ getPolicyValueDataDefinition.setPolicyId(policyDefinition.getUniqueId());
+ getPolicyValueDataDefinition.setPropertyName(propertyDefinition.getName());
+
+ getPolicyValueDataDefinition.setOrigPropertyValue(origValue);
+
+ propertyDefinition.setGetPolicyValues(Collections.singletonList(getPolicyValueDataDefinition));
+ }
+
+ private void setMocksForPropertyDeclaration(PolicyDefinition policyDefinition) {
+ when(request.getSession()).thenReturn(session);
+ when(session.getServletContext()).thenReturn(context);
+ when(context.getAttribute(eq(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR))).thenReturn(contextWrapper);
+ when(contextWrapper.getWebAppContext(any())).thenReturn(applicationContext);
+ when(applicationContext.getBean(eq(PolicyBusinessLogic.class))).thenReturn(businessLogic);
+ when(businessLogic.declareProperties(eq(USER_ID), eq(SERVICE_ID), any(), any())).thenReturn(
+ Either.left(Collections.singletonList(policyDefinition)));
+ when(componentsUtils
+ .convertJsonToObjectUsingObjectMapper(any(), any(), eq(ComponentInstInputsMap.class), eq(
+ AuditingActionEnum.CREATE_RESOURCE), eq(ComponentTypeEnum.SERVICE)))
+ .thenReturn(Either.left(getDeclarationBodyForProperty(PROP_1)));
+ }
+
private List<PropertyDataDefinition> getPropertiesList() {
PropertyDefinition prop1 = new PropertyDataDefinitionBuilder()
.setUniqueId("prop1")
@@ -316,6 +408,41 @@ public class PolicyServletTest extends JerseySpringBaseTest{
.request(MediaType.APPLICATION_JSON)
.header(Constants.USER_ID_HEADER, USER_ID);
}
+
+ private Invocation buildDeletePolicyRequest(PolicyDefinition policyDefinition) {
+ return target(DELETE_URL)
+ .resolveTemplate("containerComponentType", "services")
+ .resolveTemplate("componentId", SERVICE_ID)
+ .resolveTemplate("policyId", policyDefinition.getUniqueId())
+ .request(MediaType.APPLICATION_JSON)
+ .header(Constants.USER_ID_HEADER, USER_ID)
+ .buildDelete();
+ }
+
+ private Invocation buildDeclarePropertiesRequest(String propertyId) {
+ return target(DECLARE_URL)
+ .resolveTemplate("componentType", "services")
+ .resolveTemplate("serviceId", SERVICE_ID)
+ .request(MediaType.APPLICATION_JSON)
+ .header(Constants.USER_ID_HEADER, USER_ID)
+ .buildPost(Entity.entity(getDeclarationBodyForProperty(propertyId), MediaType.APPLICATION_JSON));
+ }
+
+ private ComponentInstInputsMap getDeclarationBodyForProperty(String propertyId) {
+ ComponentInstInputsMap componentInstInputsMap = new ComponentInstInputsMap();
+ ComponentInstancePropInput propInput = new ComponentInstancePropInput();
+ PropertyDefinition propertyDefinition = new PropertyDefinition();
+
+ propertyDefinition.setType("string");
+ propertyDefinition.setUniqueId(SERVICE_ID + "." + propertyId);
+ propInput.setInput(propertyDefinition);
+ propInput.setPropertiesName(propertyId);
+
+ componentInstInputsMap.setComponentInstancePropertiesToPolicies(new HashMap<>());
+ componentInstInputsMap.getComponentInstancePropertiesToPolicies().put("componentInstancePropertiesToPolicies", Collections.singletonList(propInput));
+
+ return componentInstInputsMap;
+ }
@Override
protected ResourceConfig configure() {
@@ -324,7 +451,15 @@ public class PolicyServletTest extends JerseySpringBaseTest{
}
private static void createMocks() {
+ propertyDeclarationOrchestrator = Mockito.mock(PropertyDeclarationOrchestrator.class);
+ toscaOperationFacade = Mockito.mock(ToscaOperationFacade.class);
businessLogic = Mockito.mock(PolicyBusinessLogic.class);
+ businessLogic.setPropertyDeclarationOrchestrator(propertyDeclarationOrchestrator);
+ businessLogic.setToscaOperationFacade(toscaOperationFacade);
+
+ baseBusinessLogic = Mockito.spy(BaseBusinessLogic.class);
+ baseBusinessLogic.setToscaOperationFacade(toscaOperationFacade);
+
componentsUtils = Mockito.mock(ComponentsUtils.class);
servletUtils = Mockito.mock(ServletUtils.class);
responseFormat = Mockito.mock(ResponseFormat.class);
diff --git a/catalog-model/pom.xml b/catalog-model/pom.xml
index 994b2f7960..06b65915be 100644
--- a/catalog-model/pom.xml
+++ b/catalog-model/pom.xml
@@ -281,12 +281,17 @@
<artifactId>netty-handler</artifactId>
</dependency>
<dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-collections4</artifactId>
- <version>4.1</version>
+ <groupId>org.projectlombok</groupId>
+ <artifactId>lombok</artifactId>
+ <version>${lombok.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>joda-time</groupId>
+ <artifactId>joda-time</artifactId>
+ <version>${joda.time.version}</version>
</dependency>
- </dependencies>
+ </dependencies>
<build>
<plugins>
<plugin>
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java
index e33ded2fb4..65ad149a89 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java
@@ -39,28 +39,18 @@ import java.util.stream.Collectors;
import org.apache.commons.collections.MapUtils;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.utils.MapUtil;
-import org.openecomp.sdc.be.datatypes.elements.*;
+import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.PolicyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.PolicyTargetType;
+import org.openecomp.sdc.be.datatypes.elements.PropertiesOwner;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.model.category.CategoryDefinition;
import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElementTypeEnum;
import org.openecomp.sdc.common.api.ArtifactTypeEnum;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.function.Predicate;
-import java.util.stream.Collectors;
-
-import static java.util.Collections.emptyList;
-import static java.util.Collections.emptyMap;
-import static java.util.stream.Collectors.toMap;
-import static org.apache.commons.collections.CollectionUtils.isEmpty;
-import static org.apache.commons.collections.MapUtils.isEmpty;
-
public abstract class Component implements PropertiesOwner {
private ComponentMetadataDefinition componentMetadataDefinition;
@@ -83,9 +73,11 @@ public abstract class Component implements PropertiesOwner {
private String derivedFromGenericVersion;
private String toscaType;
protected List<AdditionalInformationDefinition> additionalInformation;
+ private Map<String, CINodeFilterDataDefinition> nodeFilterComponents;
+ private Map<String, List<UploadNodeFilterInfo>> nodeFilters;
+ private Map<String, List<UploadNodeFilterInfo>> serviceFilters;
protected List<PropertyDefinition> properties;
private Map<String, InterfaceDefinition> interfaces;
- private Map<String, CINodeFilterDataDefinition> nodeFilterComponents;
public Map<String, InterfaceDefinition> getInterfaces() {
return interfaces;
@@ -567,6 +559,42 @@ public abstract class Component implements PropertiesOwner {
this.policies = policies;
}
+ public void addPolicy(PolicyDefinition policyDefinition) {
+ if(MapUtils.isEmpty(this.policies)) {
+ this.policies = new HashMap<>();
+ }
+
+ this.policies.put(policyDefinition.getUniqueId(), policyDefinition);
+ }
+
+ public Map<String, CINodeFilterDataDefinition> getNodeFilterComponents() {
+ return nodeFilterComponents;
+ }
+
+ public void setNodeFilterComponents(Map<String, CINodeFilterDataDefinition> nodeFilter) {
+ this.nodeFilterComponents = nodeFilter;
+ }
+
+
+
+ public Map<String, List<UploadNodeFilterInfo>> getNodeFilters() {
+ return nodeFilters;
+ }
+
+ public void setNodeFilters(
+ Map<String, List<UploadNodeFilterInfo>> nodeFilters) {
+ this.nodeFilters = nodeFilters;
+ }
+
+ public Map<String, List<UploadNodeFilterInfo>> getServiceFilters() {
+ return serviceFilters;
+ }
+
+ public void setServiceFilters(
+ Map<String, List<UploadNodeFilterInfo>> serviceFilters) {
+ this.serviceFilters = serviceFilters;
+ }
+
public List<PropertyDefinition> getProperties() {
return properties;
}
@@ -575,6 +603,14 @@ public abstract class Component implements PropertiesOwner {
this.properties = properties;
}
+ public void addProperty(PropertyDefinition propertyDefinition) {
+ if(org.apache.commons.collections.CollectionUtils.isEmpty(this.properties)) {
+ this.properties = new ArrayList<>();
+ }
+
+ this.properties.add(propertyDefinition);;
+ }
+
@Override
public int hashCode() {
final int prime = 31;
@@ -582,11 +618,7 @@ public abstract class Component implements PropertiesOwner {
result = prime * result + ((artifacts == null) ? 0 : artifacts.hashCode());
result = prime * result + ((categories == null) ? 0 : categories.hashCode());
result = prime * result + ((componentMetadataDefinition == null) ? 0 : componentMetadataDefinition.hashCode());
-// result = prime * result + ((creatorUserId == null) ? 0 : creatorUserId.hashCode());
-// result = prime * result + ((creatorFullName == null) ? 0 : creatorFullName.hashCode());
result = prime * result + ((deploymentArtifacts == null) ? 0 : deploymentArtifacts.hashCode());
-// result = prime * result + ((lastUpdaterUserId == null) ? 0 : lastUpdaterUserId.hashCode());
-// result = prime * result + ((lastUpdaterFullName == null) ? 0 : lastUpdaterFullName.hashCode());
result = prime * result + ((capabilities == null) ? 0 : capabilities.hashCode());
result = prime * result + ((requirements == null) ? 0 : requirements.hashCode());
result = prime * result + ((componentInstances == null) ? 0 : componentInstances.hashCode());
@@ -604,14 +636,6 @@ public abstract class Component implements PropertiesOwner {
return result;
}
- public Map<String, CINodeFilterDataDefinition> getNodeFilterComponents() {
- return nodeFilterComponents;
- }
-
- public void setNodeFilterComponents(Map<String, CINodeFilterDataDefinition> nodeFilterComponents) {
- this.nodeFilterComponents = nodeFilterComponents;
- }
-
@Override
public boolean equals(Object obj) {
if (this == obj) {
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstInputsMap.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstInputsMap.java
index 9d0877d8f9..a7903b3f30 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstInputsMap.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstInputsMap.java
@@ -20,6 +20,8 @@
package org.openecomp.sdc.be.model;
+import lombok.Getter;
+import lombok.Setter;
import org.apache.commons.lang3.tuple.Pair;
import java.util.List;
@@ -27,6 +29,8 @@ import java.util.Map;
import static org.apache.commons.collections.MapUtils.isNotEmpty;
+@Getter
+@Setter
public class ComponentInstInputsMap {
private Map<String, List<ComponentInstancePropInput>> componentInstanceInputsMap;
@@ -34,6 +38,8 @@ public class ComponentInstInputsMap {
private Map<String, List<ComponentInstancePropInput>> serviceProperties;
private Map<String, List<ComponentInstancePropInput>> policyProperties;
private Map<String, List<ComponentInstancePropInput>> groupProperties;
+ private Map<String, List<ComponentInstancePropInput>> componentPropertiesToPolicies;
+ private Map<String, List<ComponentInstancePropInput>> componentInstancePropertiesToPolicies;
public Pair<String, List<ComponentInstancePropInput>> resolvePropertiesToDeclare() {
if (isNotEmpty(componentInstanceInputsMap)) {
@@ -51,6 +57,12 @@ public class ComponentInstInputsMap {
if (isNotEmpty(groupProperties)) {
return singleMapEntry(groupProperties);
}
+ if(isNotEmpty(componentPropertiesToPolicies)) {
+ return singleMapEntry(componentPropertiesToPolicies);
+ }
+ if (isNotEmpty(componentInstancePropertiesToPolicies)) {
+ return singleMapEntry(componentInstancePropertiesToPolicies);
+ }
throw new IllegalStateException("there are no properties selected for declaration");
}
@@ -58,48 +70,4 @@ public class ComponentInstInputsMap {
Map.Entry<String, List<ComponentInstancePropInput>> singleEntry = propertiesMap.entrySet().iterator().next();
return Pair.of(singleEntry.getKey(), singleEntry.getValue());
}
-
- public Map<String, List<ComponentInstancePropInput>> getComponentInstanceInputsMap() {
- return componentInstanceInputsMap;
- }
-
- public void setComponentInstanceInputsMap(Map<String, List<ComponentInstancePropInput>> componentInstanceInputsMap) {
- this.componentInstanceInputsMap = componentInstanceInputsMap;
- }
-
- public Map<String, List<ComponentInstancePropInput>> getComponentInstanceProperties() {
- return componentInstanceProperties;
- }
-
- public void setComponentInstancePropInput(Map<String, List<ComponentInstancePropInput>> componentInstanceProperties) {
- this.componentInstanceProperties = componentInstanceProperties;
- }
-
- public Map<String, List<ComponentInstancePropInput>> getPolicyProperties() {
- return policyProperties;
- }
-
- public void setPolicyProperties(Map<String, List<ComponentInstancePropInput>> policyProperties) {
- this.policyProperties = policyProperties;
- }
-
- public Map<String, List<ComponentInstancePropInput>> getServiceProperties() {
- return serviceProperties;
- }
-
- public void setServiceProperties(
- Map<String, List<ComponentInstancePropInput>> serviceProperties) {
- this.serviceProperties = serviceProperties;
- }
-
- public Map<String, List<ComponentInstancePropInput>> getGroupProperties() {
- return groupProperties;
- }
-
- public void setGroupProperties(Map<String, List<ComponentInstancePropInput>> groupProperties) {
- this.groupProperties = groupProperties;
- }
-
-
-
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentParametersView.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentParametersView.java
index 35b4a865a1..05d9a572a3 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentParametersView.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentParametersView.java
@@ -20,12 +20,11 @@
package org.openecomp.sdc.be.model;
+import java.util.List;
import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
import org.openecomp.sdc.be.datatypes.enums.ComponentFieldsEnum;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import java.util.List;
-
public class ComponentParametersView {
private boolean ignoreUsers = false;
@@ -40,6 +39,7 @@ public class ComponentParametersView {
private boolean ignoreAdditionalInformation = false;
private boolean ignoreArtifacts = false;
private boolean ignoreInterfaces = false;
+ private boolean ignoreInterfaceInstances = false;
private boolean ignoreComponentInstancesInterfaces = false;
private boolean ignoreDerivedFrom = false;
private boolean ignoreAttributesFrom = false;
@@ -49,6 +49,7 @@ public class ComponentParametersView {
private boolean ignoreCapabiltyProperties = true;
private boolean ignoreServicePath = true;
private boolean ignorePolicies = false;
+ private boolean ignoreNodeFilterRequirements = false;
private boolean ignoreNodeFilter = false;
public ComponentParametersView() {
@@ -146,6 +147,7 @@ public class ComponentParametersView {
this.setIgnorePolicies(false);
break;
case NODE_FILTER:
+ this.setIgnoreNodeFilterRequirements(false);
this.setIgnoreNodeFilter(false);
break;
case COMPONENT_INSTANCES_INTERFACES:
@@ -165,96 +167,120 @@ public class ComponentParametersView {
public Component filter(Component component, ComponentTypeEnum componentType) {
- if (ignoreUsers) {
- component.setCreatorUserId(null);
- component.setCreatorFullName(null);
- component.setLastUpdaterUserId(null);
- component.setLastUpdaterFullName(null);
- }
- if (ignoreGroups) {
- component.setGroups(null);
- }
- if (ignoreComponentInstances) {
- component.setComponentInstances(null);
- component.setComponentInstancesRelations(null);
- }
- if (ignoreComponentInstancesProperties) {
- component.setComponentInstancesProperties(null);
- }
- if (ignoreProperties && componentType == ComponentTypeEnum.RESOURCE) {
- ((Resource) component).setProperties(null);
- }
- if (ignoreCapabilities) {
- component.setCapabilities(null);
- }
- if (ignoreRequirements) {
- component.setRequirements(null);
- }
- if (ignoreCategories) {
- component.setCategories(null);
- }
- if (ignoreAllVersions) {
- component.setAllVersions(null);
- }
- if (ignoreAdditionalInformation && componentType == ComponentTypeEnum.RESOURCE) {
- ((Resource) component).setAdditionalInformation(null);
- }
- if (ignoreArtifacts) {
- component.setArtifacts(null);
- component.setSpecificComponetTypeArtifacts(null);
- component.setDeploymentArtifacts(null);
- component.setToscaArtifacts(null);
- }
- if (ignoreInterfaces && componentType == ComponentTypeEnum.RESOURCE) {
- ((Resource) component).setInterfaces(null);
- }
- if (ignoreDerivedFrom && componentType == ComponentTypeEnum.RESOURCE) {
- ((Resource) component).setDerivedFrom(null);
- }
- if (ignoreAttributesFrom && componentType == ComponentTypeEnum.RESOURCE) {
- ((Resource) component).setAttributes(null);
- }
- if (ignoreComponentInstancesAttributesFrom) {
- component.setComponentInstancesAttributes(null);
- }
- if (ignoreInputs) {
- component.setInputs(null);
- }
- if (ignoreComponentInstancesInputs) {
- component.setComponentInstancesInputs(null);
- }
- if (ignoreServicePath && componentType == ComponentTypeEnum.SERVICE) {
- ((Service) component).setForwardingPaths(null);
- }
- if (ignoreNodeFilter){
- component.setNodeFilterComponents(null);
- }
- return component;
- }
-
- public void disableAll() {
- ignoreUsers = true;
- ignoreGroups = true;
- ignorePolicies = true;
- ignoreComponentInstances = true;
- ignoreComponentInstancesProperties = true;
- ignoreProperties = true;
- ignoreCapabilities = true;
- ignoreRequirements = true;
- ignoreCategories = true;
- ignoreAllVersions = true;
- ignoreAdditionalInformation = true;
- ignoreArtifacts = true;
- ignoreInterfaces = true;
- ignoreDerivedFrom = true;
- ignoreAttributesFrom = true;
- ignoreInputs = true;
- ignoreComponentInstancesAttributesFrom = true;
- ignoreComponentInstancesInputs = true;
- ignoreCapabiltyProperties = true;
- ignoreServicePath = true;
+ if (ignoreUsers) {
+ component.setCreatorUserId(null);
+ component.setCreatorFullName(null);
+ component.setLastUpdaterUserId(null);
+ component.setLastUpdaterFullName(null);
+ }
+
+ if (ignoreGroups) {
+ component.setGroups(null);
+ }
+
+ if (ignoreComponentInstances) {
+ component.setComponentInstances(null);
+ component.setComponentInstancesRelations(null);
+ }
+
+ if (ignoreComponentInstancesProperties) {
+ component.setComponentInstancesProperties(null);
+ }
+
+ if (ignoreProperties && componentType == ComponentTypeEnum.RESOURCE) {
+ ((Resource) component).setProperties(null);
+ }
+
+ if (ignoreCapabilities) {
+ component.setCapabilities(null);
+ }
+
+ if (ignoreRequirements) {
+ component.setRequirements(null);
+ }
+
+ if (ignoreCategories) {
+ component.setCategories(null);
+ }
+
+ if (ignoreAllVersions) {
+ component.setAllVersions(null);
+ }
+ if (ignoreAdditionalInformation && componentType == ComponentTypeEnum.RESOURCE) {
+ ((Resource) component).setAdditionalInformation(null);
+ }
+
+ if (ignoreArtifacts) {
+ component.setArtifacts(null);
+ component.setSpecificComponetTypeArtifacts(null);
+ component.setDeploymentArtifacts(null);
+ component.setToscaArtifacts(null);
+ }
+ if (ignoreNodeFilterRequirements){
+ component.setNodeFilterComponents(null);
+ }
+ if (ignoreInterfaces && ignoreInterfaceInstances &&
+ componentType == ComponentTypeEnum.RESOURCE) {
+ component.setInterfaces(null);
+ }
+ if (ignoreDerivedFrom && componentType == ComponentTypeEnum.RESOURCE) {
+ ((Resource) component).setDerivedFrom(null);
+ }
+ if (ignoreAttributesFrom && componentType == ComponentTypeEnum.RESOURCE) {
+ ((Resource) component).setAttributes(null);
+ }
+ if (ignoreComponentInstancesAttributesFrom) {
+ component.setComponentInstancesAttributes(null);
+ }
+ if (ignoreInputs) {
+ component.setInputs(null);
+ }
+ if (ignoreComponentInstancesInputs) {
+ component.setComponentInstancesInputs(null);
+ }
+ if (ignoreServicePath && componentType == ComponentTypeEnum.SERVICE) {
+ ((Service) component).setForwardingPaths(null);
+ }
+ if (ignoreNodeFilter){
+ component.setNodeFilterComponents(null);
+ }
+ return component;
+
+ }
+
+ public boolean isIgnoreNodeFilterRequirements() {
+ return ignoreNodeFilterRequirements;
+ }
+
+ public void setIgnoreNodeFilterRequirements(boolean ignoreNodeFilter) {
+ this.ignoreNodeFilterRequirements = ignoreNodeFilter;
+ }
+
+ public void disableAll() {
+ ignoreUsers = true;
+ ignoreGroups = true;
+ ignorePolicies = true;
+ ignoreComponentInstances = true;
+ ignoreComponentInstancesProperties = true;
+ ignoreProperties = true;
+ ignoreCapabilities = true;
+ ignoreRequirements = true;
+ ignoreCategories = true;
+ ignoreAllVersions = true;
+ ignoreAdditionalInformation = true;
+ ignoreArtifacts = true;
+ ignoreInterfaces = true;
+ ignoreInterfaceInstances = true;
+ ignoreDerivedFrom = true;
+ ignoreAttributesFrom = true;
+ ignoreInputs = true;
+ ignoreComponentInstancesAttributesFrom = true;
+ ignoreComponentInstancesInputs = true;
+ ignoreCapabiltyProperties = true;
+ ignoreServicePath = true;
+ ignoreNodeFilterRequirements = true;
ignoreNodeFilter = true;
- }
+ }
public boolean isIgnoreGroups() {
return ignoreGroups;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/PolicyDefinition.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/PolicyDefinition.java
index 17e422bc5b..e69bf3f16b 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/PolicyDefinition.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/PolicyDefinition.java
@@ -1,12 +1,11 @@
package org.openecomp.sdc.be.model;
-import org.openecomp.sdc.be.datatypes.elements.PolicyDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.PropertiesOwner;
-import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
-
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
+import org.openecomp.sdc.be.datatypes.elements.PolicyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.PropertiesOwner;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
/**
* public class representing the component policy
*/
@@ -19,6 +18,10 @@ public class PolicyDefinition extends PolicyDataDefinition implements Properties
super();
}
+ public PolicyDefinition(PropertyDataDefinition propertyDataDefinition) {
+ super(propertyDataDefinition);
+ }
+
/**
* public constructor from superclass
* @param policy
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/ToscaFunctions.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/ToscaFunctions.java
index 1f55fecc86..6e52976a42 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/ToscaFunctions.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/ToscaFunctions.java
@@ -7,7 +7,8 @@ public enum ToscaFunctions {
GET_INPUT("get_input"),
GET_PROPERTY("get_property"),
- GET_OPERATION_OUTPUT("get_operation_output");
+ GET_OPERATION_OUTPUT("get_operation_output"),
+ GET_POLICY("get_policy");
private String functionName;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/ToscaType.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/ToscaType.java
index 6384146df9..04b6874f93 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/ToscaType.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/ToscaType.java
@@ -20,6 +20,8 @@
package org.openecomp.sdc.be.model.tosca;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
@@ -27,8 +29,6 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.codehaus.jackson.type.TypeReference;
import org.openecomp.sdc.be.model.tosca.constraints.ConstraintUtil;
import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintValueDoNotMatchPropertyTypeException;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/ConstraintUtil.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/ConstraintUtil.java
index 0bbc0f755f..188ad1b5c7 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/ConstraintUtil.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/ConstraintUtil.java
@@ -20,14 +20,14 @@
package org.openecomp.sdc.be.model.tosca.constraints;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.codehaus.jackson.type.TypeReference;
import org.openecomp.sdc.be.model.tosca.ToscaType;
import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintValueDoNotMatchPropertyTypeException;
import org.slf4j.Logger;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/DataTypePropertyConverter.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/DataTypePropertyConverter.java
index f3b842e0cf..7f11330bdf 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/DataTypePropertyConverter.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/DataTypePropertyConverter.java
@@ -5,14 +5,13 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.stream.JsonReader;
-import org.openecomp.sdc.be.model.DataTypeDefinition;
-import org.openecomp.sdc.be.model.PropertyDefinition;
-import org.openecomp.sdc.common.util.JsonUtils;
-
import java.io.StringReader;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.common.util.JsonUtils;
public class DataTypePropertyConverter {
@@ -52,7 +51,7 @@ public class DataTypePropertyConverter {
}
private void mergeDefaultValuesRec(JsonObject defaultValue, JsonObject value) {
- if (ToscaConverterUtils.isGetInputValue(value)) {
+ if (ToscaConverterUtils.isGetInputValue(value) || ToscaConverterUtils.isGetPolicyValue(value)) {
return;
}
for (Map.Entry<String, JsonElement> defVal : defaultValue.entrySet()) {
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/ToscaConverterUtils.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/ToscaConverterUtils.java
index 941535a09d..5848abfc49 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/ToscaConverterUtils.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/ToscaConverterUtils.java
@@ -5,8 +5,14 @@ import org.openecomp.sdc.be.model.tosca.ToscaFunctions;
public class ToscaConverterUtils {
+ private ToscaConverterUtils() {}
+
public static boolean isGetInputValue(JsonObject value) {
return value.get(ToscaFunctions.GET_INPUT.getFunctionName()) != null;
}
+ public static boolean isGetPolicyValue(JsonObject value) {
+ return value.get(ToscaFunctions.GET_POLICY.getFunctionName()) != null;
+ }
+
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/ToscaMapValueConverter.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/ToscaMapValueConverter.java
index 04636d87e0..f0b3ca25b9 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/ToscaMapValueConverter.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/ToscaMapValueConverter.java
@@ -20,18 +20,27 @@
package org.openecomp.sdc.be.model.tosca.converters;
-import com.google.gson.*;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParseException;
+import com.google.gson.JsonParser;
+import com.google.gson.JsonSyntaxException;
import com.google.gson.stream.JsonReader;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.tosca.ToscaFunctions;
import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
import org.openecomp.sdc.common.log.wrappers.Logger;
-import java.io.StringReader;
-import java.util.*;
-import java.util.Map.Entry;
-
public class ToscaMapValueConverter extends ToscaValueBaseConverter implements ToscaValueConverter {
private static ToscaMapValueConverter mapConverter = new ToscaMapValueConverter();
@@ -230,7 +239,7 @@ public class ToscaMapValueConverter extends ToscaValueBaseConverter implements T
convValue = handleComplexJsonValue(elementValue);
}
}
- if(preserveEmptyValue || !isEmptyObjectValue(convValue)){
+ if(preserveEmptyValue || !isEmptyObjectValue(convValue) || isGetPolicyValue(propName)){
toscaObjectPresentation.put(propName, convValue);
}
}
@@ -238,4 +247,7 @@ public class ToscaMapValueConverter extends ToscaValueBaseConverter implements T
return convertedValue;
}
+ private boolean isGetPolicyValue(String key) {
+ return key.equals(ToscaFunctions.GET_POLICY.getFunctionName());
+ }
}
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/ComponentInstInputsMapTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ComponentInstInputsMapTest.java
index 95247c7cd4..43f7f0c1cb 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/ComponentInstInputsMapTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ComponentInstInputsMapTest.java
@@ -51,7 +51,7 @@ public class ComponentInstInputsMapTest {
// default test
testSubject = createTestSubject();
- testSubject.setComponentInstancePropInput(componentInstanceProperties);
+ testSubject.setComponentInstanceProperties(componentInstanceProperties);
}
@Test
@@ -80,7 +80,7 @@ public class ComponentInstInputsMapTest {
testSubject.setComponentInstanceInputsMap(inputs);
testSubject.resolvePropertiesToDeclare();
testSubject = createTestSubject();
- testSubject.setComponentInstancePropInput(inputs);
+ testSubject.setComponentInstanceProperties(inputs);
testSubject.resolvePropertiesToDeclare();
testSubject = createTestSubject();
testSubject.setPolicyProperties(inputs);
diff --git a/catalog-ui/src/app/models/graph/zones/policy-instance.ts b/catalog-ui/src/app/models/graph/zones/policy-instance.ts
index c0a6678b21..cef1705a41 100644
--- a/catalog-ui/src/app/models/graph/zones/policy-instance.ts
+++ b/catalog-ui/src/app/models/graph/zones/policy-instance.ts
@@ -62,6 +62,7 @@ export class PolicyInstance implements IZoneInstanceMethod {
iconSprite:string;
icon:string;
originArchived:boolean;
+ instanceUniqueId: string;
constructor(policy?:PolicyInstance) {
@@ -81,6 +82,7 @@ export class PolicyInstance implements IZoneInstanceMethod {
this.targets = policy.targets;
this.uniqueId = policy.uniqueId;
this.version = policy.version;
+ this.instanceUniqueId = policy.instanceUniqueId;
this.iconSprite = '';
this.icon = 'icon-policy';
diff --git a/catalog-ui/src/app/models/properties-inputs/property-be-model.ts b/catalog-ui/src/app/models/properties-inputs/property-be-model.ts
index a1a85aa73d..15b9534b99 100644
--- a/catalog-ui/src/app/models/properties-inputs/property-be-model.ts
+++ b/catalog-ui/src/app/models/properties-inputs/property-be-model.ts
@@ -26,14 +26,26 @@ export enum DerivedPropertyType {
MAP,
COMPLEX
}
+export class PropertyPolicyDetail {
+ policyId: string;
+ propertyName: string;
+ constructor(propertyPolicy?:PropertyPolicyDetail) {
+ if(propertyPolicy) {
+ this.policyId = propertyPolicy.policyId;
+ this.propertyName = propertyPolicy.propertyName;
+ }
+ }
+}
export class PropertyBEModel {
+
constraints: Array<any>;
defaultValue: string;
definition: boolean;
description: string;
fromDerived: boolean;
getInputValues: Array<PropertyInputDetail>;
+ getPolicyValues: Array<PropertyPolicyDetail>;
name: string;
parentUniqueId: string;
password: boolean;
@@ -45,6 +57,7 @@ export class PropertyBEModel {
value: string;
parentPropertyType: string;
subPropertyInputPath: string;
+ inputPath: string;
constructor(property?: PropertyBEModel) {
if (property) {
@@ -65,6 +78,8 @@ export class PropertyBEModel {
this.getInputValues = property.getInputValues;
this.parentPropertyType = property.parentPropertyType;
this.subPropertyInputPath = property.subPropertyInputPath;
+ this.getPolicyValues = property.getPolicyValues;
+ this.inputPath = property.inputPath;
}
if (!this.schema || !this.schema.property) {
diff --git a/catalog-ui/src/app/ng2/components/logic/policies-table/policies-table.component.html b/catalog-ui/src/app/ng2/components/logic/policies-table/policies-table.component.html
new file mode 100644
index 0000000000..6106e13924
--- /dev/null
+++ b/catalog-ui/src/app/ng2/components/logic/policies-table/policies-table.component.html
@@ -0,0 +1,48 @@
+
+<div class="properties-table">
+ <loader [display]="isLoading" [size]="'large'" [relative]="true"></loader>
+ <div class="table-header">
+ <div class="table-cell col1" (click)="sort('name')">Property Name
+ <span *ngIf="sortBy === 'name'" class="table-header-sort-arrow" [ngClass]="{'down': reverse, 'up':!reverse}">
+ </span>
+ </div>
+ <div class="table-cell col3" (click)="sort('instanceUniqueId')">From Instance
+ <span *ngIf="sortBy === 'instanceUniqueId'" class="table-header-sort-arrow" [ngClass]="{'down': reverse, 'up':!reverse}">
+ </span>
+ </div>
+ <div class="table-cell col2" (click)="sort('type')">Type
+ <span *ngIf="sortBy === 'type'" class="table-header-sort-arrow" [ngClass]="{'down': reverse, 'up':!reverse}">
+ </span>
+ </div>
+ </div>
+ <div class="table-body">
+ <div class="no-data" *ngIf="!policies || !policies.length">No data to display</div>
+ <div>
+ <div class="table-row" *ngFor="let policy of policies">
+ <div class="table-cell col1">
+ <div class="inner-cell-div" tooltips tooltip="{{policy.name}}">
+ <span class="property-name">{{policy.name}}</span>
+ </div>
+ </div>
+ <div class="table-cell col3">
+ <div class="inner-cell-div" tooltips tooltip="{{instanceNamesMap[policy.instanceUniqueId]?.name}}">
+ <span>{{instanceNamesMap[policy.instanceUniqueId]?.name}}</span>
+ </div>
+ </div>
+ <div class="table-cell col2">
+ <div class="inner-cell-div" tooltips tooltip="{{policy.type | contentAfterLastDot}}">
+ <span>{{policy.type | contentAfterLastDot}}</span>
+ </div>
+ </div>
+ <div class="table-cell valueCol policy-value-col">
+ <div class="delete-button-container">
+ <span *ngIf="policy.uniqueId && !readonly" class="sprite-new delete-btn" (click)="openDeleteModal(policy)" data-tests-id="delete-policy-button"></span>
+ </div>
+ </div>
+
+ </div>
+ </div>
+ </div>
+</div>
+
+
diff --git a/catalog-ui/src/app/ng2/components/logic/policies-table/policies-table.component.less b/catalog-ui/src/app/ng2/components/logic/policies-table/policies-table.component.less
new file mode 100644
index 0000000000..57a69a3aa1
--- /dev/null
+++ b/catalog-ui/src/app/ng2/components/logic/policies-table/policies-table.component.less
@@ -0,0 +1,169 @@
+
+@import './../../../../../assets/styles/variables.less';
+
+:host /deep/ input { width:100%;}
+
+.properties-table {
+ display:flex;
+ flex-direction:column;
+ flex: 1;
+ height:100%;
+ text-align:left;
+
+ .inner-cell-div{
+ max-width: 100%;
+ text-overflow: ellipsis;
+ overflow: hidden;
+ height: 20px;
+ }
+
+
+ .table-header {
+ font-weight:bold;
+ border-top: @main_color_o solid 1px;
+ background-color: @tlv_color_u;
+ color:@func_color_s;
+
+ .table-cell {
+ font-size: 13px;
+ .table-header-sort-arrow {
+ display: inline-block;
+ background-color: transparent;
+ border: none;
+ color: #AAA;
+ margin: 8px 0 0 5px;
+ &.up {
+ border-left: 5px solid transparent;
+ border-right: 5px solid transparent;
+ border-bottom: 5px solid;
+ }
+ &.down {
+ border-left: 5px solid transparent;
+ border-right: 5px solid transparent;
+ border-top: 5px solid;
+ }
+ }
+ }
+ }
+ .table-header, .table-row {
+ display: flex;
+ flex-direction:row;
+ flex: 0 0 auto;
+ }
+
+ .table-body {
+ display:flex;
+ flex-direction: column;
+ overflow-y:auto;
+ flex: 1;
+
+ .no-data {
+ border: @main_color_o solid 1px;
+ border-top:none;
+ text-align: center;
+ height: 100%;
+ padding: 20px;
+ }
+ /deep/.selected{
+ background-color: @tlv_color_v;
+ color: @main_color_a;
+ }
+ }
+
+ .table-row {
+ &:hover {
+ background-color:@tlv_color_t; cursor:pointer;
+ }
+
+ &:last-child {
+ flex: 1 0 auto;
+ }
+ .selected-row {
+ background-color:@tlv_color_v;
+ }
+ }
+
+ .table-cell {
+ font-size:13px;
+ flex:1;
+ border: @main_color_o solid 1px;
+ border-right:none;
+ border-top:none;
+ padding: 10px;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+
+
+ &:last-child {
+ border-right:@main_color_o solid 1px;
+ }
+ &.col1 {
+ flex: 1 0 130px;
+ max-width:130px;
+
+ justify-content: space-between;
+
+ .policy-name {
+ flex: 1;
+ }
+
+ //.policy-description-icon {
+ // float: right;
+ // margin-top: 4px;
+ // margin-left: 5px;
+ // flex: 0 0 auto;
+ //}
+ }
+ &.col2 {
+ flex: 0 0 140px;
+ max-width:140px;
+ }
+
+ &.col3 {
+ flex:0 0 120px;
+ max-width:120px;
+ }
+
+ &.valueCol {
+ .value-input {
+ flex: 1;
+ border: none;
+ background-color: inherit;
+
+ &:focus, &:active {
+ border:none;
+ outline:none;
+ }
+ }
+
+ .delete-btn {
+ flex: 0 0 auto;
+ }
+
+ .delete-button-container {
+ max-height: 24px;
+ }
+
+ &.inner-table-container {
+ padding: 0px;
+
+ .delete-button-container {
+ padding: 0 8px 0 0 ;
+ }
+ }
+ }
+
+ &.input-value-col {
+ padding: 8px;
+ }
+
+
+ }
+
+ .filtered {
+ /deep/ .checkbox-label-content{
+ background-color: yellow;
+ }
+ }
+
+}
diff --git a/catalog-ui/src/app/ng2/components/logic/policies-table/policies-table.component.ts b/catalog-ui/src/app/ng2/components/logic/policies-table/policies-table.component.ts
new file mode 100644
index 0000000000..aa5f2420b3
--- /dev/null
+++ b/catalog-ui/src/app/ng2/components/logic/policies-table/policies-table.component.ts
@@ -0,0 +1,100 @@
+/*!
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+
+
+import { Component, Input, Output, EventEmitter } from "@angular/core";
+import { PolicyInstance } from "app/models";
+import { ModalService } from "../../../services/modal.service";
+import { InstanceFeDetails } from "app/models/instance-fe-details";
+import {TranslateService} from 'app/ng2/shared/translator/translate.service';
+
+@Component({
+ selector: 'policies-table',
+ templateUrl: 'policies-table.component.html',
+ styleUrls: ['policies-table.component.less'],
+})
+export class PoliciesTableComponent {
+
+ @Input() policies: Array<PolicyInstance>;
+ @Input() instanceNamesMap: Map<string, InstanceFeDetails>;
+ @Input() readonly: boolean;
+ @Input() isLoading: boolean;
+ @Output() deletePolicy: EventEmitter<any> = new EventEmitter<any>();
+
+ sortBy: String;
+ reverse: boolean;
+ selectedPolicyToDelete: PolicyInstance;
+ deleteMsgTitle: string;
+ deleteMsgBodyTxt: string;
+ modalDeleteBtn: string;
+ modalCancelBtn: string;
+
+ sort = (sortBy) => {
+ this.reverse = (this.sortBy === sortBy) ? !this.reverse : true;
+ let reverse = this.reverse ? 1 : -1;
+ this.sortBy = sortBy;
+ let instanceNameMapTemp = this.instanceNamesMap;
+ let itemIdx1Val = "";
+ let itemIdx2Val = "";
+ this.policies.sort(function (itemIdx1, itemIdx2) {
+ if (sortBy == 'instanceUniqueId') {
+ itemIdx1Val = (itemIdx1[sortBy] && instanceNameMapTemp[itemIdx1[sortBy]] !== undefined) ? instanceNameMapTemp[itemIdx1[sortBy]].name : "";
+ itemIdx2Val = (itemIdx2[sortBy] && instanceNameMapTemp[itemIdx2[sortBy]] !== undefined) ? instanceNameMapTemp[itemIdx2[sortBy]].name : "";
+ }
+ else {
+ itemIdx1Val = itemIdx1[sortBy];
+ itemIdx2Val = itemIdx2[sortBy];
+ }
+ if (itemIdx1Val < itemIdx2Val) {
+ return -1 * reverse;
+ }
+ else if (itemIdx1Val > itemIdx2Val) {
+ return 1 * reverse;
+ }
+ else {
+ return 0;
+ }
+ });
+ };
+
+
+ constructor(private modalService: ModalService, private translateService: TranslateService) {
+ }
+
+ ngOnInit() {
+ this.translateService.languageChangedObservable.subscribe(lang => {
+ this.deleteMsgTitle = this.translateService.translate("DELETE_POLICY_TITLE");
+ this.modalDeleteBtn = this.translateService.translate("MODAL_DELETE");
+ this.modalCancelBtn = this.translateService.translate("MODAL_CANCEL");
+
+ });
+ }
+
+ onDeletePolicy = () => {
+ this.deletePolicy.emit(this.selectedPolicyToDelete);
+ this.modalService.closeCurrentModal();
+ };
+
+ openDeleteModal = (policy: PolicyInstance) => {
+ this.selectedPolicyToDelete = policy;
+ this.translateService.languageChangedObservable.subscribe(lang => {
+ this.deleteMsgBodyTxt = this.translateService.translate("DELETE_POLICY_MSG", {policyName: policy.name});
+ this.modalService.createActionModal(this.deleteMsgTitle, this.deleteMsgBodyTxt, this.modalDeleteBtn, this.onDeletePolicy, this.modalCancelBtn).instance.open();
+ });
+ }
+}
+
+
diff --git a/catalog-ui/src/app/ng2/components/logic/policies-table/policies-table.module.ts b/catalog-ui/src/app/ng2/components/logic/policies-table/policies-table.module.ts
new file mode 100644
index 0000000000..f780c62c0b
--- /dev/null
+++ b/catalog-ui/src/app/ng2/components/logic/policies-table/policies-table.module.ts
@@ -0,0 +1,41 @@
+/*!
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+
+import { NgModule } from "@angular/core";
+import {CommonModule} from "@angular/common";
+import {PoliciesTableComponent} from "./policies-table.component";
+import {TranslateModule} from 'app/ng2/shared/translator/translate.module';
+import {UiElementsModule} from "app/ng2/components/ui/ui-elements.module";
+import {GlobalPipesModule} from "../../../pipes/global-pipes.module";
+
+@NgModule({
+ declarations: [
+ PoliciesTableComponent
+ ],
+ imports: [
+ CommonModule,
+ GlobalPipesModule,
+ UiElementsModule,
+ TranslateModule
+ ],
+ exports: [PoliciesTableComponent],
+ entryComponents: [
+ PoliciesTableComponent
+ ],
+ providers: []
+})
+export class PoliciesTableModule {
+} \ No newline at end of file
diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.module.ts b/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.module.ts
index 907f7638bb..c46d617b86 100644
--- a/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.module.ts
+++ b/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.module.ts
@@ -27,6 +27,7 @@ import {GlobalPipesModule} from "../../pipes/global-pipes.module";
import {BrowserModule} from "@angular/platform-browser";
import {FilterPropertiesAssignmentComponent} from "../../components/logic/filter-properties-assignment/filter-properties-assignment.component";
import {InputsTableComponent} from "../../components/logic/inputs-table/inputs-table.component";
+import {PoliciesTableModule} from "../../components/logic/policies-table/policies-table.module";
import {PropertiesService} from "../../services/properties.service";
import {DataTypeService} from "../../services/data-type.service";
import {PropertiesAssignmentComponent} from "./properties-assignment.page.component";
@@ -48,6 +49,7 @@ import {ComponentModeService} from "../../services/component-services/component-
HttpModule,
GlobalPipesModule,
PropertyTableModule,
+ PoliciesTableModule,
UiElementsModule],
entryComponents: [PropertiesAssignmentComponent],
diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.html b/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.html
index 8a3e8d23ee..1ec6df9bc1 100644
--- a/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.html
+++ b/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.html
@@ -49,6 +49,15 @@
(inputChanged)="dataChanged($event)">
</inputs-table>
</tab>
+ <tab tabTitle="Policies">
+ <policies-table class="properties-table"
+ [readonly]="isReadonly"
+ [policies]="policies | searchFilter:'name':searchQuery"
+ [instanceNamesMap]="componentInstanceNamesMap"
+ [isLoading]="loadingPolicies"
+ (deletePolicy)="deletePolicy($event)">
+ </policies-table>
+ </tab>
</tabs>
<div class="main-tabs-section-buttons">
<button class="tlv-btn outline blue" [disabled]="!hasChangedData || savingChangedData" (click)="reverseChangedData()" data-tests-id="properties-reverse-button">Discard</button>
@@ -56,13 +65,14 @@
</div>
</div>
<div class="header">
- <div class="search-filter-container" [class.without-filter]="isInputsTabSelected">
+ <div class="search-filter-container" [class.without-filter]="isInputsTabSelected || isPoliciesTabSelected">
<span *ngIf="displayClearSearch && isPropertiesTabSelected" (click)="clickOnClearSearch()" class="clear-filter" data-tests-id="clear-filter-button">Clear All</span>
<input type="text" class="search-box" placeholder="Search" [(ngModel)]="searchQuery" data-tests-id="search-box"/>
<span class="sprite search-icon" data-tests-id="search-button"></span>
<filter-properties-assignment *ngIf="isPropertiesTabSelected" #advanceSearch class="advance-search" [componentType]="component.componentType" (searchProperties)="searchPropertiesInstances($event)"></filter-properties-assignment>
</div>
- <button class="tlv-btn blue declare-button" [disabled]="!checkedPropertiesCount || isReadonly || hasChangedData" (click)="declareProperties()" data-tests-id="declare-button">Declare</button>
+ <button class="tlv-btn blue declare-button" [disabled]="!checkedPropertiesCount || isReadonly || hasChangedData" (click)="declareProperties()" data-tests-id="declare-button declare-input">Declare Input</button>
+ <button class="tlv-btn blue declare-button" [disabled]="!checkedPropertiesCount || isReadonly || hasChangedData || isSelf()" (click)="declarePropertiesToPolicies()" data-tests-id="declare-button declare-policy">Declare Policy</button>
</div>
</div>
<div class="right-column">
@@ -75,10 +85,10 @@
<div class="hierarchy-header white-sub-header">
<span tooltip="{{component.name}}">{{component.name}}</span>
</div>
- <div *ngIf="!instancesNavigationData || instancesNavigationData.length === 0 || isInputsTabSelected">No data to display</div>
+ <div *ngIf="!instancesNavigationData || instancesNavigationData.length === 0 || isInputsTabSelected || isPoliciesTabSelected">No data to display</div>
<hierarchy-navigation class="hierarchy-nav"
(updateSelected)="onInstanceSelectedUpdate($event)"
- [displayData]="isInputsTabSelected ? []: instancesNavigationData"
+ [displayData]="isInputsTabSelected || isPoliciesTabSelected ? []: instancesNavigationData"
[selectedItem]="selectedInstanceData?.uniqueId"
[displayOptions]="hierarchyInstancesDisplayOptions"></hierarchy-navigation>
</div>
@@ -88,10 +98,10 @@
<div class="hierarchy-header white-sub-header" [class.selected]="selectedFlatProperty.path == propertyStructureHeader">
<span tooltip="{{isPropertiesTabSelected ? propertyStructureHeader : ''}}">{{isPropertiesTabSelected ? (propertyStructureHeader || "No Property Selected") : "No Property Selected"}}</span>
</div>
- <div *ngIf="!propertiesNavigationData || propertiesNavigationData.length === 0 || isInputsTabSelected">No data to display</div>
+ <div *ngIf="!propertiesNavigationData || propertiesNavigationData.length === 0 || isInputsTabSelected || isPoliciesTabSelected">No data to display</div>
<hierarchy-navigation class="hierarchy-nav"
(updateSelected)="onPropertySelectedUpdate($event)"
- [displayData]="isInputsTabSelected ? [] : propertiesNavigationData"
+ [displayData]="isInputsTabSelected || isPoliciesTabSelected ? [] : propertiesNavigationData"
[selectedItem]="selectedFlatProperty.path"
[displayOptions]="hierarchyPropertiesDisplayOptions"></hierarchy-navigation>
</div>
diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.less b/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.less
index 95ff94317c..523eda2e9f 100644
--- a/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.less
+++ b/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.less
@@ -59,11 +59,10 @@
position:absolute;
top:0;
right:0;
+ display: flex;
}
.search-filter-container{
- position: absolute;
- right: 100px;
display:flex;
flex-direction:row;
@@ -87,7 +86,7 @@
width: 14px;
height: 14px;
position: absolute;
- right:42px;
+ left:170px;
top: 8px;
}
@@ -110,9 +109,9 @@
}
.declare-button{
- position: absolute;
- top: 0;
- right: 0;
+ &:first-of-type {
+ margin-right: 10px;
+ }
}
.main-tabs-section {
diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.ts b/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.ts
index 615325559e..037b7f4963 100644
--- a/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.ts
+++ b/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.ts
@@ -61,6 +61,7 @@ export class PropertiesAssignmentComponent {
instanceFePropertiesMap:InstanceFePropertiesMap;
inputs: Array<InputFEModel> = [];
+ policies: Array<PolicyInstance> = [];
instances: Array<ComponentInstance|GroupInstance|PolicyInstance> = [];
searchQuery: string;
propertyStructureHeader: string;
@@ -76,10 +77,12 @@ export class PropertiesAssignmentComponent {
currentMainTab:Tab;
isInputsTabSelected:boolean;
isPropertiesTabSelected:boolean;
+ isPoliciesTabSelected:boolean;
isReadonly:boolean;
resourceIsReadonly:boolean;
loadingInstances:boolean = false;
loadingInputs:boolean = false;
+ loadingPolicies:boolean = false;
loadingProperties:boolean = false;
changedData:Array<PropertyFEModel|InputFEModel>;
hasChangedData:boolean;
@@ -123,6 +126,7 @@ export class PropertiesAssignmentComponent {
ngOnInit() {
console.log("==>" + this.constructor.name + ": ngOnInit");
this.loadingInputs = true;
+ this.loadingPolicies = true;
this.loadingInstances = true;
this.loadingProperties = true;
this.componentServiceNg2
@@ -139,10 +143,16 @@ export class PropertiesAssignmentComponent {
this.componentServiceNg2
.getComponentResourcePropertiesData(this.component)
.subscribe(response => {
+ this.loadingPolicies = false;
this.instances = [];
this.instances.push(...response.componentInstances);
this.instances.push(...response.groupInstances);
- this.instances.push(...response.policies);
+
+ _.forEach(response.policies, (policy: any) => {
+ const newPolicy: InputFEModel = new InputFEModel(policy);
+ this.inputsUtils.resetInputDefaultValue(newPolicy, policy.defaultValue);
+ this.policies.push(policy);
+ });
// add the service self instance to the top of the list.
const serviceInstance = new ComponentInstance();
@@ -296,6 +306,8 @@ export class PropertiesAssignmentComponent {
itemHasChanged = item.hasValueObjChanged();
} else if (this.isInputsTabSelected && item instanceof InputFEModel) {
itemHasChanged = item.hasDefaultValueChanged();
+ } else if (this.isPoliciesTabSelected && item instanceof InputFEModel) {
+ itemHasChanged = item.hasDefaultValueChanged();
}
const dataChangedIdx = this.changedData.findIndex((changedItem) => changedItem === item);
@@ -311,7 +323,7 @@ export class PropertiesAssignmentComponent {
if (this.isPropertiesTabSelected) {
this.isValidChangedData = this.changedData.every((changedItem) => (<PropertyFEModel>changedItem).valueObjIsValid);
- } else if (this.isInputsTabSelected) {
+ } else if (this.isInputsTabSelected || this.isPoliciesTabSelected) {
this.isValidChangedData = this.changedData.every((changedItem) => (<InputFEModel>changedItem).defaultValueObjIsValid);
}
this.updateHasChangedData();
@@ -385,6 +397,7 @@ export class PropertiesAssignmentComponent {
this.currentMainTab = this.propertyInputTabs.tabs.find((tab) => tab.title === event.title);
this.isPropertiesTabSelected = this.currentMainTab.title === "Properties";
this.isInputsTabSelected = this.currentMainTab.title === "Inputs";
+ this.isPoliciesTabSelected = this.currentMainTab.title === "Policies";
this.propertyStructureHeader = null;
this.searchQuery = '';
};
@@ -432,6 +445,46 @@ export class PropertiesAssignmentComponent {
}, error => {}); //ignore error
};
+ /*** DECLARE PROPERTIES/POLICIES ***/
+ declarePropertiesToPolicies = (): void => {
+ let selectedComponentInstancesProperties: InstanceBePropertiesMap = new InstanceBePropertiesMap();
+ let instancesIds = new KeysPipe().transform(this.instanceFePropertiesMap, []);
+
+ angular.forEach(instancesIds, (instanceId: string): void => {
+ let selectedInstanceData: any = this.instances.find(instance => instance.uniqueId == instanceId);
+ if (selectedInstanceData instanceof ComponentInstance) {
+ if (!this.isInput(selectedInstanceData.originType)) {
+ selectedComponentInstancesProperties[instanceId] = this.propertiesService.getCheckedProperties(this.instanceFePropertiesMap[instanceId]);
+ }
+ }
+ });
+
+ let policiesToCreate: InstancePropertiesAPIMap = new InstancePropertiesAPIMap(null, selectedComponentInstancesProperties, null, null);
+ this.loadingPolicies = true;
+
+ this.componentServiceNg2
+ .createPolicy(this.component, policiesToCreate, this.isSelf())
+ .subscribe(response => {
+ this.setPolicyTabIndication(response.length);
+ this.checkedPropertiesCount = 0;
+ this.displayPoliciesAsDeclared(response);
+ this.loadingPolicies = false;
+ }); //ignore error
+
+ };
+
+ displayPoliciesAsDeclared = (policies) => {
+ _.forEach(policies, (policy: any) => {
+ let newPolicy: InputFEModel = new InputFEModel(policy);
+ this.inputsUtils.resetInputDefaultValue(newPolicy, policy.defaultValue);
+ newPolicy.relatedPropertyName = policy.name;
+ newPolicy.relatedPropertyValue = policy.value;
+ this.updatePropertyValueAfterDeclare(newPolicy);
+ this.policies.push(policy);
+ });
+ };
+
+
saveChangedData = ():Promise<(PropertyBEModel|InputBEModel)[]> => {
return new Promise((resolve, reject) => {
if (!this.isValidChangedData) {
@@ -648,6 +701,10 @@ export class PropertiesAssignmentComponent {
this.propertyInputTabs.setTabIndication('Inputs', numInputs);
};
+ setPolicyTabIndication = (numPolicies: number): void => {
+ this.propertyInputTabs.setTabIndication('Policies', numPolicies);
+ };
+
resetUnsavedChangesForInput = (input:InputFEModel) => {
this.inputsUtils.resetInputDefaultValue(input, input.defaultValue);
this.changedData = this.changedData.filter((changedItem) => changedItem.uniqueId !== input.uniqueId);
@@ -685,6 +742,18 @@ export class PropertiesAssignmentComponent {
}, error => {}); //ignore error
};
+ deletePolicy = (policy: PolicyInstance) => {
+ this.loadingPolicies = true;
+ this.componentServiceNg2
+ .deletePolicy(this.component, policy)
+ .subscribe(response => {
+ this.policies = this.policies.filter(policy => policy.uniqueId !== response.uniqueId);
+ //Reload the whole instance for now - TODO: CHANGE THIS after the BE starts returning properties within the response, use commented code below instead!
+ this.changeSelectedInstance(this.selectedInstanceData);
+ this.loadingPolicies = false;
+ });
+ };
+
deleteProperty = (property: PropertyFEModel) => {
let propertyToDelete = new PropertyFEModel(property);
this.loadingProperties = true;
diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/services/properties.utils.ts b/catalog-ui/src/app/ng2/pages/properties-assignment/services/properties.utils.ts
index 3ed535d6a0..011be41611 100644
--- a/catalog-ui/src/app/ng2/pages/properties-assignment/services/properties.utils.ts
+++ b/catalog-ui/src/app/ng2/pages/properties-assignment/services/properties.utils.ts
@@ -67,6 +67,10 @@ export class PropertiesUtils {
this.propertiesService.disableRelatedProperties(newFEProp, inputPath);
});
}
+ if (newFEProp.getPolicyValues && newFEProp.getPolicyValues.length) {
+ newFEProp.setAsDeclared(newFEProp.inputPath); //if a path is sent, its a child prop. this param is optional
+ this.propertiesService.disableRelatedProperties(newFEProp, newFEProp.inputPath);
+ }
}
});
instanceFePropertiesMap[instanceId] = propertyFeArray;
diff --git a/catalog-ui/src/app/ng2/services/component-services/component.service.ts b/catalog-ui/src/app/ng2/services/component-services/component.service.ts
index 3243291483..fd746516b7 100644
--- a/catalog-ui/src/app/ng2/services/component-services/component.service.ts
+++ b/catalog-ui/src/app/ng2/services/component-services/component.service.ts
@@ -25,7 +25,7 @@ import 'rxjs/add/operator/map';
import 'rxjs/add/operator/toPromise';
import {Response, URLSearchParams} from '@angular/http';
import { Component, ComponentInstance, InputBEModel, InstancePropertiesAPIMap, FilterPropertiesAssignmentData,
- PropertyBEModel, OperationModel, BEOperationModel, Capability, Requirement} from "app/models";
+ PropertyBEModel, OperationModel, BEOperationModel, Capability, Requirement, PolicyInstance} from "app/models";
import {COMPONENT_FIELDS, CommonUtils, SERVICE_FIELDS} from "app/utils";
import {downgradeInjectable} from '@angular/upgrade/static';
import {ComponentGenericResponse} from "../responses/component-generic-response";
@@ -285,6 +285,30 @@ export class ComponentServiceNg2 {
})
}
+ createPolicy(component:Component, policiesToCreate:InstancePropertiesAPIMap, isSelf:boolean):Observable<any> {
+ const policiesList =
+ isSelf ?
+ {'componentPropertiesToPolicies': {
+ ...policiesToCreate.componentInstanceProperties
+ }
+ } :
+ {'componentInstancePropertiesToPolicies': {
+ ...policiesToCreate.componentInstanceProperties
+ }
+ };
+ return this.http.post(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/create/policies', policiesList)
+ .map(res => {
+ return res.json();
+ });
+ }
+
+ deletePolicy(component:Component, policy: PolicyInstance) {
+ return this.http.put(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/policies/' + policy.uniqueId + '/undeclare', policy)
+ .map(res => {
+ return res.json();
+ });
+ }
+
restoreComponent(componentType:string, componentId:string){
return this.http.post(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/restore', {})
}
diff --git a/catalog-ui/src/assets/languages/en_US.json b/catalog-ui/src/assets/languages/en_US.json
index b81dadffd9..c2a81dd82e 100644
--- a/catalog-ui/src/assets/languages/en_US.json
+++ b/catalog-ui/src/assets/languages/en_US.json
@@ -531,6 +531,10 @@
"=========== POLICY AND GROUPS ===========": "",
"ADD_TARGETS" : "Add Targets",
"ADD_MEMBERS" : "Add Members",
+ "=========== PROPERTIES ASSIGNMENT DECLARE AS POLICY ===========": "",
+ "DELETE_POLICY_TITLE": "Delete Policy",
+ "DELETE_POLICY_MSG": "Are you sure you want to delete policy '{{policyName}}'?",
+
"=========== AUTOMATED UPGRADE ===========": "",
"RESOURCE_UPGRADE_TITLE" : "Upgrade Services",
"SERVICE_UPGRADE_TITLE" : "Update Service References",
diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/api/Constants.java b/common-app-api/src/main/java/org/openecomp/sdc/common/api/Constants.java
index 0a7a105f19..b106472f4d 100644
--- a/common-app-api/src/main/java/org/openecomp/sdc/common/api/Constants.java
+++ b/common-app-api/src/main/java/org/openecomp/sdc/common/api/Constants.java
@@ -125,6 +125,7 @@ public final class Constants {
public static final String VF_LICENSE_DISPLAY_NAME = "VF License";
public static final String VF_LICENSE_DESCRIPTION = "VF license file";
public static final String GET_INPUT = "get_input";
+ public static final String GET_POLICY = "get_policy";
public static final String SERVICE_TEMPLATE_FILE_POSTFIX = "ServiceTemplate.yaml";
public static final String SERVICE_TEMPLATES_CONTAINING_FOLDER = "Definitions/";
public static final String UNBOUNDED = "unbounded";
diff --git a/common-be/pom.xml b/common-be/pom.xml
index 3ae7db22ef..c02de892b5 100644
--- a/common-be/pom.xml
+++ b/common-be/pom.xml
@@ -60,8 +60,18 @@
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.onap.sdc.common</groupId>
+ <artifactId>onap-tosca-datatype</artifactId>
+ <version>${tosca.datatype.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.projectlombok</groupId>
+ <artifactId>lombok</artifactId>
+ <version>${lombok.version}</version>
+ </dependency>
- </dependencies>
+ </dependencies>
<build>
<plugins>
<plugin>
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/GetPolicyValueDataDefinition.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/GetPolicyValueDataDefinition.java
new file mode 100644
index 0000000000..bf552741a5
--- /dev/null
+++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/GetPolicyValueDataDefinition.java
@@ -0,0 +1,17 @@
+package org.openecomp.sdc.be.datatypes.elements;
+
+import java.util.Objects;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.Setter;
+
+
+@Getter
+@Setter
+@EqualsAndHashCode
+public class GetPolicyValueDataDefinition {
+ private String policyId;
+ private String propertyName;
+ private String origPropertyValue;
+
+}
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/PolicyDataDefinition.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/PolicyDataDefinition.java
index 1e0d5935da..64efe8fd15 100644
--- a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/PolicyDataDefinition.java
+++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/PolicyDataDefinition.java
@@ -1,12 +1,10 @@
package org.openecomp.sdc.be.datatypes.elements;
-import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
-import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
+import static java.util.Collections.emptyList;
import java.util.List;
import java.util.Map;
-
-import static java.util.Collections.emptyList;
+import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
/**
* public class representing the component policy,
@@ -27,7 +25,7 @@ import static java.util.Collections.emptyList;
* targets
* isFromCsar
*/
-public class PolicyDataDefinition extends ToscaDataDefinition {
+public class PolicyDataDefinition extends PropertyDataDefinition {
/**
* public constructor by default
@@ -36,6 +34,10 @@ public class PolicyDataDefinition extends ToscaDataDefinition {
super();
}
+ public PolicyDataDefinition(PropertyDataDefinition propertyDataDefinition) {
+ super(propertyDataDefinition);
+ }
+
/**
* public constructor from superclass
*
@@ -51,6 +53,7 @@ public class PolicyDataDefinition extends ToscaDataDefinition {
* @param other
*/
public PolicyDataDefinition(PolicyDataDefinition other) {
+ super(other);
this.setName(other.getName());
this.setUniqueId(other.getUniqueId());
this.setPolicyTypeName(other.getPolicyTypeName());
@@ -63,6 +66,11 @@ public class PolicyDataDefinition extends ToscaDataDefinition {
this.setInvariantName(other.getInvariantName());
this.setComponentName(other.getComponentName());
this.setIsFromCsar(other.getIsFromCsar());
+ this.setValue(other.getValue());
+ this.setOwnerId(other.getOwnerId());
+ this.setType(other.getType());
+ this.setInstanceUniqueId(other.getInstanceUniqueId());
+ this.setInputPath(other.getInputPath());
if (other.getProperties() != null) {
this.setProperties(other.getProperties());
}
@@ -100,22 +108,6 @@ public class PolicyDataDefinition extends ToscaDataDefinition {
setToscaPresentationValue(JsonPresentationFields.CI_INVARIANT_NAME, invariantName);
}
- public String getName() {
- return (String) getToscaPresentationValue(JsonPresentationFields.NAME);
- }
-
- public void setName(String name) {
- setToscaPresentationValue(JsonPresentationFields.NAME, name);
- }
-
- public String getUniqueId() {
- return (String) getToscaPresentationValue(JsonPresentationFields.UNIQUE_ID);
- }
-
- public void setUniqueId(String uniqueId) {
- setToscaPresentationValue(JsonPresentationFields.UNIQUE_ID, uniqueId);
- }
-
public String getPolicyTypeName() {
return (String) getToscaPresentationValue(JsonPresentationFields.TYPE);
}
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/PropertyDataDefinition.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/PropertyDataDefinition.java
index 88863b2cf5..fed728dade 100644
--- a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/PropertyDataDefinition.java
+++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/PropertyDataDefinition.java
@@ -20,13 +20,18 @@
package org.openecomp.sdc.be.datatypes.elements;
+import static org.apache.commons.collections.CollectionUtils.isNotEmpty;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import org.apache.commons.collections.CollectionUtils;
import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
-import java.util.*;
-
-import static org.apache.commons.collections.CollectionUtils.isNotEmpty;
-
public class PropertyDataDefinition extends ToscaDataDefinition {
private String uniqueId;
@@ -59,8 +64,8 @@ public class PropertyDataDefinition extends ToscaDataDefinition {
private String inputId;
private String instanceUniqueId;
private String propertyId;
- private String parentPropertyType;
- private String subPropertyInputPath;
+ private String parentPropertyType;
+ private String subPropertyInputPath;
private List<Annotation> annotations;
/**
@@ -70,6 +75,8 @@ public class PropertyDataDefinition extends ToscaDataDefinition {
private List<GetInputValueDataDefinition> getInputValues;
+ private List<GetPolicyValueDataDefinition> getPolicyValues;
+
public PropertyDataDefinition() {
super();
}
@@ -97,32 +104,33 @@ public class PropertyDataDefinition extends ToscaDataDefinition {
this.setParentUniqueId(p.getParentUniqueId());
this.setOwnerId(p.getOwnerId());
this.setGetInputValues(p.getGetInputValues());
+ this.setGetPolicyValues(p.getGetPolicyValues());
this.setInputPath(p.getInputPath());
this.setStatus(p.getStatus());
this.setInputId(p.getInputId());
this.setInstanceUniqueId(p.getInstanceUniqueId());
this.setPropertyId(p.getPropertyId());
- this.setParentPropertyType(p.getParentPropertyType());
- this.setSubPropertyInputPath(p.getSubPropertyInputPath());
+ this.parentPropertyType = p.getParentPropertyType();
+ this.subPropertyInputPath = p.getSubPropertyInputPath();
if(isNotEmpty(p.annotations)){
this.setAnnotations(p.annotations);
}
}
public String getParentPropertyType() {
- return parentPropertyType;
+ return parentPropertyType;
}
public void setParentPropertyType(String parentPropertyType) {
- this.parentPropertyType = parentPropertyType;
+ this.parentPropertyType = parentPropertyType;
}
public String getSubPropertyInputPath() {
- return subPropertyInputPath;
+ return subPropertyInputPath;
}
public void setSubPropertyInputPath(String subPropertyInputPath) {
- this.subPropertyInputPath = subPropertyInputPath;
+ this.subPropertyInputPath = subPropertyInputPath;
}
public String getInputPath() {
@@ -269,6 +277,18 @@ public class PropertyDataDefinition extends ToscaDataDefinition {
this.getInputValues = getInputValues;
}
+ public List<GetPolicyValueDataDefinition> safeGetGetPolicyValues() {
+ return CollectionUtils.isEmpty(getPolicyValues) ? new ArrayList<>() : getPolicyValues;
+ }
+
+ public List<GetPolicyValueDataDefinition> getGetPolicyValues() {
+ return getPolicyValues;
+ }
+
+ public void setGetPolicyValues(List<GetPolicyValueDataDefinition> getPolicyValues) {
+ this.getPolicyValues = getPolicyValues;
+ }
+
public String getStatus() {
return status;
}
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/DeclarationTypeEnum.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/DeclarationTypeEnum.java
new file mode 100644
index 0000000000..7b78ff9893
--- /dev/null
+++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/DeclarationTypeEnum.java
@@ -0,0 +1,6 @@
+package org.openecomp.sdc.be.datatypes.enums;
+
+public enum DeclarationTypeEnum {
+ INPUT,
+ POLICY;
+}
diff --git a/pom.xml b/pom.xml
index af318f774e..fc92ae308a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,6 +31,8 @@ Modifications copyright (c) 2018 Nokia
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <tosca.datatype.version>1.3.2-SNAPSHOT</tosca.datatype.version>
+
<!-- 3rd parties versions -->
<bean-matcher.version>0.11</bean-matcher.version>
<lang3.version>3.3.2</lang3.version>
@@ -46,6 +48,7 @@ Modifications copyright (c) 2018 Nokia
<wire-mock.version>2.18.0</wire-mock.version>
<ecomp.version>2.4.0</ecomp.version>
<cassandra.unit.version>3.5.0.1</cassandra.unit.version>
+ <lombok.version>1.18.2</lombok.version>
<commons.collections.version>4.1</commons.collections.version>
@@ -58,6 +61,7 @@ Modifications copyright (c) 2018 Nokia
<!-- JSON and YAML Parsing -->
<jackson.version>2.8.10</jackson.version>
<jackson-annotations.version>2.8.0</jackson-annotations.version>
+ <jackson.mapper.version>1.9.13</jackson.mapper.version>
<!-- Yaml for properties -->
<snakeyaml.version>1.14</snakeyaml.version>
@@ -129,6 +133,8 @@ Modifications copyright (c) 2018 Nokia
<!--docker tags-->
<docker.tag>${project.version}-${maven.build.timestamp}</docker.tag>
+ <joda.time.version>2.9.9</joda.time.version>
+
</properties>