diff options
Diffstat (limited to 'catalog-be/src/main/java/org/openecomp/sdc/be/components/property/ComponentInstanceInputPropertyDeclarator.java')
-rw-r--r-- | catalog-be/src/main/java/org/openecomp/sdc/be/components/property/ComponentInstanceInputPropertyDeclarator.java | 62 |
1 files changed, 35 insertions, 27 deletions
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 c7d9cfb841..40a6223bd0 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 @@ -7,9 +7,9 @@ * 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. @@ -17,10 +17,17 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - 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; @@ -37,15 +44,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.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Optional; - -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> { @@ -54,7 +52,9 @@ public class ComponentInstanceInputPropertyDeclarator extends DefaultPropertyDec private final ComponentInstanceBusinessLogic componentInstanceBusinessLogic; private final ExceptionUtils exceptionUtils; - public ComponentInstanceInputPropertyDeclarator(ComponentsUtils componentsUtils, PropertyOperation propertyOperation, ToscaOperationFacade toscaOperationFacade, ComponentInstanceBusinessLogic componentInstanceBusinessLogic, ExceptionUtils exceptionUtils) { + public ComponentInstanceInputPropertyDeclarator(ComponentsUtils componentsUtils, PropertyOperation propertyOperation, + ToscaOperationFacade toscaOperationFacade, + ComponentInstanceBusinessLogic componentInstanceBusinessLogic, ExceptionUtils exceptionUtils) { super(componentsUtils, propertyOperation); this.toscaOperationFacade = toscaOperationFacade; this.componentInstanceBusinessLogic = componentInstanceBusinessLogic; @@ -67,8 +67,10 @@ public class ComponentInstanceInputPropertyDeclarator extends DefaultPropertyDec } @Override - 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()); + 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); } @@ -82,7 +84,7 @@ public class ComponentInstanceInputPropertyDeclarator extends DefaultPropertyDec @Override public void addPropertiesListToInput(ComponentInstanceInput declaredProp, InputDefinition input) { List<ComponentInstanceInput> inputsValueList = input.getInputs(); - if(inputsValueList == null) { + if (inputsValueList == null) { inputsValueList = new ArrayList<>(); // adding the property with the new value for UI } inputsValueList.add(declaredProp); @@ -91,26 +93,33 @@ public class ComponentInstanceInputPropertyDeclarator extends DefaultPropertyDec @Override public StorageOperationStatus unDeclarePropertiesAsInputs(Component component, InputDefinition input) { - List<ComponentInstanceInput> componentInstanceInputsByInputId = componentInstanceBusinessLogic.getComponentInstanceInputsByInputId(component, input.getUniqueId()); + List<ComponentInstanceInput> componentInstanceInputsByInputId = componentInstanceBusinessLogic + .getComponentInstanceInputsByInputId(component, input.getUniqueId()); if (isEmpty(componentInstanceInputsByInputId)) { return StorageOperationStatus.OK; } - componentInstanceInputsByInputId.forEach(cmptInstanceInput -> prepareValueBeforeDelete(input, cmptInstanceInput, cmptInstanceInput.getPath())); - return toscaOperationFacade.updateComponentInstanceInputs(component, componentInstanceInputsByInputId.get(0).getComponentInstanceId(), componentInstanceInputsByInputId); + componentInstanceInputsByInputId + .forEach(cmptInstanceInput -> prepareValueBeforeDelete(input, cmptInstanceInput, cmptInstanceInput.getPath())); + return toscaOperationFacade.updateComponentInstanceInputs(component, componentInstanceInputsByInputId.get(0).getComponentInstanceId(), + componentInstanceInputsByInputId); } @Override public StorageOperationStatus unDeclarePropertiesAsListInputs(Component component, InputDefinition input) { - List<ComponentInstanceInput> componentInstanceInputsByInputId = componentInstanceBusinessLogic.getComponentInstanceInputsByInputId(component, input.getUniqueId()); + List<ComponentInstanceInput> componentInstanceInputsByInputId = componentInstanceBusinessLogic + .getComponentInstanceInputsByInputId(component, input.getUniqueId()); if (isEmpty(componentInstanceInputsByInputId)) { return StorageOperationStatus.OK; } - componentInstanceInputsByInputId.forEach(cmptInstanceInput -> prepareValueBeforeDelete(input, cmptInstanceInput, cmptInstanceInput.getPath())); - return toscaOperationFacade.updateComponentInstanceInputs(component, componentInstanceInputsByInputId.get(0).getComponentInstanceId(), componentInstanceInputsByInputId); + componentInstanceInputsByInputId + .forEach(cmptInstanceInput -> prepareValueBeforeDelete(input, cmptInstanceInput, cmptInstanceInput.getPath())); + return toscaOperationFacade.updateComponentInstanceInputs(component, componentInstanceInputsByInputId.get(0).getComponentInstanceId(), + componentInstanceInputsByInputId); } @Override - InputDefinition createInputFromProperty(String componentId, ComponentInstance propertiesOwner, String inputName, ComponentInstancePropInput propInput, PropertyDataDefinition prop) { + InputDefinition createInputFromProperty(String componentId, ComponentInstance propertiesOwner, String inputName, + ComponentInstancePropInput propInput, PropertyDataDefinition prop) { InputDefinition inputFromProperty = super.createInputFromProperty(componentId, propertiesOwner, inputName, propInput, prop); Component propertiesOwnerNodeType = getInstanceOriginType(propertiesOwner); enrichInputWithAnnotations(prop, inputFromProperty, propertiesOwnerNodeType); @@ -119,15 +128,14 @@ public class ComponentInstanceInputPropertyDeclarator extends DefaultPropertyDec private void enrichInputWithAnnotations(PropertyDataDefinition prop, InputDefinition inputFromProperty, Component propertiesOwnerNodeType) { List<Annotation> inputAnnotations = getInputAnnotations(propertiesOwnerNodeType, prop.getName()); - if(!isEmpty(inputAnnotations)){ + if (!isEmpty(inputAnnotations)) { inputFromProperty.setAnnotations(inputAnnotations); } } private Component getInstanceOriginType(ComponentInstance propertiesOwner) { - return toscaOperationFacade.getToscaElement(propertiesOwner.getActualComponentUid(), getFilterComponentInputs()) - .left() - .on(err -> exceptionUtils.rollBackAndThrow(err, propertiesOwner.getActualComponentUid())); + return toscaOperationFacade.getToscaElement(propertiesOwner.getActualComponentUid(), getFilterComponentInputs()).left() + .on(err -> exceptionUtils.rollBackAndThrow(err, propertiesOwner.getActualComponentUid())); } private ComponentParametersView getFilterComponentInputs() { |