diff options
23 files changed, 220 insertions, 120 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>>() { diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphGenericDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphGenericDao.java index 19f78ced24..c6ad5f2c26 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphGenericDao.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphGenericDao.java @@ -851,7 +851,7 @@ public class JanusGraphGenericDao { public <T extends GraphNode> Either<List<T>, JanusGraphOperationStatus> getByCriteriaWithPredicate(NodeTypeEnum type, Map<String, Entry<JanusGraphPredicate, Object>> props, - Class<T> clazz) { + Class<T> clazz, String modelName) { Either<JanusGraph, JanusGraphOperationStatus> graph = janusGraphClient.getGraph(); if (graph.isLeft()) { try { @@ -871,7 +871,11 @@ public class JanusGraphGenericDao { if (vertices == null) { return Either.right(JanusGraphOperationStatus.NOT_FOUND); } - Iterator<JanusGraphVertex> iterator = vertices.iterator(); + final Predicate<? super JanusGraphVertex> filterPredicate = + StringUtils.isEmpty(modelName) ? this::vertexNotConnectedToAnyModel : vertex -> vertexValidForModel(vertex, modelName); + final List<JanusGraphVertex> verticesForModel = StreamSupport.stream(vertices.spliterator(), false).filter(filterPredicate) + .collect(Collectors.toList()); + Iterator<JanusGraphVertex> iterator = verticesForModel.iterator(); List<T> result = new ArrayList<>(); while (iterator.hasNext()) { Vertex vertex = iterator.next(); diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphUtils.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphUtils.java index 1e62a952cf..941e13af6b 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphUtils.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphUtils.java @@ -19,7 +19,6 @@ */ package org.openecomp.sdc.be.dao.janusgraph; -import static java.util.Collections.emptyMap; import static org.apache.commons.collections.CollectionUtils.isEmpty; import static org.janusgraph.core.attribute.Contain.NOT_IN; @@ -36,7 +35,7 @@ public class JanusGraphUtils { public static <T> Map<String, Entry<JanusGraphPredicate, Object>> buildNotInPredicate(String propKey, Collection<T> notInCollection) { if (isEmpty(notInCollection)) { - return emptyMap(); + return new HashMap<>(); } Map<String, Entry<JanusGraphPredicate, Object>> predicateCriteria = new HashMap<>(); predicateCriteria.put(propKey, new HashMap.SimpleEntry<>(NOT_IN, notInCollection)); diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java index d08d705a2b..bfb6cae3aa 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java @@ -206,6 +206,9 @@ public abstract class ToscaElementOperation extends BaseOperation { } } if (result == null) { + result = createModelEdge(previousToscaElement, nextToscaElement, user, createdToscaElementVertex); + } + if (result == null) { status = janusGraphDao.createEdge(user.getVertex(), createdToscaElementVertex.getVertex(), EdgeLabelEnum.LAST_MODIFIER, new HashMap<>()); if (status != JanusGraphOperationStatus.OK) { CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, @@ -260,6 +263,33 @@ public abstract class ToscaElementOperation extends BaseOperation { return result; } + /** + * Creates the MODEL in case it exits on the previous version + * @param previousToscaElement previous element version + * @param nextToscaElement latest element version + * @param user user + * @param createdToscaElementVertex created tosca element + * @return + */ + private Either<GraphVertex, StorageOperationStatus> createModelEdge(final GraphVertex previousToscaElement, + final GraphVertex nextToscaElement, GraphVertex user, + final GraphVertex createdToscaElementVertex) { + Either<GraphVertex, StorageOperationStatus> result = null; + final Either<GraphVertex, JanusGraphOperationStatus> modelElementVertexResponse = janusGraphDao + .getParentVertex(previousToscaElement, EdgeLabelEnum.MODEL, JsonParseFlagEnum.NoParse); + if (modelElementVertexResponse.isLeft()) { + final JanusGraphOperationStatus status = janusGraphDao + .createEdge(nextToscaElement.getVertex(), createdToscaElementVertex.getVertex(), EdgeLabelEnum.MODEL, new HashMap<>()); + if (JanusGraphOperationStatus.OK != status) { + CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, + FAILED_TO_CREATE_EDGE_WITH_LABEL_FROM_USER_VERTEX_TO_TOSCA_ELEMENT_VERTEX_ON_GRAPH_STATUS_IS, EdgeLabelEnum.MODEL, + user.getUniqueId(), nextToscaElement.getMetadataProperty(GraphPropertyEnum.NORMALIZED_NAME), status); + result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); + } + } + return result; + } + protected JanusGraphOperationStatus setLastModifierFromGraph(GraphVertex componentV, ToscaElement toscaElement) { Either<GraphVertex, JanusGraphOperationStatus> parentVertex = janusGraphDao .getParentVertex(componentV, EdgeLabelEnum.LAST_MODIFIER, JsonParseFlagEnum.NoParse); diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java index 814ac01eac..25bac1642c 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java @@ -43,7 +43,9 @@ import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.function.BiPredicate; +import java.util.function.Predicate; import java.util.stream.Collectors; +import java.util.stream.StreamSupport; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; @@ -531,8 +533,12 @@ public class ToscaOperationFacade { if (vertex.isRight() || Objects.isNull(vertex.left().value())) { return Optional.empty(); } + return getElementModelVertex(model, vertex.left().value()); + } + + private Optional<GraphVertex> getElementModelVertex(final String model, final GraphVertex vertex) { final Either<List<GraphVertex>, JanusGraphOperationStatus> nodeModelVertices = janusGraphDao - .getParentVertices(vertex.left().value(), EdgeLabelEnum.MODEL_ELEMENT, JsonParseFlagEnum.NoParse); + .getParentVertices(vertex, EdgeLabelEnum.MODEL_ELEMENT, JsonParseFlagEnum.NoParse); if (nodeModelVertices.isRight() || Objects.isNull(nodeModelVertices.left().value())) { return Optional.empty(); } @@ -1884,7 +1890,8 @@ public class ToscaOperationFacade { } private Either<List<Service>, StorageOperationStatus> getLatestVersionNonCheckoutServicesMetadataOnly(Map<GraphPropertyEnum, Object> hasProps, - Map<GraphPropertyEnum, Object> hasNotProps) { + Map<GraphPropertyEnum, Object> hasNotProps, + String modelName) { List<Service> services = new ArrayList<>(); List<LifecycleStateEnum> states = new ArrayList<>(); // include props @@ -1895,30 +1902,27 @@ public class ToscaOperationFacade { hasNotProps.put(GraphPropertyEnum.STATE, states); hasNotProps.put(GraphPropertyEnum.IS_DELETED, true); hasNotProps.put(GraphPropertyEnum.IS_ARCHIVED, true); - return fetchServicesByCriteria(services, hasProps, hasNotProps); + return fetchServicesByCriteria(services, hasProps, hasNotProps, modelName); } private Either<List<Component>, StorageOperationStatus> getLatestVersionNotAbstractToscaElementsMetadataOnly(boolean isAbstract, ComponentTypeEnum componentTypeEnum, String internalComponentType, - VertexTypeEnum vertexType) { + VertexTypeEnum vertexType, + String modelName) { List<Service> services = null; Map<GraphPropertyEnum, Object> hasProps = new EnumMap<>(GraphPropertyEnum.class); Map<GraphPropertyEnum, Object> hasNotProps = new EnumMap<>(GraphPropertyEnum.class); fillPropsMap(hasProps, hasNotProps, internalComponentType, componentTypeEnum, isAbstract, vertexType); Either<List<GraphVertex>, JanusGraphOperationStatus> getRes = janusGraphDao .getByCriteria(vertexType, hasProps, hasNotProps, JsonParseFlagEnum.ParseMetadata); - if (getRes.isRight()) { - if (getRes.right().value().equals(JanusGraphOperationStatus.NOT_FOUND)) { - return Either.left(new ArrayList<>()); - } else { - return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(getRes.right().value())); - } + if (getRes.isRight() && !JanusGraphOperationStatus.NOT_FOUND.equals(getRes.right().value())) { + return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(getRes.right().value())); } // region -> Fetch non checked-out services if (internalComponentType != null && internalComponentType.toLowerCase().trim().equals(SERVICE) && VertexTypeEnum.NODE_TYPE == vertexType) { Either<List<Service>, StorageOperationStatus> result = getLatestVersionNonCheckoutServicesMetadataOnly( - new EnumMap<>(GraphPropertyEnum.class), new EnumMap<>(GraphPropertyEnum.class)); + new EnumMap<>(GraphPropertyEnum.class), new EnumMap<>(GraphPropertyEnum.class), modelName); if (result.isRight()) { log.debug("Failed to fetch services for"); return Either.right(result.right().value()); @@ -1932,15 +1936,17 @@ public class ToscaOperationFacade { List<Component> nonAbstractLatestComponents = new ArrayList<>(); ComponentParametersView params = new ComponentParametersView(true); params.setIgnoreAllVersions(false); - for (GraphVertex vertexComponent : getRes.left().value()) { - Either<ToscaElement, StorageOperationStatus> componentRes = topologyTemplateOperation - .getLightComponent(vertexComponent, componentTypeEnum, params); - if (componentRes.isRight()) { - log.debug("Failed to fetch light element for {} error {}", vertexComponent.getUniqueId(), componentRes.right().value()); - return Either.right(componentRes.right().value()); - } else { - Component component = ModelConverter.convertFromToscaElement(componentRes.left().value()); - nonAbstractLatestComponents.add(component); + if (getRes.isLeft()) { + for (GraphVertex vertexComponent : getVerticesForModel(modelName, getRes.left().value())) { + Either<ToscaElement, StorageOperationStatus> componentRes = topologyTemplateOperation + .getLightComponent(vertexComponent, componentTypeEnum, params); + if (componentRes.isRight()) { + log.debug("Failed to fetch light element for {} error {}", vertexComponent.getUniqueId(), componentRes.right().value()); + return Either.right(componentRes.right().value()); + } else { + Component component = ModelConverter.convertFromToscaElement(componentRes.left().value()); + nonAbstractLatestComponents.add(component); + } } } if (CollectionUtils.isNotEmpty(services)) { @@ -2034,7 +2040,7 @@ public class ToscaOperationFacade { private Either<List<String>, StorageOperationStatus> getComponentUids(boolean isAbstract, ComponentTypeEnum componentTypeEnum, String internalComponentType) { Either<List<Component>, StorageOperationStatus> getToscaElementsRes = getLatestVersionNotAbstractMetadataOnly(isAbstract, componentTypeEnum, - internalComponentType); + internalComponentType, null); if (getToscaElementsRes.isRight()) { return Either.right(getToscaElementsRes.right().value()); } @@ -2178,12 +2184,13 @@ public class ToscaOperationFacade { public Either<List<Component>, StorageOperationStatus> getLatestVersionNotAbstractMetadataOnly(boolean isAbstract, ComponentTypeEnum componentTypeEnum, - String internalComponentType) { + String internalComponentType, + String modelName) { List<VertexTypeEnum> internalVertexTypes = getInternalVertexTypes(componentTypeEnum, internalComponentType); List<Component> result = new ArrayList<>(); for (VertexTypeEnum vertexType : internalVertexTypes) { Either<List<Component>, StorageOperationStatus> listByVertexType = getLatestVersionNotAbstractToscaElementsMetadataOnly(isAbstract, - componentTypeEnum, internalComponentType, vertexType); + componentTypeEnum, internalComponentType, vertexType, modelName); if (listByVertexType.isRight()) { return listByVertexType; } @@ -2533,7 +2540,7 @@ public class ToscaOperationFacade { for (DistributionStatusEnum state : distStatus) { propertiesToMatch.put(GraphPropertyEnum.DISTRIBUTION_STATUS, state.name()); Either<List<Service>, StorageOperationStatus> fetchServicesByCriteria = fetchServicesByCriteria(servicesAll, propertiesToMatch, - propertiesNotToMatch); + propertiesNotToMatch, null); if (fetchServicesByCriteria.isRight()) { return fetchServicesByCriteria; } else { @@ -2542,13 +2549,14 @@ public class ToscaOperationFacade { } return Either.left(servicesAll); } else { - return fetchServicesByCriteria(servicesAll, propertiesToMatch, propertiesNotToMatch); + return fetchServicesByCriteria(servicesAll, propertiesToMatch, propertiesNotToMatch, null); } } private Either<List<Service>, StorageOperationStatus> fetchServicesByCriteria(List<Service> servicesAll, Map<GraphPropertyEnum, Object> propertiesToMatch, - Map<GraphPropertyEnum, Object> propertiesNotToMatch) { + Map<GraphPropertyEnum, Object> propertiesNotToMatch, + String modelName) { Either<List<GraphVertex>, JanusGraphOperationStatus> getRes = janusGraphDao .getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseAll); if (getRes.isRight()) { @@ -2559,7 +2567,7 @@ public class ToscaOperationFacade { return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(getRes.right().value())); } } else { - for (GraphVertex vertex : getRes.left().value()) { + for (final GraphVertex vertex : getVerticesForModel(modelName, getRes.left().value())) { Either<ToscaElement, StorageOperationStatus> getServiceRes = topologyTemplateOperation .getLightComponent(vertex, ComponentTypeEnum.SERVICE, new ComponentParametersView(true)); if (getServiceRes.isRight()) { @@ -2574,6 +2582,27 @@ public class ToscaOperationFacade { return Either.left(servicesAll); } + private List<GraphVertex> getVerticesForModel(final String modelName, final List<GraphVertex> graphVertexList) { + final Predicate<? super GraphVertex> filterPredicate = + StringUtils.isEmpty(modelName) ? this::vertexNotConnectedToAnyModel + : graphVertex -> vertexValidForModel(graphVertex, modelName).isPresent(); + return StreamSupport.stream(graphVertexList.spliterator(), false).filter(filterPredicate).collect(Collectors.toList()); + } + + private boolean vertexNotConnectedToAnyModel(final GraphVertex vertex) { + return !vertex.getVertex().edges(Direction.OUT, EdgeLabelEnum.MODEL.name()).hasNext(); + } + + private Optional<GraphVertex> vertexValidForModel(final GraphVertex vertex, final String model) { + final Either<List<GraphVertex>, JanusGraphOperationStatus> nodeModelVertices = janusGraphDao + .getParentVertices(vertex, EdgeLabelEnum.MODEL, JsonParseFlagEnum.NoParse); + if (nodeModelVertices.isRight() || Objects.isNull(nodeModelVertices.left().value())) { + return Optional.empty(); + } + return nodeModelVertices.left().value().stream().filter(graphVertex -> graphVertex.getMetadataProperty(GraphPropertyEnum.MODEL).equals(model)) + .findFirst(); + } + public void rollback() { janusGraphDao.rollback(); } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IPolicyTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IPolicyTypeOperation.java index bda3e95e0b..bba124ec0d 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IPolicyTypeOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IPolicyTypeOperation.java @@ -33,5 +33,5 @@ public interface IPolicyTypeOperation { Either<PolicyTypeDefinition, StorageOperationStatus> updatePolicyType(PolicyTypeDefinition updatedPolicyType, PolicyTypeDefinition currPolicyType); - List<PolicyTypeDefinition> getAllPolicyTypes(Set<String> excludedPolicyTypes); + List<PolicyTypeDefinition> getAllPolicyTypes(Set<String> excludedPolicyTypes, String modelName); } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperation.java index 542d4cf0c0..488ab78cab 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperation.java @@ -273,13 +273,11 @@ public class GroupTypeOperation implements IGroupTypeOperation { return janusGraphGenericDao.createRelation(groupTypeData, capabilityData, GraphEdgeLabels.GROUP_TYPE_CAPABILITY, properties); } - public List<GroupTypeDefinition> getAllGroupTypes(Set<String> excludedGroupTypes) { + public List<GroupTypeDefinition> getAllGroupTypes(Set<String> excludedGroupTypes, String modelName) { Map<String, Map.Entry<JanusGraphPredicate, Object>> predicateCriteria = buildNotInPredicate(GraphPropertiesDictionary.TYPE.getProperty(), excludedGroupTypes); - List<GroupTypeData> groupTypes = janusGraphGenericDao - .getByCriteriaWithPredicate(NodeTypeEnum.GroupType, predicateCriteria, GroupTypeData.class).left() - .on(operationUtils::onJanusGraphOperationFailure); - return convertGroupTypesToDefinition(groupTypes); + return janusGraphGenericDao.getByCriteriaWithPredicate(NodeTypeEnum.GroupType, predicateCriteria, GroupTypeData.class, modelName).left() + .map(this::convertGroupTypesToDefinition).left().on(operationUtils::validateJanusGraphOperationFailure); } private List<GroupTypeDefinition> convertGroupTypesToDefinition(List<GroupTypeData> groupTypes) { diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/OperationUtils.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/OperationUtils.java index 947b2168b9..c30c39835b 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/OperationUtils.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/OperationUtils.java @@ -20,6 +20,8 @@ package org.openecomp.sdc.be.model.operations.impl; import fj.data.Either; +import java.util.Collections; +import java.util.List; import java.util.Map; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; @@ -60,4 +62,11 @@ public class OperationUtils { janusGraphDao.rollback(); throw new StorageException(status); } + + public <T> List<T> validateJanusGraphOperationFailure(final JanusGraphOperationStatus status) { + if (JanusGraphOperationStatus.NOT_FOUND.equals(status)) { + return Collections.emptyList(); + } + return onJanusGraphOperationFailure(status); + } } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperation.java index 2b3695fc13..03b531b3b1 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperation.java @@ -18,7 +18,6 @@ * ============LICENSE_END========================================================= */ package org.openecomp.sdc.be.model.operations.impl; - import static org.openecomp.sdc.be.dao.janusgraph.JanusGraphUtils.buildNotInPredicate; import fj.data.Either; @@ -95,12 +94,11 @@ public class PolicyTypeOperation extends AbstractOperation implements IPolicyTyp return updatePolicyTypeOnGraph(updatedPolicyType, currPolicyType); } - @Override - public List<PolicyTypeDefinition> getAllPolicyTypes(Set<String> excludedPolicyTypes) { + public List<PolicyTypeDefinition> getAllPolicyTypes(Set<String> excludedPolicyTypes, String modelName) { Map<String, Map.Entry<JanusGraphPredicate, Object>> predicateCriteria = buildNotInPredicate(GraphPropertiesDictionary.TYPE.getProperty(), excludedPolicyTypes); - return janusGraphGenericDao.getByCriteriaWithPredicate(NodeTypeEnum.PolicyType, predicateCriteria, PolicyTypeData.class).left() - .map(this::convertPolicyTypesToDefinition).left().on(operationUtils::onJanusGraphOperationFailure); + return janusGraphGenericDao.getByCriteriaWithPredicate(NodeTypeEnum.PolicyType, predicateCriteria, PolicyTypeData.class, modelName).left() + .map(this::convertPolicyTypesToDefinition).left().on(operationUtils::validateJanusGraphOperationFailure); } private List<PolicyTypeDefinition> convertPolicyTypesToDefinition(List<PolicyTypeData> policiesTypes) { diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperationTest.java index 9187604f66..062f668b05 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperationTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperationTest.java @@ -20,11 +20,24 @@ package org.openecomp.sdc.be.model.operations.impl; -import org.janusgraph.core.JanusGraph; -import org.janusgraph.core.JanusGraphVertex; +import static com.google.common.collect.Sets.newHashSet; +import static java.util.Arrays.asList; +import static java.util.Collections.singletonList; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import fj.data.Either; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import javax.annotation.Resource; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.tinkerpop.gremlin.structure.Edge; +import org.janusgraph.core.JanusGraph; +import org.janusgraph.core.JanusGraphVertex; import org.junit.After; import org.junit.BeforeClass; import org.junit.Test; @@ -36,7 +49,12 @@ import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels; import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary; import org.openecomp.sdc.be.datatypes.elements.GroupTypeDataDefinition; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; -import org.openecomp.sdc.be.model.*; +import org.openecomp.sdc.be.model.CapabilityDefinition; +import org.openecomp.sdc.be.model.CapabilityTypeDefinition; +import org.openecomp.sdc.be.model.ComponentInstanceProperty; +import org.openecomp.sdc.be.model.GroupTypeDefinition; +import org.openecomp.sdc.be.model.ModelTestBase; +import org.openecomp.sdc.be.model.PropertyDefinition; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.model.tosca.ToscaType; import org.openecomp.sdc.be.resources.data.CapabilityTypeData; @@ -44,18 +62,6 @@ import org.openecomp.sdc.be.resources.data.GroupTypeData; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import javax.annotation.Resource; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import static com.google.common.collect.Sets.newHashSet; -import static java.util.Arrays.asList; -import static java.util.Collections.singletonList; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.*; - @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:application-context-test.xml") public class GroupTypeOperationTest extends ModelTestBase { @@ -92,7 +98,7 @@ public class GroupTypeOperationTest extends ModelTestBase { groupTypeOperation.addGroupType(type1); groupTypeOperation.addGroupType(type2); - List<GroupTypeDefinition> allGroupTypesNoExclusion = groupTypeOperation.getAllGroupTypes(null); + List<GroupTypeDefinition> allGroupTypesNoExclusion = groupTypeOperation.getAllGroupTypes(null, null); assertThat(allGroupTypesNoExclusion) .usingElementComparatorOnFields("type", "icon", "name") .containsExactlyInAnyOrder(rootGroupDefinition, type1, type2); @@ -107,7 +113,7 @@ public class GroupTypeOperationTest extends ModelTestBase { groupTypeOperation.addGroupType(type1); groupTypeOperation.addGroupType(type2); - List<GroupTypeDefinition> allGroupTypes = groupTypeOperation.getAllGroupTypes(newHashSet("type1", "type2")); + List<GroupTypeDefinition> allGroupTypes = groupTypeOperation.getAllGroupTypes(newHashSet("type1", "type2"), null); assertThat(allGroupTypes) .usingElementComparatorOnFields("type") .containsExactly(rootGroupDefinition); diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperationTest.java index 518de1eb1d..47bc484193 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperationTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperationTest.java @@ -26,29 +26,28 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import org.janusgraph.core.JanusGraph; -import org.janusgraph.core.JanusGraphVertex; import fj.data.Either; import java.util.Iterator; import java.util.List; import java.util.stream.Stream; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; +import org.janusgraph.core.JanusGraph; +import org.janusgraph.core.JanusGraphVertex; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge; +import org.openecomp.sdc.be.dao.janusgraph.HealingJanusGraphGenericDao; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels; -import org.openecomp.sdc.be.dao.janusgraph.HealingJanusGraphGenericDao; import org.openecomp.sdc.be.datatypes.elements.PolicyTypeDataDefinition; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; import org.openecomp.sdc.be.model.ModelTestBase; import org.openecomp.sdc.be.model.PolicyTypeDefinition; import org.openecomp.sdc.be.model.PropertyDefinition; -import org.openecomp.sdc.be.model.operations.StorageException; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.resources.data.PolicyTypeData; import org.springframework.beans.factory.annotation.Autowired; @@ -156,9 +155,10 @@ public class PolicyTypeOperationTest extends ModelTestBase { .containsExactlyInAnyOrder(prop1, prop2, prop3); } - @Test(expected = StorageException.class) + @Test public void getAllPolicyTypes_noPolicies() { - policyTypeOperation.getAllPolicyTypes(null); + final List<PolicyTypeDefinition> result = policyTypeOperation.getAllPolicyTypes(null, null); + assertThat(result).isEmpty(); } @Test @@ -166,7 +166,7 @@ public class PolicyTypeOperationTest extends ModelTestBase { PolicyTypeDefinition policyType1 = createPolicyTypeDef(); PolicyTypeDefinition policyType2 = createPolicyTypeDef("tosca.policies.test1", "desc1", "tosca.policies.Root"); addPolicyTypesToDB(policyType1, policyType2); - List<PolicyTypeDefinition> allPolicyTypesWithNoExcluded = policyTypeOperation.getAllPolicyTypes(null); + List<PolicyTypeDefinition> allPolicyTypesWithNoExcluded = policyTypeOperation.getAllPolicyTypes(null, null); assertThat(allPolicyTypesWithNoExcluded).hasSize(2); assertThat(allPolicyTypesWithNoExcluded).usingElementComparatorOnFields("uniqueId", "description", "version", "type") .containsExactlyInAnyOrder(policyType1, policyType2); @@ -180,7 +180,8 @@ public class PolicyTypeOperationTest extends ModelTestBase { policyTypeOperation.addPolicyType(policyType1); policyTypeOperation.addPolicyType(policyType2); policyTypeOperation.addPolicyType(policyType3); - List<PolicyTypeDefinition> allPolicyTypes = policyTypeOperation.getAllPolicyTypes(newHashSet("tosca.policies.test1", "tosca.policies.test2")); + List<PolicyTypeDefinition> allPolicyTypes = policyTypeOperation.getAllPolicyTypes(newHashSet("tosca.policies.test1", "tosca.policies.test2"), + null); assertThat(allPolicyTypes).hasSize(1); assertThat(allPolicyTypes).usingElementComparatorOnFields("type") .containsExactly(policyType1); diff --git a/catalog-ui/src/app/models/component-metadata.ts b/catalog-ui/src/app/models/component-metadata.ts index 186cd8aa39..1cbecda2b3 100644 --- a/catalog-ui/src/app/models/component-metadata.ts +++ b/catalog-ui/src/app/models/component-metadata.ts @@ -85,6 +85,9 @@ export interface IComponentMetadata { capabilities: CapabilitiesGroup; requirements: RequirementsGroup; + // Model + model: string; + } export class ComponentMetadata implements IComponentMetadata { @@ -141,6 +144,7 @@ export class ComponentMetadata implements IComponentMetadata { public serviceRole: string; public environmentContext: string; public instantiationType: string; + public model: string; // backend lifecycleState public state: string; @@ -196,6 +200,7 @@ export class ComponentMetadata implements IComponentMetadata { this.capabilities = response.capabilities; this.requirements = response.requirements; this.categorySpecificMetadata = response.categorySpecificMetadata; + this.model = response.model; return this; } diff --git a/catalog-ui/src/app/ng2/pages/composition/palette/services/palette.service.ts b/catalog-ui/src/app/ng2/pages/composition/palette/services/palette.service.ts index ba165b0d50..5e0fb1e170 100644 --- a/catalog-ui/src/app/ng2/pages/composition/palette/services/palette.service.ts +++ b/catalog-ui/src/app/ng2/pages/composition/palette/services/palette.service.ts @@ -30,7 +30,10 @@ export class CompositionPaletteService { let params = new HttpParams(); params = params.append('internalComponentType', this.workspaceService.getMetadataType()); - + let model = this.workspaceService.metadata.model + if (model) { + params = params.append('componentModel', model); + } const loadInstances = this.http.get(this.facadeUrl, {params}); const loadGroups = this.http.get(this.baseUrl + 'groupTypes', {params}); const loadPolicies = this.http.get(this.baseUrl + 'policyTypes', {params}); |