summaryrefslogtreecommitdiffstats
path: root/catalog-be
diff options
context:
space:
mode:
authortalio <tali.orenbach@amdocs.com>2019-04-14 15:37:20 +0300
committerAvi Gaffa <avi.gaffa@amdocs.com>2019-04-14 16:07:26 +0000
commitfe4afd47955705bb377583649cb53e2cf4508493 (patch)
tree335f4555155fbeb1085e7ab554ad8406a3ad68be /catalog-be
parentb08309847c24bd3c060839a335a20cb3f750ed30 (diff)
Declare properties as policies
Change-Id: I54dc7b444e08117097c314cf5f51bd356ac5287d Issue-ID: SDC-2240 Signed-off-by: talio <tali.orenbach@amdocs.com>
Diffstat (limited to 'catalog-be')
-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
32 files changed, 2133 insertions, 641 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);