diff options
Diffstat (limited to 'catalog-model/src')
2 files changed, 59 insertions, 41 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/InterfaceOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/InterfaceOperation.java index bc67281035..786c98d1a7 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/InterfaceOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/InterfaceOperation.java @@ -26,27 +26,40 @@ import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum; import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum; import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition; import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields; +import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition; +import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.InterfaceDefinition; +import org.openecomp.sdc.be.model.Resource; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter; @org.springframework.stereotype.Component("interfaces-operation") public class InterfaceOperation extends BaseOperation { - public Either<List<InterfaceDefinition>, StorageOperationStatus> addInterfaces(String componentId, + public Either<List<InterfaceDefinition>, StorageOperationStatus> addInterfaces(final Component component, List<InterfaceDefinition> interfaceDefinitions) { - return addOrUpdateInterfaces(false, componentId, interfaceDefinitions); + final String componentId = component.getUniqueId(); + if (isVfc(component)) { + return addOrUpdateInterfaces(componentId, VertexTypeEnum.INTERFACE_ARTIFACTS, EdgeLabelEnum.INTERFACE_ARTIFACTS, interfaceDefinitions, + false); + } else { + return addOrUpdateInterfaces(componentId, VertexTypeEnum.INTERFACE, EdgeLabelEnum.INTERFACE, interfaceDefinitions, false); + } } - private Either<List<InterfaceDefinition>, StorageOperationStatus> addOrUpdateInterfaces(boolean isUpdateAction, String componentId, - List<InterfaceDefinition> interfaceDefinitions) { - List<ToscaDataDefinition> interfaceDataDefinitions = interfaceDefinitions.stream().map(InterfaceDataDefinition::new) + private Either<List<InterfaceDefinition>, StorageOperationStatus> addOrUpdateInterfaces(final String componentId, + final VertexTypeEnum vertexTypeEnum, + final EdgeLabelEnum edgeLabelEnum, + final List<InterfaceDefinition> interfaceDefinitions, + final boolean isUpdateAction) { + final List<ToscaDataDefinition> interfaceDataDefinitions = interfaceDefinitions.stream() + .map(InterfaceDataDefinition::new) .collect(Collectors.toList()); - StorageOperationStatus statusRes = performUpdateToscaAction(isUpdateAction, componentId, interfaceDataDefinitions, EdgeLabelEnum.INTERFACE, - VertexTypeEnum.INTERFACE); - if (!statusRes.equals(StorageOperationStatus.OK)) { - return Either.right(statusRes); + final StorageOperationStatus status = performUpdateToscaAction(isUpdateAction, componentId, interfaceDataDefinitions, edgeLabelEnum, + vertexTypeEnum); + if (!status.equals(StorageOperationStatus.OK)) { + return Either.right(status); } return Either.left(interfaceDefinitions); } @@ -60,25 +73,43 @@ public class InterfaceOperation extends BaseOperation { } } - public Either<List<InterfaceDefinition>, StorageOperationStatus> updateInterfaces(String componentId, - List<InterfaceDefinition> interfaceDefinitions) { - return addOrUpdateInterfaces(true, componentId, interfaceDefinitions); + public Either<List<InterfaceDefinition>, StorageOperationStatus> updateInterfaces(final Component component, + final List<InterfaceDefinition> interfaceDefinitions) { + final String componentId = component.getUniqueId(); + if (isVfc(component)) { + return addOrUpdateInterfaces(componentId, VertexTypeEnum.INTERFACE_ARTIFACTS, EdgeLabelEnum.INTERFACE_ARTIFACTS, interfaceDefinitions, + true); + } else { + return addOrUpdateInterfaces(componentId, VertexTypeEnum.INTERFACE, EdgeLabelEnum.INTERFACE, interfaceDefinitions, true); + } + } + + public Either<String, StorageOperationStatus> deleteInterface(final Component component, final String interfacesToDelete) { + final String componentId = component.getUniqueId(); + if (isVfc(component)) { + return deleteInterface(componentId, interfacesToDelete, EdgeLabelEnum.INTERFACE_ARTIFACTS, VertexTypeEnum.INTERFACE_ARTIFACTS); + } else { + return deleteInterface(componentId, interfacesToDelete, EdgeLabelEnum.INTERFACE, VertexTypeEnum.INTERFACE); + } + } + + private boolean isVfc(Component component) { + return component instanceof Resource && ((Resource) component).getResourceType() == ResourceTypeEnum.VFC; } - public Either<String, StorageOperationStatus> deleteInterface(String componentId, String interfacesToDelete) { - StorageOperationStatus statusRes = deleteToscaDataElements(componentId, EdgeLabelEnum.INTERFACE, - Collections.singletonList(interfacesToDelete)); + private Either<String, StorageOperationStatus> deleteInterface(final String componentId, final String interfacesToDelete, + final EdgeLabelEnum edgeLabel, final VertexTypeEnum vertexType) { + StorageOperationStatus statusRes = deleteToscaDataElements(componentId, edgeLabel, Collections.singletonList(interfacesToDelete)); if (!statusRes.equals(StorageOperationStatus.OK)) { return Either.right(statusRes); } - Either<Map<String, InterfaceDataDefinition>, JanusGraphOperationStatus> componentEither = getDataFromGraph(componentId, - EdgeLabelEnum.INTERFACE); - if (componentEither.isRight()) { - return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(componentEither.right().value())); + Either<Map<String, InterfaceDataDefinition>, JanusGraphOperationStatus> interfaceEither = getDataFromGraph(componentId, edgeLabel); + if (interfaceEither.isRight()) { + return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(interfaceEither.right().value())); } - Map<String, InterfaceDataDefinition> interfaceDataDefinitionMap = componentEither.left().value(); + final Map<String, InterfaceDataDefinition> interfaceDataDefinitionMap = interfaceEither.left().value(); if (MapUtils.isEmpty(interfaceDataDefinitionMap)) { - statusRes = removeToscaData(componentId, EdgeLabelEnum.INTERFACE, VertexTypeEnum.INTERFACE); + statusRes = removeToscaData(componentId, edgeLabel, vertexType); if (!statusRes.equals(StorageOperationStatus.OK)) { return Either.right(statusRes); } diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/InterfaceOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/InterfaceOperationTest.java index 7353c511db..44d0fbdf1e 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/InterfaceOperationTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/InterfaceOperationTest.java @@ -357,10 +357,7 @@ public class InterfaceOperationTest extends ModelTestBase { private void testAddSingleInterface(Component component) { InterfaceDefinition interfaceDefinition = buildInterfaceDefinition("1"); - Either<List<InterfaceDefinition>, StorageOperationStatus> res = interfaceOperation - .addInterfaces(component.getUniqueId(), - Collections.singletonList( - interfaceDefinition)); + final var res = interfaceOperation.addInterfaces(component, Collections.singletonList(interfaceDefinition)); Assert.assertTrue(res.isLeft()); Assert.assertEquals("1", res.left().value().get(0).getUniqueId()); } @@ -398,8 +395,7 @@ public class InterfaceOperationTest extends ModelTestBase { List<InterfaceDefinition> interfaceDefinitions = new ArrayList<>(); interfaceDefinitions.add(interfaceDefinition1); interfaceDefinitions.add(interfaceDefinition2); - Either<List<InterfaceDefinition>, StorageOperationStatus> res = - interfaceOperation.addInterfaces(component.getUniqueId(), interfaceDefinitions); + final var res = interfaceOperation.addInterfaces(component, interfaceDefinitions); Assert.assertTrue(res.isLeft()); Assert.assertEquals(2, res.left().value().size()); } @@ -411,17 +407,13 @@ public class InterfaceOperationTest extends ModelTestBase { private void testUpdateInterface(Component component) { InterfaceDefinition interfaceDefinition = buildInterfaceDefinition("1"); - Either<List<InterfaceDefinition>, StorageOperationStatus> res = interfaceOperation - .addInterfaces(component.getUniqueId(), - Collections.singletonList( - interfaceDefinition)); + var res = interfaceOperation.addInterfaces(component, Collections.singletonList(interfaceDefinition)); Assert.assertTrue(res.isLeft()); List<InterfaceDefinition> value = res.left().value(); InterfaceDefinition createdInterfaceDef = value.get(0); String newDescription = "New Description"; createdInterfaceDef.setDescription(newDescription); - res = interfaceOperation - .updateInterfaces(component.getUniqueId(), Collections.singletonList(createdInterfaceDef)); + res = interfaceOperation.updateInterfaces(component, Collections.singletonList(createdInterfaceDef)); assertTrue(res.isLeft()); assertEquals(newDescription, res.left().value().get(0).getDescription()); } @@ -438,14 +430,10 @@ public class InterfaceOperationTest extends ModelTestBase { private void testDeleteInterface(Component component) { InterfaceDefinition interfaceDefinition = buildInterfaceDefinition("1"); - Either<List<InterfaceDefinition>, StorageOperationStatus> res = interfaceOperation - .addInterfaces(component.getUniqueId(), - Collections.singletonList( - interfaceDefinition)); + var res = interfaceOperation.addInterfaces(component, Collections.singletonList(interfaceDefinition)); Assert.assertTrue(res.isLeft()); List<InterfaceDefinition> value = res.left().value(); - Either<String, StorageOperationStatus> deleteInterfaceOperationRes = - interfaceOperation.deleteInterface(component.getUniqueId(), value.get(0).getUniqueId()); + final var deleteInterfaceOperationRes = interfaceOperation.deleteInterface(component, value.get(0).getUniqueId()); assertTrue(deleteInterfaceOperationRes.isLeft()); } @@ -459,8 +447,7 @@ public class InterfaceOperationTest extends ModelTestBase { Component component = createResource(); InterfaceDefinition interfaceDefinition = buildInterfaceDefinitionWithoutOperation(); interfaceDefinition.setOperationsMap(createMockOperationMap()); - Either<List<InterfaceDefinition>, StorageOperationStatus> res = interfaceOperation.updateInterfaces( - component.getUniqueId(), Collections.singletonList(interfaceDefinition)); + final var res = interfaceOperation.updateInterfaces(component, Collections.singletonList(interfaceDefinition)); Assert.assertTrue(res.isRight()); } |