From a3da4a7625f75f719a0ef1ffe1c2bef87828d2f3 Mon Sep 17 00:00:00 2001 From: davsad Date: Wed, 16 Jun 2021 10:36:24 +0100 Subject: Support for associating interface types to models Issue-ID: SDC-3639 Change-Id: I5eaa9ffbe3c88416bf17ff9a94e76faad79fe888 Signed-off-by: davsad --- .../impl/InterfaceLifecycleTypeImportManager.java | 19 ++++++++++++++----- .../openecomp/sdc/be/servlets/TypesUploadServlet.java | 5 +++-- 2 files changed, 17 insertions(+), 7 deletions(-) (limited to 'catalog-be/src/main/java/org') 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, ResponseFormat> createLifecycleTypes(String interfaceLifecycleTypesYml) { - Either, ActionStatus> interfaces = createInterfaceTypeFromYml(interfaceLifecycleTypesYml); + public Either, ResponseFormat> createLifecycleTypes(String interfaceLifecycleTypesYml, final String modelName) { + Either, 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, ActionStatus> createInterfaceTypeFromYml(final String interfaceTypesYml) { - return commonImportManager.createElementTypesFromYml(interfaceTypesYml, this::createInterfaceDefinition); + private Either, ActionStatus> createInterfaceTypeFromYml(final String interfaceTypesYml, final String modelName) { + final Either, 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, ResponseFormat> createInterfacesByDao(List 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, String> createElementsMethod = (responseWrapper, ymlPayload) -> createElementsType(responseWrapper, - () -> interfaceLifecycleTypeImportManager.createLifecycleTypes(ymlPayload)); + () -> interfaceLifecycleTypeImportManager.createLifecycleTypes(ymlPayload, modelName)); return uploadElementTypeServletLogic(createElementsMethod, file, request, creator, "Interface Types"); } -- cgit 1.2.3-korg