summaryrefslogtreecommitdiffstats
path: root/catalog-be/src
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2023-01-30 15:17:39 +0000
committerMichael Morris <michael.morris@est.tech>2023-02-09 11:19:05 +0000
commite2a9c9c4d6c76bf4c70953a9e5289777bc63c1f5 (patch)
tree070f87478380f7637291c23c51f20319b6587ea5 /catalog-be/src
parentc6cb16f234b8ae9de4aede3ca09a57e6ca177abe (diff)
Improve getting Service with specific version
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech> Change-Id: Ia788649016fe261802a081788b8844a80bbc3dcc Issue-ID: SDC-4358
Diffstat (limited to 'catalog-be/src')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java28
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactBusinessLogicTest.java5
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogicTest.java16
3 files changed, 10 insertions, 39 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java
index 9f5436d152..c17af4d4de 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java
@@ -2513,32 +2513,14 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
}
private Service validateServiceNameAndVersion(String serviceName, String serviceVersion) {
- Either<List<Service>, StorageOperationStatus> serviceListBySystemName = toscaOperationFacade
- .getBySystemName(ComponentTypeEnum.SERVICE, serviceName);
- if (serviceListBySystemName.isRight()) {
+ final Either<Service, StorageOperationStatus> serviceBySystemNameAndVersion
+ = toscaOperationFacade.getBySystemNameAndVersion(ComponentTypeEnum.SERVICE, serviceName, serviceVersion);
+ if (serviceBySystemNameAndVersion.isRight()) {
log.debug("Couldn't fetch any service with name {}", serviceName);
throw new ByActionStatusComponentException(
- componentsUtils.convertFromStorageResponse(serviceListBySystemName.right().value(), ComponentTypeEnum.SERVICE), serviceName);
+ componentsUtils.convertFromStorageResponse(serviceBySystemNameAndVersion.right().value(), ComponentTypeEnum.SERVICE), serviceName);
}
- List<Service> serviceList = serviceListBySystemName.left().value();
- if (serviceList == null || serviceList.isEmpty()) {
- log.debug("Couldn't fetch any service with name {}", serviceName);
- throw new ByActionStatusComponentException(ActionStatus.SERVICE_NOT_FOUND, serviceName);
- }
- Service foundService = null;
- for (Service service : serviceList) {
- if (service.getVersion().equals(serviceVersion)) {
- log.trace("Found service with version {}", serviceVersion);
- foundService = service;
- break;
- }
- }
- if (foundService == null) {
- log.debug("Couldn't find version {} for service {}", serviceVersion, serviceName);
- throw new ByActionStatusComponentException(ActionStatus.COMPONENT_VERSION_NOT_FOUND, ComponentTypeEnum.SERVICE.getValue(),
- serviceVersion);
- }
- return foundService;
+ return serviceBySystemNameAndVersion.left().value();
}
private Resource validateResourceNameAndVersion(String resourceName, String resourceVersion) {
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactBusinessLogicTest.java
index 616d9e42f9..fdc762ed44 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactBusinessLogicTest.java
@@ -466,10 +466,7 @@ public class ArtifactBusinessLogicTest extends BaseBusinessLogicMock{
DAOArtifactData.setDataAsArray(payload);
Either<DAOArtifactData, CassandraOperationStatus> artifactfromESres = Either.left(DAOArtifactData);
when(artifactCassandraDao.getArtifact(esArtifactId)).thenReturn(artifactfromESres);
- List<org.openecomp.sdc.be.model.Component> serviceList = new ArrayList<>();
- serviceList.add(service);
- Either<List<org.openecomp.sdc.be.model.Component>, StorageOperationStatus> getServiceRes = Either.left(serviceList);
- when(toscaOperationFacade.getBySystemName(ComponentTypeEnum.SERVICE, serviceName)).thenReturn(getServiceRes);
+ when(toscaOperationFacade.getBySystemNameAndVersion(ComponentTypeEnum.SERVICE, serviceName,serviceVersion)).thenReturn(Either.left(service));
byte[] downloadServiceArtifactByNamesRes =
artifactBL.downloadServiceArtifactByNames(serviceName, serviceVersion, artifactName);
assertThat(downloadServiceArtifactByNamesRes !=null &&
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogicTest.java
index c13a46500f..54ccf2bee9 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogicTest.java
@@ -728,11 +728,7 @@ public class ArtifactsBusinessLogicTest extends BaseBusinessLogicMock {
DAOArtifactData.setDataAsArray(payload);
Either<DAOArtifactData, CassandraOperationStatus> artifactfromESres = Either.left(DAOArtifactData);
when(artifactCassandraDao.getArtifact(esArtifactId)).thenReturn(artifactfromESres);
- List<org.openecomp.sdc.be.model.Component> serviceList = new ArrayList<>();
- serviceList.add(service);
- Either<List<org.openecomp.sdc.be.model.Component>, StorageOperationStatus> getServiceRes = Either
- .left(serviceList);
- when(toscaOperationFacade.getBySystemName(ComponentTypeEnum.SERVICE, serviceName)).thenReturn(getServiceRes);
+ when(toscaOperationFacade.getBySystemNameAndVersion(ComponentTypeEnum.SERVICE, serviceName, serviceVersion)).thenReturn(Either.left(service));
byte[] downloadServiceArtifactByNamesRes = artifactBL
.downloadServiceArtifactByNames(serviceName, serviceVersion, artifactName);
assertThat(downloadServiceArtifactByNamesRes != null
@@ -2428,19 +2424,15 @@ public class ArtifactsBusinessLogicTest extends BaseBusinessLogicMock {
esArtifactData.setDataAsArray("test".getBytes());
artifactDefinition.setArtifactName(artifactName);
- List<Service> serviceList = new ArrayList<>();
Map<String, ArtifactDefinition> artifacts = new HashMap<>();
artifacts.put(artifactName, artifactDefinition);
-
- serviceList.add(service);
resource.setDeploymentArtifacts(artifacts);
when(toscaOperationFacade.getComponentByNameAndVersion(eq(ComponentTypeEnum.RESOURCE), eq(resourceName), eq(version),
eq(JsonParseFlagEnum.ParseMetadata)))
.thenReturn(Either.left(resource));
- doReturn(Either.left(serviceList)).when(toscaOperationFacade).getBySystemName(eq(ComponentTypeEnum.SERVICE), eq(serviceName));
- when(artifactCassandraDao.getArtifact(any()))
- .thenReturn(Either.left(esArtifactData));
+ doReturn(Either.left(service)).when(toscaOperationFacade).getBySystemNameAndVersion(ComponentTypeEnum.SERVICE, serviceName, version);
+ when(artifactCassandraDao.getArtifact(any())).thenReturn(Either.left(esArtifactData));
byte[] result = artifactBL.downloadRsrcArtifactByNames(serviceName, version, resourceName, version, artifactName);
Assert.assertEquals(esArtifactData.getDataAsArray(), result);
@@ -2455,4 +2447,4 @@ public class ArtifactsBusinessLogicTest extends BaseBusinessLogicMock {
artifactsBusinessLogic.setComponentsUtils(componentsUtils);
return artifactsBusinessLogic;
}
-} \ No newline at end of file
+}