diff options
Diffstat (limited to 'catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/CapabilitiesOperation.java')
-rw-r--r-- | catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/CapabilitiesOperation.java | 77 |
1 files changed, 31 insertions, 46 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/CapabilitiesOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/CapabilitiesOperation.java index 3b544aaa39..65673345e7 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/CapabilitiesOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/CapabilitiesOperation.java @@ -13,10 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.be.model.jsonjanusgraph.operations; import fj.data.Either; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; import org.apache.commons.collections.MapUtils; import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum; @@ -38,15 +41,16 @@ import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; - @org.springframework.stereotype.Component("capabilities-operation") public class CapabilitiesOperation extends BaseOperation { + private static final Logger LOGGER = LoggerFactory.getLogger(CapabilitiesOperation.class); + private static ListCapabilityDataDefinition convertToListCapabilityDataDefinition(List<CapabilityDefinition> capabilities) { + List<CapabilityDataDefinition> capabilityDefinitions = new ArrayList<>(capabilities); + return new ListCapabilityDataDefinition(capabilityDefinitions); + } + public Either<List<CapabilityDefinition>, StorageOperationStatus> addCapabilities(String componentId, List<CapabilityDefinition> capabilityDefinitions) { return addOrUpdateCapabilities(componentId, capabilityDefinitions, false); @@ -60,89 +64,71 @@ public class CapabilitiesOperation extends BaseOperation { private Either<List<CapabilityDefinition>, StorageOperationStatus> addOrUpdateCapabilities(String componentId, List<CapabilityDefinition> capabilityDefinitions, boolean isUpdateAction) { - StorageOperationStatus statusRes = performUpdateToscaAction(isUpdateAction, - componentId, Collections.singletonList(convertToListCapabilityDataDefinition(capabilityDefinitions))); + StorageOperationStatus statusRes = performUpdateToscaAction(isUpdateAction, componentId, + Collections.singletonList(convertToListCapabilityDataDefinition(capabilityDefinitions))); if (!statusRes.equals(StorageOperationStatus.OK)) { - LOGGER.error("Failed to find the parent capability of capability type {}." + " status is {}", componentId, - statusRes); + LOGGER.error("Failed to find the parent capability of capability type {}." + " status is {}", componentId, statusRes); return Either.right(statusRes); } return Either.left(capabilityDefinitions); } public StorageOperationStatus deleteCapabilities(Component component, String capabilityIdToDelete) { - return deleteToscaDataElements(component.getUniqueId(), EdgeLabelEnum.CAPABILITIES, - Collections.singletonList(capabilityIdToDelete)); + return deleteToscaDataElements(component.getUniqueId(), EdgeLabelEnum.CAPABILITIES, Collections.singletonList(capabilityIdToDelete)); } public StorageOperationStatus deleteCapabilityProperties(Component component, String capabilityPropIdToDelete) { return deleteToscaDataElements(component.getUniqueId(), EdgeLabelEnum.CAPABILITIES_PROPERTIES, - Collections.singletonList(capabilityPropIdToDelete)); - } - - private static ListCapabilityDataDefinition convertToListCapabilityDataDefinition(List<CapabilityDefinition> capabilities) { - List<CapabilityDataDefinition> capabilityDefinitions = new ArrayList<>(capabilities); - return new ListCapabilityDataDefinition(capabilityDefinitions); + Collections.singletonList(capabilityPropIdToDelete)); } - private StorageOperationStatus performUpdateToscaAction(boolean isUpdate, String componentId, - List<ListCapabilityDataDefinition> toscaDataList) { + private StorageOperationStatus performUpdateToscaAction(boolean isUpdate, String componentId, List<ListCapabilityDataDefinition> toscaDataList) { if (isUpdate) { - return updateToscaDataOfToscaElement(componentId, EdgeLabelEnum.CAPABILITIES, - VertexTypeEnum.CAPABILITIES, toscaDataList, JsonPresentationFields.TYPE); + return updateToscaDataOfToscaElement(componentId, EdgeLabelEnum.CAPABILITIES, VertexTypeEnum.CAPABILITIES, toscaDataList, + JsonPresentationFields.TYPE); } else { - return addToscaDataToToscaElement(componentId, EdgeLabelEnum.CAPABILITIES, - VertexTypeEnum.CAPABILITIES, toscaDataList, JsonPresentationFields.TYPE); + return addToscaDataToToscaElement(componentId, EdgeLabelEnum.CAPABILITIES, VertexTypeEnum.CAPABILITIES, toscaDataList, + JsonPresentationFields.TYPE); } } private StorageOperationStatus createOrUpdateCapabilityProperties(String componentId, TopologyTemplate toscaElement, Map<String, MapPropertiesDataDefinition> propertiesMap) { - GraphVertex toscaElementV = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum - .NoParse) - .left().on(this::throwStorageException); + GraphVertex toscaElementV = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse).left().on(this::throwStorageException); Map<String, MapPropertiesDataDefinition> capabilitiesProperties = toscaElement.getCapabilitiesProperties(); - if(MapUtils.isNotEmpty(capabilitiesProperties)) { - + if (MapUtils.isNotEmpty(capabilitiesProperties)) { capabilitiesProperties.forEach((key, val) -> { Map<String, PropertyDataDefinition> mapToscaDataDefinition = val.getMapToscaDataDefinition(); mapToscaDataDefinition.forEach((key1, val1) -> { - propertiesMap.forEach((propKey, propVal) -> { Map<String, PropertyDataDefinition> propValMapToscaDataDefinition = propVal.getMapToscaDataDefinition(); propValMapToscaDataDefinition.forEach((propKey1, propVal1) -> { - if(propKey1.equals(key1) && val1.getUniqueId().equals(propVal1.getUniqueId())) { + if (propKey1.equals(key1) && val1.getUniqueId().equals(propVal1.getUniqueId())) { ToscaDataDefinition.mergeDataMaps(mapToscaDataDefinition, propValMapToscaDataDefinition); } }); }); }); }); - ToscaDataDefinition.mergeDataMaps(propertiesMap, capabilitiesProperties); } - - return topologyTemplateOperation.updateFullToscaData(toscaElementV, - EdgeLabelEnum.CAPABILITIES_PROPERTIES, VertexTypeEnum.CAPABILITIES_PROPERTIES, propertiesMap); + return topologyTemplateOperation + .updateFullToscaData(toscaElementV, EdgeLabelEnum.CAPABILITIES_PROPERTIES, VertexTypeEnum.CAPABILITIES_PROPERTIES, propertiesMap); } - public StorageOperationStatus createOrUpdateCapabilityProperties(String componentId, - Map<String, MapPropertiesDataDefinition> propertiesMap) { + public StorageOperationStatus createOrUpdateCapabilityProperties(String componentId, Map<String, MapPropertiesDataDefinition> propertiesMap) { StorageOperationStatus propertiesStatusRes = null; - if(MapUtils.isNotEmpty(propertiesMap)) { - propertiesStatusRes = createOrUpdateCapabilityProperties(componentId, getTopologyTemplate(componentId), - propertiesMap); + if (MapUtils.isNotEmpty(propertiesMap)) { + propertiesStatusRes = createOrUpdateCapabilityProperties(componentId, getTopologyTemplate(componentId), propertiesMap); } - return propertiesStatusRes; } private TopologyTemplate getTopologyTemplate(String componentId) { - return (TopologyTemplate)topologyTemplateOperation - .getToscaElement(componentId, getFilterComponentWithCapProperties()) - .left() - .on(this::throwStorageException); + return (TopologyTemplate) topologyTemplateOperation.getToscaElement(componentId, getFilterComponentWithCapProperties()).left() + .on(this::throwStorageException); } + private ComponentParametersView getFilterComponentWithCapProperties() { ComponentParametersView filter = new ComponentParametersView(); filter.setIgnoreCapabiltyProperties(false); @@ -152,5 +138,4 @@ public class CapabilitiesOperation extends BaseOperation { private ToscaElement throwStorageException(StorageOperationStatus status) { throw new StorageException(status); } - } |