diff options
34 files changed, 246 insertions, 104 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java index e2c3df172d..f4daea703f 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java @@ -446,7 +446,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic { } final Component service = getServiceResult.left().value(); final Either<Component, StorageOperationStatus> getServiceDerivedFromTypeResult = toscaOperationFacade - .getLatestByToscaResourceName(service.getDerivedFromGenericType()); + .getLatestByToscaResourceName(service.getDerivedFromGenericType(), service.getModel()); if (getServiceDerivedFromTypeResult.isRight()) { throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(getServiceResult.right().value())); } @@ -2835,7 +2835,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic { final Component service = getServiceResult.left().value(); final Either<Component, StorageOperationStatus> getServiceDerivedFromTypeResult = toscaOperationFacade - .getLatestByToscaResourceName(service.getDerivedFromGenericType()); + .getLatestByToscaResourceName(service.getDerivedFromGenericType(), service.getModel()); if (getServiceDerivedFromTypeResult.isRight()) { throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(getServiceResult.right().value())); } 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 3b92e62e72..1bffb4e789 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 @@ -1288,11 +1288,11 @@ public class ElementBusinessLogic extends BaseBusinessLogic { } } - public Either<List<BaseType>, ActionStatus> getBaseTypes(final String categoryName, final String userId) { + public Either<List<BaseType>, ActionStatus> getBaseTypes(final String categoryName, final String userId, final String modelName) { final ActionStatus status = validateUserExistsActionStatus(userId); if (ActionStatus.OK != status) { return Either.right(status); } - return Either.left(elementOperation.getBaseTypes(categoryName)); + return Either.left(elementOperation.getBaseTypes(categoryName, modelName)); } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java index 4983c0160f..321ed99ae7 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java @@ -107,7 +107,7 @@ public class GroupTypeImportManager { for (String member : groupType.getMembers()) { // Verify that such Resource exist Either<org.openecomp.sdc.be.model.Resource, StorageOperationStatus> eitherMemberExist = toscaOperationFacade - .getLatestByToscaResourceName(member); + .getLatestByToscaResourceName(member, groupType.getModel()); if (eitherMemberExist.isRight()) { StorageOperationStatus operationStatus = eitherMemberExist.right().value(); log.debug("Error when fetching parent resource {}, error: {}", member, operationStatus); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeImportManager.java index d10680db0d..9fa8e303ac 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeImportManager.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeImportManager.java @@ -105,7 +105,7 @@ public class PolicyTypeImportManager { } if (result.isLeft()) { for (String targetId : policyType.getTargets()) { - boolean isValid = toscaOperationFacade.getLatestByToscaResourceName(targetId).isLeft(); + boolean isValid = toscaOperationFacade.getLatestByToscaResourceName(targetId, policyType.getModel()).isLeft(); if (!isValid) { // check if it is a groupType final Either<GroupTypeDefinition, StorageOperationStatus> groupTypeFound = groupTypeOperation .getLatestGroupTypeByType(targetId, policyType.getModel(), false); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java index c401948495..152b78b15c 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java @@ -802,7 +802,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), resource, AuditingActionEnum.CREATE_RESOURCE); throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(status), csarInfo.getCsarUUID()); } else if (StringUtils.isNotEmpty(currVfcToscaName)) { - return (Resource) toscaOperationFacade.getLatestByToscaResourceName(currVfcToscaName).left() + return (Resource) toscaOperationFacade.getLatestByToscaResourceName(currVfcToscaName, resource.getModel()).left() .on(st -> findVfcResource(csarInfo, resource, previousVfcToscaName, null, st)); } return null; @@ -1969,7 +1969,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { String nodeName, String substitutableAsNodeType) { try { for (Entry<String, NodeTypeInfo> nodeTypeEntry : nodeTypesInfo.entrySet()) { - if (nodeTypeEntry.getValue().isNested() && !nodeTypeAlreadyExists(nodeTypeEntry.getKey())) { + if (nodeTypeEntry.getValue().isNested() && !nodeTypeAlreadyExists(nodeTypeEntry.getKey(), resource.getModel())) { handleNestedVfc(resource, nodeTypesArtifactsToHandle, nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo, nodeTypeEntry.getKey()); log.trace("************* finished to create node {}", nodeTypeEntry.getKey()); @@ -1997,8 +1997,8 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } } - private boolean nodeTypeAlreadyExists(final String toscaResourceName) { - return toscaOperationFacade.getLatestByToscaResourceName(toscaResourceName).isLeft(); + private boolean nodeTypeAlreadyExists(final String toscaResourceName, String modelName) { + return toscaOperationFacade.getLatestByToscaResourceName(toscaResourceName, modelName).isLeft(); } private Either<Resource, ResponseFormat> handleVfCsarArtifacts(Resource resource, CsarInfo csarInfo, List<ArtifactDefinition> createdArtifacts, @@ -3490,7 +3490,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { final CsarInfo csarInfo, final boolean isNested, final String nodeName) { final Either<Component, StorageOperationStatus> latestByToscaName = toscaOperationFacade.getLatestByToscaResourceName( - buildNestedToscaResourceName(resource.getResourceType().name(), csarInfo.getVfResourceName(), nodeName).getRight()); + buildNestedToscaResourceName(resource.getResourceType().name(), csarInfo.getVfResourceName(), nodeName).getRight(), resource.getModel()); if (latestByToscaName.isLeft()) { final Resource nestedResource = (Resource) latestByToscaName.left().value(); log.debug(VALIDATE_DERIVED_BEFORE_UPDATE); @@ -3676,7 +3676,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { private Component getParentComponent(Resource newResource) { String toscaResourceNameDerivedFrom = newResource.getDerivedFrom().get(0); Either<Component, StorageOperationStatus> latestByToscaResourceName = toscaOperationFacade - .getLatestByToscaResourceName(toscaResourceNameDerivedFrom); + .getLatestByToscaResourceName(toscaResourceNameDerivedFrom, newResource.getModel()); if (latestByToscaResourceName.isRight()) { BeEcompErrorManager.getInstance() .logInternalDataError("mergeOldResourceMetadataWithNew", "derived from resource not found", ErrorSeverity.ERROR); @@ -4601,7 +4601,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { String currentTemplateName = currentResource.getDerivedFrom().get(0); String updatedTemplateName = updateInfoResource.getDerivedFrom().get(0); Either<Boolean, StorageOperationStatus> dataModelResponse = toscaOperationFacade - .validateToscaResourceNameExtends(currentTemplateName, updatedTemplateName); + .validateToscaResourceNameExtends(currentTemplateName, updatedTemplateName, currentResource.getModel()); if (dataModelResponse.isRight()) { StorageOperationStatus storageStatus = dataModelResponse.right().value(); BeEcompErrorManager.getInstance().logBeDaoSystemError("Create/Update Resource - validateDerivingFromExtendingType"); @@ -4905,20 +4905,20 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { log.debug("validate resource properties default values"); List<PropertyDefinition> properties = resource.getProperties(); if (properties != null) { - iterateOverProperties(properties); + iterateOverProperties(properties, resource.getModel()); } return true; } - public void iterateOverProperties(List<PropertyDefinition> properties) { + public void iterateOverProperties(List<PropertyDefinition> properties, String model) { String type = null; String innerType = null; for (PropertyDefinition property : properties) { - if (!propertyOperation.isPropertyTypeValid(property, null)) { + if (!propertyOperation.isPropertyTypeValid(property, model)) { log.info("Invalid type for property {}", property); throw new ByActionStatusComponentException(ActionStatus.INVALID_PROPERTY_TYPE, property.getType(), property.getName()); } - Map<String, DataTypeDefinition> allDataTypes = componentsUtils.getAllDataTypes(applicationDataTypeCache, property.getModel()); + Map<String, DataTypeDefinition> allDataTypes = componentsUtils.getAllDataTypes(applicationDataTypeCache, model); type = property.getType(); if (type.equals(ToscaPropertyType.LIST.getType()) || type.equals(ToscaPropertyType.MAP.getType())) { ResponseFormat responseFormat = validateMapOrListPropertyType(property, innerType, allDataTypes); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java index 9f1669c135..4f65230383 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java @@ -215,7 +215,7 @@ public class ResourceImportManager { } final Either<Resource, StorageOperationStatus> resourceEither = toscaOperationFacade.getComponentByNameAndVendorRelease(resource.getComponentType(), resource.getName(), - resource.getVendorRelease(), JsonParseFlagEnum.ParseAll); + resource.getVendorRelease(), JsonParseFlagEnum.ParseAll, resource.getModel()); if (resourceEither.isLeft() && toscaOperationFacade.isNodeAssociatedToModel(resource.getModel(), resource)) { if (resource.getModel() == null) { throw new ByActionStatusComponentException(ActionStatus.COMPONENT_WITH_VENDOR_RELEASE_ALREADY_EXISTS, @@ -528,7 +528,7 @@ public class ResourceImportManager { String derivedFrom = toscaDerivedFromElement.left().value(); log.debug("Derived from TOSCA name is {}", derivedFrom); resource.setDerivedFrom(Arrays.asList(new String[]{derivedFrom})); - Either<Resource, StorageOperationStatus> latestByToscaResourceName = toscaOperationFacade.getLatestByToscaResourceName(derivedFrom); + Either<Resource, StorageOperationStatus> latestByToscaResourceName = toscaOperationFacade.getLatestByToscaResourceName(derivedFrom, resource.getModel()); if (latestByToscaResourceName.isRight()) { StorageOperationStatus operationStatus = latestByToscaResourceName.right().value(); if (operationStatus == StorageOperationStatus.NOT_FOUND) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java index 3404323c9d..994092911f 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java @@ -313,7 +313,7 @@ public class ServiceImportParseLogic { log.debug("Error occured during fetching node type with tosca name {}, error: {}", currVfcToscaName, status); throw new ComponentException(componentsUtils.convertFromStorageResponse(status), csarInfo.getCsarUUID()); } else if (org.apache.commons.lang.StringUtils.isNotEmpty(currVfcToscaName)) { - return (Resource) toscaOperationFacade.getLatestByToscaResourceName(currVfcToscaName).left() + return (Resource) toscaOperationFacade.getLatestByToscaResourceName(currVfcToscaName, resource.getModel()).left() .on(st -> findVfcResource(csarInfo, resource, previousVfcToscaName, null, st)); } return null; @@ -1504,7 +1504,7 @@ public class ServiceImportParseLogic { String currentTemplateName = currentResource.getDerivedFrom().get(0); String updatedTemplateName = updateInfoResource.getDerivedFrom().get(0); Either<Boolean, StorageOperationStatus> dataModelResponse = toscaOperationFacade - .validateToscaResourceNameExtends(currentTemplateName, updatedTemplateName); + .validateToscaResourceNameExtends(currentTemplateName, updatedTemplateName, currentResource.getModel()); if (dataModelResponse.isRight()) { StorageOperationStatus storageStatus = dataModelResponse.right().value(); BeEcompErrorManager.getInstance().logBeDaoSystemError("Create/Update Resource - validateDerivingFromExtendingType"); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/generic/GenericTypeBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/generic/GenericTypeBusinessLogic.java index 6cf4327a99..07d71eabb4 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/generic/GenericTypeBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/generic/GenericTypeBusinessLogic.java @@ -72,7 +72,7 @@ public class GenericTypeBusinessLogic { return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERIC_TYPE_NOT_FOUND, component.assetType(), genericTypeToscaName)); } } else { - genericType = toscaOperationFacade.getByToscaResourceNameAndVersion(genericTypeToscaName, component.getDerivedFromGenericVersion()); + genericType = toscaOperationFacade.getByToscaResourceNameAndVersion(genericTypeToscaName, component.getDerivedFromGenericVersion(), component.getModel()); } Resource genericTypeResource = genericType.left().value(); 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 4efca8a2b8..f79650ddc7 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 @@ -202,11 +202,11 @@ public class ElementServlet extends BeGenericServlet { @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) { - + @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); + 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"); 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 ef5192c048..8b8c3153cf 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 @@ -220,7 +220,7 @@ public class ToscaExportHandler { if (component.getDerivedFromGenericType() != null && !component.getDerivedFromGenericType() .startsWith("org.openecomp.resource.abstract.nodes.")) { final Either<Component, StorageOperationStatus> baseType = toscaOperationFacade - .getByToscaResourceNameAndVersion(component.getDerivedFromGenericType(), component.getDerivedFromGenericVersion()); + .getByToscaResourceNameAndVersion(component.getDerivedFromGenericType(), component.getDerivedFromGenericVersion(), component.getModel()); if (baseType.isLeft() && baseType.left().value() != null) { addDependencies(imports, dependencies, baseType.left().value()); } else { diff --git a/catalog-be/src/test/java/org/openecomp/sdc/ElementOperationMock.java b/catalog-be/src/test/java/org/openecomp/sdc/ElementOperationMock.java index 5d05e65886..117ef9cc5a 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/ElementOperationMock.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/ElementOperationMock.java @@ -282,7 +282,7 @@ public class ElementOperationMock implements IElementOperation { } @Override - public List<BaseType> getBaseTypes(String categoryName) { + public List<BaseType> getBaseTypes(String categoryName, String modelName) { // TODO Auto-generated method stub return null; } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java index 00e0681c8d..1609299e66 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java @@ -110,7 +110,7 @@ public class ResourceImportManagerTest { public static void beforeClass() { importManager = new ResourceImportManager(componentsUtils, capabilityTypeOperation, interfaceDefinitionHandler); importManager.setAuditingManager(auditingManager); - when(toscaOperationFacade.getLatestByToscaResourceName(Mockito.anyString())).thenReturn(Either.left(null)); + when(toscaOperationFacade.getLatestByToscaResourceName(Mockito.anyString(), Mockito.any())).thenReturn(Either.left(null)); when(toscaOperationFacade.getLatestByToscaResourceNameAndModel(Mockito.anyString(), Mockito.any())).thenReturn(Either.left(null)); importManager.setResponseFormatManager(responseFormatManager); importManager.setResourceBusinessLogic(resourceBusinessLogic); @@ -130,7 +130,7 @@ public class ResourceImportManagerTest { Mockito.reset(auditingManager, responseFormatManager, resourceBusinessLogic, userAdmin); Either<Component, StorageOperationStatus> notFound = Either.right(StorageOperationStatus.NOT_FOUND); when(toscaOperationFacade.getComponentByNameAndVendorRelease(any(ComponentTypeEnum.class), anyString(), anyString(), - any(JsonParseFlagEnum.class))).thenReturn(notFound); + any(JsonParseFlagEnum.class), any())).thenReturn(notFound); } @Test @@ -308,7 +308,7 @@ public class ResourceImportManagerTest { setResourceBusinessLogicMock(); final Either<Component, StorageOperationStatus> foundResourceEither = Either.left(Mockito.mock(Resource.class)); when(toscaOperationFacade.getComponentByNameAndVendorRelease(any(ComponentTypeEnum.class), anyString(), anyString(), - any(JsonParseFlagEnum.class))).thenReturn(foundResourceEither); + any(JsonParseFlagEnum.class), any())).thenReturn(foundResourceEither); when(toscaOperationFacade.isNodeAssociatedToModel(eq(null), any(Resource.class))).thenReturn(true); String jsonContent = ImportUtilsTest.loadFileNameToJsonString("normative-types-new-blockStorage.yml"); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java index a2996c531d..3029bf7bc1 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java @@ -33,6 +33,7 @@ import static org.junit.jupiter.api.DynamicTest.dynamicTest; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anySet; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -1851,7 +1852,7 @@ class ComponentInstanceBusinessLogicTest { .thenReturn(Either.left(service)); when(toscaOperationFacade.getToscaFullElement(eq(ORIGIN_COMPONENT_ID))) .thenReturn(Either.left(originService)); - when(toscaOperationFacade.getLatestByToscaResourceName(eq(originService.getDerivedFromGenericType()))) + when(toscaOperationFacade.getLatestByToscaResourceName(eq(originService.getDerivedFromGenericType()), isNull())) .thenReturn(Either.left(serviceBaseComponent)); when(toscaOperationFacade.getToscaElement(eq(ORIGIN_COMPONENT_ID), any(ComponentParametersView.class))) .thenReturn(Either.left(originService)); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogicTest.java index 36eee96848..f52ae209db 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogicTest.java @@ -312,16 +312,17 @@ public class ElementBusinessLogicTest extends BaseBusinessLogicMock { List<BaseType> baseTypes = new ArrayList<>(); baseTypes.add(new BaseType("org.openecomp.type")); String categoryName = "CAT01"; + String modelName = "MODEL01"; when(userValidations.validateUserExistsActionStatus(eq(user.getUserId()))).thenReturn(ActionStatus.OK); - when(elementDao.getBaseTypes(categoryName)).thenReturn(baseTypes); - Assert.assertTrue(elementBusinessLogic.getBaseTypes(categoryName, user.getUserId()) + when(elementDao.getBaseTypes(categoryName, modelName)).thenReturn(baseTypes); + Assert.assertTrue(elementBusinessLogic.getBaseTypes(categoryName, user.getUserId(), modelName) .isLeft()); } @Test public void testGetBaseTypes_givenUserValidationFails_thenReturnsException() { when(userValidations.validateUserExistsActionStatus(eq(user.getUserId()))).thenReturn(ActionStatus.RESTRICTED_OPERATION); - Assert.assertTrue(elementBusinessLogic.getBaseTypes("CAT01", user.getUserId()).isRight()); + Assert.assertTrue(elementBusinessLogic.getBaseTypes("CAT01", user.getUserId(), null).isRight()); } }
\ No newline at end of file diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java index a2893af2ba..cfbd63363a 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java @@ -1460,7 +1460,7 @@ public class ResourceBusinessLogicTest { YamlTemplateParsingHandler yamlTemplateParser = new YamlTemplateParsingHandler(mockJanusGraphDao, null, Mockito.mock(AnnotationBusinessLogic.class), null); final ParsedToscaYamlInfo parsedToscaYamlInfo = yamlTemplateParser.parseResourceInfoFromYAML("Definitions/my_vnf.yml", resourceYml, Collections.EMPTY_MAP, Collections.EMPTY_MAP, "myVnf", resourceResponse); - when(toscaOperationFacade.getLatestByToscaResourceName(anyString())).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); + when(toscaOperationFacade.getLatestByToscaResourceName(anyString(), any())).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); Resource vduCp = new Resource(); vduCp.setToscaResourceName("tosca.nodes.nfv.VduCp"); vduCp.setState(LifecycleStateEnum.CERTIFIED); @@ -1673,7 +1673,7 @@ public class ResourceBusinessLogicTest { when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate); Either<Boolean, StorageOperationStatus> isToscaNameExtending = Either.left(true); - when(toscaOperationFacade.validateToscaResourceNameExtends(anyString(), anyString())) + when(toscaOperationFacade.validateToscaResourceNameExtends(anyString(), anyString(), anyString())) .thenReturn(isToscaNameExtending); Either<Map<String, PropertyDefinition>, StorageOperationStatus> findPropertiesOfNode = Either @@ -1703,7 +1703,7 @@ public class ResourceBusinessLogicTest { when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate); Either<Boolean, StorageOperationStatus> isToscaNameExtending = Either.left(false); - when(toscaOperationFacade.validateToscaResourceNameExtends(anyString(), anyString())) + when(toscaOperationFacade.validateToscaResourceNameExtends(anyString(), anyString(), anyString())) .thenReturn(isToscaNameExtending); resource.setVersion("1.0"); @@ -1740,7 +1740,7 @@ public class ResourceBusinessLogicTest { assertThat(createdResource).isNotNull(); Either<Resource, StorageOperationStatus> getLatestResult = Either.left(createdResource); Either<Component, StorageOperationStatus> getCompLatestResult = Either.left(createdResource); - when(toscaOperationFacade.getLatestByToscaResourceName(resourceExist.getToscaResourceName())) + when(toscaOperationFacade.getLatestByToscaResourceName(resourceExist.getToscaResourceName(), null)) .thenReturn(getCompLatestResult); when(toscaOperationFacade.getLatestByToscaResourceNameAndModel(resourceExist.getToscaResourceName(), null)) .thenReturn(getCompLatestResult); @@ -1851,9 +1851,9 @@ public class ResourceBusinessLogicTest { .getRight(); when(toscaOperationFacade.getLatestByName(resourceToUpdate.getName(), null)) .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); - when(toscaOperationFacade.getLatestByToscaResourceName(resourceToUpdate.getToscaResourceName())) + when(toscaOperationFacade.getLatestByToscaResourceName(resourceToUpdate.getToscaResourceName(), null)) .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); - when(toscaOperationFacade.getLatestByToscaResourceName(nestedResourceName)) + when(toscaOperationFacade.getLatestByToscaResourceName(nestedResourceName, null)) .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); when(toscaOperationFacade.getLatestByToscaResourceNameAndModel(resourceToUpdate.getToscaResourceName(), null)) @@ -1889,11 +1889,11 @@ public class ResourceBusinessLogicTest { .getRight(); when(toscaOperationFacade.getLatestByName(resourceToUpdate.getName(), null)) .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); - when(toscaOperationFacade.getLatestByToscaResourceName(resourceToUpdate.getToscaResourceName())) + when(toscaOperationFacade.getLatestByToscaResourceName(resourceToUpdate.getToscaResourceName(), null)) .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); when(toscaOperationFacade.getLatestByToscaResourceNameAndModel(resourceToUpdate.getToscaResourceName(), null)) .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); - when(toscaOperationFacade.getLatestByToscaResourceName(nestedResourceName)) + when(toscaOperationFacade.getLatestByToscaResourceName(nestedResourceName, null)) .thenReturn(Either.left(resourceResponse)); when(toscaOperationFacade.overrideComponent(any(Resource.class), any(Resource.class))) .thenReturn(Either.left(resourceResponse)); @@ -2283,7 +2283,7 @@ public class ResourceBusinessLogicTest { private Resource createRoot() { rootType = setupGenericTypeMock(GENERIC_ROOT_NAME); - when(toscaOperationFacade.getLatestByToscaResourceName(GENERIC_ROOT_NAME)) + when(toscaOperationFacade.getLatestByToscaResourceName(GENERIC_ROOT_NAME, null)) .thenReturn(Either.left(rootType)); return rootType; } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogicTest.java index a3232f61ce..ccc7139fa6 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogicTest.java @@ -203,7 +203,7 @@ class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBaseTestSet final Service service = createServiceObject(false); Resource resource = new Resource(); Either<Component, StorageOperationStatus> getCompLatestResult = Either.left(resource); - when(toscaOperationFacade.getLatestByToscaResourceName(anyString())) + when(toscaOperationFacade.getLatestByToscaResourceName(anyString(), any())) .thenReturn(getCompLatestResult); final CsarInfo csarInfo = getCsarInfo(); @@ -229,7 +229,7 @@ class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBaseTestSet final Service service = createServiceObject(false); Resource resource = new Resource(); Either<Component, StorageOperationStatus> getCompLatestResult = Either.left(resource); - when(toscaOperationFacade.getLatestByToscaResourceName(anyString())) + when(toscaOperationFacade.getLatestByToscaResourceName(anyString(), any())) .thenReturn(getCompLatestResult); Assertions.assertNotNull(extractedVfcsArtifacts); testSubject.findAddNodeTypeArtifactsToHandle(getCsarInfo(), nodeTypesArtifactsToHandle, service, @@ -1205,7 +1205,7 @@ class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBaseTestSet updatedDerivedFromList.add("23344567778"); updateInfoResource.setDerivedFrom(updatedDerivedFromList); - when(toscaOperationFacade.validateToscaResourceNameExtends(anyString(), anyString())) + when(toscaOperationFacade.validateToscaResourceNameExtends(anyString(), anyString(), any())) .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); Assertions.assertNotNull( @@ -1218,7 +1218,7 @@ class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBaseTestSet Resource currentResource = createParseResourceObject(true); Resource updateInfoResource = createParseResourceObject(true); - when(toscaOperationFacade.validateToscaResourceNameExtends(anyString(), anyString())) + when(toscaOperationFacade.validateToscaResourceNameExtends(anyString(), anyString(), any())) .thenReturn(Either.left(false)); Assertions.assertNotNull( diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/ForwardingPathToscaOperationFacade.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/ForwardingPathToscaOperationFacade.java index 3774332b23..3fbd84f6a4 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/ForwardingPathToscaOperationFacade.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/beans/ForwardingPathToscaOperationFacade.java @@ -55,12 +55,12 @@ public class ForwardingPathToscaOperationFacade extends ToscaOperationFacade { } @Override - public <T extends Component> Either<T, StorageOperationStatus> getLatestByToscaResourceName(String toscaResourceName) { + public <T extends Component> Either<T, StorageOperationStatus> getLatestByToscaResourceName(String toscaResourceName, String model) { if(toscaResourceName.equals(ForwardingPathUtils.FORWARDING_PATH_NODE_NAME) || toscaResourceName.equals(ForwardingPathUtils.FORWARDER_CAPABILITY)){ Resource component = new Resource(); component.setToscaResourceName(GENERIC_SERVICE_NAME); return Either.left((T)component); } - return super.getLatestByToscaResourceName(toscaResourceName); + return super.getLatestByToscaResourceName(toscaResourceName, model); } } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ElementServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ElementServletTest.java index 4d2c3621d9..c1837846f6 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ElementServletTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ElementServletTest.java @@ -1110,7 +1110,7 @@ class ElementServletTest extends JerseyTest { void getBaseTypesTest() { String path = "/v1/category/services/CAT1/baseTypes"; Either<List<BaseType>, ActionStatus> baseTypesEither = Either.left(new ArrayList<>()); - when(elementBusinessLogic.getBaseTypes("CAT1", designerUser.getUserId())) + when(elementBusinessLogic.getBaseTypes("CAT1", designerUser.getUserId(), null)) .thenReturn(baseTypesEither); Response response = target() @@ -1128,7 +1128,7 @@ class ElementServletTest extends JerseyTest { String path = "/v1/category/services/CAT1/baseTypes"; Either<List<BaseType>, ActionStatus> baseTypesEither = Either.right(ActionStatus.NO_CONTENT); - when(elementBusinessLogic.getBaseTypes("CAT1", designerUser.getUserId())) + when(elementBusinessLogic.getBaseTypes("CAT1", designerUser.getUserId(), null)) .thenReturn(baseTypesEither); Response response = target() diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java index 38c72922fd..325a003133 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java @@ -529,7 +529,7 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { component.setDerivedFromGenericType("org.typeA"); component.setDerivedFromGenericVersion("1.0"); - when(toscaOperationFacade.getByToscaResourceNameAndVersion("org.typeA", "1.0")).thenReturn(Either.left(baseType)); + when(toscaOperationFacade.getByToscaResourceNameAndVersion("org.typeA", "1.0", null)).thenReturn(Either.left(baseType)); // default test result = Deencapsulation.invoke(testSubject, "fillImports", component, toscaTemplate); diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/JanusGraphDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/JanusGraphDao.java index 3e10c7941d..76fddc070b 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/JanusGraphDao.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/JanusGraphDao.java @@ -29,8 +29,12 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.function.Predicate; +import java.util.stream.Collectors; +import java.util.stream.StreamSupport; import java.util.Optional; import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.tinkerpop.gremlin.structure.Direction; import org.apache.tinkerpop.gremlin.structure.Edge; @@ -52,6 +56,7 @@ import org.openecomp.sdc.be.dao.jsongraph.types.EdgePropertyEnum; import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum; import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum; import org.openecomp.sdc.be.dao.jsongraph.utils.JsonParserUtils; +import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum; import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition; @@ -441,20 +446,23 @@ public class JanusGraphDao { public Either<List<GraphVertex>, JanusGraphOperationStatus> getByCriteria(VertexTypeEnum type, Map<GraphPropertyEnum, Object> props, Map<GraphPropertyEnum, Object> hasNotProps, - JsonParseFlagEnum parseFlag) { - return getByCriteria(type, props, hasNotProps, null, parseFlag); + JsonParseFlagEnum parseFlag, + String model) { + return getByCriteria(type, props, hasNotProps, null, parseFlag, model); } public Either<List<GraphVertex>, JanusGraphOperationStatus> getByCriteria(final VertexTypeEnum type, final Map<GraphPropertyEnum, Object> hasProps, final Map<GraphPropertyEnum, Object> hasNotProps, final Map<String, Entry<JanusGraphPredicate, Object>> predicates, - final JsonParseFlagEnum parseFlag) { + final JsonParseFlagEnum parseFlag, + final String model) { Either<JanusGraph, JanusGraphOperationStatus> graph = janusGraphClient.getGraph(); if (graph.isLeft()) { try { JanusGraph tGraph = graph.left().value(); JanusGraphQuery<? extends JanusGraphQuery> query = tGraph.query(); + if (type != null) { query = query.has(GraphPropertyEnum.LABEL.getProperty(), type.getName()); } @@ -484,7 +492,14 @@ public class JanusGraphDao { return Either.right(JanusGraphOperationStatus.NOT_FOUND); } List<GraphVertex> result = new ArrayList<>(); - vertices.forEach(vertex -> result.add(createAndFill(vertex, parseFlag))); + + final Predicate<? super JanusGraphVertex> filterPredicate = StringUtils.isEmpty(model) ? this::vertexNotConnectedToAnyModel : vertex -> vertexValidForModel(vertex, model); + final List<JanusGraphVertex> verticesForModel = StreamSupport.stream(vertices.spliterator(), false).filter(filterPredicate).collect(Collectors.toList()); + if (verticesForModel == null || verticesForModel.size() == 0) { + return Either.right(JanusGraphOperationStatus.NOT_FOUND); + } + + verticesForModel.forEach(vertex -> result.add(createAndFill(vertex, parseFlag))); if (logger.isDebugEnabled()) { logger.debug("Number of fetched nodes in graph for criteria : from type '{}' and properties '{}' is '{}'", type, hasProps, result.size()); @@ -503,6 +518,116 @@ public class JanusGraphDao { return Either.right(graph.right().value()); } } + + public Either<List<GraphVertex>, JanusGraphOperationStatus> getByCriteria(VertexTypeEnum type, + Map<GraphPropertyEnum, Object> props, Map<GraphPropertyEnum, Object> hasNotProps, + JsonParseFlagEnum parseFlag) { + return getByCriteria(type, props, hasNotProps, null, parseFlag); + } + + public Either<List<GraphVertex>, JanusGraphOperationStatus> getByCriteria(final VertexTypeEnum type, + final Map<GraphPropertyEnum, Object> hasProps, final Map<GraphPropertyEnum, Object> hasNotProps, + final Map<String, Entry<JanusGraphPredicate, Object>> predicates, final JsonParseFlagEnum parseFlag) { + Either<JanusGraph, JanusGraphOperationStatus> graph = janusGraphClient.getGraph(); + if (graph.isLeft()) { + try { + JanusGraph tGraph = graph.left().value(); + JanusGraphQuery<? extends JanusGraphQuery> query = tGraph.query(); + + if (type != null) { + query = query.has(GraphPropertyEnum.LABEL.getProperty(), type.getName()); + } + if (hasProps != null && !hasProps.isEmpty()) { + for (Map.Entry<GraphPropertyEnum, Object> entry : hasProps.entrySet()) { + query = query.has(entry.getKey().getProperty(), entry.getValue()); + } + } + if (hasNotProps != null && !hasNotProps.isEmpty()) { + for (Map.Entry<GraphPropertyEnum, Object> entry : hasNotProps.entrySet()) { + if (entry.getValue() instanceof List) { + buildMultipleNegateQueryFromList(entry, query); + } else { + query = query.hasNot(entry.getKey().getProperty(), entry.getValue()); + } + } + } + if (predicates != null && !predicates.isEmpty()) { + for (Map.Entry<String, Entry<JanusGraphPredicate, Object>> entry : predicates.entrySet()) { + JanusGraphPredicate predicate = entry.getValue().getKey(); + Object object = entry.getValue().getValue(); + query = query.has(entry.getKey(), predicate, object); + } + } + Iterable<JanusGraphVertex> vertices = query.vertices(); + if (vertices == null || !vertices.iterator().hasNext()) { + return Either.right(JanusGraphOperationStatus.NOT_FOUND); + } + List<GraphVertex> result = new ArrayList<>(); + + vertices.forEach(vertex -> result.add(createAndFill(vertex, parseFlag))); + if (logger.isDebugEnabled()) { + logger.debug( + "Number of fetched nodes in graph for criteria : from type '{}' and properties '{}' is '{}'", + type, hasProps, result.size()); + } + return Either.left(result); + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("Failed to get by criteria for type '{}' and properties '{}'", type, hasProps, e); + } + return Either.right(JanusGraphClient.handleJanusGraphException(e)); + } + } else { + if (logger.isDebugEnabled()) { + logger.debug("Failed to get by criteria for type '{}' and properties '{}'. Error : '{}'", type, + hasProps, graph.right().value()); + } + return Either.right(graph.right().value()); + } + } + + private boolean vertexValidForModel(final JanusGraphVertex vertex, final String model) { + final Either<List<ImmutablePair<JanusGraphVertex, Edge>>, JanusGraphOperationStatus> modelVertices = getParentVerticies(vertex, GraphEdgeLabels.MODEL_ELEMENT); + + if (modelVertices.isLeft()) { + for (ImmutablePair<JanusGraphVertex, Edge> vertexPair : modelVertices.left().value()) { + if (model.equals((String)vertexPair.getLeft().property("name").value())) { + return true; + } + } + } + return false; + } + + private Either<List<ImmutablePair<JanusGraphVertex, Edge>>, JanusGraphOperationStatus> getParentVerticies( + final JanusGraphVertex rootVertex, final GraphEdgeLabels edgeType) { + return getEdgeVerticies(rootVertex, Direction.IN, edgeType); + } + + private Either<List<ImmutablePair<JanusGraphVertex, Edge>>, JanusGraphOperationStatus> getEdgeVerticies( + final JanusGraphVertex rootVertex, final Direction direction, final GraphEdgeLabels edgeType) { + final List<ImmutablePair<JanusGraphVertex, Edge>> immutablePairs = new ArrayList<>(); + final Iterator<Edge> edgesCreatorIterator = rootVertex.edges(direction, edgeType.getProperty()); + if (edgesCreatorIterator != null) { + while (edgesCreatorIterator.hasNext()) { + Edge edge = edgesCreatorIterator.next(); + JanusGraphVertex vertex = Direction.OUT.equals(direction)? (JanusGraphVertex) edge.inVertex() : (JanusGraphVertex) edge.outVertex(); + ImmutablePair<JanusGraphVertex, Edge> immutablePair = new ImmutablePair<>(vertex, edge); + immutablePairs.add(immutablePair); + } + } + if (immutablePairs.isEmpty()) { + return Either.right(JanusGraphOperationStatus.NOT_FOUND); + } + return Either.left(immutablePairs); + } + + private boolean vertexNotConnectedToAnyModel(final JanusGraphVertex vertex) { + String vt = (String)vertex.property(GraphPropertyEnum.LABEL.getProperty()).value(); + VertexTypeEnum vertexType = VertexTypeEnum.getByName(vt); + EdgeLabelEnum edgeLabel = vertexType.equals(VertexTypeEnum.TOPOLOGY_TEMPLATE) ? EdgeLabelEnum.MODEL : EdgeLabelEnum.MODEL_ELEMENT; + return !vertex.edges(Direction.IN, edgeLabel.name()).hasNext(); + } public Either<Iterator<Vertex>, JanusGraphOperationStatus> getCatalogOrArchiveVerticies(boolean isCatalog) { Either<JanusGraph, JanusGraphOperationStatus> graph = janusGraphClient.getGraph(); diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTypeOperation.java index b74b290295..76d8e71c69 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTypeOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTypeOperation.java @@ -934,7 +934,7 @@ public class NodeTypeOperation extends ToscaElementOperation { Map<GraphPropertyEnum, Object> propsHasNot = new HashMap<>(); propsHasNot.put(GraphPropertyEnum.IS_DELETED, true); Either<List<GraphVertex>, JanusGraphOperationStatus> byCriteria = janusGraphDao - .getByCriteria(VertexTypeEnum.NODE_TYPE, props, propsHasNot, JsonParseFlagEnum.NoParse); + .getByCriteria(VertexTypeEnum.NODE_TYPE, props, propsHasNot, JsonParseFlagEnum.NoParse, nodeType.getModel()); if (byCriteria.isRight()) { log.debug("Failed to fetch derived by props {} error {}", props, byCriteria.right().value()); return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(byCriteria.right().value())); 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 faedba5363..6466683db6 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 @@ -364,10 +364,9 @@ public class ToscaOperationFacade { final Map<GraphPropertyEnum, Object> propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class); propertiesToMatch.put(GraphPropertyEnum.TOSCA_RESOURCE_NAME, nodeName); propertiesToMatch.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true); - propertiesToMatch.put(GraphPropertyEnum.MODEL, model); propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true); final Either<List<GraphVertex>, JanusGraphOperationStatus> highestResources = janusGraphDao - .getByCriteria(null, propertiesToMatch, propertiesNotToMatch, parseFlag); + .getByCriteria(null, propertiesToMatch, propertiesNotToMatch, parseFlag, model); if (highestResources.isRight()) { final JanusGraphOperationStatus status = highestResources.right().value(); log.debug("failed to find resource with name {}. status={} ", nodeName, status); @@ -388,8 +387,8 @@ public class ToscaOperationFacade { return getToscaElementByOperation(highestResource, filter); } - public <T extends Component> Either<T, StorageOperationStatus> getLatestByToscaResourceName(String toscaResourceName) { - return getLatestByName(GraphPropertyEnum.TOSCA_RESOURCE_NAME, toscaResourceName, null); + public <T extends Component> Either<T, StorageOperationStatus> getLatestByToscaResourceName(String toscaResourceName, String modelName) { + return getLatestByName(GraphPropertyEnum.TOSCA_RESOURCE_NAME, toscaResourceName, modelName); } public <T extends Component> Either<T, StorageOperationStatus> getFullLatestComponentByToscaResourceName(String toscaResourceName) { @@ -459,7 +458,7 @@ public class ToscaOperationFacade { props.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name()); Map<String, Entry<JanusGraphPredicate, Object>> predicateCriteria = getVendorVersionPredicate(vendorRelease); Either<List<GraphVertex>, JanusGraphOperationStatus> getLatestRes = janusGraphDao - .getByCriteria(vertexType, props, null, predicateCriteria, parseFlag); + .getByCriteria(vertexType, props, null, predicateCriteria, parseFlag, null); if (getLatestRes.isRight() || CollectionUtils.isEmpty(getLatestRes.left().value())) { getLatestRes = janusGraphDao.getByCriteria(vertexType, props, parseFlag); } @@ -486,7 +485,7 @@ public class ToscaOperationFacade { }); } - public <T extends Component> Either<T, StorageOperationStatus> getByToscaResourceNameAndVersion(final String toscaResourceName, final String version) { + public <T extends Component> Either<T, StorageOperationStatus> getByToscaResourceNameAndVersion(final String toscaResourceName, final String version, final String model) { Either<T, StorageOperationStatus> result; Map<GraphPropertyEnum, Object> hasProperties = new EnumMap<>(GraphPropertyEnum.class); @@ -497,7 +496,7 @@ public class ToscaOperationFacade { hasNotProperties.put(GraphPropertyEnum.IS_DELETED, true); Either<List<GraphVertex>, JanusGraphOperationStatus> getResourceRes = janusGraphDao - .getByCriteria(VertexTypeEnum.NODE_TYPE, hasProperties, hasNotProperties, JsonParseFlagEnum.ParseAll); + .getByCriteria(VertexTypeEnum.NODE_TYPE, hasProperties, hasNotProperties, JsonParseFlagEnum.ParseAll, model); if (getResourceRes.isRight()) { JanusGraphOperationStatus status = getResourceRes.right().value(); log.debug("failed to find resource with toscaResourceName {}, version {}. Status is {} ", toscaResourceName, version, status); @@ -807,10 +806,9 @@ public class ToscaOperationFacade { Map<GraphPropertyEnum, Object> propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class); propertiesToMatch.put(property, nodeName); propertiesToMatch.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true); - propertiesToMatch.put(GraphPropertyEnum.MODEL, model); propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true); Either<List<GraphVertex>, JanusGraphOperationStatus> highestResources = janusGraphDao - .getByCriteria(null, propertiesToMatch, propertiesNotToMatch, parseFlag); + .getByCriteria(null, propertiesToMatch, propertiesNotToMatch, parseFlag, model); if (highestResources.isRight()) { JanusGraphOperationStatus status = highestResources.right().value(); log.debug("failed to find resource with name {}. status={} ", nodeName, status); @@ -905,7 +903,7 @@ public class ToscaOperationFacade { public <T extends Component> Either<T, StorageOperationStatus> getComponentByNameAndVendorRelease(final ComponentTypeEnum componentType, final String name, final String vendorRelease, - final JsonParseFlagEnum parseFlag) { + final JsonParseFlagEnum parseFlag, final String modelName) { Map<GraphPropertyEnum, Object> hasProperties = new EnumMap<>(GraphPropertyEnum.class); Map<GraphPropertyEnum, Object> hasNotProperties = new EnumMap<>(GraphPropertyEnum.class); hasProperties.put(GraphPropertyEnum.NAME, name); @@ -915,7 +913,7 @@ public class ToscaOperationFacade { } Map<String, Entry<JanusGraphPredicate, Object>> predicateCriteria = getVendorVersionPredicate(vendorRelease); Either<List<GraphVertex>, JanusGraphOperationStatus> getResourceRes = janusGraphDao.getByCriteria(null, hasProperties, hasNotProperties, - predicateCriteria, parseFlag); + predicateCriteria, parseFlag, modelName); if (getResourceRes.isRight()) { JanusGraphOperationStatus status = getResourceRes.right().value(); log.debug("failed to find resource with name {}, version {}. Status is {} ", name, predicateCriteria, status); @@ -1947,7 +1945,7 @@ public class ToscaOperationFacade { Map<GraphPropertyEnum, Object> hasNotProps = new EnumMap<>(GraphPropertyEnum.class); fillPropsMap(hasProps, hasNotProps, internalComponentType, componentTypeEnum, isAbstract, vertexType, modelName); Either<List<GraphVertex>, JanusGraphOperationStatus> getRes = janusGraphDao - .getByCriteria(vertexType, hasProps, hasNotProps, JsonParseFlagEnum.ParseMetadata); + .getByCriteria(vertexType, hasProps, hasNotProps, JsonParseFlagEnum.ParseMetadata, modelName); if (getRes.isRight() && !JanusGraphOperationStatus.NOT_FOUND.equals(getRes.right().value())) { return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(getRes.right().value())); } @@ -1969,7 +1967,7 @@ public class ToscaOperationFacade { ComponentParametersView params = new ComponentParametersView(true); params.setIgnoreAllVersions(false); if (getRes.isLeft()) { - for (GraphVertex vertexComponent : getVerticesForModel(modelName, getRes.left().value())) { + for (GraphVertex vertexComponent : getRes.left().value()) { Either<ToscaElement, StorageOperationStatus> componentRes = topologyTemplateOperation .getLightComponent(vertexComponent, componentTypeEnum, params); if (componentRes.isRight()) { @@ -2129,13 +2127,13 @@ public class ToscaOperationFacade { final ComponentTypeEnum componentType) { final String normalizedName = ValidationUtils.normaliseComponentName(resourceName); final Either<List<GraphVertex>, JanusGraphOperationStatus> vertexEither = janusGraphDao - .getByCriteria(getVertexTypeEnum(resourceType), propertiesToMatch(normalizedName, componentType), null, null, JsonParseFlagEnum.NoParse); + .getByCriteria(getVertexTypeEnum(resourceType), propertiesToMatch(normalizedName, componentType), null, null, JsonParseFlagEnum.NoParse, modelName); if (vertexEither.isRight() && vertexEither.right().value() != JanusGraphOperationStatus.NOT_FOUND) { log.debug("failed to get vertex from graph with property normalizedName: {} and model: {}", normalizedName, modelName); return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(vertexEither.right().value())); } return Either.left(CollectionUtils.isEmpty(vertexEither.isLeft() ? vertexEither.left().value().stream() - .filter(graphVertex -> graphVertex.getMetadataProperty(GraphPropertyEnum.NAME).equals(modelName)).collect(Collectors.toList()) : null)); + .collect(Collectors.toList()) : null)); } private VertexTypeEnum getVertexTypeEnum(final ResourceTypeEnum resourceType) { @@ -2359,7 +2357,7 @@ public class ToscaOperationFacade { } public <T extends Component> Either<T, StorageOperationStatus> getLatestByNameAndVersion(String name, String version, - JsonParseFlagEnum parseFlag) { + JsonParseFlagEnum parseFlag, String model) { Either<T, StorageOperationStatus> result; Map<GraphPropertyEnum, Object> hasProperties = new EnumMap<>(GraphPropertyEnum.class); Map<GraphPropertyEnum, Object> hasNotProperties = new EnumMap<>(GraphPropertyEnum.class); @@ -2368,7 +2366,7 @@ public class ToscaOperationFacade { hasProperties.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true); hasNotProperties.put(GraphPropertyEnum.IS_DELETED, true); Either<List<GraphVertex>, JanusGraphOperationStatus> getResourceRes = janusGraphDao - .getByCriteria(null, hasProperties, hasNotProperties, parseFlag); + .getByCriteria(null, hasProperties, hasNotProperties, parseFlag, model); if (getResourceRes.isRight()) { JanusGraphOperationStatus status = getResourceRes.right().value(); log.debug("failed to find resource with name {}, version {}. Status is {} ", name, version, status); @@ -2471,10 +2469,10 @@ public class ToscaOperationFacade { return null; } - public Either<Boolean, StorageOperationStatus> validateToscaResourceNameExtends(String templateNameCurrent, String templateNameExtends) { + public Either<Boolean, StorageOperationStatus> validateToscaResourceNameExtends(String templateNameCurrent, String templateNameExtends, String model) { String currentTemplateNameChecked = templateNameExtends; while (currentTemplateNameChecked != null && !currentTemplateNameChecked.equalsIgnoreCase(templateNameCurrent)) { - Either<Resource, StorageOperationStatus> latestByToscaResourceName = getLatestByToscaResourceName(currentTemplateNameChecked); + Either<Resource, StorageOperationStatus> latestByToscaResourceName = getLatestByToscaResourceName(currentTemplateNameChecked, model); if (latestByToscaResourceName.isRight()) { return latestByToscaResourceName.right().value() == StorageOperationStatus.NOT_FOUND ? Either.left(false) : Either.right(latestByToscaResourceName.right().value()); @@ -2593,7 +2591,7 @@ public class ToscaOperationFacade { Map<GraphPropertyEnum, Object> propertiesNotToMatch, String modelName) { Either<List<GraphVertex>, JanusGraphOperationStatus> getRes = janusGraphDao - .getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseAll); + .getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseAll, modelName); if (getRes.isRight()) { if (getRes.right().value() != JanusGraphOperationStatus.NOT_FOUND) { CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, @@ -2602,7 +2600,7 @@ public class ToscaOperationFacade { return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(getRes.right().value())); } } else { - for (final GraphVertex vertex : getVerticesForModel(modelName, getRes.left().value())) { + for (final GraphVertex vertex : getRes.left().value()) { Either<ToscaElement, StorageOperationStatus> getServiceRes = topologyTemplateOperation .getLightComponent(vertex, ComponentTypeEnum.SERVICE, new ComponentParametersView(true)); if (getServiceRes.isRight()) { diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IElementOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IElementOperation.java index aac14625c5..7457ed727e 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IElementOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IElementOperation.java @@ -86,7 +86,7 @@ public interface IElementOperation { Either<List<CategoryDefinition>, ActionStatus> getAllCategories(NodeTypeEnum nodeType, boolean inTransaction); - List<BaseType> getBaseTypes(String categoryName); + List<BaseType> getBaseTypes(String categoryName, String modelName); Either<CategoryDefinition, ActionStatus> getCategory(NodeTypeEnum nodeType, String categoryId); diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ElementOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ElementOperation.java index 054788a519..42f1b03028 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ElementOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ElementOperation.java @@ -380,7 +380,7 @@ public class ElementOperation implements IElementOperation { } @Override - public List<BaseType> getBaseTypes(final String categoryName){ + public List<BaseType> getBaseTypes(final String categoryName, final String modelName){ final ArrayList<BaseType> baseTypes = new ArrayList<>(); final Map<String, String> categoriesSpecificBaseTypes = ConfigurationManager.getConfigurationManager().getConfiguration().getServiceNodeTypes(); final String categorySpecificBaseType = categoriesSpecificBaseTypes == null ? null : categoriesSpecificBaseTypes.get(categoryName); @@ -391,8 +391,8 @@ public class ElementOperation implements IElementOperation { props.put(GraphPropertyEnum.TOSCA_RESOURCE_NAME, baseToscaResourceName); props.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name()); final Either<List<GraphVertex>, JanusGraphOperationStatus> baseTypeVertex = janusGraphDao - .getByCriteria(VertexTypeEnum.NODE_TYPE, props, JsonParseFlagEnum.ParseAll); - + .getByCriteria(VertexTypeEnum.NODE_TYPE, props, null, JsonParseFlagEnum.ParseAll, modelName); + if (baseTypeVertex.isLeft()) { BaseType baseType = new BaseType(baseToscaResourceName); baseTypes.add(baseType); diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacadeTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacadeTest.java index a19e7c431f..b88eec2993 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacadeTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacadeTest.java @@ -263,10 +263,9 @@ public class ToscaOperationFacadeTest { Map<GraphPropertyEnum, Object> propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class); propertiesToMatch.put(GraphPropertyEnum.TOSCA_RESOURCE_NAME, "toscaResourceName"); propertiesToMatch.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true); - propertiesToMatch.put(GraphPropertyEnum.MODEL, null); propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true); - when(janusGraphDaoMock.getByCriteria(null, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseAll)) + when(janusGraphDaoMock.getByCriteria(null, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseAll, null)) .thenReturn(Either.left(list)); when(topologyTemplateOperationMock.getToscaElement(ArgumentMatchers.eq(graphVertex), any(ComponentParametersView.class))) .thenReturn(Either.left(toscaElement)); @@ -437,12 +436,12 @@ public class ToscaOperationFacadeTest { public void testGetLatestByToscaResourceName() { Either<Component, StorageOperationStatus> result; String toscaResourceName = "name"; + String model = "testModel"; ToscaElement toscaElement = getToscaElementForTest(); Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class); propertiesToMatch.put(GraphPropertyEnum.TOSCA_RESOURCE_NAME, toscaResourceName); propertiesToMatch.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true); - propertiesToMatch.put(GraphPropertyEnum.MODEL, null); Map<GraphPropertyEnum, Object> propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class); propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true); @@ -454,11 +453,11 @@ public class ToscaOperationFacadeTest { graphVertex.setMetadataProperties(props); graphVertexList.add(graphVertex); - when(janusGraphDaoMock.getByCriteria(null, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseMetadata)) + when(janusGraphDaoMock.getByCriteria(null, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseMetadata, model)) .thenReturn(Either.left(graphVertexList)); when(topologyTemplateOperationMock.getToscaElement(any(GraphVertex.class), any(ComponentParametersView.class))) .thenReturn(Either.left(toscaElement)); - result = testInstance.getLatestByToscaResourceName(toscaResourceName); + result = testInstance.getLatestByToscaResourceName(toscaResourceName, model); assertTrue(result.isLeft()); } diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ElementOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ElementOperationTest.java index 230fbe1aba..d8b7e53860 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ElementOperationTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ElementOperationTest.java @@ -490,7 +490,7 @@ public class ElementOperationTest extends ModelTestBase { GraphVertex baseTypeVertex = mock(GraphVertex.class); when(baseTypeVertex.getMetadataProperty(GraphPropertyEnum.VERSION)).thenReturn("1.0"); - when(healingJanusGraphDao.getByCriteria(any(), any(), any())) + when(healingJanusGraphDao.getByCriteria(eq(VertexTypeEnum.NODE_TYPE), any(), isNull(), eq(JsonParseFlagEnum.ParseAll), any())) .thenReturn(Either.left(Collections.singletonList(baseTypeVertex))); GraphVertex derivedTypeVertex = mock(GraphVertex.class); @@ -508,7 +508,7 @@ public class ElementOperationTest extends ModelTestBase { when(derivedTypeVertex.getMetadataProperty(GraphPropertyEnum.TOSCA_RESOURCE_NAME)) .thenReturn("org.parent.type"); - List<BaseType> baseTypes = elementOperation.getBaseTypes("serviceCategoryA"); + List<BaseType> baseTypes = elementOperation.getBaseTypes("serviceCategoryA", null); assertEquals(2, baseTypes.size()); assertEquals("org.base.type", baseTypes.get(0).getToscaResourceName()); @@ -539,13 +539,13 @@ public class ElementOperationTest extends ModelTestBase { GraphVertex baseTypeVertex = mock(GraphVertex.class); when(baseTypeVertex.getMetadataProperty(GraphPropertyEnum.VERSION)).thenReturn("1.0"); - when(healingJanusGraphDao.getByCriteria(any(), any(), any())) + when(healingJanusGraphDao.getByCriteria(eq(VertexTypeEnum.NODE_TYPE), any(), isNull(), eq(JsonParseFlagEnum.ParseAll), any())) .thenReturn(Either.left(Collections.singletonList(baseTypeVertex))); when(healingJanusGraphDao.getParentVertices(baseTypeVertex, EdgeLabelEnum.DERIVED_FROM, JsonParseFlagEnum.ParseAll)).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)); - List<BaseType> baseTypes = elementOperation.getBaseTypes("serviceCategoryA"); + List<BaseType> baseTypes = elementOperation.getBaseTypes("serviceCategoryA", null); assertEquals(1, baseTypes.size()); assertEquals("org.service.default", baseTypes.get(0).getToscaResourceName()); diff --git a/catalog-ui/src/app/models/components/component.ts b/catalog-ui/src/app/models/components/component.ts index a2d28ebeac..6d176df216 100644 --- a/catalog-ui/src/app/models/components/component.ts +++ b/catalog-ui/src/app/models/components/component.ts @@ -147,7 +147,7 @@ export abstract class Component implements IComponent { public categorySpecificMetadata: Metadata = new Metadata(); public derivedFromGenericType: string; public derivedFromGenericVersion: string; - public model: Model; + public model: string; constructor(componentService:IComponentService, protected $q:ng.IQService, component?:Component) { if (component) { diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.ts b/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.ts index fbbc4d8b0e..8e483ea5ef 100644 --- a/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.ts +++ b/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.ts @@ -1146,7 +1146,7 @@ export class PropertiesAssignmentComponent { } /*** addProperty ***/ - addProperty = (model: Model) => { + addProperty = (model: string) => { this.loadDataTypesByComponentModel(model) let modalTitle = 'Add Property'; let modal = this.ModalService.createCustomModal(new ModalModel( @@ -1251,9 +1251,8 @@ export class PropertiesAssignmentComponent { return instanceType === ResourceType.VF || instanceType === ResourceType.PNF || instanceType === ResourceType.CVFC || instanceType === ResourceType.CR; } - loadDataTypesByComponentModel(model:Model) { - let modelName = new Model(model).name; - this.propertyCreatorComponent.filterDataTypesByModel(modelName); + loadDataTypesByComponentModel(model:string) { + this.propertyCreatorComponent.filterDataTypesByModel(model); } } diff --git a/catalog-ui/src/app/ng2/services/element.service.ts b/catalog-ui/src/app/ng2/services/element.service.ts index 97efbccfef..b3cf8c38f4 100644 --- a/catalog-ui/src/app/ng2/services/element.service.ts +++ b/catalog-ui/src/app/ng2/services/element.service.ts @@ -33,8 +33,9 @@ export class ElementService { this.baseUrl = sdcConfig.api.root; } - getCategoryBasetypes(categoryName:string):Observable<BaseTypeResponse[]> { - return this.http.get<ListBaseTypesResponse>(this.baseUrl + "/v1/category/services/" + categoryName + "/baseTypes") + getCategoryBasetypes(categoryName:string, modelName:string):Observable<BaseTypeResponse[]> { + let modelQueryParam: string = modelName ? '?model=' + modelName : ''; + return this.http.get<ListBaseTypesResponse>(this.baseUrl + "/v1/category/services/" + categoryName + "/baseTypes" + modelQueryParam) .pipe(map(response => response.baseTypes)); } diff --git a/catalog-ui/src/app/ng2/services/responses/component-generic-response.ts b/catalog-ui/src/app/ng2/services/responses/component-generic-response.ts index fa3de88c7b..aaf105463d 100644 --- a/catalog-ui/src/app/ng2/services/responses/component-generic-response.ts +++ b/catalog-ui/src/app/ng2/services/responses/component-generic-response.ts @@ -62,7 +62,7 @@ export class ComponentGenericResponse implements Serializable<ComponentGenericR public substitutionFilters: any; public derivedFromGenericType; public derivedFromGenericVersion; - public model:Model; + public model:string; deserialize (response): ComponentGenericResponse { diff --git a/catalog-ui/src/app/view-models/forms/property-forms/base-property-form/property-form-base-model.ts b/catalog-ui/src/app/view-models/forms/property-forms/base-property-form/property-form-base-model.ts index 5e48dc8115..fe578b6865 100644 --- a/catalog-ui/src/app/view-models/forms/property-forms/base-property-form/property-form-base-model.ts +++ b/catalog-ui/src/app/view-models/forms/property-forms/base-property-form/property-form-base-model.ts @@ -135,7 +135,7 @@ export abstract class PropertyFormBaseView { this.$scope.property = new PropertyModel(this.originalProperty); //we create a new Object so if user press cance we won't update the property this.$scope.types = PROPERTY_DATA.TYPES; //All types - simple type + map + list this.$scope.simpleTypes = PROPERTY_DATA.SIMPLE_TYPES; //All simple types - this.$scope.dataTypes = this.DataTypesService.getAllDataTypesFromModel(this.component.model.name); //Get all data types in service + this.$scope.dataTypes = this.DataTypesService.getAllDataTypesFromModel(this.component.model); //Get all data types in service this.$scope.modalPropertyFormBase = this.$uibModalInstance; this.$scope.isNew = !angular.isDefined(this.$scope.property.name); diff --git a/catalog-ui/src/app/view-models/forms/property-forms/select-datatype-modal/select-datatype-modal-view-model.ts b/catalog-ui/src/app/view-models/forms/property-forms/select-datatype-modal/select-datatype-modal-view-model.ts index 9be3b642b4..2e8788f1fa 100644 --- a/catalog-ui/src/app/view-models/forms/property-forms/select-datatype-modal/select-datatype-modal-view-model.ts +++ b/catalog-ui/src/app/view-models/forms/property-forms/select-datatype-modal/select-datatype-modal-view-model.ts @@ -63,7 +63,7 @@ export class SelectDataTypeViewModel extends PropertyFormBaseView { this.$templateCache.put("select-datatype-modal-view.html", require('app/view-models/forms/property-forms/select-datatype-modal/select-datatype-modal-view.html')); this.$scope.innerViewSrcUrl = "select-datatype-modal-view.html"; - this.$scope.modelNameFilter = this.component.model.name; + this.$scope.modelNameFilter = this.component.model; this.initChildScope(); } diff --git a/catalog-ui/src/app/view-models/workspace/tabs/general/general-view-model.ts b/catalog-ui/src/app/view-models/workspace/tabs/general/general-view-model.ts index 20eaec6aad..c78852de4c 100644 --- a/catalog-ui/src/app/view-models/workspace/tabs/general/general-view-model.ts +++ b/catalog-ui/src/app/view-models/workspace/tabs/general/general-view-model.ts @@ -451,7 +451,8 @@ export class GeneralViewModel { this.$scope.initBaseTypes = ():void => { if (this.$scope.componentType === ComponentType.SERVICE && this.$scope.component && this.$scope.component.categories) { - this.elementService.getCategoryBasetypes(this.$scope.component.categories[0].name).subscribe((data: BaseTypeResponse[]) => { + let modelName = this.$scope.component.model ? this.$scope.component.model : null; + this.elementService.getCategoryBasetypes(this.$scope.component.categories[0].name, modelName).subscribe((data: BaseTypeResponse[]) => { this.$scope.baseTypes = [] this.$scope.baseTypeVersions = [] data.forEach(baseType => { @@ -682,7 +683,8 @@ export class GeneralViewModel { } } if (this.$scope.componentType === ComponentType.SERVICE && this.$scope.component.categories[0]) { - this.elementService.getCategoryBasetypes(this.$scope.component.categories[0].name).subscribe((data: BaseTypeResponse[]) => { + let modelName : string = this.$scope.component.model ? this.$scope.component.model : null; + this.elementService.getCategoryBasetypes(this.$scope.component.categories[0].name, modelName).subscribe((data: BaseTypeResponse[]) => { if(this.$scope.isCreateMode()){ this.$scope.baseTypes = [] @@ -709,7 +711,8 @@ export class GeneralViewModel { }; this.$scope.onBaseTypeChange = (): void => { - this.elementService.getCategoryBasetypes(this.$scope.component.categories[0].name).subscribe((data: BaseTypeResponse[]) => { + let modelName : string = this.$scope.component.model ? this.$scope.component.model : null; + this.elementService.getCategoryBasetypes(this.$scope.component.categories[0].name, modelName).subscribe((data: BaseTypeResponse[]) => { this.$scope.baseTypeVersions = [] data.forEach(baseType => { if(baseType.toscaResourceName === this.$scope.component.derivedFromGenericType) { @@ -720,6 +723,20 @@ export class GeneralViewModel { }) }; + this.$scope.onModelChange = (): void => { + if (this.$scope.componentType === ComponentType.SERVICE && this.$scope.component && this.$scope.component.categories) { + let modelName = this.$scope.component.model ? this.$scope.component.model : null; + this.elementService.getCategoryBasetypes(this.$scope.component.categories[0].name, modelName).subscribe((data: BaseTypeResponse[]) => { + this.$scope.baseTypes = [] + this.$scope.baseTypeVersions = [] + data.forEach(baseType => this.$scope.baseTypes.push(baseType.toscaResourceName)); + data[0].versions.reverse().forEach(version => this.$scope.baseTypeVersions.push(version)); + this.$scope.component.derivedFromGenericType = data[0].toscaResourceName; + this.$scope.component.derivedFromGenericVersion = data[0].versions[0]; + }) + } + }; + this.$scope.onVendorNameChange = (oldVendorName: string): void => { if (this.$scope.component.icon === oldVendorName) { this.$scope.component.icon = DEFAULT_ICON; diff --git a/catalog-ui/src/app/view-models/workspace/tabs/general/general-view.html b/catalog-ui/src/app/view-models/workspace/tabs/general/general-view.html index d84f4c87e0..fa4af6d6f5 100644 --- a/catalog-ui/src/app/view-models/workspace/tabs/general/general-view.html +++ b/catalog-ui/src/app/view-models/workspace/tabs/general/general-view.html @@ -617,6 +617,7 @@ data-ng-class="{'view-mode': isViewMode()}" data-ng-disabled="component.isCsarComponent() || !isCreateMode()" data-ng-model="component.model" + data-ng-change="onModelChange()" data-tests-id="modelName"> <option value="">SDC AID</option> <option ng-repeat="model in models | orderBy:[name]">{{model}}</option> |