From ab6a90df6444ef7282fe9de8fe8107641bf7082f Mon Sep 17 00:00:00 2001 From: MichaelMorris Date: Fri, 28 May 2021 12:29:13 +0100 Subject: Support adding capability types to model Signed-off-by: MichaelMorris Issue-ID: SDC-3612 Change-Id: I5d3713ba420c2392dd232b5651aef4d51560ab4a --- .../be/components/impl/CapabilityTypeImportManager.java | 16 +++++++++++----- .../openecomp/sdc/be/servlets/TypesUploadServlet.java | 9 +++++---- 2 files changed, 16 insertions(+), 9 deletions(-) (limited to 'catalog-be/src/main/java/org/openecomp') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CapabilityTypeImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CapabilityTypeImportManager.java index df7650f24a..4ce08ea74a 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CapabilityTypeImportManager.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CapabilityTypeImportManager.java @@ -22,11 +22,13 @@ package org.openecomp.sdc.be.components.impl; import fj.data.Either; import java.util.List; import java.util.Map; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.model.CapabilityTypeDefinition; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.model.operations.impl.CapabilityTypeOperation; +import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder; import org.openecomp.sdc.be.model.utils.TypeCompareUtils; import org.openecomp.sdc.be.utils.TypeUtils; import org.openecomp.sdc.common.log.wrappers.Logger; @@ -47,19 +49,23 @@ public class CapabilityTypeImportManager { this.commonImportManager = commonImportManager; } - public Either>, ResponseFormat> createCapabilityTypes(String capabilityTypesYml) { - return commonImportManager.createElementTypes(capabilityTypesYml, this::createCapabilityTypesFromYml, this::upsertCapabilityTypesByDao, + public Either>, ResponseFormat> createCapabilityTypes(final String capabilityTypesYml, final String modelName) { + return commonImportManager.createElementTypes(capabilityTypesYml, capabilityTypesFromYml -> createCapabilityTypesFromYml(capabilityTypesYml, modelName), this::upsertCapabilityTypesByDao, CommonImportManager.ElementTypeEnum.CAPABILITY_TYPE); } - private Either, ActionStatus> createCapabilityTypesFromYml(String capabilityTypesYml) { - return commonImportManager.createElementTypesFromYml(capabilityTypesYml, this::createCapabilityType); + private Either, ActionStatus> createCapabilityTypesFromYml(final String capabilityTypesYml, final String modelName) { + final Either, ActionStatus> capabilityTypes = commonImportManager.createElementTypesFromYml(capabilityTypesYml, this::createCapabilityType); + if (capabilityTypes.isLeft() && StringUtils.isNotEmpty(modelName)){ + capabilityTypes.left().value().forEach(capabilityType -> capabilityType.setModel(modelName)); + } + return capabilityTypes; } private Either>, ResponseFormat> upsertCapabilityTypesByDao( List capabilityTypesToCreate) { return commonImportManager.createElementTypesByDao(capabilityTypesToCreate, capabilityType -> Either.left(ActionStatus.OK), - capabilityType -> new ImmutablePair<>(CommonImportManager.ElementTypeEnum.CAPABILITY_TYPE, capabilityType.getType()), + capabilityType -> new ImmutablePair<>(CommonImportManager.ElementTypeEnum.CAPABILITY_TYPE, UniqueIdBuilder.buildCapabilityTypeUid(capabilityType.getModel(), capabilityType.getType())), capabilityTypeOperation::getCapabilityType, capabilityTypeOperation::addCapabilityType, this::updateCapabilityType); } 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 fed26cccde..9656550f95 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 @@ -130,10 +130,11 @@ public class TypesUploadServlet extends AbstractValidationsServlet { @ApiResponse(responseCode = "409", description = "Capability Type already exist")}) @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE) public Response uploadCapabilityType(@Parameter(description = "FileInputStream") @FormDataParam("capabilityTypeZip") File file, - @Context final HttpServletRequest request, @HeaderParam("USER_ID") String creator) { - ConsumerTwoParam, String> createElementsMethod = (responseWrapper, ymlPayload) -> createElementsType(responseWrapper, - () -> capabilityTypeImportManager.createCapabilityTypes(ymlPayload)); - return uploadElementTypeServletLogic(createElementsMethod, file, request, creator, NodeTypeEnum.CapabilityType.name()); + @Context final HttpServletRequest request, @HeaderParam("USER_ID") String creator, + @Parameter(description = "model") @FormDataParam("model") String modelName) { + ConsumerThreeParam, String, String> createElementsMethod = (responseWrapper, ymlPayload, model) -> createElementsType(responseWrapper, + () -> capabilityTypeImportManager.createCapabilityTypes(ymlPayload, modelName)); + return uploadElementTypeServletLogic(createElementsMethod, file, request, creator, NodeTypeEnum.CapabilityType.name(), modelName); } @POST -- cgit 1.2.3-korg