aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src
diff options
context:
space:
mode:
authordavsad <david.sadlier@est.tech>2021-06-16 10:36:24 +0100
committerMichael Morris <michael.morris@est.tech>2021-07-21 14:12:28 +0000
commita3da4a7625f75f719a0ef1ffe1c2bef87828d2f3 (patch)
tree2673985092a7ae9e2fb2acccdfa48afff6b2c4f1 /catalog-be/src
parent8a312e6cf2bc0a0c539712b03e75ca3fcfe909ff (diff)
Support for associating interface types to models
Issue-ID: SDC-3639 Change-Id: I5eaa9ffbe3c88416bf17ff9a94e76faad79fe888 Signed-off-by: davsad <david.sadlier@est.tech>
Diffstat (limited to 'catalog-be/src')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceLifecycleTypeImportManager.java19
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java5
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceLifecycleTypeImportManagerTest.java2
3 files changed, 18 insertions, 8 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceLifecycleTypeImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceLifecycleTypeImportManager.java
index 1c5411434f..eb8df50d70 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceLifecycleTypeImportManager.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceLifecycleTypeImportManager.java
@@ -19,7 +19,6 @@
*/
package org.openecomp.sdc.be.components.impl;
-import fj.data.Either;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -28,8 +27,11 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;
+
import javax.annotation.Resource;
+
import org.apache.commons.collections.MapUtils;
+import org.apache.commons.lang3.StringUtils;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
import org.openecomp.sdc.be.impl.ComponentsUtils;
@@ -37,11 +39,14 @@ import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.model.Operation;
import org.openecomp.sdc.be.model.operations.api.IInterfaceLifecycleOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
import org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.stereotype.Component;
+import fj.data.Either;
+
@Component("interfaceLifecycleTypeImportManager")
public class InterfaceLifecycleTypeImportManager {
@@ -53,8 +58,8 @@ public class InterfaceLifecycleTypeImportManager {
@Resource
private CommonImportManager commonImportManager;
- public Either<List<InterfaceDefinition>, ResponseFormat> createLifecycleTypes(String interfaceLifecycleTypesYml) {
- Either<List<InterfaceDefinition>, ActionStatus> interfaces = createInterfaceTypeFromYml(interfaceLifecycleTypesYml);
+ public Either<List<InterfaceDefinition>, ResponseFormat> createLifecycleTypes(String interfaceLifecycleTypesYml, final String modelName) {
+ Either<List<InterfaceDefinition>, ActionStatus> interfaces = createInterfaceTypeFromYml(interfaceLifecycleTypesYml, modelName);
if (interfaces.isRight()) {
ActionStatus status = interfaces.right().value();
ResponseFormat responseFormat = componentsUtils.getResponseFormatByGroupType(status, null);
@@ -63,8 +68,12 @@ public class InterfaceLifecycleTypeImportManager {
return createInterfacesByDao(interfaces.left().value());
}
- private Either<List<InterfaceDefinition>, ActionStatus> createInterfaceTypeFromYml(final String interfaceTypesYml) {
- return commonImportManager.createElementTypesFromYml(interfaceTypesYml, this::createInterfaceDefinition);
+ private Either<List<InterfaceDefinition>, ActionStatus> createInterfaceTypeFromYml(final String interfaceTypesYml, final String modelName) {
+ final Either<List<InterfaceDefinition>, ActionStatus> interfaceTypes = commonImportManager.createElementTypesFromYml(interfaceTypesYml, this::createInterfaceDefinition);
+ if (interfaceTypes.isLeft() && StringUtils.isNotEmpty(modelName)){
+ interfaceTypes.left().value().forEach(interfaceType -> interfaceType.setModel(modelName));
+ }
+ return interfaceTypes;
}
private Either<List<InterfaceDefinition>, ResponseFormat> createInterfacesByDao(List<InterfaceDefinition> interfacesToCreate) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java
index 396cb42d47..0fd4206cd6 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java
@@ -162,9 +162,10 @@ public class TypesUploadServlet extends AbstractValidationsServlet {
@ApiResponse(responseCode = "409", description = "Interface Lifecycle Type already exist")})
@PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response uploadInterfaceLifecycleType(@Parameter(description = "FileInputStream") @FormDataParam("interfaceLifecycleTypeZip") File file,
- @Context final HttpServletRequest request, @HeaderParam("USER_ID") String creator) {
+ @Context final HttpServletRequest request, @HeaderParam("USER_ID") String creator,
+ @Parameter(description = "model") @FormDataParam("model") String modelName) {
ConsumerTwoParam<Wrapper<Response>, String> createElementsMethod = (responseWrapper, ymlPayload) -> createElementsType(responseWrapper,
- () -> interfaceLifecycleTypeImportManager.createLifecycleTypes(ymlPayload));
+ () -> interfaceLifecycleTypeImportManager.createLifecycleTypes(ymlPayload, modelName));
return uploadElementTypeServletLogic(createElementsMethod, file, request, creator, "Interface Types");
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceLifecycleTypeImportManagerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceLifecycleTypeImportManagerTest.java
index 21307ad608..9cd18bc9a2 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceLifecycleTypeImportManagerTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceLifecycleTypeImportManagerTest.java
@@ -84,7 +84,7 @@ public class InterfaceLifecycleTypeImportManagerTest {
public void createLifecycleTypesTest() throws IOException {
final String ymlContent = getYmlContent();
final Either<List<InterfaceDefinition>, ResponseFormat> createCapabilityTypes =
- importManager.createLifecycleTypes(ymlContent);
+ importManager.createLifecycleTypes(ymlContent, "test");
assertTrue(createCapabilityTypes.isLeft());
final List<InterfaceDefinition> interfaceDefinitionList = createCapabilityTypes.left().value();
assertThat("Interface definitions should not be empty", interfaceDefinitionList, is(not(empty())));