From 7f5501ed9e9807a4e5a17c06dd9b5989cced11aa Mon Sep 17 00:00:00 2001 From: aribeiro Date: Fri, 4 Sep 2020 13:31:21 +0100 Subject: Make directives options configurable backend Issue-ID: SDC-3277 Signed-off-by: aribeiro Change-Id: I51ece01c0b0deb93cc7ab79ce8dcb9e1c5503074 --- .../impl/ComponentInstanceBusinessLogic.java | 7 +-- .../be/components/impl/utils/DirectivesEnum.java | 51 ------------------ .../be/components/impl/utils/DirectivesUtil.java | 46 ++++++++++++++++ .../impl/ComponentNodeFilterBusinessLogicTest.java | 5 +- ...mponentSubstitutionFilterBusinessLogicTest.java | 7 +-- .../components/impl/utils/DirectivesEnumTest.java | 61 --------------------- .../components/impl/utils/DirectivesUtilTest.java | 62 ++++++++++++++++++++++ .../be/nodeFilter/BaseServiceFilterUtilsTest.java | 12 +++-- 8 files changed, 127 insertions(+), 124 deletions(-) delete mode 100644 catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/DirectivesEnum.java create mode 100644 catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/DirectivesUtil.java delete mode 100644 catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/DirectivesEnumTest.java create mode 100644 catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/DirectivesUtilTest.java 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 236db5fe40..e7d8dd56f5 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 @@ -49,7 +49,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.DirectivesEnum; +import org.openecomp.sdc.be.components.impl.utils.DirectivesUtil; 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; @@ -991,14 +991,15 @@ 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(!DirectivesEnum.isValid(componentInstance.getDirectives())) { + if(!DirectivesUtil.isValid(componentInstance.getDirectives())) { final String directivesStr = componentInstance.getDirectives().stream().collect(Collectors.joining(" , ", " [ ", " ] ")); CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to update the directives of the component instance {} to {}. Directives data {} is invalid. ", oldComponentInstance.getName(), newInstanceName , directivesStr); - throw new ByActionStatusComponentException(ActionStatus.DIRECTIVES_INVALID_VALUE, containerComponentType.getValue(), componentInstance.getName()); } + throw new ByActionStatusComponentException(ActionStatus.DIRECTIVES_INVALID_VALUE, containerComponentType.getValue(), componentInstance.getName()); + } updateRes = toscaOperationFacade.updateComponentInstanceMetadataOfTopologyTemplate(containerComponent, origComponent, updateComponentInstanceMetadata(oldComponentInstance, componentInstance)); if (updateRes.isRight()) { CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to update metadata of component instance {} belonging to container component {}. Status is {}. ", componentInstance.getName(), containerComponent.getName(), 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 deleted file mode 100644 index e312504a2a..0000000000 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/DirectivesEnum.java +++ /dev/null @@ -1,51 +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 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 getDirective(final String directiveValue) { - return Arrays.stream(values()) - .filter(directivesEnum -> directivesEnum.getValue().equals(directiveValue)) - .findFirst(); - } - - public static boolean isValid(final List 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/DirectivesUtil.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/DirectivesUtil.java new file mode 100644 index 0000000000..eb7e6baaf3 --- /dev/null +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/DirectivesUtil.java @@ -0,0 +1,46 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.be.components.impl.utils; + +import java.util.List; +import java.util.Optional; +import org.apache.commons.collections.CollectionUtils; +import org.openecomp.sdc.be.config.ConfigurationManager; + +public class DirectivesUtil { + + private static Optional getDirective(final String directiveValue) { + final List directives = ConfigurationManager.getConfigurationManager().getConfiguration().getDirectives(); + if (CollectionUtils.isNotEmpty(directives)) { + return directives.stream() + .filter(directiveValues -> directiveValues.equalsIgnoreCase(directiveValue)) + .findFirst(); + } + return Optional.empty(); + } + + public static boolean isValid(final List inDirectives) { + if (CollectionUtils.isEmpty(inDirectives)) { + return true; + } + return inDirectives.stream().allMatch(directive -> getDirective(directive).isPresent()); + } + +} diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogicTest.java index 5867c4d199..be9dd1689a 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogicTest.java @@ -49,10 +49,10 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.mockito.junit.jupiter.MockitoExtension; import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException; -import org.openecomp.sdc.be.components.impl.utils.DirectivesEnum; import org.openecomp.sdc.be.components.impl.utils.NodeFilterConstraintAction; import org.openecomp.sdc.be.components.validation.NodeFilterValidator; import org.openecomp.sdc.be.components.validation.UserValidations; +import org.openecomp.sdc.be.config.ConfigurationManager; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao; import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; @@ -552,7 +552,8 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock componentInstance = new ComponentInstance(); componentInstance.setUniqueId(componentInstanceId); componentInstance.setName("myComponentInstance"); - componentInstance.setDirectives(new LinkedList<>(Arrays.asList(DirectivesEnum.SELECT.getValue()))); + componentInstance.setDirectives(ConfigurationManager.getConfigurationManager().getConfiguration() + .getDirectives()); final UIConstraint uiConstraint = new UIConstraint(servicePropertyName, constraintOperator, sourceType, sourceName, propertyValue); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentSubstitutionFilterBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentSubstitutionFilterBusinessLogicTest.java index 6031416dbb..eaeb5ea11a 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentSubstitutionFilterBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentSubstitutionFilterBusinessLogicTest.java @@ -48,10 +48,10 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.mockito.junit.jupiter.MockitoExtension; import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException; -import org.openecomp.sdc.be.components.impl.utils.DirectivesEnum; import org.openecomp.sdc.be.components.impl.utils.NodeFilterConstraintAction; import org.openecomp.sdc.be.components.validation.NodeFilterValidator; import org.openecomp.sdc.be.components.validation.UserValidations; +import org.openecomp.sdc.be.config.ConfigurationManager; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao; import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; @@ -439,7 +439,8 @@ public class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLo componentInstance = new ComponentInstance(); componentInstance.setUniqueId(componentInstanceId); componentInstance.setName("myComponentInstance"); - componentInstance.setDirectives(new LinkedList<>(Arrays.asList(DirectivesEnum.SUBSTITUTE.getValue()))); + componentInstance.setDirectives(ConfigurationManager.getConfigurationManager().getConfiguration() + .getDirectives()); final UIConstraint uiConstraint = new UIConstraint(servicePropertyName, constraintOperator, sourceType, sourceName, propertyValue); @@ -479,4 +480,4 @@ public class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLo fail(e.getMessage()); } } -} \ No newline at end of file +} diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/DirectivesEnumTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/DirectivesEnumTest.java deleted file mode 100644 index 529625b451..0000000000 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/DirectivesEnumTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * - - * * ============LICENSE_START======================================================= - * * Copyright (C) 2019 Nordix Foundation. - * * ================================================================================ - * * 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. - * * - * * SPDX-License-Identifier: Apache-2.0 - * * ============LICENSE_END========================================================= - * - */ - -package org.openecomp.sdc.be.components.impl.utils; - -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; - -public class DirectivesEnumTest { - - private List directives; - - @Before - public void setup() { - directives = new ArrayList<>(); - } - - @Test - 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(DirectivesEnum.isValid(directives)); - } - - @Test - public void testGivenInvalidDirectives_returnsFalse() { - directives.add("Invalid"); - assertFalse(DirectivesEnum.isValid(directives)); - } -} \ No newline at end of file diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/DirectivesUtilTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/DirectivesUtilTest.java new file mode 100644 index 0000000000..412b62cb0a --- /dev/null +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/DirectivesUtilTest.java @@ -0,0 +1,62 @@ +/* + * - + * * ============LICENSE_START======================================================= + * * Copyright (C) 2019 Nordix Foundation. + * * ================================================================================ + * * 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. + * * + * * SPDX-License-Identifier: Apache-2.0 + * * ============LICENSE_END========================================================= + * + */ + +package org.openecomp.sdc.be.components.impl.utils; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import org.junit.Before; +import org.junit.Test; +import org.openecomp.sdc.be.config.ConfigurationManager; +import org.openecomp.sdc.common.impl.ExternalConfiguration; +import org.openecomp.sdc.common.impl.FSConfigurationSource; + +public class DirectivesUtilTest { + + @Before + public void setup() { + new ConfigurationManager(new FSConfigurationSource( + ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be")); + } + + @Test + public void testGivenValidDirectives_returnsTrue() { + assertTrue(DirectivesUtil.isValid(ConfigurationManager.getConfigurationManager().getConfiguration() + .getDirectives())); + } + + @Test + public void testGivenEmptyDirectives_returnsTrue() { + assertTrue(DirectivesUtil.isValid(Collections.emptyList())); + } + + @Test + public void testGivenInvalidDirectives_returnsFalse() { + final List directives = new ArrayList<>(); + directives.add("invalidValue"); + assertFalse(DirectivesUtil.isValid(directives)); + } +} 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 adf6e4439d..68ceaca0a6 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 @@ -16,17 +16,18 @@ package org.openecomp.sdc.be.nodeFilter; +import java.util.Arrays; import org.junit.Assert; import org.junit.Before; -import org.openecomp.sdc.be.components.impl.utils.DirectivesEnum; +import org.openecomp.sdc.be.config.ConfigurationManager; import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition; import org.openecomp.sdc.be.datatypes.elements.RequirementNodeFilterPropertyDataDefinition; import org.openecomp.sdc.be.model.ComponentInstance; import org.openecomp.sdc.be.model.PropertyDefinition; import org.openecomp.sdc.be.model.Service; - -import java.util.Arrays; +import org.openecomp.sdc.common.impl.ExternalConfiguration; +import org.openecomp.sdc.common.impl.FSConfigurationSource; public class BaseServiceFilterUtilsTest { @@ -41,12 +42,15 @@ public class BaseServiceFilterUtilsTest { @Before public void initService() { try { + new ConfigurationManager(new FSConfigurationSource( + ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be")); service = new Service(); ComponentInstance componentInstance = new ComponentInstance(); componentInstance.setUniqueId(CI_NAME); componentInstance.setName(CI_NAME); service.setComponentInstances(Arrays.asList(componentInstance)); - componentInstance.setDirectives(Arrays.asList(DirectivesEnum.SELECTABLE.getValue())); + componentInstance.setDirectives(ConfigurationManager.getConfigurationManager().getConfiguration() + .getDirectives()); CINodeFilterDataDefinition serviceFilter = new CINodeFilterDataDefinition(); componentInstance.setNodeFilter(serviceFilter); requirementNodeFilterPropertyDataDefinition = new RequirementNodeFilterPropertyDataDefinition(); -- cgit 1.2.3-korg