diff options
Diffstat (limited to 'catalog-be/src')
11 files changed, 70 insertions, 52 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; diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogicTest.java index 2baafdc9cb..d3a27a8615 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogicTest.java @@ -21,8 +21,16 @@ */ package org.openecomp.sdc.be.components.impl; +import static com.google.common.collect.Sets.newHashSet; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; + import com.google.common.collect.ImmutableMap; import fj.data.Either; +import java.util.Arrays; +import java.util.List; +import java.util.Set; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -44,17 +52,6 @@ import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.model.operations.impl.PolicyTypeOperation; import org.openecomp.sdc.exception.ResponseFormat; -import java.util.Arrays; -import java.util.List; -import java.util.Set; - -import static com.google.common.collect.Sets.newHashSet; -import static java.util.Collections.emptyList; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.anySet; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.when; - @RunWith(MockitoJUnitRunner.class) public class PolicyTypeBusinessLogicTest { @@ -89,7 +86,7 @@ public class PolicyTypeBusinessLogicTest { ResponseFormat userNotExistResponse = new ResponseFormat(); when(userValidations.validateUserExists(eq(USER_ID))).thenThrow(new ByResponseFormatComponentException(userNotExistResponse)); try{ - testInstance.getAllPolicyTypes(USER_ID, COMPONENT_TYPE); + testInstance.getAllPolicyTypes(USER_ID, COMPONENT_TYPE, null); }catch(ByResponseFormatComponentException e){ assertThat(e.getResponseFormat()).isSameAs(userNotExistResponse); } @@ -98,8 +95,7 @@ public class PolicyTypeBusinessLogicTest { @Test public void getAllPolicyTypes_whenExcludePolicyTypesSetIsNull_passNullExcludedTypesSet() { when(ConfigurationManager.getConfigurationManager().getConfiguration().getExcludedPolicyTypesMapping()).thenCallRealMethod(); - when(policyTypeOperation.getAllPolicyTypes(anySet())).thenReturn(emptyList()); - List<PolicyTypeDefinition> allPolicyTypes = testInstance.getAllPolicyTypes(USER_ID, COMPONENT_TYPE); + List<PolicyTypeDefinition> allPolicyTypes = testInstance.getAllPolicyTypes(USER_ID, COMPONENT_TYPE, null); assertThat(allPolicyTypes).isEmpty(); } @@ -108,16 +104,16 @@ public class PolicyTypeBusinessLogicTest { List<PolicyTypeDefinition> policyTypes = Arrays.asList(new PolicyTypeBuilder().setUniqueId("id1").build(), new PolicyTypeBuilder().setUniqueId("id2").build(), new PolicyTypeBuilder().setUniqueId("id3").build()); - when(policyTypeOperation.getAllPolicyTypes(EXCLUDED_POLICY_TYPES)).thenReturn(policyTypes); - List<PolicyTypeDefinition> allPolicyTypes = testInstance.getAllPolicyTypes(USER_ID, COMPONENT_TYPE); + when(policyTypeOperation.getAllPolicyTypes(EXCLUDED_POLICY_TYPES, null)).thenReturn(policyTypes); + List<PolicyTypeDefinition> allPolicyTypes = testInstance.getAllPolicyTypes(USER_ID, COMPONENT_TYPE, null); assertThat(allPolicyTypes).isSameAs(policyTypes); } @Test public void getAllPolicyTypes_noPolicyTypes() { - when(policyTypeOperation.getAllPolicyTypes(EXCLUDED_POLICY_TYPES)).thenThrow(new StorageException(StorageOperationStatus.NOT_FOUND)); + when(policyTypeOperation.getAllPolicyTypes(EXCLUDED_POLICY_TYPES, null)).thenThrow(new StorageException(StorageOperationStatus.NOT_FOUND)); try { - testInstance.getAllPolicyTypes(USER_ID, COMPONENT_TYPE); + testInstance.getAllPolicyTypes(USER_ID, COMPONENT_TYPE, null); }catch(StorageException e){ assertThat(e.getStorageOperationStatus()).isSameAs(StorageOperationStatus.NOT_FOUND); } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/GroupTypesEndpointTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/GroupTypesEndpointTest.java index 1e4e56cb0d..e3de541376 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/GroupTypesEndpointTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/GroupTypesEndpointTest.java @@ -35,7 +35,6 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.stream.Stream; import javax.ws.rs.client.Invocation; import javax.ws.rs.core.GenericType; import javax.ws.rs.core.MediaType; @@ -134,9 +133,9 @@ class GroupTypesEndpointTest extends JerseySpringBaseTest { @BeforeEach public void before() throws Exception { super.setUp(); - when(userValidations.validateUserExists(eq(USER_ID))).thenReturn(user); + when(userValidations.validateUserExists(USER_ID)).thenReturn(user); when( - janusGraphGenericDao.getByCriteriaWithPredicate(eq(NodeTypeEnum.GroupType), any(), eq(GroupTypeData.class))) + janusGraphGenericDao.getByCriteriaWithPredicate(eq(NodeTypeEnum.GroupType), any(), eq(GroupTypeData.class), any())) .thenReturn(Either.left(buildGroupTypeDataList())); } @@ -171,16 +170,15 @@ class GroupTypesEndpointTest extends JerseySpringBaseTest { void getGroupTypes_validUser_Success() { List<GroupTypeDefinition> testConfigGroupTypes = buildGroupTypesList(); List<GroupTypeDefinition> fetchedGroupTypes = buildGetGroupTypesCall(USER_ID, COMPONENT_TYPE) - .get(new GenericType<List<GroupTypeDefinition>>() { - }); + .get(new GenericType<>() {}); verifyGroupTypesList(testConfigGroupTypes, fetchedGroupTypes); } @Test - void getGroupTypes_whenNoInteranlComponentType_passEmptyAsExcludedTypes() { + void getGroupTypes_whenNoInternalComponentType_passEmptyAsExcludedTypes() { List<GroupTypeDefinition> testConfigGroupTypes = buildGroupTypesList(); List<GroupTypeDefinition> fetchedGroupTypes = buildGetGroupTypesCallNoInternalComponent(USER_ID) - .get(new GenericType<List<GroupTypeDefinition>>() { + .get(new GenericType<>() { }); verifyGroupTypesList(testConfigGroupTypes, fetchedGroupTypes); } @@ -261,9 +259,4 @@ class GroupTypesEndpointTest extends JerseySpringBaseTest { return asList(gt1, gt2); } - private GroupTypeDefinition[] listOfEmptyGroupTypes(int size) { - return Stream.generate(GroupTypeDefinition::new).limit(size).toArray(GroupTypeDefinition[]::new); - } - - } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/PolicyTypesEndpointTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/PolicyTypesEndpointTest.java index 34377b05cb..89d10322ed 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/PolicyTypesEndpointTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/PolicyTypesEndpointTest.java @@ -75,7 +75,7 @@ class PolicyTypesEndpointTest extends JerseySpringBaseTest { @Test void getPolicyTypes() { List<PolicyTypeDefinition> policyTypes = buildPolicyTypesList(); - when(policyTypeBusinessLogic.getAllPolicyTypes(USER_ID, COMPONENT_TYPE)).thenReturn(policyTypes); + when(policyTypeBusinessLogic.getAllPolicyTypes(USER_ID, COMPONENT_TYPE, null)).thenReturn(policyTypes); when(componentUtils.getResponseFormat(ActionStatus.OK)).thenReturn(new ResponseFormat(HttpStatus.SC_OK)); List<PolicyTypeDefinition> fetchedPolicyTypes = buildGetPolicyTypesCall() .get(new GenericType<List<PolicyTypeDefinition>>() { @@ -86,7 +86,7 @@ class PolicyTypesEndpointTest extends JerseySpringBaseTest { @Test void getPolicyTypes_whenNoInternalComponent_passNullAsComponentType() { List<PolicyTypeDefinition> policyTypes = buildPolicyTypesList(); - when(policyTypeBusinessLogic.getAllPolicyTypes(USER_ID, null)).thenReturn(policyTypes); + when(policyTypeBusinessLogic.getAllPolicyTypes(USER_ID, null, null)).thenReturn(policyTypes); when(componentUtils.getResponseFormat(ActionStatus.OK)).thenReturn(new ResponseFormat(HttpStatus.SC_OK)); List<PolicyTypeDefinition> fetchedPolicyTypes = buildGetPolicyTypesCallNoInternalComponent() .get(new GenericType<List<PolicyTypeDefinition>>() { |