From 0ed125f98ae8ea9e80c855a640c328654660d081 Mon Sep 17 00:00:00 2001 From: davsad Date: Sat, 24 Jul 2021 19:40:56 +0100 Subject: Consider component model when retrieving interface types Issue-ID: SDC-3414 Signed-off-by: davsad Change-Id: Ie16a2604cfdff042e32bfa4f9a3a509b5da22226 --- .../impl/InterfaceDefinitionHandler.java | 9 ++-- .../impl/InterfaceOperationBusinessLogic.java | 6 +-- .../be/components/impl/ResourceImportManager.java | 11 ++-- .../sdc/be/servlets/TypesFetchServlet.java | 34 ++++++------ .../openecomp/sdc/be/tosca/ToscaExportHandler.java | 4 +- .../be/components/ResourceImportManagerTest.java | 11 ++-- .../impl/InterfaceDefinitionHandlerTest.java | 11 ++-- .../impl/InterfaceOperationBusinessLogicTest.java | 62 +++++++++++----------- .../sdc/be/tosca/ToscaExportHandlerTest.java | 26 ++++----- .../api/IInterfaceLifecycleOperation.java | 7 ++- .../impl/InterfaceLifecycleOperation.java | 4 +- .../impl/InterfaceLifecycleOperationTest.java | 13 ++--- .../relationship-operations-step.component.ts | 2 +- .../component-services/component.service.ts | 2 +- 14 files changed, 111 insertions(+), 91 deletions(-) diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceDefinitionHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceDefinitionHandler.java index 62e6ce5182..de8f2934d5 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceDefinitionHandler.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceDefinitionHandler.java @@ -75,8 +75,9 @@ public class InterfaceDefinitionHandler { * @param interfaceDefinitionToscaMap the TOSCA interface definition structure * @return an interface definition representation */ - public InterfaceDefinition create(final Map interfaceDefinitionToscaMap) { + public InterfaceDefinition create(final Map interfaceDefinitionToscaMap, final String model) { final InterfaceDefinition interfaceDefinition = new InterfaceDefinition(); + interfaceDefinition.setModel(model); if (interfaceDefinitionToscaMap.containsKey(TYPE.getElementName())) { final Object typeObj = interfaceDefinitionToscaMap.get(TYPE.getElementName()); if (!(typeObj instanceof String)) { @@ -101,18 +102,18 @@ public class InterfaceDefinitionHandler { operationMap = handleLegacyOperations(interfaceDefinitionToscaMap); } if (!operationMap.isEmpty()) { - validateOperations(interfaceDefinition.getType(), operationMap); + validateOperations(interfaceDefinition.getType(), operationMap, model); interfaceDefinition.setOperations(operationMap); } return interfaceDefinition; } - private void validateOperations(final String interfaceType, final Map operationMap) { + private void validateOperations(final String interfaceType, final Map operationMap, final String model) { if (MapUtils.isEmpty(operationMap)) { return; } Either, ResponseFormat> interfaceDefinitionMapEither = interfaceOperationBusinessLogic - .getAllInterfaceLifecycleTypes(); + .getAllInterfaceLifecycleTypes(model); if (interfaceDefinitionMapEither.isRight() || MapUtils.isEmpty(interfaceDefinitionMapEither.left().value())) { throw new ByActionStatusComponentException(ActionStatus.INTERFACE_UNKNOWN, interfaceType); } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java index e23818c957..d633141fdf 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java @@ -258,7 +258,7 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { } org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value(); lockComponentResult(lock, storedComponent, errorContext); - Either, ResponseFormat> interfaceLifecycleTypes = getAllInterfaceLifecycleTypes(); + Either, ResponseFormat> interfaceLifecycleTypes = getAllInterfaceLifecycleTypes(storedComponent.getModel()); if (interfaceLifecycleTypes.isRight()) { return Either.right(interfaceLifecycleTypes.right().value()); } @@ -349,9 +349,9 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { } } - public Either, ResponseFormat> getAllInterfaceLifecycleTypes() { + public Either, ResponseFormat> getAllInterfaceLifecycleTypes(final String model) { Either, StorageOperationStatus> interfaceLifecycleTypes = interfaceLifecycleTypeOperation - .getAllInterfaceLifecycleTypes(); + .getAllInterfaceLifecycleTypes(model); if (interfaceLifecycleTypes.isRight()) { return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_LIFECYCLE_TYPES_NOT_FOUND)); } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java index a7defab60a..6efdab4a96 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java @@ -24,7 +24,6 @@ package org.openecomp.sdc.be.components.impl; import static org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaElementOperation.createDataType; import static org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaElementOperation.createDataTypeDefinitionWithName; -import fj.data.Either; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -37,7 +36,9 @@ import java.util.Set; import java.util.function.Function; import java.util.regex.Pattern; import java.util.stream.Collectors; + import javax.servlet.ServletContext; + import org.apache.commons.codec.binary.Base64; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; @@ -97,6 +98,8 @@ import org.springframework.stereotype.Component; import org.springframework.web.context.WebApplicationContext; import org.yaml.snakeyaml.Yaml; +import fj.data.Either; + @Component("resourceImportManager") public class ResourceImportManager { @@ -351,7 +354,7 @@ public class ResourceImportManager { Map jsonInterfaces = toscaInterfaces.left().value(); Map moduleInterfaces = new HashMap<>(); for (final Entry interfaceNameValue : jsonInterfaces.entrySet()) { - final Either eitherInterface = createModuleInterface(interfaceNameValue.getValue()); + final Either eitherInterface = createModuleInterface(interfaceNameValue.getValue(), resource.getModel()); if (eitherInterface.isRight()) { log.info("error when creating interface:{}, for resource:{}", interfaceNameValue.getKey(), resource.getName()); } else { @@ -365,7 +368,7 @@ public class ResourceImportManager { } } - private Either createModuleInterface(final Object interfaceJson) { + private Either createModuleInterface(final Object interfaceJson, final String model) { try { if (interfaceJson instanceof String) { final InterfaceDefinition interfaceDefinition = new InterfaceDefinition(); @@ -374,7 +377,7 @@ public class ResourceImportManager { } if (interfaceJson instanceof Map) { final Map interfaceJsonMap = (Map) interfaceJson; - final InterfaceDefinition interfaceDefinition = interfaceDefinitionHandler.create(interfaceJsonMap); + final InterfaceDefinition interfaceDefinition = interfaceDefinitionHandler.create(interfaceJsonMap, model); return Either.left(interfaceDefinition); } return Either.right(ResultStatusEnum.GENERAL_ERROR); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java index c3c42e27f5..ac195f9315 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java @@ -19,22 +19,11 @@ */ package org.openecomp.sdc.be.servlets; -import com.jcabi.aspects.Loggable; -import fj.data.Either; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.media.ArraySchema; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; -import io.swagger.v3.oas.annotations.servers.Server; -import io.swagger.v3.oas.annotations.servers.Servers; -import io.swagger.v3.oas.annotations.tags.Tag; -import io.swagger.v3.oas.annotations.tags.Tags; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; + import javax.inject.Inject; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; @@ -47,8 +36,8 @@ import javax.ws.rs.QueryParam; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; + import org.apache.commons.collections4.ListUtils; -import org.glassfish.jersey.media.multipart.FormDataParam; import org.openecomp.sdc.be.components.impl.CapabilitiesBusinessLogic; import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic; import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; @@ -79,6 +68,20 @@ import org.openecomp.sdc.common.log.wrappers.Logger; import org.openecomp.sdc.exception.ResponseFormat; import org.springframework.stereotype.Controller; +import com.jcabi.aspects.Loggable; + +import fj.data.Either; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.servers.Server; +import io.swagger.v3.oas.annotations.servers.Servers; +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.tags.Tags; + @Loggable(prepend = true, value = Loggable.DEBUG, trim = false) @Path("/v1/catalog") @Tags({@Tag(name = "SDCE-2 APIs")}) @@ -145,7 +148,8 @@ public class TypesFetchServlet extends AbstractValidationsServlet { @ApiResponse(responseCode = "404", description = "Interface lifecycle types not found")}) @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE) public Response getInterfaceLifecycleTypes(@Context final HttpServletRequest request, - @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { + @HeaderParam(value = Constants.USER_ID_HEADER) String userId, + @Parameter(description = "model") @QueryParam("model") String modelName) { Wrapper responseWrapper = new Wrapper<>(); Wrapper userWrapper = new Wrapper<>(); try { @@ -154,7 +158,7 @@ public class TypesFetchServlet extends AbstractValidationsServlet { String url = request.getMethod() + " " + request.getRequestURI(); log.info("Start handle request of {} | modifier id is {}", url, userId); Either, ResponseFormat> allInterfaceLifecycleTypes = interfaceOperationBusinessLogic - .getAllInterfaceLifecycleTypes(); + .getAllInterfaceLifecycleTypes(modelName); if (allInterfaceLifecycleTypes.isRight()) { log.info("Failed to get all interface lifecycle types. Reason - {}", allInterfaceLifecycleTypes.right().value()); Response errorResponse = buildErrorResponse(allInterfaceLifecycleTypes.right().value()); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java index 4f815a316d..3fe3bd5c42 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java @@ -693,7 +693,7 @@ public class ToscaExportHandler { log.debug("start convert node type for {}", component.getUniqueId()); ToscaNodeType toscaNodeType = createNodeType(component); Either, StorageOperationStatus> lifecycleTypeEither = interfaceLifecycleOperation - .getAllInterfaceLifecycleTypes(); + .getAllInterfaceLifecycleTypes(component.getModel()); if (lifecycleTypeEither.isRight()) { log.debug("Failed to fetch all interface types :", lifecycleTypeEither.right().value()); return Either.right(ToscaError.GENERAL_ERROR); @@ -1077,7 +1077,7 @@ public class ToscaExportHandler { } Either, StorageOperationStatus> lifecycleTypeEither = - interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(); + interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(serviceComponent.getModel()); if (lifecycleTypeEither.isRight()) { log.debug("Failed to retrieve global interface types :", lifecycleTypeEither.right().value()); return Either.right(ToscaError.GENERAL_ERROR); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java index a9368b2b01..00e0681c8d 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java @@ -34,12 +34,13 @@ import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; -import fj.data.Either; import java.io.IOException; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; + +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; @@ -87,6 +88,8 @@ import org.openecomp.sdc.common.impl.FSConfigurationSource; import org.openecomp.sdc.exception.PolicyException; import org.openecomp.sdc.exception.ResponseFormat; +import fj.data.Either; + public class ResourceImportManagerTest { static ResourceImportManager importManager; @@ -236,7 +239,7 @@ public class ResourceImportManagerTest { operations.put("configure", new OperationDataDefinition()); interfaceDefinition.setOperations(operations ); interfaceTypes.put("tosca.interfaces.node.lifecycle.standard", interfaceDefinition); - when(interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes()).thenReturn(Either.left(interfaceTypes)); + when(interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes(any())).thenReturn(Either.left(interfaceTypes)); final ImmutablePair createResource = importManager .importNormativeResource(jsonContent, resourceMD, user, true, true); @@ -261,7 +264,7 @@ public class ResourceImportManagerTest { operations.put("configure", new OperationDataDefinition()); interfaceDefinition.setOperations(operations ); interfaceTypes.put("tosca.interfaces.node.lifecycle.standard", interfaceDefinition); - when(interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes()).thenReturn(Either.left(interfaceTypes)); + when(interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes(any())).thenReturn(Either.left(interfaceTypes)); ImmutablePair createResource = importManager.importNormativeResource(jsonContent, resourceMD, user, true, true); assertNull(createResource.left.getInterfaces()); @@ -285,7 +288,7 @@ public class ResourceImportManagerTest { operations.put("configure", new OperationDataDefinition()); interfaceDefinition.setOperations(operations ); interfaceTypes.put("tosca.interfaces.node.lifecycle.standard", interfaceDefinition); - when(interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes()).thenReturn(Either.left(interfaceTypes)); + when(interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes(any())).thenReturn(Either.left(interfaceTypes)); ImmutablePair createResource = importManager.importNormativeResource(jsonContent, resourceMD, user, true, true); assertNull(createResource.left.getInterfaces()); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceDefinitionHandlerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceDefinitionHandlerTest.java index f819eceb43..83fa8e2da5 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceDefinitionHandlerTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceDefinitionHandlerTest.java @@ -29,7 +29,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.when; -import fj.data.Either; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.nio.file.Path; @@ -39,7 +38,9 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; + import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang3.StringUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -53,6 +54,8 @@ import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition; import org.openecomp.sdc.be.model.InterfaceDefinition; import org.yaml.snakeyaml.Yaml; +import fj.data.Either; + @ExtendWith(MockitoExtension.class) class InterfaceDefinitionHandlerTest { @@ -84,20 +87,20 @@ class InterfaceDefinitionHandlerTest { operations.put(DELETE_OPERATION, new OperationDataDefinition()); interfaceLifecyleStandard.setOperations(operations); interfaceTypes.put(INTERFACE_TYPE, interfaceLifecyleStandard); - when(interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes()).thenReturn(Either.left(interfaceTypes)); + when(interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes(StringUtils.EMPTY)).thenReturn(Either.left(interfaceTypes)); } @Test void testCreateWithLegacyOperationDeclarationSuccess() throws FileNotFoundException { final Map load = loadYaml(Paths.get("interfaceDefinition-legacy.yaml")); - final InterfaceDefinition actualInterfaceDefinition = interfaceDefinitionHandler.create(load); + final InterfaceDefinition actualInterfaceDefinition = interfaceDefinitionHandler.create(load, StringUtils.EMPTY); assertInterfaceDefinition(actualInterfaceDefinition); } @Test void testCreateWithOperationSuccess() throws FileNotFoundException { final Map load = loadYaml(Paths.get("interfaceDefinition-tosca1.3.yaml")); - final InterfaceDefinition actualInterfaceDefinition = interfaceDefinitionHandler.create(load); + final InterfaceDefinition actualInterfaceDefinition = interfaceDefinitionHandler.create(load, StringUtils.EMPTY); assertInterfaceDefinition(actualInterfaceDefinition); } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java index 3ab235c779..724bf6ab34 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java @@ -16,7 +16,21 @@ package org.openecomp.sdc.be.components.impl; -import fj.data.Either; +import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyMap; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.lang3.StringUtils; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -57,19 +71,7 @@ import org.openecomp.sdc.common.impl.FSConfigurationSource; import org.openecomp.sdc.exception.ResponseFormat; import org.openecomp.sdc.test.utils.InterfaceOperationTestUtils; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static org.junit.Assert.fail; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyBoolean; -import static org.mockito.ArgumentMatchers.anyMap; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.when; +import fj.data.Either; @RunWith(MockitoJUnitRunner.class) public class InterfaceOperationBusinessLogicTest { @@ -147,7 +149,7 @@ public class InterfaceOperationBusinessLogicTest { @Test public void createInterfaceOperationTestOnExistingInterface() { - when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()) + when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())) .thenReturn(Either.left(Collections.emptyMap())); when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left( Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName)))); @@ -161,7 +163,7 @@ public class InterfaceOperationBusinessLogicTest { @Test public void createInterfaceOperationTestOnExistingInterfaceInputsFromCapProp() { - when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()) + when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())) .thenReturn(Either.left(Collections.emptyMap())); when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left( Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName)))); @@ -200,7 +202,7 @@ public class InterfaceOperationBusinessLogicTest { @Test public void createInterfaceOperationWithoutInterfaceTest() { resource.getInterfaces().clear(); - when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()) + when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())) .thenReturn(Either.left(Collections.emptyMap())); when(interfaceOperation.addInterfaces(any(), any())).thenReturn(Either.left( Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName)))); @@ -217,7 +219,7 @@ public class InterfaceOperationBusinessLogicTest { @Test public void createInterfaceOperationWithoutInterfaceTestFail() { resource.getInterfaces().clear(); - when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()) + when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())) .thenReturn(Either.left(Collections.emptyMap())); when(interfaceOperation.addInterfaces(any(), any())) .thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR)); @@ -231,7 +233,7 @@ public class InterfaceOperationBusinessLogicTest { @Test public void shouldFailWhenCreateInterfaceOperationFailedTest() { - when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()) + when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())) .thenReturn(Either.left(Collections.emptyMap())); when(interfaceOperation.updateInterfaces(any(), any())) .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); @@ -242,7 +244,7 @@ public class InterfaceOperationBusinessLogicTest { @Test public void updateInterfaceOperationTestWithArtifactSuccess() { - when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()) + when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())) .thenReturn(Either.left(Collections.emptyMap())); when(artifactToscaOperation.removeArifactFromResource(any(), any(), any(), anyBoolean())) .thenReturn(Either.left(new ArtifactDefinition())); @@ -260,7 +262,7 @@ public class InterfaceOperationBusinessLogicTest { @Test public void updateInterfaceOperationTestWithArtifactFailure() { - when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()) + when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())) .thenReturn(Either.left(Collections.emptyMap())); when(artifactToscaOperation.getArtifactById(any(), any())).thenReturn(Either.left(new ArtifactDefinition())); when(artifactToscaOperation.removeArifactFromResource(any(), any(), any(), anyBoolean())) @@ -275,7 +277,7 @@ public class InterfaceOperationBusinessLogicTest { @Test public void updateInterfaceOperationTestWithoutArtifact() { - when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()) + when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())) .thenReturn(Either.left(Collections.emptyMap())); when(artifactToscaOperation.getArtifactById(any(), any())).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left( @@ -290,7 +292,7 @@ public class InterfaceOperationBusinessLogicTest { @Test public void updateInterfaceOperationTestDoesntExist() { - when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()) + when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())) .thenReturn(Either.left(Collections.emptyMap())); Either, ResponseFormat> interfaceOperation = interfaceOperationBusinessLogic.updateInterfaceOperation(resourceId, @@ -302,7 +304,7 @@ public class InterfaceOperationBusinessLogicTest { @Test public void createInterfaceOperationTestFailOnException() { - when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()) + when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())) .thenReturn(Either.left(Collections.emptyMap())); when(interfaceOperation.updateInterfaces(any(), any())).thenThrow(new RuntimeException()); Either, ResponseFormat> interfaceOperationEither = @@ -315,7 +317,7 @@ public class InterfaceOperationBusinessLogicTest { @Test public void createInterfaceOperationTestFailOnFetchinGlobalTypes() { - when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()) + when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())) .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); Either, ResponseFormat> interfaceOperationEither = interfaceOperationBusinessLogic.createInterfaceOperation(resourceId, @@ -327,7 +329,7 @@ public class InterfaceOperationBusinessLogicTest { @Test public void createInterfaceOperationTestFailOnValidation() { - when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()) + when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())) .thenReturn(Either.left(Collections.emptyMap())); when(interfaceOperationValidation .validateInterfaceOperations(any(), any(), any(), anyMap(), anyBoolean())) @@ -510,10 +512,10 @@ public class InterfaceOperationBusinessLogicTest { @Test public void testGetAllInterfaceLifecycleTypes_TypesNotFound() { - when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()) + when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())) .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); Either, ResponseFormat> response = - interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes(); + interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes(any()); Assert.assertTrue(response.isRight()); } @@ -524,10 +526,10 @@ public class InterfaceOperationBusinessLogicTest { interfaceDefinition.setType(interfaceId); Map interfaceDefinitionMap = new HashMap<>(); interfaceDefinitionMap.put(interfaceDefinition.getUniqueId(), interfaceDefinition); - when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()) + when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())) .thenReturn(Either.left(interfaceDefinitionMap)); Either, ResponseFormat> response = - interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes(); + interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes(StringUtils.EMPTY); Assert.assertEquals(1, response.left().value().size()); } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java index acd4cb4128..5c8d522482 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java @@ -239,7 +239,7 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>())); when(capabilityRequirementConverter.convertRequirements(any(Map.class), any(Resource.class), any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType())); - when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()) + when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())) .thenReturn(Either.left(Collections.emptyMap())); // default test when component is Resource @@ -264,7 +264,7 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { ((Resource) component).setInterfaces(new HashMap<>()); when(dataTypeCache.getAll()).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)); - when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()) + when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())) .thenReturn(Either.left(Collections.emptyMap())); // default test when convertInterfaceNodeType is right result = testSubject.exportComponentInterface(component, false); @@ -296,7 +296,7 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { component.setName(RESOURCE_NAME); component.setToscaResourceName(RESOURCE_NAME); - when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()) + when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())) .thenReturn(Either.left(Collections.emptyMap())); when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>())); // when convertRequirements is called, make it return the same value as 3rd (index=2) argument. @@ -581,7 +581,7 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { Either result; when(dataTypeCache.getAll()).thenReturn(Either.right(JanusGraphOperationStatus.ALREADY_EXIST)); - when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()) + when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())) .thenReturn(Either.left(Collections.emptyMap())); // default test result = Deencapsulation @@ -600,7 +600,7 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { component.setInputs(inputs); when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>())); - when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()) + when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())) .thenReturn(Either.left(Collections.emptyMap())); when(capabilityRequirementConverter.convertRequirements(any(Map.class), any(Resource.class), @@ -729,7 +729,7 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { when(capabilityRequirementConverter .convertComponentInstanceCapabilities(any(ComponentInstance.class), any(Map.class), any(ToscaNodeTemplate.class))) .thenReturn(Either.left(new ToscaNodeTemplate())); - when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()).thenReturn(Either.left(Collections.emptyMap())); + when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())).thenReturn(Either.left(Collections.emptyMap())); when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>())); when(capabilityRequirementConverter.convertRequirements(any(Map.class), any(Resource.class), any(ToscaNodeType.class))) .thenReturn(Either.left(new ToscaNodeType())); @@ -853,7 +853,7 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { when(capabilityRequirementConverter .convertComponentInstanceCapabilities(any(ComponentInstance.class), any(Map.class), any(ToscaNodeTemplate.class))) .thenReturn(Either.left(new ToscaNodeTemplate())); - when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()).thenReturn(Either.left(Collections.emptyMap())); + when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())).thenReturn(Either.left(Collections.emptyMap())); when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>())); when(capabilityRequirementConverter.convertRequirements(any(Map.class), any(Resource.class), any(ToscaNodeType.class))) .thenReturn(Either.left(new ToscaNodeType())); @@ -916,7 +916,7 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { when(capabilityRequirementConverter .convertComponentInstanceCapabilities(any(ComponentInstance.class), any(Map.class), any(ToscaNodeTemplate.class))) .thenReturn(Either.right(ToscaError.GENERAL_ERROR)); - when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()).thenReturn(Either.left(Collections.emptyMap())); + when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())).thenReturn(Either.left(Collections.emptyMap())); when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>())); when(capabilityRequirementConverter.convertRequirements(any(Map.class), any(Resource.class), any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType())); @@ -967,7 +967,7 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { componentCache.put("uid", component); when(capabilityRequirementConverter.getOriginComponent(any(Map.class), any(ComponentInstance.class))).thenReturn(Either.right(false)); - when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()).thenReturn(Either.left(Collections.emptyMap())); + when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())).thenReturn(Either.left(Collections.emptyMap())); when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>())); when(capabilityRequirementConverter.convertRequirements(any(Map.class), any(Resource.class), any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType())); @@ -1022,7 +1022,7 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { doReturn(Either.left(component)).when(toscaOperationFacade).getToscaFullElement("id"); when(capabilityRequirementConverter.getOriginComponent(any(Map.class), any(ComponentInstance.class))).thenReturn(Either.left(component)); - when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()).thenReturn(Either.left(Collections.emptyMap())); + when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())).thenReturn(Either.left(Collections.emptyMap())); when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>())); when(capabilityRequirementConverter.convertRequirements(any(Map.class), any(Resource.class), any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType())); @@ -1087,7 +1087,7 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { when(toscaOperationFacade.getToscaElement(any(String.class), any(ComponentParametersView.class))) .thenReturn(Either.left(new Resource())); - when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()) + when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())) .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST)); result = Deencapsulation.invoke(testSubject, "createProxyInterfaceTypes", container); Assert.assertTrue(result.isRight()); @@ -1105,7 +1105,7 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { componentInstances.add(instance); container.setComponentInstances(componentInstances); - when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()) + when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())) .thenReturn(Either.left(Collections.emptyMap())); Component proxyResource = new Resource(); @@ -1163,7 +1163,7 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { componentInstances.add(instance); containerService.setComponentInstances(componentInstances); - when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()) + when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())) .thenReturn(Either.left(Collections.emptyMap())); when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>())); when(capabilityRequirementConverter.convertRequirements(any(Map.class), any(Service.class), diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IInterfaceLifecycleOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IInterfaceLifecycleOperation.java index 6783fcda13..a30405527f 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IInterfaceLifecycleOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IInterfaceLifecycleOperation.java @@ -19,12 +19,14 @@ */ package org.openecomp.sdc.be.model.operations.api; -import fj.data.Either; import java.util.Map; + import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition; import org.openecomp.sdc.be.model.InterfaceDefinition; import org.openecomp.sdc.be.model.Operation; +import fj.data.Either; + public interface IInterfaceLifecycleOperation { public Either createInterfaceOnResource(InterfaceDefinition interf, String resourceId, @@ -56,5 +58,6 @@ public interface IInterfaceLifecycleOperation { public String getShortInterfaceName(InterfaceDataDefinition interfaceDefinition); - Either, StorageOperationStatus> getAllInterfaceLifecycleTypes(); + Either, StorageOperationStatus> getAllInterfaceLifecycleTypes(final String model); + } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperation.java index 3fa1f8933d..9299aec7e0 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperation.java @@ -850,9 +850,9 @@ public class InterfaceLifecycleOperation implements IInterfaceLifecycleOperation } @Override - public Either, StorageOperationStatus> getAllInterfaceLifecycleTypes() { + public Either, StorageOperationStatus> getAllInterfaceLifecycleTypes(final String model) { Either, JanusGraphOperationStatus> allInterfaceLifecycleTypes = janusGraphGenericDao - .getByCriteria(NodeTypeEnum.Interface, Collections.emptyMap(), InterfaceData.class); + .getByCriteriaForModel(NodeTypeEnum.Interface, Collections.emptyMap(), model, InterfaceData.class); if (allInterfaceLifecycleTypes.isRight()) { return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(allInterfaceLifecycleTypes.right().value())); } diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperationTest.java index 0b5a7fae81..4e0d68f7e2 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperationTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperationTest.java @@ -31,6 +31,7 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; import org.junit.Assert; import org.junit.Before; @@ -156,9 +157,9 @@ public class InterfaceLifecycleOperationTest { @Test public void testGetAllInterfaceLifecycleTypes_TypesNotFound() { - when(janusGraphGenericDao.getByCriteria(NodeTypeEnum.Interface, Collections.emptyMap(), + when(janusGraphGenericDao.getByCriteriaForModel(NodeTypeEnum.Interface, Collections.emptyMap(), StringUtils.EMPTY, InterfaceData.class)).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)); - Either, StorageOperationStatus> types = interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(); + Either, StorageOperationStatus> types = interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(StringUtils.EMPTY); Assert.assertEquals(types.isRight(), Boolean.TRUE); } @@ -173,14 +174,14 @@ public class InterfaceLifecycleOperationTest { interfaceDataList.add(interfaceData); Either, JanusGraphOperationStatus> allInterfaceTypes = Either.left(interfaceDataList); when(janusGraphGenericDao - .getByCriteria(NodeTypeEnum.Interface, Collections.emptyMap(), InterfaceData.class)).thenReturn(allInterfaceTypes); + .getByCriteriaForModel(NodeTypeEnum.Interface, Collections.emptyMap(), StringUtils.EMPTY, InterfaceData.class)).thenReturn(allInterfaceTypes); List> list = new ArrayList<>(); Either>, JanusGraphOperationStatus> childrenNodes = Either.left(list); when(janusGraphGenericDao.getChildrenNodes(interfaceData.getUniqueIdKey(), interfaceData.getUniqueId(), GraphEdgeLabels.INTERFACE_OPERATION, NodeTypeEnum.InterfaceOperation, OperationData.class)).thenReturn(childrenNodes); when(janusGraphGenericDao.getParentNode(any(), any(), any(), any(), any())) .thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)); - Either, StorageOperationStatus> types = interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(); + Either, StorageOperationStatus> types = interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(StringUtils.EMPTY); Assert.assertEquals(types.left().value().size(),1); } @@ -200,10 +201,10 @@ public class InterfaceLifecycleOperationTest { when(janusGraphGenericDao.getParentNode(any(), any(), any(), any(), any())) .thenReturn(Either.left(modelNode)); when(janusGraphGenericDao - .getByCriteria(NodeTypeEnum.Interface, Collections.emptyMap(), InterfaceData.class)).thenReturn(Either.left(interfaceTypes)); + .getByCriteriaForModel(NodeTypeEnum.Interface, Collections.emptyMap(), MODEL_NAME, InterfaceData.class)).thenReturn(Either.left(interfaceTypes)); when(janusGraphGenericDao.getChildrenNodes(interfaceData.getUniqueIdKey(), interfaceData.getUniqueId(), GraphEdgeLabels.INTERFACE_OPERATION, NodeTypeEnum.InterfaceOperation, OperationData.class)).thenReturn(Either.left(Collections.emptyList())); - Assert.assertEquals(1, interfaceLifecycleOperation.getAllInterfaceLifecycleTypes().left().value().size()); + Assert.assertEquals(1, interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(MODEL_NAME).left().value().size()); } } diff --git a/catalog-ui/src/app/ng2/pages/composition/graph/connection-wizard/relationship-operations-step/relationship-operations-step.component.ts b/catalog-ui/src/app/ng2/pages/composition/graph/connection-wizard/relationship-operations-step/relationship-operations-step.component.ts index d595c2b8f6..c093029033 100644 --- a/catalog-ui/src/app/ng2/pages/composition/graph/connection-wizard/relationship-operations-step/relationship-operations-step.component.ts +++ b/catalog-ui/src/app/ng2/pages/composition/graph/connection-wizard/relationship-operations-step/relationship-operations-step.component.ts @@ -64,7 +64,7 @@ export class RelationshipOperationsStepComponent implements OnInit, IStepCompone } private loadInterfaceTypeMap(): void { - this.componentService.getInterfaceTypes(null).subscribe(response => { + this.componentService.getInterfaceTypes(this.component).subscribe(response => { for (const interfaceType in response) { let operationList = response[interfaceType]; //ignore interfaceTypes that doesn't contain operations diff --git a/catalog-ui/src/app/ng2/services/component-services/component.service.ts b/catalog-ui/src/app/ng2/services/component-services/component.service.ts index d406cf05f6..5d7b37f0fa 100644 --- a/catalog-ui/src/app/ng2/services/component-services/component.service.ts +++ b/catalog-ui/src/app/ng2/services/component-services/component.service.ts @@ -210,7 +210,7 @@ export class ComponentServiceNg2 { } getInterfaceTypes(component:Component):Observable<{[id:string]: Array}> { - return this.http.get(this.baseUrl + 'interfaceLifecycleTypes') + return this.http.get(this.baseUrl + 'interfaceLifecycleTypes' + ((component && component.model) ? '?model=' + component.model : '')) .map((res: any) => { const interfaceMap = {}; if (!res) { -- cgit 1.2.3-korg