aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be
diff options
context:
space:
mode:
authoraribeiro <anderson.ribeiro@est.tech>2020-05-20 10:05:48 +0100
committerOfir Sonsino <ofir.sonsino@intl.att.com>2020-06-08 06:56:36 +0000
commit966271e4e2601d58eb06f286a3b2921e803fa9af (patch)
tree01752d24145128fa3687e91e21e58fd6fabe6276 /catalog-be
parent116c26e1c243f26258558148e9f69e42b3787367 (diff)
Make Directive values Tosca compliant
Issue-ID: SDC-3079 Signed-off-by: aribeiro <anderson.ribeiro@est.tech> Change-Id: Ie711c61244a4e2d68a96e2814ba2db52e067c6e4
Diffstat (limited to 'catalog-be')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java46
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/DirectivesEnum.java51
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/DirectivesUtils.java63
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/impl/ServiceFilterUtils.java22
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInstanceServlet.java59
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/DirectivesEnumTest.java (renamed from catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/DirectivesUtilsTest.java)31
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/BaseServiceFilterUtilsTest.java4
7 files changed, 128 insertions, 148 deletions
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 e943af8519..486a6b2a35 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
@@ -20,8 +20,26 @@
package org.openecomp.sdc.be.components.impl;
+import static org.openecomp.sdc.be.components.property.GetInputUtils.isGetInputValueForInput;
+import static org.openecomp.sdc.be.components.utils.PropertiesUtils.getPropertyCapabilityOfChildInstance;
+
import com.google.common.collect.Sets;
import fj.data.Either;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.UUID;
+import java.util.function.BiConsumer;
+import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
@@ -30,7 +48,7 @@ import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentEx
import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.impl.instance.ComponentInstanceChangeOperationOrchestrator;
-import org.openecomp.sdc.be.components.impl.utils.DirectivesUtils;
+import org.openecomp.sdc.be.components.impl.utils.DirectivesEnum;
import org.openecomp.sdc.be.components.merge.instance.ComponentInstanceMergeDataBusinessLogic;
import org.openecomp.sdc.be.components.merge.instance.DataForMergeHolder;
import org.openecomp.sdc.be.components.utils.PropertiesUtils;
@@ -109,25 +127,6 @@ import org.openecomp.sdc.common.util.ValidationUtils;
import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.beans.factory.annotation.Autowired;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.Set;
-import java.util.UUID;
-import java.util.function.BiConsumer;
-import java.util.stream.Collectors;
-
-import static org.openecomp.sdc.be.components.property.GetInputUtils.isGetInputValueForInput;
-import static org.openecomp.sdc.be.components.utils.PropertiesUtils.getPropertyCapabilityOfChildInstance;
-
@org.springframework.stereotype.Component
public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
@@ -943,7 +942,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to update the name of the component instance {} to {}. A component instance with the same name already exists. ", oldComponentInstance.getName(), newInstanceName);
throw new ByActionStatusComponentException(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, containerComponentType.getValue(), componentInstance.getName());
}
- if(!DirectivesUtils.isValid(componentInstance.getDirectives())) {
+ if(!DirectivesEnum.isValid(componentInstance.getDirectives())) {
final String directivesStr =
componentInstance.getDirectives().stream().collect(Collectors.joining(" , ", " [ ", " ] "));
CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG,
@@ -1124,9 +1123,8 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
}
ComponentInstance ci = componentInstanceById.get();
- List<String> directives = ci.getDirectives();
- directives.remove(DirectivesUtils.SELECTABLE);
- ci.setDirectives(directives);
+ ci.setDirectives(Collections.emptyList());
+
final Either<ComponentInstance, ResponseFormat> componentInstanceResponseFormatEither =
updateComponentInstanceMetadata(ComponentTypeEnum.SERVICE_PARAM_NAME, service.getUniqueId(),
ci.getUniqueId(), userId, ci, true, false);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/DirectivesEnum.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/DirectivesEnum.java
new file mode 100644
index 0000000000..e312504a2a
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/DirectivesEnum.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openecomp.sdc.be.components.impl.utils;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Optional;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import org.apache.commons.collections.CollectionUtils;
+
+@AllArgsConstructor
+@Getter
+public enum DirectivesEnum {
+
+ SELECT("select"),
+ SELECTABLE("selectable"),
+ SUBSTITUTE("substitute"),
+ SUBSTITUTABLE("substitutable");
+
+ private final String value;
+
+ public static Optional<DirectivesEnum> getDirective(final String directiveValue) {
+ return Arrays.stream(values())
+ .filter(directivesEnum -> directivesEnum.getValue().equals(directiveValue))
+ .findFirst();
+ }
+
+ public static boolean isValid(final List<String> inDirectives) {
+ if (CollectionUtils.isEmpty(inDirectives)) {
+ return true;
+ }
+
+ return inDirectives.stream().allMatch(directive -> getDirective(directive).isPresent());
+ }
+
+} \ No newline at end of file
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/DirectivesUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/DirectivesUtils.java
deleted file mode 100644
index 900e961359..0000000000
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/DirectivesUtils.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright © 2016-2018 European Support Limited
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.openecomp.sdc.be.components.impl.utils;
-
-import com.google.common.collect.Sets;
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.lang.StringUtils;
-
-import java.util.List;
-import java.util.Optional;
-
-public class DirectivesUtils {
-
- public static final String SUBSTITUTABLE = "substitutable";
- public static final String SELECTABLE = "selectable";
- public enum DIRECTIVE {
-
- SUBSTITUTABLE(DirectivesUtils.SUBSTITUTABLE), SELECTABLE(DirectivesUtils.SELECTABLE);
-
- private final String value;
-
- DIRECTIVE(String value) {
- this.value = value;
- }
-
- @Override
- public String toString() {
- return value;
- }
-
- }
-
- public static Optional<DIRECTIVE> getDirective(String inDirective) {
- if (StringUtils.isEmpty(inDirective)) {
- return Optional.empty();
- }
-
- return Sets.newHashSet(DIRECTIVE.values()).stream()
- .filter(directive -> directive.toString().equals(inDirective)).findAny();
- }
-
- public static boolean isValid(List<String> inDirectives){
- if (CollectionUtils.isEmpty(inDirectives)){
- return true;
- }
- return inDirectives.stream().allMatch(directive -> getDirective(directive).isPresent());
- }
-
-}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ServiceFilterUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ServiceFilterUtils.java
index 4485db1a50..e6d7df62cc 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ServiceFilterUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ServiceFilterUtils.java
@@ -16,8 +16,13 @@
package org.openecomp.sdc.be.impl;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import org.apache.commons.collections.CollectionUtils;
import org.javatuples.Pair;
-import org.openecomp.sdc.be.components.impl.utils.DirectivesUtils;
import org.openecomp.sdc.be.datamodel.utils.ConstraintConvertor;
import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.RequirementNodeFilterPropertyDataDefinition;
@@ -26,12 +31,6 @@ import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.ui.model.UIConstraint;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.function.Function;
-import java.util.stream.Collectors;
-
public class ServiceFilterUtils {
@@ -46,8 +45,7 @@ public class ServiceFilterUtils {
private static boolean propertyIsUsedInCI(ComponentInstance ci, String ciName, String propertyName) {
- final List<String> directives = ci.getDirectives();
- if (!directives.contains(DirectivesUtils.SELECTABLE)) {
+ if (CollectionUtils.isEmpty(ci.getDirectives())) {
return false;
}
if (ci.getNodeFilter() == null || ci.getNodeFilter().getProperties() == null
@@ -114,8 +112,7 @@ public class ServiceFilterUtils {
private static boolean isNodeFilterUsingChangedCi(ComponentInstance ci, String name) {
- final List<String> directives = ci.getDirectives();
- if (!directives.contains(DirectivesUtils.SELECTABLE)) {
+ if (CollectionUtils.isEmpty(ci.getDirectives())) {
return false;
}
if (ci.getNodeFilter() == null || ci.getNodeFilter().getProperties() == null
@@ -152,8 +149,7 @@ public class ServiceFilterUtils {
}
private static boolean isNodeFilterUsingChangedInput(ComponentInstance ci, InputDefinition changedInput) {
- final List<String> directives = ci.getDirectives();
- if (!directives.contains(DirectivesUtils.SELECTABLE)) {
+ if (CollectionUtils.isEmpty(ci.getDirectives())) {
return false;
}
return ci.getNodeFilter().getProperties().getListToscaDataDefinition().stream()
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInstanceServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInstanceServlet.java
index a8d3bc0670..d8580e86f6 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInstanceServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInstanceServlet.java
@@ -38,6 +38,30 @@ import io.swagger.v3.oas.annotations.servers.Server;
import io.swagger.v3.oas.annotations.servers.Servers;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.tags.Tags;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import javax.inject.Inject;
+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.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
@@ -48,7 +72,6 @@ import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
-import org.openecomp.sdc.be.components.impl.utils.DirectivesUtils;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datamodel.ForwardingPaths;
@@ -78,30 +101,6 @@ import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.stereotype.Controller;
-import javax.inject.Inject;
-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.QueryParam;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import java.io.IOException;
-import java.io.InputStream;
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
/**
* Root resource (exposed at "/" path) .json
*/
@@ -249,19 +248,17 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet {
}
ComponentInstance resultValue = actionResponse.left().value();
if (componentTypeEnum.equals(ComponentTypeEnum.SERVICE)){
- boolean shouldCreateServiceFilter = resourceInstance.getDirectives() != null && resourceInstance.getDirectives().contains(
- DirectivesUtils.SELECTABLE);
-
- if(shouldCreateServiceFilter) {
+ if(CollectionUtils.isNotEmpty(resourceInstance.getDirectives())) {
Either<CINodeFilterDataDefinition, ResponseFormat> either =
- serviceBusinessLogic.createIfNotAlreadyExistServiceFilter(componentId, componentInstanceId, userId,
- true);
+ serviceBusinessLogic.createIfNotAlreadyExistServiceFilter(componentId, componentInstanceId, userId,
+ true);
if (either.isRight()){
BeEcompErrorManager.getInstance().logBeSystemError("Resource Instance - updateResourceInstance Failed to create service filter.");
log.debug("Failed to create service filter.");
return buildErrorResponse(convertResponse.right().value());
}
resultValue.setNodeFilter(either.left().value());
+
} else {
Either<String, ResponseFormat> either = serviceBusinessLogic.deleteIfNotAlreadyDeletedServiceFilter(componentId, componentInstanceId, userId,true);
if (either.isRight()){
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/DirectivesUtilsTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/DirectivesEnumTest.java
index 9e27134a33..529625b451 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/DirectivesUtilsTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/DirectivesEnumTest.java
@@ -22,39 +22,40 @@
package org.openecomp.sdc.be.components.impl.utils;
-import org.junit.Before;
-import org.junit.Test;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
+import org.junit.Before;
+import org.junit.Test;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-public class DirectivesUtilsTest {
+public class DirectivesEnumTest {
private List<String> directives;
@Before
- public void setup(){
+ public void setup() {
directives = new ArrayList<>();
}
@Test
- public void testGivenValidDirectives_returnsTrue(){
- directives.add(DirectivesUtils.DIRECTIVE.SUBSTITUTABLE.toString());
- directives.add(DirectivesUtils.DIRECTIVE.SELECTABLE.toString());
- assertTrue(DirectivesUtils.isValid(directives));
+ public void testGivenValidDirectives_returnsTrue() {
+ directives.add(DirectivesEnum.SELECT.getValue());
+ directives.add(DirectivesEnum.SELECTABLE.getValue());
+ directives.add(DirectivesEnum.SUBSTITUTE.getValue());
+ directives.add(DirectivesEnum.SUBSTITUTABLE.getValue());
+ assertTrue(DirectivesEnum.isValid(directives));
}
@Test
- public void testGivenEmptyDirectives_returnsTrue(){
- assertTrue(DirectivesUtils.isValid(directives));
+ public void testGivenEmptyDirectives_returnsTrue() {
+ assertTrue(DirectivesEnum.isValid(directives));
}
@Test
- public void testGivenInvalidDirectives_returnsFalse(){
+ public void testGivenInvalidDirectives_returnsFalse() {
directives.add("Invalid");
- assertFalse(DirectivesUtils.isValid(directives));
+ assertFalse(DirectivesEnum.isValid(directives));
}
} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/BaseServiceFilterUtilsTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/BaseServiceFilterUtilsTest.java
index 8ddf06abb8..adf6e4439d 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/BaseServiceFilterUtilsTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/BaseServiceFilterUtilsTest.java
@@ -18,7 +18,7 @@ package org.openecomp.sdc.be.nodeFilter;
import org.junit.Assert;
import org.junit.Before;
-import org.openecomp.sdc.be.components.impl.utils.DirectivesUtils;
+import org.openecomp.sdc.be.components.impl.utils.DirectivesEnum;
import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.RequirementNodeFilterPropertyDataDefinition;
@@ -46,7 +46,7 @@ public class BaseServiceFilterUtilsTest {
componentInstance.setUniqueId(CI_NAME);
componentInstance.setName(CI_NAME);
service.setComponentInstances(Arrays.asList(componentInstance));
- componentInstance.setDirectives(Arrays.asList(DirectivesUtils.SELECTABLE));
+ componentInstance.setDirectives(Arrays.asList(DirectivesEnum.SELECTABLE.getValue()));
CINodeFilterDataDefinition serviceFilter = new CINodeFilterDataDefinition();
componentInstance.setNodeFilter(serviceFilter);
requirementNodeFilterPropertyDataDefinition = new RequirementNodeFilterPropertyDataDefinition();