diff options
author | andre.schmid <andre.schmid@est.tech> | 2021-11-26 10:29:09 +0000 |
---|---|---|
committer | Michael Morris <michael.morris@est.tech> | 2023-02-09 11:39:31 +0000 |
commit | be850f6e83cbaa5c16f79c2c8732583f42e55429 (patch) | |
tree | 3b36e783c5018ffe79e309397a88ca70721ede6e /catalog-be/src | |
parent | e2a9c9c4d6c76bf4c70953a9e5289777bc63c1f5 (diff) |
Consider model in generic substitution type query
Change-Id: I9905b5f6b1bd658befb88b2dbb6903dfaa1f0f8a
Issue-ID: SDC-3794
Signed-off-by: andre.schmid <andre.schmid@est.tech>
Diffstat (limited to 'catalog-be/src')
2 files changed, 26 insertions, 10 deletions
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 600f7fa3eb..52ae99e390 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 @@ -19,6 +19,8 @@ */ package org.openecomp.sdc.be.components.impl.generic; +import static org.openecomp.sdc.common.api.Constants.ABSTRACT; + import fj.data.Either; import java.util.ArrayList; import java.util.List; @@ -68,24 +70,35 @@ public class GenericTypeBusinessLogic { return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR)); } Either<Resource, StorageOperationStatus> genericType; - if (StringUtils.isEmpty(component.getDerivedFromGenericVersion())){ - genericType = toscaOperationFacade - .getLatestCertifiedNodeTypeByToscaResourceName(genericTypeToscaName); + if (StringUtils.isEmpty(component.getDerivedFromGenericVersion())) { + genericType = toscaOperationFacade.getLatestByToscaResourceNameAndModel(genericTypeToscaName, component.getModel()); if (genericType.isRight()) { - log.debug("Failed to fetch certified node type by tosca resource name {}", genericTypeToscaName); - return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERIC_TYPE_NOT_FOUND, component.assetType(), genericTypeToscaName)); + if (genericTypeToscaName.contains(ABSTRACT)) { + genericType = toscaOperationFacade.getLatestCertifiedNodeTypeByToscaResourceName(genericTypeToscaName); + if (genericType.isRight()) { + log.debug("Failed to fetch certified node type by tosca resource name {}", genericTypeToscaName); + return Either.right( + componentsUtils.getResponseFormat(ActionStatus.GENERIC_TYPE_NOT_FOUND, component.assetType(), genericTypeToscaName)); + } + } else { + log.debug("Failed to fetch latest node type by tosca resource name {} and model {}", genericTypeToscaName, component.getModel()); + return Either.right( + componentsUtils.getResponseFormat(ActionStatus.GENERIC_TYPE_NOT_FOUND, component.assetType(), genericTypeToscaName)); + } } } else { - genericType = toscaOperationFacade.getByToscaResourceNameAndVersion(genericTypeToscaName, component.getDerivedFromGenericVersion(), component.getModel()); + genericType = toscaOperationFacade.getByToscaResourceNameAndVersion(genericTypeToscaName, component.getDerivedFromGenericVersion(), + component.getModel()); } Resource genericTypeResource = genericType.left().value(); return Either.left(genericTypeResource); } - + public Either<Resource, ResponseFormat> fetchDerivedFromGenericType(final Component component, final String toscaType) { if (StringUtils.isNotEmpty(toscaType)) { - final Either<Resource, StorageOperationStatus> genericType = toscaOperationFacade.getLatestByToscaResourceNameAndModel(toscaType, component.getModel()); + final Either<Resource, StorageOperationStatus> genericType = toscaOperationFacade.getLatestByToscaResourceNameAndModel(toscaType, + component.getModel()); if (genericType.isRight()) { log.debug("Failed to fetch certified node type by tosca resource name {}", toscaType); return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERIC_TYPE_NOT_FOUND, component.assetType(), toscaType)); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/generic/GenericTypeBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/generic/GenericTypeBusinessLogicTest.java index 564e02dca5..ff0bd72113 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/generic/GenericTypeBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/generic/GenericTypeBusinessLogicTest.java @@ -86,8 +86,9 @@ class GenericTypeBusinessLogicTest { cvfc.setResourceType(ResourceTypeEnum.CVFC); cvfc.setDerivedFrom(Arrays.asList("genericType", "someOtherType")); cvfc.setDerivedFromGenericType("genericType"); + cvfc.setModel("model"); Resource genericResource = new Resource(); - when(toscaOperationFacadeMock.getLatestCertifiedNodeTypeByToscaResourceName(cvfc.getDerivedFromGenericType())) + when(toscaOperationFacadeMock.getLatestByToscaResourceNameAndModel(cvfc.getDerivedFromGenericType(), cvfc.getModel())) .thenReturn(Either.left(genericResource)); Either<Resource, ResponseFormat> fetchedGenericType = testInstance.fetchDerivedFromGenericType(cvfc); assertEquals(genericResource, fetchedGenericType.left().value()); @@ -99,8 +100,10 @@ class GenericTypeBusinessLogicTest { when(resource.getResourceType()).thenReturn(ResourceTypeEnum.VF); final var genericType = "genericType"; when(resource.fetchGenericTypeToscaNameFromConfig()).thenReturn(genericType); + final var model = "model"; + when(resource.getModel()).thenReturn(model); Resource genericResource = new Resource(); - when(toscaOperationFacadeMock.getLatestCertifiedNodeTypeByToscaResourceName(genericType)).thenReturn(Either.left(genericResource)); + when(toscaOperationFacadeMock.getLatestByToscaResourceNameAndModel(genericType, model)).thenReturn(Either.left(genericResource)); Either<Resource, ResponseFormat> fetchedGenericType = testInstance.fetchDerivedFromGenericType(resource); assertEquals(genericResource, fetchedGenericType.left().value()); } |