From c0b223d4fa51947c1aad771cae210678554aff3e Mon Sep 17 00:00:00 2001 From: Satoshi Fujii Date: Mon, 20 May 2019 16:00:56 +0900 Subject: Fixed declared properties are not updated properly Change-Id: I3712f9656d7cdeb8fa9c4212b2dd1496043c1006 Issue-ID: SDC-2314 Signed-off-by: Satoshi Fujii --- .../jsontitan/operations/ToscaOperationFacade.java | 60 +++++++++++----------- 1 file changed, 30 insertions(+), 30 deletions(-) (limited to 'catalog-model/src/main/java') diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacade.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacade.java index 4482f7f943..dd9c3ca29e 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacade.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacade.java @@ -20,7 +20,6 @@ package org.openecomp.sdc.be.model.jsontitan.operations; -import com.datastax.driver.core.DataType; import fj.data.Either; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; @@ -47,7 +46,6 @@ import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter; import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder; import org.openecomp.sdc.be.resources.data.ComponentMetadataData; -import org.openecomp.sdc.be.resources.data.DataTypeData; import org.openecomp.sdc.common.jsongraph.util.CommonUtility; import org.openecomp.sdc.common.jsongraph.util.CommonUtility.LogLevelEnum; import org.openecomp.sdc.common.log.wrappers.Logger; @@ -1236,30 +1234,31 @@ public class ToscaOperationFacade { public Either>, StorageOperationStatus> addComponentInstancePropertiesToComponent(Component containerComponent, Map> instProperties) { requireNonNull(instProperties); - StorageOperationStatus status = null; for (Entry> entry : instProperties.entrySet()) { List props = entry.getValue(); String componentInstanceId = entry.getKey(); - + List originalComponentInstProps = + containerComponent.getComponentInstancesProperties().get(componentInstanceId); Map> containerComponentCapabilities = containerComponent.getCapabilities(); - if (!isEmpty(props)) { - for (ComponentInstanceProperty property : props) { - String propertyParentUniqueId = property.getParentUniqueId(); - Optional - capPropDefinition = getPropertyCapability(propertyParentUniqueId, containerComponent); - if(capPropDefinition.isPresent() && MapUtils.isNotEmpty(containerComponentCapabilities)) { - status = populateAndUpdateInstanceCapProperty(containerComponent, componentInstanceId, - containerComponentCapabilities, property, capPropDefinition.get()); - } - if(status == null) { - List instanceProperties = containerComponent - .getComponentInstancesProperties().get(componentInstanceId); - status = updateInstanceProperty(containerComponent, componentInstanceId, instanceProperties, property); - } - if(status != StorageOperationStatus.OK) { - return Either.right(status); - } + if(isEmpty(props)) { + continue; + } + for (ComponentInstanceProperty property : props) { + StorageOperationStatus status = null; + String propertyParentUniqueId = property.getParentUniqueId(); + Optional + capPropDefinition = getPropertyCapability(propertyParentUniqueId, containerComponent); + if(capPropDefinition.isPresent() && MapUtils.isNotEmpty(containerComponentCapabilities)) { + status = populateAndUpdateInstanceCapProperty(containerComponent, componentInstanceId, + containerComponentCapabilities, property, capPropDefinition.get()); + } + if(status == null) { + status = updateOrAddComponentInstanceProperty(containerComponent, componentInstanceId, + originalComponentInstProps, property); + } + if(status != StorageOperationStatus.OK) { + return Either.right(status); } } } @@ -1299,23 +1298,24 @@ public class ToscaOperationFacade { .findAny(); } - private StorageOperationStatus updateInstanceProperty(Component containerComponent, String componentInstanceId, - List instanceProperties, - ComponentInstanceProperty property) { + private StorageOperationStatus updateOrAddComponentInstanceProperty(Component containerComponent, + String componentInstanceId, List originalComponentInstProps, + ComponentInstanceProperty property) + { StorageOperationStatus status; - Optional instanceProperty = instanceProperties.stream() - .filter(p -> p.getUniqueId().equals(property.getUniqueId())) - .findAny(); + // check if the property already exists or not + Optional instanceProperty = originalComponentInstProps.stream() + .filter(p -> p.getUniqueId().equals(property.getUniqueId())).findAny(); if (instanceProperty.isPresent()) { status = updateComponentInstanceProperty(containerComponent, componentInstanceId, property); } else { status = addComponentInstanceProperty(containerComponent, componentInstanceId, property); } if (status != StorageOperationStatus.OK) { - log.debug("Failed to update instance property {} for instance {} error {} ", property, componentInstanceId, status); - return status; + log.debug("Failed to update instance property {} for instance {} error {} ", + property, componentInstanceId, status); } - return StorageOperationStatus.OK; + return status; } public StorageOperationStatus updateInstanceCapabilityProperty(Component containerComponent, String componentInstanceId, -- cgit 1.2.3-korg