diff options
Diffstat (limited to 'catalog-be/src/main/java/org/openecomp/sdc/be/components/property/ComponentInstancePropertyDeclarator.java')
-rw-r--r-- | catalog-be/src/main/java/org/openecomp/sdc/be/components/property/ComponentInstancePropertyDeclarator.java | 74 |
1 files changed, 38 insertions, 36 deletions
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 1d8a23ec55..3c5ca44b33 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 @@ -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,14 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - 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.components.utils.PropertiesUtils; @@ -36,12 +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.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Optional; - @org.springframework.stereotype.Component public class ComponentInstancePropertyDeclarator extends DefaultPropertyDeclarator<ComponentInstance, ComponentInstanceProperty> { @@ -49,7 +47,9 @@ public class ComponentInstancePropertyDeclarator extends DefaultPropertyDeclarat private ToscaOperationFacade toscaOperationFacade; private ComponentInstanceBusinessLogic componentInstanceBusinessLogic; - public ComponentInstancePropertyDeclarator(ComponentsUtils componentsUtils, PropertyOperation propertyOperation, ToscaOperationFacade toscaOperationFacade, ComponentInstanceBusinessLogic componentInstanceBusinessLogic) { + public ComponentInstancePropertyDeclarator(ComponentsUtils componentsUtils, PropertyOperation propertyOperation, + ToscaOperationFacade toscaOperationFacade, + ComponentInstanceBusinessLogic componentInstanceBusinessLogic) { super(componentsUtils, propertyOperation); this.toscaOperationFacade = toscaOperationFacade; this.componentInstanceBusinessLogic = componentInstanceBusinessLogic; @@ -61,8 +61,10 @@ public class ComponentInstancePropertyDeclarator extends DefaultPropertyDeclarat } @Override - 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()); + 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); } @@ -76,7 +78,7 @@ public class ComponentInstancePropertyDeclarator extends DefaultPropertyDeclarat @Override public void addPropertiesListToInput(ComponentInstanceProperty declaredProp, InputDefinition input) { List<ComponentInstanceProperty> propertiesList = input.getProperties(); - if(propertiesList == null) { + if (propertiesList == null) { propertiesList = new ArrayList<>(); // adding the property with the new value for UI } propertiesList.add(declaredProp); @@ -85,44 +87,44 @@ public class ComponentInstancePropertyDeclarator extends DefaultPropertyDeclarat @Override public StorageOperationStatus unDeclarePropertiesAsInputs(Component component, InputDefinition input) { - - Optional<ComponentInstanceProperty> propertyByInputId = PropertiesUtils.getPropertyByInputId(component, - input.getUniqueId()); - if(propertyByInputId.isPresent()) { - List<ComponentInstanceProperty> capabilityPropertyDeclaredAsInput = - PropertiesUtils.getCapabilityProperty(propertyByInputId.get(), input.getUniqueId()); - capabilityPropertyDeclaredAsInput.forEach(cmptInstanceProperty -> prepareValueBeforeDeleteOfCapProp(input, - cmptInstanceProperty)); - - Optional<CapabilityDefinition> propertyCapabilityOptional = PropertiesUtils.getPropertyCapabilityOfChildInstance( - capabilityPropertyDeclaredAsInput.get(0).getParentUniqueId(), component.getCapabilities()); - if(!propertyCapabilityOptional.isPresent()) { + Optional<ComponentInstanceProperty> propertyByInputId = PropertiesUtils.getPropertyByInputId(component, input.getUniqueId()); + if (propertyByInputId.isPresent()) { + List<ComponentInstanceProperty> capabilityPropertyDeclaredAsInput = PropertiesUtils + .getCapabilityProperty(propertyByInputId.get(), input.getUniqueId()); + capabilityPropertyDeclaredAsInput.forEach(cmptInstanceProperty -> prepareValueBeforeDeleteOfCapProp(input, cmptInstanceProperty)); + Optional<CapabilityDefinition> propertyCapabilityOptional = PropertiesUtils + .getPropertyCapabilityOfChildInstance(capabilityPropertyDeclaredAsInput.get(0).getParentUniqueId(), component.getCapabilities()); + if (!propertyCapabilityOptional.isPresent()) { return StorageOperationStatus.OK; } - - return toscaOperationFacade.updateInstanceCapabilityProperty(component, input.getInstanceUniqueId(), - capabilityPropertyDeclaredAsInput.get(0), propertyCapabilityOptional.get() ); + return toscaOperationFacade + .updateInstanceCapabilityProperty(component, input.getInstanceUniqueId(), capabilityPropertyDeclaredAsInput.get(0), + propertyCapabilityOptional.get()); } else { List<ComponentInstanceProperty> componentInstancePropertiesDeclaredAsInput = componentInstanceBusinessLogic - .getComponentInstancePropertiesByInputId(component, input.getUniqueId()); + .getComponentInstancePropertiesByInputId(component, input.getUniqueId()); if (CollectionUtils.isEmpty(componentInstancePropertiesDeclaredAsInput)) { return StorageOperationStatus.OK; } - componentInstancePropertiesDeclaredAsInput.forEach(cmptInstanceProperty -> prepareValueBeforeDelete(input, - cmptInstanceProperty, cmptInstanceProperty.getPath())); - return toscaOperationFacade.updateComponentInstanceProperties(component, - componentInstancePropertiesDeclaredAsInput.get(0).getComponentInstanceId(), + componentInstancePropertiesDeclaredAsInput + .forEach(cmptInstanceProperty -> prepareValueBeforeDelete(input, cmptInstanceProperty, cmptInstanceProperty.getPath())); + return toscaOperationFacade + .updateComponentInstanceProperties(component, componentInstancePropertiesDeclaredAsInput.get(0).getComponentInstanceId(), componentInstancePropertiesDeclaredAsInput); } } @Override public StorageOperationStatus unDeclarePropertiesAsListInputs(Component component, InputDefinition input) { - List<ComponentInstanceProperty> componentInstancePropertiesDeclaredAsInput = componentInstanceBusinessLogic.getComponentInstancePropertiesByInputId(component, input.getUniqueId()); + List<ComponentInstanceProperty> componentInstancePropertiesDeclaredAsInput = componentInstanceBusinessLogic + .getComponentInstancePropertiesByInputId(component, input.getUniqueId()); if (CollectionUtils.isEmpty(componentInstancePropertiesDeclaredAsInput)) { return StorageOperationStatus.OK; } - componentInstancePropertiesDeclaredAsInput.forEach(cmptInstanceProperty -> prepareValueBeforeDelete(input, cmptInstanceProperty, cmptInstanceProperty.getPath())); - return toscaOperationFacade.updateComponentInstanceProperties(component, componentInstancePropertiesDeclaredAsInput.get(0).getComponentInstanceId(), componentInstancePropertiesDeclaredAsInput); + componentInstancePropertiesDeclaredAsInput + .forEach(cmptInstanceProperty -> prepareValueBeforeDelete(input, cmptInstanceProperty, cmptInstanceProperty.getPath())); + return toscaOperationFacade + .updateComponentInstanceProperties(component, componentInstancePropertiesDeclaredAsInput.get(0).getComponentInstanceId(), + componentInstancePropertiesDeclaredAsInput); } } |