From d378c37fbd1ecec7b43394926f1ca32a695e07de Mon Sep 17 00:00:00 2001 From: vasraz Date: Mon, 22 Mar 2021 15:33:06 +0000 Subject: Reformat openecomp-be Signed-off-by: Vasyl Razinkov Issue-ID: SDC-3449 Change-Id: I13e02322f8e00820cc5a1d85752caaeda9bf10d1 --- ...estrationTemplateFileExtensionErrorBuilder.java | 31 +- ...VendorSoftwareProductCreationFailedBuilder.java | 34 +- .../VendorSoftwareProductNotFoundErrorBuilder.java | 39 +- .../dao/impl/ComponentDaoFactoryImpl.java | 17 +- .../ComponentDependencyModelDaoFactoryImpl.java | 18 +- .../dao/impl/ComputeDaoFactoryImpl.java | 17 +- .../dao/impl/DeploymentFlavorDaoFactoryImpl.java | 10 +- .../dao/impl/ImageDaoFactoryImpl.java | 16 +- .../dao/impl/MonitoringUploadDaoFactoryImpl.java | 17 +- .../dao/impl/NetworkDaoFactoryImpl.java | 17 +- .../dao/impl/NicDaoFactoryImpl.java | 17 +- ...chestrationTemplateCandidateDaoFactoryImpl.java | 22 +- .../impl/OrchestrationTemplateDaoFactoryImpl.java | 21 +- .../dao/impl/PackageInfoDaoFactoryImpl.java | 16 +- .../dao/impl/PackageInfoDaoImpl.java | 89 +- .../dao/impl/ProcessDaoFactoryImpl.java | 17 +- .../VendorSoftwareProductInfoDaoFactoryImpl.java | 19 +- .../dao/impl/VspMergeDaoFactoryImpl.java | 17 +- .../dao/impl/VspMergeDaoImpl.java | 257 +++-- .../zusammen/ComponentArtifactDaoZusammenImpl.java | 310 +++--- .../impl/zusammen/ComponentDaoZusammenImpl.java | 364 +++---- .../ComponentDependencyModelDaoZusammenImpl.java | 221 ++--- .../ComponentDependencyModelPropertyName.java | 13 +- .../dao/impl/zusammen/ComputeDaoZusammenImpl.java | 341 +++---- .../zusammen/DeploymentFlavorDaoZusammenImpl.java | 235 ++--- .../dao/impl/zusammen/ImageDaoZusammenImpl.java | 339 +++---- .../dao/impl/zusammen/NetworkDaoZusammenImpl.java | 223 ++--- .../dao/impl/zusammen/NicDaoZusammenImpl.java | 376 ++++---- ...hestrationTemplateCandidateDaoZusammenImpl.java | 377 +++----- .../OrchestrationTemplateDaoZusammenImpl.java | 309 +++--- .../dao/impl/zusammen/ProcessDaoZusammenImpl.java | 365 +++---- .../VendorSoftwareProductInfoDaoZusammenImpl.java | 403 ++++---- .../dao/impl/zusammen/VspZusammenUtil.java | 62 +- .../convertor/ElementToComponentConvertor.java | 50 +- ...ElementToComponentDependencyModelConvertor.java | 59 +- ...lementToComponentMonitoringUploadConvertor.java | 61 +- .../ElementToComponentQuestionnnaireConvertor.java | 20 +- .../ElementToCompositionEntityConvertor.java | 69 +- .../convertor/ElementToComputeConvertor.java | 56 +- .../ElementToComputeQuestionnaireConvertor.java | 23 +- .../ElementToDeploymentFlavorConvertor.java | 56 +- .../convertor/ElementToImageConvertor.java | 56 +- .../ElementToImageQuestionnaireConvertor.java | 23 +- .../ElementToMonitoringUploadMapConvertor.java | 27 +- .../convertor/ElementToNetworkConvertor.java | 54 +- .../zusammen/convertor/ElementToNicConvertor.java | 55 +- .../ElementToNicQuestionnaireConvertor.java | 25 +- ...OrchestrationTemplateCandidateMapConvertor.java | 17 +- .../convertor/ElementToProcessConvertor.java | 68 +- .../ElementToServiceModelMapConvertor.java | 25 +- .../convertor/ElementToVSPGeneralConvertor.java | 104 +- .../ElementToVSPQuestionnaireConvertor.java | 14 +- .../errors/VendorSoftwareProductErrorCodes.java | 167 ++-- .../InformationArtifactGeneratorFactoryImpl.java | 15 +- .../QuestionnaireDataServiceFactoryImpl.java | 15 +- .../factory/impl/CandidateServiceFactoryImpl.java | 16 +- .../impl/CompositionDataExtractorFactoryImpl.java | 13 +- .../factory/impl/ManifestCreatorFactoryImpl.java | 13 +- .../impl/TxtInformationArtifactConstants.java | 129 ++- .../impl/TxtInformationArtifactGeneratorImpl.java | 380 ++++---- .../QuestionnaireDataServiceImpl.java | 102 +- .../services/ManualVspDataCollectionService.java | 611 ++++++------ .../composition/CompositionDataExtractorImpl.java | 686 ++++++------- .../services/impl/etsi/ETSIServiceImpl.java | 92 +- .../CandidateServiceImpl.java | 1006 +++++++++----------- .../ManifestCreatorNamingConventionImpl.java | 513 +++++----- .../services/utils/CandidateServiceValidator.java | 69 +- 67 files changed, 4088 insertions(+), 5230 deletions(-) (limited to 'openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core') 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/errors/OrchestrationTemplateFileExtensionErrorBuilder.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/errors/OrchestrationTemplateFileExtensionErrorBuilder.java index 58faa41872..caf4f0486d 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/errors/OrchestrationTemplateFileExtensionErrorBuilder.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/errors/OrchestrationTemplateFileExtensionErrorBuilder.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,26 +17,25 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.errors; +import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes.INVALID_EXTENSION; + import org.openecomp.sdc.common.errors.ErrorCategory; import org.openecomp.sdc.common.errors.ErrorCode; -import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes.INVALID_EXTENSION; - public class OrchestrationTemplateFileExtensionErrorBuilder { - private static final String INVALID_EXTENSION_MSG = "Invalid file extension. Valid extensions " + - "are : zip, csar."; - private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder(); - public OrchestrationTemplateFileExtensionErrorBuilder(){ - builder.withId(INVALID_EXTENSION); - builder.withCategory(ErrorCategory.APPLICATION); - builder.withMessage(String.format(INVALID_EXTENSION_MSG)); - } + private static final String INVALID_EXTENSION_MSG = "Invalid file extension. Valid extensions " + "are : zip, csar."; + private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder(); + + public OrchestrationTemplateFileExtensionErrorBuilder() { + builder.withId(INVALID_EXTENSION); + builder.withCategory(ErrorCategory.APPLICATION); + builder.withMessage(String.format(INVALID_EXTENSION_MSG)); + } - public ErrorCode build() { - return builder.build(); - } + public ErrorCode build() { + return builder.build(); + } } 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/errors/VendorSoftwareProductCreationFailedBuilder.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/errors/VendorSoftwareProductCreationFailedBuilder.java index a7abbe0dd9..1dc1c40ca9 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/errors/VendorSoftwareProductCreationFailedBuilder.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/errors/VendorSoftwareProductCreationFailedBuilder.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.errors; import org.openecomp.sdc.common.errors.ErrorCategory; @@ -25,21 +24,20 @@ import org.openecomp.sdc.common.errors.ErrorCode; import org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes; public class VendorSoftwareProductCreationFailedBuilder { - private static final String VSP_CREATION_FAILED = "Failed to create VSP; %s"; - private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder(); - /** - * Instantiates a new Vendor software product creation failed error builder. - * - */ - public VendorSoftwareProductCreationFailedBuilder(String reason) { - builder.withId(VendorSoftwareProductErrorCodes.FAILED_TO_CREATE_VSP); - builder.withCategory(ErrorCategory.APPLICATION); - builder - .withMessage(String.format(VSP_CREATION_FAILED, reason)); - } + private static final String VSP_CREATION_FAILED = "Failed to create VSP; %s"; + private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder(); + + /** + * Instantiates a new Vendor software product creation failed error builder. + */ + public VendorSoftwareProductCreationFailedBuilder(String reason) { + builder.withId(VendorSoftwareProductErrorCodes.FAILED_TO_CREATE_VSP); + builder.withCategory(ErrorCategory.APPLICATION); + builder.withMessage(String.format(VSP_CREATION_FAILED, reason)); + } - public ErrorCode build() { - return builder.build(); - } + public ErrorCode build() { + return builder.build(); + } } 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/errors/VendorSoftwareProductNotFoundErrorBuilder.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/errors/VendorSoftwareProductNotFoundErrorBuilder.java index ef5b43fad4..8cb2d72d25 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/errors/VendorSoftwareProductNotFoundErrorBuilder.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/errors/VendorSoftwareProductNotFoundErrorBuilder.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,31 +17,30 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.errors; +import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes.VSP_NOT_FOUND; import org.openecomp.sdc.common.errors.ErrorCategory; import org.openecomp.sdc.common.errors.ErrorCode; -import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes.VSP_NOT_FOUND; - public class VendorSoftwareProductNotFoundErrorBuilder { - private static final String VSP_FOUND_MSG = "Vendor software product with Id %s not found."; - private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder(); - /** - * Instantiates a new Vendor software product not found error builder. - * - * @param vendorSoftwareProductId the vendor software product id - */ - public VendorSoftwareProductNotFoundErrorBuilder(String vendorSoftwareProductId) { - builder.withId(VSP_NOT_FOUND); - builder.withCategory(ErrorCategory.APPLICATION); - builder.withMessage(String.format(VSP_FOUND_MSG, vendorSoftwareProductId)); - } + private static final String VSP_FOUND_MSG = "Vendor software product with Id %s not found."; + private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder(); + + /** + * Instantiates a new Vendor software product not found error builder. + * + * @param vendorSoftwareProductId the vendor software product id + */ + public VendorSoftwareProductNotFoundErrorBuilder(String vendorSoftwareProductId) { + builder.withId(VSP_NOT_FOUND); + builder.withCategory(ErrorCategory.APPLICATION); + builder.withMessage(String.format(VSP_FOUND_MSG, vendorSoftwareProductId)); + } - public ErrorCode build() { - return builder.build(); - } + public ErrorCode build() { + return builder.build(); + } } 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/ComponentDaoFactoryImpl.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/ComponentDaoFactoryImpl.java index 1ef0caac0c..bcf4cf1dcd 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/ComponentDaoFactoryImpl.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/ComponentDaoFactoryImpl.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory; @@ -26,11 +25,11 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDaoFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.ComponentDaoZusammenImpl; public class ComponentDaoFactoryImpl extends ComponentDaoFactory { - private static final ComponentDao INSTANCE = new ComponentDaoZusammenImpl( - ZusammenAdaptorFactory.getInstance().createInterface()); - @Override - public ComponentDao createInterface() { - return INSTANCE; - } + private static final ComponentDao INSTANCE = new ComponentDaoZusammenImpl(ZusammenAdaptorFactory.getInstance().createInterface()); + + @Override + public ComponentDao createInterface() { + return INSTANCE; + } } 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/ComponentDependencyModelDaoFactoryImpl.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/ComponentDependencyModelDaoFactoryImpl.java index f4f36c3355..180f11917a 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/ComponentDependencyModelDaoFactoryImpl.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/ComponentDependencyModelDaoFactoryImpl.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,10 +17,8 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; - import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDependencyModelDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDependencyModelDaoFactory; @@ -28,11 +26,11 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.ComponentDepend public class ComponentDependencyModelDaoFactoryImpl extends ComponentDependencyModelDaoFactory { - private static final ComponentDependencyModelDao INSTANCE = new - ComponentDependencyModelDaoZusammenImpl( ZusammenAdaptorFactory.getInstance().createInterface()); + private static final ComponentDependencyModelDao INSTANCE = new ComponentDependencyModelDaoZusammenImpl( + ZusammenAdaptorFactory.getInstance().createInterface()); - @Override - public ComponentDependencyModelDao createInterface() { - return INSTANCE; - } + @Override + public ComponentDependencyModelDao createInterface() { + return INSTANCE; + } } 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/ComputeDaoFactoryImpl.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/ComputeDaoFactoryImpl.java index 3032d523c4..1a9127c95a 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/ComputeDaoFactoryImpl.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/ComputeDaoFactoryImpl.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory; @@ -26,11 +25,11 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.ComputeDaoFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.ComputeDaoZusammenImpl; public class ComputeDaoFactoryImpl extends ComputeDaoFactory { - private static final ComputeDao INSTANCE = new ComputeDaoZusammenImpl( - ZusammenAdaptorFactory.getInstance().createInterface()); - @Override - public ComputeDao createInterface() { - return INSTANCE; - } + private static final ComputeDao INSTANCE = new ComputeDaoZusammenImpl(ZusammenAdaptorFactory.getInstance().createInterface()); + + @Override + public ComputeDao createInterface() { + return INSTANCE; + } } 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/DeploymentFlavorDaoFactoryImpl.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/DeploymentFlavorDaoFactoryImpl.java index 93ce6b122c..b4ad183539 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/DeploymentFlavorDaoFactoryImpl.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/DeploymentFlavorDaoFactoryImpl.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory; @@ -25,10 +24,9 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.DeploymentFlavorDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.DeploymentFlavorDaoFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.DeploymentFlavorDaoZusammenImpl; +public class DeploymentFlavorDaoFactoryImpl extends DeploymentFlavorDaoFactory { -public class DeploymentFlavorDaoFactoryImpl extends DeploymentFlavorDaoFactory{ - private static final DeploymentFlavorDao INSTANCE = new DeploymentFlavorDaoZusammenImpl( - ZusammenAdaptorFactory.getInstance().createInterface()); + private static final DeploymentFlavorDao INSTANCE = new DeploymentFlavorDaoZusammenImpl(ZusammenAdaptorFactory.getInstance().createInterface()); @Override public DeploymentFlavorDao createInterface() { 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/ImageDaoFactoryImpl.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/ImageDaoFactoryImpl.java index 21abcae517..2d01ecf96a 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/ImageDaoFactoryImpl.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/ImageDaoFactoryImpl.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory; @@ -27,11 +26,10 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.ImageDaoZusamme public class ImageDaoFactoryImpl extends ImageDaoFactory { - private static final ImageDao INSTANCE = new ImageDaoZusammenImpl( - ZusammenAdaptorFactory.getInstance().createInterface()); + private static final ImageDao INSTANCE = new ImageDaoZusammenImpl(ZusammenAdaptorFactory.getInstance().createInterface()); - @Override - public ImageDao createInterface() { - return INSTANCE; - } + @Override + public ImageDao createInterface() { + return INSTANCE; + } } 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/MonitoringUploadDaoFactoryImpl.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/MonitoringUploadDaoFactoryImpl.java index fa6a0cbfc2..bcee3a2789 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/MonitoringUploadDaoFactoryImpl.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/MonitoringUploadDaoFactoryImpl.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory; @@ -26,11 +25,11 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.MonitoringUploadDaoFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.ComponentArtifactDaoZusammenImpl; public class MonitoringUploadDaoFactoryImpl extends MonitoringUploadDaoFactory { - private static final ComponentArtifactDao INSTANCE = new ComponentArtifactDaoZusammenImpl( - ZusammenAdaptorFactory.getInstance().createInterface()); - @Override - public ComponentArtifactDao createInterface() { - return INSTANCE; - } + private static final ComponentArtifactDao INSTANCE = new ComponentArtifactDaoZusammenImpl(ZusammenAdaptorFactory.getInstance().createInterface()); + + @Override + public ComponentArtifactDao createInterface() { + return INSTANCE; + } } 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/NetworkDaoFactoryImpl.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/NetworkDaoFactoryImpl.java index 5bccc5ced2..cc555b4a6c 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/NetworkDaoFactoryImpl.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/NetworkDaoFactoryImpl.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory; @@ -26,11 +25,11 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.NetworkDaoFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.NetworkDaoZusammenImpl; public class NetworkDaoFactoryImpl extends NetworkDaoFactory { - private static final NetworkDao INSTANCE = new NetworkDaoZusammenImpl( - ZusammenAdaptorFactory.getInstance().createInterface()); - @Override - public NetworkDao createInterface() { - return INSTANCE; - } + private static final NetworkDao INSTANCE = new NetworkDaoZusammenImpl(ZusammenAdaptorFactory.getInstance().createInterface()); + + @Override + public NetworkDao createInterface() { + return INSTANCE; + } } 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/NicDaoFactoryImpl.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/NicDaoFactoryImpl.java index 76e5d443f2..956d84e2d4 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/NicDaoFactoryImpl.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/NicDaoFactoryImpl.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory; @@ -26,11 +25,11 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDaoFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.NicDaoZusammenImpl; public class NicDaoFactoryImpl extends NicDaoFactory { - private static final NicDao INSTANCE = new NicDaoZusammenImpl( - ZusammenAdaptorFactory.getInstance().createInterface()); - @Override - public NicDao createInterface() { - return INSTANCE; - } + private static final NicDao INSTANCE = new NicDaoZusammenImpl(ZusammenAdaptorFactory.getInstance().createInterface()); + + @Override + public NicDao createInterface() { + return INSTANCE; + } } 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/OrchestrationTemplateCandidateDaoFactoryImpl.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/OrchestrationTemplateCandidateDaoFactoryImpl.java index 8cc2c6f61f..d0e838ff19 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/OrchestrationTemplateCandidateDaoFactoryImpl.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/OrchestrationTemplateCandidateDaoFactoryImpl.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory; @@ -25,14 +24,13 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateCandidat import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateCandidateDaoFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.OrchestrationTemplateCandidateDaoZusammenImpl; -public class OrchestrationTemplateCandidateDaoFactoryImpl - extends OrchestrationTemplateCandidateDaoFactory { - private static final OrchestrationTemplateCandidateDao INSTANCE = - new OrchestrationTemplateCandidateDaoZusammenImpl( - ZusammenAdaptorFactory.getInstance().createInterface()); +public class OrchestrationTemplateCandidateDaoFactoryImpl extends OrchestrationTemplateCandidateDaoFactory { + + private static final OrchestrationTemplateCandidateDao INSTANCE = new OrchestrationTemplateCandidateDaoZusammenImpl( + ZusammenAdaptorFactory.getInstance().createInterface()); - @Override - public OrchestrationTemplateCandidateDao createInterface() { - return INSTANCE; - } + @Override + public OrchestrationTemplateCandidateDao createInterface() { + return INSTANCE; + } } 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/OrchestrationTemplateDaoFactoryImpl.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/OrchestrationTemplateDaoFactoryImpl.java index 8b90462131..57f37beb24 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/OrchestrationTemplateDaoFactoryImpl.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/OrchestrationTemplateDaoFactoryImpl.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory; @@ -25,15 +24,13 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDaoFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.OrchestrationTemplateDaoZusammenImpl; +public class OrchestrationTemplateDaoFactoryImpl extends OrchestrationTemplateDaoFactory { -public class OrchestrationTemplateDaoFactoryImpl - extends OrchestrationTemplateDaoFactory { - private static final OrchestrationTemplateDao INSTANCE = - new OrchestrationTemplateDaoZusammenImpl( - ZusammenAdaptorFactory.getInstance().createInterface()); + private static final OrchestrationTemplateDao INSTANCE = new OrchestrationTemplateDaoZusammenImpl( + ZusammenAdaptorFactory.getInstance().createInterface()); - @Override - public OrchestrationTemplateDao createInterface() { - return INSTANCE; - } + @Override + public OrchestrationTemplateDao createInterface() { + return INSTANCE; + } } 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/PackageInfoDaoFactoryImpl.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/PackageInfoDaoFactoryImpl.java index 8b9bedcd3a..2982e07d2f 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/PackageInfoDaoFactoryImpl.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/PackageInfoDaoFactoryImpl.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,17 +17,17 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; import org.openecomp.sdc.vendorsoftwareproduct.dao.PackageInfoDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.PackageInfoDaoFactory; public class PackageInfoDaoFactoryImpl extends PackageInfoDaoFactory { - private static final PackageInfoDao INSTANCE = new PackageInfoDaoImpl(); - @Override - public PackageInfoDao createInterface() { - return INSTANCE; - } + private static final PackageInfoDao INSTANCE = new PackageInfoDaoImpl(); + + @Override + public PackageInfoDao createInterface() { + return INSTANCE; + } } 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/PackageInfoDaoImpl.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/PackageInfoDaoImpl.java index ff4fd45420..591af3c8b9 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/PackageInfoDaoImpl.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/PackageInfoDaoImpl.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,72 +17,67 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; import com.datastax.driver.mapping.Mapper; import com.datastax.driver.mapping.Result; import com.datastax.driver.mapping.annotations.Accessor; import com.datastax.driver.mapping.annotations.Query; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; import org.openecomp.core.dao.impl.CassandraBaseDao; import org.openecomp.core.nosqldb.api.NoSqlDb; import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.PackageInfoDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.PackageInfo; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - public class PackageInfoDaoImpl extends CassandraBaseDao implements PackageInfoDao { - private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); - private static final Mapper mapper = - noSqlDb.getMappingManager().mapper(PackageInfo.class); - private static final PackageInfoAccessor accessor = - noSqlDb.getMappingManager().createAccessor(PackageInfoAccessor.class); - @Override - protected Mapper getMapper() { - return mapper; - } + private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); + private static final Mapper mapper = noSqlDb.getMappingManager().mapper(PackageInfo.class); + private static final PackageInfoAccessor accessor = noSqlDb.getMappingManager().createAccessor(PackageInfoAccessor.class); - @Override - protected Object[] getKeys(PackageInfo entity) { - return new Object[]{entity.getVspId(), entity.getVersion()}; - } + @Override + protected Mapper getMapper() { + return mapper; + } - @Override - public Collection list(PackageInfo entity) { - return accessor.listInfo().all(); - } + @Override + protected Object[] getKeys(PackageInfo entity) { + return new Object[]{entity.getVspId(), entity.getVersion()}; + } - @Override - public List listByCategory(String category, String subCategory) { - Result packages = accessor.listInfo(); + @Override + public Collection list(PackageInfo entity) { + return accessor.listInfo().all(); + } - List filteredPackages = new ArrayList<>(); - for (PackageInfo packageInfo : packages) { - if (category != null) { - if (category.equals(packageInfo.getCategory())) { - filteredPackages.add(packageInfo); - } - } else if (subCategory != null) { - if (subCategory.equals(packageInfo.getSubCategory())) { - filteredPackages.add(packageInfo); + @Override + public List listByCategory(String category, String subCategory) { + Result packages = accessor.listInfo(); + List filteredPackages = new ArrayList<>(); + for (PackageInfo packageInfo : packages) { + if (category != null) { + if (category.equals(packageInfo.getCategory())) { + filteredPackages.add(packageInfo); + } + } else if (subCategory != null) { + if (subCategory.equals(packageInfo.getSubCategory())) { + filteredPackages.add(packageInfo); + } + } else { + filteredPackages.add(packageInfo); + } } - } else { - filteredPackages.add(packageInfo); - } + return filteredPackages; } - return filteredPackages; - } - @Accessor - interface PackageInfoAccessor { + @Accessor + interface PackageInfoAccessor { - @Query( - "SELECT vsp_id,version,display_name,vsp_name,vsp_description,vendor_name,category" + @Query("SELECT vsp_id,version,display_name,vsp_name,vsp_description,vendor_name,category" + " ,sub_category, vendor_release,package_checksum,package_type, resource_type FROM package_details") - Result listInfo(); - } + Result listInfo(); + } } 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/ProcessDaoFactoryImpl.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/ProcessDaoFactoryImpl.java index 0205446ae8..72b9c76615 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/ProcessDaoFactoryImpl.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/ProcessDaoFactoryImpl.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory; @@ -26,11 +25,11 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessDaoFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.ProcessDaoZusammenImpl; public class ProcessDaoFactoryImpl extends ProcessDaoFactory { - private static final ProcessDao INSTANCE = new ProcessDaoZusammenImpl( - ZusammenAdaptorFactory.getInstance().createInterface()); - @Override - public ProcessDao createInterface() { - return INSTANCE; - } + private static final ProcessDao INSTANCE = new ProcessDaoZusammenImpl(ZusammenAdaptorFactory.getInstance().createInterface()); + + @Override + public ProcessDao createInterface() { + return INSTANCE; + } } 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/VendorSoftwareProductInfoDaoFactoryImpl.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/VendorSoftwareProductInfoDaoFactoryImpl.java index a5f9d17431..978d11cd3b 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/VendorSoftwareProductInfoDaoFactoryImpl.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/VendorSoftwareProductInfoDaoFactoryImpl.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory; @@ -26,12 +25,12 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDaoF import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.VendorSoftwareProductInfoDaoZusammenImpl; public class VendorSoftwareProductInfoDaoFactoryImpl extends VendorSoftwareProductInfoDaoFactory { - private static final VendorSoftwareProductInfoDao INSTANCE = - new VendorSoftwareProductInfoDaoZusammenImpl( - ZusammenAdaptorFactory.getInstance().createInterface()); - @Override - public VendorSoftwareProductInfoDao createInterface() { - return INSTANCE; - } + private static final VendorSoftwareProductInfoDao INSTANCE = new VendorSoftwareProductInfoDaoZusammenImpl( + ZusammenAdaptorFactory.getInstance().createInterface()); + + @Override + public VendorSoftwareProductInfoDao createInterface() { + return INSTANCE; + } } 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/VspMergeDaoFactoryImpl.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/VspMergeDaoFactoryImpl.java index f6f3c84303..0c7c552489 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/VspMergeDaoFactoryImpl.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/VspMergeDaoFactoryImpl.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,21 +17,18 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; - import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.VspMergeDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.VspMergeDaoFactory; public class VspMergeDaoFactoryImpl extends VspMergeDaoFactory { - private static final VspMergeDao INSTANCE = new - VspMergeDaoImpl(ZusammenAdaptorFactory.getInstance().createInterface()); + private static final VspMergeDao INSTANCE = new VspMergeDaoImpl(ZusammenAdaptorFactory.getInstance().createInterface()); - @Override - public VspMergeDao createInterface() { - return INSTANCE; - } + @Override + public VspMergeDao createInterface() { + return INSTANCE; + } } 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/VspMergeDaoImpl.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/VspMergeDaoImpl.java index 86045ab20a..e7579c6ce6 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/VspMergeDaoImpl.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/VspMergeDaoImpl.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,9 +17,11 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; +import static org.openecomp.core.zusammen.api.ZusammenUtil.buildElement; +import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext; + import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo; import com.amdocs.zusammen.datatypes.Id; import com.amdocs.zusammen.datatypes.SessionContext; @@ -32,6 +34,8 @@ import com.datastax.driver.extras.codecs.enums.EnumNameCodec; import com.datastax.driver.mapping.MappingManager; import com.datastax.driver.mapping.annotations.Accessor; import com.datastax.driver.mapping.annotations.Query; +import java.util.List; +import java.util.stream.Collectors; import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; import org.openecomp.core.zusammen.api.ZusammenAdaptor; import org.openecomp.sdc.common.session.SessionContextProviderFactory; @@ -39,155 +43,120 @@ import org.openecomp.sdc.datatypes.model.ElementType; import org.openecomp.sdc.vendorsoftwareproduct.dao.VspMergeDao; import org.openecomp.sdc.versioning.dao.types.Version; -import java.util.List; -import java.util.stream.Collectors; +public class VspMergeDaoImpl implements VspMergeDao { -import static org.openecomp.core.zusammen.api.ZusammenUtil.buildElement; -import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext; + private static final String VSP_MODEL_NOT_EXIST = "Vsp model does not exist for Vsp %s, version %s."; + private static final VspMergeHintAccessor accessor; -public class VspMergeDaoImpl implements VspMergeDao { - private static final String VSP_MODEL_NOT_EXIST = - "Vsp model does not exist for Vsp %s, version %s."; - - private static final VspMergeHintAccessor accessor; - - static { - MappingManager mappingManager = NoSqlDbFactory.getInstance().createInterface().getMappingManager(); - mappingManager.getSession().getCluster().getConfiguration().getCodecRegistry() - .register(new EnumNameCodec<>(Resolution.class)); - accessor = mappingManager.createAccessor(VspMergeHintAccessor.class); - } - - private ZusammenAdaptor zusammenAdaptor; - - public VspMergeDaoImpl(ZusammenAdaptor zusammenAdaptor) { - this.zusammenAdaptor = zusammenAdaptor; - } - - @Override - public boolean isConflicted(String vspId, Version version) { - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(new Id(vspId), new Id(version.getId())); - - return listVspModels(context, elementContext).size() > 1; - } - - @Override - public void updateHint(String vspId, Version version) { - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(new Id(vspId), new Id(version.getId())); - - String vspModelId = zusammenAdaptor - .getElementInfoByName(context, elementContext, null, ElementType.VspModel.name()) - .orElseThrow(() -> new IllegalStateException( - String.format(VSP_MODEL_NOT_EXIST, vspId, version.getId()))) - .getId().getValue(); - - updateVspModelId(vspId, version, vspModelId); - } - - @Override - public void deleteHint(String vspId, Version version) { - accessor.delete(getUser(),vspId,version.getId()); - } - - @Override - public void updateConflictResolution(String vspId, Version version, - Resolution resolution) { - accessor.updateModelResolution(resolution, getUser(), vspId, version.getId()); - } - - @Override - public void applyConflictResolution(String vspId, Version version) { - //called only when no conflicts - - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(new Id(vspId), new Id(version.getId())); - - List vspModels = listVspModels(context, elementContext); - if (vspModels.size() == 1) { - updateVspModelId(vspId, version, vspModels.iterator().next().getId().getValue()); - return; + static { + MappingManager mappingManager = NoSqlDbFactory.getInstance().createInterface().getMappingManager(); + mappingManager.getSession().getCluster().getConfiguration().getCodecRegistry().register(new EnumNameCodec<>(Resolution.class)); + accessor = mappingManager.createAccessor(VspMergeHintAccessor.class); + } + + private ZusammenAdaptor zusammenAdaptor; + + public VspMergeDaoImpl(ZusammenAdaptor zusammenAdaptor) { + this.zusammenAdaptor = zusammenAdaptor; + } + + @Override + public boolean isConflicted(String vspId, Version version) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(new Id(vspId), new Id(version.getId())); + return listVspModels(context, elementContext).size() > 1; } - if (vspModels.size() != 2) { - return; + @Override + public void updateHint(String vspId, Version version) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(new Id(vspId), new Id(version.getId())); + String vspModelId = zusammenAdaptor.getElementInfoByName(context, elementContext, null, ElementType.VspModel.name()) + .orElseThrow(() -> new IllegalStateException(String.format(VSP_MODEL_NOT_EXIST, vspId, version.getId()))).getId().getValue(); + updateVspModelId(vspId, version, vspModelId); } - String user = getUser(); - Row row = accessor.get(user, vspId, version.getId()).one(); - if (row == null) { - throw new IllegalStateException( - "Vsp model id must exists if its conflict is being resolved"); + @Override + public void deleteHint(String vspId, Version version) { + accessor.delete(getUser(), vspId, version.getId()); } - String resolutionValue = row.getString("model_resolution"); - if (resolutionValue == null) { - return; // model conflict is not resolved yet + + @Override + public void updateConflictResolution(String vspId, Version version, Resolution resolution) { + accessor.updateModelResolution(resolution, getUser(), vspId, version.getId()); + } + + @Override + public void applyConflictResolution(String vspId, Version version) { + //called only when no conflicts + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(new Id(vspId), new Id(version.getId())); + List vspModels = listVspModels(context, elementContext); + if (vspModels.size() == 1) { + updateVspModelId(vspId, version, vspModels.iterator().next().getId().getValue()); + return; + } + if (vspModels.size() != 2) { + return; + } + String user = getUser(); + Row row = accessor.get(user, vspId, version.getId()).one(); + if (row == null) { + throw new IllegalStateException("Vsp model id must exists if its conflict is being resolved"); + } + String resolutionValue = row.getString("model_resolution"); + if (resolutionValue == null) { + return; // model conflict is not resolved yet + } + Resolution resolution = Resolution.valueOf(resolutionValue); + String localModelId = row.getString("model_id"); + String chosenModelId = keepOnlyChosenVspModel(context, elementContext, vspModels, resolution, localModelId); + accessor.update(chosenModelId, null, user, vspId, version.getId()); + } + + private String keepOnlyChosenVspModel(SessionContext context, ElementContext elementContext, List vspModels, Resolution resolution, + String localModelId) { + String newLocalModelId = null; + for (ElementInfo vspModel : vspModels) { + if (isRedundantModel(vspModel.getId().getValue(), localModelId, resolution)) { + zusammenAdaptor.saveElement(context, elementContext, buildElement(vspModel.getId(), Action.DELETE), "Delete Redundant Vsp Model"); + } else { + newLocalModelId = vspModel.getId().getValue(); + } + } + return newLocalModelId; + } + + private boolean isRedundantModel(String modelId, String localModelId, Resolution resolution) { + return resolution == Resolution.THEIRS && modelId.equals(localModelId) || resolution == Resolution.YOURS && !modelId.equals(localModelId); + } + + private List listVspModels(SessionContext context, ElementContext elementContext) { + return zusammenAdaptor.listElements(context, elementContext, null).stream() + .filter(elementInfo -> ElementType.VspModel.name().equals(elementInfo.getInfo().getName())).collect(Collectors.toList()); } - Resolution resolution = Resolution.valueOf(resolutionValue); - String localModelId = row.getString("model_id"); - - String chosenModelId = - keepOnlyChosenVspModel(context, elementContext, vspModels, resolution, localModelId); - - accessor.update(chosenModelId, null, user, vspId, version.getId()); - } - - private String keepOnlyChosenVspModel(SessionContext context, ElementContext elementContext, - List vspModels, Resolution resolution, - String localModelId) { - String newLocalModelId = null; - for (ElementInfo vspModel : vspModels) { - if (isRedundantModel(vspModel.getId().getValue(), localModelId, resolution)) { - zusammenAdaptor - .saveElement(context, elementContext, buildElement(vspModel.getId(), Action.DELETE), - "Delete Redundant Vsp Model"); - } else { - newLocalModelId = vspModel.getId().getValue(); - } + private void updateVspModelId(String vspId, Version version, String vspModelId) { + accessor.update(vspModelId, null, getUser(), vspId, version.getId()); + } + + private String getUser() { + return SessionContextProviderFactory.getInstance().createInterface().get().getUser().getUserId(); + } + + @Accessor + interface VspMergeHintAccessor { + + @Query("SELECT model_id, model_resolution FROM vsp_merge_hint " + "WHERE space=? AND item_id=? AND version_id=?") + ResultSet get(String space, String itemId, String versionId); + + @Query("UPDATE vsp_merge_hint SET model_id=?, model_resolution=? " + "WHERE space=? AND item_id=? AND version_id=?") + void update(String vspModelId, Resolution modelResolution, String space, String itemId, String versionId); + + @Query("UPDATE vsp_merge_hint SET model_resolution=? WHERE space=? AND item_id=? AND version_id=?") + void updateModelResolution(Resolution modelResolution, String space, String itemId, String versionId); + + @Query("DELETE from vsp_merge_hint WHERE space=? AND item_id=? AND version_id=?") + void delete(String space, String itemId, String versionId); } - return newLocalModelId; - } - - private boolean isRedundantModel(String modelId, String localModelId, Resolution resolution) { - return resolution == Resolution.THEIRS && modelId.equals(localModelId) || - resolution == Resolution.YOURS && !modelId.equals(localModelId); - } - - private List listVspModels(SessionContext context, ElementContext elementContext) { - return zusammenAdaptor.listElements(context, elementContext, null).stream() - .filter(elementInfo -> ElementType.VspModel.name().equals(elementInfo.getInfo().getName())) - .collect(Collectors.toList()); - } - - private void updateVspModelId(String vspId, Version version, String vspModelId) { - accessor.update(vspModelId, null, getUser(), vspId, version.getId()); - } - - private String getUser() { - return SessionContextProviderFactory.getInstance().createInterface() - .get().getUser().getUserId(); - } - - @Accessor - interface VspMergeHintAccessor { - - @Query("SELECT model_id, model_resolution FROM vsp_merge_hint " + - "WHERE space=? AND item_id=? AND version_id=?") - ResultSet get(String space, String itemId, String versionId); - - @Query("UPDATE vsp_merge_hint SET model_id=?, model_resolution=? " + - "WHERE space=? AND item_id=? AND version_id=?") - void update(String vspModelId, Resolution modelResolution, String space, - String itemId, String versionId); - - @Query( - "UPDATE vsp_merge_hint SET model_resolution=? WHERE space=? AND item_id=? AND version_id=?") - void updateModelResolution(Resolution modelResolution, String space, String itemId, - String versionId); - - @Query("DELETE from vsp_merge_hint WHERE space=? AND item_id=? AND version_id=?") - void delete(String space, String itemId, String versionId); - } } 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/ComponentArtifactDaoZusammenImpl.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/ComponentArtifactDaoZusammenImpl.java index e80e7d5d66..dbfee03219 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/ComponentArtifactDaoZusammenImpl.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/ComponentArtifactDaoZusammenImpl.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,15 +17,24 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen; +import static org.openecomp.core.zusammen.api.ZusammenUtil.buildElement; +import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement; +import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext; + import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement; import com.amdocs.zusammen.datatypes.Id; import com.amdocs.zusammen.datatypes.SessionContext; import com.amdocs.zusammen.datatypes.item.Action; import com.amdocs.zusammen.datatypes.item.ElementContext; +import java.io.ByteArrayInputStream; +import java.nio.ByteBuffer; +import java.util.Collection; +import java.util.Collections; +import java.util.Optional; +import java.util.stream.Collectors; import org.openecomp.core.enrichment.types.MonitoringUploadType; import org.openecomp.core.utilities.file.FileUtils; import org.openecomp.core.zusammen.api.ZusammenAdaptor; @@ -34,202 +43,145 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentArtifactDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor.ElementToComponentMonitoringUploadConvertor; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentMonitoringUploadEntity; -import java.io.ByteArrayInputStream; -import java.nio.ByteBuffer; -import java.util.Collection; -import java.util.Collections; -import java.util.Optional; -import java.util.stream.Collectors; - -import static org.openecomp.core.zusammen.api.ZusammenUtil.*; - /** * @author Avrahamg. * @since March 21, 2017 */ public class ComponentArtifactDaoZusammenImpl implements ComponentArtifactDao { - private static final String ARTIFACT_NAME = "artifactName"; + private static final String ARTIFACT_NAME = "artifactName"; + private ZusammenAdaptor zusammenAdaptor; - private ZusammenAdaptor zusammenAdaptor; - - public ComponentArtifactDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { - this.zusammenAdaptor = zusammenAdaptor; - } + public ComponentArtifactDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { + this.zusammenAdaptor = zusammenAdaptor; + } - @Override - public void registerVersioning(String versionableEntityType) { - // registerVersioning is not implemented for ComponentArtifactDaoZusammenImpl - } + @Override + public void registerVersioning(String versionableEntityType) { + // registerVersioning is not implemented for ComponentArtifactDaoZusammenImpl + } - @Override - public Optional getByType( - ComponentMonitoringUploadEntity componentMonitoringUploadEntity) { - SessionContext context = createSessionContext(); - ElementContext elementContext = - new ElementContext(componentMonitoringUploadEntity.getVspId(), + @Override + public Optional getByType(ComponentMonitoringUploadEntity componentMonitoringUploadEntity) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(componentMonitoringUploadEntity.getVspId(), componentMonitoringUploadEntity.getVersion().getId()); - - Optional mibsElement = - zusammenAdaptor.getElementByName(context, elementContext, - new Id(componentMonitoringUploadEntity.getComponentId()), ElementType.Mibs.toString()); - if (mibsElement.isPresent()) { - Optional monitoringElement = zusammenAdaptor - .getElementByName(context, elementContext, mibsElement.get().getElementId(), - getMonitoringStructuralElement(componentMonitoringUploadEntity.getType()).toString()); - if (monitoringElement.isPresent()) { - ComponentMonitoringUploadEntity entity = - new ElementToComponentMonitoringUploadConvertor().convert(monitoringElement.get()); - entity.setVspId(componentMonitoringUploadEntity.getVspId()); - entity.setVersion(componentMonitoringUploadEntity.getVersion()); - entity.setComponentId(componentMonitoringUploadEntity.getComponentId()); - return Optional.of(entity); - } + Optional mibsElement = zusammenAdaptor + .getElementByName(context, elementContext, new Id(componentMonitoringUploadEntity.getComponentId()), ElementType.Mibs.toString()); + if (mibsElement.isPresent()) { + Optional monitoringElement = zusammenAdaptor.getElementByName(context, elementContext, mibsElement.get().getElementId(), + getMonitoringStructuralElement(componentMonitoringUploadEntity.getType()).toString()); + if (monitoringElement.isPresent()) { + ComponentMonitoringUploadEntity entity = new ElementToComponentMonitoringUploadConvertor().convert(monitoringElement.get()); + entity.setVspId(componentMonitoringUploadEntity.getVspId()); + entity.setVersion(componentMonitoringUploadEntity.getVersion()); + entity.setComponentId(componentMonitoringUploadEntity.getComponentId()); + return Optional.of(entity); + } + } + return Optional.empty(); } - return Optional.empty(); - } - - @Override - public void create(ComponentMonitoringUploadEntity entity) { - ZusammenElement mibElement = buildMibElement(entity); - - ZusammenElement mibsElement = buildStructuralElement(ElementType.Mibs, null); - - ZusammenElement componentElement = buildElement(new Id(entity.getComponentId()), Action.IGNORE); - - SessionContext context = createSessionContext(); - ElementContext elementContext = - new ElementContext(entity.getVspId(), entity.getVersion().getId()); - - Element savedElement = zusammenAdaptor.saveElement(context, elementContext, - VspZusammenUtil.aggregateElements(componentElement, mibsElement, mibElement), - "Create monitoring upload"); - entity.setId(savedElement.getSubElements().iterator().next() - .getSubElements().iterator().next().getElementId().getValue()); - } - - @Override - public void delete(ComponentMonitoringUploadEntity componentMonitoringUploadEntity) { + @Override + public void create(ComponentMonitoringUploadEntity entity) { + ZusammenElement mibElement = buildMibElement(entity); + ZusammenElement mibsElement = buildStructuralElement(ElementType.Mibs, null); + ZusammenElement componentElement = buildElement(new Id(entity.getComponentId()), Action.IGNORE); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(entity.getVspId(), entity.getVersion().getId()); + Element savedElement = zusammenAdaptor + .saveElement(context, elementContext, VspZusammenUtil.aggregateElements(componentElement, mibsElement, mibElement), + "Create monitoring upload"); + entity.setId(savedElement.getSubElements().iterator().next().getSubElements().iterator().next().getElementId().getValue()); + } - ZusammenElement mibElement = buildMibElementStructure(componentMonitoringUploadEntity); - mibElement.setElementId(new Id(componentMonitoringUploadEntity.getId())); - SessionContext context = createSessionContext(); - ElementContext elementContext = - new ElementContext(componentMonitoringUploadEntity.getVspId(), + @Override + public void delete(ComponentMonitoringUploadEntity componentMonitoringUploadEntity) { + ZusammenElement mibElement = buildMibElementStructure(componentMonitoringUploadEntity); + mibElement.setElementId(new Id(componentMonitoringUploadEntity.getId())); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(componentMonitoringUploadEntity.getVspId(), componentMonitoringUploadEntity.getVersion().getId()); + zusammenAdaptor + .saveElement(context, elementContext, mibElement, String.format("Delete mib with id %s", componentMonitoringUploadEntity.getId())); + } + + @Override + public Collection list(ComponentMonitoringUploadEntity mibEntity) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(mibEntity.getVspId(), mibEntity.getVersion().getId()); + return zusammenAdaptor.listElementsByName(context, elementContext, new Id(mibEntity.getComponentId()), ElementType.Mibs.toString()).stream() + .map(new ElementToComponentMonitoringUploadConvertor()::convert).map(mib -> { + mib.setVspId(mibEntity.getVspId()); + mib.setVersion(mibEntity.getVersion()); + mib.setComponentId(mibEntity.getComponentId()); + return mib; + }).collect(Collectors.toList()); + } - zusammenAdaptor.saveElement(context, elementContext, mibElement, - String.format("Delete mib with id %s", componentMonitoringUploadEntity.getId())); - } - - - - @Override - public Collection list( - ComponentMonitoringUploadEntity mibEntity) { - SessionContext context = createSessionContext(); - ElementContext elementContext = - new ElementContext(mibEntity.getVspId(), mibEntity.getVersion().getId()); - return zusammenAdaptor - .listElementsByName(context, elementContext, new Id(mibEntity.getComponentId()), - ElementType.Mibs.toString()) - .stream() - .map(new ElementToComponentMonitoringUploadConvertor()::convert) - .map(mib -> { - mib.setVspId(mibEntity.getVspId()); - mib.setVersion(mibEntity.getVersion()); - mib.setComponentId(mibEntity.getComponentId()); - return mib; - }) - .collect(Collectors.toList()); - } - - @Override - public void deleteAll(ComponentMonitoringUploadEntity componentMonitoringUploadEntity) { - SessionContext context = createSessionContext(); - ElementContext elementContext = - new ElementContext(componentMonitoringUploadEntity.getVspId(), + @Override + public void deleteAll(ComponentMonitoringUploadEntity componentMonitoringUploadEntity) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(componentMonitoringUploadEntity.getVspId(), componentMonitoringUploadEntity.getVersion().getId()); + Optional optionalElement = zusammenAdaptor + .getElementByName(context, elementContext, new Id(componentMonitoringUploadEntity.getComponentId()), ElementType.Mibs.name()); + if (optionalElement.isPresent()) { + Element mibsElement = optionalElement.get(); + Collection mibs = mibsElement.getSubElements(); + mibs.forEach(mib -> { + ZusammenElement mibZusammenElement = buildElement(mib.getElementId(), Action.DELETE); + zusammenAdaptor.saveElement(context, elementContext, mibZusammenElement, "Delete mib with id " + mib.getElementId()); + }); + } + } - Optional optionalElement = zusammenAdaptor.getElementByName(context, - elementContext, new Id(componentMonitoringUploadEntity.getComponentId()), ElementType.Mibs - .name()); + @Override + public Collection listArtifacts(ComponentMonitoringUploadEntity monitoringUploadEntity) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(monitoringUploadEntity.getVspId(), monitoringUploadEntity.getVersion().getId()); + final Optional elementByName = zusammenAdaptor + .getElementByName(context, elementContext, new Id(monitoringUploadEntity.getComponentId()), ElementType.Mibs.name()); + if (!elementByName.isPresent()) { + return Collections.emptyList(); + } else { + final Id elementId = elementByName.get().getElementId(); + return zusammenAdaptor.listElementData(context, elementContext, elementId).stream() + .map(element -> buildMibEntity(element, monitoringUploadEntity)).collect(Collectors.toList()); + } + } - if (optionalElement.isPresent()) { - Element mibsElement = optionalElement.get(); - Collection mibs = mibsElement.getSubElements(); + private ComponentMonitoringUploadEntity buildMibEntity(Element element, ComponentMonitoringUploadEntity monitoringUploadEntity) { + final String componentId = monitoringUploadEntity.getComponentId(); + ComponentMonitoringUploadEntity createdMib = new ComponentMonitoringUploadEntity(monitoringUploadEntity.getVspId(), + monitoringUploadEntity.getVersion(), componentId, null); + createdMib.setArtifactName((String) element.getInfo().getProperties().get(ARTIFACT_NAME)); + createdMib.setArtifact(ByteBuffer.wrap(FileUtils.toByteArray(element.getData()))); + createdMib.setType(MonitoringUploadType.valueOf(element.getInfo().getName())); + return createdMib; + } - mibs.forEach(mib -> { - ZusammenElement mibZusammenElement = buildElement(mib.getElementId(), Action.DELETE); - zusammenAdaptor.saveElement(context, elementContext, mibZusammenElement, - "Delete mib with id " + mib.getElementId()); - }); + private ZusammenElement buildMibElement(ComponentMonitoringUploadEntity monitoringUploadEntity) { + ZusammenElement monitoringElement = buildMibElementStructure(monitoringUploadEntity); + monitoringElement.getInfo().getProperties().put(ARTIFACT_NAME, monitoringUploadEntity.getArtifactName()); + monitoringElement.setData(new ByteArrayInputStream(monitoringUploadEntity.getArtifact().array())); + return monitoringElement; } - } - - @Override - public Collection listArtifacts( - ComponentMonitoringUploadEntity monitoringUploadEntity) { - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(monitoringUploadEntity.getVspId(), - monitoringUploadEntity.getVersion().getId()); - - final Optional elementByName = - zusammenAdaptor.getElementByName(context, elementContext, - new Id(monitoringUploadEntity.getComponentId()), ElementType.Mibs.name()); - - if (!elementByName.isPresent()) { - return Collections.emptyList(); - } else { - final Id elementId = elementByName.get().getElementId(); - return zusammenAdaptor.listElementData(context, elementContext, elementId).stream() - .map(element -> buildMibEntity(element, monitoringUploadEntity)) - .collect(Collectors.toList()); + + private ZusammenElement buildMibElementStructure(ComponentMonitoringUploadEntity componentMonitoringUploadEntity) { + return buildStructuralElement(getMonitoringStructuralElement(componentMonitoringUploadEntity.getType()), Action.UPDATE); } - } - - private ComponentMonitoringUploadEntity buildMibEntity(Element element, - ComponentMonitoringUploadEntity monitoringUploadEntity) { - final String componentId = monitoringUploadEntity.getComponentId(); - ComponentMonitoringUploadEntity - createdMib = new ComponentMonitoringUploadEntity(monitoringUploadEntity.getVspId(), - monitoringUploadEntity.getVersion(), - componentId, - null); - createdMib.setArtifactName((String) element.getInfo().getProperties().get(ARTIFACT_NAME)); - createdMib.setArtifact(ByteBuffer.wrap(FileUtils.toByteArray(element.getData()))); - createdMib.setType(MonitoringUploadType.valueOf(element.getInfo().getName())); - return createdMib; - } - - private ZusammenElement buildMibElement( - ComponentMonitoringUploadEntity monitoringUploadEntity) { - - ZusammenElement monitoringElement = buildMibElementStructure(monitoringUploadEntity); - monitoringElement.getInfo().getProperties() - .put(ARTIFACT_NAME, monitoringUploadEntity.getArtifactName()); - monitoringElement - .setData(new ByteArrayInputStream(monitoringUploadEntity.getArtifact().array())); - return monitoringElement; - } - - private ZusammenElement buildMibElementStructure( - ComponentMonitoringUploadEntity componentMonitoringUploadEntity) { - return buildStructuralElement(getMonitoringStructuralElement(componentMonitoringUploadEntity - .getType()), Action.UPDATE); - } - - private ElementType getMonitoringStructuralElement(MonitoringUploadType type){ - switch (type) { - case SNMP_POLL: - return ElementType.SNMP_POLL; - case SNMP_TRAP: - return ElementType.SNMP_TRAP; - case VES_EVENTS: - return ElementType.VES_EVENTS; - default: - throw new IllegalArgumentException(); + + private ElementType getMonitoringStructuralElement(MonitoringUploadType type) { + switch (type) { + case SNMP_POLL: + return ElementType.SNMP_POLL; + case SNMP_TRAP: + return ElementType.SNMP_TRAP; + case VES_EVENTS: + return ElementType.VES_EVENTS; + default: + throw new IllegalArgumentException(); + } } - } } 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/ComponentDaoZusammenImpl.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/ComponentDaoZusammenImpl.java index d38db0b0da..8c2fb92f17 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/ComponentDaoZusammenImpl.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/ComponentDaoZusammenImpl.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,9 +17,12 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen; +import static org.openecomp.core.zusammen.api.ZusammenUtil.buildElement; +import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement; +import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext; + import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo; import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement; @@ -28,6 +31,12 @@ import com.amdocs.zusammen.datatypes.SessionContext; import com.amdocs.zusammen.datatypes.item.Action; import com.amdocs.zusammen.datatypes.item.ElementContext; import com.amdocs.zusammen.datatypes.item.Info; +import java.io.ByteArrayInputStream; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Optional; +import java.util.stream.Collectors; import org.openecomp.core.zusammen.api.ZusammenAdaptor; import org.openecomp.sdc.datatypes.model.ElementType; import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao; @@ -37,233 +46,170 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; import org.openecomp.sdc.versioning.dao.types.Version; import org.openecomp.types.ElementPropertyName; -import java.io.ByteArrayInputStream; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Optional; -import java.util.stream.Collectors; - -import static org.openecomp.core.zusammen.api.ZusammenUtil.*; - public class ComponentDaoZusammenImpl implements ComponentDao { - private ZusammenAdaptor zusammenAdaptor; - - public ComponentDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { - this.zusammenAdaptor = zusammenAdaptor; - } - - @Override - public void registerVersioning(String versionableEntityType) { - // registerVersioning is not implemented for ComponentDaoZusammenImpl - } - - @Override - public Collection list(ComponentEntity component) { - SessionContext context = createSessionContext(); - - return listComponents(zusammenAdaptor, context, component.getVspId(), component.getVersion()); - } - - static Collection listComponents(ZusammenAdaptor zusammenAdaptor, - SessionContext context, - String vspId, Version version) { - ElementContext elementContext = new ElementContext(vspId, version.getId()); + private ZusammenAdaptor zusammenAdaptor; - Optional vspModel = zusammenAdaptor - .getElementInfoByName(context, elementContext, null, ElementType.VspModel.name()); - if (!vspModel.isPresent()) { - return new ArrayList<>(); + public ComponentDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { + this.zusammenAdaptor = zusammenAdaptor; } - ElementToComponentConvertor convertor = new ElementToComponentConvertor(); - return zusammenAdaptor.listElementsByName(context, elementContext, vspModel.get().getId(), - ElementType.Components.name()).stream() - .map(elementInfo -> { - ComponentEntity entity = convertor.convert(elementInfo); - entity.setVspId(vspId); - entity.setVersion(version); - return entity; - }) - .collect(Collectors.toList()); - } - - - @Override - public void create(ComponentEntity component) { - ZusammenElement componentElement = componentToZusammen(component, Action.CREATE); - - ZusammenElement componentsElement = - buildStructuralElement(ElementType.Components, Action.IGNORE); - componentsElement.getSubElements().add(componentElement); - - ZusammenElement vspModel = buildStructuralElement(ElementType.VspModel, Action.IGNORE); - vspModel.addSubElement(componentsElement); - - SessionContext context = createSessionContext(); - Element savedVspModel = zusammenAdaptor.saveElement(context, - new ElementContext(component.getVspId(), component.getVersion().getId()), - vspModel, "Create component"); - component.setId(savedVspModel.getSubElements().iterator().next() - .getSubElements().iterator().next().getElementId().getValue()); - } - - @Override - public void update(ComponentEntity component) { - ZusammenElement componentElement = componentToZusammen(component, Action.UPDATE); - - SessionContext context = createSessionContext(); - zusammenAdaptor.saveElement(context, - new ElementContext(component.getVspId(), component.getVersion().getId()), - componentElement, String.format("Update component with id %s", component.getId())); - } - - @Override - public ComponentEntity get(ComponentEntity component) { - SessionContext context = createSessionContext(); - - Optional element = - zusammenAdaptor.getElement(context, - new ElementContext(component.getVspId(), component.getVersion().getId()), - component.getId()); - - if (element.isPresent()) { - ComponentEntity entity = new ElementToComponentConvertor().convert(element.get()); - entity.setVspId(component.getVspId()); - entity.setVersion(component.getVersion()); - return entity; + static Collection listComponents(ZusammenAdaptor zusammenAdaptor, SessionContext context, String vspId, Version version) { + ElementContext elementContext = new ElementContext(vspId, version.getId()); + Optional vspModel = zusammenAdaptor.getElementInfoByName(context, elementContext, null, ElementType.VspModel.name()); + if (!vspModel.isPresent()) { + return new ArrayList<>(); + } + ElementToComponentConvertor convertor = new ElementToComponentConvertor(); + return zusammenAdaptor.listElementsByName(context, elementContext, vspModel.get().getId(), ElementType.Components.name()).stream() + .map(elementInfo -> { + ComponentEntity entity = convertor.convert(elementInfo); + entity.setVspId(vspId); + entity.setVersion(version); + return entity; + }).collect(Collectors.toList()); } - return null; - } - - @Override - public void delete(ComponentEntity component) { - ZusammenElement componentElement = buildElement(new Id(component.getId()), Action.DELETE); - - SessionContext context = createSessionContext(); - zusammenAdaptor.saveElement(context, - new ElementContext(component.getVspId(), component.getVersion().getId()), - componentElement, String.format("Delete component with id %s", component.getId())); - } - - @Override - public ComponentEntity getQuestionnaireData(String vspId, Version version, String componentId) { - SessionContext context = createSessionContext(); - - return getQuestionnaire(context, new ElementContext(vspId, version.getId()), - new ComponentEntity(vspId, version, componentId)); - } - - private ComponentEntity getQuestionnaire(SessionContext context, ElementContext elementContext, - ComponentEntity component) { - Optional questionnaireElement = zusammenAdaptor - .getElementByName(context, elementContext, new Id(component.getId()), - ElementType.ComponentQuestionnaire.name()); - return questionnaireElement.map(new ElementToComponentQuestionnnaireConvertor()::convert) - .map(entity -> { - entity.setVspId(component.getVspId()); - entity.setVersion(component.getVersion()); - return entity; - }) - .orElse(null); - } - - @Override - public void updateQuestionnaireData(String vspId, Version version, String componentId, - String questionnaireData) { - ZusammenElement questionnaireElement = - componentQuestionnaireToZusammen(questionnaireData, Action.UPDATE); - - ZusammenElement componentElement = buildElement(new Id(componentId), Action.IGNORE); - componentElement.setSubElements(Collections.singletonList(questionnaireElement)); - - SessionContext context = createSessionContext(); - zusammenAdaptor.saveElement(context, new ElementContext(vspId, version.getId()), - componentElement, "Update component questionnaire"); - } - - @Override - public Collection listQuestionnaires(String vspId, Version version) { - return listCompositionAndQuestionnaire(vspId, version); - } - @Override - public Collection listCompositionAndQuestionnaire(String vspId, - Version version) { - SessionContext context = createSessionContext(); + @Override + public void registerVersioning(String versionableEntityType) { + // registerVersioning is not implemented for ComponentDaoZusammenImpl + } - Collection components = - listComponents(zusammenAdaptor, context, vspId, version); + @Override + public Collection list(ComponentEntity component) { + SessionContext context = createSessionContext(); + return listComponents(zusammenAdaptor, context, component.getVspId(), component.getVersion()); + } - ElementContext elementContext = new ElementContext(vspId, version.getId()); - components.forEach(component -> component.setQuestionnaireData( - getQuestionnaire(context, elementContext, component).getQuestionnaireData())); - return components; - } + @Override + public void create(ComponentEntity component) { + ZusammenElement componentElement = componentToZusammen(component, Action.CREATE); + ZusammenElement componentsElement = buildStructuralElement(ElementType.Components, Action.IGNORE); + componentsElement.getSubElements().add(componentElement); + ZusammenElement vspModel = buildStructuralElement(ElementType.VspModel, Action.IGNORE); + vspModel.addSubElement(componentsElement); + SessionContext context = createSessionContext(); + Element savedVspModel = zusammenAdaptor + .saveElement(context, new ElementContext(component.getVspId(), component.getVersion().getId()), vspModel, "Create component"); + component.setId(savedVspModel.getSubElements().iterator().next().getSubElements().iterator().next().getElementId().getValue()); + } - @Override - public void deleteAll(String vspId, Version version) { - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(vspId, version.getId()); + @Override + public void update(ComponentEntity component) { + ZusammenElement componentElement = componentToZusammen(component, Action.UPDATE); + SessionContext context = createSessionContext(); + zusammenAdaptor.saveElement(context, new ElementContext(component.getVspId(), component.getVersion().getId()), componentElement, + String.format("Update component with id %s", component.getId())); + } - Collection vspModelSubs = zusammenAdaptor - .listElementsByName(context, elementContext, null, ElementType.VspModel.name()); + @Override + public ComponentEntity get(ComponentEntity component) { + SessionContext context = createSessionContext(); + Optional element = zusammenAdaptor + .getElement(context, new ElementContext(component.getVspId(), component.getVersion().getId()), component.getId()); + if (element.isPresent()) { + ComponentEntity entity = new ElementToComponentConvertor().convert(element.get()); + entity.setVspId(component.getVspId()); + entity.setVersion(component.getVersion()); + return entity; + } + return null; + } - Optional componentsElement = vspModelSubs.stream() - .filter(elementInfo -> elementInfo.getInfo() != null - && ElementType.Components.name().equals(elementInfo.getInfo().getName())) - .findFirst(); - if (!componentsElement.isPresent()) { - return; + @Override + public void delete(ComponentEntity component) { + ZusammenElement componentElement = buildElement(new Id(component.getId()), Action.DELETE); + SessionContext context = createSessionContext(); + zusammenAdaptor.saveElement(context, new ElementContext(component.getVspId(), component.getVersion().getId()), componentElement, + String.format("Delete component with id %s", component.getId())); } - ZusammenElement components = buildElement(componentsElement.get().getId(), Action.IGNORE); - components.setSubElements(componentsElement.get().getSubElements().stream() - .map(component -> buildElement(component.getId(), Action.DELETE)) - .collect(Collectors.toList())); + @Override + public ComponentEntity getQuestionnaireData(String vspId, Version version, String componentId) { + SessionContext context = createSessionContext(); + return getQuestionnaire(context, new ElementContext(vspId, version.getId()), new ComponentEntity(vspId, version, componentId)); + } - zusammenAdaptor.saveElement(context, elementContext, components, "Delete all components"); - } + private ComponentEntity getQuestionnaire(SessionContext context, ElementContext elementContext, ComponentEntity component) { + Optional questionnaireElement = zusammenAdaptor + .getElementByName(context, elementContext, new Id(component.getId()), ElementType.ComponentQuestionnaire.name()); + return questionnaireElement.map(new ElementToComponentQuestionnnaireConvertor()::convert).map(entity -> { + entity.setVspId(component.getVspId()); + entity.setVersion(component.getVersion()); + return entity; + }).orElse(null); + } - private ZusammenElement componentToZusammen(ComponentEntity component, Action action) { - ZusammenElement componentElement = buildComponentElement(component, action); + @Override + public void updateQuestionnaireData(String vspId, Version version, String componentId, String questionnaireData) { + ZusammenElement questionnaireElement = componentQuestionnaireToZusammen(questionnaireData, Action.UPDATE); + ZusammenElement componentElement = buildElement(new Id(componentId), Action.IGNORE); + componentElement.setSubElements(Collections.singletonList(questionnaireElement)); + SessionContext context = createSessionContext(); + zusammenAdaptor.saveElement(context, new ElementContext(vspId, version.getId()), componentElement, "Update component questionnaire"); + } - if (action == Action.CREATE) { - ZusammenElement mibs = buildStructuralElement(ElementType.Mibs, Action.CREATE); - mibs.addSubElement(buildStructuralElement(ElementType.SNMP_TRAP, Action.CREATE)); - mibs.addSubElement(buildStructuralElement(ElementType.VES_EVENTS, Action.CREATE)); - mibs.addSubElement(buildStructuralElement(ElementType.SNMP_POLL, Action.CREATE)); + @Override + public Collection listQuestionnaires(String vspId, Version version) { + return listCompositionAndQuestionnaire(vspId, version); + } - componentElement.addSubElement(mibs); - componentElement.addSubElement( - componentQuestionnaireToZusammen(component.getQuestionnaireData(), Action.CREATE)); - componentElement.addSubElement(buildStructuralElement(ElementType.Nics, Action.CREATE)); - componentElement.addSubElement(buildStructuralElement(ElementType.Processes, Action.CREATE)); - componentElement.addSubElement(buildStructuralElement(ElementType.Computes, Action.CREATE)); - componentElement.addSubElement(buildStructuralElement(ElementType.Images, Action.CREATE)); + @Override + public Collection listCompositionAndQuestionnaire(String vspId, Version version) { + SessionContext context = createSessionContext(); + Collection components = listComponents(zusammenAdaptor, context, vspId, version); + ElementContext elementContext = new ElementContext(vspId, version.getId()); + components.forEach(component -> component.setQuestionnaireData(getQuestionnaire(context, elementContext, component).getQuestionnaireData())); + return components; } - return componentElement; - } - private ZusammenElement componentQuestionnaireToZusammen(String questionnaireData, - Action action) { - ZusammenElement questionnaireElement = - buildStructuralElement(ElementType.ComponentQuestionnaire, action); - questionnaireElement.setData(new ByteArrayInputStream(questionnaireData.getBytes())); - return questionnaireElement; - } + @Override + public void deleteAll(String vspId, Version version) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(vspId, version.getId()); + Collection vspModelSubs = zusammenAdaptor.listElementsByName(context, elementContext, null, ElementType.VspModel.name()); + Optional componentsElement = vspModelSubs.stream() + .filter(elementInfo -> elementInfo.getInfo() != null && ElementType.Components.name().equals(elementInfo.getInfo().getName())) + .findFirst(); + if (!componentsElement.isPresent()) { + return; + } + ZusammenElement components = buildElement(componentsElement.get().getId(), Action.IGNORE); + components.setSubElements(componentsElement.get().getSubElements().stream().map(component -> buildElement(component.getId(), Action.DELETE)) + .collect(Collectors.toList())); + zusammenAdaptor.saveElement(context, elementContext, components, "Delete all components"); + } - private ZusammenElement buildComponentElement(ComponentEntity component, Action action) { - ZusammenElement componentElement = - buildElement(component.getId() == null ? null : new Id(component.getId()), action); - Info info = new Info(); - info.addProperty(ElementPropertyName.elementType.name(), ElementType.Component); - info.addProperty(ElementPropertyName.compositionData.name(), component.getCompositionData()); - componentElement.setInfo(info); - componentElement.setData(new ByteArrayInputStream(component.getCompositionData().getBytes())); - return componentElement; - } + private ZusammenElement componentToZusammen(ComponentEntity component, Action action) { + ZusammenElement componentElement = buildComponentElement(component, action); + if (action == Action.CREATE) { + ZusammenElement mibs = buildStructuralElement(ElementType.Mibs, Action.CREATE); + mibs.addSubElement(buildStructuralElement(ElementType.SNMP_TRAP, Action.CREATE)); + mibs.addSubElement(buildStructuralElement(ElementType.VES_EVENTS, Action.CREATE)); + mibs.addSubElement(buildStructuralElement(ElementType.SNMP_POLL, Action.CREATE)); + componentElement.addSubElement(mibs); + componentElement.addSubElement(componentQuestionnaireToZusammen(component.getQuestionnaireData(), Action.CREATE)); + componentElement.addSubElement(buildStructuralElement(ElementType.Nics, Action.CREATE)); + componentElement.addSubElement(buildStructuralElement(ElementType.Processes, Action.CREATE)); + componentElement.addSubElement(buildStructuralElement(ElementType.Computes, Action.CREATE)); + componentElement.addSubElement(buildStructuralElement(ElementType.Images, Action.CREATE)); + } + return componentElement; + } + private ZusammenElement componentQuestionnaireToZusammen(String questionnaireData, Action action) { + ZusammenElement questionnaireElement = buildStructuralElement(ElementType.ComponentQuestionnaire, action); + questionnaireElement.setData(new ByteArrayInputStream(questionnaireData.getBytes())); + return questionnaireElement; + } + private ZusammenElement buildComponentElement(ComponentEntity component, Action action) { + ZusammenElement componentElement = buildElement(component.getId() == null ? null : new Id(component.getId()), action); + Info info = new Info(); + info.addProperty(ElementPropertyName.elementType.name(), ElementType.Component); + info.addProperty(ElementPropertyName.compositionData.name(), component.getCompositionData()); + componentElement.setInfo(info); + componentElement.setData(new ByteArrayInputStream(component.getCompositionData().getBytes())); + return componentElement; + } } 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/ComponentDependencyModelDaoZusammenImpl.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/ComponentDependencyModelDaoZusammenImpl.java index bb80a95aab..5662da2769 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/ComponentDependencyModelDaoZusammenImpl.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/ComponentDependencyModelDaoZusammenImpl.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen; import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; @@ -34,7 +33,6 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDependencyModelDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor.ElementToComponentDependencyModelConvertor; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentDependencyModelEntity; import org.openecomp.types.ElementPropertyName; - import java.util.ArrayList; import java.util.Collection; import java.util.Optional; @@ -47,148 +45,103 @@ import static org.openecomp.core.zusammen.api.ZusammenUtil.*; */ public class ComponentDependencyModelDaoZusammenImpl implements ComponentDependencyModelDao { - private ZusammenAdaptor zusammenAdaptor; - - public ComponentDependencyModelDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { - this.zusammenAdaptor = zusammenAdaptor; - } - - @Override - public ComponentDependencyModelEntity get(ComponentDependencyModelEntity dependency) { + private ZusammenAdaptor zusammenAdaptor; - SessionContext context = createSessionContext(); - ElementContext elementContext = - new ElementContext(dependency.getVspId(), dependency.getVersion().getId()); - - Optional componentDependencyElement = - zusammenAdaptor.getElementInfo(context, elementContext, new Id(dependency.getId())); - - if (componentDependencyElement.isPresent()) { - ElementToComponentDependencyModelConvertor convertor = new - ElementToComponentDependencyModelConvertor(); - - ComponentDependencyModelEntity entity = convertor.convert(componentDependencyElement.get()); - entity.setVspId(dependency.getVspId()); - entity.setVersion(dependency.getVersion()); - return entity; + public ComponentDependencyModelDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { + this.zusammenAdaptor = zusammenAdaptor; } - return null; - } - - @Override - public void create(ComponentDependencyModelEntity dependency) { - ZusammenElement componentDependency = - buildComponentDependencyElement(dependency, Action.CREATE); - - ZusammenElement componentDependencies = - buildStructuralElement(ElementType.ComponentDependencies, Action.IGNORE); - componentDependencies.addSubElement(componentDependency); - - ZusammenElement vspModel = buildStructuralElement(ElementType.VspModel, Action.IGNORE); - vspModel.addSubElement(componentDependencies); - - SessionContext context = createSessionContext(); - ElementContext elementContext = - new ElementContext(dependency.getVspId(), dependency.getVersion().getId()); - - Element compDepsSavedElement = zusammenAdaptor - .saveElement(context, elementContext, vspModel, "Create component dependency model"); - - dependency.setId(compDepsSavedElement.getSubElements().iterator().next() - .getSubElements().iterator().next().getElementId().getValue()); - } - - @Override - public void update(ComponentDependencyModelEntity dependency) { - ZusammenElement componentDependencyElement = - buildComponentDependencyElement(dependency, Action.UPDATE); - - SessionContext context = createSessionContext(); - ElementContext elementContext = - new ElementContext(dependency.getVspId(), dependency.getVersion().getId()); - - zusammenAdaptor.saveElement(context, elementContext, componentDependencyElement, - String.format("Update component dependency model with id %s", dependency.getId())); - } - - @Override - public void delete(ComponentDependencyModelEntity dependency) { - ZusammenElement componentDependencyElement = - buildElement(new Id(dependency.getId()), Action.DELETE); - - SessionContext context = createSessionContext(); - ElementContext elementContext = - new ElementContext(dependency.getVspId(), dependency.getVersion().getId()); - - zusammenAdaptor.saveElement(context, elementContext, componentDependencyElement, - String.format("Delete component dependency model with id %s", dependency.getId())); - } - - @Override - public void registerVersioning(String versionableEntityType) { - //not implemented? - } - - @Override - public Collection list( - ComponentDependencyModelEntity dependency) { - SessionContext context = createSessionContext(); - ElementContext elementContext = - new ElementContext(dependency.getVspId(), dependency.getVersion().getId()); - - Optional vspModel = zusammenAdaptor - .getElementInfoByName(context, elementContext, null, ElementType.VspModel.name()); - if (!vspModel.isPresent()) { - return new ArrayList<>(); + @Override + public ComponentDependencyModelEntity get(ComponentDependencyModelEntity dependency) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(dependency.getVspId(), dependency.getVersion().getId()); + Optional componentDependencyElement = zusammenAdaptor.getElementInfo(context, elementContext, new Id(dependency.getId())); + if (componentDependencyElement.isPresent()) { + ElementToComponentDependencyModelConvertor convertor = new ElementToComponentDependencyModelConvertor(); + ComponentDependencyModelEntity entity = convertor.convert(componentDependencyElement.get()); + entity.setVspId(dependency.getVspId()); + entity.setVersion(dependency.getVersion()); + return entity; + } + return null; } - ElementToComponentDependencyModelConvertor convertor = - new ElementToComponentDependencyModelConvertor(); - return zusammenAdaptor.listElementsByName(context, elementContext, vspModel.get().getId(), - ElementType.ComponentDependencies.name()).stream() - .map(elementInfo -> { - ComponentDependencyModelEntity entity = convertor.convert(elementInfo); - entity.setVspId(dependency.getVspId()); - entity.setVersion(dependency.getVersion()); - entity.setId(elementInfo.getId().getValue()); - return entity; - }) - .collect(Collectors.toList()); - } + @Override + public void create(ComponentDependencyModelEntity dependency) { + ZusammenElement componentDependency = buildComponentDependencyElement(dependency, Action.CREATE); + ZusammenElement componentDependencies = buildStructuralElement(ElementType.ComponentDependencies, Action.IGNORE); + componentDependencies.addSubElement(componentDependency); + ZusammenElement vspModel = buildStructuralElement(ElementType.VspModel, Action.IGNORE); + vspModel.addSubElement(componentDependencies); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(dependency.getVspId(), dependency.getVersion().getId()); + Element compDepsSavedElement = zusammenAdaptor.saveElement(context, elementContext, vspModel, "Create component dependency model"); + dependency.setId(compDepsSavedElement.getSubElements().iterator().next().getSubElements().iterator().next().getElementId().getValue()); + } - private ZusammenElement buildComponentDependencyElement(ComponentDependencyModelEntity compDep, - Action action) { - ZusammenElement componentDependencyElement = - buildElement(compDep.getId() == null ? null : new Id(compDep.getId()), action); + @Override + public void update(ComponentDependencyModelEntity dependency) { + ZusammenElement componentDependencyElement = buildComponentDependencyElement(dependency, Action.UPDATE); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(dependency.getVspId(), dependency.getVersion().getId()); + zusammenAdaptor.saveElement(context, elementContext, componentDependencyElement, + String.format("Update component dependency model with id %s", dependency.getId())); + } - Info info = new Info(); - info.addProperty(ElementPropertyName.elementType.name(), ElementType.ComponentDependency); - info.addProperty(ComponentDependencyModelPropertyName.RELATION.getVal(), compDep.getRelation()); - info.addProperty(ComponentDependencyModelPropertyName.SOURCE_COMPONENT_ID.getVal(), - compDep.getSourceComponentId()); - info.addProperty(ComponentDependencyModelPropertyName.TARGET_COMPONENT_ID.getVal(), - compDep.getTargetComponentId()); + @Override + public void delete(ComponentDependencyModelEntity dependency) { + ZusammenElement componentDependencyElement = buildElement(new Id(dependency.getId()), Action.DELETE); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(dependency.getVspId(), dependency.getVersion().getId()); + zusammenAdaptor.saveElement(context, elementContext, componentDependencyElement, + String.format("Delete component dependency model with id %s", dependency.getId())); + } - componentDependencyElement.setInfo(info); + @Override + public void registerVersioning(String versionableEntityType) { + //not implemented? + } - return componentDependencyElement; - } + @Override + public Collection list(ComponentDependencyModelEntity dependency) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(dependency.getVspId(), dependency.getVersion().getId()); + Optional vspModel = zusammenAdaptor.getElementInfoByName(context, elementContext, null, ElementType.VspModel.name()); + if (!vspModel.isPresent()) { + return new ArrayList<>(); + } + ElementToComponentDependencyModelConvertor convertor = new ElementToComponentDependencyModelConvertor(); + return zusammenAdaptor.listElementsByName(context, elementContext, vspModel.get().getId(), ElementType.ComponentDependencies.name()).stream() + .map(elementInfo -> { + ComponentDependencyModelEntity entity = convertor.convert(elementInfo); + entity.setVspId(dependency.getVspId()); + entity.setVersion(dependency.getVersion()); + entity.setId(elementInfo.getId().getValue()); + return entity; + }).collect(Collectors.toList()); + } - private enum ComponentDependencyModelPropertyName { - ID("id"), - RELATION("relation"), - SOURCE_COMPONENT_ID("sourcecomponent_id"), - TARGET_COMPONENT_ID("targetcomponent_id"); + private ZusammenElement buildComponentDependencyElement(ComponentDependencyModelEntity compDep, Action action) { + ZusammenElement componentDependencyElement = buildElement(compDep.getId() == null ? null : new Id(compDep.getId()), action); + Info info = new Info(); + info.addProperty(ElementPropertyName.elementType.name(), ElementType.ComponentDependency); + info.addProperty(ComponentDependencyModelPropertyName.RELATION.getVal(), compDep.getRelation()); + info.addProperty(ComponentDependencyModelPropertyName.SOURCE_COMPONENT_ID.getVal(), compDep.getSourceComponentId()); + info.addProperty(ComponentDependencyModelPropertyName.TARGET_COMPONENT_ID.getVal(), compDep.getTargetComponentId()); + componentDependencyElement.setInfo(info); + return componentDependencyElement; + } - private String val; + private enum ComponentDependencyModelPropertyName { + ID("id"), RELATION("relation"), SOURCE_COMPONENT_ID("sourcecomponent_id"), TARGET_COMPONENT_ID("targetcomponent_id"); + private String val; - ComponentDependencyModelPropertyName(String val){ - this.val=val; - } + ComponentDependencyModelPropertyName(String val) { + this.val = val; + } - public String getVal() { - return val; + public 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/dao/impl/zusammen/ComponentDependencyModelPropertyName.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/ComponentDependencyModelPropertyName.java index 534c253811..7624886b9c 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/ComponentDependencyModelPropertyName.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/ComponentDependencyModelPropertyName.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,16 +17,9 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen; /** * Created by ayalaben on 5/16/2017 */ -public enum ComponentDependencyModelPropertyName { - id, - relation, - sourcecomponent_id, - targetcomponent_id, - -} +public enum ComponentDependencyModelPropertyName {id, relation, sourcecomponent_id, targetcomponent_id,} 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/ComputeDaoZusammenImpl.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/ComputeDaoZusammenImpl.java index d1b540b312..48111ad041 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/ComputeDaoZusammenImpl.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/ComputeDaoZusammenImpl.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,9 +17,11 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen; +import static org.openecomp.core.zusammen.api.ZusammenUtil.buildElement; +import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement; +import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext; import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement; @@ -28,6 +30,11 @@ import com.amdocs.zusammen.datatypes.SessionContext; import com.amdocs.zusammen.datatypes.item.Action; import com.amdocs.zusammen.datatypes.item.ElementContext; import com.amdocs.zusammen.datatypes.item.Info; +import java.io.ByteArrayInputStream; +import java.util.Collection; +import java.util.Collections; +import java.util.Optional; +import java.util.stream.Collectors; import org.openecomp.core.utilities.file.FileUtils; import org.openecomp.core.zusammen.api.ZusammenAdaptor; import org.openecomp.sdc.datatypes.model.ElementType; @@ -38,222 +45,156 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComputeEntity; import org.openecomp.sdc.versioning.dao.types.Version; import org.openecomp.types.ElementPropertyName; -import java.io.ByteArrayInputStream; -import java.util.Collection; -import java.util.Collections; -import java.util.Optional; -import java.util.stream.Collectors; - -import static org.openecomp.core.zusammen.api.ZusammenUtil.*; - public class ComputeDaoZusammenImpl implements ComputeDao { - private ZusammenAdaptor zusammenAdaptor; - - public ComputeDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { - this.zusammenAdaptor = zusammenAdaptor; - } - - @Override - public void registerVersioning(String versionableEntityType) { - // registerVersioning not implemented for ComputeDaoZusammenImpl - } - - @Override - public Collection list(ComputeEntity compute) { - SessionContext context = createSessionContext(); - ElementContext elementContext = - new ElementContext(compute.getVspId(), compute.getVersion().getId()); - - return listComputes(context, elementContext, compute); - } - - private Collection listComputes(SessionContext context, - ElementContext elementContext, - ComputeEntity compute) { - return zusammenAdaptor - .listElementsByName(context, elementContext, new Id(compute.getComponentId()), - ElementType.Computes.name()) - .stream() - .map(new ElementToComputeConvertor()::convert) - .map(computeEntity -> { - computeEntity.setComponentId(compute.getComponentId()); - computeEntity.setVspId(compute.getVspId()); - computeEntity.setVersion(compute.getVersion()); - return computeEntity; - }) - .collect(Collectors.toList()); - } - - @Override - public void create(ComputeEntity compute) { - ZusammenElement computeElement = computeToZusammen(compute, Action.CREATE); - - ZusammenElement computesElement = buildStructuralElement(ElementType.Computes, Action.IGNORE); - computesElement.setSubElements(Collections.singletonList(computeElement)); - - ZusammenElement componentElement = - buildElement(new Id(compute.getComponentId()), Action.IGNORE); - componentElement.setSubElements(Collections.singletonList(computesElement)); - - SessionContext context = createSessionContext(); - ElementContext elementContext = - new ElementContext(compute.getVspId(), compute.getVersion().getId()); + private ZusammenAdaptor zusammenAdaptor; - Element savedElement = - zusammenAdaptor.saveElement(context, elementContext, componentElement, "Create compute"); - compute.setId(savedElement.getSubElements().iterator().next() - .getSubElements().iterator().next().getElementId().getValue()); - } - - @Override - public void update(ComputeEntity compute) { - ZusammenElement computeElement = computeToZusammen(compute, Action.UPDATE); - - SessionContext context = createSessionContext(); - ElementContext elementContext = - new ElementContext(compute.getVspId(), compute.getVersion().getId()); - zusammenAdaptor.saveElement(context, elementContext, computeElement, - String.format("Update compute with id %s", compute.getId())); - } - - @Override - public ComputeEntity get(ComputeEntity compute) { - SessionContext context = createSessionContext(); - ElementContext elementContext = - new ElementContext(compute.getVspId(), compute.getVersion().getId()); - Optional element = - zusammenAdaptor.getElement(context, elementContext, compute.getId()); - - if (element.isPresent()) { - - ElementToComputeConvertor convertor = new ElementToComputeConvertor(); - ComputeEntity entity = convertor.convert(element.get()); - entity.setVspId(compute.getVspId()); - entity.setVersion(compute.getVersion()); - entity.setComponentId(compute.getComponentId()); - return entity; - } else { - return null; + public ComputeDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { + this.zusammenAdaptor = zusammenAdaptor; } - } - - @Override - public void delete(ComputeEntity compute) { - ZusammenElement computeElement = buildElement(new Id(compute.getId()), Action.DELETE); - SessionContext context = createSessionContext(); - ElementContext elementContext = - new ElementContext(compute.getVspId(), compute.getVersion().getId()); - zusammenAdaptor.saveElement(context, elementContext, computeElement, - String.format("Delete compute with id %s", compute.getId())); - } - - @Override - public ComputeEntity getQuestionnaireData(String vspId, Version version, String componentId, - String computeId) { - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(vspId, version.getId()); - - return getQuestionnaire(context, elementContext, - new ComputeEntity(vspId, version, componentId, computeId)); - } - - private ComputeEntity getQuestionnaire(SessionContext context, ElementContext elementContext, - ComputeEntity compute) { - Optional questionnaireElement = zusammenAdaptor - .getElementByName(context, elementContext, new Id(compute.getId()), - ElementType.ComputeQuestionnaire.name()); - return questionnaireElement.map( - element -> element.getData() == null - ? null - : new String(FileUtils.toByteArray(element.getData()))) - .map(questionnaireData -> { - compute.setQuestionnaireData(questionnaireData); - return compute; - }) - .orElse(null); - } + @Override + public void registerVersioning(String versionableEntityType) { + // registerVersioning not implemented for ComputeDaoZusammenImpl + } - @Override - public void updateQuestionnaireData(String vspId, Version version, String componentId, - String computeId, String questionnaireData) { - ZusammenElement questionnaireElement = - computeQuestionnaireToZusammen(questionnaireData, Action.UPDATE); + @Override + public Collection list(ComputeEntity compute) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(compute.getVspId(), compute.getVersion().getId()); + return listComputes(context, elementContext, compute); + } - ZusammenElement computeElement = buildElement(new Id(computeId), Action.IGNORE); - computeElement.setSubElements(Collections.singletonList(questionnaireElement)); + private Collection listComputes(SessionContext context, ElementContext elementContext, ComputeEntity compute) { + return zusammenAdaptor.listElementsByName(context, elementContext, new Id(compute.getComponentId()), ElementType.Computes.name()).stream() + .map(new ElementToComputeConvertor()::convert).map(computeEntity -> { + computeEntity.setComponentId(compute.getComponentId()); + computeEntity.setVspId(compute.getVspId()); + computeEntity.setVersion(compute.getVersion()); + return computeEntity; + }).collect(Collectors.toList()); + } - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(vspId, version.getId()); - zusammenAdaptor.saveElement(context, elementContext, computeElement, "Update compute " - + "questionnaire"); - } + @Override + public void create(ComputeEntity compute) { + ZusammenElement computeElement = computeToZusammen(compute, Action.CREATE); + ZusammenElement computesElement = buildStructuralElement(ElementType.Computes, Action.IGNORE); + computesElement.setSubElements(Collections.singletonList(computeElement)); + ZusammenElement componentElement = buildElement(new Id(compute.getComponentId()), Action.IGNORE); + componentElement.setSubElements(Collections.singletonList(computesElement)); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(compute.getVspId(), compute.getVersion().getId()); + Element savedElement = zusammenAdaptor.saveElement(context, elementContext, componentElement, "Create compute"); + compute.setId(savedElement.getSubElements().iterator().next().getSubElements().iterator().next().getElementId().getValue()); + } - @Override - public Collection listByVsp(String vspId, Version version) { - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(vspId, version.getId()); + @Override + public void update(ComputeEntity compute) { + ZusammenElement computeElement = computeToZusammen(compute, Action.UPDATE); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(compute.getVspId(), compute.getVersion().getId()); + zusammenAdaptor.saveElement(context, elementContext, computeElement, String.format("Update compute with id %s", compute.getId())); + } - Collection components = ComponentDaoZusammenImpl - .listComponents(zusammenAdaptor, context, vspId, version); + @Override + public ComputeEntity get(ComputeEntity compute) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(compute.getVspId(), compute.getVersion().getId()); + Optional element = zusammenAdaptor.getElement(context, elementContext, compute.getId()); + if (element.isPresent()) { + ElementToComputeConvertor convertor = new ElementToComputeConvertor(); + ComputeEntity entity = convertor.convert(element.get()); + entity.setVspId(compute.getVspId()); + entity.setVersion(compute.getVersion()); + entity.setComponentId(compute.getComponentId()); + return entity; + } else { + return null; + } + } - return components.stream() - .map(component -> - listComputes(context, elementContext, - new ComputeEntity(vspId, version, component.getId(), null)).stream() - .map(compute -> getQuestionnaire(context, elementContext, compute)) - .collect(Collectors.toList())) - .flatMap(Collection::stream) - .collect(Collectors.toList()); - } + @Override + public void delete(ComputeEntity compute) { + ZusammenElement computeElement = buildElement(new Id(compute.getId()), Action.DELETE); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(compute.getVspId(), compute.getVersion().getId()); + zusammenAdaptor.saveElement(context, elementContext, computeElement, String.format("Delete compute with id %s", compute.getId())); + } - @Override - public void deleteAll(String vspId, Version version) { + @Override + public ComputeEntity getQuestionnaireData(String vspId, Version version, String componentId, String computeId) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(vspId, version.getId()); + return getQuestionnaire(context, elementContext, new ComputeEntity(vspId, version, componentId, computeId)); + } - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(vspId, version.getId()); + private ComputeEntity getQuestionnaire(SessionContext context, ElementContext elementContext, ComputeEntity compute) { + Optional questionnaireElement = zusammenAdaptor + .getElementByName(context, elementContext, new Id(compute.getId()), ElementType.ComputeQuestionnaire.name()); + return questionnaireElement.map(element -> element.getData() == null ? null : new String(FileUtils.toByteArray(element.getData()))) + .map(questionnaireData -> { + compute.setQuestionnaireData(questionnaireData); + return compute; + }).orElse(null); + } - Optional optionalElement = zusammenAdaptor.getElementByName(context, - elementContext, null, ElementType.Computes.name()); + @Override + public void updateQuestionnaireData(String vspId, Version version, String componentId, String computeId, String questionnaireData) { + ZusammenElement questionnaireElement = computeQuestionnaireToZusammen(questionnaireData, Action.UPDATE); + ZusammenElement computeElement = buildElement(new Id(computeId), Action.IGNORE); + computeElement.setSubElements(Collections.singletonList(questionnaireElement)); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(vspId, version.getId()); + zusammenAdaptor.saveElement(context, elementContext, computeElement, "Update compute " + "questionnaire"); + } - if (optionalElement.isPresent()) { - Element computesElement = optionalElement.get(); - Collection computes = computesElement.getSubElements(); + @Override + public Collection listByVsp(String vspId, Version version) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(vspId, version.getId()); + Collection components = ComponentDaoZusammenImpl.listComponents(zusammenAdaptor, context, vspId, version); + return components.stream().map( + component -> listComputes(context, elementContext, new ComputeEntity(vspId, version, component.getId(), null)).stream() + .map(compute -> getQuestionnaire(context, elementContext, compute)).collect(Collectors.toList())).flatMap(Collection::stream) + .collect(Collectors.toList()); + } - computes.forEach(compute -> { - ZusammenElement computeElement = buildElement(compute.getElementId(), Action.DELETE); - zusammenAdaptor.saveElement(context, elementContext, computeElement, - "Delete compute with id " + compute.getElementId()); - }); + @Override + public void deleteAll(String vspId, Version version) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(vspId, version.getId()); + Optional optionalElement = zusammenAdaptor.getElementByName(context, elementContext, null, ElementType.Computes.name()); + if (optionalElement.isPresent()) { + Element computesElement = optionalElement.get(); + Collection computes = computesElement.getSubElements(); + computes.forEach(compute -> { + ZusammenElement computeElement = buildElement(compute.getElementId(), Action.DELETE); + zusammenAdaptor.saveElement(context, elementContext, computeElement, "Delete compute with id " + compute.getElementId()); + }); + } } - } - private ZusammenElement computeToZusammen(ComputeEntity compute, Action action) { - ZusammenElement computeElement = buildComputeElement(compute, action); - if (action == Action.CREATE) { - computeElement.setSubElements(Collections.singletonList( - computeQuestionnaireToZusammen(compute.getQuestionnaireData(), Action.CREATE))); + private ZusammenElement computeToZusammen(ComputeEntity compute, Action action) { + ZusammenElement computeElement = buildComputeElement(compute, action); + if (action == Action.CREATE) { + computeElement.setSubElements(Collections.singletonList(computeQuestionnaireToZusammen(compute.getQuestionnaireData(), Action.CREATE))); + } + return computeElement; } - return computeElement; - } - private ZusammenElement computeQuestionnaireToZusammen(String questionnaireData, - Action action) { - ZusammenElement questionnaireElement = - buildStructuralElement(ElementType.ComputeQuestionnaire, action); - questionnaireElement.setData(new ByteArrayInputStream(questionnaireData.getBytes())); - return questionnaireElement; - } + private ZusammenElement computeQuestionnaireToZusammen(String questionnaireData, Action action) { + ZusammenElement questionnaireElement = buildStructuralElement(ElementType.ComputeQuestionnaire, action); + questionnaireElement.setData(new ByteArrayInputStream(questionnaireData.getBytes())); + return questionnaireElement; + } - private ZusammenElement buildComputeElement(ComputeEntity compute, Action action) { - ZusammenElement computeElement = - buildElement(compute.getId() == null ? null : new Id(compute.getId()), action); - Info info = new Info(); - info.addProperty(ElementPropertyName.elementType.name(), ElementType.Compute); - info.addProperty(ElementPropertyName.compositionData.name(), compute.getCompositionData()); - computeElement.setInfo(info); - computeElement.setData(new ByteArrayInputStream(compute.getCompositionData().getBytes())); - return computeElement; - } + private ZusammenElement buildComputeElement(ComputeEntity compute, Action action) { + ZusammenElement computeElement = buildElement(compute.getId() == null ? null : new Id(compute.getId()), action); + Info info = new Info(); + info.addProperty(ElementPropertyName.elementType.name(), ElementType.Compute); + info.addProperty(ElementPropertyName.compositionData.name(), compute.getCompositionData()); + computeElement.setInfo(info); + computeElement.setData(new ByteArrayInputStream(compute.getCompositionData().getBytes())); + return computeElement; + } } 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/DeploymentFlavorDaoZusammenImpl.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/DeploymentFlavorDaoZusammenImpl.java index 8ccaf083d1..d72bd6b9b9 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/DeploymentFlavorDaoZusammenImpl.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/DeploymentFlavorDaoZusammenImpl.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,9 +17,12 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen; +import static org.openecomp.core.zusammen.api.ZusammenUtil.buildElement; +import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement; +import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext; + import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement; import com.amdocs.zusammen.datatypes.Id; @@ -27,6 +30,10 @@ import com.amdocs.zusammen.datatypes.SessionContext; import com.amdocs.zusammen.datatypes.item.Action; import com.amdocs.zusammen.datatypes.item.ElementContext; import com.amdocs.zusammen.datatypes.item.Info; +import java.io.ByteArrayInputStream; +import java.util.Collection; +import java.util.Optional; +import java.util.stream.Collectors; import org.openecomp.core.utilities.file.FileUtils; import org.openecomp.core.zusammen.api.ZusammenAdaptor; import org.openecomp.sdc.datatypes.model.ElementType; @@ -36,153 +43,105 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.type.DeploymentFlavorEntity; import org.openecomp.sdc.versioning.dao.types.Version; import org.openecomp.types.ElementPropertyName; -import java.io.ByteArrayInputStream; -import java.util.Collection; -import java.util.Optional; -import java.util.stream.Collectors; - -import static org.openecomp.core.zusammen.api.ZusammenUtil.*; - public class DeploymentFlavorDaoZusammenImpl implements DeploymentFlavorDao { - private ZusammenAdaptor zusammenAdaptor; - - public DeploymentFlavorDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { - this.zusammenAdaptor = zusammenAdaptor; - } - - @Override - public void registerVersioning(String versionableEntityType) { - // registerVersioning not implemented for DeploymentFlavorDaoZusammenImpl - } - - @Override - public Collection list(DeploymentFlavorEntity deploymentFlavor) { - SessionContext context = createSessionContext(); - ElementContext elementContext = - new ElementContext(deploymentFlavor.getVspId(), deploymentFlavor.getVersion().getId()); - - return listDeploymentFlavor(zusammenAdaptor, context, elementContext, - deploymentFlavor.getVspId(), - deploymentFlavor.getVersion()); - } + private ZusammenAdaptor zusammenAdaptor; - private static Collection listDeploymentFlavor( - ZusammenAdaptor zusammenAdaptor, - SessionContext context, - ElementContext elementContext, - String vspId, Version version) { - ElementToDeploymentFlavorConvertor convertor = new ElementToDeploymentFlavorConvertor(); - return zusammenAdaptor - .listElementsByName(context, elementContext, null, - ElementType.DeploymentFlavors.name()) - .stream().map(elementInfo -> { - DeploymentFlavorEntity entity = convertor.convert( - elementInfo); - entity.setVspId(vspId); - entity.setVersion(version); - return entity; - }) - .collect(Collectors.toList()); - } - - - @Override - public void create(DeploymentFlavorEntity deploymentFlavor) { - ZusammenElement deploymentFlavorElement = deploymentFlavorToZusammen(deploymentFlavor, - Action.CREATE); - ZusammenElement deploymentFlavorElements = - buildStructuralElement(ElementType.DeploymentFlavors, Action.IGNORE); - deploymentFlavorElements.getSubElements().add(deploymentFlavorElement); - - SessionContext context = createSessionContext(); - Element savedElement = zusammenAdaptor.saveElement(context, - new ElementContext(deploymentFlavor.getVspId(), deploymentFlavor.getVersion().getId()), - deploymentFlavorElements, "Create deloymentFlavor"); - deploymentFlavor.setId(savedElement.getSubElements().iterator().next().getElementId() - .getValue()); - } - - @Override - public void update(DeploymentFlavorEntity deploymentFlavor) { - ZusammenElement deploymentFlavorElement = deploymentFlavorToZusammen(deploymentFlavor, - Action.UPDATE); - - SessionContext context = createSessionContext(); - zusammenAdaptor.saveElement(context, - new ElementContext(deploymentFlavor.getVspId(), deploymentFlavor.getVersion().getId()), - deploymentFlavorElement, String.format("Update deloymentFlavor with id %s", - deploymentFlavor.getId())); - } - - @Override - public DeploymentFlavorEntity get(DeploymentFlavorEntity deploymentFlavor) { - SessionContext context = createSessionContext(); - ElementContext elementContext = - new ElementContext(deploymentFlavor.getVspId(), deploymentFlavor.getVersion().getId()); - - Optional element = - zusammenAdaptor.getElement(context, elementContext, deploymentFlavor.getId()); + public DeploymentFlavorDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { + this.zusammenAdaptor = zusammenAdaptor; + } - if (element.isPresent()) { - ElementToDeploymentFlavorConvertor convertor = new ElementToDeploymentFlavorConvertor(); - DeploymentFlavorEntity entity = convertor.convert(element.get()); - deploymentFlavor.setCompositionData(new String(FileUtils.toByteArray(element.get() - .getData()))); - entity.setVspId(deploymentFlavor.getVspId()); - entity.setVersion(deploymentFlavor.getVersion()); - return entity; + private static Collection listDeploymentFlavor(ZusammenAdaptor zusammenAdaptor, SessionContext context, + ElementContext elementContext, String vspId, Version version) { + ElementToDeploymentFlavorConvertor convertor = new ElementToDeploymentFlavorConvertor(); + return zusammenAdaptor.listElementsByName(context, elementContext, null, ElementType.DeploymentFlavors.name()).stream().map(elementInfo -> { + DeploymentFlavorEntity entity = convertor.convert(elementInfo); + entity.setVspId(vspId); + entity.setVersion(version); + return entity; + }).collect(Collectors.toList()); } - return null; - } - @Override - public void delete(DeploymentFlavorEntity deploymentFlavor) { - ZusammenElement componentElement = - buildElement(new Id(deploymentFlavor.getId()), Action.DELETE); + @Override + public void registerVersioning(String versionableEntityType) { + // registerVersioning not implemented for DeploymentFlavorDaoZusammenImpl + } - SessionContext context = createSessionContext(); - zusammenAdaptor.saveElement(context, - new ElementContext(deploymentFlavor.getVspId(), deploymentFlavor.getVersion().getId()), - componentElement, String.format("Delete deloymentFlavor with id %s", - deploymentFlavor.getId())); - } + @Override + public Collection list(DeploymentFlavorEntity deploymentFlavor) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(deploymentFlavor.getVspId(), deploymentFlavor.getVersion().getId()); + return listDeploymentFlavor(zusammenAdaptor, context, elementContext, deploymentFlavor.getVspId(), deploymentFlavor.getVersion()); + } - @Override - public void deleteAll(String vspId, Version version) { - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(vspId, version.getId()); + @Override + public void create(DeploymentFlavorEntity deploymentFlavor) { + ZusammenElement deploymentFlavorElement = deploymentFlavorToZusammen(deploymentFlavor, Action.CREATE); + ZusammenElement deploymentFlavorElements = buildStructuralElement(ElementType.DeploymentFlavors, Action.IGNORE); + deploymentFlavorElements.getSubElements().add(deploymentFlavorElement); + SessionContext context = createSessionContext(); + Element savedElement = zusammenAdaptor + .saveElement(context, new ElementContext(deploymentFlavor.getVspId(), deploymentFlavor.getVersion().getId()), deploymentFlavorElements, + "Create deloymentFlavor"); + deploymentFlavor.setId(savedElement.getSubElements().iterator().next().getElementId().getValue()); + } - Optional optionalElement = zusammenAdaptor.getElementByName(context, - elementContext, null, ElementType.DeploymentFlavors.name()); + @Override + public void update(DeploymentFlavorEntity deploymentFlavor) { + ZusammenElement deploymentFlavorElement = deploymentFlavorToZusammen(deploymentFlavor, Action.UPDATE); + SessionContext context = createSessionContext(); + zusammenAdaptor + .saveElement(context, new ElementContext(deploymentFlavor.getVspId(), deploymentFlavor.getVersion().getId()), deploymentFlavorElement, + String.format("Update deloymentFlavor with id %s", deploymentFlavor.getId())); + } - if (optionalElement.isPresent()) { - Element deploymentFlavorsElement = optionalElement.get(); - Collection deploymentFlavors = deploymentFlavorsElement.getSubElements(); + @Override + public DeploymentFlavorEntity get(DeploymentFlavorEntity deploymentFlavor) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(deploymentFlavor.getVspId(), deploymentFlavor.getVersion().getId()); + Optional element = zusammenAdaptor.getElement(context, elementContext, deploymentFlavor.getId()); + if (element.isPresent()) { + ElementToDeploymentFlavorConvertor convertor = new ElementToDeploymentFlavorConvertor(); + DeploymentFlavorEntity entity = convertor.convert(element.get()); + deploymentFlavor.setCompositionData(new String(FileUtils.toByteArray(element.get().getData()))); + entity.setVspId(deploymentFlavor.getVspId()); + entity.setVersion(deploymentFlavor.getVersion()); + return entity; + } + return null; + } - deploymentFlavors.forEach(deplymentFlavor -> { - ZusammenElement deplymentFlavorZusammenElement = - buildElement(deplymentFlavor.getElementId(), Action.DELETE); - zusammenAdaptor.saveElement(context, - elementContext, deplymentFlavorZusammenElement, " Delete Deplyment Flavor with id " - + deplymentFlavor.getElementId()); - }); + @Override + public void delete(DeploymentFlavorEntity deploymentFlavor) { + ZusammenElement componentElement = buildElement(new Id(deploymentFlavor.getId()), Action.DELETE); + SessionContext context = createSessionContext(); + zusammenAdaptor.saveElement(context, new ElementContext(deploymentFlavor.getVspId(), deploymentFlavor.getVersion().getId()), componentElement, + String.format("Delete deloymentFlavor with id %s", deploymentFlavor.getId())); } - } - private ZusammenElement deploymentFlavorToZusammen(DeploymentFlavorEntity deploymentFlavor, - Action action) { - ZusammenElement deploymentFlavorElement = - buildElement(deploymentFlavor.getId() == null ? null : new Id(deploymentFlavor.getId()), - action); - Info info = new Info(); - info.addProperty(ElementPropertyName.elementType.name(), ElementType.DeploymentFlavor); - info.addProperty(ElementPropertyName.compositionData.name(), deploymentFlavor - .getCompositionData()); - deploymentFlavorElement.setInfo(info); - deploymentFlavorElement.setData(new ByteArrayInputStream(deploymentFlavor.getCompositionData() - .getBytes())); - return deploymentFlavorElement; - } + @Override + public void deleteAll(String vspId, Version version) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(vspId, version.getId()); + Optional optionalElement = zusammenAdaptor.getElementByName(context, elementContext, null, ElementType.DeploymentFlavors.name()); + if (optionalElement.isPresent()) { + Element deploymentFlavorsElement = optionalElement.get(); + Collection deploymentFlavors = deploymentFlavorsElement.getSubElements(); + deploymentFlavors.forEach(deplymentFlavor -> { + ZusammenElement deplymentFlavorZusammenElement = buildElement(deplymentFlavor.getElementId(), Action.DELETE); + zusammenAdaptor.saveElement(context, elementContext, deplymentFlavorZusammenElement, + " Delete Deplyment Flavor with id " + deplymentFlavor.getElementId()); + }); + } + } + private ZusammenElement deploymentFlavorToZusammen(DeploymentFlavorEntity deploymentFlavor, Action action) { + ZusammenElement deploymentFlavorElement = buildElement(deploymentFlavor.getId() == null ? null : new Id(deploymentFlavor.getId()), action); + Info info = new Info(); + info.addProperty(ElementPropertyName.elementType.name(), ElementType.DeploymentFlavor); + info.addProperty(ElementPropertyName.compositionData.name(), deploymentFlavor.getCompositionData()); + deploymentFlavorElement.setInfo(info); + deploymentFlavorElement.setData(new ByteArrayInputStream(deploymentFlavor.getCompositionData().getBytes())); + return deploymentFlavorElement; + } } 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/ImageDaoZusammenImpl.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/ImageDaoZusammenImpl.java index f82827d02b..5227a4cff4 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/ImageDaoZusammenImpl.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/ImageDaoZusammenImpl.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,9 +17,11 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen; +import static org.openecomp.core.zusammen.api.ZusammenUtil.buildElement; +import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement; +import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext; import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement; @@ -28,6 +30,11 @@ import com.amdocs.zusammen.datatypes.SessionContext; import com.amdocs.zusammen.datatypes.item.Action; import com.amdocs.zusammen.datatypes.item.ElementContext; import com.amdocs.zusammen.datatypes.item.Info; +import java.io.ByteArrayInputStream; +import java.util.Collection; +import java.util.Collections; +import java.util.Optional; +import java.util.stream.Collectors; import org.openecomp.core.utilities.file.FileUtils; import org.openecomp.core.zusammen.api.ZusammenAdaptor; import org.openecomp.sdc.datatypes.model.ElementType; @@ -38,220 +45,156 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ImageEntity; import org.openecomp.sdc.versioning.dao.types.Version; import org.openecomp.types.ElementPropertyName; -import java.io.ByteArrayInputStream; -import java.util.Collection; -import java.util.Collections; -import java.util.Optional; -import java.util.stream.Collectors; - -import static org.openecomp.core.zusammen.api.ZusammenUtil.*; - public class ImageDaoZusammenImpl implements ImageDao { - private ZusammenAdaptor zusammenAdaptor; - - public ImageDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { - this.zusammenAdaptor = zusammenAdaptor; - } - - @Override - public void registerVersioning(String versionableEntityType) { - // registerVersioning not implemented for ImageDaoZusammenImpl - } - - @Override - public Collection list(ImageEntity image) { - SessionContext context = createSessionContext(); - ElementContext elementContext = - new ElementContext(image.getVspId(), image.getVersion().getId()); - - return listImages(context, elementContext, image); - } - - private Collection listImages(SessionContext context, - ElementContext elementContext, ImageEntity image) { - return zusammenAdaptor - .listElementsByName(context, elementContext, new Id(image.getComponentId()), - ElementType.Images.name()) - .stream().map(new ElementToImageConvertor()::convert) - .map(imageEntity -> { - imageEntity.setComponentId(image.getComponentId()); - imageEntity.setVspId(image.getVspId()); - imageEntity.setVersion(image.getVersion()); - return imageEntity; - }) - .collect(Collectors.toList()); - } - - @Override - public void create(ImageEntity image) { - ZusammenElement imageElement = imageToZusammen(image, Action.CREATE); - - ZusammenElement imagesElement = - buildStructuralElement(ElementType.Images, Action.IGNORE); - imagesElement.setSubElements(Collections.singletonList(imageElement)); - - ZusammenElement componentElement = buildElement(new Id(image.getComponentId()), Action.IGNORE); - componentElement.setSubElements(Collections.singletonList(imagesElement)); - - SessionContext context = createSessionContext(); - ElementContext elementContext = - new ElementContext(image.getVspId(), image.getVersion().getId()); - - Element savedElement = - zusammenAdaptor.saveElement(context, elementContext, componentElement, "Create image"); - image.setId(savedElement.getSubElements().iterator().next() - .getSubElements().iterator().next().getElementId().getValue()); - } + private ZusammenAdaptor zusammenAdaptor; - @Override - public void update(ImageEntity image) { - ZusammenElement imageElement = imageToZusammen(image, Action.UPDATE); - - SessionContext context = createSessionContext(); - ElementContext elementContext = - new ElementContext(image.getVspId(), image.getVersion().getId()); - zusammenAdaptor.saveElement(context, elementContext, imageElement, - String.format("Update image with id %s", image.getId())); - } - - @Override - public ImageEntity get(ImageEntity image) { - SessionContext context = createSessionContext(); - - ElementContext elementContext = - new ElementContext(image.getVspId(), image.getVersion().getId()); - Optional element = zusammenAdaptor.getElement(context, elementContext, image.getId()); - - if (element.isPresent()) { - ElementToImageConvertor convertor = new ElementToImageConvertor(); - ImageEntity entity = convertor.convert(element.get()); - entity.setComponentId(image.getComponentId()); - entity.setVspId(image.getVspId()); - entity.setVersion(image.getVersion()); - return entity; - } else { - return null; + public ImageDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { + this.zusammenAdaptor = zusammenAdaptor; } - } - - @Override - public void delete(ImageEntity image) { - ZusammenElement imageElement = buildElement(new Id(image.getId()), Action.DELETE); - - SessionContext context = createSessionContext(); - ElementContext elementContext = - new ElementContext(image.getVspId(), image.getVersion().getId()); - zusammenAdaptor.saveElement(context, elementContext, imageElement, - String.format("Delete image with id %s", image.getId())); - } - @Override - public void deleteByVspId(String vspId, Version version) { - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(vspId, version.getId()); - - Optional elementOptional = zusammenAdaptor.getElementByName(context, elementContext, - null, ElementType.Images.name()); - - if (elementOptional.isPresent()) { - Element imagesElement = elementOptional.get(); - Collection images = imagesElement.getSubElements(); - images.forEach(image -> { - ZusammenElement imageZusammenElement = buildElement(image.getElementId(), Action.DELETE); - zusammenAdaptor.saveElement(context, elementContext, imageZusammenElement, "Delete image " + - "with id " + image.getElementId()); - }); + @Override + public void registerVersioning(String versionableEntityType) { + // registerVersioning not implemented for ImageDaoZusammenImpl } - } - - @Override - public Collection listByVsp(String vspId, Version version) { - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(vspId, version.getId()); - Collection components = ComponentDaoZusammenImpl - .listComponents(zusammenAdaptor, context, vspId, version); + @Override + public Collection list(ImageEntity image) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(image.getVspId(), image.getVersion().getId()); + return listImages(context, elementContext, image); + } - return components.stream() - .map(component -> - listImages(context, elementContext, - new ImageEntity(vspId, version, component.getId(), null)).stream() - .map(image -> getQuestionnaire(context, elementContext, image)) - .collect(Collectors.toList())) - .flatMap(Collection::stream) - .collect(Collectors.toList()); - } + private Collection listImages(SessionContext context, ElementContext elementContext, ImageEntity image) { + return zusammenAdaptor.listElementsByName(context, elementContext, new Id(image.getComponentId()), ElementType.Images.name()).stream() + .map(new ElementToImageConvertor()::convert).map(imageEntity -> { + imageEntity.setComponentId(image.getComponentId()); + imageEntity.setVspId(image.getVspId()); + imageEntity.setVersion(image.getVersion()); + return imageEntity; + }).collect(Collectors.toList()); + } - @Override - public ImageEntity getQuestionnaireData(String vspId, Version version, String componentId, - String imageId) { - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(vspId, version.getId()); + @Override + public void create(ImageEntity image) { + ZusammenElement imageElement = imageToZusammen(image, Action.CREATE); + ZusammenElement imagesElement = buildStructuralElement(ElementType.Images, Action.IGNORE); + imagesElement.setSubElements(Collections.singletonList(imageElement)); + ZusammenElement componentElement = buildElement(new Id(image.getComponentId()), Action.IGNORE); + componentElement.setSubElements(Collections.singletonList(imagesElement)); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(image.getVspId(), image.getVersion().getId()); + Element savedElement = zusammenAdaptor.saveElement(context, elementContext, componentElement, "Create image"); + image.setId(savedElement.getSubElements().iterator().next().getSubElements().iterator().next().getElementId().getValue()); + } - return getQuestionnaire(context, elementContext, - new ImageEntity(vspId, version, componentId, imageId)); - } + @Override + public void update(ImageEntity image) { + ZusammenElement imageElement = imageToZusammen(image, Action.UPDATE); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(image.getVspId(), image.getVersion().getId()); + zusammenAdaptor.saveElement(context, elementContext, imageElement, String.format("Update image with id %s", image.getId())); + } - private ImageEntity getQuestionnaire(SessionContext context, ElementContext elementContext, - ImageEntity image) { - Optional questionnaireElement = zusammenAdaptor - .getElementByName(context, elementContext, new Id(image.getId()), - ElementType.ImageQuestionnaire.name()); - return questionnaireElement.map( - element -> element.getData() == null - ? null - : new String(FileUtils.toByteArray(element.getData()))) - .map(questionnaireData -> { - image.setQuestionnaireData(questionnaireData); - return image; - }) - .orElse(null); - } + @Override + public ImageEntity get(ImageEntity image) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(image.getVspId(), image.getVersion().getId()); + Optional element = zusammenAdaptor.getElement(context, elementContext, image.getId()); + if (element.isPresent()) { + ElementToImageConvertor convertor = new ElementToImageConvertor(); + ImageEntity entity = convertor.convert(element.get()); + entity.setComponentId(image.getComponentId()); + entity.setVspId(image.getVspId()); + entity.setVersion(image.getVersion()); + return entity; + } else { + return null; + } + } - @Override - public void updateQuestionnaireData(String vspId, Version version, String componentId, - String imageId, String questionnaireData) { - ZusammenElement questionnaireElement = - imageQuestionnaireToZusammen(questionnaireData, Action.UPDATE); + @Override + public void delete(ImageEntity image) { + ZusammenElement imageElement = buildElement(new Id(image.getId()), Action.DELETE); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(image.getVspId(), image.getVersion().getId()); + zusammenAdaptor.saveElement(context, elementContext, imageElement, String.format("Delete image with id %s", image.getId())); + } - ZusammenElement imageElement = buildElement(new Id(imageId), Action.IGNORE); - imageElement.setSubElements(Collections.singletonList(questionnaireElement)); + @Override + public void deleteByVspId(String vspId, Version version) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(vspId, version.getId()); + Optional elementOptional = zusammenAdaptor.getElementByName(context, elementContext, null, ElementType.Images.name()); + if (elementOptional.isPresent()) { + Element imagesElement = elementOptional.get(); + Collection images = imagesElement.getSubElements(); + images.forEach(image -> { + ZusammenElement imageZusammenElement = buildElement(image.getElementId(), Action.DELETE); + zusammenAdaptor.saveElement(context, elementContext, imageZusammenElement, "Delete image " + "with id " + image.getElementId()); + }); + } + } - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(vspId, version.getId()); - zusammenAdaptor.saveElement(context, elementContext, imageElement, "Update image " - + "questionnaire"); - } + @Override + public Collection listByVsp(String vspId, Version version) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(vspId, version.getId()); + Collection components = ComponentDaoZusammenImpl.listComponents(zusammenAdaptor, context, vspId, version); + return components.stream().map( + component -> listImages(context, elementContext, new ImageEntity(vspId, version, component.getId(), null)).stream() + .map(image -> getQuestionnaire(context, elementContext, image)).collect(Collectors.toList())).flatMap(Collection::stream) + .collect(Collectors.toList()); + } + @Override + public ImageEntity getQuestionnaireData(String vspId, Version version, String componentId, String imageId) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(vspId, version.getId()); + return getQuestionnaire(context, elementContext, new ImageEntity(vspId, version, componentId, imageId)); + } - private ZusammenElement imageToZusammen(ImageEntity image, Action action) { - ZusammenElement imageElement = buildImageElement(image, action); - if (action == Action.CREATE) { - imageElement.setSubElements(Collections.singletonList( - imageQuestionnaireToZusammen(image.getQuestionnaireData(), Action.CREATE))); + private ImageEntity getQuestionnaire(SessionContext context, ElementContext elementContext, ImageEntity image) { + Optional questionnaireElement = zusammenAdaptor + .getElementByName(context, elementContext, new Id(image.getId()), ElementType.ImageQuestionnaire.name()); + return questionnaireElement.map(element -> element.getData() == null ? null : new String(FileUtils.toByteArray(element.getData()))) + .map(questionnaireData -> { + image.setQuestionnaireData(questionnaireData); + return image; + }).orElse(null); } - return imageElement; - } - private ZusammenElement imageQuestionnaireToZusammen(String questionnaireData, - Action action) { - ZusammenElement questionnaireElement = - buildStructuralElement(ElementType.ImageQuestionnaire, action); - questionnaireElement.setData(new ByteArrayInputStream(questionnaireData.getBytes())); - return questionnaireElement; - } + @Override + public void updateQuestionnaireData(String vspId, Version version, String componentId, String imageId, String questionnaireData) { + ZusammenElement questionnaireElement = imageQuestionnaireToZusammen(questionnaireData, Action.UPDATE); + ZusammenElement imageElement = buildElement(new Id(imageId), Action.IGNORE); + imageElement.setSubElements(Collections.singletonList(questionnaireElement)); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(vspId, version.getId()); + zusammenAdaptor.saveElement(context, elementContext, imageElement, "Update image " + "questionnaire"); + } - private ZusammenElement buildImageElement(ImageEntity image, Action action) { - ZusammenElement imageElement = - buildElement(image.getId() == null ? null : new Id(image.getId()), action); - Info info = new Info(); - info.addProperty(ElementPropertyName.elementType.name(), ElementType.Image); - info.addProperty(ElementPropertyName.compositionData.name(), image.getCompositionData()); - imageElement.setInfo(info); - imageElement.setData(new ByteArrayInputStream(image.getCompositionData().getBytes())); - return imageElement; - } + private ZusammenElement imageToZusammen(ImageEntity image, Action action) { + ZusammenElement imageElement = buildImageElement(image, action); + if (action == Action.CREATE) { + imageElement.setSubElements(Collections.singletonList(imageQuestionnaireToZusammen(image.getQuestionnaireData(), Action.CREATE))); + } + return imageElement; + } + private ZusammenElement imageQuestionnaireToZusammen(String questionnaireData, Action action) { + ZusammenElement questionnaireElement = buildStructuralElement(ElementType.ImageQuestionnaire, action); + questionnaireElement.setData(new ByteArrayInputStream(questionnaireData.getBytes())); + return questionnaireElement; + } + private ZusammenElement buildImageElement(ImageEntity image, Action action) { + ZusammenElement imageElement = buildElement(image.getId() == null ? null : new Id(image.getId()), action); + Info info = new Info(); + info.addProperty(ElementPropertyName.elementType.name(), ElementType.Image); + info.addProperty(ElementPropertyName.compositionData.name(), image.getCompositionData()); + imageElement.setInfo(info); + imageElement.setData(new ByteArrayInputStream(image.getCompositionData().getBytes())); + return imageElement; + } } 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/NetworkDaoZusammenImpl.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/NetworkDaoZusammenImpl.java index 4099e1264b..0230f3e486 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/NetworkDaoZusammenImpl.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/NetworkDaoZusammenImpl.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,9 +17,12 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen; +import static org.openecomp.core.zusammen.api.ZusammenUtil.buildElement; +import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement; +import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext; + import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo; import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement; @@ -28,6 +31,12 @@ import com.amdocs.zusammen.datatypes.SessionContext; import com.amdocs.zusammen.datatypes.item.Action; import com.amdocs.zusammen.datatypes.item.ElementContext; import com.amdocs.zusammen.datatypes.item.Info; +import java.io.ByteArrayInputStream; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Optional; +import java.util.stream.Collectors; import org.openecomp.core.zusammen.api.ZusammenAdaptor; import org.openecomp.sdc.datatypes.model.ElementType; import org.openecomp.sdc.vendorsoftwareproduct.dao.NetworkDao; @@ -36,141 +45,103 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity; import org.openecomp.sdc.versioning.dao.types.Version; import org.openecomp.types.ElementPropertyName; -import java.io.ByteArrayInputStream; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Optional; -import java.util.stream.Collectors; - -import static org.openecomp.core.zusammen.api.ZusammenUtil.*; - public class NetworkDaoZusammenImpl implements NetworkDao { - private ZusammenAdaptor zusammenAdaptor; - - public NetworkDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { - this.zusammenAdaptor = zusammenAdaptor; - } - - @Override - public void registerVersioning(String versionableEntityType) { - // registerVersioning not implemented for NetworkDaoZusammenImpl - } + private ZusammenAdaptor zusammenAdaptor; - @Override - public Collection list(NetworkEntity network) { - SessionContext context = createSessionContext(); - ElementContext elementContext = - new ElementContext(network.getVspId(), network.getVersion().getId()); - - Optional vspModel = zusammenAdaptor - .getElementInfoByName(context, elementContext, null, ElementType.VspModel.name()); - if (!vspModel.isPresent()) { - return new ArrayList<>(); + public NetworkDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { + this.zusammenAdaptor = zusammenAdaptor; } - return zusammenAdaptor.listElementsByName(context, elementContext, vspModel.get().getId(), - ElementType.Networks.name()).stream() - .map(new ElementToNetworkConvertor()::convert) - .map(entity -> { - entity.setVspId(network.getVspId()); - entity.setVersion(network.getVersion()); - return entity; - }) - .collect(Collectors.toList()); - } - - @Override - public void create(NetworkEntity network) { - ZusammenElement networkElement = buildNetworkElement(network, Action.CREATE); - - ZusammenElement networksElement = buildStructuralElement(ElementType.Networks, Action.IGNORE); - networksElement.setSubElements(Collections.singletonList(networkElement)); - - ZusammenElement vspModel = buildStructuralElement(ElementType.VspModel, Action.IGNORE); - vspModel.addSubElement(networksElement); - - SessionContext context = createSessionContext(); - Element savedElement = zusammenAdaptor - .saveElement(context, new ElementContext(network.getVspId(), network.getVersion().getId()), - vspModel, "Create network"); - network.setId(savedElement.getSubElements().iterator().next() - .getSubElements().iterator().next().getElementId().getValue()); - } - - @Override - public void update(NetworkEntity network) { - ZusammenElement networkElement = buildNetworkElement(network, Action.UPDATE); - - SessionContext context = createSessionContext(); - zusammenAdaptor - .saveElement(context, new ElementContext(network.getVspId(), network.getVersion().getId()), - networkElement, String.format("Update network with id %s", network.getId())); - } - - @Override - public NetworkEntity get(NetworkEntity network) { - SessionContext context = createSessionContext(); - - Optional element = - zusammenAdaptor.getElement(context, - new ElementContext(network.getVspId(), network.getVersion().getId()), network.getId()); - - if (element.isPresent()) { - ElementToNetworkConvertor convertor = new ElementToNetworkConvertor(); - NetworkEntity entity = convertor.convert(element.get()); - entity.setVspId(network.getVspId()); - entity.setVersion(network.getVersion()); - return entity; - } else { - return null; + @Override + public void registerVersioning(String versionableEntityType) { + // registerVersioning not implemented for NetworkDaoZusammenImpl } - } - - @Override - public void delete(NetworkEntity network) { - ZusammenElement networkElement = buildElement(new Id(network.getId()), Action.DELETE); - - SessionContext context = createSessionContext(); - zusammenAdaptor - .saveElement(context, new ElementContext(network.getVspId(), network.getVersion().getId()), - networkElement, String.format("Delete network with id %s", network.getId())); - } + @Override + public Collection list(NetworkEntity network) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(network.getVspId(), network.getVersion().getId()); + Optional vspModel = zusammenAdaptor.getElementInfoByName(context, elementContext, null, ElementType.VspModel.name()); + if (!vspModel.isPresent()) { + return new ArrayList<>(); + } + return zusammenAdaptor.listElementsByName(context, elementContext, vspModel.get().getId(), ElementType.Networks.name()).stream() + .map(new ElementToNetworkConvertor()::convert).map(entity -> { + entity.setVspId(network.getVspId()); + entity.setVersion(network.getVersion()); + return entity; + }).collect(Collectors.toList()); + } - @Override - public void deleteAll(String vspId, Version version) { - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(vspId, version.getId()); + @Override + public void create(NetworkEntity network) { + ZusammenElement networkElement = buildNetworkElement(network, Action.CREATE); + ZusammenElement networksElement = buildStructuralElement(ElementType.Networks, Action.IGNORE); + networksElement.setSubElements(Collections.singletonList(networkElement)); + ZusammenElement vspModel = buildStructuralElement(ElementType.VspModel, Action.IGNORE); + vspModel.addSubElement(networksElement); + SessionContext context = createSessionContext(); + Element savedElement = zusammenAdaptor + .saveElement(context, new ElementContext(network.getVspId(), network.getVersion().getId()), vspModel, "Create network"); + network.setId(savedElement.getSubElements().iterator().next().getSubElements().iterator().next().getElementId().getValue()); + } - Collection vspModelSubs = zusammenAdaptor - .listElementsByName(context, elementContext, null, ElementType.VspModel.name()); + @Override + public void update(NetworkEntity network) { + ZusammenElement networkElement = buildNetworkElement(network, Action.UPDATE); + SessionContext context = createSessionContext(); + zusammenAdaptor.saveElement(context, new ElementContext(network.getVspId(), network.getVersion().getId()), networkElement, + String.format("Update network with id %s", network.getId())); + } - Optional networksElement = vspModelSubs.stream() - .filter(elementInfo -> elementInfo.getInfo() != null - && ElementType.Networks.name().equals(elementInfo.getInfo().getName())) - .findFirst(); - if (!networksElement.isPresent()) { - return; + @Override + public NetworkEntity get(NetworkEntity network) { + SessionContext context = createSessionContext(); + Optional element = zusammenAdaptor + .getElement(context, new ElementContext(network.getVspId(), network.getVersion().getId()), network.getId()); + if (element.isPresent()) { + ElementToNetworkConvertor convertor = new ElementToNetworkConvertor(); + NetworkEntity entity = convertor.convert(element.get()); + entity.setVspId(network.getVspId()); + entity.setVersion(network.getVersion()); + return entity; + } else { + return null; + } } - ZusammenElement networks = buildElement(networksElement.get().getId(), Action.IGNORE); - networks.setSubElements(networksElement.get().getSubElements().stream() - .map(network -> buildElement(network.getId(), Action.DELETE)) - .collect(Collectors.toList())); + @Override + public void delete(NetworkEntity network) { + ZusammenElement networkElement = buildElement(new Id(network.getId()), Action.DELETE); + SessionContext context = createSessionContext(); + zusammenAdaptor.saveElement(context, new ElementContext(network.getVspId(), network.getVersion().getId()), networkElement, + String.format("Delete network with id %s", network.getId())); + } - zusammenAdaptor.saveElement(context, elementContext, networks, "Delete all networks"); - } + @Override + public void deleteAll(String vspId, Version version) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(vspId, version.getId()); + Collection vspModelSubs = zusammenAdaptor.listElementsByName(context, elementContext, null, ElementType.VspModel.name()); + Optional networksElement = vspModelSubs.stream() + .filter(elementInfo -> elementInfo.getInfo() != null && ElementType.Networks.name().equals(elementInfo.getInfo().getName())).findFirst(); + if (!networksElement.isPresent()) { + return; + } + ZusammenElement networks = buildElement(networksElement.get().getId(), Action.IGNORE); + networks.setSubElements(networksElement.get().getSubElements().stream().map(network -> buildElement(network.getId(), Action.DELETE)) + .collect(Collectors.toList())); + zusammenAdaptor.saveElement(context, elementContext, networks, "Delete all networks"); + } - private ZusammenElement buildNetworkElement(NetworkEntity network, Action action) { - ZusammenElement networkElement = - buildElement(network.getId() == null ? null : new Id(network.getId()), action); - Info info = new Info(); - info.addProperty(ElementPropertyName.elementType.name(), ElementType.Network); - info.addProperty(ElementPropertyName.compositionData.name(), network.getCompositionData()); - networkElement.setInfo(info); - networkElement.setData(new ByteArrayInputStream(network.getCompositionData().getBytes())); - return networkElement; - } + private ZusammenElement buildNetworkElement(NetworkEntity network, Action action) { + ZusammenElement networkElement = buildElement(network.getId() == null ? null : new Id(network.getId()), action); + Info info = new Info(); + info.addProperty(ElementPropertyName.elementType.name(), ElementType.Network); + info.addProperty(ElementPropertyName.compositionData.name(), network.getCompositionData()); + networkElement.setInfo(info); + networkElement.setData(new ByteArrayInputStream(network.getCompositionData().getBytes())); + return networkElement; + } } 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/NicDaoZusammenImpl.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/NicDaoZusammenImpl.java index 05f8d9dcfc..baad1d7c89 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/NicDaoZusammenImpl.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/NicDaoZusammenImpl.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,9 +17,12 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen; +import static org.openecomp.core.zusammen.api.ZusammenUtil.buildElement; +import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement; +import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext; + import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement; import com.amdocs.zusammen.datatypes.Id; @@ -27,6 +30,11 @@ import com.amdocs.zusammen.datatypes.SessionContext; import com.amdocs.zusammen.datatypes.item.Action; import com.amdocs.zusammen.datatypes.item.ElementContext; import com.amdocs.zusammen.datatypes.item.Info; +import java.io.ByteArrayInputStream; +import java.util.Collection; +import java.util.Collections; +import java.util.Optional; +import java.util.stream.Collectors; import org.openecomp.core.zusammen.api.ZusammenAdaptor; import org.openecomp.sdc.datatypes.model.ElementType; import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDao; @@ -37,217 +45,159 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity; import org.openecomp.sdc.versioning.dao.types.Version; import org.openecomp.types.ElementPropertyName; -import java.io.ByteArrayInputStream; -import java.util.Collection; -import java.util.Collections; -import java.util.Optional; -import java.util.stream.Collectors; +public class NicDaoZusammenImpl implements NicDao { -import static org.openecomp.core.zusammen.api.ZusammenUtil.*; + private ZusammenAdaptor zusammenAdaptor; -public class NicDaoZusammenImpl implements NicDao { + public NicDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { + this.zusammenAdaptor = zusammenAdaptor; + } + + @Override + public void registerVersioning(String versionableEntityType) { + // registerVersioning is not implemented for NicDaoZusammenImpl + } + + @Override + public Collection list(NicEntity nic) { + SessionContext context = createSessionContext(); + return listNics(context, new ElementContext(nic.getVspId(), nic.getVersion().getId()), nic); + } + + private Collection listNics(SessionContext context, ElementContext elementContext, NicEntity nic) { + return zusammenAdaptor.listElementsByName(context, elementContext, new Id(nic.getComponentId()), ElementType.Nics.name()).stream() + .map(new ElementToNicConvertor()::convert).map(nicEntity -> { + nicEntity.setComponentId(nic.getComponentId()); + nicEntity.setVspId(nic.getVspId()); + nicEntity.setVersion(nic.getVersion()); + return nicEntity; + }).collect(Collectors.toList()); + } + + @Override + public void create(NicEntity nic) { + ZusammenElement nicElement = nicToZusammen(nic, Action.CREATE); + ZusammenElement nicsElement = buildStructuralElement(ElementType.Nics, Action.IGNORE); + nicsElement.setSubElements(Collections.singletonList(nicElement)); + ZusammenElement componentElement = buildElement(new Id(nic.getComponentId()), Action.IGNORE); + componentElement.setSubElements(Collections.singletonList(nicsElement)); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(nic.getVspId(), nic.getVersion().getId()); + Element savedElement = zusammenAdaptor.saveElement(context, elementContext, componentElement, "Create nic"); + nic.setId(savedElement.getSubElements().iterator().next().getSubElements().iterator().next().getElementId().getValue()); + } - private ZusammenAdaptor zusammenAdaptor; - - public NicDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { - this.zusammenAdaptor = zusammenAdaptor; - } - - @Override - public void registerVersioning(String versionableEntityType) { - // registerVersioning is not implemented for NicDaoZusammenImpl - } - - @Override - public Collection list(NicEntity nic) { - SessionContext context = createSessionContext(); - return listNics(context, new ElementContext(nic.getVspId(), nic.getVersion().getId()), nic); - } - - private Collection listNics(SessionContext context, ElementContext elementContext, - NicEntity nic) { - return zusammenAdaptor.listElementsByName(context, elementContext, new Id(nic.getComponentId()), - ElementType.Nics.name()) - .stream() - .map(new ElementToNicConvertor()::convert) - .map(nicEntity -> { - nicEntity.setComponentId(nic.getComponentId()); - nicEntity.setVspId(nic.getVspId()); - nicEntity.setVersion(nic.getVersion()); - return nicEntity; - }) - .collect(Collectors.toList()); - } - - - @Override - public void create(NicEntity nic) { - ZusammenElement nicElement = nicToZusammen(nic, Action.CREATE); - - ZusammenElement nicsElement = buildStructuralElement(ElementType.Nics, Action.IGNORE); - nicsElement.setSubElements(Collections.singletonList(nicElement)); - - ZusammenElement componentElement = buildElement(new Id(nic.getComponentId()), Action.IGNORE); - componentElement.setSubElements(Collections.singletonList(nicsElement)); - - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(nic.getVspId(), nic.getVersion().getId()); - - Element savedElement = - zusammenAdaptor.saveElement(context, elementContext, componentElement, "Create nic"); - nic.setId(savedElement.getSubElements().iterator().next() - .getSubElements().iterator().next().getElementId().getValue()); - } - - @Override - public void update(NicEntity nic) { - ZusammenElement nicElement = nicToZusammen(nic, Action.UPDATE); - - SessionContext context = createSessionContext(); - zusammenAdaptor - .saveElement(context, new ElementContext(nic.getVspId(), nic.getVersion().getId()), - nicElement, String.format("Update nic with id %s", nic.getId())); - } - - @Override - public NicEntity get(NicEntity nic) { - SessionContext context = createSessionContext(); - ElementToNicConvertor convertor = new ElementToNicConvertor(); - Optional element = zusammenAdaptor - .getElement(context, new ElementContext(nic.getVspId(), nic.getVersion().getId()), - nic.getId()); - - if (element.isPresent()) { - NicEntity entity = convertor.convert(element.get()); - entity.setVspId(nic.getVspId()); - entity.setVersion(nic.getVersion()); - entity.setComponentId(nic.getComponentId()); - - return entity; - } else { - return null; - } - } - - @Override - public void delete(NicEntity nic) { - ZusammenElement nicElement = buildElement(new Id(nic.getId()), Action.DELETE); - - SessionContext context = createSessionContext(); - zusammenAdaptor - .saveElement(context, new ElementContext(nic.getVspId(), nic.getVersion().getId()), - nicElement, String.format("Delete nic with id %s", nic.getId())); - } - - @Override - public NicEntity getQuestionnaireData(String vspId, Version version, String componentId, - String nicId) { - SessionContext context = createSessionContext(); - - return getQuestionnaire(context, new ElementContext(vspId, version.getId()), - new NicEntity(vspId, version, componentId, nicId)); - } - - private NicEntity getQuestionnaire(SessionContext context, ElementContext elementContext, - NicEntity nic) { - Optional questionnaireElement = zusammenAdaptor - .getElementByName(context, elementContext, new Id(nic.getId()), - ElementType.NicQuestionnaire.name()); - return questionnaireElement.map(new ElementToNicQuestionnaireConvertor()::convert) - .map(entity -> { - entity.setVspId(nic.getVspId()); - entity.setVersion(nic.getVersion()); - entity.setComponentId(nic.getComponentId()); - return entity; - }) - .orElse(null); - } - - @Override - public void updateQuestionnaireData(String vspId, Version version, String componentId, - String nicId, String questionnaireData) { - ZusammenElement questionnaireElement = - nicQuestionnaireToZusammen(questionnaireData, Action.UPDATE); - - ZusammenElement nicElement = buildElement(new Id(nicId), Action.IGNORE); - nicElement.setSubElements(Collections.singletonList(questionnaireElement)); - - SessionContext context = createSessionContext(); - zusammenAdaptor.saveElement(context, new ElementContext(vspId, version.getId()), nicElement, - "Update nic questionnaire"); - } - - @Override - public Collection listByVsp(String vspId, Version version) { - SessionContext context = createSessionContext(); - - Collection components = ComponentDaoZusammenImpl - .listComponents(zusammenAdaptor, context, vspId, version); - - ElementContext elementContext = new ElementContext(vspId, version.getId()); - return components.stream() - .map(component -> - listNics(context, elementContext, - new NicEntity(vspId, version, component.getId(), null)).stream() - .map(nic -> { - nic.setQuestionnaireData(getQuestionnaire(context, elementContext, nic).getQuestionnaireData()); - return nic; - }) - .collect(Collectors.toList())) - .flatMap(Collection::stream) - .collect(Collectors.toList()); - } - - @Override - public void deleteByComponentId(String vspId, Version version, String componentId) { - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(vspId, version.getId()); - - Optional optionalElement = zusammenAdaptor.getElementByName(context, - elementContext, new Id(componentId), ElementType.Nics.name()); - - if (optionalElement.isPresent()) { - Element nicsElement = optionalElement.get(); - Collection nics = nicsElement.getSubElements(); - - nics.forEach(nic -> { - ZusammenElement nicZusammenElement = buildElement(nic.getElementId(), Action.DELETE); - zusammenAdaptor.saveElement(context, elementContext, nicZusammenElement, - "Delete nic with id " + nic.getElementId()); - }); - } - } - - @Override - public void deleteByVspId(String vspId, Version version) { - // deleteByVspId not implemented for NicDaoZusammenImpl - } - - private ZusammenElement nicToZusammen(NicEntity nic, Action action) { - ZusammenElement nicElement = buildNicElement(nic, action); - if (action == Action.CREATE) { - nicElement.setSubElements(Collections.singletonList( - nicQuestionnaireToZusammen(nic.getQuestionnaireData(), Action.CREATE))); - } - return nicElement; - } - - private ZusammenElement nicQuestionnaireToZusammen(String questionnaireData, - Action action) { - ZusammenElement questionnaireElement = - buildStructuralElement(ElementType.NicQuestionnaire, action); - questionnaireElement.setData(new ByteArrayInputStream(questionnaireData.getBytes())); - return questionnaireElement; - } - - private ZusammenElement buildNicElement(NicEntity nic, Action action) { - ZusammenElement nicElement = - buildElement(nic.getId() == null ? null : new Id(nic.getId()), action); - Info info = new Info(); - info.addProperty(ElementPropertyName.elementType.name(), ElementType.Nic); - info.addProperty(ElementPropertyName.compositionData.name(), nic.getCompositionData()); - nicElement.setInfo(info); - nicElement.setData(new ByteArrayInputStream(nic.getCompositionData().getBytes())); - return nicElement; - } + @Override + public void update(NicEntity nic) { + ZusammenElement nicElement = nicToZusammen(nic, Action.UPDATE); + SessionContext context = createSessionContext(); + zusammenAdaptor.saveElement(context, new ElementContext(nic.getVspId(), nic.getVersion().getId()), nicElement, + String.format("Update nic with id %s", nic.getId())); + } + + @Override + public NicEntity get(NicEntity nic) { + SessionContext context = createSessionContext(); + ElementToNicConvertor convertor = new ElementToNicConvertor(); + Optional element = zusammenAdaptor.getElement(context, new ElementContext(nic.getVspId(), nic.getVersion().getId()), nic.getId()); + if (element.isPresent()) { + NicEntity entity = convertor.convert(element.get()); + entity.setVspId(nic.getVspId()); + entity.setVersion(nic.getVersion()); + entity.setComponentId(nic.getComponentId()); + return entity; + } else { + return null; + } + } + + @Override + public void delete(NicEntity nic) { + ZusammenElement nicElement = buildElement(new Id(nic.getId()), Action.DELETE); + SessionContext context = createSessionContext(); + zusammenAdaptor.saveElement(context, new ElementContext(nic.getVspId(), nic.getVersion().getId()), nicElement, + String.format("Delete nic with id %s", nic.getId())); + } + + @Override + public NicEntity getQuestionnaireData(String vspId, Version version, String componentId, String nicId) { + SessionContext context = createSessionContext(); + return getQuestionnaire(context, new ElementContext(vspId, version.getId()), new NicEntity(vspId, version, componentId, nicId)); + } + + private NicEntity getQuestionnaire(SessionContext context, ElementContext elementContext, NicEntity nic) { + Optional questionnaireElement = zusammenAdaptor + .getElementByName(context, elementContext, new Id(nic.getId()), ElementType.NicQuestionnaire.name()); + return questionnaireElement.map(new ElementToNicQuestionnaireConvertor()::convert).map(entity -> { + entity.setVspId(nic.getVspId()); + entity.setVersion(nic.getVersion()); + entity.setComponentId(nic.getComponentId()); + return entity; + }).orElse(null); + } + + @Override + public void updateQuestionnaireData(String vspId, Version version, String componentId, String nicId, String questionnaireData) { + ZusammenElement questionnaireElement = nicQuestionnaireToZusammen(questionnaireData, Action.UPDATE); + ZusammenElement nicElement = buildElement(new Id(nicId), Action.IGNORE); + nicElement.setSubElements(Collections.singletonList(questionnaireElement)); + SessionContext context = createSessionContext(); + zusammenAdaptor.saveElement(context, new ElementContext(vspId, version.getId()), nicElement, "Update nic questionnaire"); + } + + @Override + public Collection listByVsp(String vspId, Version version) { + SessionContext context = createSessionContext(); + Collection components = ComponentDaoZusammenImpl.listComponents(zusammenAdaptor, context, vspId, version); + ElementContext elementContext = new ElementContext(vspId, version.getId()); + return components.stream() + .map(component -> listNics(context, elementContext, new NicEntity(vspId, version, component.getId(), null)).stream().map(nic -> { + nic.setQuestionnaireData(getQuestionnaire(context, elementContext, nic).getQuestionnaireData()); + return nic; + }).collect(Collectors.toList())).flatMap(Collection::stream).collect(Collectors.toList()); + } + + @Override + public void deleteByComponentId(String vspId, Version version, String componentId) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(vspId, version.getId()); + Optional optionalElement = zusammenAdaptor.getElementByName(context, elementContext, new Id(componentId), ElementType.Nics.name()); + if (optionalElement.isPresent()) { + Element nicsElement = optionalElement.get(); + Collection nics = nicsElement.getSubElements(); + nics.forEach(nic -> { + ZusammenElement nicZusammenElement = buildElement(nic.getElementId(), Action.DELETE); + zusammenAdaptor.saveElement(context, elementContext, nicZusammenElement, "Delete nic with id " + nic.getElementId()); + }); + } + } + + @Override + public void deleteByVspId(String vspId, Version version) { + // deleteByVspId not implemented for NicDaoZusammenImpl + } + + private ZusammenElement nicToZusammen(NicEntity nic, Action action) { + ZusammenElement nicElement = buildNicElement(nic, action); + if (action == Action.CREATE) { + nicElement.setSubElements(Collections.singletonList(nicQuestionnaireToZusammen(nic.getQuestionnaireData(), Action.CREATE))); + } + return nicElement; + } + + private ZusammenElement nicQuestionnaireToZusammen(String questionnaireData, Action action) { + ZusammenElement questionnaireElement = buildStructuralElement(ElementType.NicQuestionnaire, action); + questionnaireElement.setData(new ByteArrayInputStream(questionnaireData.getBytes())); + return questionnaireElement; + } + + private ZusammenElement buildNicElement(NicEntity nic, Action action) { + ZusammenElement nicElement = buildElement(nic.getId() == null ? null : new Id(nic.getId()), action); + Info info = new Info(); + info.addProperty(ElementPropertyName.elementType.name(), ElementType.Nic); + info.addProperty(ElementPropertyName.compositionData.name(), nic.getCompositionData()); + nicElement.setInfo(info); + nicElement.setData(new ByteArrayInputStream(nic.getCompositionData().getBytes())); + return nicElement; + } } 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 4c1e2e1ef2..fb26714375 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 @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen; import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement; @@ -41,251 +40,173 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCan import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.FilesDataStructure; import org.openecomp.sdc.versioning.dao.types.Version; -public class OrchestrationTemplateCandidateDaoZusammenImpl - implements OrchestrationTemplateCandidateDao { - - private static final Logger logger = - LoggerFactory.getLogger(OrchestrationTemplateCandidateDaoZusammenImpl.class); - - private final ZusammenAdaptor zusammenAdaptor; - - private static final String EMPTY_DATA = "{}"; - - public OrchestrationTemplateCandidateDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { - this.zusammenAdaptor = zusammenAdaptor; - } +public class OrchestrationTemplateCandidateDaoZusammenImpl implements OrchestrationTemplateCandidateDao { - @Override - public void registerVersioning(String versionableEntityType) { - // registerVersioning not implemented for OrchestrationTemplateCandidateDaoZusammenImpl - } + private static final Logger logger = LoggerFactory.getLogger(OrchestrationTemplateCandidateDaoZusammenImpl.class); + private static final String EMPTY_DATA = "{}"; + private final ZusammenAdaptor zusammenAdaptor; - @Override - public Optional get(String vspId, Version version) { - logger.info("Getting orchestration template for vsp id {}", vspId); - - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(vspId, version.getId()); - - Optional candidateElement = - zusammenAdaptor.getElementByName(context, elementContext, null, - ElementType.OrchestrationTemplateCandidate.name()); - - 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(); + public OrchestrationTemplateCandidateDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { + this.zusammenAdaptor = zusammenAdaptor; } - OrchestrationTemplateCandidateData candidate = new OrchestrationTemplateCandidateData(); - candidate.setFilesDataStructure( - new String(FileUtils.toByteArray(candidateElement.get().getData()))); - - 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 candidate.getFileSuffix() == null ? Optional.empty() : Optional.of(candidate); - } - - @Override - public Optional 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()); - - Optional candidateElement = - zusammenAdaptor.getElementInfoByName(context, elementContext, null, - ElementType.OrchestrationTemplateCandidate.name()); - - if (!candidateElement.isPresent() || candidateElement.get().getSubElements().isEmpty()) { - logger.info("Orchestration template info for vsp id {} does not exist", vspId); - return Optional.empty(); + @Override + public void registerVersioning(String versionableEntityType) { + // registerVersioning not implemented for OrchestrationTemplateCandidateDaoZusammenImpl } - 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(final OrchestrationTemplateCandidateData candidate, - final Element candidateInfoElement, - final boolean fullData) { - final String elementName = candidateInfoElement.getInfo().getName(); - if (ElementType.OrchestrationTemplateCandidateContent.name().equals(elementName)) { - 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 (ElementType.OrchestrationTemplateCandidateValidationData.name().equals(elementName)) { - candidate.setValidationData(new String(FileUtils.toByteArray(candidateInfoElement.getData()))); - } else if (ElementType.ORIGINAL_ONBOARDED_PACKAGE.name().equals(elementName)) { - candidate.setOriginalFileName(candidateInfoElement.getInfo() - .getProperty(InfoPropertyName.ORIGINAL_FILE_NAME.getVal())); - candidate.setOriginalFileSuffix(candidateInfoElement.getInfo() - .getProperty(InfoPropertyName.ORIGINAL_FILE_SUFFIX.getVal())); - if (fullData) { - candidate.setOriginalFileContentData( - ByteBuffer.wrap(FileUtils.toByteArray(candidateInfoElement.getData())) - ); - } + @Override + public Optional get(String vspId, Version version) { + logger.info("Getting orchestration template for vsp id {}", vspId); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(vspId, version.getId()); + Optional candidateElement = zusammenAdaptor + .getElementByName(context, elementContext, null, ElementType.OrchestrationTemplateCandidate.name()); + 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(); + } + OrchestrationTemplateCandidateData candidate = new OrchestrationTemplateCandidateData(); + candidate.setFilesDataStructure(new String(FileUtils.toByteArray(candidateElement.get().getData()))); + 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 candidate.getFileSuffix() == null ? Optional.empty() : Optional.of(candidate); } - } - - @Override - public void delete(String vspId, Version version) { - ByteArrayInputStream emptyData = new ByteArrayInputStream(EMPTY_DATA.getBytes()); - - ZusammenElement candidateContentElement = - buildStructuralElement(ElementType.OrchestrationTemplateCandidateContent, Action.UPDATE); - candidateContentElement.setData(emptyData); - - ZusammenElement validationData = buildStructuralElement(ElementType - .OrchestrationTemplateCandidateValidationData, Action.UPDATE); - validationData.setData(emptyData); - - ZusammenElement candidateElement = - buildStructuralElement(ElementType.OrchestrationTemplateCandidate, Action.UPDATE); - candidateElement.setData(emptyData); - candidateElement.addSubElement(candidateContentElement); - candidateElement.addSubElement(validationData); - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(vspId, version.getId()); - zusammenAdaptor.saveElement(context, elementContext, candidateElement, - "Delete Orchestration Template Candidate Elements's content"); - } - - @Override - public void update(final String vspId, final Version version, - final OrchestrationTemplateCandidateData candidateData) { - logger.info("Uploading candidate data entity for vsp id {}", vspId); - final ZusammenElement candidateElement = - buildStructuralElement(ElementType.OrchestrationTemplateCandidate, Action.UPDATE); - candidateElement - .setData(new ByteArrayInputStream(candidateData.getFilesDataStructure().getBytes())); - - final ZusammenElement candidateContentElement = - buildStructuralElement(ElementType.OrchestrationTemplateCandidateContent, Action.UPDATE); - candidateContentElement - .setData(new ByteArrayInputStream(candidateData.getContentData().array())); - candidateContentElement.getInfo() - .addProperty(InfoPropertyName.FILE_SUFFIX.getVal(), candidateData.getFileSuffix()); - candidateContentElement.getInfo() - .addProperty(InfoPropertyName.FILE_NAME.getVal(), candidateData.getFileName()); - - if (OnboardingTypesEnum.CSAR.toString().equalsIgnoreCase(candidateData.getFileSuffix())) { - final ZusammenElement originalPackageElement = - buildStructuralElement(ElementType.ORIGINAL_ONBOARDED_PACKAGE, Action.UPDATE); - originalPackageElement.getInfo() - .addProperty(InfoPropertyName.ORIGINAL_FILE_NAME.getVal(), candidateData.getOriginalFileName()); - originalPackageElement.getInfo() - .addProperty(InfoPropertyName.ORIGINAL_FILE_SUFFIX.getVal(), candidateData.getOriginalFileSuffix()); - originalPackageElement.setData(new ByteArrayInputStream(candidateData.getOriginalFileContentData().array())); - candidateElement.addSubElement(originalPackageElement); + @Override + public Optional 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()); + Optional candidateElement = zusammenAdaptor + .getElementInfoByName(context, elementContext, null, ElementType.OrchestrationTemplateCandidate.name()); + if (!candidateElement.isPresent() || candidateElement.get().getSubElements().isEmpty()) { + logger.info("Orchestration template info for vsp id {} does not exist", vspId); + return Optional.empty(); + } + 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); } - final ZusammenElement validationData = buildStructuralElement(ElementType - .OrchestrationTemplateCandidateValidationData, Action.UPDATE); - if (candidateData.getValidationData() != null) { - validationData - .setData(new ByteArrayInputStream(candidateData.getValidationData().getBytes())); - } - candidateElement.addSubElement(validationData); - candidateElement.addSubElement(candidateContentElement); - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(vspId, version.getId()); - zusammenAdaptor.saveElement(context, elementContext, candidateElement, - "Update Orchestration Template Candidate"); - 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); - - ZusammenElement validationDataElement = buildStructuralElement(ElementType - .OrchestrationTemplateCandidateValidationData, Action.UPDATE); - validationDataElement.setData(validationData == null ? new ByteArrayInputStream(EMPTY_DATA - .getBytes()) : new ByteArrayInputStream(JsonUtil.object2Json(validationData).getBytes())); - - ZusammenElement candidateElement = - buildStructuralElement(ElementType.OrchestrationTemplateCandidate, Action.IGNORE); - candidateElement.addSubElement(validationDataElement); - - SessionContext context = createSessionContext(); - 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); - } - - @Override - public void updateStructure(String vspId, Version version, FilesDataStructure fileDataStructure) { - logger.info("Updating orchestration template for VSP id {}", vspId); - - ZusammenElement candidateElement = - buildStructuralElement(ElementType.OrchestrationTemplateCandidate, Action.UPDATE); - candidateElement - .setData(new ByteArrayInputStream(JsonUtil.object2Json(fileDataStructure).getBytes())); - SessionContext context = createSessionContext(); - 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 vsp id {}", vspId); - } - - - @Override - public Optional getStructure(String vspId, Version version) { - logger.info("Getting orchestration template candidate structure for vsp id {}", vspId); - - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(vspId, version.getId()); + private void populateCandidate(final OrchestrationTemplateCandidateData candidate, final Element candidateInfoElement, final boolean fullData) { + final String elementName = candidateInfoElement.getInfo().getName(); + if (ElementType.OrchestrationTemplateCandidateContent.name().equals(elementName)) { + 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 (ElementType.OrchestrationTemplateCandidateValidationData.name().equals(elementName)) { + candidate.setValidationData(new String(FileUtils.toByteArray(candidateInfoElement.getData()))); + } else if (ElementType.ORIGINAL_ONBOARDED_PACKAGE.name().equals(elementName)) { + candidate.setOriginalFileName(candidateInfoElement.getInfo().getProperty(InfoPropertyName.ORIGINAL_FILE_NAME.getVal())); + candidate.setOriginalFileSuffix(candidateInfoElement.getInfo().getProperty(InfoPropertyName.ORIGINAL_FILE_SUFFIX.getVal())); + if (fullData) { + candidate.setOriginalFileContentData(ByteBuffer.wrap(FileUtils.toByteArray(candidateInfoElement.getData()))); + } + } + } - Optional element = zusammenAdaptor.getElementByName(context, elementContext, null, - ElementType.OrchestrationTemplateCandidate.name()); + @Override + public void delete(String vspId, Version version) { + ByteArrayInputStream emptyData = new ByteArrayInputStream(EMPTY_DATA.getBytes()); + ZusammenElement candidateContentElement = buildStructuralElement(ElementType.OrchestrationTemplateCandidateContent, Action.UPDATE); + candidateContentElement.setData(emptyData); + ZusammenElement validationData = buildStructuralElement(ElementType.OrchestrationTemplateCandidateValidationData, Action.UPDATE); + validationData.setData(emptyData); + ZusammenElement candidateElement = buildStructuralElement(ElementType.OrchestrationTemplateCandidate, Action.UPDATE); + candidateElement.setData(emptyData); + candidateElement.addSubElement(candidateContentElement); + candidateElement.addSubElement(validationData); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(vspId, version.getId()); + zusammenAdaptor.saveElement(context, elementContext, candidateElement, "Delete Orchestration Template Candidate Elements's content"); + } - if (element.isPresent() && !VspZusammenUtil.hasEmptyData(element.get().getData())) { - return Optional.of(new String(FileUtils.toByteArray(element.get().getData()))); + @Override + public void update(final String vspId, final Version version, final OrchestrationTemplateCandidateData candidateData) { + logger.info("Uploading candidate data entity for vsp id {}", vspId); + final ZusammenElement candidateElement = buildStructuralElement(ElementType.OrchestrationTemplateCandidate, Action.UPDATE); + candidateElement.setData(new ByteArrayInputStream(candidateData.getFilesDataStructure().getBytes())); + final ZusammenElement candidateContentElement = buildStructuralElement(ElementType.OrchestrationTemplateCandidateContent, Action.UPDATE); + candidateContentElement.setData(new ByteArrayInputStream(candidateData.getContentData().array())); + candidateContentElement.getInfo().addProperty(InfoPropertyName.FILE_SUFFIX.getVal(), candidateData.getFileSuffix()); + candidateContentElement.getInfo().addProperty(InfoPropertyName.FILE_NAME.getVal(), candidateData.getFileName()); + if (OnboardingTypesEnum.CSAR.toString().equalsIgnoreCase(candidateData.getFileSuffix())) { + final ZusammenElement originalPackageElement = buildStructuralElement(ElementType.ORIGINAL_ONBOARDED_PACKAGE, Action.UPDATE); + originalPackageElement.getInfo().addProperty(InfoPropertyName.ORIGINAL_FILE_NAME.getVal(), candidateData.getOriginalFileName()); + originalPackageElement.getInfo().addProperty(InfoPropertyName.ORIGINAL_FILE_SUFFIX.getVal(), candidateData.getOriginalFileSuffix()); + originalPackageElement.setData(new ByteArrayInputStream(candidateData.getOriginalFileContentData().array())); + candidateElement.addSubElement(originalPackageElement); + } + final ZusammenElement validationData = buildStructuralElement(ElementType.OrchestrationTemplateCandidateValidationData, Action.UPDATE); + if (candidateData.getValidationData() != null) { + validationData.setData(new ByteArrayInputStream(candidateData.getValidationData().getBytes())); + } + candidateElement.addSubElement(validationData); + candidateElement.addSubElement(candidateContentElement); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(vspId, version.getId()); + zusammenAdaptor.saveElement(context, elementContext, candidateElement, "Update Orchestration Template Candidate"); + logger.info("Finished uploading candidate data entity for vsp id {}", vspId); } - logger.info("Finished getting orchestration template candidate structure 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); + ZusammenElement validationDataElement = buildStructuralElement(ElementType.OrchestrationTemplateCandidateValidationData, Action.UPDATE); + validationDataElement.setData(validationData == null ? new ByteArrayInputStream(EMPTY_DATA.getBytes()) + : new ByteArrayInputStream(JsonUtil.object2Json(validationData).getBytes())); + ZusammenElement candidateElement = buildStructuralElement(ElementType.OrchestrationTemplateCandidate, Action.IGNORE); + candidateElement.addSubElement(validationDataElement); + SessionContext context = createSessionContext(); + 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); + } - return Optional.empty(); - } + @Override + public void updateStructure(String vspId, Version version, FilesDataStructure fileDataStructure) { + logger.info("Updating orchestration template for VSP id {}", vspId); + ZusammenElement candidateElement = buildStructuralElement(ElementType.OrchestrationTemplateCandidate, Action.UPDATE); + candidateElement.setData(new ByteArrayInputStream(JsonUtil.object2Json(fileDataStructure).getBytes())); + SessionContext context = createSessionContext(); + 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 vsp id {}", vspId); + } - public enum InfoPropertyName { - FILE_SUFFIX("fileSuffix"), - FILE_NAME("fileName"), - ORIGINAL_FILE_NAME("originalFilename"), - ORIGINAL_FILE_SUFFIX("originalFileSuffix"); + @Override + public Optional getStructure(String vspId, Version version) { + logger.info("Getting orchestration template candidate structure for vsp id {}", vspId); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(vspId, version.getId()); + Optional element = zusammenAdaptor + .getElementByName(context, elementContext, null, ElementType.OrchestrationTemplateCandidate.name()); + if (element.isPresent() && !VspZusammenUtil.hasEmptyData(element.get().getData())) { + return Optional.of(new String(FileUtils.toByteArray(element.get().getData()))); + } + logger.info("Finished getting orchestration template candidate structure for vsp id {}", vspId); + return Optional.empty(); + } - private final String val; + public enum InfoPropertyName { + FILE_SUFFIX("fileSuffix"), FILE_NAME("fileName"), ORIGINAL_FILE_NAME("originalFilename"), ORIGINAL_FILE_SUFFIX("originalFileSuffix"); + private final String val; - InfoPropertyName(String val) { - this.val = val; - } + InfoPropertyName(String val) { + this.val = val; + } - private String getVal() { - return val; + private 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/dao/impl/zusammen/OrchestrationTemplateDaoZusammenImpl.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/OrchestrationTemplateDaoZusammenImpl.java index bc186e7629..dd78a94eb5 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/OrchestrationTemplateDaoZusammenImpl.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/OrchestrationTemplateDaoZusammenImpl.java @@ -13,9 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen; +import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement; +import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext; + import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo; import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement; @@ -23,6 +25,10 @@ import com.amdocs.zusammen.datatypes.SessionContext; import com.amdocs.zusammen.datatypes.item.Action; import com.amdocs.zusammen.datatypes.item.ElementContext; import com.amdocs.zusammen.utils.fileutils.FileUtils; +import java.io.ByteArrayInputStream; +import java.nio.ByteBuffer; +import java.util.Collection; +import java.util.Optional; import org.openecomp.core.zusammen.api.ZusammenAdaptor; import org.openecomp.sdc.datatypes.model.ElementType; import org.openecomp.sdc.logging.api.Logger; @@ -31,205 +37,142 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateEntity; 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; -import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext; - public class OrchestrationTemplateDaoZusammenImpl implements OrchestrationTemplateDao { - private static final Logger LOGGER = LoggerFactory.getLogger( - OrchestrationTemplateDaoZusammenImpl.class); - private ZusammenAdaptor zusammenAdaptor; - - public OrchestrationTemplateDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { - this.zusammenAdaptor = zusammenAdaptor; - } - - @Override - public void registerVersioning(String versionableEntityType) { - // registerVersioning not implemented for OrchestrationTemplateDaoZusammenImpl - } - - @Override - public OrchestrationTemplateEntity getInfo(String vspId, Version version) { - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(vspId, version.getId()); - - Optional vspModel = zusammenAdaptor - .getElementInfoByName(context, elementContext, null, ElementType.VspModel.name()); - if (!vspModel.isPresent()) { - return null; - } - - Optional elementInfo = zusammenAdaptor - .getElementInfoByName(context, elementContext, vspModel.get().getId(), - ElementType.OrchestrationTemplate.name()); - if (!elementInfo.isPresent()) { - return null; - } - - Optional element = - zusammenAdaptor.getElementByName(context, elementContext, elementInfo.get().getId(), - ElementType.OrchestrationTemplateValidationData.name()); + private static final Logger LOGGER = LoggerFactory.getLogger(OrchestrationTemplateDaoZusammenImpl.class); + private ZusammenAdaptor zusammenAdaptor; - OrchestrationTemplateEntity orchestrationTemplate = new OrchestrationTemplateEntity(); - if (!element.isPresent()) { - return orchestrationTemplate; + public OrchestrationTemplateDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { + this.zusammenAdaptor = zusammenAdaptor; } - orchestrationTemplate - .setFileSuffix(element.get().getInfo().getProperty(InfoPropertyName.FILE_SUFFIX.getVal())); - orchestrationTemplate - .setFileName(element.get().getInfo().getProperty(InfoPropertyName.FILE_NAME.getVal())); - if (!VspZusammenUtil.hasEmptyData(element.get().getData())) { - orchestrationTemplate - .setValidationData(new String(FileUtils.toByteArray(element.get().getData()))); - } - return orchestrationTemplate; - } - - @Override - public OrchestrationTemplateEntity get(String vspId, Version version) { - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(vspId, version.getId()); - - OrchestrationTemplateEntity orchestrationTemplate = new OrchestrationTemplateEntity(); - Optional vspModel = zusammenAdaptor - .getElementInfoByName(context, elementContext, null, ElementType.VspModel.name()); - if (!vspModel.isPresent()) { - return orchestrationTemplate; + @Override + public void registerVersioning(String versionableEntityType) { + // registerVersioning not implemented for OrchestrationTemplateDaoZusammenImpl } - Optional orchestrationTemplateElementOpt = zusammenAdaptor - .getElementByName(context, elementContext, vspModel.get().getId(), - ElementType.OrchestrationTemplate.name()); - - if (! orchestrationTemplateElementOpt.isPresent()) { - return orchestrationTemplate; - } else { - Element orchestrationTemplateElement = orchestrationTemplateElementOpt.get(); - - if (VspZusammenUtil.hasEmptyData(orchestrationTemplateElement.getData())) { - return orchestrationTemplate; - } - - orchestrationTemplate.setContentData( - ByteBuffer.wrap(FileUtils.toByteArray(orchestrationTemplateElement.getData()))); - - Collection subElements = orchestrationTemplateElement.getSubElements(); - if (subElements.isEmpty()) { + @Override + public OrchestrationTemplateEntity getInfo(String vspId, Version version) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(vspId, version.getId()); + Optional vspModel = zusammenAdaptor.getElementInfoByName(context, elementContext, null, ElementType.VspModel.name()); + if (!vspModel.isPresent()) { + return null; + } + Optional elementInfo = zusammenAdaptor + .getElementInfoByName(context, elementContext, vspModel.get().getId(), ElementType.OrchestrationTemplate.name()); + if (!elementInfo.isPresent()) { + return null; + } + Optional element = zusammenAdaptor + .getElementByName(context, elementContext, elementInfo.get().getId(), ElementType.OrchestrationTemplateValidationData.name()); + OrchestrationTemplateEntity orchestrationTemplate = new OrchestrationTemplateEntity(); + if (!element.isPresent()) { + return orchestrationTemplate; + } + orchestrationTemplate.setFileSuffix(element.get().getInfo().getProperty(InfoPropertyName.FILE_SUFFIX.getVal())); + orchestrationTemplate.setFileName(element.get().getInfo().getProperty(InfoPropertyName.FILE_NAME.getVal())); + if (!VspZusammenUtil.hasEmptyData(element.get().getData())) { + orchestrationTemplate.setValidationData(new String(FileUtils.toByteArray(element.get().getData()))); + } return orchestrationTemplate; - } - - for (Element element : subElements) { - Optional subElementOpt = zusammenAdaptor.getElement(context, - elementContext, element.getElementId().toString()); - - subElementOpt.ifPresent(subElement -> { - if (subElement.getInfo().getName().equals(ElementType - .OrchestrationTemplateValidationData.name())) { - - orchestrationTemplate.setFileSuffix(subElement.getInfo() - .getProperty(InfoPropertyName.FILE_SUFFIX.getVal())); - orchestrationTemplate.setFileName(subElement.getInfo() - .getProperty(InfoPropertyName.FILE_NAME.getVal())); + } - if (!VspZusammenUtil.hasEmptyData(subElement.getData())) { - orchestrationTemplate.setValidationData( - new String(FileUtils.toByteArray(subElement.getData()))); + @Override + public OrchestrationTemplateEntity get(String vspId, Version version) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(vspId, version.getId()); + OrchestrationTemplateEntity orchestrationTemplate = new OrchestrationTemplateEntity(); + Optional vspModel = zusammenAdaptor.getElementInfoByName(context, elementContext, null, ElementType.VspModel.name()); + if (!vspModel.isPresent()) { + return orchestrationTemplate; + } + Optional orchestrationTemplateElementOpt = zusammenAdaptor + .getElementByName(context, elementContext, vspModel.get().getId(), ElementType.OrchestrationTemplate.name()); + if (!orchestrationTemplateElementOpt.isPresent()) { + return orchestrationTemplate; + } else { + Element orchestrationTemplateElement = orchestrationTemplateElementOpt.get(); + if (VspZusammenUtil.hasEmptyData(orchestrationTemplateElement.getData())) { + return orchestrationTemplate; } - } else if (subElement.getInfo().getName().equals(ElementType - .OrchestrationTemplateStructure.name())) { - orchestrationTemplate.setFilesDataStructure(new String(FileUtils.toByteArray(subElement - .getData()))); - } - }); - } + orchestrationTemplate.setContentData(ByteBuffer.wrap(FileUtils.toByteArray(orchestrationTemplateElement.getData()))); + Collection subElements = orchestrationTemplateElement.getSubElements(); + if (subElements.isEmpty()) { + return orchestrationTemplate; + } + for (Element element : subElements) { + Optional subElementOpt = zusammenAdaptor.getElement(context, elementContext, element.getElementId().toString()); + subElementOpt.ifPresent(subElement -> { + if (subElement.getInfo().getName().equals(ElementType.OrchestrationTemplateValidationData.name())) { + orchestrationTemplate.setFileSuffix(subElement.getInfo().getProperty(InfoPropertyName.FILE_SUFFIX.getVal())); + orchestrationTemplate.setFileName(subElement.getInfo().getProperty(InfoPropertyName.FILE_NAME.getVal())); + if (!VspZusammenUtil.hasEmptyData(subElement.getData())) { + orchestrationTemplate.setValidationData(new String(FileUtils.toByteArray(subElement.getData()))); + } + } else if (subElement.getInfo().getName().equals(ElementType.OrchestrationTemplateStructure.name())) { + orchestrationTemplate.setFilesDataStructure(new String(FileUtils.toByteArray(subElement.getData()))); + } + }); + } + } + return orchestrationTemplate; } - return orchestrationTemplate; - } - - @Override - public void update(String vspId, Version version, - OrchestrationTemplateEntity orchestrationTemplate) { - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(vspId, version.getId()); - - ZusammenElement validationData = - buildStructuralElement(ElementType.OrchestrationTemplateValidationData, Action.UPDATE); - validationData - .setData(new ByteArrayInputStream(orchestrationTemplate.getValidationData().getBytes())); - validationData.getInfo() - .addProperty(InfoPropertyName.FILE_SUFFIX.getVal(), orchestrationTemplate.getFileSuffix()); - validationData.getInfo() - .addProperty(InfoPropertyName.FILE_NAME.getVal(), orchestrationTemplate.getFileName()); - ZusammenElement orchestrationTemplateStructure = buildStructuralElement(ElementType - .OrchestrationTemplateStructure, Action.UPDATE); - orchestrationTemplateStructure - .setData(new ByteArrayInputStream(orchestrationTemplate.getFilesDataStructure() - .getBytes())); - ZusammenElement orchestrationTemplateElement = - buildStructuralElement(ElementType.OrchestrationTemplate, Action.UPDATE); - orchestrationTemplateElement - .setData(new ByteArrayInputStream(orchestrationTemplate.getContentData().array())); - orchestrationTemplateElement.addSubElement(validationData); - orchestrationTemplateElement.addSubElement(orchestrationTemplateStructure); - ZusammenElement vspModel = buildStructuralElement(ElementType.VspModel, Action.IGNORE); - vspModel.addSubElement(orchestrationTemplateElement); - - zusammenAdaptor.saveElement(context, elementContext, vspModel, "Update Orchestration Template"); - } - @Override - public Optional getOrchestrationTemplateStructure(String vspId, Version version) { - LOGGER.info("Getting orchestration template structure for VendorSoftwareProduct id" + - " " + "-> " + vspId); - - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(vspId, version.getId()); - - Optional vspModel = zusammenAdaptor.getElementInfoByName(context, elementContext, - null, ElementType.VspModel.name()); - if (!vspModel.isPresent()) { - return Optional.empty(); - } - Optional orchestrationTemplateElement = zusammenAdaptor.getElementByName(context, - elementContext, vspModel.get().getId(), ElementType.OrchestrationTemplate.name()); - if (!orchestrationTemplateElement.isPresent()) { - return Optional.empty(); + @Override + public void update(String vspId, Version version, OrchestrationTemplateEntity orchestrationTemplate) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(vspId, version.getId()); + ZusammenElement validationData = buildStructuralElement(ElementType.OrchestrationTemplateValidationData, Action.UPDATE); + validationData.setData(new ByteArrayInputStream(orchestrationTemplate.getValidationData().getBytes())); + validationData.getInfo().addProperty(InfoPropertyName.FILE_SUFFIX.getVal(), orchestrationTemplate.getFileSuffix()); + validationData.getInfo().addProperty(InfoPropertyName.FILE_NAME.getVal(), orchestrationTemplate.getFileName()); + ZusammenElement orchestrationTemplateStructure = buildStructuralElement(ElementType.OrchestrationTemplateStructure, Action.UPDATE); + orchestrationTemplateStructure.setData(new ByteArrayInputStream(orchestrationTemplate.getFilesDataStructure().getBytes())); + ZusammenElement orchestrationTemplateElement = buildStructuralElement(ElementType.OrchestrationTemplate, Action.UPDATE); + orchestrationTemplateElement.setData(new ByteArrayInputStream(orchestrationTemplate.getContentData().array())); + orchestrationTemplateElement.addSubElement(validationData); + orchestrationTemplateElement.addSubElement(orchestrationTemplateStructure); + ZusammenElement vspModel = buildStructuralElement(ElementType.VspModel, Action.IGNORE); + vspModel.addSubElement(orchestrationTemplateElement); + zusammenAdaptor.saveElement(context, elementContext, vspModel, "Update Orchestration Template"); } - Optional orchestrationTemplateStructureElement = zusammenAdaptor - .getElementByName(context, elementContext, - orchestrationTemplateElement.get().getElementId(), - ElementType.OrchestrationTemplateStructure.name()); - if (orchestrationTemplateStructureElement.isPresent() && - !VspZusammenUtil.hasEmptyData(orchestrationTemplateStructureElement.get().getData())) { - return Optional.of(new String( - FileUtils.toByteArray(orchestrationTemplateStructureElement.get().getData()))); + @Override + public Optional getOrchestrationTemplateStructure(String vspId, Version version) { + LOGGER.info("Getting orchestration template structure for VendorSoftwareProduct id" + " " + "-> " + vspId); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(vspId, version.getId()); + Optional vspModel = zusammenAdaptor.getElementInfoByName(context, elementContext, null, ElementType.VspModel.name()); + if (!vspModel.isPresent()) { + return Optional.empty(); + } + Optional orchestrationTemplateElement = zusammenAdaptor + .getElementByName(context, elementContext, vspModel.get().getId(), ElementType.OrchestrationTemplate.name()); + if (!orchestrationTemplateElement.isPresent()) { + return Optional.empty(); + } + Optional orchestrationTemplateStructureElement = zusammenAdaptor + .getElementByName(context, elementContext, orchestrationTemplateElement.get().getElementId(), + ElementType.OrchestrationTemplateStructure.name()); + if (orchestrationTemplateStructureElement.isPresent() && !VspZusammenUtil + .hasEmptyData(orchestrationTemplateStructureElement.get().getData())) { + return Optional.of(new String(FileUtils.toByteArray(orchestrationTemplateStructureElement.get().getData()))); + } + LOGGER.info("Finished getting orchestration template structure for VendorSoftwareProduct " + "id -> " + vspId); + return Optional.empty(); } - LOGGER.info("Finished getting orchestration template structure for VendorSoftwareProduct " + - "id -> " + vspId); - return Optional.empty(); - } + private enum InfoPropertyName { + FILE_SUFFIX("fileSuffix"), FILE_NAME("fileName"); + private String val; - private enum InfoPropertyName { - FILE_SUFFIX("fileSuffix"), - FILE_NAME("fileName"); - - private String val; - - InfoPropertyName(String val){ - this.val=val; - } + InfoPropertyName(String val) { + this.val = val; + } - public String getVal() { - return val; + public 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/dao/impl/zusammen/ProcessDaoZusammenImpl.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/ProcessDaoZusammenImpl.java index 76e14d8606..28bf1d8ddb 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/ProcessDaoZusammenImpl.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/ProcessDaoZusammenImpl.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,9 +17,16 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen; +import static org.openecomp.core.zusammen.api.ZusammenUtil.buildElement; +import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement; +import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext; +import static org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor.ElementToProcessConvertor.ARTIFACT_NAME; +import static org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor.ElementToProcessConvertor.DESCRIPTION; +import static org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor.ElementToProcessConvertor.NAME; +import static org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor.ElementToProcessConvertor.PROCESS_TYPE; + import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo; import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement; @@ -28,6 +35,12 @@ import com.amdocs.zusammen.datatypes.SessionContext; import com.amdocs.zusammen.datatypes.item.Action; import com.amdocs.zusammen.datatypes.item.ElementContext; import com.amdocs.zusammen.datatypes.item.Info; +import java.io.ByteArrayInputStream; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Objects; +import java.util.Optional; +import java.util.stream.Collectors; import org.openecomp.core.zusammen.api.ZusammenAdaptor; import org.openecomp.sdc.datatypes.model.ElementType; import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessDao; @@ -36,238 +49,176 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity; import org.openecomp.sdc.versioning.dao.types.Version; import org.openecomp.types.ElementPropertyName; -import java.io.ByteArrayInputStream; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Objects; -import java.util.Optional; -import java.util.stream.Collectors; - -import static org.openecomp.core.zusammen.api.ZusammenUtil.*; -import static org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor.ElementToProcessConvertor.*; - /** * @author Avrahamg. * @since March 23, 2017 */ public class ProcessDaoZusammenImpl implements ProcessDao { - private ZusammenAdaptor zusammenAdaptor; - - public ProcessDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { - this.zusammenAdaptor = zusammenAdaptor; - } - - @Override - public void registerVersioning(String versionableEntityType) { - // registerVersioning not implemented for ProcessDaoZusammenImpl - } + private ZusammenAdaptor zusammenAdaptor; - @Override - public void create(ProcessEntity processEntity) { - ZusammenElement processElement = buildProcessElement(processEntity, Action.CREATE); - - ZusammenElement processesElement = - buildStructuralElement(ElementType.Processes, Action.IGNORE); - ZusammenElement aggregatedElement = VspZusammenUtil.aggregateElements(processesElement, - processElement); - ZusammenElement componentElement; - if (processEntity.getComponentId() != null) { - componentElement = buildElement(new Id(processEntity.getComponentId()), Action.IGNORE); - aggregatedElement = - VspZusammenUtil.aggregateElements(componentElement, aggregatedElement); + public ProcessDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { + this.zusammenAdaptor = zusammenAdaptor; } - SessionContext context = createSessionContext(); - ElementContext elementContext = - new ElementContext(processEntity.getVspId(), processEntity.getVersion().getId()); - - Element savedElement = - zusammenAdaptor.saveElement(context, elementContext, aggregatedElement, "Create process"); - processEntity - .setId(processEntity.getComponentId() == null - ? savedElement.getSubElements().iterator().next().getElementId().getValue() - : savedElement.getSubElements().iterator().next().getSubElements() - .iterator().next().getElementId().getValue()); - } - - @Override - public ProcessEntity get(ProcessEntity processEntity) { - SessionContext context = createSessionContext(); - ElementContext elementContext = - new ElementContext(processEntity.getVspId(), processEntity.getVersion().getId()); - - return zusammenAdaptor.getElementInfo(context, elementContext, new Id(processEntity.getId())) - .map(elementInfo -> convertToProcessEntity(elementInfo, new ElementToProcessConvertor(), - processEntity)) - .orElse(null); - } - - @Override - public void update(ProcessEntity processEntity) { - ProcessEntity retrieved = getArtifact(processEntity); - if (retrieved != null && retrieved.getArtifact() != null) { - processEntity.setArtifactName(retrieved.getArtifactName()); - processEntity.setArtifact(retrieved.getArtifact()); + @Override + public void registerVersioning(String versionableEntityType) { + // registerVersioning not implemented for ProcessDaoZusammenImpl } - update(processEntity, "Update process"); - } - - @Override - public void delete(ProcessEntity processEntity) { - ZusammenElement processElement = buildElement(new Id(processEntity.getId()), Action.DELETE); - - SessionContext context = createSessionContext(); - ElementContext elementContext = - new ElementContext(processEntity.getVspId(), processEntity.getVersion().getId()); - - zusammenAdaptor.saveElement(context, elementContext, processElement, - String.format("Delete process with id %s", processEntity.getId())); - } - - @Override - public void deleteAll(ProcessEntity processEntity) { - SessionContext context = createSessionContext(); - ElementContext elementContext = - new ElementContext(processEntity.getVspId(), processEntity.getVersion().getId()); - - Optional optionalElement = zusammenAdaptor.getElementByName(context, - elementContext, new Id(processEntity.getComponentId()), ElementType.Processes.name()); - - if (optionalElement.isPresent()) { - Element processesElement = optionalElement.get(); - Collection processes = processesElement.getSubElements(); - - processes.forEach(process -> { - ZusammenElement processZusammenElement = - buildElement(process.getElementId(), Action.DELETE); - zusammenAdaptor.saveElement(context, elementContext, processZusammenElement, - "Delete Process with id " + process.getElementId()); - }); + @Override + public void create(ProcessEntity processEntity) { + ZusammenElement processElement = buildProcessElement(processEntity, Action.CREATE); + ZusammenElement processesElement = buildStructuralElement(ElementType.Processes, Action.IGNORE); + ZusammenElement aggregatedElement = VspZusammenUtil.aggregateElements(processesElement, processElement); + ZusammenElement componentElement; + if (processEntity.getComponentId() != null) { + componentElement = buildElement(new Id(processEntity.getComponentId()), Action.IGNORE); + aggregatedElement = VspZusammenUtil.aggregateElements(componentElement, aggregatedElement); + } + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(processEntity.getVspId(), processEntity.getVersion().getId()); + Element savedElement = zusammenAdaptor.saveElement(context, elementContext, aggregatedElement, "Create process"); + processEntity.setId(processEntity.getComponentId() == null ? savedElement.getSubElements().iterator().next().getElementId().getValue() + : savedElement.getSubElements().iterator().next().getSubElements().iterator().next().getElementId().getValue()); } - } - - @Override - public void deleteVspAll(String vspId, Version version) { - SessionContext context = createSessionContext(); - ElementContext elementContext = - new ElementContext(vspId, version.getId()); - - Optional optionalElement = zusammenAdaptor.getElementByName(context, - elementContext, null, ElementType.Processes.name()); - if (optionalElement.isPresent()) { - Element processesElement = optionalElement.get(); - Collection processes = processesElement.getSubElements(); - - processes.forEach(process -> { - ZusammenElement processZusammenElement = - buildElement(process.getElementId(), Action.DELETE); - zusammenAdaptor.saveElement(context, elementContext, processZusammenElement, - "Delete Process with id " + process.getElementId()); - }); + @Override + public ProcessEntity get(ProcessEntity processEntity) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(processEntity.getVspId(), processEntity.getVersion().getId()); + return zusammenAdaptor.getElementInfo(context, elementContext, new Id(processEntity.getId())) + .map(elementInfo -> convertToProcessEntity(elementInfo, new ElementToProcessConvertor(), processEntity)).orElse(null); } - } - - @Override - public ProcessEntity getArtifact(ProcessEntity processEntity) { - SessionContext context = createSessionContext(); - ElementContext elementContext = - new ElementContext(processEntity.getVspId(), processEntity.getVersion().getId()); - - return zusammenAdaptor.getElement(context, elementContext, processEntity.getId()) - .map(element -> { - ProcessEntity process = new ElementToProcessConvertor().convert(element); - process.setVspId(processEntity.getVspId()); - process.setVersion(processEntity.getVersion()); - process.setComponentId(processEntity.getComponentId()); - return process; - }) - .orElse(null); - } - @Override - public void uploadArtifact(ProcessEntity processEntity) { - ProcessEntity retrieved = get(processEntity); - if (retrieved != null) { - retrieved.setArtifactName(processEntity.getArtifactName()); - retrieved.setArtifact(processEntity.getArtifact()); - - update(retrieved, "Upload process artifact"); + @Override + public void update(ProcessEntity processEntity) { + ProcessEntity retrieved = getArtifact(processEntity); + if (retrieved != null && retrieved.getArtifact() != null) { + processEntity.setArtifactName(retrieved.getArtifactName()); + processEntity.setArtifact(retrieved.getArtifact()); + } + update(processEntity, "Update process"); } - } - - @Override - public void deleteArtifact(ProcessEntity processEntity) { - ProcessEntity retrieved = get(processEntity); - if (retrieved != null) { - retrieved.setArtifactName(null); - retrieved.setArtifact(null); - update(retrieved, "Delete process artifact"); + @Override + public void delete(ProcessEntity processEntity) { + ZusammenElement processElement = buildElement(new Id(processEntity.getId()), Action.DELETE); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(processEntity.getVspId(), processEntity.getVersion().getId()); + zusammenAdaptor.saveElement(context, elementContext, processElement, String.format("Delete process with id %s", processEntity.getId())); } - } - - @Override - public Collection list(ProcessEntity processEntity) { - SessionContext context = createSessionContext(); - ElementContext elementContext = - new ElementContext(processEntity.getVspId(), processEntity.getVersion().getId()); - Optional processesOptional = - zusammenAdaptor.getElementInfoByName(context, elementContext, - extractParentElementId(processEntity), ElementType.Processes.name()); - if (!processesOptional.isPresent()) { - return new ArrayList<>(); + @Override + public void deleteAll(ProcessEntity processEntity) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(processEntity.getVspId(), processEntity.getVersion().getId()); + Optional optionalElement = zusammenAdaptor + .getElementByName(context, elementContext, new Id(processEntity.getComponentId()), ElementType.Processes.name()); + if (optionalElement.isPresent()) { + Element processesElement = optionalElement.get(); + Collection processes = processesElement.getSubElements(); + processes.forEach(process -> { + ZusammenElement processZusammenElement = buildElement(process.getElementId(), Action.DELETE); + zusammenAdaptor.saveElement(context, elementContext, processZusammenElement, "Delete Process with id " + process.getElementId()); + }); + } } - ElementToProcessConvertor convertor = new ElementToProcessConvertor(); - return zusammenAdaptor.listElements(context, elementContext, processesOptional.get().getId()) - .stream() - .map(elementInfo -> convertToProcessEntity(elementInfo, convertor, processEntity)) - .collect(Collectors.toList()); - } - private ProcessEntity convertToProcessEntity(ElementInfo elementInfo, - ElementToProcessConvertor convertor, - ProcessEntity inputProcess) { - ProcessEntity process = convertor.convert(elementInfo); - process.setVspId(inputProcess.getVspId()); - process.setVersion(inputProcess.getVersion()); - process.setComponentId(inputProcess.getComponentId()); - return process; - } + @Override + public void deleteVspAll(String vspId, Version version) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(vspId, version.getId()); + Optional optionalElement = zusammenAdaptor.getElementByName(context, elementContext, null, ElementType.Processes.name()); + if (optionalElement.isPresent()) { + Element processesElement = optionalElement.get(); + Collection processes = processesElement.getSubElements(); + processes.forEach(process -> { + ZusammenElement processZusammenElement = buildElement(process.getElementId(), Action.DELETE); + zusammenAdaptor.saveElement(context, elementContext, processZusammenElement, "Delete Process with id " + process.getElementId()); + }); + } + } - private void update(ProcessEntity processEntity, String message) { - ZusammenElement processElement = buildProcessElement(processEntity, Action.UPDATE); + @Override + public ProcessEntity getArtifact(ProcessEntity processEntity) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(processEntity.getVspId(), processEntity.getVersion().getId()); + return zusammenAdaptor.getElement(context, elementContext, processEntity.getId()).map(element -> { + ProcessEntity process = new ElementToProcessConvertor().convert(element); + process.setVspId(processEntity.getVspId()); + process.setVersion(processEntity.getVersion()); + process.setComponentId(processEntity.getComponentId()); + return process; + }).orElse(null); + } - SessionContext context = createSessionContext(); - ElementContext elementContext = - new ElementContext(processEntity.getVspId(), processEntity.getVersion().getId()); + @Override + public void uploadArtifact(ProcessEntity processEntity) { + ProcessEntity retrieved = get(processEntity); + if (retrieved != null) { + retrieved.setArtifactName(processEntity.getArtifactName()); + retrieved.setArtifact(processEntity.getArtifact()); + update(retrieved, "Upload process artifact"); + } + } - zusammenAdaptor.saveElement(context, elementContext, processElement, message); - } + @Override + public void deleteArtifact(ProcessEntity processEntity) { + ProcessEntity retrieved = get(processEntity); + if (retrieved != null) { + retrieved.setArtifactName(null); + retrieved.setArtifact(null); + update(retrieved, "Delete process artifact"); + } + } - private Id extractParentElementId(ProcessEntity processEntity) { - return processEntity.getComponentId() == null ? null : new Id(processEntity.getComponentId()); - } + @Override + public Collection list(ProcessEntity processEntity) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(processEntity.getVspId(), processEntity.getVersion().getId()); + Optional processesOptional = zusammenAdaptor + .getElementInfoByName(context, elementContext, extractParentElementId(processEntity), ElementType.Processes.name()); + if (!processesOptional.isPresent()) { + return new ArrayList<>(); + } + ElementToProcessConvertor convertor = new ElementToProcessConvertor(); + return zusammenAdaptor.listElements(context, elementContext, processesOptional.get().getId()).stream() + .map(elementInfo -> convertToProcessEntity(elementInfo, convertor, processEntity)).collect(Collectors.toList()); + } - private ZusammenElement buildProcessElement(ProcessEntity process, Action action) { + private ProcessEntity convertToProcessEntity(ElementInfo elementInfo, ElementToProcessConvertor convertor, ProcessEntity inputProcess) { + ProcessEntity process = convertor.convert(elementInfo); + process.setVspId(inputProcess.getVspId()); + process.setVersion(inputProcess.getVersion()); + process.setComponentId(inputProcess.getComponentId()); + return process; + } - Info info = new Info(); - info.setName(process.getName()); - info.addProperty(NAME, process.getName()); - info.addProperty(ElementPropertyName.elementType.name(), ElementType.Process); - info.addProperty(ARTIFACT_NAME, process.getArtifactName()); - info.addProperty(DESCRIPTION, process.getDescription()); - info.addProperty(PROCESS_TYPE, process.getType() != null ? process.getType().name() : null); + private void update(ProcessEntity processEntity, String message) { + ZusammenElement processElement = buildProcessElement(processEntity, Action.UPDATE); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(processEntity.getVspId(), processEntity.getVersion().getId()); + zusammenAdaptor.saveElement(context, elementContext, processElement, message); + } - ZusammenElement processElement = buildElement(new Id(process.getId()), action); - processElement.setInfo(info); - if (Objects.nonNull(process.getArtifact())) { - processElement.setData(new ByteArrayInputStream(process.getArtifact().array())); + private Id extractParentElementId(ProcessEntity processEntity) { + return processEntity.getComponentId() == null ? null : new Id(processEntity.getComponentId()); } - return processElement; - } + private ZusammenElement buildProcessElement(ProcessEntity process, Action action) { + Info info = new Info(); + info.setName(process.getName()); + info.addProperty(NAME, process.getName()); + info.addProperty(ElementPropertyName.elementType.name(), ElementType.Process); + info.addProperty(ARTIFACT_NAME, process.getArtifactName()); + info.addProperty(DESCRIPTION, process.getDescription()); + info.addProperty(PROCESS_TYPE, process.getType() != null ? process.getType().name() : null); + ZusammenElement processElement = buildElement(new Id(process.getId()), action); + processElement.setInfo(info); + if (Objects.nonNull(process.getArtifact())) { + processElement.setData(new ByteArrayInputStream(process.getArtifact().array())); + } + return processElement; + } } 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/VendorSoftwareProductInfoDaoZusammenImpl.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/VendorSoftwareProductInfoDaoZusammenImpl.java index de42344788..9655434e74 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/VendorSoftwareProductInfoDaoZusammenImpl.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/VendorSoftwareProductInfoDaoZusammenImpl.java @@ -15,11 +15,17 @@ */ package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen; +import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement; +import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext; + import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement; import com.amdocs.zusammen.datatypes.SessionContext; import com.amdocs.zusammen.datatypes.item.Action; import com.amdocs.zusammen.datatypes.item.ElementContext; import com.amdocs.zusammen.datatypes.item.Info; +import java.io.ByteArrayInputStream; +import java.util.Collection; +import java.util.stream.Collectors; import org.openecomp.core.zusammen.api.ZusammenAdaptor; import org.openecomp.sdc.datatypes.model.ElementType; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; @@ -33,256 +39,197 @@ import org.openecomp.sdc.versioning.dao.types.Version; import org.openecomp.sdc.versioning.types.VersionableEntityMetadata; import org.openecomp.sdc.versioning.types.VersionableEntityStoreType; -import java.io.ByteArrayInputStream; -import java.util.Collection; -import java.util.stream.Collectors; - -import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement; -import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext; - public class VendorSoftwareProductInfoDaoZusammenImpl implements VendorSoftwareProductInfoDao { - private static final String EMPTY_DATA = "{}"; - - private ZusammenAdaptor zusammenAdaptor; - - public VendorSoftwareProductInfoDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { - this.zusammenAdaptor = zusammenAdaptor; - } - - @Override - public void registerVersioning(String versionableEntityType) { - VersionableEntityMetadata metadata = - new VersionableEntityMetadata(VersionableEntityStoreType.Zusammen, "VendorSoftwareProduct", - null, null); - - ActionVersioningManagerFactory.getInstance().createInterface() - .register(versionableEntityType, metadata); - } - - @Override - public Collection list(VspDetails entity) { - return zusammenAdaptor.listItems(createSessionContext()).stream() - .filter(item -> "VendorSoftwareProduct".equals(item.getInfo().getProperty("item_type"))) - .map(new ElementToVSPGeneralConvertor()::convert) - .collect(Collectors.toList()); - } - - @Override - public void create(VspDetails vspDetails) { - ZusammenElement generalElement = mapVspDetailsToZusammenElement(vspDetails, Action.CREATE); - - SessionContext context = createSessionContext(); - ElementContext elementContext = - new ElementContext(vspDetails.getId(), vspDetails.getVersion().getId()); - zusammenAdaptor.saveElement(context, elementContext, generalElement, - "Create VSP General Info Element"); - - createVspStructure(context, elementContext); - } - - private void createVspStructure(SessionContext context, ElementContext elementContext) { - createOrchestrationTemplateCandidateStructure(context, elementContext); - createVspModelStructure(context, elementContext); - - zusammenAdaptor.saveElement(context, elementContext, - buildStructuralElement(ElementType.DeploymentFlavors, Action.CREATE), - "Create VSP Deployment Flavors Element"); - - zusammenAdaptor.saveElement(context, elementContext, - buildStructuralElement(ElementType.Processes, Action.CREATE), - "Create VSP Processes Element"); - } - - private void createOrchestrationTemplateCandidateStructure(SessionContext context, - ElementContext elementContext) { - ByteArrayInputStream emptyData = new ByteArrayInputStream(EMPTY_DATA.getBytes()); - ZusammenElement candidateContentElement = - buildStructuralElement(ElementType.OrchestrationTemplateCandidateContent, Action.CREATE); - candidateContentElement.setData(emptyData); - ZusammenElement validationData = buildStructuralElement(ElementType - .OrchestrationTemplateCandidateValidationData, Action.CREATE); - ZusammenElement candidateElement = - buildStructuralElement(ElementType.OrchestrationTemplateCandidate, Action.CREATE); - candidateElement.setData(emptyData); - candidateElement.addSubElement(candidateContentElement); - candidateElement.addSubElement(validationData); - zusammenAdaptor.saveElement(context, elementContext, candidateElement, - "Create Orchestration Template Candidate Elements"); - } + private static final String EMPTY_DATA = "{}"; + private ZusammenAdaptor zusammenAdaptor; - private void createVspModelStructure(SessionContext context, ElementContext elementContext) { - ZusammenElement vspModel = buildStructuralElement(ElementType.VspModel, Action.CREATE); - vspModel.addSubElement(buildOrchestrationTemplateStructure()); - vspModel.addSubElement(buildStructuralElement(ElementType.Networks, Action.CREATE)); - vspModel.addSubElement(buildStructuralElement(ElementType.Components, Action.CREATE)); - vspModel - .addSubElement(buildStructuralElement(ElementType.ComponentDependencies, Action.CREATE)); - - ZusammenElement templates = buildStructuralElement(ElementType.Templates, Action.CREATE); - ZusammenElement artifacts = buildStructuralElement(ElementType.Artifacts, Action.CREATE); - vspModel.addSubElement( - buildServiceModelStructure(ElementType.ServiceModel, templates, artifacts)); - vspModel.addSubElement( - buildServiceModelStructure(ElementType.EnrichedServiceModel, templates, artifacts)); - - zusammenAdaptor.saveElement(context, elementContext, vspModel, "Create VSP Model Elements"); - } - - private ZusammenElement buildOrchestrationTemplateStructure() { - ByteArrayInputStream emptyData = new ByteArrayInputStream(EMPTY_DATA.getBytes()); - - ZusammenElement validationData = - buildStructuralElement(ElementType.OrchestrationTemplateValidationData, Action.CREATE); - validationData.setData(emptyData); - - ZusammenElement orchestrationTemplateStructure = buildStructuralElement(ElementType - .OrchestrationTemplateStructure, Action.CREATE); - validationData.setData(emptyData); - - ZusammenElement orchestrationTemplate = - buildStructuralElement(ElementType.OrchestrationTemplate, Action.CREATE); - orchestrationTemplate.setData(emptyData); - orchestrationTemplate.addSubElement(validationData); - orchestrationTemplate.addSubElement(orchestrationTemplateStructure); - - return orchestrationTemplate; - } - - private ZusammenElement buildServiceModelStructure(ElementType serviceModelElementType, - ZusammenElement templates, - ZusammenElement artifacts) { - ZusammenElement serviceModel = buildStructuralElement(serviceModelElementType, Action.CREATE); - serviceModel.addSubElement(templates); - serviceModel.addSubElement(artifacts); - return serviceModel; - } + public VendorSoftwareProductInfoDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { + this.zusammenAdaptor = zusammenAdaptor; + } - @Override - public void update(VspDetails vspDetails) { - ZusammenElement generalElement = mapVspDetailsToZusammenElement(vspDetails, Action.UPDATE); + @Override + public void registerVersioning(String versionableEntityType) { + VersionableEntityMetadata metadata = new VersionableEntityMetadata(VersionableEntityStoreType.Zusammen, "VendorSoftwareProduct", null, null); + ActionVersioningManagerFactory.getInstance().createInterface().register(versionableEntityType, metadata); + } - SessionContext context = createSessionContext(); - zusammenAdaptor.saveElement(context, - new ElementContext(vspDetails.getId(), vspDetails.getVersion().getId()), generalElement, - "Update VSP General Info Element"); - } + @Override + public Collection list(VspDetails entity) { + return zusammenAdaptor.listItems(createSessionContext()).stream() + .filter(item -> "VendorSoftwareProduct".equals(item.getInfo().getProperty("item_type"))).map(new ElementToVSPGeneralConvertor()::convert) + .collect(Collectors.toList()); + } - @Override - public VspDetails get(VspDetails vspDetails) { - SessionContext context = createSessionContext(); - ElementContext elementContext = - new ElementContext(vspDetails.getId(), vspDetails.getVersion().getId()); - return zusammenAdaptor.getElementInfoByName(context, elementContext, null, - ElementType.VendorSoftwareProduct.name()) - .map(new ElementToVSPGeneralConvertor()::convert) - .map(vsp -> { - vsp.setId(vspDetails.getId()); - vsp.setVersion(vspDetails.getVersion()); - return vsp; - }) - .orElse(null); - } + @Override + public void create(VspDetails vspDetails) { + ZusammenElement generalElement = mapVspDetailsToZusammenElement(vspDetails, Action.CREATE); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(vspDetails.getId(), vspDetails.getVersion().getId()); + zusammenAdaptor.saveElement(context, elementContext, generalElement, "Create VSP General Info Element"); + createVspStructure(context, elementContext); + } - @Override - public void delete(VspDetails vspDetails) { - SessionContext context = createSessionContext(); - ElementContext elementContext = - new ElementContext(vspDetails.getId(), vspDetails.getVersion().getId()); + private void createVspStructure(SessionContext context, ElementContext elementContext) { + createOrchestrationTemplateCandidateStructure(context, elementContext); + createVspModelStructure(context, elementContext); + zusammenAdaptor.saveElement(context, elementContext, buildStructuralElement(ElementType.DeploymentFlavors, Action.CREATE), + "Create VSP Deployment Flavors Element"); + zusammenAdaptor + .saveElement(context, elementContext, buildStructuralElement(ElementType.Processes, Action.CREATE), "Create VSP Processes Element"); + } - zusammenAdaptor.saveElement(context, elementContext, - buildStructuralElement(ElementType.VspModel, Action.DELETE), - "Delete VSP Model Elements"); + private void createOrchestrationTemplateCandidateStructure(SessionContext context, ElementContext elementContext) { + ByteArrayInputStream emptyData = new ByteArrayInputStream(EMPTY_DATA.getBytes()); + ZusammenElement candidateContentElement = buildStructuralElement(ElementType.OrchestrationTemplateCandidateContent, Action.CREATE); + candidateContentElement.setData(emptyData); + ZusammenElement validationData = buildStructuralElement(ElementType.OrchestrationTemplateCandidateValidationData, Action.CREATE); + ZusammenElement candidateElement = buildStructuralElement(ElementType.OrchestrationTemplateCandidate, Action.CREATE); + candidateElement.setData(emptyData); + candidateElement.addSubElement(candidateContentElement); + candidateElement.addSubElement(validationData); + zusammenAdaptor.saveElement(context, elementContext, candidateElement, "Create Orchestration Template Candidate Elements"); + } - createVspModelStructure(context, elementContext); - } + private void createVspModelStructure(SessionContext context, ElementContext elementContext) { + ZusammenElement vspModel = buildStructuralElement(ElementType.VspModel, Action.CREATE); + vspModel.addSubElement(buildOrchestrationTemplateStructure()); + vspModel.addSubElement(buildStructuralElement(ElementType.Networks, Action.CREATE)); + vspModel.addSubElement(buildStructuralElement(ElementType.Components, Action.CREATE)); + vspModel.addSubElement(buildStructuralElement(ElementType.ComponentDependencies, Action.CREATE)); + ZusammenElement templates = buildStructuralElement(ElementType.Templates, Action.CREATE); + ZusammenElement artifacts = buildStructuralElement(ElementType.Artifacts, Action.CREATE); + vspModel.addSubElement(buildServiceModelStructure(ElementType.ServiceModel, templates, artifacts)); + vspModel.addSubElement(buildServiceModelStructure(ElementType.EnrichedServiceModel, templates, artifacts)); + zusammenAdaptor.saveElement(context, elementContext, vspModel, "Create VSP Model Elements"); + } - @Override - public void updateQuestionnaireData(String vspId, Version version, String questionnaireData) { - SessionContext context = createSessionContext(); + private ZusammenElement buildOrchestrationTemplateStructure() { + ByteArrayInputStream emptyData = new ByteArrayInputStream(EMPTY_DATA.getBytes()); + ZusammenElement validationData = buildStructuralElement(ElementType.OrchestrationTemplateValidationData, Action.CREATE); + validationData.setData(emptyData); + ZusammenElement orchestrationTemplateStructure = buildStructuralElement(ElementType.OrchestrationTemplateStructure, Action.CREATE); + validationData.setData(emptyData); + ZusammenElement orchestrationTemplate = buildStructuralElement(ElementType.OrchestrationTemplate, Action.CREATE); + orchestrationTemplate.setData(emptyData); + orchestrationTemplate.addSubElement(validationData); + orchestrationTemplate.addSubElement(orchestrationTemplateStructure); + return orchestrationTemplate; + } - ZusammenElement questionnaireElement = mapQuestionnaireToZusammenElement(questionnaireData); - zusammenAdaptor.saveElement(context, new ElementContext(vspId, version.getId()), - questionnaireElement, "Update VSP Questionnaire"); - } + private ZusammenElement buildServiceModelStructure(ElementType serviceModelElementType, ZusammenElement templates, ZusammenElement artifacts) { + ZusammenElement serviceModel = buildStructuralElement(serviceModelElementType, Action.CREATE); + serviceModel.addSubElement(templates); + serviceModel.addSubElement(artifacts); + return serviceModel; + } - @Override - public VspQuestionnaireEntity getQuestionnaire(String vspId, Version version) { - SessionContext context = createSessionContext(); - VspQuestionnaireEntity entity = new ElementToVSPQuestionnaireConvertor().convert(zusammenAdaptor - .getElementByName(context, new ElementContext(vspId, version.getId()), null, - ElementType.VSPQuestionnaire.name()) - .orElse(null)); - entity.setId(vspId); - entity.setVersion(version); - return entity; - } + @Override + public void update(VspDetails vspDetails) { + ZusammenElement generalElement = mapVspDetailsToZusammenElement(vspDetails, Action.UPDATE); + SessionContext context = createSessionContext(); + zusammenAdaptor.saveElement(context, new ElementContext(vspDetails.getId(), vspDetails.getVersion().getId()), generalElement, + "Update VSP General Info Element"); + } - @Override - public boolean isManual(String vspId, Version version) { - final VspDetails vspDetails = get(new VspDetails(vspId, version)); - return vspDetails != null && - OnboardingMethod.Manual.name().equals(vspDetails.getOnboardingMethod()); - } + @Override + public VspDetails get(VspDetails vspDetails) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(vspDetails.getId(), vspDetails.getVersion().getId()); + return zusammenAdaptor.getElementInfoByName(context, elementContext, null, ElementType.VendorSoftwareProduct.name()) + .map(new ElementToVSPGeneralConvertor()::convert).map(vsp -> { + vsp.setId(vspDetails.getId()); + vsp.setVersion(vspDetails.getVersion()); + return vsp; + }).orElse(null); + } - private ZusammenElement mapVspDetailsToZusammenElement(VspDetails vspDetails, Action action) { - ZusammenElement generalElement = - buildStructuralElement(ElementType.VendorSoftwareProduct, action); - addVspDetailsToInfo(generalElement.getInfo(), vspDetails); - return generalElement; - } + @Override + public void delete(VspDetails vspDetails) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(vspDetails.getId(), vspDetails.getVersion().getId()); + zusammenAdaptor + .saveElement(context, elementContext, buildStructuralElement(ElementType.VspModel, Action.DELETE), "Delete VSP Model Elements"); + createVspModelStructure(context, elementContext); + } - private ZusammenElement mapQuestionnaireToZusammenElement(String questionnaireData) { - ZusammenElement questionnaireElement = - buildStructuralElement(ElementType.VSPQuestionnaire, Action.UPDATE); - questionnaireElement.setData(new ByteArrayInputStream(questionnaireData.getBytes())); - return questionnaireElement; - } + @Override + public void updateQuestionnaireData(String vspId, Version version, String questionnaireData) { + SessionContext context = createSessionContext(); + ZusammenElement questionnaireElement = mapQuestionnaireToZusammenElement(questionnaireData); + zusammenAdaptor.saveElement(context, new ElementContext(vspId, version.getId()), questionnaireElement, "Update VSP Questionnaire"); + } - private void addVspDetailsToInfo(Info info, VspDetails vspDetails) { - info.addProperty(InfoPropertyName.NAME.getValue(), vspDetails.getName()); - info.addProperty(InfoPropertyName.DESCRIPTION.getValue(), vspDetails.getDescription()); - info.addProperty(InfoPropertyName.ICON.getValue(), vspDetails.getIcon()); - info.addProperty(InfoPropertyName.CATEGORY.getValue(), vspDetails.getCategory()); - info.addProperty(InfoPropertyName.SUB_CATEGORY.getValue(), vspDetails.getSubCategory()); - info.addProperty(InfoPropertyName.VENDOR_ID.getValue(), vspDetails.getVendorId()); - info.addProperty(InfoPropertyName.VENDOR_NAME.getValue(), vspDetails.getVendorName()); - if (vspDetails.getVlmVersion() != null) { - info.addProperty(InfoPropertyName.VENDOR_VERSION.getValue(), - vspDetails.getVlmVersion().getId()); + @Override + public VspQuestionnaireEntity getQuestionnaire(String vspId, Version version) { + SessionContext context = createSessionContext(); + VspQuestionnaireEntity entity = new ElementToVSPQuestionnaireConvertor().convert( + zusammenAdaptor.getElementByName(context, new ElementContext(vspId, version.getId()), null, ElementType.VSPQuestionnaire.name()) + .orElse(null)); + entity.setId(vspId); + entity.setVersion(version); + return entity; } - info.addProperty(InfoPropertyName.LICENSE_TYPE.getValue(), - vspDetails.getLicenseType()); - info.addProperty(InfoPropertyName.LICENSE_AGREEMENT.getValue(), - vspDetails.getLicenseAgreement()); - info.addProperty(InfoPropertyName.FEATURE_GROUPS.getValue(), vspDetails.getFeatureGroups()); - info.addProperty(InfoPropertyName.ON_BOARDING_METHOD.getValue(), - vspDetails.getOnboardingMethod()); - } - public enum InfoPropertyName { - NAME("name"), - DESCRIPTION("description"), - ICON("icon"), - CATEGORY("category"), - SUB_CATEGORY("subCategory"), - VENDOR_ID("vendorId"), - VENDOR_NAME("vendorName"), - VENDOR_VERSION("vendorVersion"), - LICENSE_TYPE("licenseType"), - LICENSE_AGREEMENT("licenseAgreement"), - FEATURE_GROUPS("featureGroups"), - ON_BOARDING_METHOD("onboardingMethod"); + @Override + public boolean isManual(String vspId, Version version) { + final VspDetails vspDetails = get(new VspDetails(vspId, version)); + return vspDetails != null && OnboardingMethod.Manual.name().equals(vspDetails.getOnboardingMethod()); + } - private String value; + private ZusammenElement mapVspDetailsToZusammenElement(VspDetails vspDetails, Action action) { + ZusammenElement generalElement = buildStructuralElement(ElementType.VendorSoftwareProduct, action); + addVspDetailsToInfo(generalElement.getInfo(), vspDetails); + return generalElement; + } - InfoPropertyName(String value) { - this.value = value; + private ZusammenElement mapQuestionnaireToZusammenElement(String questionnaireData) { + ZusammenElement questionnaireElement = buildStructuralElement(ElementType.VSPQuestionnaire, Action.UPDATE); + questionnaireElement.setData(new ByteArrayInputStream(questionnaireData.getBytes())); + return questionnaireElement; } - public String getValue() { - return value; + private void addVspDetailsToInfo(Info info, VspDetails vspDetails) { + info.addProperty(InfoPropertyName.NAME.getValue(), vspDetails.getName()); + info.addProperty(InfoPropertyName.DESCRIPTION.getValue(), vspDetails.getDescription()); + info.addProperty(InfoPropertyName.ICON.getValue(), vspDetails.getIcon()); + info.addProperty(InfoPropertyName.CATEGORY.getValue(), vspDetails.getCategory()); + info.addProperty(InfoPropertyName.SUB_CATEGORY.getValue(), vspDetails.getSubCategory()); + info.addProperty(InfoPropertyName.VENDOR_ID.getValue(), vspDetails.getVendorId()); + info.addProperty(InfoPropertyName.VENDOR_NAME.getValue(), vspDetails.getVendorName()); + if (vspDetails.getVlmVersion() != null) { + info.addProperty(InfoPropertyName.VENDOR_VERSION.getValue(), vspDetails.getVlmVersion().getId()); + } + info.addProperty(InfoPropertyName.LICENSE_TYPE.getValue(), vspDetails.getLicenseType()); + info.addProperty(InfoPropertyName.LICENSE_AGREEMENT.getValue(), vspDetails.getLicenseAgreement()); + info.addProperty(InfoPropertyName.FEATURE_GROUPS.getValue(), vspDetails.getFeatureGroups()); + info.addProperty(InfoPropertyName.ON_BOARDING_METHOD.getValue(), vspDetails.getOnboardingMethod()); } - } + public enum InfoPropertyName { + // @formatter:off + NAME("name"), + DESCRIPTION("description"), + ICON("icon"), + CATEGORY("category"), + SUB_CATEGORY("subCategory"), + VENDOR_ID("vendorId"), + VENDOR_NAME("vendorName"), + VENDOR_VERSION("vendorVersion"), + LICENSE_TYPE("licenseType"), + LICENSE_AGREEMENT("licenseAgreement"), + FEATURE_GROUPS("featureGroups"), + ON_BOARDING_METHOD("onboardingMethod"); + // @formatter:on + + private String value; + + InfoPropertyName(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + } } 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/VspZusammenUtil.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/VspZusammenUtil.java index d78e48bff8..c0b1be61bf 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/VspZusammenUtil.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/VspZusammenUtil.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,49 +17,47 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen; import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement; -import org.apache.commons.io.IOUtils; - import java.io.IOException; import java.io.InputStream; import java.util.Arrays; import java.util.Objects; +import org.apache.commons.io.IOUtils; class VspZusammenUtil { - private VspZusammenUtil(){} + private VspZusammenUtil() { + } - static ZusammenElement aggregateElements(ZusammenElement... elements) { - ZusammenElement head = null; - ZusammenElement father = null; - for (ZusammenElement element : elements) { - if (Objects.isNull(head)) { - head = father = element; - } else { - if (father != null) { - father.getSubElements().add(element); - father = element; + static ZusammenElement aggregateElements(ZusammenElement... elements) { + ZusammenElement head = null; + ZusammenElement father = null; + for (ZusammenElement element : elements) { + if (Objects.isNull(head)) { + head = father = element; + } else { + if (father != null) { + father.getSubElements().add(element); + father = element; + } + } } - } + return head; } - return head; - } - - static boolean hasEmptyData(InputStream elementData) { - String EMPTY_DATA = "{}"; - byte[] byteElementData; - try { - byteElementData = IOUtils.toByteArray(elementData); - } catch (IOException ex) { - return false; - } - if (Arrays.equals(EMPTY_DATA.getBytes(), byteElementData)) { - return true; + static boolean hasEmptyData(InputStream elementData) { + String EMPTY_DATA = "{}"; + byte[] byteElementData; + try { + byteElementData = IOUtils.toByteArray(elementData); + } catch (IOException ex) { + return false; + } + if (Arrays.equals(EMPTY_DATA.getBytes(), byteElementData)) { + return true; + } + return false; } - return false; - } } 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/convertor/ElementToComponentConvertor.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/convertor/ElementToComponentConvertor.java index b7a172ed90..d4c7fd05db 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/convertor/ElementToComponentConvertor.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/convertor/ElementToComponentConvertor.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor; import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; @@ -30,29 +29,24 @@ import org.openecomp.types.ElementPropertyName; public class ElementToComponentConvertor extends ElementConvertor { - @Override - public ComponentEntity convert(Element element) { - ComponentEntity componentEntity = new ComponentEntity(); - componentEntity.setId(element.getElementId().getValue()); - componentEntity.setCompositionData(new String(FileUtils.toByteArray(element.getData()))); - mapInfoToComponentEntity(componentEntity,element.getInfo()); - return componentEntity; - } - - @Override - public ComponentEntity convert( ElementInfo elementInfo) { - ComponentEntity componentEntity = new ComponentEntity(); - componentEntity.setId(elementInfo.getId().getValue()); - mapInfoToComponentEntity(componentEntity,elementInfo.getInfo()); - return componentEntity; - } - - - public void mapInfoToComponentEntity(ComponentEntity componentEntity,Info info){ - - - componentEntity.setCompositionData( - info.getProperty(ElementPropertyName.compositionData.name())); - } - + @Override + public ComponentEntity convert(Element element) { + ComponentEntity componentEntity = new ComponentEntity(); + componentEntity.setId(element.getElementId().getValue()); + componentEntity.setCompositionData(new String(FileUtils.toByteArray(element.getData()))); + mapInfoToComponentEntity(componentEntity, element.getInfo()); + return componentEntity; + } + + @Override + public ComponentEntity convert(ElementInfo elementInfo) { + ComponentEntity componentEntity = new ComponentEntity(); + componentEntity.setId(elementInfo.getId().getValue()); + mapInfoToComponentEntity(componentEntity, elementInfo.getInfo()); + return componentEntity; + } + + public void mapInfoToComponentEntity(ComponentEntity componentEntity, Info info) { + componentEntity.setCompositionData(info.getProperty(ElementPropertyName.compositionData.name())); + } } 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/convertor/ElementToComponentDependencyModelConvertor.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/convertor/ElementToComponentDependencyModelConvertor.java index 232ff336aa..b00f4e4846 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/convertor/ElementToComponentDependencyModelConvertor.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/convertor/ElementToComponentDependencyModelConvertor.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor; import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; @@ -27,35 +26,27 @@ import org.openecomp.convertor.ElementConvertor; import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.ComponentDependencyModelPropertyName; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentDependencyModelEntity; -public class ElementToComponentDependencyModelConvertor extends ElementConvertor { - - @Override - public ComponentDependencyModelEntity convert( Element element) { - ComponentDependencyModelEntity componentDependencyModelEntity = new ComponentDependencyModelEntity(); - componentDependencyModelEntity.setId(element.getElementId().getValue()); - mapInfoToComponentDependencyModelEntity(componentDependencyModelEntity,element.getInfo()); - return componentDependencyModelEntity; - } - - @Override - public ComponentDependencyModelEntity convert(ElementInfo elementInfo) { - ComponentDependencyModelEntity componentDependencyModelEntity = new ComponentDependencyModelEntity(); - - componentDependencyModelEntity.setId(elementInfo.getId().getValue()); - mapInfoToComponentDependencyModelEntity(componentDependencyModelEntity,elementInfo.getInfo()); - return componentDependencyModelEntity; - } - - - public void mapInfoToComponentDependencyModelEntity(ComponentDependencyModelEntity componentDependencyModelEntity,Info info){ - - componentDependencyModelEntity.setSourceComponentId(info - .getProperty(ComponentDependencyModelPropertyName.sourcecomponent_id.name())); - componentDependencyModelEntity.setTargetComponentId(info - .getProperty(ComponentDependencyModelPropertyName.targetcomponent_id.name())); - componentDependencyModelEntity.setRelation(info - .getProperty(ComponentDependencyModelPropertyName.relation.name())); - - } - +public class ElementToComponentDependencyModelConvertor extends ElementConvertor { + + @Override + public ComponentDependencyModelEntity convert(Element element) { + ComponentDependencyModelEntity componentDependencyModelEntity = new ComponentDependencyModelEntity(); + componentDependencyModelEntity.setId(element.getElementId().getValue()); + mapInfoToComponentDependencyModelEntity(componentDependencyModelEntity, element.getInfo()); + return componentDependencyModelEntity; + } + + @Override + public ComponentDependencyModelEntity convert(ElementInfo elementInfo) { + ComponentDependencyModelEntity componentDependencyModelEntity = new ComponentDependencyModelEntity(); + componentDependencyModelEntity.setId(elementInfo.getId().getValue()); + mapInfoToComponentDependencyModelEntity(componentDependencyModelEntity, elementInfo.getInfo()); + return componentDependencyModelEntity; + } + + public void mapInfoToComponentDependencyModelEntity(ComponentDependencyModelEntity componentDependencyModelEntity, Info info) { + componentDependencyModelEntity.setSourceComponentId(info.getProperty(ComponentDependencyModelPropertyName.sourcecomponent_id.name())); + componentDependencyModelEntity.setTargetComponentId(info.getProperty(ComponentDependencyModelPropertyName.targetcomponent_id.name())); + componentDependencyModelEntity.setRelation(info.getProperty(ComponentDependencyModelPropertyName.relation.name())); + } } 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/convertor/ElementToComponentMonitoringUploadConvertor.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/convertor/ElementToComponentMonitoringUploadConvertor.java index 2a8b3b9c81..044a862e4d 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/convertor/ElementToComponentMonitoringUploadConvertor.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/convertor/ElementToComponentMonitoringUploadConvertor.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,49 +17,40 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor; +import static org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor.ElementToProcessConvertor.ARTIFACT_NAME; + import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo; import com.amdocs.zusammen.datatypes.item.Info; +import java.nio.ByteBuffer; import org.openecomp.convertor.ElementConvertor; import org.openecomp.core.enrichment.types.MonitoringUploadType; import org.openecomp.core.utilities.file.FileUtils; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentMonitoringUploadEntity; -import java.nio.ByteBuffer; - -import static org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor.ElementToProcessConvertor.ARTIFACT_NAME; - public class ElementToComponentMonitoringUploadConvertor extends ElementConvertor { - @Override - public ComponentMonitoringUploadEntity convert(Element element) { - ComponentMonitoringUploadEntity mibEntity = new ComponentMonitoringUploadEntity(); - - mibEntity.setId(element.getElementId().getValue()); - mibEntity.setArtifact(ByteBuffer.wrap(FileUtils.toByteArray(element.getData()))); - mapInfoToComponentMonitoringUploadEntity(mibEntity, element.getInfo()); - return mibEntity; - } - - @Override - public ComponentMonitoringUploadEntity convert(ElementInfo elementInfo) { - ComponentMonitoringUploadEntity mibEntity = new ComponentMonitoringUploadEntity(); - - mibEntity.setId(elementInfo.getId().getValue()); - mapInfoToComponentMonitoringUploadEntity(mibEntity, elementInfo.getInfo()); - return mibEntity; - } - - - public void mapInfoToComponentMonitoringUploadEntity(ComponentMonitoringUploadEntity mibEntity, - Info info) { - - mibEntity.setArtifactName((String) info.getProperties().get(ARTIFACT_NAME)); - mibEntity.setType(MonitoringUploadType.valueOf(info.getName())); - } - - + @Override + public ComponentMonitoringUploadEntity convert(Element element) { + ComponentMonitoringUploadEntity mibEntity = new ComponentMonitoringUploadEntity(); + mibEntity.setId(element.getElementId().getValue()); + mibEntity.setArtifact(ByteBuffer.wrap(FileUtils.toByteArray(element.getData()))); + mapInfoToComponentMonitoringUploadEntity(mibEntity, element.getInfo()); + return mibEntity; + } + + @Override + public ComponentMonitoringUploadEntity convert(ElementInfo elementInfo) { + ComponentMonitoringUploadEntity mibEntity = new ComponentMonitoringUploadEntity(); + mibEntity.setId(elementInfo.getId().getValue()); + mapInfoToComponentMonitoringUploadEntity(mibEntity, elementInfo.getInfo()); + return mibEntity; + } + + public void mapInfoToComponentMonitoringUploadEntity(ComponentMonitoringUploadEntity mibEntity, Info info) { + mibEntity.setArtifactName((String) info.getProperties().get(ARTIFACT_NAME)); + mibEntity.setType(MonitoringUploadType.valueOf(info.getName())); + } } 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/convertor/ElementToComponentQuestionnnaireConvertor.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/convertor/ElementToComponentQuestionnnaireConvertor.java index f8ab803280..febafaae2f 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/convertor/ElementToComponentQuestionnnaireConvertor.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/convertor/ElementToComponentQuestionnnaireConvertor.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor; import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; @@ -25,17 +24,16 @@ import org.openecomp.convertor.ElementConvertor; import org.openecomp.core.utilities.file.FileUtils; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; - /** * Created by ayalaben on 9/27/2017 */ public class ElementToComponentQuestionnnaireConvertor extends ElementConvertor { - @Override - public ComponentEntity convert( Element element) { - ComponentEntity componentEntity = new ComponentEntity(); - componentEntity.setId(element.getElementId().getValue()); - componentEntity.setQuestionnaireData(new String(FileUtils.toByteArray(element.getData()))); - return componentEntity; - } + @Override + public ComponentEntity convert(Element element) { + ComponentEntity componentEntity = new ComponentEntity(); + componentEntity.setId(element.getElementId().getValue()); + componentEntity.setQuestionnaireData(new String(FileUtils.toByteArray(element.getData()))); + return componentEntity; + } } 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/convertor/ElementToCompositionEntityConvertor.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/convertor/ElementToCompositionEntityConvertor.java index ca0d564ce2..b3271f5db4 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/convertor/ElementToCompositionEntityConvertor.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/convertor/ElementToCompositionEntityConvertor.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,45 +17,44 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor; import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; import org.openecomp.convertor.ElementConvertor; import org.openecomp.core.utilities.file.FileUtils; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.*; - -public class ElementToCompositionEntityConvertor extends ElementConvertor { +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.CompositionEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ImageEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspQuestionnaireEntity; - @Override - public CompositionEntity convert(Element element) { +public class ElementToCompositionEntityConvertor extends ElementConvertor { - CompositionEntity compositionEntity = null; - switch (getElementType(element)) { - case ComponentQuestionnaire: - compositionEntity = new ComponentEntity(); - break; - case VSPQuestionnaire: - compositionEntity = new VspQuestionnaireEntity(); - break; - case ImageQuestionnaire: - compositionEntity = new ImageEntity(); - break; - case ComputeQuestionnaire: - compositionEntity = new ComponentEntity(); - break; - case NicQuestionnaire: - compositionEntity = new NicEntity(); + @Override + public CompositionEntity convert(Element element) { + CompositionEntity compositionEntity = null; + switch (getElementType(element)) { + case ComponentQuestionnaire: + compositionEntity = new ComponentEntity(); + break; + case VSPQuestionnaire: + compositionEntity = new VspQuestionnaireEntity(); + break; + case ImageQuestionnaire: + compositionEntity = new ImageEntity(); + break; + case ComputeQuestionnaire: + compositionEntity = new ComponentEntity(); + break; + case NicQuestionnaire: + compositionEntity = new NicEntity(); + } + if (compositionEntity != null) { + compositionEntity.setId(element.getElementId().getValue()); + compositionEntity.setQuestionnaireData(element.getData() == null ? null : new String(FileUtils.toByteArray(element.getData()))); + return compositionEntity; + } else { + return null; + } } - if (compositionEntity != null) { - compositionEntity.setId(element.getElementId().getValue()); - compositionEntity.setQuestionnaireData(element.getData() == null - ? null - : new String(FileUtils.toByteArray(element.getData()))); - return compositionEntity; - } else { - return null; - } - } - } 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/convertor/ElementToComputeConvertor.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/convertor/ElementToComputeConvertor.java index ee10221862..12fba38009 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/convertor/ElementToComputeConvertor.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/convertor/ElementToComputeConvertor.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor; import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; @@ -28,33 +27,26 @@ import org.openecomp.core.utilities.file.FileUtils; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComputeEntity; import org.openecomp.types.ElementPropertyName; -public class ElementToComputeConvertor extends ElementConvertor { - - @Override - public ComputeEntity convert( Element element) { - ComputeEntity computeEntity = new ComputeEntity(); - - computeEntity.setId(element.getElementId().getValue()); - computeEntity.setCompositionData(new String(FileUtils.toByteArray(element.getData()))); - mapInfoToComputeEntity(computeEntity,element.getInfo()); - return computeEntity; - } - - @Override - public ComputeEntity convert( ElementInfo elementInfo) { - ComputeEntity computeEntity = new ComputeEntity(); - - computeEntity.setId(elementInfo.getId().getValue()); - mapInfoToComputeEntity(computeEntity,elementInfo.getInfo()); - return computeEntity; - } - - - public void mapInfoToComputeEntity(ComputeEntity computeEntity,Info info){ - - - computeEntity.setCompositionData( - info.getProperty(ElementPropertyName.compositionData.name())); - } - +public class ElementToComputeConvertor extends ElementConvertor { + + @Override + public ComputeEntity convert(Element element) { + ComputeEntity computeEntity = new ComputeEntity(); + computeEntity.setId(element.getElementId().getValue()); + computeEntity.setCompositionData(new String(FileUtils.toByteArray(element.getData()))); + mapInfoToComputeEntity(computeEntity, element.getInfo()); + return computeEntity; + } + + @Override + public ComputeEntity convert(ElementInfo elementInfo) { + ComputeEntity computeEntity = new ComputeEntity(); + computeEntity.setId(elementInfo.getId().getValue()); + mapInfoToComputeEntity(computeEntity, elementInfo.getInfo()); + return computeEntity; + } + + public void mapInfoToComputeEntity(ComputeEntity computeEntity, Info info) { + computeEntity.setCompositionData(info.getProperty(ElementPropertyName.compositionData.name())); + } } 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/convertor/ElementToComputeQuestionnaireConvertor.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/convertor/ElementToComputeQuestionnaireConvertor.java index bc5b556625..c255dcce24 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/convertor/ElementToComputeQuestionnaireConvertor.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/convertor/ElementToComputeQuestionnaireConvertor.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor; import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; @@ -25,15 +24,13 @@ import org.openecomp.convertor.ElementConvertor; import org.openecomp.core.utilities.file.FileUtils; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComputeEntity; -public class ElementToComputeQuestionnaireConvertor extends ElementConvertor { - - @Override - public ComputeEntity convert( Element element) { - ComputeEntity computeEntity = new ComputeEntity(); - - computeEntity.setId(element.getElementId().getValue()); - computeEntity.setQuestionnaireData(new String(FileUtils.toByteArray(element.getData()))); - return computeEntity; - } +public class ElementToComputeQuestionnaireConvertor extends ElementConvertor { + @Override + public ComputeEntity convert(Element element) { + ComputeEntity computeEntity = new ComputeEntity(); + computeEntity.setId(element.getElementId().getValue()); + computeEntity.setQuestionnaireData(new String(FileUtils.toByteArray(element.getData()))); + return computeEntity; + } } 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/convertor/ElementToDeploymentFlavorConvertor.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/convertor/ElementToDeploymentFlavorConvertor.java index 19719c6827..c354da1707 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/convertor/ElementToDeploymentFlavorConvertor.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/convertor/ElementToDeploymentFlavorConvertor.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor; import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; @@ -28,33 +27,26 @@ import org.openecomp.core.utilities.file.FileUtils; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.DeploymentFlavorEntity; import org.openecomp.types.ElementPropertyName; -public class ElementToDeploymentFlavorConvertor extends ElementConvertor { - - @Override - public DeploymentFlavorEntity convert( Element element) { - DeploymentFlavorEntity deploymentFlavorEntity = new DeploymentFlavorEntity(); - - deploymentFlavorEntity.setId(element.getElementId().getValue()); - deploymentFlavorEntity.setCompositionData(new String(FileUtils.toByteArray(element.getData()))); - mapInfoToDeploymentFlavorEntity(deploymentFlavorEntity,element.getInfo()); - return deploymentFlavorEntity; - } - - @Override - public DeploymentFlavorEntity convert( ElementInfo elementInfo) { - DeploymentFlavorEntity deploymentFlavorEntity = new DeploymentFlavorEntity(); - - deploymentFlavorEntity.setId(elementInfo.getId().getValue()); - mapInfoToDeploymentFlavorEntity(deploymentFlavorEntity,elementInfo.getInfo()); - return deploymentFlavorEntity; - } - - - public void mapInfoToDeploymentFlavorEntity(DeploymentFlavorEntity deploymentFlavorEntity,Info info){ - - - deploymentFlavorEntity.setCompositionData( - info.getProperty(ElementPropertyName.compositionData.name())); - } - +public class ElementToDeploymentFlavorConvertor extends ElementConvertor { + + @Override + public DeploymentFlavorEntity convert(Element element) { + DeploymentFlavorEntity deploymentFlavorEntity = new DeploymentFlavorEntity(); + deploymentFlavorEntity.setId(element.getElementId().getValue()); + deploymentFlavorEntity.setCompositionData(new String(FileUtils.toByteArray(element.getData()))); + mapInfoToDeploymentFlavorEntity(deploymentFlavorEntity, element.getInfo()); + return deploymentFlavorEntity; + } + + @Override + public DeploymentFlavorEntity convert(ElementInfo elementInfo) { + DeploymentFlavorEntity deploymentFlavorEntity = new DeploymentFlavorEntity(); + deploymentFlavorEntity.setId(elementInfo.getId().getValue()); + mapInfoToDeploymentFlavorEntity(deploymentFlavorEntity, elementInfo.getInfo()); + return deploymentFlavorEntity; + } + + public void mapInfoToDeploymentFlavorEntity(DeploymentFlavorEntity deploymentFlavorEntity, Info info) { + deploymentFlavorEntity.setCompositionData(info.getProperty(ElementPropertyName.compositionData.name())); + } } 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/convertor/ElementToImageConvertor.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/convertor/ElementToImageConvertor.java index 66621d6934..5aa164c06b 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/convertor/ElementToImageConvertor.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/convertor/ElementToImageConvertor.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor; import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; @@ -28,33 +27,26 @@ import org.openecomp.core.utilities.file.FileUtils; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ImageEntity; import org.openecomp.types.ElementPropertyName; -public class ElementToImageConvertor extends ElementConvertor { - - @Override - public ImageEntity convert( Element element) { - ImageEntity imageEntity = new ImageEntity(); - - imageEntity.setId(element.getElementId().getValue()); - imageEntity.setCompositionData(new String(FileUtils.toByteArray(element.getData()))); - mapInfoToImageEntity(imageEntity,element.getInfo()); - return imageEntity; - } - - @Override - public ImageEntity convert( ElementInfo elementInfo) { - ImageEntity imageEntity = new ImageEntity(); - - imageEntity.setId(elementInfo.getId().getValue()); - mapInfoToImageEntity(imageEntity,elementInfo.getInfo()); - return imageEntity; - } - - - public void mapInfoToImageEntity(ImageEntity imageEntity,Info info){ - - - imageEntity.setCompositionData( - info.getProperty(ElementPropertyName.compositionData.name())); - } - +public class ElementToImageConvertor extends ElementConvertor { + + @Override + public ImageEntity convert(Element element) { + ImageEntity imageEntity = new ImageEntity(); + imageEntity.setId(element.getElementId().getValue()); + imageEntity.setCompositionData(new String(FileUtils.toByteArray(element.getData()))); + mapInfoToImageEntity(imageEntity, element.getInfo()); + return imageEntity; + } + + @Override + public ImageEntity convert(ElementInfo elementInfo) { + ImageEntity imageEntity = new ImageEntity(); + imageEntity.setId(elementInfo.getId().getValue()); + mapInfoToImageEntity(imageEntity, elementInfo.getInfo()); + return imageEntity; + } + + public void mapInfoToImageEntity(ImageEntity imageEntity, Info info) { + imageEntity.setCompositionData(info.getProperty(ElementPropertyName.compositionData.name())); + } } 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/convertor/ElementToImageQuestionnaireConvertor.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/convertor/ElementToImageQuestionnaireConvertor.java index 4dfe9d297f..32aa3c4041 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/convertor/ElementToImageQuestionnaireConvertor.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/convertor/ElementToImageQuestionnaireConvertor.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor; import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; @@ -25,15 +24,13 @@ import org.openecomp.convertor.ElementConvertor; import org.openecomp.core.utilities.file.FileUtils; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ImageEntity; -public class ElementToImageQuestionnaireConvertor extends ElementConvertor { - - @Override - public ImageEntity convert( Element element) { - ImageEntity imageEntity = new ImageEntity(); - - imageEntity.setId(element.getElementId().getValue()); - imageEntity.setQuestionnaireData(new String(FileUtils.toByteArray(element.getData()))); - return imageEntity; - } +public class ElementToImageQuestionnaireConvertor extends ElementConvertor { + @Override + public ImageEntity convert(Element element) { + ImageEntity imageEntity = new ImageEntity(); + imageEntity.setId(element.getElementId().getValue()); + imageEntity.setQuestionnaireData(new String(FileUtils.toByteArray(element.getData()))); + return imageEntity; + } } 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/convertor/ElementToMonitoringUploadMapConvertor.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/convertor/ElementToMonitoringUploadMapConvertor.java index 8c4a284fa4..0f2b208808 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/convertor/ElementToMonitoringUploadMapConvertor.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/convertor/ElementToMonitoringUploadMapConvertor.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,27 +17,24 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor; -import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; -import org.openecomp.convertor.ElementConvertor; +import static org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor.ElementToProcessConvertor.ARTIFACT_NAME; +import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; import java.util.HashMap; import java.util.Map; - -import static org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor.ElementToProcessConvertor.ARTIFACT_NAME; +import org.openecomp.convertor.ElementConvertor; /** * Created by ayalaben on 9/5/2017. */ +public class ElementToMonitoringUploadMapConvertor extends ElementConvertor> { -public class ElementToMonitoringUploadMapConvertor extends ElementConvertor> { - - @Override - public Map convert(Element element) { - HashMap map = new HashMap<>(); - map.put("File Name",element.getInfo().getProperty(ARTIFACT_NAME)); - return map; - } + @Override + public Map convert(Element element) { + HashMap map = new HashMap<>(); + map.put("File Name", element.getInfo().getProperty(ARTIFACT_NAME)); + return map; + } } 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/convertor/ElementToNetworkConvertor.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/convertor/ElementToNetworkConvertor.java index a34e650e78..0a64ff54c2 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/convertor/ElementToNetworkConvertor.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/convertor/ElementToNetworkConvertor.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor; import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; @@ -28,31 +27,26 @@ import org.openecomp.core.utilities.file.FileUtils; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity; import org.openecomp.types.ElementPropertyName; -public class ElementToNetworkConvertor extends ElementConvertor { - - @Override - public NetworkEntity convert( Element element) { - NetworkEntity networkEntity = new NetworkEntity(); - - networkEntity.setId(element.getElementId().getValue()); - networkEntity.setCompositionData(new String(FileUtils.toByteArray(element.getData()))); - mapInfoToNetworkEntity(networkEntity,element.getInfo()); - return networkEntity; - } - - @Override - public NetworkEntity convert( ElementInfo elementInfo) { - NetworkEntity networkEntity = new NetworkEntity(); - - networkEntity.setId(elementInfo.getId().getValue()); - mapInfoToNetworkEntity(networkEntity,elementInfo.getInfo()); - return networkEntity; - } - - - public void mapInfoToNetworkEntity(NetworkEntity networkEntity,Info info){ - networkEntity.setCompositionData( - info.getProperty(ElementPropertyName.compositionData.name())); - } - +public class ElementToNetworkConvertor extends ElementConvertor { + + @Override + public NetworkEntity convert(Element element) { + NetworkEntity networkEntity = new NetworkEntity(); + networkEntity.setId(element.getElementId().getValue()); + networkEntity.setCompositionData(new String(FileUtils.toByteArray(element.getData()))); + mapInfoToNetworkEntity(networkEntity, element.getInfo()); + return networkEntity; + } + + @Override + public NetworkEntity convert(ElementInfo elementInfo) { + NetworkEntity networkEntity = new NetworkEntity(); + networkEntity.setId(elementInfo.getId().getValue()); + mapInfoToNetworkEntity(networkEntity, elementInfo.getInfo()); + return networkEntity; + } + + public void mapInfoToNetworkEntity(NetworkEntity networkEntity, Info info) { + networkEntity.setCompositionData(info.getProperty(ElementPropertyName.compositionData.name())); + } } 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/convertor/ElementToNicConvertor.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/convertor/ElementToNicConvertor.java index a41eb382b2..e126586420 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/convertor/ElementToNicConvertor.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/convertor/ElementToNicConvertor.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor; import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; @@ -28,32 +27,26 @@ import org.openecomp.core.utilities.file.FileUtils; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity; import org.openecomp.types.ElementPropertyName; -public class ElementToNicConvertor extends ElementConvertor { - - @Override - public NicEntity convert( Element element) { - NicEntity nicEntity = new NicEntity(); - - nicEntity.setId(element.getElementId().getValue()); - nicEntity.setCompositionData(new String(FileUtils.toByteArray(element.getData()))); - mapInfoToNicEntity(nicEntity,element.getInfo()); - return nicEntity; - } - - @Override - public NicEntity convert( ElementInfo elementInfo) { - NicEntity nicEntity = new NicEntity(); - - nicEntity.setId(elementInfo.getId().getValue()); - mapInfoToNicEntity(nicEntity,elementInfo.getInfo()); - return nicEntity; - } - - - public void mapInfoToNicEntity(NicEntity nicEntity,Info info){ - - nicEntity.setCompositionData( - info.getProperty(ElementPropertyName.compositionData.name())); - } - +public class ElementToNicConvertor extends ElementConvertor { + + @Override + public NicEntity convert(Element element) { + NicEntity nicEntity = new NicEntity(); + nicEntity.setId(element.getElementId().getValue()); + nicEntity.setCompositionData(new String(FileUtils.toByteArray(element.getData()))); + mapInfoToNicEntity(nicEntity, element.getInfo()); + return nicEntity; + } + + @Override + public NicEntity convert(ElementInfo elementInfo) { + NicEntity nicEntity = new NicEntity(); + nicEntity.setId(elementInfo.getId().getValue()); + mapInfoToNicEntity(nicEntity, elementInfo.getInfo()); + return nicEntity; + } + + public void mapInfoToNicEntity(NicEntity nicEntity, Info info) { + nicEntity.setCompositionData(info.getProperty(ElementPropertyName.compositionData.name())); + } } 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/convertor/ElementToNicQuestionnaireConvertor.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/convertor/ElementToNicQuestionnaireConvertor.java index ec84ae9f6d..fe397f772d 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/convertor/ElementToNicQuestionnaireConvertor.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/convertor/ElementToNicQuestionnaireConvertor.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor; import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; @@ -25,17 +24,13 @@ import org.openecomp.convertor.ElementConvertor; import org.openecomp.core.utilities.file.FileUtils; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity; -public class ElementToNicQuestionnaireConvertor extends ElementConvertor { - - @Override - public NicEntity convert( Element element) { - NicEntity nicEntity = new NicEntity(); - - nicEntity.setId(element.getElementId().getValue()); - nicEntity.setQuestionnaireData( element.getData() == null - ? null - : new String(FileUtils.toByteArray(element.getData()))); - return nicEntity; - } +public class ElementToNicQuestionnaireConvertor extends ElementConvertor { + @Override + public NicEntity convert(Element element) { + NicEntity nicEntity = new NicEntity(); + nicEntity.setId(element.getElementId().getValue()); + nicEntity.setQuestionnaireData(element.getData() == null ? null : new String(FileUtils.toByteArray(element.getData()))); + return nicEntity; + } } 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/convertor/ElementToOrchestrationTemplateCandidateMapConvertor.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/convertor/ElementToOrchestrationTemplateCandidateMapConvertor.java index de9cc520b3..653c561ca6 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/convertor/ElementToOrchestrationTemplateCandidateMapConvertor.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/convertor/ElementToOrchestrationTemplateCandidateMapConvertor.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor; import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; @@ -29,12 +28,10 @@ import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.FilesDataStru /** * Created by ayalaben on 9/6/2017 */ -public class ElementToOrchestrationTemplateCandidateMapConvertor - extends ElementConvertor { +public class ElementToOrchestrationTemplateCandidateMapConvertor extends ElementConvertor { - @Override - public FilesDataStructure convert(Element element) { - return JsonUtil.json2Object(new String(FileUtils.toByteArray(element.getData())), - FilesDataStructure.class); - } + @Override + public FilesDataStructure convert(Element element) { + return JsonUtil.json2Object(new String(FileUtils.toByteArray(element.getData())), FilesDataStructure.class); + } } 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/convertor/ElementToProcessConvertor.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/convertor/ElementToProcessConvertor.java index ec8aa172bd..d14f870eac 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/convertor/ElementToProcessConvertor.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/convertor/ElementToProcessConvertor.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,55 +17,51 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor; import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo; import com.amdocs.zusammen.datatypes.item.Info; +import java.nio.ByteBuffer; import org.openecomp.convertor.ElementConvertor; import org.openecomp.core.utilities.file.FileUtils; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessType; -import java.nio.ByteBuffer; - public class ElementToProcessConvertor extends ElementConvertor { - public static final String NAME = "name"; - public static final String ARTIFACT_NAME = "artifactName"; - public static final String DESCRIPTION = "description"; - public static final String PROCESS_TYPE = "processType"; + public static final String NAME = "name"; + public static final String ARTIFACT_NAME = "artifactName"; + public static final String DESCRIPTION = "description"; + public static final String PROCESS_TYPE = "processType"; - @Override - public ProcessEntity convert(Element element) { - if (element == null) { - return null; + @Override + public ProcessEntity convert(Element element) { + if (element == null) { + return null; + } + ProcessEntity processEntity = new ProcessEntity(); + processEntity.setId(element.getElementId().getValue()); + processEntity.setArtifact(ByteBuffer.wrap(FileUtils.toByteArray(element.getData()))); + mapInfoToProcessEntity(processEntity, element.getInfo()); + return processEntity; } - ProcessEntity processEntity = new ProcessEntity(); - processEntity.setId(element.getElementId().getValue()); - processEntity.setArtifact(ByteBuffer.wrap(FileUtils.toByteArray(element.getData()))); - mapInfoToProcessEntity(processEntity, element.getInfo()); - return processEntity; - } - @Override - public ProcessEntity convert(ElementInfo elementInfo) { - if (elementInfo == null) { - return null; + @Override + public ProcessEntity convert(ElementInfo elementInfo) { + if (elementInfo == null) { + return null; + } + ProcessEntity processEntity = new ProcessEntity(); + processEntity.setId(elementInfo.getId().getValue()); + mapInfoToProcessEntity(processEntity, elementInfo.getInfo()); + return processEntity; } - ProcessEntity processEntity = new ProcessEntity(); - processEntity.setId(elementInfo.getId().getValue()); - mapInfoToProcessEntity(processEntity, elementInfo.getInfo()); - return processEntity; - } - public void mapInfoToProcessEntity(ProcessEntity processEntity, Info info) { - processEntity.setName(info.getProperty(NAME)); - processEntity.setArtifactName(info.getProperty(ARTIFACT_NAME)); - processEntity.setDescription(info.getProperty(DESCRIPTION)); - processEntity.setType(info.getProperty - (PROCESS_TYPE) != null ? ProcessType.valueOf(info.getProperty - (PROCESS_TYPE)) : null); - } + public void mapInfoToProcessEntity(ProcessEntity processEntity, Info info) { + processEntity.setName(info.getProperty(NAME)); + processEntity.setArtifactName(info.getProperty(ARTIFACT_NAME)); + processEntity.setDescription(info.getProperty(DESCRIPTION)); + processEntity.setType(info.getProperty(PROCESS_TYPE) != null ? ProcessType.valueOf(info.getProperty(PROCESS_TYPE)) : null); + } } 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/convertor/ElementToServiceModelMapConvertor.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/convertor/ElementToServiceModelMapConvertor.java index 574d3b30f6..e6a151a6c3 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/convertor/ElementToServiceModelMapConvertor.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/convertor/ElementToServiceModelMapConvertor.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,24 +17,23 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor; import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; -import org.openecomp.convertor.ElementConvertor; - import java.util.HashMap; import java.util.Map; +import org.openecomp.convertor.ElementConvertor; /** * Created by ayalaben on 9/11/2017 */ -public class ElementToServiceModelMapConvertor extends ElementConvertor> { - @Override - public Map convert(Element element) { - //TODO : after merge with 1802 change to heat fle name/TOSCA file name - HashMap map = new HashMap<>(); - map.put("Service Model Definition Entry", element.getInfo().getProperty("base")); - return map; - } +public class ElementToServiceModelMapConvertor extends ElementConvertor> { + + @Override + public Map convert(Element element) { + //TODO : after merge with 1802 change to heat fle name/TOSCA file name + HashMap map = new HashMap<>(); + map.put("Service Model Definition Entry", element.getInfo().getProperty("base")); + return map; + } } 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/convertor/ElementToVSPGeneralConvertor.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/convertor/ElementToVSPGeneralConvertor.java index d8bb1798ff..8234eeeaf1 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/convertor/ElementToVSPGeneralConvertor.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/convertor/ElementToVSPGeneralConvertor.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor; import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; @@ -29,72 +28,51 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.VendorSoftwareP import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; import org.openecomp.sdc.versioning.dao.types.Version; - public class ElementToVSPGeneralConvertor extends ElementConvertor { - @Override - public VspDetails convert(Element element) { - if (element == null) { - return null; - } - return mapInfoToVspDetails(element.getInfo()); - } - - @Override - public VspDetails convert(Item item) { - if (item == null) { - return null; + @Override + public VspDetails convert(Element element) { + if (element == null) { + return null; + } + return mapInfoToVspDetails(element.getInfo()); } - VspDetails vspDetails = mapInfoToVspDetails(item.getInfo()); - vspDetails.setId(item.getId().getValue()); - return vspDetails; - } - @Override - public VspDetails convert(ElementInfo elementInfo) { - if (elementInfo == null) { - return null; + @Override + public VspDetails convert(Item item) { + if (item == null) { + return null; + } + VspDetails vspDetails = mapInfoToVspDetails(item.getInfo()); + vspDetails.setId(item.getId().getValue()); + return vspDetails; } - return mapInfoToVspDetails(elementInfo.getInfo()); - - } - - private VspDetails mapInfoToVspDetails(Info info) { - - VspDetails vspDetails = new VspDetails(); - - vspDetails.setName(info.getProperty(VendorSoftwareProductInfoDaoZusammenImpl - .InfoPropertyName.NAME.getValue())); - vspDetails.setDescription(info.getProperty( - VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.DESCRIPTION.getValue())); - vspDetails.setIcon(info.getProperty( - VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.ICON.getValue())); - vspDetails.setCategory(info.getProperty( - VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.CATEGORY.getValue())); - vspDetails.setSubCategory(info.getProperty( - VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.SUB_CATEGORY.getValue())); - vspDetails.setVendorId(info.getProperty( - VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.VENDOR_ID.getValue())); - vspDetails.setVendorName(info.getProperty( - VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.VENDOR_NAME.getValue())); - if (info.getProperty( - VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.VENDOR_VERSION.getValue()) != null) { - vspDetails.setVlmVersion(new Version(info.getProperty( - VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.VENDOR_VERSION.getValue()))); + @Override + public VspDetails convert(ElementInfo elementInfo) { + if (elementInfo == null) { + return null; + } + return mapInfoToVspDetails(elementInfo.getInfo()); } - vspDetails.setLicenseType(info.getProperty( - VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.LICENSE_TYPE.getValue())); - vspDetails.setLicenseAgreement(info.getProperty( - VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.LICENSE_AGREEMENT.getValue())); - vspDetails.setFeatureGroups(info.getProperty( - VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.FEATURE_GROUPS.getValue())); - vspDetails.setOnboardingMethod(info.getProperty( - VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.ON_BOARDING_METHOD.getValue())); - - return vspDetails; - } - - + private VspDetails mapInfoToVspDetails(Info info) { + VspDetails vspDetails = new VspDetails(); + vspDetails.setName(info.getProperty(VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.NAME.getValue())); + vspDetails.setDescription(info.getProperty(VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.DESCRIPTION.getValue())); + vspDetails.setIcon(info.getProperty(VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.ICON.getValue())); + vspDetails.setCategory(info.getProperty(VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.CATEGORY.getValue())); + vspDetails.setSubCategory(info.getProperty(VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.SUB_CATEGORY.getValue())); + vspDetails.setVendorId(info.getProperty(VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.VENDOR_ID.getValue())); + vspDetails.setVendorName(info.getProperty(VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.VENDOR_NAME.getValue())); + if (info.getProperty(VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.VENDOR_VERSION.getValue()) != null) { + vspDetails + .setVlmVersion(new Version(info.getProperty(VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.VENDOR_VERSION.getValue()))); + } + vspDetails.setLicenseType(info.getProperty(VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.LICENSE_TYPE.getValue())); + vspDetails.setLicenseAgreement(info.getProperty(VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.LICENSE_AGREEMENT.getValue())); + vspDetails.setFeatureGroups(info.getProperty(VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.FEATURE_GROUPS.getValue())); + vspDetails.setOnboardingMethod(info.getProperty(VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.ON_BOARDING_METHOD.getValue())); + return 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/convertor/ElementToVSPQuestionnaireConvertor.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/convertor/ElementToVSPQuestionnaireConvertor.java index b8797cf8e2..71a2b4782d 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/convertor/ElementToVSPQuestionnaireConvertor.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/convertor/ElementToVSPQuestionnaireConvertor.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor; import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; @@ -23,11 +22,10 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspQuestionnaireEntity; public class ElementToVSPQuestionnaireConvertor extends ElementConvertor { - @Override - public VspQuestionnaireEntity convert(Element element) { - VspQuestionnaireEntity entity = new VspQuestionnaireEntity(); - entity.setQuestionnaireData( - element == null ? "{}" : new String(FileUtils.toByteArray(element.getData()))); - return entity; - } + @Override + public VspQuestionnaireEntity convert(Element element) { + VspQuestionnaireEntity entity = new VspQuestionnaireEntity(); + entity.setQuestionnaireData(element == null ? "{}" : new String(FileUtils.toByteArray(element.getData()))); + return entity; + } } 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/errors/VendorSoftwareProductErrorCodes.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/VendorSoftwareProductErrorCodes.java index 83abbfb123..13ade278bf 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/VendorSoftwareProductErrorCodes.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/VendorSoftwareProductErrorCodes.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.vendorsoftwareproduct.errors; /** @@ -21,110 +20,64 @@ package org.openecomp.sdc.vendorsoftwareproduct.errors; */ public class VendorSoftwareProductErrorCodes { - public static final String VSP_NOT_FOUND = "VSP_NOT_FOUND"; - public static final String VSP_INVALID = "VSP_INVALID"; - public static final String VFC_INVALID = "VFC_INVALID"; - public static final String FAILED_TO_CREATE_VSP = "FAILED_TO_CREATE_VSP"; - - public static final String UPLOAD_INVALID = "UPLOAD_INVALID"; - - public static final String PACKAGE_NOT_FOUND = "PACKAGE_NOT_FOUND"; - - public static final String PACKAGE_INVALID = "PACKAGE_INVALID"; - public static final String VSP_COMPOSITION_EDIT_NOT_ALLOWED = "VSP_COMPOSITION_EDIT_NOT_ALLOWED"; - - public static final String CREATE_PACKAGE_FOR_NON_FINAL_VSP = "CREATE_PACKAGE_FOR_NON_FINAL_VSP"; - - public static final String TRANSLATION_FILE_CREATION = "TRANSLATION_FILE_CREATION"; - - public static final String HEAT_PACKAGE_FILE_CREATION = "HEAT_PACKAGE_FILE_CREATION"; - - public static final String TOSCA_ENTRY_NOT_FOUND = "TOSCA_ENTRY_NOT_FOUND"; - public static final String TOSCA_INVALID_SUBSTITUTE_NODE_TEMPLATE = - "TOSCA_INVALID_SUBSTITUTE_NODE_TEMPLATE"; - - public static final String MONITORING_UPLOAD_INVALID = "MONITORING_UPLOAD_INVALID"; - - public static final String ORCHESTRATION_NOT_FOUND = "ORCHESTRATION_NOT_FOUND"; - - - public static final String CYCLIC_DEPENDENCY_IN_COMPONENTS = "CYCLIC_DEPENDENCY_IN_COMPONENTS"; - - public static final String INVALID_COMPONENT_RELATION_TYPE = "INVALID_COMPONENT_RELATION_TYPE"; - - public static final String NO_SOURCE_COMPONENT = "NO_SOURCE_COMPONENT"; - - public static final String SAME_SOURCE_TARGET_COMPONENT = "SAME_SOURCE_TARGET_COMPONENT"; - - public static final String DUPLICATE_NIC_NAME_NOT_ALLOWED = "DUPLICATE_NIC_NAME_NOT_ALLOWED"; - public static final String NIC_NAME_FORMAT_NOT_ALLOWED = "NIC_NAME_FORMAT_NOT_ALLOWED"; - - public static final String NULL_NETWORKID_NOT_ALLOWED = "NULL_NETWORKID_NOT_ALLOWED"; - - public static final String NETWORKID_NOT_ALLOWED_FOR_EXTERNAL_NETWORK = - "NETWORKID_NOT_ALLOWED_FOR_EXTERNAL_NETWORK"; - - public static final String VFC_ADD_NOT_ALLOWED_IN_HEAT_ONBOARDING = - "VFC_ADD_NOT_ALLOWED_IN_HEAT_ONBOARDING"; - public static final String VSP_VFC_COUNT_EXCEED = "VSP_VFC_COUNT_EXCEED"; - public static final String VSP_VFC_DUPLICATE_NAME = "VSP_VFC_DUPLICATE_NAME"; - public static final String VSP_INVALID_ONBOARDING_METHOD = "VSP_INVALID_ONBOARDING_METHOD"; - public static final String - ADD_NIC_NOT_ALLOWED_IN_HEAT_ONBOARDING = "ADD_NIC_NOT_ALLOWED_IN_HEAT_ONBOARDING"; - public static final String NETWORK_DESCRIPTION_NOT_ALLOWED_FOR_INTERNAL_NETWORK - = "NETWORK_DESCRIPTION_NOT_ALLOWED_FOR_INTERNAL_NETWORK"; - - public static final String VFC_ATTRIBUTE_UPDATE_NOT_ALLOWED = - "VFC_ATTRIBUTE_UPDATE_NOT_ALLOWED"; - public static final String NETWORK_TYPE_UPDATE_NOT_ALLOWED - = "NETWORK_TYPE_UPDATE_NOT_ALLOWED"; - public static final String DELETE_NIC_NOT_ALLOWED = "DELETE_NIC_NOT_ALLOWED"; - - public static final String CREATE_DEPLOYMENT_FLAVOR_NOT_ALLOWED_IN_HEAT_ONBOARDING = - "CREATE_DEPLOYMENT_FLAVOR_NOT_ALLOWED_IN_HEAT_ONBOARDING"; - - public static final String DELETE_DEPLOYMENT_FLAVOR_NOT_ALLOWED_IN_HEAT_ONBOARDING = - "DELETE_DEPLOYMENT_FLAVOR_NOT_ALLOWED_IN_HEAT_ONBOARDING"; - - public static final String EDIT_DEPLOYMENT_FLAVOR_NOT_ALLOWED_IN_HEAT_ONBOARDING = - "EDIT_DEPLOYMENT_FLAVOR_NOT_ALLOWED_IN_HEAT_ONBOARDING"; - - public static final String FEATUREGROUP_REQUIRED_IN_DEPLOYMENT_FLAVOR = - "FEATUREGROUP_REQUIRED_IN_DEPLOYMENT_FLAVOR"; - - public static final String - ADD_IMAGE_NOT_ALLOWED_IN_HEAT_ONBOARDING = "ADD_IMAGE_NOT_ALLOWED_IN_HEAT_ONBOARDING"; - - public static final String DUPLICATE_IMAGE_NAME_NOT_ALLOWED = "DUPLICATE_IMAGE_NAME_NOT_ALLOWED"; - public static final String DUPLICATE_IMAGE_VERSION_NOT_ALLOWED = "DUPLICATE_IMAGE_VERSION_NOT_ALLOWED"; - public static final String IMAGE_NAME_FORMAT_NOT_ALLOWED = "IMAGE_NAME_FORMAT_NOT_ALLOWED"; - public static final String VFC_IMAGE_INVALID_FORMAT = "VFC_IMAGE_INVALID_FORMAT"; - public static final String FEATURE_GROUP_NOT_EXIST_FOR_VSP = "FEATURE_GROUP_NOT_EXIST_FOR_VSP"; - - public static final String - ADD_COMPUTE_NOT_ALLOWED_IN_HEAT_ONBOARDING = "ADD_COMPUTE_NOT_ALLOWED_IN_HEAT_ONBOARDING"; - public static final String VFC_COMPUTE_INVALID_FORMAT = "VFC_COMPUTE_INVALID_FORMAT"; - public static final String UPDATE_COMPUTE_NOT_ALLOWED = "UPDATE_COMPUTE_NOT_ALLOWED"; - public static final String - INVALID_COMPONENT_COMPUTE_ASSOCIATION = "INVALID_COMPONENT_COMPUTE_ASSOCIATION"; - public static final String SAME_VFC_ASSOCIATION_MORE_THAN_ONCE_NOT_ALLOWED - = "SAME_VFC_ASSOCIATION_MORE_THAN_ONCE_NOT_ALLOWED"; - public static final String DUPLICATE_DEPLOYMENT_FLAVOR_MODEL_NOT_ALLOWED - = "DUPLICATE_DEPLOYMENT_FLAVOR_MODEL_NOT_ALLOWED"; - public static final String DEPLOYMENT_FLAVOR_NAME_FORMAT_NOT_ALLOWED = - "DEPLOYMENT_FLAVOR_NAME_FORMAT_NOT_ALLOWED"; - public static final String INVALID_COMPUTE_FLAVOR_ID = "INVALID_COMPUTE_FLAVOR_ID"; - public static final String INVALID_COMPONENT_ID = "INVALID_COMPONENT_ID"; - public static final String DUPLICATE_COMPUTE_NAME_NOT_ALLOWED = "DUPLICATE_COMPUTE_NAME_NOT_ALLOWED"; - public static final String COMPUTE_NAME_FORMAT_NOT_ALLOWED = "COMPUTE_NAME_FORMAT_NOT_ALLOWED"; - - public static final String DELETE_IMAGE_NOT_ALLOWED = "DELETE_IMAGE_NOT_ALLOWED"; - public static final String UPDATE_IMAGE_NOT_ALLOWED = "UPDATE_IMAGE_NOT_ALLOWED"; - - public static final String INVALID_EXTENSION = "INVALID_EXTENSION"; - - public static final String VSP_ONBOARD_METHOD_UPDATE_NOT_ALLOWED = - "VSP_ONBOARD_METHOD_UPDATE_NOT_ALLOWED"; - - private VendorSoftwareProductErrorCodes(){} + public static final String VSP_NOT_FOUND = "VSP_NOT_FOUND"; + public static final String VSP_INVALID = "VSP_INVALID"; + public static final String VFC_INVALID = "VFC_INVALID"; + public static final String FAILED_TO_CREATE_VSP = "FAILED_TO_CREATE_VSP"; + public static final String UPLOAD_INVALID = "UPLOAD_INVALID"; + public static final String PACKAGE_NOT_FOUND = "PACKAGE_NOT_FOUND"; + public static final String PACKAGE_INVALID = "PACKAGE_INVALID"; + public static final String VSP_COMPOSITION_EDIT_NOT_ALLOWED = "VSP_COMPOSITION_EDIT_NOT_ALLOWED"; + public static final String CREATE_PACKAGE_FOR_NON_FINAL_VSP = "CREATE_PACKAGE_FOR_NON_FINAL_VSP"; + public static final String TRANSLATION_FILE_CREATION = "TRANSLATION_FILE_CREATION"; + public static final String HEAT_PACKAGE_FILE_CREATION = "HEAT_PACKAGE_FILE_CREATION"; + public static final String TOSCA_ENTRY_NOT_FOUND = "TOSCA_ENTRY_NOT_FOUND"; + public static final String TOSCA_INVALID_SUBSTITUTE_NODE_TEMPLATE = "TOSCA_INVALID_SUBSTITUTE_NODE_TEMPLATE"; + public static final String MONITORING_UPLOAD_INVALID = "MONITORING_UPLOAD_INVALID"; + public static final String ORCHESTRATION_NOT_FOUND = "ORCHESTRATION_NOT_FOUND"; + public static final String CYCLIC_DEPENDENCY_IN_COMPONENTS = "CYCLIC_DEPENDENCY_IN_COMPONENTS"; + public static final String INVALID_COMPONENT_RELATION_TYPE = "INVALID_COMPONENT_RELATION_TYPE"; + public static final String NO_SOURCE_COMPONENT = "NO_SOURCE_COMPONENT"; + public static final String SAME_SOURCE_TARGET_COMPONENT = "SAME_SOURCE_TARGET_COMPONENT"; + public static final String DUPLICATE_NIC_NAME_NOT_ALLOWED = "DUPLICATE_NIC_NAME_NOT_ALLOWED"; + public static final String NIC_NAME_FORMAT_NOT_ALLOWED = "NIC_NAME_FORMAT_NOT_ALLOWED"; + public static final String NULL_NETWORKID_NOT_ALLOWED = "NULL_NETWORKID_NOT_ALLOWED"; + public static final String NETWORKID_NOT_ALLOWED_FOR_EXTERNAL_NETWORK = "NETWORKID_NOT_ALLOWED_FOR_EXTERNAL_NETWORK"; + public static final String VFC_ADD_NOT_ALLOWED_IN_HEAT_ONBOARDING = "VFC_ADD_NOT_ALLOWED_IN_HEAT_ONBOARDING"; + public static final String VSP_VFC_COUNT_EXCEED = "VSP_VFC_COUNT_EXCEED"; + public static final String VSP_VFC_DUPLICATE_NAME = "VSP_VFC_DUPLICATE_NAME"; + public static final String VSP_INVALID_ONBOARDING_METHOD = "VSP_INVALID_ONBOARDING_METHOD"; + public static final String ADD_NIC_NOT_ALLOWED_IN_HEAT_ONBOARDING = "ADD_NIC_NOT_ALLOWED_IN_HEAT_ONBOARDING"; + public static final String NETWORK_DESCRIPTION_NOT_ALLOWED_FOR_INTERNAL_NETWORK = "NETWORK_DESCRIPTION_NOT_ALLOWED_FOR_INTERNAL_NETWORK"; + public static final String VFC_ATTRIBUTE_UPDATE_NOT_ALLOWED = "VFC_ATTRIBUTE_UPDATE_NOT_ALLOWED"; + public static final String NETWORK_TYPE_UPDATE_NOT_ALLOWED = "NETWORK_TYPE_UPDATE_NOT_ALLOWED"; + public static final String DELETE_NIC_NOT_ALLOWED = "DELETE_NIC_NOT_ALLOWED"; + public static final String CREATE_DEPLOYMENT_FLAVOR_NOT_ALLOWED_IN_HEAT_ONBOARDING = "CREATE_DEPLOYMENT_FLAVOR_NOT_ALLOWED_IN_HEAT_ONBOARDING"; + public static final String DELETE_DEPLOYMENT_FLAVOR_NOT_ALLOWED_IN_HEAT_ONBOARDING = "DELETE_DEPLOYMENT_FLAVOR_NOT_ALLOWED_IN_HEAT_ONBOARDING"; + public static final String EDIT_DEPLOYMENT_FLAVOR_NOT_ALLOWED_IN_HEAT_ONBOARDING = "EDIT_DEPLOYMENT_FLAVOR_NOT_ALLOWED_IN_HEAT_ONBOARDING"; + public static final String FEATUREGROUP_REQUIRED_IN_DEPLOYMENT_FLAVOR = "FEATUREGROUP_REQUIRED_IN_DEPLOYMENT_FLAVOR"; + public static final String ADD_IMAGE_NOT_ALLOWED_IN_HEAT_ONBOARDING = "ADD_IMAGE_NOT_ALLOWED_IN_HEAT_ONBOARDING"; + public static final String DUPLICATE_IMAGE_NAME_NOT_ALLOWED = "DUPLICATE_IMAGE_NAME_NOT_ALLOWED"; + public static final String DUPLICATE_IMAGE_VERSION_NOT_ALLOWED = "DUPLICATE_IMAGE_VERSION_NOT_ALLOWED"; + public static final String IMAGE_NAME_FORMAT_NOT_ALLOWED = "IMAGE_NAME_FORMAT_NOT_ALLOWED"; + public static final String VFC_IMAGE_INVALID_FORMAT = "VFC_IMAGE_INVALID_FORMAT"; + public static final String FEATURE_GROUP_NOT_EXIST_FOR_VSP = "FEATURE_GROUP_NOT_EXIST_FOR_VSP"; + public static final String ADD_COMPUTE_NOT_ALLOWED_IN_HEAT_ONBOARDING = "ADD_COMPUTE_NOT_ALLOWED_IN_HEAT_ONBOARDING"; + public static final String VFC_COMPUTE_INVALID_FORMAT = "VFC_COMPUTE_INVALID_FORMAT"; + public static final String UPDATE_COMPUTE_NOT_ALLOWED = "UPDATE_COMPUTE_NOT_ALLOWED"; + public static final String INVALID_COMPONENT_COMPUTE_ASSOCIATION = "INVALID_COMPONENT_COMPUTE_ASSOCIATION"; + public static final String SAME_VFC_ASSOCIATION_MORE_THAN_ONCE_NOT_ALLOWED = "SAME_VFC_ASSOCIATION_MORE_THAN_ONCE_NOT_ALLOWED"; + public static final String DUPLICATE_DEPLOYMENT_FLAVOR_MODEL_NOT_ALLOWED = "DUPLICATE_DEPLOYMENT_FLAVOR_MODEL_NOT_ALLOWED"; + public static final String DEPLOYMENT_FLAVOR_NAME_FORMAT_NOT_ALLOWED = "DEPLOYMENT_FLAVOR_NAME_FORMAT_NOT_ALLOWED"; + public static final String INVALID_COMPUTE_FLAVOR_ID = "INVALID_COMPUTE_FLAVOR_ID"; + public static final String INVALID_COMPONENT_ID = "INVALID_COMPONENT_ID"; + public static final String DUPLICATE_COMPUTE_NAME_NOT_ALLOWED = "DUPLICATE_COMPUTE_NAME_NOT_ALLOWED"; + public static final String COMPUTE_NAME_FORMAT_NOT_ALLOWED = "COMPUTE_NAME_FORMAT_NOT_ALLOWED"; + public static final String DELETE_IMAGE_NOT_ALLOWED = "DELETE_IMAGE_NOT_ALLOWED"; + public static final String UPDATE_IMAGE_NOT_ALLOWED = "UPDATE_IMAGE_NOT_ALLOWED"; + public static final String INVALID_EXTENSION = "INVALID_EXTENSION"; + public static final String VSP_ONBOARD_METHOD_UPDATE_NOT_ALLOWED = "VSP_ONBOARD_METHOD_UPDATE_NOT_ALLOWED"; + + private VendorSoftwareProductErrorCodes() { + } } 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/factory/InformationArtifactGeneratorFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/factory/InformationArtifactGeneratorFactoryImpl.java index df5e44122d..90019a2467 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/factory/InformationArtifactGeneratorFactoryImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/factory/InformationArtifactGeneratorFactoryImpl.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,18 +17,15 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.factory; - import org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.InformationArtifactGenerator; import org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactGeneratorImpl; - public class InformationArtifactGeneratorFactoryImpl extends InformationArtifactGeneratorFactory { - @Override - public InformationArtifactGenerator createInterface() { - return new TxtInformationArtifactGeneratorImpl(); - } + @Override + public InformationArtifactGenerator createInterface() { + return new TxtInformationArtifactGeneratorImpl(); + } } 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/factory/QuestionnaireDataServiceFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/factory/QuestionnaireDataServiceFactoryImpl.java index 865c7f1189..3c0cbe5ff3 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/factory/QuestionnaireDataServiceFactoryImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/factory/QuestionnaireDataServiceFactoryImpl.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,18 +17,15 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.factory; - import org.openecomp.sdc.vendorsoftwareproduct.questionnaire.QuestionnaireDataService; import org.openecomp.sdc.vendorsoftwareproduct.quiestionnaire.QuestionnaireDataServiceImpl; - public class QuestionnaireDataServiceFactoryImpl extends QuestionnnaireDataServiceFactory { - @Override - public QuestionnaireDataService createInterface() { - return new QuestionnaireDataServiceImpl(); - } + @Override + public QuestionnaireDataService createInterface() { + return new QuestionnaireDataServiceImpl(); + } } 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/factory/impl/CandidateServiceFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/factory/impl/CandidateServiceFactoryImpl.java index b98605a53d..b777b586d0 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/factory/impl/CandidateServiceFactoryImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/factory/impl/CandidateServiceFactoryImpl.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.factory.impl; import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.OrchestrationTemplateCandidateDaoFactoryImpl; @@ -26,12 +25,11 @@ import org.openecomp.sdc.vendorsoftwareproduct.factory.ManifestCreatorFactory; import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService; import org.openecomp.sdc.vendorsoftwareproduct.services.impl.filedatastructuremodule.CandidateServiceImpl; - public class CandidateServiceFactoryImpl extends CandidateServiceFactory { - @Override - public CandidateService createInterface() { - return new CandidateServiceImpl(ManifestCreatorFactory.getInstance().createInterface(), - OrchestrationTemplateCandidateDaoFactoryImpl.getInstance().createInterface()); - } + @Override + public CandidateService createInterface() { + return new CandidateServiceImpl(ManifestCreatorFactory.getInstance().createInterface(), + OrchestrationTemplateCandidateDaoFactoryImpl.getInstance().createInterface()); + } } 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/factory/impl/CompositionDataExtractorFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/factory/impl/CompositionDataExtractorFactoryImpl.java index 21b0d9c0a8..fe0e82e9f4 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/factory/impl/CompositionDataExtractorFactoryImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/factory/impl/CompositionDataExtractorFactoryImpl.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.factory.impl; import org.openecomp.sdc.vendorsoftwareproduct.factory.CompositionDataExtractorFactory; @@ -26,8 +25,8 @@ import org.openecomp.sdc.vendorsoftwareproduct.services.impl.composition.Composi public class CompositionDataExtractorFactoryImpl extends CompositionDataExtractorFactory { - @Override - public CompositionDataExtractor createInterface() { - return new CompositionDataExtractorImpl(); - } + @Override + public CompositionDataExtractor createInterface() { + return new CompositionDataExtractorImpl(); + } } 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/factory/impl/ManifestCreatorFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/factory/impl/ManifestCreatorFactoryImpl.java index c7d088408e..6700fe977c 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/factory/impl/ManifestCreatorFactoryImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/factory/impl/ManifestCreatorFactoryImpl.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.factory.impl; import org.openecomp.sdc.vendorsoftwareproduct.factory.ManifestCreatorFactory; @@ -29,8 +28,8 @@ import org.openecomp.sdc.vendorsoftwareproduct.services.impl.filedatastructuremo */ public class ManifestCreatorFactoryImpl extends ManifestCreatorFactory { - @Override - public ManifestCreator createInterface(){ - return new ManifestCreatorNamingConventionImpl(); - } + @Override + public ManifestCreator createInterface() { + return new ManifestCreatorNamingConventionImpl(); + } } 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/informationArtifact/impl/TxtInformationArtifactConstants.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/informationArtifact/impl/TxtInformationArtifactConstants.java index 4fee8aec75..28575c77c0 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/informationArtifact/impl/TxtInformationArtifactConstants.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/informationArtifact/impl/TxtInformationArtifactConstants.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,81 +17,68 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl; /** * @author KATYR * @since December 07, 2016 */ - public class TxtInformationArtifactConstants { - public static final String QUOTEMARK = "\""; - public static final String SPACE = " "; - public static final String TAB = SPACE + SPACE + SPACE + SPACE; - public static final String NL = System.lineSeparator(); - public static final String DELIMITER = ":"; - public static final String FOUR_TABS = TAB + TAB + TAB + TAB; - - - public static final String TITLE = "1." + TAB + "VSP Details" + DELIMITER; - public static final String VSP_NAME = "a." + TAB + "Name" + DELIMITER; - public static final String VSP_DESC = "b." + TAB + "Description"; - public static final String VSP_VENDOR = "d." + TAB + "Vendor" + DELIMITER; - public static final String VSP_VERSION = "c." + TAB + "Version" + DELIMITER; - public static final String VSP_CATEGORY = "e." + TAB + "Category" + DELIMITER; - public static final String LICENSE_DETAILS = "f." + TAB + "License Details" + DELIMITER; - public static final String LICENSE_MODEL_VERSION = - "i." + TAB + "License Model Version" + DELIMITER; - public static final String LICENSE_AGREEMENT_NAME = - "ii." + TAB + "License Agreement Name" + DELIMITER; - public static final String LIST_OF_FEATURE_GROUPS = "iii" + TAB + "List of Feature Groups"+DELIMITER; - public static final String HIGH_AVAILABILITY = "g." + TAB + "High Availability"; - public static final String USING_AVAILABILITY_ZONES = "i." + TAB + "Using Availability " - + "Zones" + DELIMITER; - public static final String STORAGE_BACKUP_DETAILS = "h." + TAB + "Storage Data Back-up " - + "Details" + DELIMITER; - public static final String IS_DATA_REPLICATION = - "i." + TAB + "Data Replication Required?" + DELIMITER; - public static final String DATA_SIZE_TO_REP = - "ii." + TAB + " Data Size to replicate in GB" + DELIMITER; - public static final String DATA_REP_FREQUENCY = - "iii." + TAB + "Data replication frequency" + DELIMITER; - public static final String DATA_REP_SOURCE = "iv." + TAB + "Replication Source" + DELIMITER; - public static final String DATA_REP_DEST = "v." + TAB + "Replication Destination" + DELIMITER; - public static final String LIST_OF_NETWORKS = "List of Internal Networks";//currently not used - public static final String LIST_OF_VFCS = "3." + TAB + "List of VFCs"; - public static final String FOR_EACH_VFC = "a." + TAB + "For each VFC" + DELIMITER; - public static final String VFC_NAME = "i." + TAB + "VFC Name" + DELIMITER; - public static final String VFC_DESC = "ii." + TAB + "Description" + DELIMITER; - public static final String VFC_IMAGES = "iii." + TAB + "Images" + DELIMITER; - public static final String VFC_COMPUTE = "iv." + TAB + "Compute/VM Characteristics"; - public static final String VFC_COMPUTE_VCPU = "1." + TAB + "vCPU" + DELIMITER; - public static final String VFC_COMPUTE_CPU_OVER_SUBSCRIPTION = "2." + TAB + "CPU " - + "over-subscription" + DELIMITER; - public static final String VFC_COMPUTE_MEMORY = "3." + TAB + "Memory" + DELIMITER; - public static final String VFC_COMPUTE_DISK = "4." + TAB + "Disk" + DELIMITER; - public static final String HYPERVISOR_DETAILS = "v." + TAB + "Hypervisor Details"; - public static final String HYPERVISOR_DETAILS_NAME = "1." + TAB + "Name" + DELIMITER; - public static final String HYPERVISOR_DETAILS_DRIVERS = "2." + TAB + "Drivers" + DELIMITER; - public static final String GUEST_OS_DETAILS = "vi." + TAB + "Guest OS Details"; - public static final String GUEST_OS_NAME = "1." + TAB + "Name" + DELIMITER; - public static final String GUEST_OS_BIT_SIZE = "2." + TAB + "Bit Size" + DELIMITER; - public static final String GUEST_OS_TOOLS = "3." + TAB + "Tools" + DELIMITER; - public static final String VFC_INSTANCE_NUMBER = "vii." + TAB + "Number of VFC Instances"; - public static final String VFC_INSTANCE_NUMBER_MIN = "1." + TAB + "Minimum" + DELIMITER; - public static final String VFC_INSTANCE_NUMBER_MAX = "2." + TAB + "Maximum" + DELIMITER; - public static final String VNICS = "viii." + TAB + "vNICs"; - public static final String VNICS_NAME = "1." + TAB + "Name" + DELIMITER; - public static final String VNICS_PURPOSE = "2." + TAB + "Purpose" + DELIMITER; - public static final String VNICS_INT_EXT = "3." + TAB + "Internal/External" + DELIMITER; - public static final String VNICS_NETWORK = "4." + TAB + "Network" + DELIMITER; - public static final String VNICS_PROTOCOLS = "5." + TAB + "Protocols" + DELIMITER; - public static final String VNICS_IPV4 = "6." + TAB + "IP v4 Required" + DELIMITER; - public static final String VNICS_IPV6 = "7." + TAB + "IP v6 Required" + DELIMITER; - public static final String RECOVERY_DETAILS = "ix." + TAB + "Recovery Details" + DELIMITER; - public static final String RECOVERY_DETAILS_POINT = "1." + TAB + "Recovery Point" + DELIMITER; - public static final String RECOVERY_DETAILS_TIME = "2." + TAB + "Recovery Time" + DELIMITER; - + public static final String QUOTEMARK = "\""; + public static final String SPACE = " "; + public static final String TAB = SPACE + SPACE + SPACE + SPACE; + public static final String NL = System.lineSeparator(); + public static final String DELIMITER = ":"; + public static final String FOUR_TABS = TAB + TAB + TAB + TAB; + public static final String TITLE = "1." + TAB + "VSP Details" + DELIMITER; + public static final String VSP_NAME = "a." + TAB + "Name" + DELIMITER; + public static final String VSP_DESC = "b." + TAB + "Description"; + public static final String VSP_VENDOR = "d." + TAB + "Vendor" + DELIMITER; + public static final String VSP_VERSION = "c." + TAB + "Version" + DELIMITER; + public static final String VSP_CATEGORY = "e." + TAB + "Category" + DELIMITER; + public static final String LICENSE_DETAILS = "f." + TAB + "License Details" + DELIMITER; + public static final String LICENSE_MODEL_VERSION = "i." + TAB + "License Model Version" + DELIMITER; + public static final String LICENSE_AGREEMENT_NAME = "ii." + TAB + "License Agreement Name" + DELIMITER; + public static final String LIST_OF_FEATURE_GROUPS = "iii" + TAB + "List of Feature Groups" + DELIMITER; + public static final String HIGH_AVAILABILITY = "g." + TAB + "High Availability"; + public static final String USING_AVAILABILITY_ZONES = "i." + TAB + "Using Availability " + "Zones" + DELIMITER; + public static final String STORAGE_BACKUP_DETAILS = "h." + TAB + "Storage Data Back-up " + "Details" + DELIMITER; + public static final String IS_DATA_REPLICATION = "i." + TAB + "Data Replication Required?" + DELIMITER; + public static final String DATA_SIZE_TO_REP = "ii." + TAB + " Data Size to replicate in GB" + DELIMITER; + public static final String DATA_REP_FREQUENCY = "iii." + TAB + "Data replication frequency" + DELIMITER; + public static final String DATA_REP_SOURCE = "iv." + TAB + "Replication Source" + DELIMITER; + public static final String DATA_REP_DEST = "v." + TAB + "Replication Destination" + DELIMITER; + public static final String LIST_OF_NETWORKS = "List of Internal Networks";//currently not used + public static final String LIST_OF_VFCS = "3." + TAB + "List of VFCs"; + public static final String FOR_EACH_VFC = "a." + TAB + "For each VFC" + DELIMITER; + public static final String VFC_NAME = "i." + TAB + "VFC Name" + DELIMITER; + public static final String VFC_DESC = "ii." + TAB + "Description" + DELIMITER; + public static final String VFC_IMAGES = "iii." + TAB + "Images" + DELIMITER; + public static final String VFC_COMPUTE = "iv." + TAB + "Compute/VM Characteristics"; + public static final String VFC_COMPUTE_VCPU = "1." + TAB + "vCPU" + DELIMITER; + public static final String VFC_COMPUTE_CPU_OVER_SUBSCRIPTION = "2." + TAB + "CPU " + "over-subscription" + DELIMITER; + public static final String VFC_COMPUTE_MEMORY = "3." + TAB + "Memory" + DELIMITER; + public static final String VFC_COMPUTE_DISK = "4." + TAB + "Disk" + DELIMITER; + public static final String HYPERVISOR_DETAILS = "v." + TAB + "Hypervisor Details"; + public static final String HYPERVISOR_DETAILS_NAME = "1." + TAB + "Name" + DELIMITER; + public static final String HYPERVISOR_DETAILS_DRIVERS = "2." + TAB + "Drivers" + DELIMITER; + public static final String GUEST_OS_DETAILS = "vi." + TAB + "Guest OS Details"; + public static final String GUEST_OS_NAME = "1." + TAB + "Name" + DELIMITER; + public static final String GUEST_OS_BIT_SIZE = "2." + TAB + "Bit Size" + DELIMITER; + public static final String GUEST_OS_TOOLS = "3." + TAB + "Tools" + DELIMITER; + public static final String VFC_INSTANCE_NUMBER = "vii." + TAB + "Number of VFC Instances"; + public static final String VFC_INSTANCE_NUMBER_MIN = "1." + TAB + "Minimum" + DELIMITER; + public static final String VFC_INSTANCE_NUMBER_MAX = "2." + TAB + "Maximum" + DELIMITER; + public static final String VNICS = "viii." + TAB + "vNICs"; + public static final String VNICS_NAME = "1." + TAB + "Name" + DELIMITER; + public static final String VNICS_PURPOSE = "2." + TAB + "Purpose" + DELIMITER; + public static final String VNICS_INT_EXT = "3." + TAB + "Internal/External" + DELIMITER; + public static final String VNICS_NETWORK = "4." + TAB + "Network" + DELIMITER; + public static final String VNICS_PROTOCOLS = "5." + TAB + "Protocols" + DELIMITER; + public static final String VNICS_IPV4 = "6." + TAB + "IP v4 Required" + DELIMITER; + public static final String VNICS_IPV6 = "7." + TAB + "IP v6 Required" + DELIMITER; + public static final String RECOVERY_DETAILS = "ix." + TAB + "Recovery Details" + DELIMITER; + public static final String RECOVERY_DETAILS_POINT = "1." + TAB + "Recovery Point" + DELIMITER; + public static final String RECOVERY_DETAILS_TIME = "2." + TAB + "Recovery Time" + DELIMITER; } 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/informationArtifact/impl/TxtInformationArtifactGeneratorImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/informationArtifact/impl/TxtInformationArtifactGeneratorImpl.java index e69ca8d149..7a50d9aab8 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/informationArtifact/impl/TxtInformationArtifactGeneratorImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/informationArtifact/impl/TxtInformationArtifactGeneratorImpl.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,9 +17,63 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.DATA_REP_DEST; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.DATA_REP_FREQUENCY; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.DATA_REP_SOURCE; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.DATA_SIZE_TO_REP; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.FOR_EACH_VFC; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.GUEST_OS_BIT_SIZE; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.GUEST_OS_DETAILS; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.GUEST_OS_NAME; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.GUEST_OS_TOOLS; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.HIGH_AVAILABILITY; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.HYPERVISOR_DETAILS; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.HYPERVISOR_DETAILS_DRIVERS; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.HYPERVISOR_DETAILS_NAME; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.IS_DATA_REPLICATION; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.LICENSE_AGREEMENT_NAME; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.LICENSE_DETAILS; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.LICENSE_MODEL_VERSION; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.LIST_OF_FEATURE_GROUPS; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.LIST_OF_VFCS; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.NL; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.RECOVERY_DETAILS; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.RECOVERY_DETAILS_POINT; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.RECOVERY_DETAILS_TIME; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.SPACE; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.STORAGE_BACKUP_DETAILS; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.TAB; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.TITLE; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.USING_AVAILABILITY_ZONES; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.VFC_COMPUTE; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.VFC_COMPUTE_CPU_OVER_SUBSCRIPTION; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.VFC_COMPUTE_DISK; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.VFC_COMPUTE_MEMORY; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.VFC_COMPUTE_VCPU; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.VFC_DESC; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.VFC_IMAGES; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.VFC_INSTANCE_NUMBER; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.VFC_INSTANCE_NUMBER_MAX; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.VFC_INSTANCE_NUMBER_MIN; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.VFC_NAME; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.VNICS; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.VNICS_INT_EXT; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.VNICS_IPV4; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.VNICS_IPV6; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.VNICS_NAME; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.VNICS_NETWORK; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.VNICS_PROTOCOLS; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.VNICS_PURPOSE; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.VSP_CATEGORY; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.VSP_DESC; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.VSP_NAME; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.VSP_VENDOR; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.VSP_VERSION; + +import java.util.List; +import java.util.Optional; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; import org.openecomp.sdc.vendorsoftwareproduct.factory.QuestionnnaireDataServiceFactory; import org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.InformationArtifactData; @@ -40,223 +94,149 @@ import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.vsp.general.G import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.vsp.general.StorageDataReplication; import org.openecomp.sdc.versioning.dao.types.Version; -import java.util.List; -import java.util.Optional; - -import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.*; - /** * @author katyr * @since November 23, 2016 */ - public class TxtInformationArtifactGeneratorImpl implements InformationArtifactGenerator { - private QuestionnaireDataService questionnaireDataService = QuestionnnaireDataServiceFactory - .getInstance().createInterface(); - private StringBuilder textArtifact; - @Override - public String generate(String vspId, Version version) { - InformationArtifactData informationArtifactData = - questionnaireDataService.generateQuestionnaireDataForInformationArtifact(vspId, version); - return createTxtArtifact(informationArtifactData); - } - private String createTxtArtifact(InformationArtifactData informationArtifactData) { - textArtifact = new StringBuilder(); - addVspVlmEntries(informationArtifactData); - addAvailabilityEntries(); - addDataEntries(informationArtifactData); - addEntryWithIndent(LIST_OF_VFCS, "", TAB); - addEntryWithIndent(FOR_EACH_VFC, "", TAB + TAB); - List componentQuestionnaires = - informationArtifactData.getComponentQuestionnaires(); - - for (ComponentQuestionnaire componentQuestionnaire : componentQuestionnaires) { - addEntriesPerComponent(componentQuestionnaire); + private QuestionnaireDataService questionnaireDataService = QuestionnnaireDataServiceFactory.getInstance().createInterface(); + private StringBuilder textArtifact; + static String roundVersionAsNeeded(Version version) { + if (version.isFinal()) { + return version.toString(); + } else { + return String.valueOf(Math.ceil(Double.valueOf(version.toString()))); + } } - List nicQuestionnaires = informationArtifactData.getNicQuestionnaires(); - for (NicQuestionnaire nicQuestionnaire : nicQuestionnaires) { - addEntriesPerNic(nicQuestionnaire); - + @Override + public String generate(String vspId, Version version) { + InformationArtifactData informationArtifactData = questionnaireDataService.generateQuestionnaireDataForInformationArtifact(vspId, version); + return createTxtArtifact(informationArtifactData); } - for (ComponentQuestionnaire componentQuestionnaire : componentQuestionnaires) { - addRecoveryEntriesPerComponent(componentQuestionnaire); - } - return textArtifact.toString(); - - } - - private void addDataEntries(InformationArtifactData informationArtifactData) { - addEntryWithIndent(STORAGE_BACKUP_DETAILS, "", TAB); - - Optional storageDataReplication = - Optional.of(informationArtifactData).map(InformationArtifactData::getVspQuestionnaire) - .map(VspQuestionnaire::getGeneral).map(General::getStorageDataReplication); - storageDataReplication - .ifPresent(replication -> addEntryWithIndent(IS_DATA_REPLICATION, - String.valueOf(replication.isStorageReplicationAcrossRegion()), TAB + TAB)); - - storageDataReplication.ifPresent(rep -> addEntryWithIndent(DATA_SIZE_TO_REP, - String.valueOf(rep.getStorageReplicationSize()), TAB + TAB)); - - storageDataReplication.ifPresent(rep -> addEntryWithIndent(DATA_REP_FREQUENCY, - String.valueOf(rep.getStorageReplicationFrequency()), TAB + TAB)); - - storageDataReplication.ifPresent(rep -> addEntryWithIndent(DATA_REP_SOURCE, - String.valueOf(rep.getStorageReplicationSource()), TAB + TAB)); - - storageDataReplication.ifPresent(rep -> addEntryWithIndent(DATA_REP_DEST, - String.valueOf(rep.getStorageReplicationDestination()), TAB + TAB)); - } + private String createTxtArtifact(InformationArtifactData informationArtifactData) { + textArtifact = new StringBuilder(); + addVspVlmEntries(informationArtifactData); + addAvailabilityEntries(); + addDataEntries(informationArtifactData); + addEntryWithIndent(LIST_OF_VFCS, "", TAB); + addEntryWithIndent(FOR_EACH_VFC, "", TAB + TAB); + List componentQuestionnaires = informationArtifactData.getComponentQuestionnaires(); + for (ComponentQuestionnaire componentQuestionnaire : componentQuestionnaires) { + addEntriesPerComponent(componentQuestionnaire); + } + List nicQuestionnaires = informationArtifactData.getNicQuestionnaires(); + for (NicQuestionnaire nicQuestionnaire : nicQuestionnaires) { + addEntriesPerNic(nicQuestionnaire); + } + for (ComponentQuestionnaire componentQuestionnaire : componentQuestionnaires) { + addRecoveryEntriesPerComponent(componentQuestionnaire); + } + return textArtifact.toString(); + } - private void addAvailabilityEntries() { - addEntryWithIndent(HIGH_AVAILABILITY, "", TAB); + private void addDataEntries(InformationArtifactData informationArtifactData) { + addEntryWithIndent(STORAGE_BACKUP_DETAILS, "", TAB); + Optional storageDataReplication = Optional.of(informationArtifactData) + .map(InformationArtifactData::getVspQuestionnaire).map(VspQuestionnaire::getGeneral).map(General::getStorageDataReplication); + storageDataReplication.ifPresent( + replication -> addEntryWithIndent(IS_DATA_REPLICATION, String.valueOf(replication.isStorageReplicationAcrossRegion()), TAB + TAB)); + storageDataReplication.ifPresent(rep -> addEntryWithIndent(DATA_SIZE_TO_REP, String.valueOf(rep.getStorageReplicationSize()), TAB + TAB)); + storageDataReplication + .ifPresent(rep -> addEntryWithIndent(DATA_REP_FREQUENCY, String.valueOf(rep.getStorageReplicationFrequency()), TAB + TAB)); + storageDataReplication.ifPresent(rep -> addEntryWithIndent(DATA_REP_SOURCE, String.valueOf(rep.getStorageReplicationSource()), TAB + TAB)); + storageDataReplication.ifPresent(rep -> addEntryWithIndent(DATA_REP_DEST, String.valueOf(rep.getStorageReplicationDestination()), TAB + TAB)); + } - Optional availability = - Optional.of(new InformationArtifactData()).map(InformationArtifactData::getVspQuestionnaire) + private void addAvailabilityEntries() { + addEntryWithIndent(HIGH_AVAILABILITY, "", TAB); + Optional availability = Optional.of(new InformationArtifactData()).map(InformationArtifactData::getVspQuestionnaire) .map(VspQuestionnaire::getGeneral).map(General::getAvailability); - availability - .ifPresent(availabilityVal -> addEntryWithIndent(USING_AVAILABILITY_ZONES, String.valueOf( - availabilityVal.isUseAvailabilityZonesForHighAvailability()), TAB + TAB)); - } - - private void addVspVlmEntries(InformationArtifactData informationArtifactData) { - addEntryWithIndent(TITLE, "", ""); - Optional vspDetails = Optional.of(informationArtifactData).map - (InformationArtifactData::getVspDetails); - addEntryWithIndent(VSP_NAME, informationArtifactData.getVspDetails().getName(), TAB); - addEntryWithIndent(VSP_DESC, informationArtifactData.getVspDetails().getDescription(), TAB); - addEntryWithIndent(VSP_VERSION, - roundVersionAsNeeded(informationArtifactData.getVspDetails().getVersion()), TAB); - addEntryWithIndent(VSP_VENDOR, informationArtifactData.getVspDetails().getVendorName(), TAB); - addEntryWithIndent(VSP_CATEGORY, informationArtifactData.getVspDetails().getCategory(), TAB); - addEntryWithIndent(LICENSE_DETAILS, "", TAB); - addEntryWithIndent(LICENSE_MODEL_VERSION, - informationArtifactData.getVspDetails().getVlmVersion() == null - ? "" - : informationArtifactData.getVspDetails().getVlmVersion().toString(), - TAB + TAB); - addEntryWithIndent(LICENSE_AGREEMENT_NAME, informationArtifactData.getVspDetails() - .getLicenseAgreement(), TAB + TAB); - addEntryWithIndent(LIST_OF_FEATURE_GROUPS, "", TAB + TAB); - vspDetails.ifPresent(vspDets -> addListEntriesWithIndent(vspDets - .getFeatureGroups(), TAB + TAB + TAB)); - } - - static String roundVersionAsNeeded(Version version) { - if (version.isFinal()) { - return version.toString(); - } else { - return String.valueOf(Math.ceil(Double.valueOf(version.toString()))); + availability.ifPresent(availabilityVal -> addEntryWithIndent(USING_AVAILABILITY_ZONES, + String.valueOf(availabilityVal.isUseAvailabilityZonesForHighAvailability()), TAB + TAB)); } - } - - private void addRecoveryEntriesPerComponent(ComponentQuestionnaire componentQuestionnaire) { - addEntryWithIndent(RECOVERY_DETAILS, "", TAB + TAB + TAB); - Optional recovery = Optional.of(componentQuestionnaire).map( - ComponentQuestionnaire::getGeneral).map( - org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.general - .General::getRecovery); - recovery.ifPresent(recoveryVal -> addEntryWithIndent(RECOVERY_DETAILS_POINT, String.valueOf( - recoveryVal.getPointObjective()), TAB + TAB + TAB + TAB)); - - recovery.ifPresent(recoveryVal -> addEntryWithIndent(RECOVERY_DETAILS_TIME, String.valueOf( - recoveryVal.getTimeObjective()), TAB + TAB + TAB + TAB)); - } - - private void addEntriesPerNic(NicQuestionnaire nicQuestionnaire) { - addEntryWithIndent(VNICS, "", TAB + TAB + TAB); - Optional networkOpt = Optional.of(nicQuestionnaire).map( - NicQuestionnaire::getNetwork); - - networkOpt.ifPresent(network -> addEntryWithIndent(VNICS_NAME, network - .getNetworkDescription(), - TAB + TAB + TAB + TAB)); - networkOpt.ifPresent(network -> addEntryWithIndent(VNICS_PURPOSE, network - .getNetworkDescription(), TAB + TAB + TAB + TAB)); - networkOpt.ifPresent(network -> addEntryWithIndent(VNICS_INT_EXT, network - .getNetworkDescription(), TAB + TAB + TAB + TAB)); - networkOpt.ifPresent(network -> addEntryWithIndent(VNICS_NETWORK, network.toString(), - TAB + TAB + TAB + TAB)); - addEntryWithIndent(VNICS_PROTOCOLS, nicQuestionnaire.getProtocols() == null ? "" : nicQuestionnaire.getProtocols().toString(), - TAB + TAB + TAB + TAB); - - Optional ipconfigOpt = Optional.of(nicQuestionnaire).map - (NicQuestionnaire::getIpConfiguration); - ipconfigOpt.ifPresent(ipconfig -> addEntryWithIndent(VNICS_IPV4, String.valueOf(ipconfig - .isIpv4Required()), TAB + TAB + TAB + TAB)); - ipconfigOpt.ifPresent(ipconfig -> addEntryWithIndent(VNICS_IPV6, String.valueOf(ipconfig - .isIpv6Required()), TAB + TAB + TAB + TAB)); - } - - private void addEntriesPerComponent(ComponentQuestionnaire componentQuestionnaire) { - addEntryWithIndent(VFC_NAME, "", TAB + TAB + TAB); - addEntryWithIndent(VFC_DESC, "", TAB + TAB + TAB); - addEntryWithIndent(VFC_IMAGES, "", TAB + TAB + TAB); - //todo component name +desc +img+vcpu - addEntryWithIndent(VFC_COMPUTE, "", TAB + TAB + TAB); - addEntryWithIndent(VFC_COMPUTE_VCPU, "", TAB + TAB + TAB + TAB); - addEntryWithIndent(VFC_COMPUTE_CPU_OVER_SUBSCRIPTION, "", - TAB + TAB + TAB + TAB); - addEntryWithIndent(VFC_COMPUTE_MEMORY, "", TAB + TAB + TAB + TAB); - addEntryWithIndent(VFC_COMPUTE_DISK, "", TAB + TAB + TAB + TAB); - - addEntryWithIndent(HYPERVISOR_DETAILS, "", TAB + TAB + TAB); - - Optional hypervisorOpt = Optional.of(componentQuestionnaire).map( - ComponentQuestionnaire::getGeneral).map( - org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.general - .General::getHypervisor); - hypervisorOpt.ifPresent(hypervisor -> addEntryWithIndent(HYPERVISOR_DETAILS_NAME, hypervisor - .getHypervisor(), TAB - + TAB + TAB + TAB)); - - hypervisorOpt.ifPresent(hypervisor -> addEntryWithIndent(HYPERVISOR_DETAILS_DRIVERS, hypervisor - .getDrivers(), TAB + TAB + TAB + TAB)); - addEntryWithIndent(GUEST_OS_DETAILS, "", TAB + TAB + TAB); - Optional guestOSOptional = Optional.of(componentQuestionnaire).map - (ComponentQuestionnaire::getCompute).map(Compute::getGuestOS); - guestOSOptional.ifPresent(guestOs -> addEntryWithIndent(GUEST_OS_NAME, guestOs.getName(), - TAB + TAB + TAB + TAB)); - - - guestOSOptional - .ifPresent(guestOs -> addEntryWithIndent(GUEST_OS_BIT_SIZE, String.valueOf(guestOs - .getBitSize()), TAB + TAB + TAB + TAB)); - guestOSOptional.ifPresent(guestOs -> addEntryWithIndent(GUEST_OS_TOOLS, guestOs.getTools - (), TAB + TAB + TAB + TAB)); - - addEntryWithIndent(VFC_INSTANCE_NUMBER, "", - TAB + TAB + TAB); - - Optional numVmsOpt = Optional.of(componentQuestionnaire).map - (ComponentQuestionnaire::getCompute).map(Compute::getNumOfVMs); - numVmsOpt.ifPresent(numVms -> addEntryWithIndent(VFC_INSTANCE_NUMBER_MIN, String.valueOf - (numVms.getMinimum()), TAB + TAB + TAB + TAB)); - - numVmsOpt.ifPresent(numVms -> addEntryWithIndent(VFC_INSTANCE_NUMBER_MAX, String.valueOf - (numVms.getMaximum()), TAB + TAB + TAB + TAB)); - } + private void addVspVlmEntries(InformationArtifactData informationArtifactData) { + addEntryWithIndent(TITLE, "", ""); + Optional vspDetails = Optional.of(informationArtifactData).map(InformationArtifactData::getVspDetails); + addEntryWithIndent(VSP_NAME, informationArtifactData.getVspDetails().getName(), TAB); + addEntryWithIndent(VSP_DESC, informationArtifactData.getVspDetails().getDescription(), TAB); + addEntryWithIndent(VSP_VERSION, roundVersionAsNeeded(informationArtifactData.getVspDetails().getVersion()), TAB); + addEntryWithIndent(VSP_VENDOR, informationArtifactData.getVspDetails().getVendorName(), TAB); + addEntryWithIndent(VSP_CATEGORY, informationArtifactData.getVspDetails().getCategory(), TAB); + addEntryWithIndent(LICENSE_DETAILS, "", TAB); + addEntryWithIndent(LICENSE_MODEL_VERSION, + informationArtifactData.getVspDetails().getVlmVersion() == null ? "" : informationArtifactData.getVspDetails().getVlmVersion().toString(), + TAB + TAB); + addEntryWithIndent(LICENSE_AGREEMENT_NAME, informationArtifactData.getVspDetails().getLicenseAgreement(), TAB + TAB); + addEntryWithIndent(LIST_OF_FEATURE_GROUPS, "", TAB + TAB); + vspDetails.ifPresent(vspDets -> addListEntriesWithIndent(vspDets.getFeatureGroups(), TAB + TAB + TAB)); + } - private void addListEntriesWithIndent(List fieldValues, String indent) { - int counter = 1; - if (fieldValues == null) { - return; + private void addRecoveryEntriesPerComponent(ComponentQuestionnaire componentQuestionnaire) { + addEntryWithIndent(RECOVERY_DETAILS, "", TAB + TAB + TAB); + Optional recovery = Optional.of(componentQuestionnaire).map(ComponentQuestionnaire::getGeneral) + .map(org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.general.General::getRecovery); + recovery.ifPresent( + recoveryVal -> addEntryWithIndent(RECOVERY_DETAILS_POINT, String.valueOf(recoveryVal.getPointObjective()), TAB + TAB + TAB + TAB)); + recovery.ifPresent( + recoveryVal -> addEntryWithIndent(RECOVERY_DETAILS_TIME, String.valueOf(recoveryVal.getTimeObjective()), TAB + TAB + TAB + TAB)); } - for (String fieldValue : fieldValues) { - textArtifact.append(indent).append(counter++).append(".").append(TAB).append(fieldValue) - .append - (NL); + + private void addEntriesPerNic(NicQuestionnaire nicQuestionnaire) { + addEntryWithIndent(VNICS, "", TAB + TAB + TAB); + Optional networkOpt = Optional.of(nicQuestionnaire).map(NicQuestionnaire::getNetwork); + networkOpt.ifPresent(network -> addEntryWithIndent(VNICS_NAME, network.getNetworkDescription(), TAB + TAB + TAB + TAB)); + networkOpt.ifPresent(network -> addEntryWithIndent(VNICS_PURPOSE, network.getNetworkDescription(), TAB + TAB + TAB + TAB)); + networkOpt.ifPresent(network -> addEntryWithIndent(VNICS_INT_EXT, network.getNetworkDescription(), TAB + TAB + TAB + TAB)); + networkOpt.ifPresent(network -> addEntryWithIndent(VNICS_NETWORK, network.toString(), TAB + TAB + TAB + TAB)); + addEntryWithIndent(VNICS_PROTOCOLS, nicQuestionnaire.getProtocols() == null ? "" : nicQuestionnaire.getProtocols().toString(), + TAB + TAB + TAB + TAB); + Optional ipconfigOpt = Optional.of(nicQuestionnaire).map(NicQuestionnaire::getIpConfiguration); + ipconfigOpt.ifPresent(ipconfig -> addEntryWithIndent(VNICS_IPV4, String.valueOf(ipconfig.isIpv4Required()), TAB + TAB + TAB + TAB)); + ipconfigOpt.ifPresent(ipconfig -> addEntryWithIndent(VNICS_IPV6, String.valueOf(ipconfig.isIpv6Required()), TAB + TAB + TAB + TAB)); } - } + private void addEntriesPerComponent(ComponentQuestionnaire componentQuestionnaire) { + addEntryWithIndent(VFC_NAME, "", TAB + TAB + TAB); + addEntryWithIndent(VFC_DESC, "", TAB + TAB + TAB); + addEntryWithIndent(VFC_IMAGES, "", TAB + TAB + TAB); + //todo component name +desc +img+vcpu + addEntryWithIndent(VFC_COMPUTE, "", TAB + TAB + TAB); + addEntryWithIndent(VFC_COMPUTE_VCPU, "", TAB + TAB + TAB + TAB); + addEntryWithIndent(VFC_COMPUTE_CPU_OVER_SUBSCRIPTION, "", TAB + TAB + TAB + TAB); + addEntryWithIndent(VFC_COMPUTE_MEMORY, "", TAB + TAB + TAB + TAB); + addEntryWithIndent(VFC_COMPUTE_DISK, "", TAB + TAB + TAB + TAB); + addEntryWithIndent(HYPERVISOR_DETAILS, "", TAB + TAB + TAB); + Optional hypervisorOpt = Optional.of(componentQuestionnaire).map(ComponentQuestionnaire::getGeneral) + .map(org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.general.General::getHypervisor); + hypervisorOpt.ifPresent(hypervisor -> addEntryWithIndent(HYPERVISOR_DETAILS_NAME, hypervisor.getHypervisor(), TAB + TAB + TAB + TAB)); + hypervisorOpt.ifPresent(hypervisor -> addEntryWithIndent(HYPERVISOR_DETAILS_DRIVERS, hypervisor.getDrivers(), TAB + TAB + TAB + TAB)); + addEntryWithIndent(GUEST_OS_DETAILS, "", TAB + TAB + TAB); + Optional guestOSOptional = Optional.of(componentQuestionnaire).map(ComponentQuestionnaire::getCompute).map(Compute::getGuestOS); + guestOSOptional.ifPresent(guestOs -> addEntryWithIndent(GUEST_OS_NAME, guestOs.getName(), TAB + TAB + TAB + TAB)); + guestOSOptional.ifPresent(guestOs -> addEntryWithIndent(GUEST_OS_BIT_SIZE, String.valueOf(guestOs.getBitSize()), TAB + TAB + TAB + TAB)); + guestOSOptional.ifPresent(guestOs -> addEntryWithIndent(GUEST_OS_TOOLS, guestOs.getTools(), TAB + TAB + TAB + TAB)); + addEntryWithIndent(VFC_INSTANCE_NUMBER, "", TAB + TAB + TAB); + Optional numVmsOpt = Optional.of(componentQuestionnaire).map(ComponentQuestionnaire::getCompute).map(Compute::getNumOfVMs); + numVmsOpt.ifPresent(numVms -> addEntryWithIndent(VFC_INSTANCE_NUMBER_MIN, String.valueOf(numVms.getMinimum()), TAB + TAB + TAB + TAB)); + numVmsOpt.ifPresent(numVms -> addEntryWithIndent(VFC_INSTANCE_NUMBER_MAX, String.valueOf(numVms.getMaximum()), TAB + TAB + TAB + TAB)); + } + private void addListEntriesWithIndent(List fieldValues, String indent) { + int counter = 1; + if (fieldValues == null) { + return; + } + for (String fieldValue : fieldValues) { + textArtifact.append(indent).append(counter++).append(".").append(TAB).append(fieldValue).append(NL); + } + } - private void addEntryWithIndent(String fieldName, String fieldValue, String indent) { - textArtifact.append(indent).append(fieldName).append(SPACE).append(fieldValue).append(NL); - } + private void addEntryWithIndent(String fieldName, String fieldValue, String indent) { + textArtifact.append(indent).append(fieldName).append(SPACE).append(fieldValue).append(NL); + } } 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/quiestionnaire/QuestionnaireDataServiceImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/quiestionnaire/QuestionnaireDataServiceImpl.java index 3af6dfc598..0142091176 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/quiestionnaire/QuestionnaireDataServiceImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/quiestionnaire/QuestionnaireDataServiceImpl.java @@ -13,13 +13,23 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.vendorsoftwareproduct.quiestionnaire; - +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; import org.openecomp.core.utilities.json.JsonUtil; -import org.openecomp.sdc.vendorsoftwareproduct.dao.*; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.*; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.CompositionEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspQuestionnaireEntity; import org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.InformationArtifactData; import org.openecomp.sdc.vendorsoftwareproduct.questionnaire.QuestionnaireDataService; import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.ComponentQuestionnaire; @@ -27,67 +37,47 @@ import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.nic.NicQuesti import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.vsp.VspQuestionnaire; import org.openecomp.sdc.versioning.dao.types.Version; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - /** * Created by TALIO on 11/22/2016 */ public class QuestionnaireDataServiceImpl implements QuestionnaireDataService { - private static final ComponentDao componentDao = - ComponentDaoFactory.getInstance().createInterface(); - private static final NicDao nicDao = NicDaoFactory.getInstance().createInterface(); - private static final VendorSoftwareProductInfoDao vspInfoDao = - VendorSoftwareProductInfoDaoFactory.getInstance().createInterface(); - @Override - public InformationArtifactData generateQuestionnaireDataForInformationArtifact(String vspId, - Version version) { - VspDetails vspDetails = vspInfoDao.get(new VspDetails(vspId, version)); - Collection componentEntities = componentDao.listQuestionnaires(vspId, version); - Collection nicEntities = nicDao.listByVsp(vspId, version); - VspQuestionnaire vspQuestionnaire = getVspQuestionnaireFromJson(vspId, version); - List componentQuestionnaireList = - getListOfComponentQuestionnaireFromJson(componentEntities); - List nicQuestionnaireList = getListOfNicQuestionnaireFromJson(nicEntities); - return new InformationArtifactData(vspDetails, vspQuestionnaire, componentQuestionnaireList, - nicQuestionnaireList); - } - - private VspQuestionnaire getVspQuestionnaireFromJson(String vspId, Version version) { - VspQuestionnaireEntity vspQuestionnaireEntity = - vspInfoDao.getQuestionnaire(vspId, version); - - if (vspQuestionnaireEntity == null) { - return null; + private static final ComponentDao componentDao = ComponentDaoFactory.getInstance().createInterface(); + private static final NicDao nicDao = NicDaoFactory.getInstance().createInterface(); + private static final VendorSoftwareProductInfoDao vspInfoDao = VendorSoftwareProductInfoDaoFactory.getInstance().createInterface(); + + @Override + public InformationArtifactData generateQuestionnaireDataForInformationArtifact(String vspId, Version version) { + VspDetails vspDetails = vspInfoDao.get(new VspDetails(vspId, version)); + Collection componentEntities = componentDao.listQuestionnaires(vspId, version); + Collection nicEntities = nicDao.listByVsp(vspId, version); + VspQuestionnaire vspQuestionnaire = getVspQuestionnaireFromJson(vspId, version); + List componentQuestionnaireList = getListOfComponentQuestionnaireFromJson(componentEntities); + List nicQuestionnaireList = getListOfNicQuestionnaireFromJson(nicEntities); + return new InformationArtifactData(vspDetails, vspQuestionnaire, componentQuestionnaireList, nicQuestionnaireList); } - return JsonUtil - .json2Object(vspQuestionnaireEntity.getQuestionnaireData(), VspQuestionnaire.class); - } - - private List getListOfComponentQuestionnaireFromJson( - Collection entities) { - List componentQuestionnaireList = new ArrayList<>(); - - for (CompositionEntity componentEntity : entities) { - componentQuestionnaireList.add(JsonUtil - .json2Object(componentEntity.getQuestionnaireData(), ComponentQuestionnaire.class)); + private VspQuestionnaire getVspQuestionnaireFromJson(String vspId, Version version) { + VspQuestionnaireEntity vspQuestionnaireEntity = vspInfoDao.getQuestionnaire(vspId, version); + if (vspQuestionnaireEntity == null) { + return null; + } + return JsonUtil.json2Object(vspQuestionnaireEntity.getQuestionnaireData(), VspQuestionnaire.class); } - return componentQuestionnaireList; - } - - private List getListOfNicQuestionnaireFromJson(Collection entities) { - List nicQuestionnaireList = new ArrayList<>(); - - for (NicEntity nicEntity : entities) { - nicQuestionnaireList - .add(JsonUtil.json2Object(nicEntity.getQuestionnaireData(), NicQuestionnaire.class)); + private List getListOfComponentQuestionnaireFromJson(Collection entities) { + List componentQuestionnaireList = new ArrayList<>(); + for (CompositionEntity componentEntity : entities) { + componentQuestionnaireList.add(JsonUtil.json2Object(componentEntity.getQuestionnaireData(), ComponentQuestionnaire.class)); + } + return componentQuestionnaireList; } - return nicQuestionnaireList; - } - + private List getListOfNicQuestionnaireFromJson(Collection entities) { + List nicQuestionnaireList = new ArrayList<>(); + for (NicEntity nicEntity : entities) { + nicQuestionnaireList.add(JsonUtil.json2Object(nicEntity.getQuestionnaireData(), NicQuestionnaire.class)); + } + return nicQuestionnaireList; + } } 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/ManualVspDataCollectionService.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/ManualVspDataCollectionService.java index dc60419973..f50c1339b3 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/ManualVspDataCollectionService.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/ManualVspDataCollectionService.java @@ -12,374 +12,355 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. -*/ - + */ package org.openecomp.sdc.vendorsoftwareproduct.services; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang.StringUtils; import org.openecomp.core.utilities.json.JsonUtil; -import org.openecomp.sdc.generator.datatypes.tosca.*; +import org.openecomp.sdc.generator.datatypes.tosca.ComputeFlavor; +import org.openecomp.sdc.generator.datatypes.tosca.DeploymentFlavorModel; +import org.openecomp.sdc.generator.datatypes.tosca.LicenseFlavor; +import org.openecomp.sdc.generator.datatypes.tosca.MultiFlavorVfcImage; +import org.openecomp.sdc.generator.datatypes.tosca.VendorInfo; import org.openecomp.sdc.logging.api.Logger; import org.openecomp.sdc.logging.api.LoggerFactory; import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity; import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupModel; import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade; import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacadeFactory; -import org.openecomp.sdc.vendorsoftwareproduct.dao.*; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.*; -import org.openecomp.sdc.vendorsoftwareproduct.types.composition.*; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComputeDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComputeDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.DeploymentFlavorDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.DeploymentFlavorDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ImageDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ImageDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComputeEntity; +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.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentComputeAssociation; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentData; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.DeploymentFlavor; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Image; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic; import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.compute.Compute; import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.image.ImageDetails; import org.openecomp.sdc.versioning.dao.types.Version; -import java.util.*; - - public class ManualVspDataCollectionService { - private static final VendorSoftwareProductInfoDao vendorSoftwareProductInfoDao = - VendorSoftwareProductInfoDaoFactory.getInstance().createInterface(); - private static final DeploymentFlavorDao deploymentFlavorDao = - DeploymentFlavorDaoFactory.getInstance().createInterface(); - private static final ComputeDao computeDao = - ComputeDaoFactory.getInstance().createInterface(); - private static final ImageDao imageDao = - ImageDaoFactory.getInstance().createInterface(); - private static final ComponentDao componentDao = - ComponentDaoFactory.getInstance().createInterface(); - - private static final NicDao nicDao = - NicDaoFactory.getInstance().createInterface(); - private static final VendorLicenseFacade vendorLicenseFacade = - VendorLicenseFacadeFactory.getInstance().createInterface(); - - private final Logger log = LoggerFactory.getLogger(this.getClass().getName()); - - /** - * Gets vendor name for the vsp. - * - * @param vspId the vsp id - * @param version the version - * @return the release vendor name - */ - public Optional getReleaseVendor(String vspId, Version version) { - String vendorName = null; - VspDetails vspDetails = vendorSoftwareProductInfoDao.get(new VspDetails(vspId, version)); - if (Objects.nonNull(vspDetails)) { - vendorName = vspDetails.getVendorName(); - } - return Optional.ofNullable(vendorName); - } - - /** - * Gets the deployment flavor data for manually onboarded VSPs. - * - * @param vspId the vsp id - * @param version the version - * @return the allowed flavors - */ - public Map getAllowedFlavors(String vspId, Version version) { - Map allowedFlavors = new HashMap<>(); - Collection deploymentFlavorEntities = - deploymentFlavorDao.list(new DeploymentFlavorEntity(vspId, version, null)); - if (CollectionUtils.isNotEmpty(deploymentFlavorEntities)) { - for (DeploymentFlavorEntity deploymentFlavorEntity : deploymentFlavorEntities) { - DeploymentFlavor deploymentFlavorCompositionData = - deploymentFlavorEntity.getDeploymentFlavorCompositionData(); + private static final VendorSoftwareProductInfoDao vendorSoftwareProductInfoDao = VendorSoftwareProductInfoDaoFactory.getInstance() + .createInterface(); + private static final DeploymentFlavorDao deploymentFlavorDao = DeploymentFlavorDaoFactory.getInstance().createInterface(); + private static final ComputeDao computeDao = ComputeDaoFactory.getInstance().createInterface(); + private static final ImageDao imageDao = ImageDaoFactory.getInstance().createInterface(); + private static final ComponentDao componentDao = ComponentDaoFactory.getInstance().createInterface(); + private static final NicDao nicDao = NicDaoFactory.getInstance().createInterface(); + private static final VendorLicenseFacade vendorLicenseFacade = VendorLicenseFacadeFactory.getInstance().createInterface(); + private final Logger log = LoggerFactory.getLogger(this.getClass().getName()); + /** + * Gets vendor name for the vsp. + * + * @param vspId the vsp id + * @param version the version + * @return the release vendor name + */ + public Optional getReleaseVendor(String vspId, Version version) { + String vendorName = null; VspDetails vspDetails = vendorSoftwareProductInfoDao.get(new VspDetails(vspId, version)); - String vspVlmId; - Version vlmVersion; if (Objects.nonNull(vspDetails)) { - vspVlmId = vspDetails.getVendorId(); - vlmVersion = vspDetails.getVlmVersion(); - if (StringUtils.isNotEmpty(vspVlmId)) { - DeploymentFlavorModel deploymentFlavorModel = new DeploymentFlavorModel(); - String featureGroupId = deploymentFlavorCompositionData.getFeatureGroupId(); - if (Objects.isNull(featureGroupId)) { - //No feature group associated with deployment flavor. So excluding this deployment - // flavor for Tosca model - continue; - } - //Gather and set License flavor info - LicenseFlavor licenseFlavor = getLicenseFlavor(featureGroupId); - deploymentFlavorModel.setLicense_flavor(licenseFlavor); - //Get sp_part_number - Optional partNumber = getPartNumber(vspVlmId, vlmVersion, featureGroupId); - partNumber.ifPresent(deploymentFlavorModel::setSp_part_number); - //Gather and set Vendor Info - String vendorModel = deploymentFlavorCompositionData.getModel(); - Optional vendorInfo = getVendorInfo(vspVlmId, vendorModel, vlmVersion, - featureGroupId); - vendorInfo.ifPresent(deploymentFlavorModel::setVendor_info); - //Gather and set Compute info - List componentComputeAssociations = - deploymentFlavorCompositionData.getComponentComputeAssociations(); - if (CollectionUtils.isNotEmpty(componentComputeAssociations)) { - for (ComponentComputeAssociation componentComputeAssociation : - componentComputeAssociations) { - String componentId = componentComputeAssociation.getComponentId(); - String computeFlavorId = componentComputeAssociation.getComputeFlavorId(); - Optional computeFlavor = - getComputeFlavor(vspId, version, componentId, computeFlavorId); - computeFlavor.ifPresent(deploymentFlavorModel::setCompute_flavor); - } - } - partNumber.ifPresent(spPartNumber -> allowedFlavors.put(spPartNumber, - deploymentFlavorModel)); - } + vendorName = vspDetails.getVendorName(); } - } + return Optional.ofNullable(vendorName); } - return allowedFlavors; - } - /** - * Gets the component image data for manually onboarded VSPs. - * - * @param vspId the vsp id - * @param version the version - * @return the vsp component images - */ - public Map> getVspComponentImages(String vspId, - Version version) { - Map> vspComponentImages = new HashMap<>(); - Collection deploymentFlavorEntities = - deploymentFlavorDao.list(new DeploymentFlavorEntity(vspId, version, null)); - for (DeploymentFlavorEntity deploymentFlavorEntity : deploymentFlavorEntities) { - DeploymentFlavor deploymentFlavorCompositionData = - deploymentFlavorEntity.getDeploymentFlavorCompositionData(); + /** + * Gets the deployment flavor data for manually onboarded VSPs. + * + * @param vspId the vsp id + * @param version the version + * @return the allowed flavors + */ + public Map getAllowedFlavors(String vspId, Version version) { + Map allowedFlavors = new HashMap<>(); + Collection deploymentFlavorEntities = deploymentFlavorDao.list(new DeploymentFlavorEntity(vspId, version, null)); + if (CollectionUtils.isNotEmpty(deploymentFlavorEntities)) { + for (DeploymentFlavorEntity deploymentFlavorEntity : deploymentFlavorEntities) { + DeploymentFlavor deploymentFlavorCompositionData = deploymentFlavorEntity.getDeploymentFlavorCompositionData(); + VspDetails vspDetails = vendorSoftwareProductInfoDao.get(new VspDetails(vspId, version)); + String vspVlmId; + Version vlmVersion; + if (Objects.nonNull(vspDetails)) { + vspVlmId = vspDetails.getVendorId(); + vlmVersion = vspDetails.getVlmVersion(); + if (StringUtils.isNotEmpty(vspVlmId)) { + DeploymentFlavorModel deploymentFlavorModel = new DeploymentFlavorModel(); + String featureGroupId = deploymentFlavorCompositionData.getFeatureGroupId(); + if (Objects.isNull(featureGroupId)) { + //No feature group associated with deployment flavor. So excluding this deployment - List componentComputeAssociations = - deploymentFlavorCompositionData.getComponentComputeAssociations(); - if (CollectionUtils.isNotEmpty(componentComputeAssociations)) { - for (ComponentComputeAssociation componentComputeAssociation : - componentComputeAssociations) { - String componentId = componentComputeAssociation.getComponentId(); - List componentImages = - getComponentImages(vspId, version, componentId); - if (CollectionUtils.isNotEmpty(componentImages)) { - vspComponentImages.put(componentId, componentImages); - } + // flavor for Tosca model + continue; + } + //Gather and set License flavor info + LicenseFlavor licenseFlavor = getLicenseFlavor(featureGroupId); + deploymentFlavorModel.setLicense_flavor(licenseFlavor); + //Get sp_part_number + Optional partNumber = getPartNumber(vspVlmId, vlmVersion, featureGroupId); + partNumber.ifPresent(deploymentFlavorModel::setSp_part_number); + //Gather and set Vendor Info + String vendorModel = deploymentFlavorCompositionData.getModel(); + Optional vendorInfo = getVendorInfo(vspVlmId, vendorModel, vlmVersion, featureGroupId); + vendorInfo.ifPresent(deploymentFlavorModel::setVendor_info); + //Gather and set Compute info + List componentComputeAssociations = deploymentFlavorCompositionData + .getComponentComputeAssociations(); + if (CollectionUtils.isNotEmpty(componentComputeAssociations)) { + for (ComponentComputeAssociation componentComputeAssociation : componentComputeAssociations) { + String componentId = componentComputeAssociation.getComponentId(); + String computeFlavorId = componentComputeAssociation.getComputeFlavorId(); + Optional computeFlavor = getComputeFlavor(vspId, version, componentId, computeFlavorId); + computeFlavor.ifPresent(deploymentFlavorModel::setCompute_flavor); + } + } + partNumber.ifPresent(spPartNumber -> allowedFlavors.put(spPartNumber, deploymentFlavorModel)); + } + } + } } - } + return allowedFlavors; } - return vspComponentImages; - } - /** - * Gets the component data for manually onboarded VSPs. - * - * @param vspId the vsp id - * @param version the version - * @return the vsp components - */ - public Map getVspComponents(String vspId, Version version) { - Map componentIdNameMap = new HashMap<>(); - Collection deploymentFlavorEntities = - deploymentFlavorDao.list(new DeploymentFlavorEntity(vspId, version, null)); - for (DeploymentFlavorEntity deploymentFlavorEntity : deploymentFlavorEntities) { - DeploymentFlavor deploymentFlavorCompositionData = - deploymentFlavorEntity.getDeploymentFlavorCompositionData(); - - List componentComputeAssociations = - deploymentFlavorCompositionData.getComponentComputeAssociations(); - if (CollectionUtils.isNotEmpty(componentComputeAssociations)) { - for (ComponentComputeAssociation componentComputeAssociation : - componentComputeAssociations) { - String componentId = componentComputeAssociation.getComponentId(); - Optional componentName = getComponentName(vspId, version, componentId); - componentName.ifPresent(name -> componentIdNameMap.put(componentId, name)); + /** + * Gets the component image data for manually onboarded VSPs. + * + * @param vspId the vsp id + * @param version the version + * @return the vsp component images + */ + public Map> getVspComponentImages(String vspId, Version version) { + Map> vspComponentImages = new HashMap<>(); + Collection deploymentFlavorEntities = deploymentFlavorDao.list(new DeploymentFlavorEntity(vspId, version, null)); + for (DeploymentFlavorEntity deploymentFlavorEntity : deploymentFlavorEntities) { + DeploymentFlavor deploymentFlavorCompositionData = deploymentFlavorEntity.getDeploymentFlavorCompositionData(); + List componentComputeAssociations = deploymentFlavorCompositionData.getComponentComputeAssociations(); + if (CollectionUtils.isNotEmpty(componentComputeAssociations)) { + for (ComponentComputeAssociation componentComputeAssociation : componentComputeAssociations) { + String componentId = componentComputeAssociation.getComponentId(); + List componentImages = getComponentImages(vspId, version, componentId); + if (CollectionUtils.isNotEmpty(componentImages)) { + vspComponentImages.put(componentId, componentImages); + } + } + } } - } + return vspComponentImages; } - return componentIdNameMap; - } - /** - * Gets the NIC data for manually onboarded VSPs. - * - * @param vspId the vsp id - * @param version the version - * @return the vsp component nics - */ - public Map> getVspComponentNics(String vspId, Version version) { - Map> vspComponentNics = new HashMap<>(); - Collection deploymentFlavorEntities = - deploymentFlavorDao.list(new DeploymentFlavorEntity(vspId, version, null)); - if (CollectionUtils.isNotEmpty(deploymentFlavorEntities)) { - for (DeploymentFlavorEntity deploymentFlavorEntity : deploymentFlavorEntities) { - DeploymentFlavor deploymentFlavorCompositionData = - deploymentFlavorEntity.getDeploymentFlavorCompositionData(); - if (Objects.nonNull(deploymentFlavorCompositionData)) { - List componentComputeAssociations = - deploymentFlavorCompositionData.getComponentComputeAssociations(); - if (CollectionUtils.isNotEmpty(componentComputeAssociations)) { - for (ComponentComputeAssociation componentComputeAssociation : - componentComputeAssociations) { - String componentId = componentComputeAssociation.getComponentId(); - List componentNics = getComponentNics(vspId, version, componentId); - if (CollectionUtils.isNotEmpty(componentNics)) { - vspComponentNics.put(componentId, componentNics); - } + /** + * Gets the component data for manually onboarded VSPs. + * + * @param vspId the vsp id + * @param version the version + * @return the vsp components + */ + public Map getVspComponents(String vspId, Version version) { + Map componentIdNameMap = new HashMap<>(); + Collection deploymentFlavorEntities = deploymentFlavorDao.list(new DeploymentFlavorEntity(vspId, version, null)); + for (DeploymentFlavorEntity deploymentFlavorEntity : deploymentFlavorEntities) { + DeploymentFlavor deploymentFlavorCompositionData = deploymentFlavorEntity.getDeploymentFlavorCompositionData(); + List componentComputeAssociations = deploymentFlavorCompositionData.getComponentComputeAssociations(); + if (CollectionUtils.isNotEmpty(componentComputeAssociations)) { + for (ComponentComputeAssociation componentComputeAssociation : componentComputeAssociations) { + String componentId = componentComputeAssociation.getComponentId(); + Optional componentName = getComponentName(vspId, version, componentId); + componentName.ifPresent(name -> componentIdNameMap.put(componentId, name)); + } } - } } - } + return componentIdNameMap; } - return vspComponentNics; - } - private List getComponentNics(String vspId, Version version, String componentId) { - List componentNics = new ArrayList<>(); - Collection nics = nicDao.list(new NicEntity(vspId, version, componentId, null)); - if (Objects.nonNull(nics)) { - for (NicEntity nic : nics) { - String nicId = nic.getId(); - NicEntity nicEntity = nicDao.get(new NicEntity(vspId, version, componentId, nicId)); - if (Objects.nonNull(nicEntity) - && Objects.nonNull(nicEntity.getCompositionData())) { - componentNics.add(nicEntity.getNicCompositionData()); + /** + * Gets the NIC data for manually onboarded VSPs. + * + * @param vspId the vsp id + * @param version the version + * @return the vsp component nics + */ + public Map> getVspComponentNics(String vspId, Version version) { + Map> vspComponentNics = new HashMap<>(); + Collection deploymentFlavorEntities = deploymentFlavorDao.list(new DeploymentFlavorEntity(vspId, version, null)); + if (CollectionUtils.isNotEmpty(deploymentFlavorEntities)) { + for (DeploymentFlavorEntity deploymentFlavorEntity : deploymentFlavorEntities) { + DeploymentFlavor deploymentFlavorCompositionData = deploymentFlavorEntity.getDeploymentFlavorCompositionData(); + if (Objects.nonNull(deploymentFlavorCompositionData)) { + List componentComputeAssociations = deploymentFlavorCompositionData + .getComponentComputeAssociations(); + if (CollectionUtils.isNotEmpty(componentComputeAssociations)) { + for (ComponentComputeAssociation componentComputeAssociation : componentComputeAssociations) { + String componentId = componentComputeAssociation.getComponentId(); + List componentNics = getComponentNics(vspId, version, componentId); + if (CollectionUtils.isNotEmpty(componentNics)) { + vspComponentNics.put(componentId, componentNics); + } + } + } + } + } } - } + return vspComponentNics; } - return componentNics; - } - private LicenseFlavor getLicenseFlavor(String featureGroupId) { - LicenseFlavor licenseFlavor = new LicenseFlavor(); - licenseFlavor.setFeature_group_uuid(featureGroupId); - return licenseFlavor; - } + private List getComponentNics(String vspId, Version version, String componentId) { + List componentNics = new ArrayList<>(); + Collection nics = nicDao.list(new NicEntity(vspId, version, componentId, null)); + if (Objects.nonNull(nics)) { + for (NicEntity nic : nics) { + String nicId = nic.getId(); + NicEntity nicEntity = nicDao.get(new NicEntity(vspId, version, componentId, nicId)); + if (Objects.nonNull(nicEntity) && Objects.nonNull(nicEntity.getCompositionData())) { + componentNics.add(nicEntity.getNicCompositionData()); + } + } + } + return componentNics; + } - private Optional getPartNumber(String vlmId, Version version, - String featureGroupId) { - FeatureGroupModel featureGroup = getFeatureGroup(vlmId, version, featureGroupId); - if (Objects.nonNull(featureGroup)) { - return Optional.ofNullable(featureGroup.getFeatureGroup().getPartNumber()); + private LicenseFlavor getLicenseFlavor(String featureGroupId) { + LicenseFlavor licenseFlavor = new LicenseFlavor(); + licenseFlavor.setFeature_group_uuid(featureGroupId); + return licenseFlavor; } - return Optional.empty(); - } - private Optional getVendorInfo(String vlmId, String vendorModel, Version version, - String featureGroupId) { - VendorInfo vendorInfo = null; - FeatureGroupModel featureGroup = getFeatureGroup(vlmId, version, featureGroupId); - if (Objects.nonNull(featureGroup)) { - //Process Feature group to get Manufacturer ref no. - String manufacturerReferenceNumber = featureGroup.getEntityManufacturerReferenceNumber(); - vendorInfo = new VendorInfo(); - vendorInfo.setVendor_model(vendorModel); - if (Objects.nonNull(manufacturerReferenceNumber)) { - vendorInfo.setManufacturer_reference_number(manufacturerReferenceNumber); - } + private Optional getPartNumber(String vlmId, Version version, String featureGroupId) { + FeatureGroupModel featureGroup = getFeatureGroup(vlmId, version, featureGroupId); + if (Objects.nonNull(featureGroup)) { + return Optional.ofNullable(featureGroup.getFeatureGroup().getPartNumber()); + } + return Optional.empty(); } - return Optional.ofNullable(vendorInfo); - } - private Optional getComputeFlavor(String vspId, Version version, - String componentId, String computeFlavorId) { - ComputeFlavor computeFlavor = null; - ComputeEntity computeQuestionnaire; - try { - computeQuestionnaire = computeDao.getQuestionnaireData(vspId, version, componentId, - computeFlavorId); - } catch (Exception ex) { - log.warn("Failed to get QuestionnaireData from computeDao," + - " initializing computeQuestionnaire to null", ex); - computeQuestionnaire = null; + private Optional getVendorInfo(String vlmId, String vendorModel, Version version, String featureGroupId) { + VendorInfo vendorInfo = null; + FeatureGroupModel featureGroup = getFeatureGroup(vlmId, version, featureGroupId); + if (Objects.nonNull(featureGroup)) { + //Process Feature group to get Manufacturer ref no. + String manufacturerReferenceNumber = featureGroup.getEntityManufacturerReferenceNumber(); + vendorInfo = new VendorInfo(); + vendorInfo.setVendor_model(vendorModel); + if (Objects.nonNull(manufacturerReferenceNumber)) { + vendorInfo.setManufacturer_reference_number(manufacturerReferenceNumber); + } + } + return Optional.ofNullable(vendorInfo); } - if (Objects.nonNull(computeQuestionnaire)) { - String computeQuestionnaireData = computeQuestionnaire.getQuestionnaireData(); - if (Objects.nonNull(computeQuestionnaireData)) { - Compute compute; + + private Optional getComputeFlavor(String vspId, Version version, String componentId, String computeFlavorId) { + ComputeFlavor computeFlavor = null; + ComputeEntity computeQuestionnaire; try { - compute = JsonUtil.json2Object(computeQuestionnaireData, Compute.class); + computeQuestionnaire = computeDao.getQuestionnaireData(vspId, version, componentId, computeFlavorId); } catch (Exception ex) { - log.warn("Failed to convert json value to compute object," + - "initializing compute to null", ex); - compute = null; + log.warn("Failed to get QuestionnaireData from computeDao," + " initializing computeQuestionnaire to null", ex); + computeQuestionnaire = null; } - if (compute != null && Objects.nonNull(compute.getVmSizing())) { - computeFlavor = new ComputeFlavor(); - if (Objects.nonNull(compute.getVmSizing().getNumOfCPUs())) { - computeFlavor.setNum_cpus(compute.getVmSizing().getNumOfCPUs()); - } - if (Objects.nonNull(compute.getVmSizing().getFileSystemSizeGB())) { - computeFlavor.setDisk_size(compute.getVmSizing().getFileSystemSizeGB() + " GB"); - } - if (Objects.nonNull(compute.getVmSizing().getMemoryRAM())) { - computeFlavor.setMem_size(compute.getVmSizing().getMemoryRAM()); - } + if (Objects.nonNull(computeQuestionnaire)) { + String computeQuestionnaireData = computeQuestionnaire.getQuestionnaireData(); + if (Objects.nonNull(computeQuestionnaireData)) { + Compute compute; + try { + compute = JsonUtil.json2Object(computeQuestionnaireData, Compute.class); + } catch (Exception ex) { + log.warn("Failed to convert json value to compute object," + "initializing compute to null", ex); + compute = null; + } + if (compute != null && Objects.nonNull(compute.getVmSizing())) { + computeFlavor = new ComputeFlavor(); + if (Objects.nonNull(compute.getVmSizing().getNumOfCPUs())) { + computeFlavor.setNum_cpus(compute.getVmSizing().getNumOfCPUs()); + } + if (Objects.nonNull(compute.getVmSizing().getFileSystemSizeGB())) { + computeFlavor.setDisk_size(compute.getVmSizing().getFileSystemSizeGB() + " GB"); + } + if (Objects.nonNull(compute.getVmSizing().getMemoryRAM())) { + computeFlavor.setMem_size(compute.getVmSizing().getMemoryRAM()); + } + } + } } - } + return Optional.ofNullable(computeFlavor); } - return Optional.ofNullable(computeFlavor); - } - private FeatureGroupModel getFeatureGroup(String vlmId, Version version, String featureGroupId) { - FeatureGroupEntity fgInput = new FeatureGroupEntity(); - fgInput.setVendorLicenseModelId(vlmId); - fgInput.setVersion(version); - fgInput.setId(featureGroupId); - return vendorLicenseFacade.getFeatureGroupModel(fgInput); - } - - private Optional getComponentName(String vspId, Version version, String componentId) { + private FeatureGroupModel getFeatureGroup(String vlmId, Version version, String featureGroupId) { + FeatureGroupEntity fgInput = new FeatureGroupEntity(); + fgInput.setVendorLicenseModelId(vlmId); + fgInput.setVersion(version); + fgInput.setId(featureGroupId); + return vendorLicenseFacade.getFeatureGroupModel(fgInput); + } - ComponentEntity componentEntity = - componentDao.get(new ComponentEntity(vspId, version, componentId)); - if (Objects.nonNull(componentEntity) - && Objects.nonNull(componentEntity.getComponentCompositionData())) { - ComponentData componentCompositionData = componentEntity.getComponentCompositionData(); - return Optional.ofNullable(componentCompositionData.getDisplayName()); + private Optional getComponentName(String vspId, Version version, String componentId) { + ComponentEntity componentEntity = componentDao.get(new ComponentEntity(vspId, version, componentId)); + if (Objects.nonNull(componentEntity) && Objects.nonNull(componentEntity.getComponentCompositionData())) { + ComponentData componentCompositionData = componentEntity.getComponentCompositionData(); + return Optional.ofNullable(componentCompositionData.getDisplayName()); + } + return Optional.empty(); } - return Optional.empty(); - } - private List getComponentImages(String vspId, Version version, - String componentId) { - List multiFlavorVfcImages = new ArrayList<>(); - MultiFlavorVfcImage multiFlavorVfcImage; - Collection componentImages = - imageDao.list(new ImageEntity(vspId, version, componentId, null)); - if (Objects.nonNull(componentImages)) { - for (ImageEntity componentImage : componentImages) { - ImageEntity imageEntity = imageDao.get(componentImage); - ImageEntity imageQuestionnaireDataEntity = imageDao.getQuestionnaireData(vspId, version, - componentId, componentImage.getId()); - Image imageCompositionData = imageEntity.getImageCompositionData(); - if (Objects.nonNull(imageEntity) - && Objects.nonNull(imageQuestionnaireDataEntity) - && Objects.nonNull(imageCompositionData)) { - ImageDetails imageDetails; - try { - imageDetails = JsonUtil.json2Object(imageQuestionnaireDataEntity - .getQuestionnaireData(), ImageDetails.class); - } catch (Exception ex) { - log.warn("Failed to convert json value to ImageDetails object," + - "initializing imageDetails to null", ex); - imageDetails = null; - } - if (Objects.nonNull(imageDetails) - && Objects.nonNull(imageDetails.getVersion())) { - //Image version is used as a key for the image block - //So excluding the population if questionnaire data is absent or invalid - multiFlavorVfcImage = new MultiFlavorVfcImage(); - multiFlavorVfcImage.setSoftware_version(imageDetails.getVersion()); - if (Objects.nonNull(imageCompositionData.getFileName())) { - multiFlavorVfcImage.setFile_name(imageCompositionData.getFileName()); - } - if (Objects.nonNull(imageDetails.getMd5())) { - multiFlavorVfcImage.setFile_hash(imageDetails.getMd5()); + private List getComponentImages(String vspId, Version version, String componentId) { + List multiFlavorVfcImages = new ArrayList<>(); + MultiFlavorVfcImage multiFlavorVfcImage; + Collection componentImages = imageDao.list(new ImageEntity(vspId, version, componentId, null)); + if (Objects.nonNull(componentImages)) { + for (ImageEntity componentImage : componentImages) { + ImageEntity imageEntity = imageDao.get(componentImage); + ImageEntity imageQuestionnaireDataEntity = imageDao.getQuestionnaireData(vspId, version, componentId, componentImage.getId()); + Image imageCompositionData = imageEntity.getImageCompositionData(); + if (Objects.nonNull(imageEntity) && Objects.nonNull(imageQuestionnaireDataEntity) && Objects.nonNull(imageCompositionData)) { + ImageDetails imageDetails; + try { + imageDetails = JsonUtil.json2Object(imageQuestionnaireDataEntity.getQuestionnaireData(), ImageDetails.class); + } catch (Exception ex) { + log.warn("Failed to convert json value to ImageDetails object," + "initializing imageDetails to null", ex); + imageDetails = null; + } + if (Objects.nonNull(imageDetails) && Objects.nonNull(imageDetails.getVersion())) { + //Image version is used as a key for the image block + + //So excluding the population if questionnaire data is absent or invalid + multiFlavorVfcImage = new MultiFlavorVfcImage(); + multiFlavorVfcImage.setSoftware_version(imageDetails.getVersion()); + if (Objects.nonNull(imageCompositionData.getFileName())) { + multiFlavorVfcImage.setFile_name(imageCompositionData.getFileName()); + } + if (Objects.nonNull(imageDetails.getMd5())) { + multiFlavorVfcImage.setFile_hash(imageDetails.getMd5()); + } + multiFlavorVfcImage.setFile_hash_type("md5"); + multiFlavorVfcImages.add(multiFlavorVfcImage); + } + } } - multiFlavorVfcImage.setFile_hash_type("md5"); - multiFlavorVfcImages.add(multiFlavorVfcImage); - } } - } + return multiFlavorVfcImages; } - return multiFlavorVfcImages; - } } 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/composition/CompositionDataExtractorImpl.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/composition/CompositionDataExtractorImpl.java index 00781c1512..15289025b1 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/composition/CompositionDataExtractorImpl.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/composition/CompositionDataExtractorImpl.java @@ -13,10 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.vendorsoftwareproduct.services.impl.composition; import com.fasterxml.jackson.databind.ObjectMapper; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.stream.Collectors; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; import org.onap.sdc.tosca.datatypes.model.NodeTemplate; @@ -27,7 +33,11 @@ import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil; import org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.logging.api.Logger; import org.openecomp.sdc.logging.api.LoggerFactory; -import org.openecomp.sdc.tosca.datatypes.*; +import org.openecomp.sdc.tosca.datatypes.ToscaCapabilityType; +import org.openecomp.sdc.tosca.datatypes.ToscaFunctions; +import org.openecomp.sdc.tosca.datatypes.ToscaNodeType; +import org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType; +import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; import org.openecomp.sdc.tosca.errors.ToscaInvalidEntryNotFoundErrorBuilder; import org.openecomp.sdc.tosca.errors.ToscaInvalidSubstituteNodeTemplateErrorBuilder; import org.openecomp.sdc.tosca.errors.ToscaMissingSubstitutionMappingForReqCapErrorBuilder; @@ -35,427 +45,343 @@ import org.openecomp.sdc.tosca.services.ToscaAnalyzerService; import org.openecomp.sdc.tosca.services.ToscaConstants; import org.openecomp.sdc.tosca.services.impl.ToscaAnalyzerServiceImpl; import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionDataExtractor; -import org.openecomp.sdc.vendorsoftwareproduct.types.composition.*; - -import java.util.*; -import java.util.stream.Collectors; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Component; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentData; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionData; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComputeData; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ExtractCompositionDataContext; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Image; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Network; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic; public class CompositionDataExtractorImpl implements CompositionDataExtractor { - protected static Logger logger; - private static ToscaAnalyzerService toscaAnalyzerService; - static { - logger = LoggerFactory.getLogger(CompositionDataExtractorImpl.class); - toscaAnalyzerService = new ToscaAnalyzerServiceImpl(); - } + protected static Logger logger; + private static ToscaAnalyzerService toscaAnalyzerService; - /** - * Extract service composition data composition data. - * - * @param toscaServiceModel the tosca service model - * @return the composition data - */ - public CompositionData extractServiceCompositionData(ToscaServiceModel toscaServiceModel) { - ExtractCompositionDataContext context = new ExtractCompositionDataContext(); - String entryDefinitionServiceTemplateFileName = - toscaServiceModel.getEntryDefinitionServiceTemplate(); - ServiceTemplate entryDefinitionServiceTemplate = - toscaServiceModel.getServiceTemplates().get(entryDefinitionServiceTemplateFileName); - extractServiceCompositionData(entryDefinitionServiceTemplateFileName, - entryDefinitionServiceTemplate, toscaServiceModel, context); - - CompositionData compositionData = new CompositionData(); - compositionData.setNetworks(context.getNetworks()); - compositionData.setComponents(context.getComponents()); - return compositionData; - } - - private void extractServiceCompositionData(String serviceTemplateFileName, - ServiceTemplate serviceTemplate, - ToscaServiceModel toscaServiceModel, - ExtractCompositionDataContext context) { - if (context.getHandledServiceTemplates().contains(serviceTemplateFileName)) { - return; + static { + logger = LoggerFactory.getLogger(CompositionDataExtractorImpl.class); + toscaAnalyzerService = new ToscaAnalyzerServiceImpl(); } - context.addNetworks(extractNetworks(serviceTemplate, toscaServiceModel)); - extractComponents(serviceTemplate, toscaServiceModel, context); - handleSubstitution(serviceTemplate, toscaServiceModel, context); - context.addHandledServiceTemplates(serviceTemplateFileName); - } - private void handleSubstitution(ServiceTemplate serviceTemplate, - ToscaServiceModel toscaServiceModel, - ExtractCompositionDataContext context) { - Map substitutableNodeTemplates = - toscaAnalyzerService.getSubstitutableNodeTemplates(serviceTemplate); - - if (substitutableNodeTemplates != null) { - for (String substitutableNodeTemplateId : substitutableNodeTemplates.keySet()) { - handleSubstitutableNodeTemplate(serviceTemplate, toscaServiceModel, - substitutableNodeTemplateId, - substitutableNodeTemplates.get(substitutableNodeTemplateId), context); - } + /** + * Extract service composition data composition data. + * + * @param toscaServiceModel the tosca service model + * @return the composition data + */ + public CompositionData extractServiceCompositionData(ToscaServiceModel toscaServiceModel) { + ExtractCompositionDataContext context = new ExtractCompositionDataContext(); + String entryDefinitionServiceTemplateFileName = toscaServiceModel.getEntryDefinitionServiceTemplate(); + ServiceTemplate entryDefinitionServiceTemplate = toscaServiceModel.getServiceTemplates().get(entryDefinitionServiceTemplateFileName); + extractServiceCompositionData(entryDefinitionServiceTemplateFileName, entryDefinitionServiceTemplate, toscaServiceModel, context); + CompositionData compositionData = new CompositionData(); + compositionData.setNetworks(context.getNetworks()); + compositionData.setComponents(context.getComponents()); + return compositionData; } - } - private void handleSubstitutableNodeTemplate(ServiceTemplate serviceTemplate, - ToscaServiceModel toscaServiceModel, - String substitutableNodeTemplateId, - NodeTemplate substitutableNodeTemplate, - ExtractCompositionDataContext context) { - ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil(); - Optional substituteServiceTemplateFileName = toscaAnalyzerService - .getSubstituteServiceTemplateName(substitutableNodeTemplateId, substitutableNodeTemplate); - if (!substituteServiceTemplateFileName.isPresent()) { - throw new CoreException( - new ToscaInvalidSubstituteNodeTemplateErrorBuilder(substitutableNodeTemplateId).build()); - } - if (context.getHandledServiceTemplates().contains(substituteServiceTemplateFileName.get())) { - //each substitution is should be handled once, and will get the connection to the upper - // service level according to the first one which was processed - return; - } - - ServiceTemplate substituteServiceTemplate = - toscaServiceModel.getServiceTemplates().get(substituteServiceTemplateFileName.get()); - extractServiceCompositionData(substituteServiceTemplateFileName.get(), - substituteServiceTemplate, toscaServiceModel, context); - - List> substitutableRequirements = - substitutableNodeTemplate.getRequirements(); - - if (CollectionUtils.isEmpty(substitutableRequirements)) { - return; + private void extractServiceCompositionData(String serviceTemplateFileName, ServiceTemplate serviceTemplate, ToscaServiceModel toscaServiceModel, + ExtractCompositionDataContext context) { + if (context.getHandledServiceTemplates().contains(serviceTemplateFileName)) { + return; + } + context.addNetworks(extractNetworks(serviceTemplate, toscaServiceModel)); + extractComponents(serviceTemplate, toscaServiceModel, context); + handleSubstitution(serviceTemplate, toscaServiceModel, context); + context.addHandledServiceTemplates(serviceTemplateFileName); } - for (Map substitutableReq : substitutableRequirements) { - substitutableReq.keySet().stream().filter(reqId -> { - RequirementAssignment reqAssignment = toscaExtensionYamlUtil - .yamlToObject(toscaExtensionYamlUtil.objectToYaml(substitutableReq.get(reqId)), - RequirementAssignment.class); - return isLinkToNetworkRequirementAssignment(reqAssignment); - }).forEach(reqId -> { - RequirementAssignment linkToNetworkRequirement = toscaExtensionYamlUtil - .yamlToObject(toscaExtensionYamlUtil.objectToYaml(substitutableReq.get(reqId)), - RequirementAssignment.class); - String connectedNodeId = linkToNetworkRequirement.getNode(); - Optional connectedNodeTemplate = - toscaAnalyzerService.getNodeTemplateById(serviceTemplate, connectedNodeId); - - if (connectedNodeTemplate.isPresent() && toscaAnalyzerService - .isTypeOf(connectedNodeTemplate.get(), ToscaNodeType.NATIVE_NETWORK, - serviceTemplate, toscaServiceModel)) { - Optional> mappedNodeTemplate = toscaAnalyzerService - .getSubstitutionMappedNodeTemplateByExposedReq( - substituteServiceTemplateFileName.get(), substituteServiceTemplate, reqId); - if (!mappedNodeTemplate.isPresent()) { - throw new CoreException(new ToscaMissingSubstitutionMappingForReqCapErrorBuilder( - ToscaMissingSubstitutionMappingForReqCapErrorBuilder.MappingExposedEntry - .REQUIREMENT, connectedNodeId).build()); - } - - if (toscaAnalyzerService.isTypeOf(mappedNodeTemplate.get().getValue(), - ToscaNodeType.NATIVE_NETWORK_PORT, serviceTemplate, - toscaServiceModel)) { - Nic port = context.getNics().get(mappedNodeTemplate.get().getKey()); - if (port != null) { - port.setNetworkName(connectedNodeId); - } else { - logger.warn( - "Different ports define for the same component which is used in different " - + "substitution service templates."); + private void handleSubstitution(ServiceTemplate serviceTemplate, ToscaServiceModel toscaServiceModel, ExtractCompositionDataContext context) { + Map substitutableNodeTemplates = toscaAnalyzerService.getSubstitutableNodeTemplates(serviceTemplate); + if (substitutableNodeTemplates != null) { + for (String substitutableNodeTemplateId : substitutableNodeTemplates.keySet()) { + handleSubstitutableNodeTemplate(serviceTemplate, toscaServiceModel, substitutableNodeTemplateId, + substitutableNodeTemplates.get(substitutableNodeTemplateId), context); } - } - } else if (!connectedNodeTemplate.isPresent()) { - throw new CoreException( - new ToscaInvalidEntryNotFoundErrorBuilder("Node Template", connectedNodeId).build()); } - }); } - } - private boolean isLinkToNetworkRequirementAssignment(RequirementAssignment requirement) { - return toscaAnalyzerService.isDesiredRequirementAssignment(requirement, - ToscaCapabilityType.NATIVE_NETWORK_LINKABLE, null, - ToscaRelationshipType.NATIVE_NETWORK_LINK_TO); - } - - - private void connectPortToNetwork(Nic port, NodeTemplate portNodeTemplate) { - List linkRequirementsToNetwork = - toscaAnalyzerService.getRequirements(portNodeTemplate, ToscaConstants.LINK_REQUIREMENT_ID); + private void handleSubstitutableNodeTemplate(ServiceTemplate serviceTemplate, ToscaServiceModel toscaServiceModel, + String substitutableNodeTemplateId, NodeTemplate substitutableNodeTemplate, + ExtractCompositionDataContext context) { + ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil(); + Optional substituteServiceTemplateFileName = toscaAnalyzerService + .getSubstituteServiceTemplateName(substitutableNodeTemplateId, substitutableNodeTemplate); + if (!substituteServiceTemplateFileName.isPresent()) { + throw new CoreException(new ToscaInvalidSubstituteNodeTemplateErrorBuilder(substitutableNodeTemplateId).build()); + } + if (context.getHandledServiceTemplates().contains(substituteServiceTemplateFileName.get())) { + //each substitution is should be handled once, and will get the connection to the upper - //port is connected to one network - for (RequirementAssignment linkRequirementToNetwork : linkRequirementsToNetwork) { - port.setNetworkName(linkRequirementToNetwork.getNode()); + // service level according to the first one which was processed + return; + } + ServiceTemplate substituteServiceTemplate = toscaServiceModel.getServiceTemplates().get(substituteServiceTemplateFileName.get()); + extractServiceCompositionData(substituteServiceTemplateFileName.get(), substituteServiceTemplate, toscaServiceModel, context); + List> substitutableRequirements = substitutableNodeTemplate.getRequirements(); + if (CollectionUtils.isEmpty(substitutableRequirements)) { + return; + } + for (Map substitutableReq : substitutableRequirements) { + substitutableReq.keySet().stream().filter(reqId -> { + RequirementAssignment reqAssignment = toscaExtensionYamlUtil + .yamlToObject(toscaExtensionYamlUtil.objectToYaml(substitutableReq.get(reqId)), RequirementAssignment.class); + return isLinkToNetworkRequirementAssignment(reqAssignment); + }).forEach(reqId -> { + RequirementAssignment linkToNetworkRequirement = toscaExtensionYamlUtil + .yamlToObject(toscaExtensionYamlUtil.objectToYaml(substitutableReq.get(reqId)), RequirementAssignment.class); + String connectedNodeId = linkToNetworkRequirement.getNode(); + Optional connectedNodeTemplate = toscaAnalyzerService.getNodeTemplateById(serviceTemplate, connectedNodeId); + if (connectedNodeTemplate.isPresent() && toscaAnalyzerService + .isTypeOf(connectedNodeTemplate.get(), ToscaNodeType.NATIVE_NETWORK, serviceTemplate, toscaServiceModel)) { + Optional> mappedNodeTemplate = toscaAnalyzerService + .getSubstitutionMappedNodeTemplateByExposedReq(substituteServiceTemplateFileName.get(), substituteServiceTemplate, reqId); + if (!mappedNodeTemplate.isPresent()) { + throw new CoreException(new ToscaMissingSubstitutionMappingForReqCapErrorBuilder( + ToscaMissingSubstitutionMappingForReqCapErrorBuilder.MappingExposedEntry.REQUIREMENT, connectedNodeId).build()); + } + if (toscaAnalyzerService + .isTypeOf(mappedNodeTemplate.get().getValue(), ToscaNodeType.NATIVE_NETWORK_PORT, serviceTemplate, toscaServiceModel)) { + Nic port = context.getNics().get(mappedNodeTemplate.get().getKey()); + if (port != null) { + port.setNetworkName(connectedNodeId); + } else { + logger.warn( + "Different ports define for the same component which is used in different " + "substitution service templates."); + } + } + } else if (!connectedNodeTemplate.isPresent()) { + throw new CoreException(new ToscaInvalidEntryNotFoundErrorBuilder("Node Template", connectedNodeId).build()); + } + }); + } } - } - /* - return Map with key - compute node template id, value - list of connected port node template id - */ - private Map> getComputeToPortsConnection( - Map portNodeTemplates) { - Map> computeToPortConnection = new HashMap<>(); - if (MapUtils.isEmpty(portNodeTemplates)) { - return computeToPortConnection; + private boolean isLinkToNetworkRequirementAssignment(RequirementAssignment requirement) { + return toscaAnalyzerService.isDesiredRequirementAssignment(requirement, ToscaCapabilityType.NATIVE_NETWORK_LINKABLE, null, + ToscaRelationshipType.NATIVE_NETWORK_LINK_TO); } - for (String portId : portNodeTemplates.keySet()) { - List bindingRequirementsToCompute = toscaAnalyzerService - .getRequirements(portNodeTemplates.get(portId), ToscaConstants.BINDING_REQUIREMENT_ID); - for (RequirementAssignment bindingRequirementToCompute : bindingRequirementsToCompute) { - computeToPortConnection - .putIfAbsent(bindingRequirementToCompute.getNode(), new ArrayList<>()); - computeToPortConnection.get(bindingRequirementToCompute.getNode()).add(portId); - } - } - return computeToPortConnection; - } - private void extractComponents(ServiceTemplate serviceTemplate, - ToscaServiceModel toscaServiceModel, - ExtractCompositionDataContext context) { - Map computeNodeTemplates = toscaAnalyzerService - .getNodeTemplatesByType(serviceTemplate, ToscaNodeType.NATIVE_COMPUTE, - toscaServiceModel); - if (MapUtils.isEmpty(computeNodeTemplates)) { - return; + private void connectPortToNetwork(Nic port, NodeTemplate portNodeTemplate) { + List linkRequirementsToNetwork = toscaAnalyzerService + .getRequirements(portNodeTemplate, ToscaConstants.LINK_REQUIREMENT_ID); + //port is connected to one network + for (RequirementAssignment linkRequirementToNetwork : linkRequirementsToNetwork) { + port.setNetworkName(linkRequirementToNetwork.getNode()); + } } - Map> imageNodeTemplates = getComponentImages(computeNodeTemplates, - toscaServiceModel); - Map> computeFlavorNodeTemplates = - getComponentComputeFlavor(computeNodeTemplates, toscaServiceModel); - Map portNodeTemplates = toscaAnalyzerService - .getNodeTemplatesByType(serviceTemplate, ToscaNodeType.NATIVE_NETWORK_PORT, - toscaServiceModel); - Map> computeToPortsConnection = - getComputeToPortsConnection(portNodeTemplates); - Map> computesGroupedByType = - getNodeTemplatesGroupedByType(computeNodeTemplates); - computesGroupedByType.keySet() - .stream() - .filter(nodeType -> - !context.getCreatedComponents().contains(nodeType)) - .forEach(nodeType -> extractComponent(serviceTemplate, computeToPortsConnection, - computesGroupedByType, imageNodeTemplates, computeFlavorNodeTemplates, nodeType, - context)); - } - - private Map> getComponentImages(Map - computeNodeTemplates, - ToscaServiceModel toscaServiceModel) { - return getComponentProperty(ToscaConstants.COMPUTE_IMAGE, computeNodeTemplates, toscaServiceModel); - } - - private Map> getComponentComputeFlavor(Map - computeNodeTemplates, - ToscaServiceModel toscaServiceModel) { - return getComponentProperty(ToscaConstants.COMPUTE_FLAVOR, computeNodeTemplates, toscaServiceModel); - } - - private Map> getComponentProperty(String propertyName, - Map computeNodeTemplates, - ToscaServiceModel toscaServiceModel) { - Map> componentPropertyValues = new HashMap<>(); - for (String component : computeNodeTemplates.keySet()) { - List computes = new ArrayList<>(); - Map properties = computeNodeTemplates.get(component).getProperties(); - - if(MapUtils.isEmpty(properties)){ - continue; - } - - List computesList = properties.entrySet() - .stream() - .filter(map -> map.getKey().equals(propertyName)) - .map(Map.Entry::getValue) - .collect(Collectors.toList()); - for (Object obj : computesList) { - if (obj instanceof String) { - computes.add((String) obj); - } else { - Map objMap = new ObjectMapper().convertValue(obj, Map.class); - computes.add(getInputs(toscaServiceModel, objMap.get("get_input"))); + /* + return Map with key - compute node template id, value - list of connected port node template id + */ + private Map> getComputeToPortsConnection(Map portNodeTemplates) { + Map> computeToPortConnection = new HashMap<>(); + if (MapUtils.isEmpty(portNodeTemplates)) { + return computeToPortConnection; } - } - componentPropertyValues.put(component,computes); + for (String portId : portNodeTemplates.keySet()) { + List bindingRequirementsToCompute = toscaAnalyzerService + .getRequirements(portNodeTemplates.get(portId), ToscaConstants.BINDING_REQUIREMENT_ID); + for (RequirementAssignment bindingRequirementToCompute : bindingRequirementsToCompute) { + computeToPortConnection.putIfAbsent(bindingRequirementToCompute.getNode(), new ArrayList<>()); + computeToPortConnection.get(bindingRequirementToCompute.getNode()).add(portId); + } + } + return computeToPortConnection; } - return componentPropertyValues; - } - - private String getInputs(ToscaServiceModel toscaServiceModel, String inputValue) { - String mainTemplate = toscaServiceModel.getEntryDefinitionServiceTemplate(); - List toscaServiceTemplates = toscaServiceModel.getServiceTemplates().entrySet() - .stream() - .filter(map -> map.getKey().equals(mainTemplate)) - .map(Map.Entry::getValue) - .collect(Collectors.toList()); - ServiceTemplate serviceTemplate = toscaServiceTemplates.get(0); - if (Objects.nonNull(serviceTemplate.getTopology_template()) - && MapUtils.isNotEmpty(serviceTemplate.getTopology_template().getInputs())) { - for (Map.Entry inputEntry : serviceTemplate - .getTopology_template().getInputs().entrySet()) { - if (inputEntry.getKey().equals(inputValue)) { - String value; - try { - value= (String) inputEntry.getValue().get_default(); - } catch (Exception e) { - logger.debug(e.getMessage(), e); - value = inputEntry.getValue().get_default().toString(); - } - return value; + private void extractComponents(ServiceTemplate serviceTemplate, ToscaServiceModel toscaServiceModel, ExtractCompositionDataContext context) { + Map computeNodeTemplates = toscaAnalyzerService + .getNodeTemplatesByType(serviceTemplate, ToscaNodeType.NATIVE_COMPUTE, toscaServiceModel); + if (MapUtils.isEmpty(computeNodeTemplates)) { + return; } - } + Map> imageNodeTemplates = getComponentImages(computeNodeTemplates, toscaServiceModel); + Map> computeFlavorNodeTemplates = getComponentComputeFlavor(computeNodeTemplates, toscaServiceModel); + Map portNodeTemplates = toscaAnalyzerService + .getNodeTemplatesByType(serviceTemplate, ToscaNodeType.NATIVE_NETWORK_PORT, toscaServiceModel); + Map> computeToPortsConnection = getComputeToPortsConnection(portNodeTemplates); + Map> computesGroupedByType = getNodeTemplatesGroupedByType(computeNodeTemplates); + computesGroupedByType.keySet().stream().filter(nodeType -> !context.getCreatedComponents().contains(nodeType)).forEach( + nodeType -> extractComponent(serviceTemplate, computeToPortsConnection, computesGroupedByType, imageNodeTemplates, + computeFlavorNodeTemplates, nodeType, context)); } - return inputValue; - } - - private void extractComponent(ServiceTemplate serviceTemplate, - Map> computeToPortsConnection, - Map> computesGroupedByType, - Map> imageList, - Map> computeFlavorNodeTemplates, - String computeNodeType, - ExtractCompositionDataContext context) { - ComponentData component = new ComponentData(); - component.setName(computeNodeType); - component.setDisplayName(getComponentDisplayName(component.getName())); - Component componentModel = new Component(); - componentModel.setData(component); - - String computeId = computesGroupedByType.get(computeNodeType).get(0); - List connectedPortIds = computeToPortsConnection.get(computeId); - List images = imageList.get(computeId); - List computeFlavors = computeFlavorNodeTemplates.get(computeId); - if (CollectionUtils.isNotEmpty(connectedPortIds)) { - componentModel.setNics(new ArrayList<>()); - componentModel.setImages(new ArrayList<>()); - componentModel.setCompute(new ArrayList<>()); - - connectedPortIds.forEach(portId -> { - Nic port = extractPort(serviceTemplate, portId); - componentModel.getNics().add(port); - context.addNic(portId, port); - }); - - if (CollectionUtils.isNotEmpty(images)) { - images.forEach(image -> { - Image img = new Image(image); - componentModel.getImages().add(img); - context.addImage(image, img); - }); - } - - if (CollectionUtils.isNotEmpty(computeFlavors)) { - computeFlavors.forEach(flavor -> { - ComputeData computeFlavor = new ComputeData(flavor); - componentModel.getCompute().add(computeFlavor); - context.addCompute(flavor, computeFlavor); - }); - } + private Map> getComponentImages(Map computeNodeTemplates, ToscaServiceModel toscaServiceModel) { + return getComponentProperty(ToscaConstants.COMPUTE_IMAGE, computeNodeTemplates, toscaServiceModel); } - context.addComponent(componentModel); - context.getCreatedComponents().add(computeNodeType); - } - private Nic extractPort(ServiceTemplate serviceTemplate, String portNodeTemplateId) { - Optional portNodeTemplate = - toscaAnalyzerService.getNodeTemplateById(serviceTemplate, portNodeTemplateId); - if (portNodeTemplate.isPresent()) { - Nic port = new Nic(); - port.setName(portNodeTemplateId); - connectPortToNetwork(port, portNodeTemplate.get()); - return port; - } else { - throw new CoreException( - new ToscaInvalidEntryNotFoundErrorBuilder("Node Template", portNodeTemplateId).build()); + private Map> getComponentComputeFlavor(Map computeNodeTemplates, ToscaServiceModel toscaServiceModel) { + return getComponentProperty(ToscaConstants.COMPUTE_FLAVOR, computeNodeTemplates, toscaServiceModel); } - } - private Map> getNodeTemplatesGroupedByType( - Map nodeTemplates) { - Map> nodeTemplatesGrouped = - new HashMap<>(); //key - node type, value - list of node ids with this type - for (String nodeId : nodeTemplates.keySet()) { - String nodeType = nodeTemplates.get(nodeId).getType(); - nodeTemplatesGrouped.putIfAbsent(nodeType, new ArrayList<>()); - nodeTemplatesGrouped.get(nodeType).add(nodeId); + private Map> getComponentProperty(String propertyName, Map computeNodeTemplates, + ToscaServiceModel toscaServiceModel) { + Map> componentPropertyValues = new HashMap<>(); + for (String component : computeNodeTemplates.keySet()) { + List computes = new ArrayList<>(); + Map properties = computeNodeTemplates.get(component).getProperties(); + if (MapUtils.isEmpty(properties)) { + continue; + } + List computesList = properties.entrySet().stream().filter(map -> map.getKey().equals(propertyName)).map(Map.Entry::getValue) + .collect(Collectors.toList()); + for (Object obj : computesList) { + if (obj instanceof String) { + computes.add((String) obj); + } else { + Map objMap = new ObjectMapper().convertValue(obj, Map.class); + computes.add(getInputs(toscaServiceModel, objMap.get("get_input"))); + } + } + componentPropertyValues.put(component, computes); + } + return componentPropertyValues; } - return nodeTemplatesGrouped; - } - private List extractNetworks(ServiceTemplate serviceTemplate, - ToscaServiceModel toscaServiceModel) { - List networks = new ArrayList<>(); - Map networkNodeTemplates = toscaAnalyzerService - .getNodeTemplatesByType(serviceTemplate, ToscaNodeType.NATIVE_NETWORK, - toscaServiceModel); - if (MapUtils.isEmpty(networkNodeTemplates)) { - return networks; - } - for (String networkId : networkNodeTemplates.keySet()) { - Network network = new Network(); - network.setName(networkId); - Optional networkDhcpValue = - getNetworkDhcpValue(serviceTemplate, networkNodeTemplates.get(networkId)); - network.setDhcp(networkDhcpValue.orElse(true)); - networks.add(network); + private String getInputs(ToscaServiceModel toscaServiceModel, String inputValue) { + String mainTemplate = toscaServiceModel.getEntryDefinitionServiceTemplate(); + List toscaServiceTemplates = toscaServiceModel.getServiceTemplates().entrySet().stream() + .filter(map -> map.getKey().equals(mainTemplate)).map(Map.Entry::getValue).collect(Collectors.toList()); + ServiceTemplate serviceTemplate = toscaServiceTemplates.get(0); + if (Objects.nonNull(serviceTemplate.getTopology_template()) && MapUtils.isNotEmpty(serviceTemplate.getTopology_template().getInputs())) { + for (Map.Entry inputEntry : serviceTemplate.getTopology_template().getInputs().entrySet()) { + if (inputEntry.getKey().equals(inputValue)) { + String value; + try { + value = (String) inputEntry.getValue().get_default(); + } catch (Exception e) { + logger.debug(e.getMessage(), e); + value = inputEntry.getValue().get_default().toString(); + } + return value; + } + } + } + return inputValue; } - return networks; - } - //dhcp default value is true - private Optional getNetworkDhcpValue(ServiceTemplate serviceTemplate, - NodeTemplate networkNodeTemplate) { - if (networkNodeTemplate == null) { - return Optional.empty(); - } - if (networkNodeTemplate.getProperties() == null - || networkNodeTemplate.getProperties().get(ToscaConstants.DHCP_ENABLED_PROPERTY_NAME) - == null) { - return Optional.of(true); + private void extractComponent(ServiceTemplate serviceTemplate, Map> computeToPortsConnection, + Map> computesGroupedByType, Map> imageList, + Map> computeFlavorNodeTemplates, String computeNodeType, + ExtractCompositionDataContext context) { + ComponentData component = new ComponentData(); + component.setName(computeNodeType); + component.setDisplayName(getComponentDisplayName(component.getName())); + Component componentModel = new Component(); + componentModel.setData(component); + String computeId = computesGroupedByType.get(computeNodeType).get(0); + List connectedPortIds = computeToPortsConnection.get(computeId); + List images = imageList.get(computeId); + List computeFlavors = computeFlavorNodeTemplates.get(computeId); + if (CollectionUtils.isNotEmpty(connectedPortIds)) { + componentModel.setNics(new ArrayList<>()); + componentModel.setImages(new ArrayList<>()); + componentModel.setCompute(new ArrayList<>()); + connectedPortIds.forEach(portId -> { + Nic port = extractPort(serviceTemplate, portId); + componentModel.getNics().add(port); + context.addNic(portId, port); + }); + if (CollectionUtils.isNotEmpty(images)) { + images.forEach(image -> { + Image img = new Image(image); + componentModel.getImages().add(img); + context.addImage(image, img); + }); + } + if (CollectionUtils.isNotEmpty(computeFlavors)) { + computeFlavors.forEach(flavor -> { + ComputeData computeFlavor = new ComputeData(flavor); + componentModel.getCompute().add(computeFlavor); + context.addCompute(flavor, computeFlavor); + }); + } + } + context.addComponent(componentModel); + context.getCreatedComponents().add(computeNodeType); } - Object dhcp = - networkNodeTemplate.getProperties().get(ToscaConstants.DHCP_ENABLED_PROPERTY_NAME); - if (dhcp instanceof String) { - return Optional.of(Boolean.valueOf((String) dhcp)); - } else if (dhcp instanceof Boolean) { - return Optional.of((Boolean) dhcp); - } else if (dhcp instanceof Map) { - String inputParameterName = - (String) ((Map) dhcp).get(ToscaFunctions.GET_INPUT.getFunctionName()); - if (inputParameterName != null) { - ParameterDefinition inputParameterDefinition = - serviceTemplate.getTopology_template().getInputs().get(inputParameterName); - if (inputParameterDefinition != null) { - if (inputParameterDefinition.get_default() != null) { - return Optional.of(Boolean.valueOf(inputParameterDefinition.get_default().toString())); - } + private Nic extractPort(ServiceTemplate serviceTemplate, String portNodeTemplateId) { + Optional portNodeTemplate = toscaAnalyzerService.getNodeTemplateById(serviceTemplate, portNodeTemplateId); + if (portNodeTemplate.isPresent()) { + Nic port = new Nic(); + port.setName(portNodeTemplateId); + connectPortToNetwork(port, portNodeTemplate.get()); + return port; } else { - throw new CoreException( - new ToscaInvalidEntryNotFoundErrorBuilder("Input Parameter", inputParameterName) - .build()); + throw new CoreException(new ToscaInvalidEntryNotFoundErrorBuilder("Node Template", portNodeTemplateId).build()); } - } } - return Optional.of(true); - } - @Override - public String getComponentDisplayName(String componentName) { - if (componentName == null) { - return null; + private Map> getNodeTemplatesGroupedByType(Map nodeTemplates) { + Map> nodeTemplatesGrouped = + new HashMap<>(); //key - node type, value - list of node ids with this type + for (String nodeId : nodeTemplates.keySet()) { + String nodeType = nodeTemplates.get(nodeId).getType(); + nodeTemplatesGrouped.putIfAbsent(nodeType, new ArrayList<>()); + nodeTemplatesGrouped.get(nodeType).add(nodeId); + } + return nodeTemplatesGrouped; } - String delimiterChar = "."; - if (componentName.contains(delimiterChar)) { - return componentName.substring(componentName.lastIndexOf(delimiterChar) + 1); + + private List extractNetworks(ServiceTemplate serviceTemplate, ToscaServiceModel toscaServiceModel) { + List networks = new ArrayList<>(); + Map networkNodeTemplates = toscaAnalyzerService + .getNodeTemplatesByType(serviceTemplate, ToscaNodeType.NATIVE_NETWORK, toscaServiceModel); + if (MapUtils.isEmpty(networkNodeTemplates)) { + return networks; + } + for (String networkId : networkNodeTemplates.keySet()) { + Network network = new Network(); + network.setName(networkId); + Optional networkDhcpValue = getNetworkDhcpValue(serviceTemplate, networkNodeTemplates.get(networkId)); + network.setDhcp(networkDhcpValue.orElse(true)); + networks.add(network); + } + return networks; } - return componentName; - } + //dhcp default value is true + private Optional getNetworkDhcpValue(ServiceTemplate serviceTemplate, NodeTemplate networkNodeTemplate) { + if (networkNodeTemplate == null) { + return Optional.empty(); + } + if (networkNodeTemplate.getProperties() == null + || networkNodeTemplate.getProperties().get(ToscaConstants.DHCP_ENABLED_PROPERTY_NAME) == null) { + return Optional.of(true); + } + Object dhcp = networkNodeTemplate.getProperties().get(ToscaConstants.DHCP_ENABLED_PROPERTY_NAME); + if (dhcp instanceof String) { + return Optional.of(Boolean.valueOf((String) dhcp)); + } else if (dhcp instanceof Boolean) { + return Optional.of((Boolean) dhcp); + } else if (dhcp instanceof Map) { + String inputParameterName = (String) ((Map) dhcp).get(ToscaFunctions.GET_INPUT.getFunctionName()); + if (inputParameterName != null) { + ParameterDefinition inputParameterDefinition = serviceTemplate.getTopology_template().getInputs().get(inputParameterName); + if (inputParameterDefinition != null) { + if (inputParameterDefinition.get_default() != null) { + return Optional.of(Boolean.valueOf(inputParameterDefinition.get_default().toString())); + } + } else { + throw new CoreException(new ToscaInvalidEntryNotFoundErrorBuilder("Input Parameter", inputParameterName).build()); + } + } + } + return Optional.of(true); + } + @Override + public String getComponentDisplayName(String componentName) { + if (componentName == null) { + return null; + } + String delimiterChar = "."; + if (componentName.contains(delimiterChar)) { + return componentName.substring(componentName.lastIndexOf(delimiterChar) + 1); + } + return componentName; + } } 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/etsi/ETSIServiceImpl.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/etsi/ETSIServiceImpl.java index 951cfc7d1f..258b058df7 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/etsi/ETSIServiceImpl.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/etsi/ETSIServiceImpl.java @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.services.impl.etsi; import static org.openecomp.sdc.tosca.csar.CSARConstants.ARTIFACTS_FOLDER; @@ -63,7 +62,6 @@ import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; public class ETSIServiceImpl implements ETSIService { private static final Logger LOGGER = LoggerFactory.getLogger(ETSIServiceImpl.class); - private final NonManoConfiguration nonManoConfiguration; public ETSIServiceImpl() { @@ -99,25 +97,19 @@ public class ETSIServiceImpl implements ETSIService { .forEach(manifestNonManoSourceEntry -> { final NonManoFolderType nonManoFolderType = nonManoKeyFolderMapping.get(manifestNonManoSourceEntry.getKey()); final List nonManoFileList = manifestNonManoSourceEntry.getValue(); - final Map actualFromToPathMap = nonManoFileList.stream() - .map(nonManoFilePath -> { - final Path normalizedFilePath = resolveNonManoFilePath(originalManifestPath, nonManoFilePath); - final Optional changedPath = updateNonManoPathInHandler(handler, nonManoFolderType, normalizedFilePath); - if (changedPath.isPresent()) { - final Map fromAndToPathMap = new HashMap<>(); - fromAndToPathMap.put(nonManoFilePath, Paths.get(ARTIFACTS_FOLDER).resolve(changedPath.get())); - return fromAndToPathMap; - } - return null; - }) - .filter(Objects::nonNull) - .collect(Collectors.toMap( - fromToPathEntry -> fromToPathEntry.keySet().iterator().next(), - fromToPathEntry -> fromToPathEntry.values().iterator().next() - )); + final Map actualFromToPathMap = nonManoFileList.stream().map(nonManoFilePath -> { + final Path normalizedFilePath = resolveNonManoFilePath(originalManifestPath, nonManoFilePath); + final Optional changedPath = updateNonManoPathInHandler(handler, nonManoFolderType, normalizedFilePath); + if (changedPath.isPresent()) { + final Map fromAndToPathMap = new HashMap<>(); + fromAndToPathMap.put(nonManoFilePath, Paths.get(ARTIFACTS_FOLDER).resolve(changedPath.get())); + return fromAndToPathMap; + } + return null; + }).filter(Objects::nonNull).collect(Collectors.toMap(fromToPathEntry -> fromToPathEntry.keySet().iterator().next(), + fromToPathEntry -> fromToPathEntry.values().iterator().next())); fromToPathMap.putAll(actualFromToPathMap); }); - return MapUtils.isEmpty(fromToPathMap) ? Optional.empty() : Optional.of(fromToPathMap); } @@ -125,7 +117,7 @@ public class ETSIServiceImpl implements ETSIService { * Resolves the non mano file path based on the original manifest path of the onboarded package. * * @param originalManifestPath The original path from the onboarded package manifest - * @param nonManoFilePath The non mano file path defined in the manifest + * @param nonManoFilePath The non mano file path defined in the manifest * @return The resolved and normalized non mano path. */ private Path resolveNonManoFilePath(final Path originalManifestPath, final String nonManoFilePath) { @@ -135,8 +127,8 @@ public class ETSIServiceImpl implements ETSIService { /** * Updates the non mano file path in the package file handler based on the non mano type. * - * @param handler The package file handler - * @param nonManoFolderType The Non Mano type of the file to update + * @param handler The package file handler + * @param nonManoFolderType The Non Mano type of the file to update * @param nonManoOriginalFilePath The Non Mano file original path * @return The new file path if it was updated in the package file handler, otherwise empty. */ @@ -144,23 +136,22 @@ public class ETSIServiceImpl implements ETSIService { final Path nonManoOriginalFilePath) { final Path fixedSourcePath = fixNonManoPath(nonManoOriginalFilePath); if (handler.containsFile(fixedSourcePath.toString())) { - final Path newNonManoPath = Paths.get(nonManoFolderType.getType(), nonManoFolderType.getLocation() - , fixedSourcePath.getFileName().toString()); + final Path newNonManoPath = Paths + .get(nonManoFolderType.getType(), nonManoFolderType.getLocation(), fixedSourcePath.getFileName().toString()); if (!handler.containsFile(newNonManoPath.toString())) { handler.addFile(newNonManoPath.toString(), handler.remove(fixedSourcePath.toString())); return Optional.of(newNonManoPath); } } - return Optional.empty(); } /** * Fix the original non mano file path to the ONAP package file path. - * - * Non mano artifacts that were inside the {@link org.openecomp.sdc.tosca.csar.CSARConstants#ARTIFACTS_FOLDER} path - * are not moved when parsed to ONAP package, but the Manifest declaration can still have the {@link - * org.openecomp.sdc.tosca.csar.CSARConstants#ARTIFACTS_FOLDER} reference in it. If so, that reference is removed. + *

+ * Non mano artifacts that were inside the {@link org.openecomp.sdc.tosca.csar.CSARConstants#ARTIFACTS_FOLDER} path are not moved when parsed to + * ONAP package, but the Manifest declaration can still have the {@link org.openecomp.sdc.tosca.csar.CSARConstants#ARTIFACTS_FOLDER} reference in + * it. If so, that reference is removed. * * @param nonManoOriginalFilePath The original non mano file path * @return The non mano fixed path to ONAP package structure. @@ -174,28 +165,22 @@ public class ETSIServiceImpl implements ETSIService { if (nonManoOriginalFilePath.startsWith(relativeArtifactsPath)) { return relativeArtifactsPath.relativize(nonManoOriginalFilePath); } - return nonManoOriginalFilePath; } @Override - public void updateMainDescriptorPaths(final ToscaServiceModel toscaServiceModel, - final Map fromToMovedArtifactMap) { - final ServiceTemplate entryDefinition = toscaServiceModel.getServiceTemplates() - .get(toscaServiceModel.getEntryDefinitionServiceTemplate()); + public void updateMainDescriptorPaths(final ToscaServiceModel toscaServiceModel, final Map fromToMovedArtifactMap) { + final ServiceTemplate entryDefinition = toscaServiceModel.getServiceTemplates().get(toscaServiceModel.getEntryDefinitionServiceTemplate()); final YamlUtil yamlUtil = new YamlUtil(); final String[] entryDefinitionYaml = {yamlUtil.objectToYaml(entryDefinition)}; - fromToMovedArtifactMap.forEach((fromPath, toPath) -> entryDefinitionYaml[0] = entryDefinitionYaml[0] - .replaceAll(fromPath, toPath.toString())); - - toscaServiceModel.addServiceTemplate(toscaServiceModel.getEntryDefinitionServiceTemplate() - , yamlUtil.yamlToObject(entryDefinitionYaml[0], ServiceTemplate.class)); + fromToMovedArtifactMap.forEach((fromPath, toPath) -> entryDefinitionYaml[0] = entryDefinitionYaml[0].replaceAll(fromPath, toPath.toString())); + toscaServiceModel.addServiceTemplate(toscaServiceModel.getEntryDefinitionServiceTemplate(), + yamlUtil.yamlToObject(entryDefinitionYaml[0], ServiceTemplate.class)); } private boolean hasMetaMandatoryEntries(final ToscaMetadata toscaMetadata) { final Map metaDataEntries = toscaMetadata.getMetaEntries(); - return metaDataEntries.containsKey(ENTRY_DEFINITIONS.getName()) && metaDataEntries - .containsKey(ETSI_ENTRY_MANIFEST.getName()) + return metaDataEntries.containsKey(ENTRY_DEFINITIONS.getName()) && metaDataEntries.containsKey(ETSI_ENTRY_MANIFEST.getName()) && metaDataEntries.containsKey(ETSI_ENTRY_CHANGE_LOG.getName()); } @@ -204,23 +189,21 @@ public class ETSIServiceImpl implements ETSIService { try { Map metadata = getManifest(handler).getMetadata(); if (metadata.containsKey(COMPATIBLE_SPECIFICATION_VERSIONS.getToken())) { - return Arrays.asList(metadata.get(COMPATIBLE_SPECIFICATION_VERSIONS.getToken()).split(",")) - .stream().map(Semver::new).max((v1, v2) -> v1.compareTo(v2)) - .orElse(new Semver(ETSI_VERSION_2_6_1)); + return Arrays.asList(metadata.get(COMPATIBLE_SPECIFICATION_VERSIONS.getToken()).split(",")).stream().map(Semver::new) + .max((v1, v2) -> v1.compareTo(v2)).orElse(new Semver(ETSI_VERSION_2_6_1)); } } catch (Exception ex) { LOGGER.error("An error occurred while getting highest compatible version from manifest file", ex); } return new Semver(ETSI_VERSION_2_6_1); - } @Override public boolean hasCnfEnhancements(final FileContentHandler fileContentHandler) throws IOException { final Manifest manifest = loadManifest(fileContentHandler); return manifest.getNonManoSources().entrySet().stream() - .filter(manifestNonManoSourceEntry -> NonManoArtifactType.ONAP_CNF_HELM.getType() - .equalsIgnoreCase(manifestNonManoSourceEntry.getKey())).findFirst().isPresent(); + .filter(manifestNonManoSourceEntry -> NonManoArtifactType.ONAP_CNF_HELM.getType().equalsIgnoreCase(manifestNonManoSourceEntry.getKey())) + .findFirst().isPresent(); } private Manifest loadManifest(final FileContentHandler handler) throws IOException { @@ -248,9 +231,10 @@ public class ETSIServiceImpl implements ETSIService { public ResourceTypeEnum getResourceType(Manifest manifest) { // Valid manifest should contain whether vnf or pnf related metadata data exclusively in SOL004 standard, + // validation of manifest done during package upload stage - if (manifest != null && !manifest.getMetadata().isEmpty() - && MANIFEST_PNF_METADATA.stream().anyMatch(e -> manifest.getMetadata().containsKey(e))) { + if (manifest != null && !manifest.getMetadata().isEmpty() && MANIFEST_PNF_METADATA.stream() + .anyMatch(e -> manifest.getMetadata().containsKey(e))) { return ResourceTypeEnum.PNF; } // VNF is default resource type @@ -280,11 +264,9 @@ public class ETSIServiceImpl implements ETSIService { private ToscaMetadata getMetadata(FileContentHandler handler) throws IOException { ToscaMetadata metadata; if (handler.containsFile(TOSCA_META_PATH_FILE_NAME)) { - metadata = OnboardingToscaMetadata - .parseToscaMetadataFile(handler.getFileContentAsStream(TOSCA_META_PATH_FILE_NAME)); + metadata = OnboardingToscaMetadata.parseToscaMetadataFile(handler.getFileContentAsStream(TOSCA_META_PATH_FILE_NAME)); } else if (handler.containsFile(TOSCA_META_ORIG_PATH_FILE_NAME)) { - metadata = OnboardingToscaMetadata - .parseToscaMetadataFile(handler.getFileContentAsStream(TOSCA_META_ORIG_PATH_FILE_NAME)); + metadata = OnboardingToscaMetadata.parseToscaMetadataFile(handler.getFileContentAsStream(TOSCA_META_ORIG_PATH_FILE_NAME)); } else { throw new IOException("TOSCA.meta file not found!"); } @@ -293,8 +275,7 @@ public class ETSIServiceImpl implements ETSIService { private ToscaMetadata getOriginalMetadata(final FileContentHandler handler) throws IOException { if (handler.containsFile(TOSCA_META_ORIG_PATH_FILE_NAME)) { - return OnboardingToscaMetadata - .parseToscaMetadataFile(handler.getFileContentAsStream(TOSCA_META_ORIG_PATH_FILE_NAME)); + return OnboardingToscaMetadata.parseToscaMetadataFile(handler.getFileContentAsStream(TOSCA_META_ORIG_PATH_FILE_NAME)); } else { throw new IOException(String.format("%s file not found", TOSCA_META_ORIG_PATH_FILE_NAME)); } @@ -307,7 +288,6 @@ public class ETSIServiceImpl implements ETSIService { } else { io = handler.getFileContentAsStream(manifestLocation); } - if (io == null) { throw new IOException("Manifest file not found!"); } 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 7c11fb65ab..7ba8732091 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 @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.vendorsoftwareproduct.services.impl.filedatastructuremodule; import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters; @@ -72,578 +71,491 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class CandidateServiceImpl implements CandidateService { - private static final Logger logger = LoggerFactory.getLogger(CandidateServiceImpl.class); - private CandidateServiceValidator candidateServiceValidator = new CandidateServiceValidator(); - private ManifestCreator manifestCreator; - private OrchestrationTemplateCandidateDao orchestrationTemplateCandidateDao; - - public CandidateServiceImpl(ManifestCreator manifestCreator, - OrchestrationTemplateCandidateDao orchestrationTemplateCandidateDao) { - this.manifestCreator = manifestCreator; - this.orchestrationTemplateCandidateDao = orchestrationTemplateCandidateDao; - } - - public CandidateServiceImpl() { - } - - @Override - public Optional validateNonEmptyFileToUpload(InputStream fileToUpload, - String fileSuffix) { - String errorMessage = - getErrorWithParameters(Messages.NO_FILE_WAS_UPLOADED_OR_FILE_NOT_EXIST.getErrorMessage(), - fileSuffix); - - if (Objects.isNull(fileToUpload)) { - return Optional.of(new ErrorMessage(ErrorLevel.ERROR, - errorMessage)); - } else { - try { - int available = fileToUpload.available(); - if (available == 0) { - return Optional.of(new ErrorMessage(ErrorLevel.ERROR, - errorMessage)); + + private static final Logger logger = LoggerFactory.getLogger(CandidateServiceImpl.class); + private CandidateServiceValidator candidateServiceValidator = new CandidateServiceValidator(); + private ManifestCreator manifestCreator; + private OrchestrationTemplateCandidateDao orchestrationTemplateCandidateDao; + + public CandidateServiceImpl(ManifestCreator manifestCreator, OrchestrationTemplateCandidateDao orchestrationTemplateCandidateDao) { + this.manifestCreator = manifestCreator; + this.orchestrationTemplateCandidateDao = orchestrationTemplateCandidateDao; + } + + public CandidateServiceImpl() { + } + + @Override + public Optional validateNonEmptyFileToUpload(InputStream fileToUpload, String fileSuffix) { + String errorMessage = getErrorWithParameters(Messages.NO_FILE_WAS_UPLOADED_OR_FILE_NOT_EXIST.getErrorMessage(), fileSuffix); + if (Objects.isNull(fileToUpload)) { + return Optional.of(new ErrorMessage(ErrorLevel.ERROR, errorMessage)); + } else { + try { + int available = fileToUpload.available(); + if (available == 0) { + return Optional.of(new ErrorMessage(ErrorLevel.ERROR, errorMessage)); + } + } catch (IOException e) { + logger.debug(e.getMessage(), e); + return Optional.of(new ErrorMessage(ErrorLevel.ERROR, errorMessage)); + } } - } catch (IOException e) { - logger.debug(e.getMessage(), e); - return Optional.of(new ErrorMessage(ErrorLevel.ERROR, - errorMessage)); - } - } - return Optional.empty(); - } - - @Override - public Optional validateRawZipData(String fileSuffix, - byte[] uploadedFileData) { - if (Objects.isNull(uploadedFileData)) { - return Optional.of(new ErrorMessage(ErrorLevel.ERROR, - getErrorWithParameters(Messages.NO_FILE_WAS_UPLOADED_OR_FILE_NOT_EXIST.getErrorMessage(), - fileSuffix))); - } - return Optional.empty(); - } - - private String heatStructureTreeToFileDataStructure(HeatStructureTree tree, - FileContentHandler zipContentMap, - Map> uploadErrors, - AnalyzedZipHeatFiles analyzedZipHeatFiles) { - FilesDataStructure structure = new FilesDataStructure(); - Set usedEnvFiles = new HashSet<>(); - addHeatsToFileDataStructure(tree, usedEnvFiles, structure, uploadErrors, - analyzedZipHeatFiles); - handleOtherResources(tree, usedEnvFiles, structure); - FilesDataStructure fileDataStructureFromManifest = - createFileDataStructureFromManifest(zipContentMap.getFileContentAsStream(SdcCommon.MANIFEST_NAME)); - List structureArtifacts = structure.getArtifacts(); - structureArtifacts.addAll(fileDataStructureFromManifest.getArtifacts().stream().filter - (artifact -> isNotStrctureArtifact(structureArtifacts, artifact)) - .collect(Collectors.toList())); - handleArtifactsFromTree(tree, structure); - - return JsonUtil.object2Json(structure); - } - - private boolean isNotStrctureArtifact(List structureArtifacts, String artifact) { - return !structureArtifacts.contains(artifact); - } - - @Override - public OrchestrationTemplateCandidateData createCandidateDataEntity( - CandidateDataEntityTo candidateDataEntityTo, InputStream zipFileManifest, - AnalyzedZipHeatFiles analyzedZipHeatFiles) { - FileContentHandler zipContentMap = candidateDataEntityTo.getContentMap(); - FilesDataStructure filesDataStructure; - String dataStructureJson; - - if (zipFileManifest != null) { - // create data structure from manifest - filesDataStructure = createFileDataStructureFromManifest(zipFileManifest); - Set zipFileList = zipContentMap.getFileList(); - balanceManifestFilesWithZipFiles(filesDataStructure, - zipContentMap, analyzedZipHeatFiles); - Set filesDataStructureFiles = getFlatFileNames(filesDataStructure); - filesDataStructure.getUnassigned().addAll(zipFileList.stream() - .filter(fileName -> (!filesDataStructureFiles.contains(fileName) - && !filesDataStructure.getNested().contains(fileName) - && !fileName.equals(SdcCommon.MANIFEST_NAME))) - .collect(Collectors.toList())); - dataStructureJson = JsonUtil.object2Json(filesDataStructure); - } else { - // create data structure from based on naming convention - dataStructureJson = - heatStructureTreeToFileDataStructure(candidateDataEntityTo.getTree(), zipContentMap, - candidateDataEntityTo.getErrors(), analyzedZipHeatFiles); - } - - OrchestrationTemplateCandidateData candidateData = new OrchestrationTemplateCandidateData(); - candidateData.setContentData(ByteBuffer.wrap(candidateDataEntityTo.getUploadedFileData())); - candidateData.setFilesDataStructure(dataStructureJson); - return candidateData; - } - - private void balanceManifestFilesWithZipFiles( - FilesDataStructure filesDataStructure, - FileContentHandler fileContentHandler, AnalyzedZipHeatFiles analyzedZipHeatFiles) { - Set zipFileList = fileContentHandler.getFileList(); - filesDataStructure.getNested().addAll(analyzedZipHeatFiles.getNestedFiles()); - List modules = filesDataStructure.getModules(); - if (CollectionUtils.isEmpty(modules)) { - return; - } - - for (int i = 0; i < modules.size(); i++) { - Module module = modules.get(i); - if (!isFileExistInZipContains(zipFileList, module.getYaml())) { - addFileToUnassigned(filesDataStructure, zipFileList, module.getEnv()); - addFileToUnassigned(filesDataStructure, zipFileList, module.getVol()); - addFileToUnassigned(filesDataStructure, zipFileList, module.getVolEnv()); - modules.remove(i--); - } else if (Objects.nonNull(module.getVol()) && !zipFileList.contains(module.getVol())) { - module.setVol(null); - CollectionUtils - .addIgnoreNull(filesDataStructure.getUnassigned(), module.getVolEnv()); - } else { - if (filesDataStructure.getNested().contains(module.getYaml())) { - moveModuleFileToNested(filesDataStructure, i--, module); + return Optional.empty(); + } + + @Override + public Optional validateRawZipData(String fileSuffix, byte[] uploadedFileData) { + if (Objects.isNull(uploadedFileData)) { + return Optional.of(new ErrorMessage(ErrorLevel.ERROR, + getErrorWithParameters(Messages.NO_FILE_WAS_UPLOADED_OR_FILE_NOT_EXIST.getErrorMessage(), fileSuffix))); } - } - } - } - - private void addFileToUnassigned(FilesDataStructure filesDataStructure, Set zipFileList, - String fileName) { - if (isFileExistInZipContains(zipFileList, fileName)) { - filesDataStructure.getUnassigned().add(fileName); - } - } - - private boolean isFileExistInZipContains(Set zipFileList, String fileName) { - return Objects.nonNull(fileName) && zipFileList.contains(fileName); - } - - private void moveModuleFileToNested(FilesDataStructure filesDataStructure, int i, - Module module) { - if (!filesDataStructure.getNested().contains(module.getYaml())) { - filesDataStructure.getNested().add(module.getYaml()); - } - if (Objects.nonNull(module.getEnv())) { - filesDataStructure.getNested().add(module.getEnv()); - } - if (Objects.nonNull(module.getVol())) { - filesDataStructure.getNested().add(module.getVol()); - } - if (Objects.nonNull(module.getVolEnv())) { - filesDataStructure.getNested().add(module.getVolEnv()); - } - filesDataStructure.getModules().remove(i); - } - - private Set getFlatFileNames(FilesDataStructure filesDataStructure) { - Set fileNames = new HashSet<>(); - if (!CollectionUtils.isEmpty(filesDataStructure.getModules())) { - for (Module module : filesDataStructure.getModules()) { - CollectionUtils.addIgnoreNull(fileNames, module.getEnv()); - CollectionUtils.addIgnoreNull(fileNames, module.getVol()); - CollectionUtils.addIgnoreNull(fileNames, module.getVolEnv()); - CollectionUtils.addIgnoreNull(fileNames, module.getYaml()); - } - } - fileNames.addAll(filesDataStructure.getArtifacts()); - fileNames.addAll(filesDataStructure.getNested()); - fileNames.addAll(filesDataStructure.getUnassigned()); - - return fileNames; - } - - private FilesDataStructure createFileDataStructureFromManifest(InputStream isManifestContent) { - ManifestContent manifestContent = - JsonUtil.json2Object(isManifestContent, ManifestContent.class); - FilesDataStructure structure = new FilesDataStructure(); - for (FileData fileData : manifestContent.getData()) { - if (Objects.nonNull(fileData.getType()) && - fileData.getType().equals(FileData.Type.HEAT)) { - Module module = new Module(); - module.setType(FileData.Type.HEAT); - module.setYaml(fileData.getFile()); - module.setIsBase(fileData.getBase()); - addHeatDependenciesToModule(module, fileData.getData()); - structure.getModules().add(module); - }else if (Objects.nonNull(fileData.getType()) && - fileData.getType().equals(FileData.Type.HELM)) { - Module module = new Module(); - module.setType(FileData.Type.HELM); - module.setYaml(fileData.getFile()); - module.setIsBase(fileData.getBase()); - structure.getModules().add(module); - } - else if (HeatFileAnalyzer.isYamlOrEnvFile(fileData.getFile()) && - !FileData.Type.isArtifact(fileData.getType())) { - structure.getUnassigned().add(fileData.getFile()); - } else { - structure.getArtifacts().add(fileData.getFile()); - } - } - return structure; - } - - private void addHeatDependenciesToModule(Module module, List data) { - if (CollectionUtils.isEmpty(data)) { - return; - } - - for (FileData fileData : data) { - if (fileData.getType().equals(FileData.Type.HEAT_ENV)) { - module.setEnv(fileData.getFile()); - } else if (fileData.getType().equals(FileData.Type.HEAT_VOL)) { // must be volume - module.setVol(fileData.getFile()); - if (!CollectionUtils.isEmpty(fileData.getData())) { - FileData volEnv = fileData.getData().get(0); - if (volEnv.getType().equals(FileData.Type.HEAT_ENV)) { - module.setVolEnv(volEnv.getFile()); - } else { - throw new CoreException((new ErrorCode.ErrorCodeBuilder()) - .withMessage(Messages.ILLEGAL_MANIFEST.getErrorMessage()) - .withId(Messages.ILLEGAL_MANIFEST.getErrorMessage()) - .withCategory(ErrorCategory.APPLICATION).build()); - } + return Optional.empty(); + } + + private String heatStructureTreeToFileDataStructure(HeatStructureTree tree, FileContentHandler zipContentMap, + Map> uploadErrors, AnalyzedZipHeatFiles analyzedZipHeatFiles) { + FilesDataStructure structure = new FilesDataStructure(); + Set usedEnvFiles = new HashSet<>(); + addHeatsToFileDataStructure(tree, usedEnvFiles, structure, uploadErrors, analyzedZipHeatFiles); + handleOtherResources(tree, usedEnvFiles, structure); + FilesDataStructure fileDataStructureFromManifest = createFileDataStructureFromManifest( + zipContentMap.getFileContentAsStream(SdcCommon.MANIFEST_NAME)); + List structureArtifacts = structure.getArtifacts(); + structureArtifacts.addAll( + fileDataStructureFromManifest.getArtifacts().stream().filter(artifact -> isNotStrctureArtifact(structureArtifacts, artifact)) + .collect(Collectors.toList())); + handleArtifactsFromTree(tree, structure); + return JsonUtil.object2Json(structure); + } + + private boolean isNotStrctureArtifact(List structureArtifacts, String artifact) { + return !structureArtifacts.contains(artifact); + } + + @Override + public OrchestrationTemplateCandidateData createCandidateDataEntity(CandidateDataEntityTo candidateDataEntityTo, InputStream zipFileManifest, + AnalyzedZipHeatFiles analyzedZipHeatFiles) { + FileContentHandler zipContentMap = candidateDataEntityTo.getContentMap(); + FilesDataStructure filesDataStructure; + String dataStructureJson; + if (zipFileManifest != null) { + // create data structure from manifest + filesDataStructure = createFileDataStructureFromManifest(zipFileManifest); + Set zipFileList = zipContentMap.getFileList(); + balanceManifestFilesWithZipFiles(filesDataStructure, zipContentMap, analyzedZipHeatFiles); + Set filesDataStructureFiles = getFlatFileNames(filesDataStructure); + filesDataStructure.getUnassigned().addAll(zipFileList.stream().filter( + fileName -> (!filesDataStructureFiles.contains(fileName) && !filesDataStructure.getNested().contains(fileName) && !fileName + .equals(SdcCommon.MANIFEST_NAME))).collect(Collectors.toList())); + dataStructureJson = JsonUtil.object2Json(filesDataStructure); + } else { + // create data structure from based on naming convention + dataStructureJson = heatStructureTreeToFileDataStructure(candidateDataEntityTo.getTree(), zipContentMap, + candidateDataEntityTo.getErrors(), analyzedZipHeatFiles); } - } else { - throw new CoreException((new ErrorCode.ErrorCodeBuilder()) - .withMessage(Messages.FILE_TYPE_NOT_LEGAL.getErrorMessage()) - .withId(Messages.FILE_TYPE_NOT_LEGAL.getErrorMessage()) - .withCategory(ErrorCategory.APPLICATION).build()); - } - } - } - - @Override - public void updateCandidateUploadData(final String vspId, final Version version, - final OrchestrationTemplateCandidateData uploadData) { - orchestrationTemplateCandidateDao.update(vspId, version, uploadData); - } - - @Override - public Optional getOrchestrationTemplateCandidateFileDataStructure( - String vspId, Version version) { - Optional jsonFileDataStructure = - orchestrationTemplateCandidateDao.getStructure(vspId, version); - - if (jsonFileDataStructure.isPresent() && JsonUtil.isValidJson(jsonFileDataStructure.get())) { - return Optional - .of(JsonUtil.json2Object(jsonFileDataStructure.get(), FilesDataStructure.class)); - } else { - return Optional.empty(); - } - } - - @Override - public void updateOrchestrationTemplateCandidateFileDataStructure(String vspId, Version version, - FilesDataStructure fileDataStructure) { - OrchestrationTemplateCandidateDaoFactory.getInstance().createInterface() - .updateStructure(vspId, version, fileDataStructure); - } - - @Override - public Optional getOrchestrationTemplateCandidate(String vspId, - Version version) { - return orchestrationTemplateCandidateDao.get(vspId, version); - } - - @Override - public Optional getOrchestrationTemplateCandidateInfo( - String vspId, - Version version) { - return orchestrationTemplateCandidateDao.getInfo(vspId, version); - } - - @Override - public String createManifest(VspDetails vspDetails, FilesDataStructure structure) { - return JsonUtil.object2Json(manifestCreator.createManifest(vspDetails, structure) - .orElseThrow(() -> new CoreException(new ErrorCode.ErrorCodeBuilder() - .withMessage(Messages.CREATE_MANIFEST_FROM_ZIP.getErrorMessage()).build()))); - } - - @Override - public String createManifestFromExisting(VspDetails vspDetails, FilesDataStructure structure, ManifestContent existingManifest) { - return JsonUtil.object2Json(manifestCreator.createManifestFromExisting(vspDetails, structure, existingManifest) - .orElseThrow(() -> new CoreException(new ErrorCode.ErrorCodeBuilder() - .withMessage(Messages.CREATE_MANIFEST_FROM_ZIP.getErrorMessage()).build()))); - } - - @Override - public Optional createManifest(VspDetails vspDetails, - FileContentHandler fileContentHandler, + OrchestrationTemplateCandidateData candidateData = new OrchestrationTemplateCandidateData(); + candidateData.setContentData(ByteBuffer.wrap(candidateDataEntityTo.getUploadedFileData())); + candidateData.setFilesDataStructure(dataStructureJson); + return candidateData; + } + + private void balanceManifestFilesWithZipFiles(FilesDataStructure filesDataStructure, FileContentHandler fileContentHandler, AnalyzedZipHeatFiles analyzedZipHeatFiles) { - return manifestCreator.createManifest(vspDetails, fileContentHandler, analyzedZipHeatFiles); - } - - @Override - public Optional fetchZipFileByteArrayInputStream(String vspId, - OrchestrationTemplateCandidateData candidateDataEntity, - String manifest, - OnboardingTypesEnum type, - Map> uploadErrors) { - byte[] file; - ByteArrayInputStream byteArrayInputStream = null; - try { - file = replaceManifestInZip(candidateDataEntity.getContentData(), manifest, type); - byteArrayInputStream = new ByteArrayInputStream( - Objects.isNull(file) ? candidateDataEntity.getContentData().array() - : file); - } catch (IOException e) { - ErrorMessage errorMessage = - new ErrorMessage(ErrorLevel.ERROR, - Messages.CANDIDATE_PROCESS_FAILED.getErrorMessage()); - logger.error(errorMessage.getMessage(), e); - ErrorsUtil - .addStructureErrorToErrorMap(SdcCommon.UPLOAD_FILE, errorMessage, uploadErrors); - } - return Optional.ofNullable(byteArrayInputStream); - } - - @Override - public byte[] replaceManifestInZip(ByteBuffer contentData, String manifest, - OnboardingTypesEnum type) - throws IOException { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - - try (final ZipOutputStream zos = new ZipOutputStream(baos); - ZipInputStream zipStream = new ZipInputStream( - new ByteArrayInputStream(contentData.array()))) { - ZipEntry zipEntry; - boolean manifestWritten = false; - while ((zipEntry = zipStream.getNextEntry()) != null) { - if (!zipEntry.getName().equalsIgnoreCase(SdcCommon.MANIFEST_NAME)) { - ZipEntry loc_ze = new ZipEntry(zipEntry.getName()); - zos.putNextEntry(loc_ze); - byte[] buf = new byte[1024]; - int len; - while ((len = zipStream.read(buf)) > 0) { - zos.write(buf, 0, (len < buf.length) ? len : buf.length); - } + Set zipFileList = fileContentHandler.getFileList(); + filesDataStructure.getNested().addAll(analyzedZipHeatFiles.getNestedFiles()); + List modules = filesDataStructure.getModules(); + if (CollectionUtils.isEmpty(modules)) { + return; + } + for (int i = 0; i < modules.size(); i++) { + Module module = modules.get(i); + if (!isFileExistInZipContains(zipFileList, module.getYaml())) { + addFileToUnassigned(filesDataStructure, zipFileList, module.getEnv()); + addFileToUnassigned(filesDataStructure, zipFileList, module.getVol()); + addFileToUnassigned(filesDataStructure, zipFileList, module.getVolEnv()); + modules.remove(i--); + } else if (Objects.nonNull(module.getVol()) && !zipFileList.contains(module.getVol())) { + module.setVol(null); + CollectionUtils.addIgnoreNull(filesDataStructure.getUnassigned(), module.getVolEnv()); + } else { + if (filesDataStructure.getNested().contains(module.getYaml())) { + moveModuleFileToNested(filesDataStructure, i--, module); + } + } + } + } + + private void addFileToUnassigned(FilesDataStructure filesDataStructure, Set zipFileList, String fileName) { + if (isFileExistInZipContains(zipFileList, fileName)) { + filesDataStructure.getUnassigned().add(fileName); + } + } + + private boolean isFileExistInZipContains(Set zipFileList, String fileName) { + return Objects.nonNull(fileName) && zipFileList.contains(fileName); + } + + private void moveModuleFileToNested(FilesDataStructure filesDataStructure, int i, Module module) { + if (!filesDataStructure.getNested().contains(module.getYaml())) { + filesDataStructure.getNested().add(module.getYaml()); + } + if (Objects.nonNull(module.getEnv())) { + filesDataStructure.getNested().add(module.getEnv()); + } + if (Objects.nonNull(module.getVol())) { + filesDataStructure.getNested().add(module.getVol()); + } + if (Objects.nonNull(module.getVolEnv())) { + filesDataStructure.getNested().add(module.getVolEnv()); + } + filesDataStructure.getModules().remove(i); + } + + private Set getFlatFileNames(FilesDataStructure filesDataStructure) { + Set fileNames = new HashSet<>(); + if (!CollectionUtils.isEmpty(filesDataStructure.getModules())) { + for (Module module : filesDataStructure.getModules()) { + CollectionUtils.addIgnoreNull(fileNames, module.getEnv()); + CollectionUtils.addIgnoreNull(fileNames, module.getVol()); + CollectionUtils.addIgnoreNull(fileNames, module.getVolEnv()); + CollectionUtils.addIgnoreNull(fileNames, module.getYaml()); + } + } + fileNames.addAll(filesDataStructure.getArtifacts()); + fileNames.addAll(filesDataStructure.getNested()); + fileNames.addAll(filesDataStructure.getUnassigned()); + return fileNames; + } + + private FilesDataStructure createFileDataStructureFromManifest(InputStream isManifestContent) { + ManifestContent manifestContent = JsonUtil.json2Object(isManifestContent, ManifestContent.class); + FilesDataStructure structure = new FilesDataStructure(); + for (FileData fileData : manifestContent.getData()) { + if (Objects.nonNull(fileData.getType()) && fileData.getType().equals(FileData.Type.HEAT)) { + Module module = new Module(); + module.setType(FileData.Type.HEAT); + module.setYaml(fileData.getFile()); + module.setIsBase(fileData.getBase()); + addHeatDependenciesToModule(module, fileData.getData()); + structure.getModules().add(module); + } else if (Objects.nonNull(fileData.getType()) && fileData.getType().equals(FileData.Type.HELM)) { + Module module = new Module(); + module.setType(FileData.Type.HELM); + module.setYaml(fileData.getFile()); + module.setIsBase(fileData.getBase()); + structure.getModules().add(module); + } else if (HeatFileAnalyzer.isYamlOrEnvFile(fileData.getFile()) && !FileData.Type.isArtifact(fileData.getType())) { + structure.getUnassigned().add(fileData.getFile()); + } else { + structure.getArtifacts().add(fileData.getFile()); + } + } + return structure; + } + + private void addHeatDependenciesToModule(Module module, List data) { + if (CollectionUtils.isEmpty(data)) { + return; + } + for (FileData fileData : data) { + if (fileData.getType().equals(FileData.Type.HEAT_ENV)) { + module.setEnv(fileData.getFile()); + } else if (fileData.getType().equals(FileData.Type.HEAT_VOL)) { // must be volume + module.setVol(fileData.getFile()); + if (!CollectionUtils.isEmpty(fileData.getData())) { + FileData volEnv = fileData.getData().get(0); + if (volEnv.getType().equals(FileData.Type.HEAT_ENV)) { + module.setVolEnv(volEnv.getFile()); + } else { + throw new CoreException((new ErrorCode.ErrorCodeBuilder()).withMessage(Messages.ILLEGAL_MANIFEST.getErrorMessage()) + .withId(Messages.ILLEGAL_MANIFEST.getErrorMessage()).withCategory(ErrorCategory.APPLICATION).build()); + } + } + } else { + throw new CoreException((new ErrorCode.ErrorCodeBuilder()).withMessage(Messages.FILE_TYPE_NOT_LEGAL.getErrorMessage()) + .withId(Messages.FILE_TYPE_NOT_LEGAL.getErrorMessage()).withCategory(ErrorCategory.APPLICATION).build()); + } + } + } + + @Override + public void updateCandidateUploadData(final String vspId, final Version version, final OrchestrationTemplateCandidateData uploadData) { + orchestrationTemplateCandidateDao.update(vspId, version, uploadData); + } + + @Override + public Optional getOrchestrationTemplateCandidateFileDataStructure(String vspId, Version version) { + Optional jsonFileDataStructure = orchestrationTemplateCandidateDao.getStructure(vspId, version); + if (jsonFileDataStructure.isPresent() && JsonUtil.isValidJson(jsonFileDataStructure.get())) { + return Optional.of(JsonUtil.json2Object(jsonFileDataStructure.get(), FilesDataStructure.class)); } else { - manifestWritten = true; - writeManifest(manifest, type, zos); + return Optional.empty(); } - zos.closeEntry(); - } - if (!manifestWritten) { - writeManifest(manifest, type, zos); - zos.closeEntry(); - } - } - return baos.toByteArray(); - } - - @Override - public byte[] getZipData(ByteBuffer contentData) - throws IOException { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - - try (final ZipOutputStream zos = new ZipOutputStream(baos); - ZipInputStream zipStream = new ZipInputStream( - new ByteArrayInputStream(contentData.array()))) { - ZipEntry zipEntry; - while ((zipEntry = zipStream.getNextEntry()) != null) { + } + + @Override + public void updateOrchestrationTemplateCandidateFileDataStructure(String vspId, Version version, FilesDataStructure fileDataStructure) { + OrchestrationTemplateCandidateDaoFactory.getInstance().createInterface().updateStructure(vspId, version, fileDataStructure); + } + + @Override + public Optional getOrchestrationTemplateCandidate(String vspId, Version version) { + return orchestrationTemplateCandidateDao.get(vspId, version); + } + + @Override + public Optional getOrchestrationTemplateCandidateInfo(String vspId, Version version) { + return orchestrationTemplateCandidateDao.getInfo(vspId, version); + } + + @Override + public String createManifest(VspDetails vspDetails, FilesDataStructure structure) { + return JsonUtil.object2Json(manifestCreator.createManifest(vspDetails, structure).orElseThrow( + () -> new CoreException(new ErrorCode.ErrorCodeBuilder().withMessage(Messages.CREATE_MANIFEST_FROM_ZIP.getErrorMessage()).build()))); + } + + @Override + public String createManifestFromExisting(VspDetails vspDetails, FilesDataStructure structure, ManifestContent existingManifest) { + return JsonUtil.object2Json(manifestCreator.createManifestFromExisting(vspDetails, structure, existingManifest).orElseThrow( + () -> new CoreException(new ErrorCode.ErrorCodeBuilder().withMessage(Messages.CREATE_MANIFEST_FROM_ZIP.getErrorMessage()).build()))); + } + + @Override + public Optional createManifest(VspDetails vspDetails, FileContentHandler fileContentHandler, + AnalyzedZipHeatFiles analyzedZipHeatFiles) { + return manifestCreator.createManifest(vspDetails, fileContentHandler, analyzedZipHeatFiles); + } + + @Override + public Optional fetchZipFileByteArrayInputStream(String vspId, OrchestrationTemplateCandidateData candidateDataEntity, + String manifest, OnboardingTypesEnum type, + Map> uploadErrors) { + byte[] file; + ByteArrayInputStream byteArrayInputStream = null; try { - ZipUtils.checkForZipSlipInRead(zipEntry); - } catch (ZipSlipException e) { - throw new IOException(e); + file = replaceManifestInZip(candidateDataEntity.getContentData(), manifest, type); + byteArrayInputStream = new ByteArrayInputStream(Objects.isNull(file) ? candidateDataEntity.getContentData().array() : file); + } catch (IOException e) { + ErrorMessage errorMessage = new ErrorMessage(ErrorLevel.ERROR, Messages.CANDIDATE_PROCESS_FAILED.getErrorMessage()); + logger.error(errorMessage.getMessage(), e); + ErrorsUtil.addStructureErrorToErrorMap(SdcCommon.UPLOAD_FILE, errorMessage, uploadErrors); } - ZipEntry locZipEntry = new ZipEntry(zipEntry.getName()); - zos.putNextEntry(locZipEntry); - byte[] buf = new byte[1024]; - int len; - while ((len = zipStream.read(buf)) > 0) { - zos.write(buf, 0, (len < buf.length) ? len : buf.length); + return Optional.ofNullable(byteArrayInputStream); + } + + @Override + public byte[] replaceManifestInZip(ByteBuffer contentData, String manifest, OnboardingTypesEnum type) throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (final ZipOutputStream zos = new ZipOutputStream(baos); ZipInputStream zipStream = new ZipInputStream( + new ByteArrayInputStream(contentData.array()))) { + ZipEntry zipEntry; + boolean manifestWritten = false; + while ((zipEntry = zipStream.getNextEntry()) != null) { + if (!zipEntry.getName().equalsIgnoreCase(SdcCommon.MANIFEST_NAME)) { + ZipEntry loc_ze = new ZipEntry(zipEntry.getName()); + zos.putNextEntry(loc_ze); + byte[] buf = new byte[1024]; + int len; + while ((len = zipStream.read(buf)) > 0) { + zos.write(buf, 0, (len < buf.length) ? len : buf.length); + } + } else { + manifestWritten = true; + writeManifest(manifest, type, zos); + } + zos.closeEntry(); + } + if (!manifestWritten) { + writeManifest(manifest, type, zos); + zos.closeEntry(); + } } - zos.closeEntry(); - } + return baos.toByteArray(); } - return baos.toByteArray(); - } - @Override - public Optional> validateFileDataStructure( - FilesDataStructure filesDataStructure) { - return candidateServiceValidator.validateFileDataStructure(filesDataStructure); - } + @Override + public byte[] getZipData(ByteBuffer contentData) throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (final ZipOutputStream zos = new ZipOutputStream(baos); ZipInputStream zipStream = new ZipInputStream( + new ByteArrayInputStream(contentData.array()))) { + ZipEntry zipEntry; + while ((zipEntry = zipStream.getNextEntry()) != null) { + try { + ZipUtils.checkForZipSlipInRead(zipEntry); + } catch (ZipSlipException e) { + throw new IOException(e); + } + ZipEntry locZipEntry = new ZipEntry(zipEntry.getName()); + zos.putNextEntry(locZipEntry); + byte[] buf = new byte[1024]; + int len; + while ((len = zipStream.read(buf)) > 0) { + zos.write(buf, 0, (len < buf.length) ? len : buf.length); + } + zos.closeEntry(); + } + } + return baos.toByteArray(); + } - @Override - public void deleteOrchestrationTemplateCandidate(String vspId, Version versionId) { - orchestrationTemplateCandidateDao.delete(vspId, versionId); - } + @Override + public Optional> validateFileDataStructure(FilesDataStructure filesDataStructure) { + return candidateServiceValidator.validateFileDataStructure(filesDataStructure); + } - @Override - public void updateValidationData(String vspId, Version version, ValidationStructureList - validationData) { - orchestrationTemplateCandidateDao.updateValidationData(vspId, version, validationData); - } + @Override + public void deleteOrchestrationTemplateCandidate(String vspId, Version versionId) { + orchestrationTemplateCandidateDao.delete(vspId, versionId); + } - private void writeManifest(String manifest, - OnboardingTypesEnum type, - ZipOutputStream zos) throws IOException { + @Override + public void updateValidationData(String vspId, Version version, ValidationStructureList validationData) { + orchestrationTemplateCandidateDao.updateValidationData(vspId, version, validationData); + } - if (isManifestNeedsToGetWritten(type)) { - return; + private void writeManifest(String manifest, OnboardingTypesEnum type, ZipOutputStream zos) throws IOException { + if (isManifestNeedsToGetWritten(type)) { + return; + } + zos.putNextEntry(new ZipEntry(SdcCommon.MANIFEST_NAME)); + try (InputStream manifestStream = new ByteArrayInputStream(manifest.getBytes(StandardCharsets.UTF_8))) { + byte[] buf = new byte[1024]; + int len; + while ((len = (manifestStream.read(buf))) > 0) { + zos.write(buf, 0, (len < buf.length) ? len : buf.length); + } + } } - zos.putNextEntry(new ZipEntry(SdcCommon.MANIFEST_NAME)); - try (InputStream manifestStream = new ByteArrayInputStream( - manifest.getBytes(StandardCharsets.UTF_8))) { - byte[] buf = new byte[1024]; - int len; - while ((len = (manifestStream.read(buf))) > 0) { - zos.write(buf, 0, (len < buf.length) ? len : buf.length); - } + private boolean isManifestNeedsToGetWritten(OnboardingTypesEnum type) { + return type.equals(OnboardingTypesEnum.CSAR); } - } - private boolean isManifestNeedsToGetWritten(OnboardingTypesEnum type) { - return type.equals(OnboardingTypesEnum.CSAR); - } + private void handleArtifactsFromTree(HeatStructureTree tree, FilesDataStructure structure) { + if (Objects.isNull(tree) || Objects.isNull(tree.getArtifacts())) { + return; + } + if (CollectionUtils.isNotEmpty(tree.getArtifacts())) { + structure.getArtifacts().addAll( + tree.getArtifacts().stream().map(Artifact::getFileName).filter(fileName -> !structure.getArtifacts().contains(fileName)) + .collect(Collectors.toList())); + } + } + + private void handleOtherResources(HeatStructureTree tree, Set usedEnvFiles, FilesDataStructure structure) { + Set others = tree.getOther(); + if (Objects.isNull(others)) { + return; + } + List artifacts = new ArrayList<>(); + List unassigned = new ArrayList<>(); + for (HeatStructureTree other : others) { + if (HeatFileAnalyzer.isYamlOrEnvFile(other.getFileName())) { + if (isEnvFileUsedByHeatFile(usedEnvFiles, other)) { + continue; + } + unassigned.add(other.getFileName()); + } else { + artifacts.add(other.getFileName()); + } + handleArtifactsFromTree(other, structure); + } + structure.getArtifacts().addAll(artifacts); + structure.getUnassigned().addAll(unassigned); + } - private void handleArtifactsFromTree(HeatStructureTree tree, FilesDataStructure structure) { + private boolean isEnvFileUsedByHeatFile(Set usedEnvFiles, HeatStructureTree other) { + return HeatFileAnalyzer.isEnvFile(other.getFileName()) && usedEnvFiles.contains(other.getFileName()); + } - if (Objects.isNull(tree) || Objects.isNull(tree.getArtifacts())) { - return; + private void addHeatsToFileDataStructure(HeatStructureTree tree, Set usedEnvFiles, FilesDataStructure structure, + Map> uploadErrors, AnalyzedZipHeatFiles analyzedZipHeatFiles) { + List modules = new ArrayList<>(); + Set heatsSet = tree.getHeat(); + if (Objects.isNull(heatsSet)) { + return; + } + for (HeatStructureTree heat : heatsSet) { + if (isFileBaseFile(heat.getFileName())) { + handleSingleHeat(structure, modules, heat, uploadErrors); + } else if (isFileModuleFile(heat.getFileName(), analyzedZipHeatFiles.getModuleFiles())) { + handleSingleHeat(structure, modules, heat, uploadErrors); + } else { + structure.getUnassigned().add(heat.getFileName()); + addNestedToFileDataStructure(heat, structure); + } + if (!Objects.isNull(heat.getEnv())) { + usedEnvFiles.add(heat.getEnv() == null ? null : heat.getEnv().getFileName()); + } + } + structure.setModules(modules); } - if (CollectionUtils.isNotEmpty(tree.getArtifacts())) { - structure.getArtifacts().addAll( - tree.getArtifacts() - .stream() - .map(Artifact::getFileName) - .filter(fileName -> !structure.getArtifacts().contains(fileName)) - .collect(Collectors.toList())); + private boolean isFileModuleFile(String fileName, Set modulesFileNames) { + return modulesFileNames.contains(fileName); } - } - private void handleOtherResources(HeatStructureTree tree, Set usedEnvFiles, - FilesDataStructure structure) { - Set others = tree.getOther(); - if (Objects.isNull(others)) { - return; + private boolean isFileBaseFile(String fileName) { + return manifestCreator.isFileBaseFile(fileName); } - List artifacts = new ArrayList<>(); - List unassigned = new ArrayList<>(); - for (HeatStructureTree other : others) { - if (HeatFileAnalyzer.isYamlOrEnvFile(other.getFileName())) { - if (isEnvFileUsedByHeatFile(usedEnvFiles, other)) { - continue; - } - unassigned.add(other.getFileName()); - } else { - artifacts.add(other.getFileName()); - } - handleArtifactsFromTree(other, structure); - } - structure.getArtifacts().addAll(artifacts); - structure.getUnassigned().addAll(unassigned); - } - - private boolean isEnvFileUsedByHeatFile(Set usedEnvFiles, HeatStructureTree other) { - return HeatFileAnalyzer.isEnvFile(other.getFileName()) && - usedEnvFiles.contains(other.getFileName()); - } - - private void addHeatsToFileDataStructure(HeatStructureTree tree, Set usedEnvFiles, - FilesDataStructure structure, - Map> uploadErrors, - AnalyzedZipHeatFiles analyzedZipHeatFiles) { - List modules = new ArrayList<>(); - Set heatsSet = tree.getHeat(); - if (Objects.isNull(heatsSet)) { - return; - } - for (HeatStructureTree heat : heatsSet) { - if (isFileBaseFile(heat.getFileName())) { - handleSingleHeat(structure, modules, heat, uploadErrors); - } else if (isFileModuleFile(heat.getFileName(), - analyzedZipHeatFiles.getModuleFiles())) { - handleSingleHeat(structure, modules, heat, uploadErrors); - } else { - structure.getUnassigned().add(heat.getFileName()); + private void handleSingleHeat(FilesDataStructure structure, List modules, HeatStructureTree heat, + Map> uploadErrors) { + Module module = new Module(); + module.setYaml(heat.getFileName()); + module.setIsBase(heat.getBase()); addNestedToFileDataStructure(heat, structure); - } - if (!Objects.isNull(heat.getEnv())) { - usedEnvFiles.add(heat.getEnv() == null ? null : heat.getEnv().getFileName()); - } - } - structure.setModules(modules); - - } - - private boolean isFileModuleFile(String fileName, Set modulesFileNames) { - return modulesFileNames.contains(fileName); - } - - private boolean isFileBaseFile(String fileName) { - return manifestCreator.isFileBaseFile(fileName); - } - - private void handleSingleHeat(FilesDataStructure structure, List modules, - HeatStructureTree heat, - Map> uploadErrors) { - Module module = new Module(); - module.setYaml(heat.getFileName()); - module.setIsBase(heat.getBase()); - addNestedToFileDataStructure(heat, structure); - Set volumeSet = heat.getVolume(); - int inx = 0; - if (Objects.nonNull(volumeSet)) { - handleVolumes(module, volumeSet, structure, inx, uploadErrors); - } - handleEnv(module, heat, false, structure); - modules.add(module); - } - - private void handleVolumes(Module module, Set volumeSet, - FilesDataStructure structure, int inx, - Map> uploadErrors) { - for (HeatStructureTree volume : volumeSet) { - Objects.requireNonNull(volume, "volume cannot be null!"); - if (inx++ > 0) { - ErrorsUtil.addStructureErrorToErrorMap(SdcCommon.UPLOAD_FILE, - new ErrorMessage(ErrorLevel.WARNING, - Messages.MORE_THEN_ONE_VOL_FOR_HEAT.getErrorMessage()), uploadErrors); - break; - } - handleArtifactsFromTree(volume, structure); - module.setVol(volume.getFileName()); - handleEnv(module, volume, true, structure); - addNestedToFileDataStructure(volume, structure); - } - } - - private void handleEnv(Module module, HeatStructureTree tree, boolean isVolEnv, - FilesDataStructure structure) { - if (Objects.nonNull(tree.getEnv())) { - if (isVolEnv) { - module.setVolEnv(tree.getEnv().getFileName()); - } else { - module.setEnv(tree.getEnv().getFileName()); - } - handleArtifactsFromTree(tree.getEnv(), structure); - } - } - - private void addNestedToFileDataStructure(HeatStructureTree heat, - FilesDataStructure structure) { - Set nestedSet = heat.getNested(); - if (Objects.isNull(nestedSet)) { - return; - } - for (HeatStructureTree nested : nestedSet) { - if (structure.getNested().contains(nested.getFileName())) { - continue; - } - structure.getNested().add(nested.getFileName()); - if (CollectionUtils.isNotEmpty(nested.getArtifacts())) { - handleArtifactsFromTree(nested, structure); - } - addNestedToFileDataStructure(nested, structure); - } - } + Set volumeSet = heat.getVolume(); + int inx = 0; + if (Objects.nonNull(volumeSet)) { + handleVolumes(module, volumeSet, structure, inx, uploadErrors); + } + handleEnv(module, heat, false, structure); + modules.add(module); + } + + private void handleVolumes(Module module, Set volumeSet, FilesDataStructure structure, int inx, + Map> uploadErrors) { + for (HeatStructureTree volume : volumeSet) { + Objects.requireNonNull(volume, "volume cannot be null!"); + if (inx++ > 0) { + ErrorsUtil.addStructureErrorToErrorMap(SdcCommon.UPLOAD_FILE, + new ErrorMessage(ErrorLevel.WARNING, Messages.MORE_THEN_ONE_VOL_FOR_HEAT.getErrorMessage()), uploadErrors); + break; + } + handleArtifactsFromTree(volume, structure); + module.setVol(volume.getFileName()); + handleEnv(module, volume, true, structure); + addNestedToFileDataStructure(volume, structure); + } + } + + private void handleEnv(Module module, HeatStructureTree tree, boolean isVolEnv, FilesDataStructure structure) { + if (Objects.nonNull(tree.getEnv())) { + if (isVolEnv) { + module.setVolEnv(tree.getEnv().getFileName()); + } else { + module.setEnv(tree.getEnv().getFileName()); + } + handleArtifactsFromTree(tree.getEnv(), structure); + } + } + + private void addNestedToFileDataStructure(HeatStructureTree heat, FilesDataStructure structure) { + Set nestedSet = heat.getNested(); + if (Objects.isNull(nestedSet)) { + return; + } + for (HeatStructureTree nested : nestedSet) { + if (structure.getNested().contains(nested.getFileName())) { + continue; + } + structure.getNested().add(nested.getFileName()); + if (CollectionUtils.isNotEmpty(nested.getArtifacts())) { + handleArtifactsFromTree(nested, structure); + } + addNestedToFileDataStructure(nested, structure); + } + } } 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/ManifestCreatorNamingConventionImpl.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/ManifestCreatorNamingConventionImpl.java index 54cc1fbf1c..f935318d01 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/ManifestCreatorNamingConventionImpl.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/ManifestCreatorNamingConventionImpl.java @@ -14,9 +14,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.vendorsoftwareproduct.services.impl.filedatastructuremodule; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.regex.Pattern; import org.apache.commons.collections4.CollectionUtils; import org.openecomp.core.utilities.file.FileContentHandler; import org.openecomp.sdc.heat.datatypes.manifest.FileData; @@ -31,322 +40,278 @@ import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.Module; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.*; -import java.util.regex.Pattern; - public class ManifestCreatorNamingConventionImpl implements ManifestCreator { - protected static final Logger logger = - LoggerFactory.getLogger(ManifestCreatorNamingConventionImpl.class); - - private static final String CLOUD_SPECIFIC_FIXED_KEY_WORD = "cloudtech"; - private static final String[][] CLOUD_SPECIFIC_KEY_WORDS = {{"k8s", "azure", "aws"}, /* cloud specific technology */ - {"charts", "day0", "configtemplate"} /*cloud specific sub type*/}; - private static final String CONTROLLER_BLUEPRINT_ARCHIVE_FIXED_KEY_WORD = "CBA"; - private static final String HELM_KEY_WORD = "HELM"; - @Override - public Optional createManifest( - VspDetails vspDetails, FilesDataStructure filesDataStructure) { - if (Objects.isNull(filesDataStructure)) { - return Optional.empty(); + protected static final Logger logger = LoggerFactory.getLogger(ManifestCreatorNamingConventionImpl.class); + private static final String CLOUD_SPECIFIC_FIXED_KEY_WORD = "cloudtech"; + private static final String[][] CLOUD_SPECIFIC_KEY_WORDS = {{"k8s", "azure", "aws"}, /* cloud specific technology */ + {"charts", "day0", "configtemplate"} /*cloud specific sub type*/}; + private static final String CONTROLLER_BLUEPRINT_ARCHIVE_FIXED_KEY_WORD = "CBA"; + private static final String HELM_KEY_WORD = "HELM"; + + @Override + public Optional createManifest(VspDetails vspDetails, FilesDataStructure filesDataStructure) { + if (Objects.isNull(filesDataStructure)) { + return Optional.empty(); + } + List fileDataList = new ArrayList<>(); + addModulesToManifestFileDataList(filesDataStructure, fileDataList); + addNestedToManifest(filesDataStructure, fileDataList); + addArtifactsToManifestFileDataList(filesDataStructure, fileDataList); + ManifestContent manifestContent = createManifest(vspDetails, fileDataList); + return Optional.of(manifestContent); } - List fileDataList = new ArrayList<>(); - addModulesToManifestFileDataList(filesDataStructure, fileDataList); - addNestedToManifest(filesDataStructure, fileDataList); - addArtifactsToManifestFileDataList(filesDataStructure, fileDataList); - - ManifestContent manifestContent = createManifest(vspDetails, fileDataList); - return Optional.of(manifestContent); - } - - @Override - public Optional createManifestFromExisting(VspDetails vspDetails, FilesDataStructure filesDataStructure, ManifestContent existingManifest) { - if (Objects.isNull(filesDataStructure)) { - return Optional.empty(); + @Override + public Optional createManifestFromExisting(VspDetails vspDetails, FilesDataStructure filesDataStructure, + ManifestContent existingManifest) { + if (Objects.isNull(filesDataStructure)) { + return Optional.empty(); + } + List fileDataList = new ArrayList<>(); + addModulesToManifestFileDataList(filesDataStructure, fileDataList); + addNestedToManifest(filesDataStructure, fileDataList); + addArtifactsToManifestFileDataList(filesDataStructure, fileDataList, existingManifest); + ManifestContent manifestContent = createManifest(vspDetails, fileDataList); + return Optional.of(manifestContent); } - List fileDataList = new ArrayList<>(); - addModulesToManifestFileDataList(filesDataStructure, fileDataList); - addNestedToManifest(filesDataStructure, fileDataList); - addArtifactsToManifestFileDataList(filesDataStructure, fileDataList, existingManifest); - - ManifestContent manifestContent = createManifest(vspDetails, fileDataList); - return Optional.of(manifestContent); - } - - private void addArtifactsToManifestFileDataList(FilesDataStructure filesDataStructure, List fileDataList, ManifestContent existingManifest) { - Collection forArtifacts = CollectionUtils - .union(filesDataStructure.getArtifacts(), filesDataStructure.getUnassigned()); - if (CollectionUtils.isNotEmpty(forArtifacts)) { - for (String artifact : forArtifacts) { - if (isCloudSpecificArtifact(artifact)) { - fileDataList.add(createBaseFileData(FileData.Type.CLOUD_TECHNOLOGY_SPECIFIC_ARTIFACT, artifact)); - } else if (isControllerBlueprintArchive(artifact)) { - fileDataList.add(createBaseFileData(FileData.Type.CONTROLLER_BLUEPRINT_ARCHIVE, artifact)); - } else if (isHelm(artifact)) { - fileDataList.add(createBaseFileData(FileData.Type.HELM, artifact)); - } else if (isPmDictionary(artifact, existingManifest)) { - fileDataList.add(createBaseFileData(FileData.Type.PM_DICTIONARY, artifact)); + private void addArtifactsToManifestFileDataList(FilesDataStructure filesDataStructure, List fileDataList, + ManifestContent existingManifest) { + Collection forArtifacts = CollectionUtils.union(filesDataStructure.getArtifacts(), filesDataStructure.getUnassigned()); + if (CollectionUtils.isNotEmpty(forArtifacts)) { + for (String artifact : forArtifacts) { + if (isCloudSpecificArtifact(artifact)) { + fileDataList.add(createBaseFileData(FileData.Type.CLOUD_TECHNOLOGY_SPECIFIC_ARTIFACT, artifact)); + } else if (isControllerBlueprintArchive(artifact)) { + fileDataList.add(createBaseFileData(FileData.Type.CONTROLLER_BLUEPRINT_ARCHIVE, artifact)); + } else if (isHelm(artifact)) { + fileDataList.add(createBaseFileData(FileData.Type.HELM, artifact)); + } else if (isPmDictionary(artifact, existingManifest)) { + fileDataList.add(createBaseFileData(FileData.Type.PM_DICTIONARY, artifact)); + } else { + fileDataList.add(createBaseFileData(FileData.Type.OTHER, artifact)); + } + } } - else { - fileDataList.add(createBaseFileData(FileData.Type.OTHER, artifact)); - } - } } - } - private boolean isPmDictionary(String artifact, ManifestContent existingManifest) { - return existingManifest.getData() - .stream() - .filter(fileData -> fileData.getType() - .equals(FileData.Type.PM_DICTIONARY)) - .map(FileData::getFile) + private boolean isPmDictionary(String artifact, ManifestContent existingManifest) { + return existingManifest.getData().stream().filter(fileData -> fileData.getType().equals(FileData.Type.PM_DICTIONARY)).map(FileData::getFile) .anyMatch(pmDictionaryFile -> pmDictionaryFile.equals(artifact)); - } - - private void addNestedToManifest( - FilesDataStructure filesDataStructure, List fileDataList) { - if (CollectionUtils.isNotEmpty(filesDataStructure.getNested())) { - for (String nested : filesDataStructure.getNested()) { - fileDataList.add(createBaseFileData(FileData.Type.HEAT, nested)); - } } - } - @Override - public Optional createManifest(VspDetails vspDetails, - FileContentHandler fileContentHandler, - AnalyzedZipHeatFiles analyzedZipHeatFiles) { - logger.info("Trying to generate manifest"); - if (Objects.isNull(fileContentHandler) - || CollectionUtils.isEmpty(fileContentHandler.getFileList())) { - logger.info("fileContentHandler or filesList is empty. ManifestContent will not be created"); - return Optional.empty(); + private void addNestedToManifest(FilesDataStructure filesDataStructure, List fileDataList) { + if (CollectionUtils.isNotEmpty(filesDataStructure.getNested())) { + for (String nested : filesDataStructure.getNested()) { + fileDataList.add(createBaseFileData(FileData.Type.HEAT, nested)); + } + } } - Map files = fileContentHandler.getFiles(); + @Override + public Optional createManifest(VspDetails vspDetails, FileContentHandler fileContentHandler, + AnalyzedZipHeatFiles analyzedZipHeatFiles) { + logger.info("Trying to generate manifest"); + if (Objects.isNull(fileContentHandler) || CollectionUtils.isEmpty(fileContentHandler.getFileList())) { + logger.info("fileContentHandler or filesList is empty. ManifestContent will not be created"); + return Optional.empty(); + } + Map files = fileContentHandler.getFiles(); + List fileDataList = createFileDataListFromZipFiles(fileContentHandler, files, analyzedZipHeatFiles.getFilesNotEligbleForModules()); + ManifestContent manifestContent = createManifest(vspDetails, fileDataList); + return Optional.of(manifestContent); + } - List fileDataList = - createFileDataListFromZipFiles(fileContentHandler, files, - analyzedZipHeatFiles.getFilesNotEligbleForModules()); - ManifestContent manifestContent = createManifest(vspDetails, fileDataList); + private ManifestContent createManifest(VspDetails vspDetails, List fileDataList) { + ManifestContent manifestContent = new ManifestContent(); + manifestContent.setName(vspDetails.getName()); + manifestContent.setDescription(vspDetails.getDescription()); + manifestContent.setVersion(vspDetails.getVersion() == null ? null : vspDetails.getVersion().toString()); + // vsp version, need to check in confluence + manifestContent.setData(fileDataList); + return manifestContent; + } - return Optional.of(manifestContent); - } + private List createFileDataListFromZipFiles(FileContentHandler fileContentHandler, Map files, + Collection filesNotEligibleForModules) { + Set processedFiles = new HashSet<>(); + List fileDataList = new ArrayList<>(); + for (String fileName : files.keySet()) { + if (processedFiles.contains(fileName)) { + continue; + } + if (isFileBaseFile(fileName)) { + fileDataList.add(createModuleFileData(fileName, true, processedFiles, fileContentHandler.getFileList(), fileDataList)); + } else if (isFileModuleFile(fileName, filesNotEligibleForModules)) { + fileDataList.add(createModuleFileData(fileName, false, processedFiles, fileContentHandler.getFileList(), fileDataList)); + } else { + if (HeatFileAnalyzer.isYamlFile(fileName)) { + fileDataList.add(createBasicFileData(fileName, FileData.Type.HEAT, null)); + } else if (HeatFileAnalyzer.isEnvFile(fileName)) { + fileDataList.add(createBasicFileData(fileName, FileData.Type.HEAT_ENV, null)); + } else { + fileDataList.add(createBasicFileData(fileName, FileData.Type.OTHER, null)); + } + } + } + return fileDataList; + } - private ManifestContent createManifest(VspDetails vspDetails, List fileDataList) { - ManifestContent manifestContent = new ManifestContent(); - manifestContent.setName(vspDetails.getName()); - manifestContent.setDescription(vspDetails.getDescription()); - manifestContent - .setVersion(vspDetails.getVersion() == null ? null : vspDetails.getVersion().toString()); - // vsp version, need to check in confluence - manifestContent.setData(fileDataList); - return manifestContent; - } + private boolean isFileModuleFile(String fileName, Collection filesCannotBeModule) { + return !filesCannotBeModule.contains(fileName); + } - private List createFileDataListFromZipFiles(FileContentHandler fileContentHandler, - Map files, - Collection filesNotEligibleForModules) { + @Override + public boolean isFileBaseFile(String fileName) { + return Pattern.matches(Constants.BASE_HEAT_REGEX, fileName) && !isVolFile(fileName); + } - Set processedFiles = new HashSet<>(); - List fileDataList = new ArrayList<>(); - for (String fileName : files.keySet()) { - if (processedFiles.contains(fileName)) { - continue; - } - if (isFileBaseFile(fileName)) { - fileDataList - .add(createModuleFileData( - fileName, true, processedFiles, fileContentHandler.getFileList(), fileDataList)); - } else if (isFileModuleFile(fileName, filesNotEligibleForModules)) { - fileDataList - .add(createModuleFileData( - fileName, false, processedFiles, fileContentHandler.getFileList(), fileDataList)); - } else { - if (HeatFileAnalyzer.isYamlFile(fileName)) { - fileDataList.add(createBasicFileData(fileName, FileData.Type.HEAT, null)); - } else if (HeatFileAnalyzer.isEnvFile(fileName)) { - fileDataList.add(createBasicFileData(fileName, FileData.Type.HEAT_ENV, null)); + protected boolean isCloudSpecificArtifact(String artifact) { + if (artifact.contains(CLOUD_SPECIFIC_FIXED_KEY_WORD)) { + for (int i = 0; i < CLOUD_SPECIFIC_KEY_WORDS.length; i++) { + if (Arrays.stream(CLOUD_SPECIFIC_KEY_WORDS[i]).noneMatch(str -> artifact.contains(str))) { + return false; + } + } + return true; } else { - fileDataList.add(createBasicFileData(fileName, FileData.Type.OTHER, null)); + return false; } - } } - return fileDataList; - } - - private boolean isFileModuleFile(String fileName, Collection filesCannotBeModule) { - return !filesCannotBeModule.contains(fileName); - } - @Override - public boolean isFileBaseFile(String fileName) { - return Pattern.matches(Constants.BASE_HEAT_REGEX, fileName) && !isVolFile(fileName); - } - - protected boolean isCloudSpecificArtifact(String artifact) { - if (artifact.contains(CLOUD_SPECIFIC_FIXED_KEY_WORD)) { - for (int i = 0; i < CLOUD_SPECIFIC_KEY_WORDS.length; i++) { - if (Arrays.stream(CLOUD_SPECIFIC_KEY_WORDS[i]).noneMatch(str -> artifact.contains(str))) { - return false; - } - } - return true; - } else { - return false; - } - } - - private boolean isControllerBlueprintArchive(String artifact) { - return artifact.toUpperCase().contains(CONTROLLER_BLUEPRINT_ARCHIVE_FIXED_KEY_WORD); - } + private boolean isControllerBlueprintArchive(String artifact) { + return artifact.toUpperCase().contains(CONTROLLER_BLUEPRINT_ARCHIVE_FIXED_KEY_WORD); + } - private boolean isHelm(String artifact) { - return artifact.toUpperCase().contains(HELM_KEY_WORD); - } + private boolean isHelm(String artifact) { + return artifact.toUpperCase().contains(HELM_KEY_WORD); + } - private void addArtifactsToManifestFileDataList( - FilesDataStructure filesDataStructure, List fileDataList) { - Collection forArtifacts = CollectionUtils - .union(filesDataStructure.getArtifacts(), filesDataStructure.getUnassigned()); - if (CollectionUtils.isNotEmpty(forArtifacts)) { - for (String artifact : forArtifacts) { - if (isCloudSpecificArtifact(artifact)) { - fileDataList.add(createBaseFileData(FileData.Type.CLOUD_TECHNOLOGY_SPECIFIC_ARTIFACT, artifact)); - } else if (isControllerBlueprintArchive(artifact)) { - fileDataList.add(createBaseFileData(FileData.Type.CONTROLLER_BLUEPRINT_ARCHIVE, artifact)); - } else if (isHelm(artifact)) { - fileDataList.add(createBaseFileData(FileData.Type.HELM, artifact)); - } else { - fileDataList.add(createBaseFileData(FileData.Type.OTHER, artifact)); + private void addArtifactsToManifestFileDataList(FilesDataStructure filesDataStructure, List fileDataList) { + Collection forArtifacts = CollectionUtils.union(filesDataStructure.getArtifacts(), filesDataStructure.getUnassigned()); + if (CollectionUtils.isNotEmpty(forArtifacts)) { + for (String artifact : forArtifacts) { + if (isCloudSpecificArtifact(artifact)) { + fileDataList.add(createBaseFileData(FileData.Type.CLOUD_TECHNOLOGY_SPECIFIC_ARTIFACT, artifact)); + } else if (isControllerBlueprintArchive(artifact)) { + fileDataList.add(createBaseFileData(FileData.Type.CONTROLLER_BLUEPRINT_ARCHIVE, artifact)); + } else if (isHelm(artifact)) { + fileDataList.add(createBaseFileData(FileData.Type.HELM, artifact)); + } else { + fileDataList.add(createBaseFileData(FileData.Type.OTHER, artifact)); + } + } } - } } - } - private void addModulesToManifestFileDataList( - FilesDataStructure filesDataStructure, List fileDataList) { - if (CollectionUtils.isNotEmpty(filesDataStructure.getModules())) { - for (Module module : filesDataStructure.getModules()) { - FileData.Type type = module.getType(); - if (type == null) { - type = FileData.Type.HEAT; + private void addModulesToManifestFileDataList(FilesDataStructure filesDataStructure, List fileDataList) { + if (CollectionUtils.isNotEmpty(filesDataStructure.getModules())) { + for (Module module : filesDataStructure.getModules()) { + FileData.Type type = module.getType(); + if (type == null) { + type = FileData.Type.HEAT; + } + FileData fileData = createBaseFileData(type, module.getYaml()); + fileData.setBase(module.getIsBase()); + addEnv(module, fileData); + addVolume(module, fileData); + fileDataList.add(fileData); + } } - FileData fileData = createBaseFileData(type, module.getYaml()); - fileData.setBase(module.getIsBase()); - addEnv(module, fileData); - addVolume(module, fileData); - fileDataList.add(fileData); - } } - } - private void addEnv(Module module, FileData fileData) { - if (Objects.nonNull(module.getEnv())) { - FileData env = createBaseFileData(FileData.Type.HEAT_ENV, module.getEnv()); - fileData.addFileData(env); + private void addEnv(Module module, FileData fileData) { + if (Objects.nonNull(module.getEnv())) { + FileData env = createBaseFileData(FileData.Type.HEAT_ENV, module.getEnv()); + fileData.addFileData(env); + } } - } - private void addVolume(Module module, FileData fileData) { - String volModule = module.getVol(); - if (Objects.nonNull(volModule)) { - FileData vol = createBaseFileData(FileData.Type.HEAT_VOL, volModule); - if (Objects.nonNull(module.getVolEnv())) { - vol.addFileData(createBaseFileData(FileData.Type.HEAT_ENV, module.getVolEnv())); - } - fileData.addFileData(vol); + private void addVolume(Module module, FileData fileData) { + String volModule = module.getVol(); + if (Objects.nonNull(volModule)) { + FileData vol = createBaseFileData(FileData.Type.HEAT_VOL, volModule); + if (Objects.nonNull(module.getVolEnv())) { + vol.addFileData(createBaseFileData(FileData.Type.HEAT_ENV, module.getVolEnv())); + } + fileData.addFileData(vol); + } } - } - - private FileData createBaseFileData(FileData.Type heat, String yaml) { - FileData fileData = new FileData(); - fileData.setType(heat); - fileData.setFile(yaml); - return fileData; - } - - private FileData createModuleFileData( - String moduleFileName, boolean isBase, Set processedFiles, - Set fileNames, List fileDataList) { - FileData moduleFileData = createBasicFileData(moduleFileName, FileData.Type.HEAT, isBase); - Optional volFile = fetchRelatedVolume(moduleFileName, fileNames); - volFile.ifPresent(vol -> { - markFileAsProcessed(vol, processedFiles); - removeFromFileDataListIfAlreadyProcessed(fileDataList, vol); - FileData volFileData = createBasicFileData(vol, FileData.Type.HEAT_VOL, null); - Optional envFile = fetchRelatedEnv(vol, fileNames); - envFile.ifPresent(env -> { - markFileAsProcessed(env, processedFiles); - removeFromFileDataListIfAlreadyProcessed(fileDataList, env); - FileData envFileData = createBasicFileData(env, FileData.Type.HEAT_ENV, null); - volFileData.addFileData(envFileData); - }); - moduleFileData.addFileData(volFileData); - }); - Optional envFile = fetchRelatedEnv(moduleFileName, fileNames); - envFile.ifPresent(env -> { - markFileAsProcessed(env, processedFiles); - FileData envFileData = createBasicFileData(env, FileData.Type.HEAT_ENV, null); - moduleFileData.addFileData(envFileData); - }); - return moduleFileData; - } - private void removeFromFileDataListIfAlreadyProcessed(List fileDataList, String vol) { - fileDataList.removeIf(fileData -> fileData.getFile().equals(vol)); - } - - private FileData createBasicFileData(String fileName, FileData.Type type, Boolean isBase) { - FileData fileData = new FileData(); - if (isBase != null) { - fileData.setBase(isBase); + private FileData createBaseFileData(FileData.Type heat, String yaml) { + FileData fileData = new FileData(); + fileData.setType(heat); + fileData.setFile(yaml); + return fileData; } - fileData.setType(type); - fileData.setFile(fileName); - return fileData; - } - - private Optional fetchRelatedEnv(String fileName, Set fileNames) { - String envFileName - = fileName.substring(0, fileName.lastIndexOf(".")) + Constants.ENV_FILE_EXTENSION; - return fileNames.contains(envFileName) ? Optional.of(envFileName) : Optional.empty(); - } - private Optional fetchRelatedVolume(String fileName, Set fileNames) { - - String volFile1stExt = - extractVolFileName(fileName, ".yaml"); - String volFile2ndExt = - extractVolFileName(fileName, ".yml"); + private FileData createModuleFileData(String moduleFileName, boolean isBase, Set processedFiles, Set fileNames, + List fileDataList) { + FileData moduleFileData = createBasicFileData(moduleFileName, FileData.Type.HEAT, isBase); + Optional volFile = fetchRelatedVolume(moduleFileName, fileNames); + volFile.ifPresent(vol -> { + markFileAsProcessed(vol, processedFiles); + removeFromFileDataListIfAlreadyProcessed(fileDataList, vol); + FileData volFileData = createBasicFileData(vol, FileData.Type.HEAT_VOL, null); + Optional envFile = fetchRelatedEnv(vol, fileNames); + envFile.ifPresent(env -> { + markFileAsProcessed(env, processedFiles); + removeFromFileDataListIfAlreadyProcessed(fileDataList, env); + FileData envFileData = createBasicFileData(env, FileData.Type.HEAT_ENV, null); + volFileData.addFileData(envFileData); + }); + moduleFileData.addFileData(volFileData); + }); + Optional envFile = fetchRelatedEnv(moduleFileName, fileNames); + envFile.ifPresent(env -> { + markFileAsProcessed(env, processedFiles); + FileData envFileData = createBasicFileData(env, FileData.Type.HEAT_ENV, null); + moduleFileData.addFileData(envFileData); + }); + return moduleFileData; + } - if (fileNames.contains(volFile1stExt)) { - return Optional.of(volFile1stExt); + private void removeFromFileDataListIfAlreadyProcessed(List fileDataList, String vol) { + fileDataList.removeIf(fileData -> fileData.getFile().equals(vol)); } - if (fileNames.contains(volFile2ndExt)) { - return Optional.of(volFile2ndExt); + + private FileData createBasicFileData(String fileName, FileData.Type type, Boolean isBase) { + FileData fileData = new FileData(); + if (isBase != null) { + fileData.setBase(isBase); + } + fileData.setType(type); + fileData.setFile(fileName); + return fileData; } - return Optional.empty(); - } - private String extractVolFileName(String fileName, String fileExt) { - return fileName.substring( - 0, fileName.lastIndexOf(".")) - + Constants.VOL_FILE_NAME_SUFFIX + fileExt; - } + private Optional fetchRelatedEnv(String fileName, Set fileNames) { + String envFileName = fileName.substring(0, fileName.lastIndexOf(".")) + Constants.ENV_FILE_EXTENSION; + return fileNames.contains(envFileName) ? Optional.of(envFileName) : Optional.empty(); + } + private Optional fetchRelatedVolume(String fileName, Set fileNames) { + String volFile1stExt = extractVolFileName(fileName, ".yaml"); + String volFile2ndExt = extractVolFileName(fileName, ".yml"); + if (fileNames.contains(volFile1stExt)) { + return Optional.of(volFile1stExt); + } + if (fileNames.contains(volFile2ndExt)) { + return Optional.of(volFile2ndExt); + } + return Optional.empty(); + } - private boolean isVolFile(String fileName) { - return fileName - .endsWith( - Constants.VOL_FILE_NAME_SUFFIX + ".yaml") - || fileName.endsWith(Constants.VOL_FILE_NAME_SUFFIX + ".yml"); - } + private String extractVolFileName(String fileName, String fileExt) { + return fileName.substring(0, fileName.lastIndexOf(".")) + Constants.VOL_FILE_NAME_SUFFIX + fileExt; + } + private boolean isVolFile(String fileName) { + return fileName.endsWith(Constants.VOL_FILE_NAME_SUFFIX + ".yaml") || fileName.endsWith(Constants.VOL_FILE_NAME_SUFFIX + ".yml"); + } - private void markFileAsProcessed(String fileName, Set processedFiles) { - processedFiles.add(fileName); - } + private void markFileAsProcessed(String fileName, Set processedFiles) { + processedFiles.add(fileName); + } } 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/utils/CandidateServiceValidator.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/utils/CandidateServiceValidator.java index c366b7f4b9..a3d2e65889 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/utils/CandidateServiceValidator.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/utils/CandidateServiceValidator.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,9 +17,13 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.services.utils; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.Optional; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.StringUtils; import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder; @@ -29,48 +33,41 @@ import org.openecomp.sdc.datatypes.error.ErrorMessage; import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.FilesDataStructure; import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.Module; -import java.util.*; - /** * Created by Talio on 12/6/2016. */ public class CandidateServiceValidator { - public Optional> validateFileDataStructure( - FilesDataStructure filesDataStructure) { - if (Objects.isNull(filesDataStructure)) { - return Optional.empty(); - } - if (validateAtLeaseOneModuleExist(filesDataStructure)) { - return Optional.of(Arrays.asList(new ErrorMessage(ErrorLevel.ERROR, Messages - .NO_MODULES_IN_MANIFEST.getErrorMessage()))); - } - List errors = new ArrayList<>(); - for (Module module : filesDataStructure.getModules()) { - validateModuleHaveYaml(errors, module); - validateNoVolEnvWithoutVol(errors, module); + public Optional> validateFileDataStructure(FilesDataStructure filesDataStructure) { + if (Objects.isNull(filesDataStructure)) { + return Optional.empty(); + } + if (validateAtLeaseOneModuleExist(filesDataStructure)) { + return Optional.of(Arrays.asList(new ErrorMessage(ErrorLevel.ERROR, Messages.NO_MODULES_IN_MANIFEST.getErrorMessage()))); + } + List errors = new ArrayList<>(); + for (Module module : filesDataStructure.getModules()) { + validateModuleHaveYaml(errors, module); + validateNoVolEnvWithoutVol(errors, module); + } + return Optional.of(errors); } - return Optional.of(errors); - } - - private boolean validateAtLeaseOneModuleExist(FilesDataStructure filesDataStructure) { - return CollectionUtils.isEmpty(filesDataStructure.getModules()); - } + private boolean validateAtLeaseOneModuleExist(FilesDataStructure filesDataStructure) { + return CollectionUtils.isEmpty(filesDataStructure.getModules()); + } - private void validateNoVolEnvWithoutVol(List errors, Module module) { - if (StringUtils.isEmpty(module.getVol()) && StringUtils.isNotEmpty(module.getVolEnv())) { - errors.add(new ErrorMessage(ErrorLevel.ERROR, ErrorMessagesFormatBuilder - .getErrorWithParameters(Messages.MODULE_IN_MANIFEST_VOL_ENV_NO_VOL.getErrorMessage(), - module.getName()))); + private void validateNoVolEnvWithoutVol(List errors, Module module) { + if (StringUtils.isEmpty(module.getVol()) && StringUtils.isNotEmpty(module.getVolEnv())) { + errors.add(new ErrorMessage(ErrorLevel.ERROR, + ErrorMessagesFormatBuilder.getErrorWithParameters(Messages.MODULE_IN_MANIFEST_VOL_ENV_NO_VOL.getErrorMessage(), module.getName()))); + } } - } - private void validateModuleHaveYaml(List errors, Module module) { - if (StringUtils.isEmpty(module.getYaml())) { - errors.add(new ErrorMessage(ErrorLevel.ERROR, ErrorMessagesFormatBuilder - .getErrorWithParameters(Messages.MODULE_IN_MANIFEST_NO_YAML.getErrorMessage(), - module.getName()))); + private void validateModuleHaveYaml(List errors, Module module) { + if (StringUtils.isEmpty(module.getYaml())) { + errors.add(new ErrorMessage(ErrorLevel.ERROR, + ErrorMessagesFormatBuilder.getErrorWithParameters(Messages.MODULE_IN_MANIFEST_NO_YAML.getErrorMessage(), module.getName()))); + } } - } } -- cgit 1.2.3-korg