diff options
author | vasraz <vasyl.razinkov@est.tech> | 2021-09-14 16:40:39 +0100 |
---|---|---|
committer | Michael Morris <michael.morris@est.tech> | 2021-10-05 08:23:33 +0000 |
commit | aae70f4bfb7126a6fc562604bf48fcd01d6d7af8 (patch) | |
tree | ec5e6dcbff4978c61f391586d7ff424db2a25e73 /catalog-be/src/main/java | |
parent | 71ecc57f5ccef81ee64762783d47bf47781c87f8 (diff) |
Allow multiple base types for a service
Change-Id: I2e37818a432295a6e9f795f38d730d60f66eef78
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Issue-ID: SDC-3727
Diffstat (limited to 'catalog-be/src/main/java')
-rw-r--r-- | catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogic.java | 16 | ||||
-rw-r--r-- | catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ElementServlet.java | 49 |
2 files changed, 29 insertions, 36 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogic.java index 1bffb4e789..42fa95e642 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogic.java @@ -116,7 +116,6 @@ public class ElementBusinessLogic extends BaseBusinessLogic { private static final String COMPONENT_TYPE_IS_INVALID = "Component type {} is invalid"; private static final String VALIDATION_OF_USER_ROLE_FAILED_USER_ID = "Validation of user role failed, userId {}"; private final IElementOperation elementOperation; - private final UserBusinessLogic userAdminManager; @Autowired public ElementBusinessLogic(IElementOperation elementDao, IGroupOperation groupOperation, IGroupInstanceOperation groupInstanceOperation, @@ -126,7 +125,6 @@ public class ElementBusinessLogic extends BaseBusinessLogic { super(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation, interfaceOperation, interfaceLifecycleTypeOperation, artifactToscaOperation); this.elementOperation = elementOperation; - this.userAdminManager = userAdminManager; } /** @@ -324,7 +322,7 @@ public class ElementBusinessLogic extends BaseBusinessLogic { return Either.right(responseFormat); } Boolean isCategoryUnique = categoryUniqueEither.left().value(); - if (!isCategoryUnique) { + if (Boolean.FALSE.equals(isCategoryUnique)) { log.debug("Category is not unique, name {}, componentType {}", categoryName, componentType); ResponseFormat responseFormat = componentsUtils .getResponseFormat(ActionStatus.COMPONENT_CATEGORY_ALREADY_EXISTS, componentType, categoryName); @@ -437,7 +435,7 @@ public class ElementBusinessLogic extends BaseBusinessLogic { return Either.right(responseFormat); } Boolean isSubUnique = subCategoryUniqueForCategory.left().value(); - if (!isSubUnique) { + if (Boolean.FALSE.equals(isSubUnique)) { log.debug("Sub-category is not unique for category, parent name {}, subcategory norm name {}, componentType {}", parentCategoryName, normalizedName, componentType); ResponseFormat responseFormat = componentsUtils @@ -618,7 +616,7 @@ public class ElementBusinessLogic extends BaseBusinessLogic { return Either.right(responseFormat); } Boolean isGroupingUnique = groupingUniqueForSubCategory.left().value(); - if (!isGroupingUnique) { + if (Boolean.FALSE.equals(isGroupingUnique)) { log.debug("Grouping is not unique for sub-category, parent name {}, grouping norm name {}, componentType {}", parentSubCategoryName, normalizedName, componentType); ResponseFormat responseFormat = componentsUtils @@ -902,7 +900,7 @@ public class ElementBusinessLogic extends BaseBusinessLogic { return elementOperation.getDefaultHeatTimeout(); } - public Either<Map<String, List<CatalogComponent>>, ResponseFormat> getCatalogComponents(String userId, List<OriginTypeEnum> excludeTypes) { + public Either<Map<String, List<CatalogComponent>>, ResponseFormat> getCatalogComponents(List<OriginTypeEnum> excludeTypes) { try { return toscaOperationFacade.getCatalogOrArchiveComponents(true, excludeTypes) .bimap(this::groupByComponentType, err -> componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(err))); @@ -1120,7 +1118,7 @@ public class ElementBusinessLogic extends BaseBusinessLogic { } CategoryData categoryData = categoryResult.left().value(); Either<List<ImmutablePair<SubCategoryData, GraphEdge>>, JanusGraphOperationStatus> childrenNodes = janusGraphGenericDao - .getChildrenNodes(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.ResourceNewCategory), (String) categoryData.getUniqueId(), + .getChildrenNodes(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.ResourceNewCategory), categoryData.getUniqueId(), GraphEdgeLabels.SUB_CATEGORY, NodeTypeEnum.ResourceSubcategory, SubCategoryData.class); if (childrenNodes.isRight()) { return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(childrenNodes.right().value())); @@ -1280,14 +1278,14 @@ public class ElementBusinessLogic extends BaseBusinessLogic { } } - public CatalogUpdateTimestamp getCatalogUpdateTime(String userId) { + public CatalogUpdateTimestamp getCatalogUpdateTime() { try { return toscaOperationFacade.getCatalogTimes(); } finally { janusGraphDao.commit(); } } - + public Either<List<BaseType>, ActionStatus> getBaseTypes(final String categoryName, final String userId, final String modelName) { final ActionStatus status = validateUserExistsActionStatus(userId); if (ActionStatus.OK != status) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ElementServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ElementServlet.java index f8028583b3..45f99a931e 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ElementServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ElementServlet.java @@ -19,12 +19,20 @@ */ 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 java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; - import javax.inject.Inject; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; @@ -40,7 +48,6 @@ 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.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic; import org.openecomp.sdc.be.components.impl.ElementBusinessLogic; import org.openecomp.sdc.be.components.impl.ModelBusinessLogic; @@ -75,19 +82,6 @@ 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.Tags; - @Path("/v1/") /** * @@ -96,8 +90,8 @@ import io.swagger.v3.oas.annotations.tags.Tags; * */ @Loggable(prepend = true, value = Loggable.DEBUG, trim = false) -@Tags({@io.swagger.v3.oas.annotations.tags.Tag(name = "SDCE-2 APIs")}) -@Servers({@Server(url = "/sdc2/rest")}) +@io.swagger.v3.oas.annotations.tags.Tag(name = "SDCE-2 APIs") +@Server(url = "/sdc2/rest") @Controller public class ElementServlet extends BeGenericServlet { @@ -197,24 +191,25 @@ public class ElementServlet extends BeGenericServlet { throw e; } } - + @GET @Path("/category/{componentType}/{categoryName}/baseTypes") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Operation(description = "Get base types for category", method = "GET", summary = "Get base types for category", - responses = {@ApiResponse(responseCode = "200", description = "Returns base types Ok"), - @ApiResponse(responseCode = "404", description = "No base types were found"), - @ApiResponse(responseCode = "500", description = "Internal Server Error")}) + responses = {@ApiResponse(responseCode = "200", description = "Returns base types Ok"), + @ApiResponse(responseCode = "404", description = "No base types were found"), + @ApiResponse(responseCode = "500", description = "Internal Server Error")}) @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE) public Response getCategoryBaseTypes(@PathParam(value = "categoryName") final String categoryName, - @PathParam(value = "componentType") final String componentType, @Context final HttpServletRequest request, - @HeaderParam(value = Constants.USER_ID_HEADER) String userId, - @Parameter(description = "model", required = false) @QueryParam("model") String modelName) { + @PathParam(value = "componentType") final String componentType, + @Context final HttpServletRequest request, + @HeaderParam(value = Constants.USER_ID_HEADER) String userId, + @Parameter(description = "model", required = false) @QueryParam("model") String modelName) { try { final ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext()); final Either<List<BaseType>, ActionStatus> either = elementBL.getBaseTypes(categoryName, userId, modelName); - + if (either.isRight() || either.left().value() == null) { log.debug("No base types were found"); return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT)); @@ -553,7 +548,7 @@ public class ElementServlet extends BeGenericServlet { String url = request.getMethod() + " " + request.getRequestURI(); log.debug(START_HANDLE_REQUEST_OF, url); Either<Map<String, List<CatalogComponent>>, ResponseFormat> catalogData = getElementBL(request.getSession().getServletContext()) - .getCatalogComponents(userId, excludeTypes); + .getCatalogComponents(excludeTypes); if (catalogData.isRight()) { log.debug("failed to get catalog data"); return buildErrorResponse(catalogData.right().value()); @@ -625,7 +620,7 @@ public class ElementServlet extends BeGenericServlet { public Response getCatalogUpdateTime(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { String url = request.getMethod() + " " + request.getRequestURI(); log.debug("(post) Start handle request of {}", url); - CatalogUpdateTimestamp catalogUpdateTimestamp = getElementBL(request.getSession().getServletContext()).getCatalogUpdateTime(userId); + CatalogUpdateTimestamp catalogUpdateTimestamp = getElementBL(request.getSession().getServletContext()).getCatalogUpdateTime(); return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), catalogUpdateTimestamp); } |