diff options
author | aribeiro <anderson.ribeiro@est.tech> | 2020-09-04 13:31:21 +0100 |
---|---|---|
committer | Julien Bertozzi <julien.bertozzi@intl.att.com> | 2020-09-07 17:59:49 +0000 |
commit | 7f5501ed9e9807a4e5a17c06dd9b5989cced11aa (patch) | |
tree | 739ff4525b7e48ea3148b3b60331792178a13968 /catalog-be/src/main/java/org | |
parent | 2c47b29930ee129c7a332b4339c36daf3b98cc18 (diff) |
Make directives options configurable backend
Issue-ID: SDC-3277
Signed-off-by: aribeiro <anderson.ribeiro@est.tech>
Change-Id: I51ece01c0b0deb93cc7ab79ce8dcb9e1c5503074
Diffstat (limited to 'catalog-be/src/main/java/org')
3 files changed, 50 insertions, 54 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 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<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/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<String> getDirective(final String directiveValue) { + final List<String> 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<String> inDirectives) { + if (CollectionUtils.isEmpty(inDirectives)) { + return true; + } + return inDirectives.stream().allMatch(directive -> getDirective(directive).isPresent()); + } + +} |