summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java85
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/OrchestrationTemplateCandidateManager.java2
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImpl.java32
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java40
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImplTest.java8
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImplTest.java65
-rw-r--r--openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/OrchestrationTemplateCandidateDao.java4
-rw-r--r--openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/filedatastructuremodule/CandidateService.java12
-rw-r--r--openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/zusammen/OrchestrationTemplateCandidateDaoZusammenImpl.java163
-rw-r--r--openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/filedatastructuremodule/CandidateServiceImpl.java49
10 files changed, 207 insertions, 253 deletions
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java
index 03f36978cf..71e188851e 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java
@@ -16,29 +16,6 @@
package org.openecomp.sdcrests.vsp.rest.services;
-import static javax.ws.rs.core.HttpHeaders.CONTENT_DISPOSITION;
-import static org.openecomp.sdc.itempermissions.notifications.NotificationConstants.PERMISSION_USER;
-import static org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME;
-import static org.openecomp.sdc.vendorsoftwareproduct.dao.type.OnboardingMethod.NetworkPackage;
-import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.ITEM_ID;
-import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.ITEM_NAME;
-import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.SUBMIT_DESCRIPTION;
-import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.VERSION_ID;
-import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.VERSION_NAME;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.function.Predicate;
-import java.util.stream.Collectors;
-import javax.inject.Named;
-import javax.ws.rs.core.Response;
import org.apache.commons.collections4.MapUtils;
import org.openecomp.core.dao.UniqueValueDaoFactory;
import org.openecomp.core.util.UniqueValueUtil;
@@ -109,6 +86,30 @@ import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
+import javax.inject.Named;
+import javax.ws.rs.core.Response;
+import java.io.File;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+
+import static javax.ws.rs.core.HttpHeaders.CONTENT_DISPOSITION;
+import static org.openecomp.sdc.itempermissions.notifications.NotificationConstants.PERMISSION_USER;
+import static org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME;
+import static org.openecomp.sdc.vendorsoftwareproduct.dao.type.OnboardingMethod.NetworkPackage;
+import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.ITEM_ID;
+import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.ITEM_NAME;
+import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.SUBMIT_DESCRIPTION;
+import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.VERSION_ID;
+import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.VERSION_NAME;
+
@Named
@Service("vendorSoftwareProducts")
@Scope(value = "prototype")
@@ -565,25 +566,29 @@ public class VendorSoftwareProductsImpl implements VendorSoftwareProducts {
.build();
}
- private void addNetworkPackageInfo(String vspId, Version version, VspDetailsDto vspDetailsDto) {
- OrchestrationTemplateCandidateData candidateInfo =
- OrchestrationTemplateCandidateManagerFactory.getInstance().createInterface()
- .getInfo(vspId, version);
- if (Objects.nonNull(candidateInfo) && Objects.nonNull(candidateInfo.getFileSuffix())) {
- vspDetailsDto.setValidationData(candidateInfo.getValidationDataStructure());
- vspDetailsDto.setNetworkPackageName(candidateInfo.getFileName());
- vspDetailsDto.setCandidateOnboardingOrigin(candidateInfo.getFileSuffix());
- } else {
- OrchestrationTemplateEntity orchestrationTemplateInfo =
- vendorSoftwareProductManager.getOrchestrationTemplateInfo(vspId, version);
- if (Objects.nonNull(orchestrationTemplateInfo) && Objects.nonNull(orchestrationTemplateInfo
- .getFileSuffix())) {
- vspDetailsDto.setValidationData(orchestrationTemplateInfo.getValidationDataStructure());
- vspDetailsDto.setNetworkPackageName(orchestrationTemplateInfo.getFileName());
- vspDetailsDto.setOnboardingOrigin(orchestrationTemplateInfo.getFileSuffix());
- }
+ private void addNetworkPackageInfo(String vspId, Version version, VspDetailsDto vspDetailsDto) {
+ Optional<OrchestrationTemplateCandidateData> candidateInfo =
+ OrchestrationTemplateCandidateManagerFactory.getInstance().createInterface()
+ .getInfo(vspId, version);
+ if (candidateInfo.isPresent()) {
+ if (candidateInfo.get().getValidationDataStructure() != null) {
+ vspDetailsDto.setValidationData(candidateInfo.get().getValidationDataStructure());
+ }
+ vspDetailsDto.setNetworkPackageName(candidateInfo.get().getFileName());
+ vspDetailsDto.setCandidateOnboardingOrigin(candidateInfo.get().getFileSuffix());
+ } else {
+ OrchestrationTemplateEntity orchestrationTemplateInfo =
+ vendorSoftwareProductManager.getOrchestrationTemplateInfo(vspId, version);
+ if (Objects.nonNull(orchestrationTemplateInfo) && Objects.nonNull(orchestrationTemplateInfo
+ .getFileSuffix())) {
+ if (orchestrationTemplateInfo.getValidationDataStructure() != null) {
+ vspDetailsDto.setValidationData(orchestrationTemplateInfo.getValidationDataStructure());
}
+ vspDetailsDto.setNetworkPackageName(orchestrationTemplateInfo.getFileName());
+ vspDetailsDto.setOnboardingOrigin(orchestrationTemplateInfo.getFileSuffix());
+ }
}
+ }
private boolean userHasPermission(String itemId, String userId) {
return permissionsManager.getUserItemPermission(itemId, userId)
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/OrchestrationTemplateCandidateManager.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/OrchestrationTemplateCandidateManager.java
index a28e2c8144..238dbc08d0 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/OrchestrationTemplateCandidateManager.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/OrchestrationTemplateCandidateManager.java
@@ -41,7 +41,7 @@ public interface OrchestrationTemplateCandidateManager {
Optional<Pair<String, byte[]>> get(String vspId, Version version) throws IOException;
- OrchestrationTemplateCandidateData getInfo(String vspId, Version version);
+ Optional<OrchestrationTemplateCandidateData> getInfo(String vspId, Version version);
void abort(String vspId, Version version);
}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImpl.java
index e5b953ffda..57f6b672be 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImpl.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImpl.java
@@ -45,7 +45,6 @@ import java.io.InputStream;
import java.util.Collections;
import java.util.List;
import java.util.Map;
-import java.util.Objects;
import java.util.Optional;
public class OrchestrationTemplateCandidateManagerImpl
@@ -78,9 +77,10 @@ public class OrchestrationTemplateCandidateManagerImpl
@Override
public OrchestrationTemplateActionResponse process(String vspId, Version version) {
- OrchestrationTemplateCandidateData candidate = fetchCandidateDataEntity(vspId, version)
- .orElseThrow(
- () -> new CoreException(new OrchestrationTemplateNotFoundErrorBuilder(vspId).build()));
+ OrchestrationTemplateCandidateData candidate =
+ candidateService.getOrchestrationTemplateCandidate(vspId, version)
+ .orElseThrow(() -> new CoreException(
+ new OrchestrationTemplateNotFoundErrorBuilder(vspId).build()));
return OrchestrationProcessFactory.getInstance(candidate.getFileSuffix())
.map(processor -> processor.process(getVspDetails(vspId, version), candidate))
@@ -117,27 +117,22 @@ public class OrchestrationTemplateCandidateManagerImpl
VspDetails vspDetails = getVspDetails(vspId, version);
Optional<OrchestrationTemplateCandidateData> candidateDataEntity =
- fetchCandidateDataEntity(vspId, version);
+ candidateService.getOrchestrationTemplateCandidate(vspId, version);
if (!candidateDataEntity.isPresent()) {
return Optional.empty();
}
- if(Objects.isNull(candidateDataEntity.get().getFileSuffix())) {
- return Optional.empty();
- }
-
- OnboardingTypesEnum type =
- OnboardingTypesEnum.getOnboardingTypesEnum(candidateDataEntity.get().getFileSuffix());
-
if (CommonUtil.isFileOriginFromZip(candidateDataEntity.get().getFileSuffix())) {
FilesDataStructure structure = JsonUtil
.json2Object(candidateDataEntity.get().getFilesDataStructure(), FilesDataStructure.class);
String manifest = candidateService.createManifest(vspDetails, structure);
+ OnboardingTypesEnum type =
+ OnboardingTypesEnum.getOnboardingTypesEnum(candidateDataEntity.get().getFileSuffix());
return Optional.of(
new ImmutablePair<>(OnboardingTypesEnum.ZIP.toString(), candidateService
.replaceManifestInZip(candidateDataEntity.get().getContentData(),
- manifest, vspId, type)));
+ manifest, type)));
}
return Optional.of(
@@ -146,7 +141,7 @@ public class OrchestrationTemplateCandidateManagerImpl
}
@Override
- public OrchestrationTemplateCandidateData getInfo(String vspId, Version version) {
+ public Optional<OrchestrationTemplateCandidateData> getInfo(String vspId, Version version) {
return candidateService.getOrchestrationTemplateCandidateInfo(vspId, version);
}
@@ -155,16 +150,7 @@ public class OrchestrationTemplateCandidateManagerImpl
candidateService.deleteOrchestrationTemplateCandidate(vspId, version);
}
- private Optional<OrchestrationTemplateCandidateData> fetchCandidateDataEntity(
- String vspId, Version version) {
- return Optional
- .ofNullable(candidateService.getOrchestrationTemplateCandidate(vspId, version));
- }
-
private VspDetails getVspDetails(String vspId, Version version) {
-
return vspInfoDao.get(new VspDetails(vspId, version));
}
-
-
}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java
index f116abef16..5874394e96 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java
@@ -68,7 +68,6 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.type.DeploymentFlavorEntity;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ImageEntity;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OnboardingMethod;
-import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateEntity;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.PackageInfo;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
@@ -127,6 +126,10 @@ import java.util.Set;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
+import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductInvalidErrorBuilder.candidateDataNotProcessedOrAbortedErrorBuilder;
+import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductInvalidErrorBuilder.invalidProcessedCandidate;
+import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductInvalidErrorBuilder.vspMissingDeploymentFlavorErrorBuilder;
+
public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductManager {
private final VspMergeDao vspMergeDao;
@@ -258,19 +261,14 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
private void validateOrchestrationTemplateCandidate(ValidationResponse validationResponse,
List<ErrorCode> vspErrors, String vspId,
Version version) {
- OrchestrationTemplateCandidateData orchestrationTemplateCandidateData =
- orchestrationTemplateCandidateManager.getInfo(vspId, version);
- String validationData = orchestrationTemplateCandidateData.getValidationData();
- String fileName = orchestrationTemplateCandidateData.getFileName();
- if (Objects.nonNull(orchestrationTemplateCandidateData.getFileSuffix())) {
- if (validationData.isEmpty()) {
- vspErrors.add(VendorSoftwareProductInvalidErrorBuilder
- .candidateDataNotProcessedOrAbortedErrorBuilder(fileName));
- } else {
- vspErrors.add(VendorSoftwareProductInvalidErrorBuilder.invalidProcessedCandidate(fileName));
- }
- validationResponse.setVspErrors(vspErrors);
- }
+ orchestrationTemplateCandidateManager.getInfo(vspId, version)
+ .ifPresent(candidateInfo -> {
+ String fileName = candidateInfo.getFileName();
+ vspErrors.add(candidateInfo.getValidationData().isEmpty()
+ ? candidateDataNotProcessedOrAbortedErrorBuilder(fileName)
+ : invalidProcessedCandidate(fileName));
+ validationResponse.setVspErrors(vspErrors);
+ });
}
private void validateManualOnboardingMethod(VspDetails vspDetails,
@@ -281,8 +279,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
Collection<DeploymentFlavorEntity> deploymentFlavors = deploymentFlavorDao
.list(new DeploymentFlavorEntity(vspDetails.getId(), vspDetails.getVersion(), null));
if (CollectionUtils.isEmpty(deploymentFlavors)) {
- vspErrors
- .add(VendorSoftwareProductInvalidErrorBuilder.vspMissingDeploymentFlavorErrorBuilder());
+ vspErrors.add(vspMissingDeploymentFlavorErrorBuilder());
}
vspErrors.addAll(validateDeploymentFlavors(deploymentFlavors));
@@ -675,7 +672,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
return packageInfo;
}
- protected void populateVersionsForVlm(String vlmId, Version vlmVersion) {
+ void populateVersionsForVlm(String vlmId, Version vlmVersion) {
VersioningManager versioningManager = VersioningManagerFactory.getInstance().createInterface();
versioningManager.list(vlmId).stream()
.filter(version -> version.getId().equalsIgnoreCase(vlmVersion.getId()))
@@ -852,11 +849,12 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
return computeDao.listByVsp(vspId, version);
}
- private boolean isOrchestrationTemplateMissing(OrchestrationTemplateEntity orchestrationTemplate) {
+ private boolean isOrchestrationTemplateMissing(
+ OrchestrationTemplateEntity orchestrationTemplate) {
return orchestrationTemplate == null
- || orchestrationTemplate.getContentData() == null
- || orchestrationTemplate.getFileSuffix() == null
- || orchestrationTemplate.getFileName() == null;
+ || orchestrationTemplate.getContentData() == null
+ || orchestrationTemplate.getFileSuffix() == null
+ || orchestrationTemplate.getFileName() == null;
}
private boolean isServiceModelMissing(ToscaServiceModel serviceModel) {
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImplTest.java
index a86b1ef0c5..2c97937eab 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImplTest.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImplTest.java
@@ -95,7 +95,7 @@ public class OrchestrationTemplateCandidateManagerImplTest {
private OrchestrationUtil orchestrationUtil;
@BeforeClass
- public void setUp() throws Exception {
+ public void setUp() {
MockitoAnnotations.initMocks(this);
}
@@ -129,7 +129,7 @@ public class OrchestrationTemplateCandidateManagerImplTest {
" }\n" +
" ]\n" +
"}");
- doReturn(orchTemplate)
+ doReturn(Optional.of(orchTemplate))
.when(candidateServiceMock).getOrchestrationTemplateCandidate(any(), any());
doReturn(new VspDetails(VSP_ID, VERSION01))
@@ -260,7 +260,7 @@ public class OrchestrationTemplateCandidateManagerImplTest {
@Test
public void testGetFileDataStructure() {
- Optional<String> jsonFileDataStructure = Optional.of(new String("{\n" +
+ Optional<String> jsonFileDataStructure = Optional.of("{\n" +
" \"modules\": [\n" +
" {\n" +
" \"yaml\": \"hot-mog-0108-bs1271.yml\",\n" +
@@ -270,7 +270,7 @@ public class OrchestrationTemplateCandidateManagerImplTest {
" \"unassigned\": [],\n" +
" \"artifacts\": [],\n" +
" \"nested\": []\n" +
- "}"));
+ "}");
Optional<FilesDataStructure> filesDataStructureOptional = Optional.of(JsonUtil.json2Object
(jsonFileDataStructure.get(), FilesDataStructure.class));
doReturn(filesDataStructureOptional).when(candidateServiceMock)
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImplTest.java
index f5c7fb29e8..9149fcfb3f 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImplTest.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImplTest.java
@@ -16,14 +16,6 @@
package org.openecomp.sdc.vendorsoftwareproduct.impl;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyObject;
-import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
-
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.InjectMocks;
@@ -67,7 +59,6 @@ import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
import org.openecomp.sdc.vendorsoftwareproduct.types.ValidationResponse;
import org.openecomp.sdc.vendorsoftwareproduct.types.composition.DeploymentFlavor;
import org.openecomp.sdc.versioning.ActionVersioningManager;
-import org.openecomp.sdc.versioning.VersioningManager;
import org.openecomp.sdc.versioning.dao.types.Version;
import org.openecomp.sdc.versioning.dao.types.VersionStatus;
import org.openecomp.sdc.versioning.types.VersionInfo;
@@ -88,22 +79,26 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
+import java.util.Optional;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+
public class VendorSoftwareProductManagerImplTest {
- private static final String INVALID_VERSION_MSG = "Invalid requested version.";
- private static String VSP_ID = "vspId";
- private static String VERSION_ID = "versionId";
- public static final Version VERSION01 = new Version(0, 1);
- private static final Version VERSION10 = new Version(1, 0);
+ private static final String VSP_ID = "vspId";
+ private static final Version VERSION01 = new Version("0, 1");
+ private static final Version VERSION10 = new Version("1, 0");
private static final String USER1 = "vspTestUser1";
private static final String USER2 = "vspTestUser2";
- private static final String USER3 = "vspTestUser3";
- private static String id006 = null;
- private static String id007 = null;
@Mock
private ActionVersioningManager versioningManagerMock;
@@ -148,12 +143,12 @@ public class VendorSoftwareProductManagerImplTest {
private ArgumentCaptor<ActivityLogEntity> activityLogEntityArg;
@BeforeMethod
- public void setUp() throws Exception {
+ public void setUp() {
MockitoAnnotations.initMocks(this);
}
@AfterMethod
- public void tearDown(){
+ public void tearDown() {
vendorSoftwareProductManager = null;
}
@@ -232,7 +227,7 @@ public class VendorSoftwareProductManagerImplTest {
doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
VersionableEntityAction.Write);
- List<String> fgs = new ArrayList<String>();
+ List<String> fgs = new ArrayList<>();
fgs.add("fg1");
fgs.add("fg2");
VspDetails existingVsp =
@@ -240,7 +235,7 @@ public class VendorSoftwareProductManagerImplTest {
"category",
"subCategory", "456", fgs);
- List<String> updFgs = new ArrayList<String>();
+ List<String> updFgs = new ArrayList<>();
//updFgs.add("fg2");
VspDetails updatedVsp =
createVspDetails(VSP_ID, VERSION01, "VSP1_updated", null, "vendorName", "vlm1Id", "icon",
@@ -256,7 +251,7 @@ public class VendorSoftwareProductManagerImplTest {
flavor.setFeatureGroupId("fg1");
dfEntity.setDeploymentFlavorCompositionData(flavor);
- List<DeploymentFlavorEntity> dfList = new ArrayList<DeploymentFlavorEntity>();
+ List<DeploymentFlavorEntity> dfList = new ArrayList<>();
dfList.add(dfEntity);
doReturn(dfList).when(deploymentFlavorDaoMock).list(anyObject());
@@ -271,7 +266,7 @@ public class VendorSoftwareProductManagerImplTest {
@Test(expectedExceptions = CoreException.class)
public void testGetNonExistingVersion_negative() {
- Version notExistversion = new Version(43, 8);
+ Version notExistversion = new Version("43, 8");
doReturn(null).when(vspInfoDaoMock).get(any(VspDetails.class));
vendorSoftwareProductManager.getVsp(VSP_ID, notExistversion);
}
@@ -301,8 +296,8 @@ public class VendorSoftwareProductManagerImplTest {
@Test
public void testGetOldVersion() {
VersionInfo versionInfo = new VersionInfo();
- versionInfo.setActiveVersion(new Version(0, 2));
- versionInfo.setViewableVersions(Arrays.asList(VERSION01, new Version(0, 2)));
+ versionInfo.setActiveVersion(new Version("0, 2"));
+ versionInfo.setViewableVersions(Arrays.asList(VERSION01, new Version("0, 2")));
versionInfo.setStatus(VersionStatus.Locked);
versionInfo.setLockingUser(USER2);
doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
@@ -440,7 +435,7 @@ public class VendorSoftwareProductManagerImplTest {
}
@Test
- public void testCreatePackage() throws IOException {
+ public void testCreatePackage() {
/*VspDetails vspDetailsMock = new VspDetails("vspId", new Version(1, 0));
doReturn(vspDetailsMock).when(vspInfoDaoMock).get(anyObject());*/
VersionInfo versionInfo = new VersionInfo();
@@ -472,7 +467,7 @@ public class VendorSoftwareProductManagerImplTest {
try (InputStream zis = getFileInputStream("/vspmanager/zips/missingYml.zip")) {
UploadFileResponse uploadFileResponse =
- candidateManager.upload(VSP_ID, VERSION01, zis, "zip", "file");
+ candidateManager.upload(VSP_ID, VERSION01, zis, "zip", "file");
Assert.assertEquals(uploadFileResponse.getErrors().size(), 0);
}
@@ -480,7 +475,7 @@ public class VendorSoftwareProductManagerImplTest {
// TODO: 3/15/2017 fix and enable
//@Test(dependsOnMethods = {"testUploadFileMissingFile"})
- public void testUploadNotZipFile() throws IOException {
+ public void testUploadNotZipFile() {
URL url = this.getClass().getResource("/notZipFile");
try {
@@ -596,7 +591,8 @@ public class VendorSoftwareProductManagerImplTest {
orchestrationTemplateCandidateData.setFileSuffix("zip");
orchestrationTemplateCandidateData.setFilesDataStructure("testdata");
orchestrationTemplateCandidateData.setValidationData("");
- doReturn(orchestrationTemplateCandidateData).when(orchestrationTemplateCandidateManagerMock)
+ doReturn(Optional.of(orchestrationTemplateCandidateData))
+ .when(orchestrationTemplateCandidateManagerMock)
.getInfo(VSP_ID, VERSION01);
ValidationResponse validationResponse =
vendorSoftwareProductManager.validate(VSP_ID, VERSION01);
@@ -619,7 +615,8 @@ public class VendorSoftwareProductManagerImplTest {
OrchestrationTemplateCandidateData();
orchestrationTemplateCandidateData.setFileSuffix("zip");
orchestrationTemplateCandidateData.setValidationData("Invalid processed data");
- doReturn(orchestrationTemplateCandidateData).when(orchestrationTemplateCandidateManagerMock)
+ doReturn(Optional.of(orchestrationTemplateCandidateData))
+ .when(orchestrationTemplateCandidateManagerMock)
.getInfo(VSP_ID, VERSION01);
ValidationResponse validationResponse =
vendorSoftwareProductManager.validate(VSP_ID, VERSION01);
@@ -639,7 +636,7 @@ public class VendorSoftwareProductManagerImplTest {
}
- public InputStream getFileInputStream(String fileName) {
+ private InputStream getFileInputStream(String fileName) {
URL url = this.getClass().getResource(fileName);
try {
return url.openStream();
@@ -649,7 +646,7 @@ public class VendorSoftwareProductManagerImplTest {
}
}
- static VspDetails createVspDetails(String id, Version version, String name, String desc,
+ private static VspDetails createVspDetails(String id, Version version, String name, String desc,
String vendorName, String vlm, String icon,
String category, String subCategory,
String licenseAgreement, List<String> featureGroups) {
@@ -661,14 +658,14 @@ public class VendorSoftwareProductManagerImplTest {
vspDetails.setSubCategory(subCategory);
vspDetails.setVendorName(vendorName);
vspDetails.setVendorId(vlm);
- vspDetails.setVlmVersion(new Version(1, 0));
+ vspDetails.setVlmVersion(new Version("1, 0"));
vspDetails.setLicenseAgreement(licenseAgreement);
vspDetails.setFeatureGroups(featureGroups);
vspDetails.setOnboardingMethod("HEAT");
return vspDetails;
}
- static void assertVspsEquals(VspDetails actual, VspDetails expected) {
+ private static void assertVspsEquals(VspDetails actual, VspDetails expected) {
Assert.assertEquals(actual.getId(), expected.getId());
Assert.assertEquals(actual.getVersion(), expected.getVersion());
Assert.assertEquals(actual.getName(), expected.getName());
diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/OrchestrationTemplateCandidateDao.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/OrchestrationTemplateCandidateDao.java
index 9743814b11..c44ee307b4 100644
--- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/OrchestrationTemplateCandidateDao.java
+++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/OrchestrationTemplateCandidateDao.java
@@ -26,9 +26,9 @@ import java.util.Optional;
public interface OrchestrationTemplateCandidateDao extends VersionableDao {
- OrchestrationTemplateCandidateData get(String vspId, Version version);
+ Optional<OrchestrationTemplateCandidateData> get(String vspId, Version version);
- OrchestrationTemplateCandidateData getInfo(String vspId, Version version);
+ Optional<OrchestrationTemplateCandidateData> getInfo(String vspId, Version version);
void delete(String vspId, Version version);
diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/filedatastructuremodule/CandidateService.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/filedatastructuremodule/CandidateService.java
index 00120759d6..578b120256 100644
--- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/filedatastructuremodule/CandidateService.java
+++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/filedatastructuremodule/CandidateService.java
@@ -44,7 +44,7 @@ public interface CandidateService {
OrchestrationTemplateCandidateData createCandidateDataEntity(
CandidateDataEntityTo candidateDataEntityTo, InputStream zipFileManifest,
- AnalyzedZipHeatFiles analyzedZipHeatFiles) throws Exception;
+ AnalyzedZipHeatFiles analyzedZipHeatFiles);
void updateCandidateUploadData(String vspId, Version version,
OrchestrationTemplateCandidateData uploadData);
@@ -55,11 +55,11 @@ public interface CandidateService {
void updateOrchestrationTemplateCandidateFileDataStructure(String vspId, Version version,
FilesDataStructure fileDataStructure);
- OrchestrationTemplateCandidateData getOrchestrationTemplateCandidate(String vspId,
- Version version);
+ Optional<OrchestrationTemplateCandidateData> getOrchestrationTemplateCandidate(String vspId,
+ Version version);
- OrchestrationTemplateCandidateData getOrchestrationTemplateCandidateInfo(String vspId,
- Version version);
+ Optional<OrchestrationTemplateCandidateData> getOrchestrationTemplateCandidateInfo(String vspId,
+ Version version);
byte[] getZipData(ByteBuffer contentData) throws IOException;
@@ -71,7 +71,7 @@ public interface CandidateService {
OnboardingTypesEnum type,
Map<String, List<ErrorMessage>> uploadErrors);
- byte[] replaceManifestInZip(ByteBuffer contentData, String manifest, String vspId,
+ byte[] replaceManifestInZip(ByteBuffer contentData, String manifest,
OnboardingTypesEnum type) throws IOException;
Optional<ManifestContent> createManifest(VspDetails vspDetails,
diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/zusammen/OrchestrationTemplateCandidateDaoZusammenImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/zusammen/OrchestrationTemplateCandidateDaoZusammenImpl.java
index 22fe1dd98c..f49832dc01 100644
--- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/zusammen/OrchestrationTemplateCandidateDaoZusammenImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/zusammen/OrchestrationTemplateCandidateDaoZusammenImpl.java
@@ -36,7 +36,6 @@ import org.openecomp.sdc.versioning.dao.types.Version;
import java.io.ByteArrayInputStream;
import java.nio.ByteBuffer;
-import java.util.Collection;
import java.util.Optional;
import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement;
@@ -48,7 +47,7 @@ public class OrchestrationTemplateCandidateDaoZusammenImpl
private static final Logger logger =
LoggerFactory.getLogger(OrchestrationTemplateCandidateDaoZusammenImpl.class);
- private ZusammenAdaptor zusammenAdaptor;
+ private final ZusammenAdaptor zusammenAdaptor;
private static final String EMPTY_DATA = "{}";
@@ -62,8 +61,8 @@ public class OrchestrationTemplateCandidateDaoZusammenImpl
}
@Override
- public OrchestrationTemplateCandidateData get(String vspId, Version version) {
- logger.info("Getting orchestration template for VendorSoftwareProduct id -> " + vspId);
+ public Optional<OrchestrationTemplateCandidateData> get(String vspId, Version version) {
+ logger.info("Getting orchestration template for vsp id {}", vspId);
SessionContext context = createSessionContext();
ElementContext elementContext = new ElementContext(vspId, version.getId());
@@ -71,93 +70,75 @@ public class OrchestrationTemplateCandidateDaoZusammenImpl
Optional<Element> candidateElement =
zusammenAdaptor.getElementByName(context, elementContext, null,
ElementType.OrchestrationTemplateCandidate.name());
- if (candidateElement.isPresent()) {
- if (VspZusammenUtil.hasEmptyData(candidateElement.get().getData())) {
- return null;
- }
- OrchestrationTemplateCandidateData candidateData = new OrchestrationTemplateCandidateData();
- candidateData.setFilesDataStructure(
- new String(FileUtils.toByteArray(candidateElement.get().getData())));
- Collection<Element> subElements = candidateElement.get().getSubElements();
- if (subElements.isEmpty()) {
- return candidateData;
- }
+ if (!candidateElement.isPresent() ||
+ VspZusammenUtil.hasEmptyData(candidateElement.get().getData()) ||
+ candidateElement.get().getSubElements().isEmpty()) {
+ logger.info("Orchestration template for vsp id {} does not exist / has empty data", vspId);
+ return Optional.empty();
+ }
- for (Element element : subElements) {
- Optional<Element> subElement = zusammenAdaptor.getElement(context,
- elementContext, element.getElementId().toString());
-
- if (subElement.get().getInfo().getName()
- .equals(ElementType.OrchestrationTemplateCandidateContent
- .name())) {
- candidateData.setContentData(
- ByteBuffer.wrap(FileUtils.toByteArray(subElement.get().getData())));
- candidateData.setFileSuffix(subElement.get().getInfo()
- .getProperty(InfoPropertyName.FILE_SUFFIX.getVal()));
- candidateData.setFileName(subElement.get().getInfo()
- .getProperty(InfoPropertyName.FILE_NAME.getVal()));
- } else if (subElement.get().getInfo().getName()
- .equals(ElementType.OrchestrationTemplateCandidateValidationData.name())) {
- candidateData.setValidationData(new String(FileUtils.toByteArray(subElement
- .get().getData())));
- }
- }
+ OrchestrationTemplateCandidateData candidate = new OrchestrationTemplateCandidateData();
+ candidate.setFilesDataStructure(
+ new String(FileUtils.toByteArray(candidateElement.get().getData())));
- logger
- .info("Finished getting orchestration template for VendorSoftwareProduct id -> " + vspId);
- return candidateData;
- }
- logger.info(String
- .format("Orchestration template for VendorSoftwareProduct id %s does not exist", vspId));
- return null;
+ candidateElement.get().getSubElements().stream()
+ .map(element -> zusammenAdaptor
+ .getElement(context, elementContext, element.getElementId().toString()))
+ .forEach(element -> element.ifPresent(
+ candidateInfoElement -> populateCandidate(candidate, candidateInfoElement, true)));
+
+ logger.info("Finished getting orchestration template for vsp id {}", vspId);
+ return Optional.of(candidate);
}
@Override
- public OrchestrationTemplateCandidateData getInfo(String vspId, Version version) {
- logger.info("Getting orchestration template info for VendorSoftwareProduct id -> " + vspId);
+ public Optional<OrchestrationTemplateCandidateData> getInfo(String vspId, Version version) {
+ logger.info("Getting orchestration template info for vsp id {}", vspId);
SessionContext context = createSessionContext();
ElementContext elementContext = new ElementContext(vspId, version.getId());
- OrchestrationTemplateCandidateData candidateData = new OrchestrationTemplateCandidateData();
-
Optional<ElementInfo> candidateElement =
zusammenAdaptor.getElementInfoByName(context, elementContext, null,
ElementType.OrchestrationTemplateCandidate.name());
- if (candidateElement.isPresent()) {
- Collection<ElementInfo> subElements = candidateElement.get().getSubElements();
- if (subElements.isEmpty()) {
- return candidateData;
- }
+ if (!candidateElement.isPresent() || candidateElement.get().getSubElements().isEmpty()) {
+ logger.info("Orchestration template info for vsp id {} does not exist", vspId);
+ return Optional.empty();
+ }
- for (ElementInfo elementInfo : subElements) {
- Optional<Element> subElement = zusammenAdaptor.getElement(context,
- elementContext, elementInfo.getId().toString());
-
- if (subElement.get().getInfo().getName().equals(ElementType
- .OrchestrationTemplateCandidateContent.name())) {
-
- candidateData.setFileSuffix(subElement.get().getInfo()
- .getProperty(InfoPropertyName.FILE_SUFFIX.getVal()));
- candidateData.setFileName(subElement.get().getInfo()
- .getProperty(InfoPropertyName.FILE_NAME.getVal()));
- } else if (subElement.get().getInfo().getName().equals(ElementType
- .OrchestrationTemplateCandidateValidationData.name())) {
- candidateData.setValidationData(new String(FileUtils.toByteArray(subElement.get()
- .getData())));
- }
+ OrchestrationTemplateCandidateData candidate = new OrchestrationTemplateCandidateData();
+ candidateElement.get().getSubElements().stream()
+ .map(elementInfo -> zusammenAdaptor
+ .getElement(context, elementContext, elementInfo.getId().toString()))
+ .forEach(element -> element.ifPresent(
+ candidateInfoElement -> populateCandidate(candidate, candidateInfoElement, false)));
+ logger.info("Finished getting orchestration template info for vsp id {}", vspId);
+ return candidate.getFileSuffix() == null ? Optional.empty() : Optional.of(candidate);
+ }
+
+ private void populateCandidate(OrchestrationTemplateCandidateData candidate,
+ Element candidateInfoElement,
+ boolean fullData) {
+ if (candidateInfoElement.getInfo().getName()
+ .equals(ElementType.OrchestrationTemplateCandidateContent.name())) {
+
+ if (fullData) {
+ candidate
+ .setContentData(ByteBuffer.wrap(FileUtils.toByteArray(candidateInfoElement.getData())));
}
+ candidate.setFileSuffix(
+ candidateInfoElement.getInfo().getProperty(InfoPropertyName.FILE_SUFFIX.getVal()));
+ candidate.setFileName(
+ candidateInfoElement.getInfo().getProperty(InfoPropertyName.FILE_NAME.getVal()));
+
+ } else if (candidateInfoElement.getInfo().getName()
+ .equals(ElementType.OrchestrationTemplateCandidateValidationData.name())) {
- logger.info(
- "Finished getting orchestration template info for VendorSoftwareProduct id -> " + vspId);
- return candidateData;
+ candidate
+ .setValidationData(new String(FileUtils.toByteArray(candidateInfoElement.getData())));
}
- logger.info(String
- .format("Orchestration template info for VendorSoftwareProduct id %s does not exist",
- vspId));
- return null;
}
@Override
@@ -187,7 +168,7 @@ public class OrchestrationTemplateCandidateDaoZusammenImpl
@Override
public void update(String vspId, Version version,
OrchestrationTemplateCandidateData candidateData) {
- logger.info("Uploading candidate data entity for VendorSoftwareProduct id -> " + vspId);
+ logger.info("Uploading candidate data entity for vsp id {}", vspId);
ZusammenElement candidateElement =
buildStructuralElement(ElementType.OrchestrationTemplateCandidate, Action.UPDATE);
@@ -215,15 +196,14 @@ public class OrchestrationTemplateCandidateDaoZusammenImpl
ElementContext elementContext = new ElementContext(vspId, version.getId());
zusammenAdaptor.saveElement(context, elementContext, candidateElement,
"Update Orchestration Template Candidate");
- logger
- .info("Finished uploading candidate data entity for VendorSoftwareProduct id -> " + vspId);
+ logger.info("Finished uploading candidate data entity for vsp id {}", vspId);
}
@Override
- public void updateValidationData(String vspId, Version version, ValidationStructureList
- validationData) {
- logger.info("Updating validation data of orchestration template candidate for VSP id -> "
- + vspId);
+ public void updateValidationData(String vspId, Version version,
+ ValidationStructureList validationData) {
+ logger
+ .info("Updating validation data of orchestration template candidate for VSP id {} ", vspId);
ZusammenElement validationDataElement = buildStructuralElement(ElementType
.OrchestrationTemplateCandidateValidationData, Action.UPDATE);
@@ -238,13 +218,14 @@ public class OrchestrationTemplateCandidateDaoZusammenImpl
ElementContext elementContext = new ElementContext(vspId, version.getId());
zusammenAdaptor.saveElement(context, elementContext, candidateElement,
"Update Orchestration Template Candidate validation data");
- logger.info("Finished updating validation data of orchestration template candidate for VSP "
- + "id -> " + vspId);
+ logger
+ .info("Finished updating validation data of orchestration template candidate for VSP id {}",
+ vspId);
}
@Override
public void updateStructure(String vspId, Version version, FilesDataStructure fileDataStructure) {
- logger.info("Updating orchestration template for VSP id -> " + vspId);
+ logger.info("Updating orchestration template for VSP id {}", vspId);
ZusammenElement candidateElement =
buildStructuralElement(ElementType.OrchestrationTemplateCandidate, Action.UPDATE);
@@ -255,15 +236,13 @@ public class OrchestrationTemplateCandidateDaoZusammenImpl
ElementContext elementContext = new ElementContext(vspId, version.getId());
zusammenAdaptor.saveElement(context, elementContext, candidateElement,
"Update Orchestration Template Candidate structure");
- logger
- .info("Finished uploading candidate data entity for VendorSoftwareProduct id -> " + vspId);
+ logger.info("Finished uploading candidate data entity for vsp id {}", vspId);
}
@Override
public Optional<String> getStructure(String vspId, Version version) {
- logger.info("Getting orchestration template candidate structure for VendorSoftwareProduct id "
- + "-> " + vspId);
+ logger.info("Getting orchestration template candidate structure for vsp id {}", vspId);
SessionContext context = createSessionContext();
ElementContext elementContext = new ElementContext(vspId, version.getId());
@@ -275,9 +254,7 @@ public class OrchestrationTemplateCandidateDaoZusammenImpl
return Optional.of(new String(FileUtils.toByteArray(element.get().getData())));
}
- logger.info(
- "Finished getting orchestration template candidate structure for VendorSoftwareProduct "
- + "id -> " + vspId);
+ logger.info("Finished getting orchestration template candidate structure for vsp id {}", vspId);
return Optional.empty();
}
@@ -286,13 +263,13 @@ public class OrchestrationTemplateCandidateDaoZusammenImpl
FILE_SUFFIX("fileSuffix"),
FILE_NAME("fileName");
- private String val;
+ private final String val;
- InfoPropertyName(String val){
+ InfoPropertyName(String val) {
this.val = val;
}
- public String getVal() {
+ String getVal() {
return val;
}
}
diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/filedatastructuremodule/CandidateServiceImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/filedatastructuremodule/CandidateServiceImpl.java
index 4618d28756..43a94e03f0 100644
--- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/filedatastructuremodule/CandidateServiceImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/filedatastructuremodule/CandidateServiceImpl.java
@@ -70,7 +70,7 @@ import java.util.zip.ZipOutputStream;
import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters;
public class CandidateServiceImpl implements CandidateService {
- protected static final Logger logger = LoggerFactory.getLogger(CandidateServiceImpl.class);
+ private static final Logger logger = LoggerFactory.getLogger(CandidateServiceImpl.class);
private CandidateServiceValidator candidateServiceValidator = new CandidateServiceValidator();
private ManifestCreator manifestCreator;
private OrchestrationTemplateCandidateDao orchestrationTemplateCandidateDao;
@@ -79,7 +79,6 @@ public class CandidateServiceImpl implements CandidateService {
OrchestrationTemplateCandidateDao orchestrationTemplateCandidateDao) {
this.manifestCreator = manifestCreator;
this.orchestrationTemplateCandidateDao = orchestrationTemplateCandidateDao;
-
}
public CandidateServiceImpl() {
@@ -125,8 +124,7 @@ public class CandidateServiceImpl implements CandidateService {
private String heatStructureTreeToFileDataStructure(HeatStructureTree tree,
FileContentHandler zipContentMap,
Map<String, List<ErrorMessage>> uploadErrors,
- AnalyzedZipHeatFiles analyzedZipHeatFiles)
- throws Exception {
+ AnalyzedZipHeatFiles analyzedZipHeatFiles) {
FilesDataStructure structure = new FilesDataStructure();
Set<String> usedEnvFiles = new HashSet<>();
addHeatsToFileDataStructure(tree, usedEnvFiles, structure, uploadErrors,
@@ -150,7 +148,7 @@ public class CandidateServiceImpl implements CandidateService {
@Override
public OrchestrationTemplateCandidateData createCandidateDataEntity(
CandidateDataEntityTo candidateDataEntityTo, InputStream zipFileManifest,
- AnalyzedZipHeatFiles analyzedZipHeatFiles) throws Exception {
+ AnalyzedZipHeatFiles analyzedZipHeatFiles) {
FileContentHandler zipContentMap = candidateDataEntityTo.getContentMap();
FilesDataStructure filesDataStructure;
String dataStructureJson;
@@ -183,8 +181,7 @@ public class CandidateServiceImpl implements CandidateService {
private void balanceManifestFilesWithZipFiles(
FilesDataStructure filesDataStructure,
- FileContentHandler fileContentHandler, AnalyzedZipHeatFiles analyzedZipHeatFiles)
- throws Exception {
+ FileContentHandler fileContentHandler, AnalyzedZipHeatFiles analyzedZipHeatFiles) {
Set<String> zipFileList = fileContentHandler.getFileList();
filesDataStructure.getNested().addAll(analyzedZipHeatFiles.getNestedFiles());
List<Module> modules = filesDataStructure.getModules();
@@ -249,9 +246,9 @@ public class CandidateServiceImpl implements CandidateService {
CollectionUtils.addIgnoreNull(fileNames, module.getYaml());
}
}
- fileNames.addAll(filesDataStructure.getArtifacts().stream().collect(Collectors.toSet()));
- fileNames.addAll(filesDataStructure.getNested().stream().collect(Collectors.toSet()));
- fileNames.addAll(filesDataStructure.getUnassigned().stream().collect(Collectors.toSet()));
+ fileNames.addAll(filesDataStructure.getArtifacts());
+ fileNames.addAll(filesDataStructure.getNested());
+ fileNames.addAll(filesDataStructure.getUnassigned());
return fileNames;
}
@@ -336,24 +333,23 @@ public class CandidateServiceImpl implements CandidateService {
}
@Override
- public OrchestrationTemplateCandidateData getOrchestrationTemplateCandidate(String vspId,
- Version version) {
+ public Optional<OrchestrationTemplateCandidateData> getOrchestrationTemplateCandidate(String vspId,
+ Version version) {
return orchestrationTemplateCandidateDao.get(vspId, version);
}
@Override
- public OrchestrationTemplateCandidateData getOrchestrationTemplateCandidateInfo(String vspId,
- Version version) {
+ public Optional<OrchestrationTemplateCandidateData> getOrchestrationTemplateCandidateInfo(
+ String vspId,
+ Version version) {
return orchestrationTemplateCandidateDao.getInfo(vspId, version);
}
@Override
public String createManifest(VspDetails vspDetails, FilesDataStructure structure) {
- Optional<ManifestContent> manifest = manifestCreator.createManifest(vspDetails, structure);
- if (!manifest.isPresent()) {
- throw new RuntimeException(Messages.CREATE_MANIFEST_FROM_ZIP.getErrorMessage());
- }
- return JsonUtil.object2Json(manifest.get());
+ return JsonUtil.object2Json(manifestCreator.createManifest(vspDetails, structure)
+ .orElseThrow(() -> new CoreException(new ErrorCode.ErrorCodeBuilder()
+ .withMessage(Messages.CREATE_MANIFEST_FROM_ZIP.getErrorMessage()).build())));
}
@Override
@@ -372,7 +368,7 @@ public class CandidateServiceImpl implements CandidateService {
byte[] file;
ByteArrayInputStream byteArrayInputStream = null;
try {
- file = replaceManifestInZip(candidateDataEntity.getContentData(), manifest, vspId, type);
+ file = replaceManifestInZip(candidateDataEntity.getContentData(), manifest, type);
byteArrayInputStream = new ByteArrayInputStream(
Objects.isNull(file) ? candidateDataEntity.getContentData().array()
: file);
@@ -388,7 +384,7 @@ public class CandidateServiceImpl implements CandidateService {
}
@Override
- public byte[] replaceManifestInZip(ByteBuffer contentData, String manifest, String vspId,
+ public byte[] replaceManifestInZip(ByteBuffer contentData, String manifest,
OnboardingTypesEnum type)
throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -525,19 +521,14 @@ public class CandidateServiceImpl implements CandidateService {
}
private boolean isEnvFileUsedByHeatFile(Set<String> usedEnvFiles, HeatStructureTree other) {
- if (HeatFileAnalyzer.isEnvFile(other.getFileName())) {
- if (usedEnvFiles.contains(other.getFileName())) {
- return true;
- }
- }
- return false;
+ return HeatFileAnalyzer.isEnvFile(other.getFileName()) &&
+ usedEnvFiles.contains(other.getFileName());
}
private void addHeatsToFileDataStructure(HeatStructureTree tree, Set<String> usedEnvFiles,
FilesDataStructure structure,
Map<String, List<ErrorMessage>> uploadErrors,
- AnalyzedZipHeatFiles analyzedZipHeatFiles)
- throws Exception {
+ AnalyzedZipHeatFiles analyzedZipHeatFiles) {
List<Module> modules = new ArrayList<>();
Set<HeatStructureTree> heatsSet = tree.getHeat();
if (Objects.isNull(heatsSet)) {