diff options
author | aribeiro <anderson.ribeiro@est.tech> | 2021-06-24 11:19:45 +0100 |
---|---|---|
committer | Michael Morris <michael.morris@est.tech> | 2021-07-15 13:22:58 +0000 |
commit | 4f4f7fb796475bb4a332e798c80438b33ce7712a (patch) | |
tree | 88b0f7285acfa2e49c5ba3ad3cc4b04bf9c58dc7 /catalog-be/src/main/java/org | |
parent | 53df976426f8845adf58e8ff9355764343a38549 (diff) |
Allow only types from selected model in service creation
Issue-ID: SDC-3629
Signed-off-by: aribeiro <anderson.ribeiro@est.tech>
Change-Id: I98edb8a1133b2df8d884782f3fb2758b42b94158
Diffstat (limited to 'catalog-be/src/main/java/org')
8 files changed, 49 insertions, 20 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java index d0d40e9db0..6007d0602e 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java @@ -426,11 +426,13 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic { public Either<List<Component>, ResponseFormat> getLatestVersionNotAbstractComponentsMetadata(boolean isAbstractAbstract, HighestFilterEnum highestFilter, ComponentTypeEnum componentTypeEnum, - String internalComponentType, String userId) { + String internalComponentType, String userId, + String modelName) { + Either<List<Component>, StorageOperationStatus> nonCheckoutCompResponse = null; try { validateUserExists(userId); - Either<List<Component>, StorageOperationStatus> nonCheckoutCompResponse = toscaOperationFacade - .getLatestVersionNotAbstractMetadataOnly(isAbstractAbstract, componentTypeEnum, internalComponentType); + nonCheckoutCompResponse = toscaOperationFacade + .getLatestVersionNotAbstractMetadataOnly(isAbstractAbstract, componentTypeEnum, internalComponentType, modelName); if (nonCheckoutCompResponse.isLeft()) { log.debug("Retrieved Resource successfully."); return Either.left(nonCheckoutCompResponse.left().value()); @@ -438,7 +440,9 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic { return Either .right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(nonCheckoutCompResponse.right().value()))); } finally { - janusGraphDao.commit(); + if(nonCheckoutCompResponse != null && nonCheckoutCompResponse.isLeft() ) { + janusGraphDao.commit(); + } } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeBusinessLogic.java index 4a67b09634..823612e4e1 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeBusinessLogic.java @@ -26,6 +26,7 @@ import static java.util.Collections.emptySet; import java.util.List; import java.util.Map; import java.util.Set; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; import org.openecomp.sdc.be.components.validation.UserValidations; @@ -54,13 +55,17 @@ public class GroupTypeBusinessLogic { this.componentsUtils = componentsUtils; } - public List<GroupTypeDefinition> getAllGroupTypes(String userId, String internalComponentType) { + public List<GroupTypeDefinition> getAllGroupTypes(String userId, String internalComponentType, String internalComponentModel) { + List<GroupTypeDefinition> groupTypes = null; try { userValidations.validateUserExists(userId); Set<String> excludeGroupTypes = getExcludedGroupTypes(internalComponentType); - return groupTypeOperation.getAllGroupTypes(excludeGroupTypes); + groupTypes = groupTypeOperation.getAllGroupTypes(excludeGroupTypes, internalComponentModel); + return groupTypes; } finally { - janusGraphDao.commit(); + if (CollectionUtils.isNotEmpty(groupTypes)) { + janusGraphDao.commit(); + } } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogic.java index 5a9e76cd69..99b56e7330 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogic.java @@ -54,10 +54,10 @@ public class PolicyTypeBusinessLogic { } @Transactional - public List<PolicyTypeDefinition> getAllPolicyTypes(String userId, String internalComponentType) { + public List<PolicyTypeDefinition> getAllPolicyTypes(String userId, String internalComponentType, String modelName) { Set<String> excludedPolicyTypes = getExcludedPolicyTypes(internalComponentType); userValidations.validateUserExists(userId); - return getPolicyTypes(excludedPolicyTypes); + return getPolicyTypes(excludedPolicyTypes, modelName); } public PolicyTypeDefinition getLatestPolicyTypeByType(String policyTypeName) { @@ -74,8 +74,8 @@ public class PolicyTypeBusinessLogic { return excludedTypes == null ? emptySet() : excludedTypes; } - private List<PolicyTypeDefinition> getPolicyTypes(Set<String> excludedTypes) { - return policyTypeOperation.getAllPolicyTypes(excludedTypes); + private List<PolicyTypeDefinition> getPolicyTypes(Set<String> excludedTypes, String modelName) { + return policyTypeOperation.getAllPolicyTypes(excludedTypes, modelName); } private PolicyTypeDefinition failOnPolicyType(StorageOperationStatus status, String policyType) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentServlet.java index 2df63a2124..7fd667d147 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentServlet.java @@ -75,6 +75,7 @@ import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.be.view.ResponseView; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.log.wrappers.Logger; +import org.openecomp.sdc.common.util.ValidationUtils; import org.openecomp.sdc.exception.ResponseFormat; import org.springframework.stereotype.Controller; @@ -248,6 +249,7 @@ public class ComponentServlet extends BeGenericServlet { public Response getLatestVersionNotAbstractCheckoutComponentsIdesOnly(@PathParam("componentType") final String componentType, @Context final HttpServletRequest request, @QueryParam("internalComponentType") String internalComponentType, + @QueryParam("componentModel") String internalComponentModel, @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @Parameter(description = "uid list", required = true) String data) throws IOException { @@ -256,9 +258,12 @@ public class ComponentServlet extends BeGenericServlet { try { ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType); ComponentBusinessLogic businessLogic = componentBusinessLogicProvider.getInstance(componentTypeEnum); + if (internalComponentModel != null) { + internalComponentModel = ValidationUtils.sanitizeInputString(internalComponentModel.trim()); + } Either<List<Component>, ResponseFormat> actionResponse = businessLogic - .getLatestVersionNotAbstractComponentsMetadata(false, HighestFilterEnum.HIGHEST_ONLY, componentTypeEnum, internalComponentType, - userId); + .getLatestVersionNotAbstractComponentsMetadata(false, HighestFilterEnum.HIGHEST_ONLY, componentTypeEnum, + internalComponentType, userId, internalComponentModel); if (actionResponse.isRight()) { log.debug(FAILED_TO_GET_ALL_NON_ABSTRACT, componentType); return buildErrorResponse(actionResponse.right().value()); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GroupTypesEndpoint.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GroupTypesEndpoint.java index f2cd4eee38..72dd2186d5 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GroupTypesEndpoint.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GroupTypesEndpoint.java @@ -47,6 +47,7 @@ import org.openecomp.sdc.be.model.GroupTypeDefinition; import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.be.view.ResponseView; import org.openecomp.sdc.common.api.Constants; +import org.openecomp.sdc.common.util.ValidationUtils; import org.springframework.stereotype.Controller; @Loggable(prepend = true, value = Loggable.DEBUG, trim = false) @@ -75,7 +76,14 @@ public class GroupTypesEndpoint extends BeGenericServlet { @ResponseView(mixin = {GroupTypeMixin.class}) @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE) public List<GroupTypeDefinition> getGroupTypes(@HeaderParam(value = Constants.USER_ID_HEADER) String userId, - @Parameter(description = "An optional parameter to indicate the type of the container from where this call is executed") @QueryParam("internalComponentType") String internalComponentType) { - return groupTypeBusinessLogic.getAllGroupTypes(userId, internalComponentType); + @Parameter(description = + "An optional parameter to indicate the type of the container from where this call is executed") + @QueryParam("internalComponentType") String internalComponentType, + @QueryParam("componentModel") String internalComponentModel) { + if (internalComponentModel != null) { + internalComponentModel = ValidationUtils.sanitizeInputString(internalComponentModel.trim()); + } + return groupTypeBusinessLogic + .getAllGroupTypes(userId, internalComponentType, internalComponentModel); } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/PolicyTypesEndpoint.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/PolicyTypesEndpoint.java index 4732780be9..3c69354203 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/PolicyTypesEndpoint.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/PolicyTypesEndpoint.java @@ -48,6 +48,7 @@ import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.be.view.ResponseView; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.log.wrappers.Logger; +import org.openecomp.sdc.common.util.ValidationUtils; import org.springframework.stereotype.Controller; @Loggable(prepend = true, value = Loggable.DEBUG, trim = false) @@ -78,9 +79,15 @@ public class PolicyTypesEndpoint extends BeGenericServlet { @ResponseView(mixin = {PolicyTypeMixin.class}) @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE) public List<PolicyTypeDefinition> getPolicyTypes( - @Parameter(description = "An optional parameter to indicate the type of the container from where this call is executed") @QueryParam("internalComponentType") String internalComponentType, - @Parameter(description = "The user id", required = true) @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { + @Parameter(description = "An optional parameter to indicate the type of the container from where this call is executed") + @QueryParam("internalComponentType") String internalComponentType, + @QueryParam("componentModel") String internalComponentModel, + @Parameter(description = "The user id", required = true) @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { log.debug("(get) Start handle request of GET policyTypes"); - return policyTypeBusinessLogic.getAllPolicyTypes(userId, internalComponentType); + if (internalComponentModel != null) { + internalComponentModel = ValidationUtils.sanitizeInputString(internalComponentModel.trim()); + } + return policyTypeBusinessLogic + .getAllPolicyTypes(userId, internalComponentType, internalComponentModel); } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java index 85f3a8a907..6fbdbaf217 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java @@ -303,7 +303,8 @@ public class TypesFetchServlet extends AbstractValidationsServlet { Either<List<Component>, ResponseFormat> actionResponse; List<Component> componentList; actionResponse = resourceBL - .getLatestVersionNotAbstractComponentsMetadata(isAbstract, HighestFilterEnum.HIGHEST_ONLY, ComponentTypeEnum.RESOURCE, null, userId); + .getLatestVersionNotAbstractComponentsMetadata(isAbstract, HighestFilterEnum.HIGHEST_ONLY, ComponentTypeEnum.RESOURCE, null, userId, + null); if (actionResponse.isRight()) { log.debug(FAILED_TO_GET_ALL_NON_ABSTRACT, ComponentTypeEnum.RESOURCE.getValue()); return Either.right(buildErrorResponse(actionResponse.right().value())); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java index 52ced65996..4f815a316d 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java @@ -472,7 +472,6 @@ public class ToscaExportHandler { toscaMetadata.put(JsonPresentationFields.RESOURCE_VENDOR.getPresentation(), resource.getVendorName()); toscaMetadata.put(JsonPresentationFields.RESOURCE_VENDOR_RELEASE.getPresentation(), resource.getVendorRelease()); toscaMetadata.put(JsonPresentationFields.RESOURCE_VENDOR_MODEL_NUMBER.getPresentation(), resource.getResourceVendorModelNumber()); - toscaMetadata.put(JsonPresentationFields.MODEL.getPresentation(), resource.getModel()); break; case SERVICE: Service service = (Service) component; |