diff options
author | MichaelMorris <michael.morris@est.tech> | 2021-05-19 17:23:13 +0100 |
---|---|---|
committer | Christophe Closset <christophe.closset@intl.att.com> | 2021-06-08 06:57:34 +0000 |
commit | 2a62c13ecfcf3fe0c22d8cd21d66d46e58105018 (patch) | |
tree | 31a8965141512adcde039c2fa1d022578fff533d /catalog-be/src/main/java | |
parent | 75cfc6b2eb67ede9e1d0d69ba1c411b534df9000 (diff) |
Support adding of relationship type to model
Signed-off-by: MichaelMorris <michael.morris@est.tech>
Issue-ID: SDC-3610
Change-Id: If315e21fa40e491cb1977dd9ceaf3e9b607e2f6f
Diffstat (limited to 'catalog-be/src/main/java')
-rw-r--r-- | catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/RelationshipTypeImportManager.java | 23 | ||||
-rw-r--r-- | catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java | 35 |
2 files changed, 44 insertions, 14 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/RelationshipTypeImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/RelationshipTypeImportManager.java index 6e4d554d98..dafd7919c1 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/RelationshipTypeImportManager.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/RelationshipTypeImportManager.java @@ -25,6 +25,7 @@ import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.model.RelationshipTypeDefinition; import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter; import org.openecomp.sdc.be.model.operations.impl.RelationshipTypeOperation; +import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder; import org.openecomp.sdc.be.utils.TypeUtils; import org.openecomp.sdc.exception.ResponseFormat; import org.springframework.beans.factory.annotation.Autowired; @@ -45,27 +46,31 @@ public class RelationshipTypeImportManager { this.componentsUtils = componentsUtils; } - public Either<List<ImmutablePair<RelationshipTypeDefinition, Boolean>>, ResponseFormat> createRelationshipTypes(String relationshipYml) { - return createRelationshipTypes(relationshipYml, false); + public Either<List<ImmutablePair<RelationshipTypeDefinition, Boolean>>, ResponseFormat> createRelationshipTypes(final String relationshipYml, final String modelName) { + return createRelationshipTypes(relationshipYml, modelName, false); } - private Either<List<ImmutablePair<RelationshipTypeDefinition, Boolean>>, ResponseFormat> createRelationshipTypes(String relationshipTypeYml, - boolean inTransaction) { + private Either<List<ImmutablePair<RelationshipTypeDefinition, Boolean>>, ResponseFormat> createRelationshipTypes(final String relationshipTypeYml, + final String modelName, final boolean inTransaction) { return commonImportManager - .createElementTypes(relationshipTypeYml, relationshipTypesFromYml -> createRelationshipTypesFromYml(relationshipTypeYml), + .createElementTypes(relationshipTypeYml, relationshipTypesFromYml -> createRelationshipTypesFromYml(relationshipTypeYml, modelName), relationshipTypesToCreate -> createRelationshipTypesByDao(relationshipTypesToCreate, inTransaction), ElementTypeEnum.RELATIONSHIP_TYPE); } - private Either<List<RelationshipTypeDefinition>, ActionStatus> createRelationshipTypesFromYml(String relationshipTypeYml) { - return commonImportManager.createElementTypesFromYml(relationshipTypeYml, this::createRelationshipType); + private Either<List<RelationshipTypeDefinition>, ActionStatus> createRelationshipTypesFromYml(final String relationshipTypeYml, final String modelName) { + final Either<List<RelationshipTypeDefinition>, ActionStatus> relationshipTypes = commonImportManager.createElementTypesFromYml(relationshipTypeYml, this::createRelationshipType); + if (relationshipTypes.isLeft()){ + relationshipTypes.left().value().forEach(relationshipType -> relationshipType.setModel(modelName)); + } + return relationshipTypes; } private Either<List<ImmutablePair<RelationshipTypeDefinition, Boolean>>, ResponseFormat> createRelationshipTypesByDao( List<RelationshipTypeDefinition> relationshipTypesToCreate, boolean inTransaction) { return commonImportManager.createElementTypesByDao(relationshipTypesToCreate, this::validateRelationshipType, - relationshipType -> new ImmutablePair<>(ElementTypeEnum.RELATIONSHIP_TYPE, relationshipType.getType()), - relationshipTypeName -> relationshipTypeOperation.getRelationshipTypeByName(relationshipTypeName).right() + relationshipType -> new ImmutablePair<>(ElementTypeEnum.RELATIONSHIP_TYPE, UniqueIdBuilder.buildRelationshipTypeUid(relationshipType.getModel(), relationshipType.getType())), + relationshipTypeUid -> relationshipTypeOperation.getRelationshipTypeByUid(relationshipTypeUid).right() .map(DaoStatusConverter::convertJanusGraphStatusToStorageStatus), relationshipType -> relationshipTypeOperation.addRelationshipType(relationshipType, inTransaction), (newRelationshipType, oldRelationshipType) -> relationshipTypeOperation 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 d98928c4e4..1ca18334c4 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 @@ -76,6 +76,7 @@ import org.openecomp.sdc.be.model.User; import org.openecomp.sdc.be.model.normatives.ToscaTypeMetadata; import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.api.Constants; +import org.openecomp.sdc.common.datastructure.FunctionalInterfaces.ConsumerThreeParam; import org.openecomp.sdc.common.datastructure.FunctionalInterfaces.ConsumerTwoParam; import org.openecomp.sdc.common.datastructure.Wrapper; import org.openecomp.sdc.common.log.wrappers.Logger; @@ -145,8 +146,9 @@ public class TypesUploadServlet extends AbstractValidationsServlet { @ApiResponse(responseCode = "409", description = "Relationship Type already exist")}) @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE) public Response uploadRelationshipType(@Parameter(description = "FileInputStream") @FormDataParam("relationshipTypeZip") File file, - @Context final HttpServletRequest request, @HeaderParam("USER_ID") String creator) { - return uploadElementTypeServletLogic(this::createRelationshipTypes, file, request, creator, NodeTypeEnum.RelationshipType.getName()); + @Context final HttpServletRequest request, @HeaderParam("USER_ID") String creator, + @Parameter(description = "model") @FormDataParam("model") String modelName) { + return uploadElementTypeServletLogic(this::createRelationshipTypes, file, request, creator, NodeTypeEnum.RelationshipType.getName(), modelName); } @POST @@ -234,7 +236,7 @@ public class TypesUploadServlet extends AbstractValidationsServlet { } private Response uploadElementTypeServletLogic(ConsumerTwoParam<Wrapper<Response>, String> createElementsMethod, File file, - final HttpServletRequest request, String creator, String elementTypeName) { + final HttpServletRequest request, String creator, String elementTypeName) { init(); String userId = initHeaderParam(creator, request, Constants.USER_ID_HEADER); try { @@ -255,6 +257,29 @@ public class TypesUploadServlet extends AbstractValidationsServlet { return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)); } } + + private Response uploadElementTypeServletLogic(final ConsumerThreeParam<Wrapper<Response>, String, String> createElementsMethod, + final File file, final HttpServletRequest request, final String creator, final String elementTypeName, final String modelName) { + init(); + final String userId = initHeaderParam(creator, request, Constants.USER_ID_HEADER); + try { + final Wrapper<String> yamlStringWrapper = new Wrapper<>(); + final String url = request.getMethod() + " " + request.getRequestURI(); + log.debug("Start handle request of {}", url); + final Wrapper<Response> responseWrapper = doUploadTypeValidations(request, userId, file); + if (responseWrapper.isEmpty()) { + fillZipContents(yamlStringWrapper, file); + } + if (responseWrapper.isEmpty()) { + createElementsMethod.accept(responseWrapper, yamlStringWrapper.getInnerElement(), modelName); + } + return responseWrapper.getInnerElement(); + } catch (final Exception e) { + log.debug("create {} failed with exception:", elementTypeName, e); + BeEcompErrorManager.getInstance().logBeRestApiGeneralError(CREATE + elementTypeName); + return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)); + } + } private Wrapper<Response> doUploadTypeValidations(final HttpServletRequest request, String userId, File file) { Wrapper<Response> responseWrapper = new Wrapper<>(); @@ -384,9 +409,9 @@ public class TypesUploadServlet extends AbstractValidationsServlet { } // relationship types - private void createRelationshipTypes(Wrapper<Response> responseWrapper, String relationshipTypesYml) { + private void createRelationshipTypes(final Wrapper<Response> responseWrapper, final String relationshipTypesYml, final String modelName) { final Supplier<Either<List<ImmutablePair<RelationshipTypeDefinition, Boolean>>, ResponseFormat>> generateElementTypeFromYml = () -> relationshipTypeImportManager - .createRelationshipTypes(relationshipTypesYml); + .createRelationshipTypes(relationshipTypesYml, modelName); buildStatusForElementTypeCreate(responseWrapper, generateElementTypeFromYml, ActionStatus.RELATIONSHIP_TYPE_ALREADY_EXIST, NodeTypeEnum.RelationshipType.name()); } |