From 280f8015d06af1f41a3ef12e8300801c7a5e0d54 Mon Sep 17 00:00:00 2001 From: AviZi Date: Fri, 9 Jun 2017 02:39:56 +0300 Subject: [SDC-29] Amdocs OnBoard 1707 initial commit. Change-Id: Ie4d12a3f574008b792899b368a0902a8b46b5370 Signed-off-by: AviZi --- .../pom.xml | 114 +++- .../pom.xml.versionsBackup | 108 ++++ ...VendorSoftwareProductCreationFailedBuilder.java | 28 + .../VendorSoftwareProductNotFoundErrorBuilder.java | 47 ++ .../impl/ComponentArtifactDaoCassandraImpl.java | 159 ------ .../dao/impl/ComponentArtifactDaoFactoryImpl.java | 33 -- .../dao/impl/ComponentDaoCassandraImpl.java | 48 +- .../dao/impl/ComponentDaoFactoryImpl.java | 5 +- .../ComponentDependencyModelDaoCassandraImpl.java | 87 +++ .../ComponentDependencyModelDaoFactoryImpl.java | 18 + .../dao/impl/MibDaoFactoryImpl.java | 36 ++ .../dao/impl/NetworkDaoCassandraImpl.java | 26 +- .../dao/impl/NetworkDaoFactoryImpl.java | 5 +- .../dao/impl/NicDaoCassandraImpl.java | 36 +- .../dao/impl/NicDaoFactoryImpl.java | 5 +- ...chestrationTemplateCandidateDaoFactoryImpl.java | 38 ++ .../impl/OrchestrationTemplateDaoFactoryImpl.java | 39 ++ .../dao/impl/PackageInfoDaoImpl.java | 23 +- .../dao/impl/ProcessArtifactDaoCassandraImpl.java | 82 --- .../dao/impl/ProcessArtifactDaoFactoryImpl.java | 33 -- .../dao/impl/ProcessDaoCassandraImpl.java | 139 ----- .../dao/impl/ProcessDaoFactoryImpl.java | 7 +- .../dao/impl/UploadDataDaoFactoryImpl.java | 33 -- .../dao/impl/UploadDataDaoImpl.java | 92 --- .../impl/VendorSoftwareProductDaoFactoryImpl.java | 2 + .../dao/impl/VendorSoftwareProductDaoImpl.java | 282 +++------- .../VendorSoftwareProductInfoDaoFactoryImpl.java | 5 +- .../dao/impl/VendorSoftwareProductInfoDaoImpl.java | 33 +- .../dao/impl/VspQuestionnaireDaoCassandraImpl.java | 72 --- .../dao/impl/VspQuestionnaireDaoFactoryImpl.java | 33 -- .../impl/zusammen/ComponentDaoZusammenImpl.java | 244 ++++++++ .../ComponentDependencyModelDaoZusammenImpl.java | 201 +++++++ .../dao/impl/zusammen/ElementPropertyName.java | 6 + .../dao/impl/zusammen/ElementType.java | 9 + .../dao/impl/zusammen/MibDaoZusammenImpl.java | 171 ++++++ .../dao/impl/zusammen/NetworkDaoZusammenImpl.java | 150 +++++ .../dao/impl/zusammen/NicDaoZusammenImpl.java | 257 +++++++++ ...hestrationTemplateCandidateDaoZusammenImpl.java | 134 +++++ .../OrchestrationTemplateDaoZusammenImpl.java | 111 ++++ .../dao/impl/zusammen/ProcessDaoZusammenImpl.java | 229 ++++++++ .../dao/impl/zusammen/StructureElement.java | 20 + .../VendorSoftwareProductInfoDaoZusammenImpl.java | 228 ++++++++ .../dao/impl/zusammen/VspZusammenUtil.java | 61 ++ .../errors/VendorSoftwareProductErrorCodes.java | 62 ++ .../InformationArtifactGeneratorFactoryImpl.java | 34 ++ .../QuestionnaireDataServiceFactoryImpl.java | 35 ++ .../factory/impl/CandidateServiceFactoryImpl.java | 37 ++ .../impl/CompositionDataExtractorFactoryImpl.java | 33 ++ .../CompositionEntityDataManagerFactoryImpl.java | 41 ++ .../factory/impl/ManifestCreatorFactoryImpl.java | 36 ++ .../impl/TxtInformationArtifactConstants.java | 105 ++++ .../impl/TxtInformationArtifactGeneratorImpl.java | 304 ++++++++++ .../QuestionnaireDataServiceImpl.java | 113 ++++ .../composition/CompositionDataExtractorImpl.java | 470 ++++++++++++++++ .../CompositionEntityDataManagerImpl.java | 585 +++++++++++++++++++ .../CandidateServiceImpl.java | 621 +++++++++++++++++++++ .../ManifestCreatorNamingConventionImpl.java | 309 ++++++++++ .../services/utils/CandidateServiceValidator.java | 97 ++++ .../dao/ServiceModelDaoFactoryTest.java | 226 +++++++- .../TxtInformationArtifactGeneratorImplTest.java | 252 +++++++++ .../src/test/resources/logback.xml | 13 + 61 files changed, 5886 insertions(+), 976 deletions(-) create mode 100644 openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/pom.xml.versionsBackup create mode 100644 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 create mode 100644 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 delete mode 100644 openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/ComponentArtifactDaoCassandraImpl.java delete mode 100644 openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/ComponentArtifactDaoFactoryImpl.java create mode 100644 openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/ComponentDependencyModelDaoCassandraImpl.java create mode 100644 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 create mode 100644 openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/MibDaoFactoryImpl.java create mode 100644 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 create mode 100644 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 delete mode 100644 openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/ProcessArtifactDaoCassandraImpl.java delete mode 100644 openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/ProcessArtifactDaoFactoryImpl.java delete mode 100644 openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/ProcessDaoCassandraImpl.java delete mode 100644 openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/UploadDataDaoFactoryImpl.java delete mode 100644 openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/UploadDataDaoImpl.java delete mode 100644 openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/VspQuestionnaireDaoCassandraImpl.java delete mode 100644 openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/VspQuestionnaireDaoFactoryImpl.java create mode 100644 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 create mode 100644 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 create mode 100644 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/ElementPropertyName.java create mode 100644 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/ElementType.java create mode 100644 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/MibDaoZusammenImpl.java create mode 100644 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 create mode 100644 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 create mode 100644 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 create mode 100644 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 create mode 100644 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 create mode 100644 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/StructureElement.java create mode 100644 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 create mode 100644 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 create mode 100644 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 create mode 100644 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 create mode 100644 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 create mode 100644 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 create mode 100644 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 create mode 100644 openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/factory/impl/CompositionEntityDataManagerFactoryImpl.java create mode 100644 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 create mode 100644 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 create mode 100644 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 create mode 100644 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 create mode 100644 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 create mode 100644 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/CompositionEntityDataManagerImpl.java create mode 100644 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 create mode 100644 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 create mode 100644 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 create mode 100644 openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/informationArtifact/impl/TxtInformationArtifactGeneratorImplTest.java create mode 100644 openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/resources/logback.xml (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/pom.xml b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/pom.xml index ce7f7be7fd..939e1b003a 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/pom.xml +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/pom.xml @@ -1,49 +1,32 @@ - 4.0.0 + openecomp-sdc-vendor-software-product-core + org.openecomp.sdc openecomp-sdc-vendor-software-product-lib 1.1.0-SNAPSHOT - openecomp-sdc-vendor-software-product-core - - - com.google.code.gson - gson - 2.3.1 - test - - - org.yaml - snakeyaml - 1.14 - test - - - org.openecomp.sdc - openecomp-sdc-enrichment-impl - ${project.version} - org.openecomp.sdc openecomp-sdc-vendor-software-product-api ${project.version} - org.openecomp.sdc + org.openecomp.core openecomp-nosqldb-api ${project.version} org.freemarker freemarker - 2.3.23 + ${freemarker.version} org.testng @@ -52,7 +35,7 @@ test - org.openecomp.sdc + org.openecomp.core openecomp-config-lib ${project.version} @@ -62,6 +45,87 @@ ${project.version} test + + org.apache.xmlgraphics + fop + ${fop.version} + + + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + ${jackson.dataformat.version} + + + commons-io + commons-io + ${commons.io.version} + + + org.mockito + mockito-all + ${mockito.all.version} + + + junit + junit + 4.12 + test + + + org.openecomp.sdc.common + openecomp-configuration-management-core + ${openecomp.sdc.common.version} + runtime + + + org.slf4j + slf4j-log4j12 + + + + + org.openecomp.sdc.common + openecomp-configuration-management-api + ${openecomp.sdc.common.version} + + + org.openecomp.core + openecomp-zusammen-api + ${project.version} + + + org.openecomp.core + openecomp-zusammen-core + ${project.version} + runtime + + + org.apache.commons + commons-lang3 + 3.4 + + + + + org.openecomp.sdc.common + openecomp-tosca-datatype + ${openecomp.sdc.common.version} + - \ No newline at end of file + + + + org.apache.maven.plugins + maven-surefire-plugin + ${mvn.surefire.version} + + true + false + true + + + + + + diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/pom.xml.versionsBackup b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/pom.xml.versionsBackup new file mode 100644 index 0000000000..634e0874ac --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/pom.xml.versionsBackup @@ -0,0 +1,108 @@ + + + 4.0.0 + + openecomp-sdc-vendor-software-product-core + 1.0-SNAPSHOT + + + org.openecomp.sdc + openecomp-sdc-vendor-software-product-lib + 1.0-SNAPSHOT + + + + + org.openecomp.sdc + openecomp-sdc-vendor-software-product-api + 1.0-SNAPSHOT + + + org.openecomp.core + openecomp-nosqldb-api + 1.0-SNAPSHOT + + + org.freemarker + freemarker + 2.3.23 + + + org.testng + testng + ${testng.version} + test + + + org.openecomp.core + openecomp-config-lib + 1.0-SNAPSHOT + + + org.openecomp.sdc + openecomp-sdc-model-impl + 1.0-SNAPSHOT + test + + + org.apache.xmlgraphics + fop + 2.1 + + + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + 2.7.4 + + + commons-io + commons-io + 2.5 + + + org.mockito + mockito-all + 1.10.19 + + + junit + junit + 4.12 + test + + + org.openecomp.sdc.common + openecomp-configuration-management-core + 1707.0.0-SNAPSHOT + runtime + + + org.slf4j + slf4j-log4j12 + + + + + org.openecomp.sdc.common + openecomp-configuration-management-api + 1707.0.0-SNAPSHOT + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.19.1 + + false + true + + + + + + \ No newline at end of file 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 new file mode 100644 index 0000000000..45989ddbf0 --- /dev/null +++ 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 @@ -0,0 +1,28 @@ +package org.openecomp.sdc.vendorsoftwareproduct.dao.errors; + +import org.openecomp.sdc.common.errors.ErrorCategory; +import org.openecomp.sdc.common.errors.ErrorCode; +import org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes; +import org.openecomp.sdc.versioning.dao.types.Version; + +import java.text.MessageFormat; + +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)); + } + + 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 new file mode 100644 index 0000000000..ef5b43fad4 --- /dev/null +++ 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 @@ -0,0 +1,47 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.dao.errors; + + +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)); + } + + 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/ComponentArtifactDaoCassandraImpl.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/ComponentArtifactDaoCassandraImpl.java deleted file mode 100644 index 2525537cef..0000000000 --- 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/ComponentArtifactDaoCassandraImpl.java +++ /dev/null @@ -1,159 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; - -import com.datastax.driver.core.ResultSet; -import com.datastax.driver.core.UDTValue; -import com.datastax.driver.mapping.Mapper; -import com.datastax.driver.mapping.Result; -import com.datastax.driver.mapping.UDTMapper; -import com.datastax.driver.mapping.annotations.Accessor; -import com.datastax.driver.mapping.annotations.Query; -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.ComponentArtifactDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentArtifactEntity; -import org.openecomp.sdc.versioning.VersioningManagerFactory; -import org.openecomp.sdc.versioning.dao.types.Version; -import org.openecomp.sdc.versioning.types.VersionableEntityMetadata; - - -import java.nio.ByteBuffer; -import java.util.Collection; - -public class ComponentArtifactDaoCassandraImpl extends CassandraBaseDao - implements ComponentArtifactDao { - - private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); - private static final ComponentArtifactAccessor accessor = - noSqlDb.getMappingManager().createAccessor(ComponentArtifactAccessor.class); - private static final Mapper mapper = - noSqlDb.getMappingManager().mapper(ComponentArtifactEntity.class); - private static final UDTMapper versionMapper = - noSqlDb.getMappingManager().udtMapper(Version.class); - - - @Override - public void registerVersioning(String versionableEntityType) { - VersionableEntityMetadata metadata = new VersionableEntityMetadata( - mapper.getTableMetadata().getName(), - mapper.getTableMetadata().getPartitionKey().get(0).getName(), - mapper.getTableMetadata().getPartitionKey().get(1).getName()); - - // metadata.setUniqueValuesMetadata(Collections.singletonList(new UniqueValueMetadata - // (VendorSoftwareProductConstants.UniqueValues.COMPONENT_ARTIFACT_NAME, - // Arrays.asList(mapper.getTableMetadata().getPartitionKey().get(0).getName(), mapper - // .getTableMetadata().getPartitionKey().get(1).getName(), "name")))); - - VersioningManagerFactory.getInstance().createInterface() - .register(versionableEntityType, metadata); - } - - @Override - public ComponentArtifactEntity getArtifactByType(ComponentArtifactEntity entity) { - return accessor.listByType(entity.getVspId(), versionMapper.toUDT(entity.getVersion()), - entity.getComponentId(), entity.getType().toString()).one(); - } - - @Override - protected Mapper getMapper() { - return mapper; - } - - @Override - protected Object[] getKeys(ComponentArtifactEntity entity) { - return new Object[]{entity.getVspId(), versionMapper.toUDT(entity.getVersion()), - entity.getComponentId(), entity.getType().toString(), entity.getId()}; - } - - @Override - public Collection list(ComponentArtifactEntity entity) { - return accessor.listByType(entity.getVspId(), versionMapper.toUDT(entity.getVersion()), - entity.getComponentId(), entity.getType().toString()).all(); - } - - @Override - public void update(ComponentArtifactEntity entity) { - accessor.update(entity.getVspId(), versionMapper.toUDT(entity.getVersion()), - entity.getComponentId(), entity.getId(), entity.getArtifactName(), entity.getArtifact(), - entity.getType().toString()); - - } - - @Override - public void delete(ComponentArtifactEntity entity) { - accessor.delete(entity.getVspId(), versionMapper.toUDT(entity.getVersion()), - entity.getComponentId(), entity.getType().toString()); - } - - @Override - public Collection getArtifactNamesAndTypesForComponent( - ComponentArtifactEntity entity) { - return accessor.getArtifactNamesAndTypesForComponent(entity.getVspId(), - versionMapper.toUDT(entity.getVersion()), entity.getComponentId()).all(); - } - - @Override - public void deleteAll(ComponentArtifactEntity entity) { - accessor.deleteAll(entity.getVspId(), versionMapper.toUDT(entity.getVersion())); - } - - - @Accessor - interface ComponentArtifactAccessor { - - @Query( - "insert into vsp_component_artifact (vsp_id, version, component_id, artifact_id, name, " - + "artifact, artifact_type) values (?,?,?,?,?,?,?)") - ResultSet update(String vspId, UDTValue version, String componentId, String id, - String artifactName, ByteBuffer artifact, String type); - - @Query( - "select vsp_id, version, component_id, artifact_type, artifact_id, name, artifact from " - + "vsp_component_artifact where vsp_id=? and version=? and component_id=? and " - + "artifact_type =?") - Result listByType(String vspId, UDTValue version, String componentId, - String type); - - @Query( - "delete name, artifact from vsp_component_artifact where vsp_id=? and version=? and " - + "component_id=? and artifact_type=? and artifact_id=?") - ResultSet delete(String vspId, UDTValue version, String componentId, String type, - String artifactId); - - @Query( - "delete from vsp_component_artifact where vsp_id=? and version=? and component_id=? " - + "and artifact_type=?") - ResultSet delete(String vspId, UDTValue version, String componentId, String artifactType); - - @Query("delete from vsp_component_artifact where vsp_id=? and version=?") - ResultSet deleteAll(String vspId, UDTValue version); - - @Query( - "select name, artifact_type from vsp_component_artifact where vsp_id=? and version=? " - + "and component_id=?") - Result getArtifactNamesAndTypesForComponent(String vspId, - UDTValue version, - String componentId); - - } -} 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/ComponentArtifactDaoFactoryImpl.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/ComponentArtifactDaoFactoryImpl.java deleted file mode 100644 index 07a9f104f4..0000000000 --- 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/ComponentArtifactDaoFactoryImpl.java +++ /dev/null @@ -1,33 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; - -import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentArtifactDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentArtifactDaoFactory; - -public class ComponentArtifactDaoFactoryImpl extends ComponentArtifactDaoFactory { - private static final ComponentArtifactDao INSTANCE = new ComponentArtifactDaoCassandraImpl(); - - @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/ComponentDaoCassandraImpl.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/ComponentDaoCassandraImpl.java index 85372380c0..9cdd950a72 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/ComponentDaoCassandraImpl.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/ComponentDaoCassandraImpl.java @@ -61,10 +61,10 @@ public class ComponentDaoCassandraImpl extends CassandraBaseDao mapper.getTableMetadata().getPartitionKey().get(1).getName()); - metadata.setUniqueValuesMetadata(Collections.singletonList( - new UniqueValueMetadata(VendorSoftwareProductConstants.UniqueValues.COMPONENT_NAME, - Arrays.asList(mapper.getTableMetadata().getPartitionKey().get(0).getName(), - mapper.getTableMetadata().getPartitionKey().get(1).getName(), "name")))); + metadata.setUniqueValuesMetadata(Collections.singletonList(new UniqueValueMetadata( + VendorSoftwareProductConstants.UniqueValues.COMPONENT_NAME, + Arrays.asList(mapper.getTableMetadata().getPartitionKey().get(0).getName(), + mapper.getTableMetadata().getPartitionKey().get(1).getName(), "name")))); VersioningManagerFactory.getInstance().createInterface() .register(versionableEntityType, metadata); @@ -93,9 +93,14 @@ public class ComponentDaoCassandraImpl extends CassandraBaseDao } @Override - public void updateQuestionnaireData(String vspId, Version version, String id, + public ComponentEntity getQuestionnaireData(String vspId, Version version, String componentId) { + return accessor.getQuestionnaireData(vspId, versionMapper.toUDT(version), componentId); + } + + @Override + public void updateQuestionnaireData(String vspId, Version version, String componentId, String questionnaireData) { - accessor.updateQuestionnaireData(questionnaireData, vspId, versionMapper.toUDT(version), id); + accessor.updateQuestionnaireData(questionnaireData, vspId, versionMapper.toUDT(version), componentId); } @Override @@ -103,6 +108,11 @@ public class ComponentDaoCassandraImpl extends CassandraBaseDao return accessor.listQuestionnaires(vspId, versionMapper.toUDT(version)).all(); } + @Override + public Collection listCompositionAndQuestionnaire(String vspId, Version version){ + return accessor.listCompositionAndQuestionnaire(vspId, versionMapper.toUDT(version)).all(); + } + @Override public void deleteAll(String vspId, Version version) { accessor.deleteAll(vspId, version); @@ -112,24 +122,34 @@ public class ComponentDaoCassandraImpl extends CassandraBaseDao interface ComponentAccessor { @Query( - "select vsp_id, version, component_id, composition_data from vsp_component " - + "where vsp_id=? and version=?") + "select vsp_id, version, component_id, composition_data from vsp_component" + + " where vsp_id=? and version=?") Result list(String vspId, UDTValue version); @Query( - "select vsp_id, version, component_id, questionnaire_data from vsp_component " - + "where vsp_id=? and version=?") + "select vsp_id, version, component_id, composition_data, questionnaire_data from vsp_component" + + " where vsp_id=? and version=?") + Result listCompositionAndQuestionnaire(String vspId, UDTValue version); + + @Query( + "select vsp_id, version, component_id, questionnaire_data from vsp_component" + + " where vsp_id=? and version=?") Result listQuestionnaires(String vspId, UDTValue version); @Query( - "insert into vsp_component (vsp_id, version, component_id, composition_data) " - + "values (?,?,?,?)") + "select vsp_id, version, component_id, questionnaire_data from vsp_component" + + " where vsp_id=? and version=? and component_id=?") + ComponentEntity getQuestionnaireData(String vspId, UDTValue version, String id); + + @Query( + "insert into vsp_component (vsp_id, version, component_id, composition_data)" + + " values (?,?,?,?)") ResultSet updateCompositionData(String vspId, UDTValue version, String id, String compositionData); @Query( - "update vsp_component set questionnaire_data=? where vsp_id=? and version=? " - + "and component_id=?") + "update vsp_component set questionnaire_data=? where vsp_id=? and version=?" + + " and component_id=?") ResultSet updateQuestionnaireData(String questionnaireData, String vspId, UDTValue version, String 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/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 1e57242ce1..1ef0caac0c 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 @@ -20,11 +20,14 @@ package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; +import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao; 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 ComponentDaoCassandraImpl(); + private static final ComponentDao INSTANCE = new ComponentDaoZusammenImpl( + ZusammenAdaptorFactory.getInstance().createInterface()); @Override public ComponentDao 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/ComponentDependencyModelDaoCassandraImpl.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/ComponentDependencyModelDaoCassandraImpl.java new file mode 100644 index 0000000000..b46486eb32 --- /dev/null +++ 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/ComponentDependencyModelDaoCassandraImpl.java @@ -0,0 +1,87 @@ +package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; + +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.UDTValue; +import com.datastax.driver.mapping.Mapper; +import com.datastax.driver.mapping.Result; +import com.datastax.driver.mapping.UDTMapper; +import com.datastax.driver.mapping.annotations.Accessor; +import com.datastax.driver.mapping.annotations.Query; +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.VendorSoftwareProductConstants; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDependencyModelDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentDependencyModelEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity; +import org.openecomp.sdc.versioning.VersioningManagerFactory; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.sdc.versioning.types.UniqueValueMetadata; +import org.openecomp.sdc.versioning.types.VersionableEntityMetadata; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; + +public class ComponentDependencyModelDaoCassandraImpl extends CassandraBaseDao + implements ComponentDependencyModelDao { + + private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); + private static final Mapper mapper = + noSqlDb.getMappingManager().mapper(ComponentDependencyModelEntity.class); + private static final ComponentDependencyModelDaoCassandraImpl.ComponentDependencyModelAccessor + accessor = noSqlDb.getMappingManager().createAccessor( + ComponentDependencyModelDaoCassandraImpl.ComponentDependencyModelAccessor.class); + private static final UDTMapper versionMapper = + noSqlDb.getMappingManager().udtMapper(Version.class); + + @Override + protected Mapper getMapper() { + return mapper; + } + + @Override + protected Object[] getKeys(ComponentDependencyModelEntity entity) { + return new Object[]{entity.getVspId(), versionMapper.toUDT(entity.getVersion()), + entity.getId()}; + } + + @Override + public Collection list(ComponentDependencyModelEntity entity) { + return accessor + .list(entity.getVspId(), versionMapper.toUDT(entity.getVersion())).all(); + } + + @Override + public void deleteAll(String vspId, Version version) { + accessor.deleteAll(vspId, versionMapper.toUDT(version)); + } + + + @Override + public void registerVersioning(String versionableEntityType) { + VersionableEntityMetadata metadata = new VersionableEntityMetadata( + mapper.getTableMetadata().getName(), + mapper.getTableMetadata().getPartitionKey().get(0).getName(), + mapper.getTableMetadata().getPartitionKey().get(1).getName()); + + metadata.setUniqueValuesMetadata(Collections.singletonList(new UniqueValueMetadata( + VendorSoftwareProductConstants.UniqueValues.PROCESS_NAME, + Arrays.asList("vsp_id", "version", "component_id", "name")))); + + VersioningManagerFactory.getInstance().createInterface() + .register(versionableEntityType, metadata); + + } + + @Accessor + interface ComponentDependencyModelAccessor { + @Query("delete from vsp_component_dependency_model where vsp_id=? and version=?") + ResultSet deleteAll(String vspId, UDTValue version); + + @Query( + "select * from vsp_component_dependency_model where vsp_id=? and version=?") + Result list(String vspId, UDTValue version); + } +} 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 new file mode 100644 index 0000000000..e90e39bbc3 --- /dev/null +++ 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 @@ -0,0 +1,18 @@ +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; +import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.ComponentDependencyModelDaoZusammenImpl; + +public class ComponentDependencyModelDaoFactoryImpl extends ComponentDependencyModelDaoFactory { + + private static final ComponentDependencyModelDao INSTANCE = new + ComponentDependencyModelDaoZusammenImpl( ZusammenAdaptorFactory.getInstance().createInterface()); + + @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/MibDaoFactoryImpl.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/MibDaoFactoryImpl.java new file mode 100644 index 0000000000..923744bae7 --- /dev/null +++ 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/MibDaoFactoryImpl.java @@ -0,0 +1,36 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * 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.MibDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.MibDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.MibDaoZusammenImpl; + +public class MibDaoFactoryImpl extends MibDaoFactory { + private static final MibDao INSTANCE = new MibDaoZusammenImpl( + ZusammenAdaptorFactory.getInstance().createInterface()); + + @Override + public MibDao 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/NetworkDaoCassandraImpl.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/NetworkDaoCassandraImpl.java index f7b8f30f0a..83807af5f8 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/NetworkDaoCassandraImpl.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/NetworkDaoCassandraImpl.java @@ -60,10 +60,10 @@ public class NetworkDaoCassandraImpl extends CassandraBaseDao imp mapper.getTableMetadata().getPartitionKey().get(1).getName()); - metadata.setUniqueValuesMetadata(Collections.singletonList( - new UniqueValueMetadata(VendorSoftwareProductConstants.UniqueValues.NETWORK_NAME, - Arrays.asList(mapper.getTableMetadata().getPartitionKey().get(0).getName(), - mapper.getTableMetadata().getPartitionKey().get(1).getName(), "name")))); + metadata.setUniqueValuesMetadata(Collections.singletonList(new UniqueValueMetadata( + VendorSoftwareProductConstants.UniqueValues.NETWORK_NAME, + Arrays.asList(mapper.getTableMetadata().getPartitionKey().get(0).getName(), + mapper.getTableMetadata().getPartitionKey().get(1).getName(), "name")))); VersioningManagerFactory.getInstance().createInterface() .register(versionableEntityType, metadata); @@ -86,28 +86,30 @@ public class NetworkDaoCassandraImpl extends CassandraBaseDao imp entity.getId(), entity.getCompositionData()); } - @Override + /*@Override public void updateQuestionnaireData(String vspId, Version version, String id, String questionnaireData) { accessor.updateQuestionnaireData(questionnaireData, vspId, versionMapper.toUDT(version), id); - } + }*/ @Override - public Collection list(NetworkEntity entity) { - return accessor.list(entity.getVspId(), versionMapper.toUDT(entity.getVersion())).all(); + public void deleteAll(String vspId, Version version) { + accessor.deleteAll(vspId, version); } + + @Override - public void deleteAll(String vspId, Version version) { - accessor.deleteAll(vspId, version); + public Collection list(NetworkEntity entity) { + return accessor.list(entity.getVspId(), versionMapper.toUDT(entity.getVersion())).all(); } @Accessor interface NetworkAccessor { @Query( - "select vsp_id, version, network_id, composition_data from vsp_network where vsp_id=? " - + "and version=?") + "select vsp_id, version, network_id, composition_data from vsp_network where vsp_id=?" + + " and version=?") Result list(String vspId, UDTValue version); @Query( 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 b4360996df..5bccc5ced2 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 @@ -20,11 +20,14 @@ package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; +import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.NetworkDao; 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 NetworkDaoCassandraImpl(); + private static final NetworkDao INSTANCE = new NetworkDaoZusammenImpl( + ZusammenAdaptorFactory.getInstance().createInterface()); @Override public NetworkDao 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/NicDaoCassandraImpl.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/NicDaoCassandraImpl.java index e7e1eed8e0..a84ab38ccc 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/NicDaoCassandraImpl.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/NicDaoCassandraImpl.java @@ -60,9 +60,9 @@ public class NicDaoCassandraImpl extends CassandraBaseDao implements mapper.getTableMetadata().getPartitionKey().get(1).getName()); - metadata.setUniqueValuesMetadata(Collections - .singletonList(new UniqueValueMetadata(VendorSoftwareProductConstants.UniqueValues.NIC_NAME, - Arrays.asList("vsp_id", "version", "component_id", "name")))); + metadata.setUniqueValuesMetadata(Collections.singletonList(new UniqueValueMetadata( + VendorSoftwareProductConstants.UniqueValues.NIC_NAME, + Arrays.asList("vsp_id", "version", "component_id", "name")))); VersioningManagerFactory.getInstance().createInterface() .register(versionableEntityType, metadata); @@ -90,6 +90,12 @@ public class NicDaoCassandraImpl extends CassandraBaseDao implements entity.getComponentId(), entity.getId(), entity.getCompositionData()); } + @Override + public NicEntity getQuestionnaireData(String vspId, Version version, String componentId, + String nicId) { + return null; // TODO: 3/20/2017 + } + @Override public void updateQuestionnaireData(String vspId, Version version, String id, String componentId, String questionnaireData) { @@ -102,12 +108,6 @@ public class NicDaoCassandraImpl extends CassandraBaseDao implements return accessor.listByVspId(vspId, versionMapper.toUDT(version)).all(); } - @Override - public Collection list(NicEntity entity) { - return accessor.listByComponentId(entity.getVspId(), versionMapper.toUDT(entity.getVersion()), - entity.getComponentId()).all(); - } - public void deleteByComponentId(String vspId, Version version, String componentId) { accessor.deleteByComponentId(vspId, version, componentId); } @@ -116,26 +116,32 @@ public class NicDaoCassandraImpl extends CassandraBaseDao implements accessor.deleteByVspId(vspId, versionMapper.toUDT(version)); } + @Override + public Collection list(NicEntity entity) { + return accessor.listByComponentId(entity.getVspId(), versionMapper.toUDT(entity.getVersion()), + entity.getComponentId()).all(); + } + @Accessor interface NicAccessor { @Query( - "select vsp_id, version, component_id, nic_id, composition_data " - + "from vsp_component_nic where vsp_id=? and version=? and component_id=?") + "select vsp_id, version, component_id, nic_id, composition_data" + + " from vsp_component_nic where vsp_id=? and version=? and component_id=?") Result listByComponentId(String vspId, UDTValue version, String componentId); @Query("select * from vsp_component_nic where vsp_id=? and version=?") Result listByVspId(String vspId, UDTValue version); @Query( - "insert into vsp_component_nic (vsp_id, version, component_id, nic_id, composition_data) " - + "values (?,?,?,?,?)") + "insert into vsp_component_nic (vsp_id, version, component_id, nic_id, composition_data)" + + " values (?,?,?,?,?)") ResultSet updateCompositionData(String vspId, UDTValue version, String componentId, String id, String compositionData); @Query( - "update vsp_component_nic set questionnaire_data=? where vsp_id=? and version=? " - + "and component_id=? and nic_id=?") + "update vsp_component_nic set questionnaire_data=? where vsp_id=? and version=?" + + " and component_id=? and nic_id=?") ResultSet updateQuestionnaireData(String questionnaireData, String vspId, UDTValue version, String componentId, String 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/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 f4dd8d5a71..76e5d443f2 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 @@ -20,11 +20,14 @@ package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; +import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDao; 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 NicDaoCassandraImpl(); + private static final NicDao INSTANCE = new NicDaoZusammenImpl( + ZusammenAdaptorFactory.getInstance().createInterface()); @Override public NicDao 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/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 new file mode 100644 index 0000000000..8cc2c6f61f --- /dev/null +++ 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 @@ -0,0 +1,38 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * 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.OrchestrationTemplateCandidateDao; +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()); + + @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 new file mode 100644 index 0000000000..8b90462131 --- /dev/null +++ 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 @@ -0,0 +1,39 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * 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.OrchestrationTemplateDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.OrchestrationTemplateDaoZusammenImpl; + + +public class OrchestrationTemplateDaoFactoryImpl + extends OrchestrationTemplateDaoFactory { + private static final OrchestrationTemplateDao INSTANCE = + new OrchestrationTemplateDaoZusammenImpl( + ZusammenAdaptorFactory.getInstance().createInterface()); + + @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/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 9b7b81fe52..37917284e0 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 @@ -20,6 +20,7 @@ package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; +import com.datastax.driver.core.UDTValue; import com.datastax.driver.mapping.Mapper; import com.datastax.driver.mapping.Result; import com.datastax.driver.mapping.UDTMapper; @@ -28,10 +29,13 @@ import com.datastax.driver.mapping.annotations.Query; 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.common.utils.CommonUtil; +import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage; import org.openecomp.sdc.vendorsoftwareproduct.dao.PackageInfoDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.PackageInfo; import org.openecomp.sdc.versioning.dao.types.Version; +import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -46,6 +50,8 @@ public class PackageInfoDaoImpl extends CassandraBaseDao implements private static final UDTMapper versionMapper = noSqlDb.getMappingManager().udtMapper(Version.class); + private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); + @Override protected Mapper getMapper() { return mapper; @@ -63,6 +69,8 @@ public class PackageInfoDaoImpl extends CassandraBaseDao implements @Override public List listByCategory(String category, String subCategory) { + + mdcDataDebugMessage.debugEntryMessage(null, null); Result packages = accessor.listInfo(); List filteredPackages = new ArrayList<>(); @@ -79,7 +87,7 @@ public class PackageInfoDaoImpl extends CassandraBaseDao implements filteredPackages.add(packageInfo); } } - + mdcDataDebugMessage.debugExitMessage(null, null); return filteredPackages; } @@ -88,16 +96,25 @@ public class PackageInfoDaoImpl extends CassandraBaseDao implements accessor.deleteRowTranslateContent(vspId, version); } + @Override + public void updateTranslatedContent(String vspId, Version version, ByteBuffer translateContent){ + accessor.updateTranslateContent(translateContent, vspId, versionMapper.toUDT(version)); + } + @Accessor interface PackageInfoAccessor { @Query( - "SELECT vsp_id,version,display_name,vsp_name,vsp_description,vendor_name,category," - + "sub_category,vendor_release,package_checksum,package_type FROM package_details") + "SELECT vsp_id,version,display_name,vsp_name,vsp_description,vendor_name,category" + + " ,sub_category, vendor_release,package_checksum,package_type FROM package_details") Result listInfo(); @Query("DELETE TRANSLATE_CONTENT FROM package_details WHERE vsp_id=? and version=?") Result deleteRowTranslateContent(String vspId, Version version); + @Query("UPDATE package_details set translate_content = ? where vsp_id = ? and version = ?") + Result updateTranslateContent(ByteBuffer translateContent, String vspId, + UDTValue version); + } } 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/ProcessArtifactDaoCassandraImpl.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/ProcessArtifactDaoCassandraImpl.java deleted file mode 100644 index 0e9fd90a13..0000000000 --- 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/ProcessArtifactDaoCassandraImpl.java +++ /dev/null @@ -1,82 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; - -import com.datastax.driver.core.ResultSet; -import com.datastax.driver.core.UDTValue; -import com.datastax.driver.mapping.UDTMapper; -import com.datastax.driver.mapping.annotations.Accessor; -import com.datastax.driver.mapping.annotations.Query; -import org.openecomp.core.nosqldb.api.NoSqlDb; -import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; -import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessArtifactDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessArtifactEntity; -import org.openecomp.sdc.versioning.dao.types.Version; - -import java.nio.ByteBuffer; - -public class ProcessArtifactDaoCassandraImpl implements ProcessArtifactDao { - - private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); - private static final ProcessArtifactAccessor accessor = - noSqlDb.getMappingManager().createAccessor(ProcessArtifactAccessor.class); - private static final UDTMapper versionMapper = - noSqlDb.getMappingManager().udtMapper(Version.class); - - @Override - public void update(ProcessArtifactEntity entity) { - accessor.update(entity.getVspId(), versionMapper.toUDT(entity.getVersion()), - entity.getComponentId(), entity.getId(), entity.getArtifactName(), entity.getArtifact()); - } - - @Override - public ProcessArtifactEntity get(ProcessArtifactEntity entity) { - return accessor - .get(entity.getVspId(), versionMapper.toUDT(entity.getVersion()), entity.getComponentId(), - entity.getId()); - } - - @Override - public void delete(ProcessArtifactEntity entity) { - accessor.delete(entity.getVspId(), versionMapper.toUDT(entity.getVersion()), - entity.getComponentId(), entity.getId()); - } - - @Accessor - interface ProcessArtifactAccessor { - - @Query( - "insert into vsp_process (vsp_id, version, component_id, process_id, artifact_name," - + " artifact) values (?,?,?,?,?,?)") - ResultSet update(String vspId, UDTValue version, String componentId, String id, - String artifactName, ByteBuffer artifact); - - @Query( - "select vsp_id, version, component_id, process_id, artifact_name, artifact " - + "from vsp_process where vsp_id=? and version=? and component_id=? and process_id=?") - ProcessArtifactEntity get(String vspId, UDTValue version, String componentId, String id); - - @Query( - "delete artifact_name, artifact from vsp_process where vsp_id=? and version=? and" - + " component_id=? and process_id=?") - ResultSet delete(String vspId, UDTValue version, String componentId, String 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/ProcessArtifactDaoFactoryImpl.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/ProcessArtifactDaoFactoryImpl.java deleted file mode 100644 index 2a5d9013bd..0000000000 --- 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/ProcessArtifactDaoFactoryImpl.java +++ /dev/null @@ -1,33 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; - -import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessArtifactDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessArtifactDaoFactory; - -public class ProcessArtifactDaoFactoryImpl extends ProcessArtifactDaoFactory { - private static final ProcessArtifactDao INSTANCE = new ProcessArtifactDaoCassandraImpl(); - - @Override - public ProcessArtifactDao 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/ProcessDaoCassandraImpl.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/ProcessDaoCassandraImpl.java deleted file mode 100644 index b8900eb5d3..0000000000 --- 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/ProcessDaoCassandraImpl.java +++ /dev/null @@ -1,139 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; - -import com.datastax.driver.core.ResultSet; -import com.datastax.driver.core.UDTValue; -import com.datastax.driver.mapping.Mapper; -import com.datastax.driver.mapping.Result; -import com.datastax.driver.mapping.UDTMapper; -import com.datastax.driver.mapping.annotations.Accessor; -import com.datastax.driver.mapping.annotations.Query; -import org.openecomp.core.nosqldb.api.NoSqlDb; -import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; -import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants; -import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity; -import org.openecomp.sdc.versioning.VersioningManagerFactory; -import org.openecomp.sdc.versioning.dao.types.Version; -import org.openecomp.sdc.versioning.types.UniqueValueMetadata; -import org.openecomp.sdc.versioning.types.VersionableEntityMetadata; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; - -public class ProcessDaoCassandraImpl implements ProcessDao { - - private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); - private static final Mapper mapper = - noSqlDb.getMappingManager().mapper(ProcessEntity.class); - private static final ProcessAccessor accessor = - noSqlDb.getMappingManager().createAccessor(ProcessAccessor.class); - private static final UDTMapper versionMapper = - noSqlDb.getMappingManager().udtMapper(Version.class); - - @Override - public void registerVersioning(String versionableEntityType) { - VersionableEntityMetadata metadata = new VersionableEntityMetadata( - mapper.getTableMetadata().getName(), - mapper.getTableMetadata().getPartitionKey().get(0).getName(), - mapper.getTableMetadata().getPartitionKey().get(1).getName()); - - metadata.setUniqueValuesMetadata(Collections.singletonList( - new UniqueValueMetadata(VendorSoftwareProductConstants.UniqueValues.PROCESS_NAME, - Arrays.asList("vsp_id", "version", "component_id", "name")))); - - VersioningManagerFactory.getInstance().createInterface() - .register(versionableEntityType, metadata); - } - - @Override - public Collection list(ProcessEntity entity) { - return accessor - .list(entity.getVspId(), versionMapper.toUDT(entity.getVersion()), entity.getComponentId()) - .all(); - } - - @Override - public void create(ProcessEntity entity) { - accessor.update(entity.getVspId(), versionMapper.toUDT(entity.getVersion()), - entity.getComponentId(), entity.getId(), entity.getName(), entity.getDescription()); - } - - @Override - public void update(ProcessEntity entity) { - accessor.update(entity.getVspId(), versionMapper.toUDT(entity.getVersion()), - entity.getComponentId(), entity.getId(), entity.getName(), entity.getDescription()); - } - - @Override - public ProcessEntity get(ProcessEntity entity) { - return accessor - .get(entity.getVspId(), versionMapper.toUDT(entity.getVersion()), entity.getComponentId(), - entity.getId()); - } - - @Override - public void delete(ProcessEntity entity) { - if (entity.getId() == null) { - accessor.deleteAll(entity.getVspId(), versionMapper.toUDT(entity.getVersion()), - entity.getComponentId()); - } else { - accessor.delete(entity.getVspId(), versionMapper.toUDT(entity.getVersion()), - entity.getComponentId(), entity.getId()); - } - } - - public void deleteAll(ProcessEntity entity) { - accessor.deleteAll(entity.getVspId(), versionMapper.toUDT(entity.getVersion())); - } - - @Accessor - interface ProcessAccessor { - - @Query( - "insert into vsp_process (vsp_id, version, component_id, process_id, name, description) " - + "values (?,?,?,?,?,?)") - ResultSet update(String vspId, UDTValue version, String componentId, String id, String name, - String description); - - @Query( - "select vsp_id, version, component_id, process_id, name, description, artifact_name " - + "from vsp_process where vsp_id=? and version=? and component_id=? and process_id=?") - ProcessEntity get(String vspId, UDTValue version, String componentId, String id); - - @Query( - "select vsp_id, version, component_id, process_id, name, description, artifact_name " - + "from vsp_process where vsp_id=? and version=? and component_id=?") - Result list(String vspId, UDTValue version, String componentId); - - @Query( - "delete from vsp_process where vsp_id=? and version=? and component_id=? and process_id=?") - ResultSet delete(String vspId, UDTValue version, String componentId, String id); - - @Query("delete from vsp_process where vsp_id=? and version=? and component_id=?") - ResultSet deleteAll(String vspId, UDTValue version, String componentId); - - @Query("delete from vsp_process where vsp_id=? and version=?") - ResultSet deleteAll(String vspId, UDTValue version); - } -} 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 4c981d8448..ada76e790a 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 @@ -20,11 +20,14 @@ package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; -import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessDao; +import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.ProcessDaoZusammenImpl; public class ProcessDaoFactoryImpl extends ProcessDaoFactory { - private static final ProcessDao INSTANCE = new ProcessDaoCassandraImpl(); + private static final ProcessDao INSTANCE = new ProcessDaoZusammenImpl( + ZusammenAdaptorFactory.getInstance().createInterface()); @Override public ProcessDao 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/UploadDataDaoFactoryImpl.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/UploadDataDaoFactoryImpl.java deleted file mode 100644 index 317bc344c4..0000000000 --- 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/UploadDataDaoFactoryImpl.java +++ /dev/null @@ -1,33 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; - -import org.openecomp.sdc.vendorsoftwareproduct.dao.UploadDataDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.UploadDataDaoFactory; - -public class UploadDataDaoFactoryImpl extends UploadDataDaoFactory { - private static final UploadDataDao INSTANCE = new UploadDataDaoImpl(); - - @Override - public UploadDataDao 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/UploadDataDaoImpl.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/UploadDataDaoImpl.java deleted file mode 100644 index df019a4f53..0000000000 --- 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/UploadDataDaoImpl.java +++ /dev/null @@ -1,92 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; - -import com.datastax.driver.core.UDTValue; -import com.datastax.driver.mapping.Mapper; -import com.datastax.driver.mapping.Result; -import com.datastax.driver.mapping.UDTMapper; -import com.datastax.driver.mapping.annotations.Accessor; -import com.datastax.driver.mapping.annotations.Query; -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.UploadDataDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.UploadDataEntity; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; -import org.openecomp.sdc.versioning.dao.types.Version; - -import java.nio.ByteBuffer; -import java.util.Collection; - -public class UploadDataDaoImpl extends CassandraBaseDao implements UploadDataDao { - - private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); - private static final Mapper mapper = - noSqlDb.getMappingManager().mapper(UploadDataEntity.class); - private static final UploadDataAccessor accessor = - noSqlDb.getMappingManager().createAccessor(UploadDataAccessor.class); - private static final UDTMapper versionMapper = - noSqlDb.getMappingManager().udtMapper(Version.class); - - @Override - protected Mapper getMapper() { - return mapper; - } - - @Override - protected Object[] getKeys(UploadDataEntity entity) { - return new Object[]{entity.getId(), versionMapper.toUDT(entity.getVersion())}; - } - - @Override - public Collection list(UploadDataEntity entity) { - return accessor.listAll().all(); - } - - @Override - public void deleteContentDataAndValidationData(String vspId, Version version) { - accessor.deleteContentDataAndValidationData(vspId, versionMapper.toUDT(version)); - } - - @Override - public ByteBuffer getContentData(String vspId, Version version) { - return accessor.getContentData(vspId, version).one().getContentData(); - } - - - @Accessor - interface UploadDataAccessor { - - @Query( - "SELECT package_name, package_version, content_data, validation_data FROM vsp_information") - Result listAll(); - - @Query( - "DELETE package_name, package_version, content_data, validation_data FROM vsp_information " - + "WHERE vsp_id=? and version=?") - Result deleteContentDataAndValidationData(String vspId, UDTValue udtValue); - - @Query("SELECT CONTENT_DATA FROM vsp_information WHERE vsp_id=? and version=?") - Result getContentData(String vspId, Version version); - - } -} 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/VendorSoftwareProductDaoFactoryImpl.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/VendorSoftwareProductDaoFactoryImpl.java index 587f8ac036..96bb16ca70 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/VendorSoftwareProductDaoFactoryImpl.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/VendorSoftwareProductDaoFactoryImpl.java @@ -20,9 +20,11 @@ package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; +import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory; + public class VendorSoftwareProductDaoFactoryImpl extends VendorSoftwareProductDaoFactory { private static final VendorSoftwareProductDao INSTANCE = new VendorSoftwareProductDaoImpl(); 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/VendorSoftwareProductDaoImpl.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/VendorSoftwareProductDaoImpl.java index f592e63280..c0a215fff5 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/VendorSoftwareProductDaoImpl.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/VendorSoftwareProductDaoImpl.java @@ -22,202 +22,97 @@ package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; import org.openecomp.core.model.dao.EnrichedServiceArtifactDao; import org.openecomp.core.model.dao.EnrichedServiceArtifactDaoFactory; +import org.openecomp.core.model.dao.EnrichedServiceModelDao; +import org.openecomp.core.model.dao.EnrichedServiceModelDaoFactory; import org.openecomp.core.model.dao.ServiceArtifactDaoFactory; import org.openecomp.core.model.dao.ServiceArtifactDaoInter; -import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentArtifactDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentArtifactDaoFactory; +import org.openecomp.core.model.dao.ServiceModelDao; +import org.openecomp.core.model.dao.ServiceModelDaoFactory; +import org.openecomp.core.model.dao.ServiceTemplateDaoFactory; +import org.openecomp.core.model.dao.ServiceTemplateDaoInter; +import org.openecomp.core.utilities.CommonMethods; import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDependencyModelDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDependencyModelDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.MibDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.MibDaoFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.NetworkDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.NetworkDaoFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateCandidateDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateCandidateDaoFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.PackageInfoDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.PackageInfoDaoFactory; -import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessArtifactDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessArtifactDaoFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessDaoFactory; -import org.openecomp.sdc.vendorsoftwareproduct.dao.UploadDataDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.UploadDataDaoFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDaoFactory; -import org.openecomp.sdc.vendorsoftwareproduct.dao.VspQuestionnaireDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.VspQuestionnaireDaoFactory; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentArtifactEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentDependencyModelEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.PackageInfo; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessArtifactEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.UploadDataEntity; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspQuestionnaireEntity; import org.openecomp.sdc.versioning.dao.types.Version; import java.nio.ByteBuffer; import java.util.Collection; import java.util.List; -import java.util.Objects; public class VendorSoftwareProductDaoImpl implements VendorSoftwareProductDao { - private static final VendorSoftwareProductInfoDao vspInfoDao = - VendorSoftwareProductInfoDaoFactory.getInstance().createInterface(); + private static final VendorSoftwareProductInfoDao vspInfoDao = VendorSoftwareProductInfoDaoFactory + .getInstance().createInterface(); private static final PackageInfoDao packageInfoDao = PackageInfoDaoFactory.getInstance().createInterface(); - private static final UploadDataDao uploadDataDao = - UploadDataDaoFactory.getInstance().createInterface(); - private static final VspQuestionnaireDao vspQuestionnaireDao = - VspQuestionnaireDaoFactory.getInstance().createInterface(); + private static final OrchestrationTemplateCandidateDao orchestrationTemplateCandidateDataDao = + OrchestrationTemplateCandidateDaoFactory.getInstance().createInterface(); private static final NetworkDao networkDao = NetworkDaoFactory.getInstance().createInterface(); private static final ComponentDao componentDao = ComponentDaoFactory.getInstance().createInterface(); private static final NicDao nicDao = NicDaoFactory.getInstance().createInterface(); private static final ProcessDao processDao = ProcessDaoFactory.getInstance().createInterface(); - private static final ProcessArtifactDao processArtifactDao = - ProcessArtifactDaoFactory.getInstance().createInterface(); - private static final ComponentArtifactDao componentArtifactDao = - ComponentArtifactDaoFactory.getInstance().createInterface(); - private static final ServiceArtifactDaoInter artifactDao = - ServiceArtifactDaoFactory.getInstance().createInterface(); + private static final MibDao + MIB_DAO = MibDaoFactory.getInstance().createInterface(); + private static final ServiceArtifactDaoInter + artifactDao = ServiceArtifactDaoFactory.getInstance().createInterface(); + public static final ServiceTemplateDaoInter + templateDao = ServiceTemplateDaoFactory.getInstance().createInterface(); private static final EnrichedServiceArtifactDao enrichArtifactDao = EnrichedServiceArtifactDaoFactory.getInstance().createInterface(); + private static final EnrichedServiceModelDao enrichedServiceModelDao = + EnrichedServiceModelDaoFactory.getInstance().createInterface(); + private static final ServiceModelDao serviceModelDao = + ServiceModelDaoFactory.getInstance().createInterface(); + private static final ComponentDependencyModelDao componentDependencyModelDao = + ComponentDependencyModelDaoFactory.getInstance().createInterface(); @Override public void registerVersioning(String versionableEntityType) { vspInfoDao.registerVersioning(versionableEntityType); - vspQuestionnaireDao.registerVersioning(versionableEntityType); networkDao.registerVersioning(versionableEntityType); componentDao.registerVersioning(versionableEntityType); nicDao.registerVersioning(versionableEntityType); processDao.registerVersioning(versionableEntityType); + orchestrationTemplateCandidateDataDao.registerVersioning(versionableEntityType); + componentDependencyModelDao.registerVersioning(versionableEntityType); } - @Override - public void createVendorSoftwareProductInfo(VspDetails vspDetails) { - vspInfoDao.create(vspDetails); - } - - @Override - public Collection listVendorSoftwareProductsInfo() { - return vspInfoDao.list(new VspDetails()); - } - - public VspDetails getVendorSoftwareProductInfo(VspDetails vspDetails) { - return vspInfoDao.get(vspDetails); - } - - - @Override - public void updateVendorSoftwareProductInfo(VspDetails vspDetails) { - vspInfoDao.update(vspDetails); - } - - @Override - public void deleteVendorSoftwareProductInfo(VspDetails vspDetails) { - vspInfoDao.delete(vspDetails); - } - - @Override - public void updateUploadData(UploadDataEntity uploadData) { - uploadDataDao.update(uploadData); - } - - @Override - public UploadDataEntity getUploadData(UploadDataEntity uploadData) { - return uploadDataDao.get(uploadData); - } - - @Override - public ByteBuffer getContentData(UploadDataEntity uploadDataEntity) { - return uploadDataDao.getContentData(uploadDataEntity.getId(), uploadDataEntity.getVersion()); - } - - @Override - public void insertPackageDetails(PackageInfo packageInfo) { - packageInfoDao.update(packageInfo); - } - - @Override - public PackageInfo getPackageInfo(PackageInfo packageInfo) { - return packageInfoDao.get(packageInfo); - } - - @Override - public void deletePackageInfo(PackageInfo packageInfo) { - packageInfoDao.delete(packageInfo); - } - - @Override - public Collection listNetworks(String vspId, Version version) { - return networkDao.list(new NetworkEntity(vspId, version, null)); - } - - @Override - public void createNetwork(NetworkEntity network) { - networkDao.create(network); - } - - @Override - public void updateNetwork(NetworkEntity networkEntity) { - networkDao.update(networkEntity); - } - - @Override - public NetworkEntity getNetwork(String vspId, Version version, String networkId) { - return networkDao.get(new NetworkEntity(vspId, version, networkId)); - } - - @Override - public void deleteNetwork(String vspId, Version version) { - NetworkEntity networkEntity = new NetworkEntity(vspId, version, null); - networkDao.delete(networkEntity); - } - - @Override - public List listPackages(String category, String subCategory) { - return packageInfoDao.listByCategory(category, subCategory); - } - - @Override public Collection listComponents(String vspId, Version version) { return componentDao.list(new ComponentEntity(vspId, version, null)); } - @Override - public void createComponent(ComponentEntity component) { - componentDao.create(component); - } - - @Override - public void updateComponent(ComponentEntity component) { - componentDao.update(component); - } - - @Override - public ComponentEntity getComponent(String vspId, Version version, String componentId) { - return componentDao.get(new ComponentEntity(vspId, version, componentId)); - } - @Override public Collection listComponentsQuestionnaire(String vspId, Version version) { return componentDao.listQuestionnaires(vspId, version); } @Override - public void updateComponentQuestionnaire(String vspId, Version version, String componentId, - String questionnaireData) { - componentDao.updateQuestionnaireData(vspId, version, componentId, questionnaireData); - } - - @Override - public void deleteComponent(String vspId, Version version) { - ComponentEntity componentEntity = new ComponentEntity(vspId, version, null); - componentDao.delete(componentEntity); + public Collection listComponentsCompositionAndQuestionnaire(String vspId, + Version version) { + return componentDao.listCompositionAndQuestionnaire(vspId, version); } @Override @@ -255,60 +150,25 @@ public class VendorSoftwareProductDaoImpl implements VendorSoftwareProductDao { @Override public void uploadProcessArtifact(String vspId, Version version, String componentId, String processId, byte[] artifact, String artifactName) { - ProcessArtifactEntity processArtifact = - new ProcessArtifactEntity(vspId, version, componentId, processId); + ProcessEntity + processArtifact = new ProcessEntity(vspId, version, componentId, processId); + processArtifact = processDao.get(processArtifact); processArtifact.setArtifact(ByteBuffer.wrap(artifact)); processArtifact.setArtifactName(artifactName); - processArtifactDao.update(processArtifact); + processDao.update(processArtifact); } @Override - public ProcessArtifactEntity getProcessArtifact(String vspId, Version version, String componentId, - String processId) { - return processArtifactDao - .get(new ProcessArtifactEntity(vspId, version, componentId, processId)); + public ProcessEntity getProcessArtifact(String vspId, Version version, String componentId, + String processId) { + return processDao + .get(new ProcessEntity(vspId, version, componentId, processId)); } @Override public void deleteProcessArtifact(String vspId, Version version, String componentId, String processId) { - processArtifactDao.delete(new ProcessArtifactEntity(vspId, version, componentId, processId)); - } - - @Override - public VspQuestionnaireEntity getQuestionnaire(String vspId, Version version) { - return vspQuestionnaireDao.get(new VspQuestionnaireEntity(vspId, version)); - } - - @Override - public void updateQuestionnaire(String vspId, Version version, String questionnaireData) { - vspQuestionnaireDao.updateQuestionnaireData(vspId, version, questionnaireData); - } - - @Override - public Collection listNics(String vspId, Version version, String componentId) { - return nicDao.list(new NicEntity(vspId, version, componentId, null)); - } - - @Override - public void createNic(NicEntity nic) { - nicDao.create(nic); - } - - @Override - public NicEntity getNic(String vspId, Version version, String componentId, String nicId) { - return nicDao.get(new NicEntity(vspId, version, componentId, nicId)); - } - - @Override - public void updateNic(NicEntity nicEntity) { - nicDao.update(nicEntity); - } - - @Override - public void updateNicQuestionnaire(String vspId, Version version, String componentId, - String nicId, String questionnaireData) { - nicDao.updateQuestionnaireData(vspId, version, componentId, nicId, questionnaireData); + processDao.delete(new ProcessEntity(vspId, version, componentId, processId)); } @Override @@ -316,34 +176,50 @@ public class VendorSoftwareProductDaoImpl implements VendorSoftwareProductDao { return nicDao.listByVsp(vspId, version); } - @Override - public void deleteNic(String vspId, Version version, String componentId) { - NicEntity nicEntity = new NicEntity(vspId, version, componentId, null); - nicDao.delete(nicEntity); - } - @Override public void deleteUploadData(String vspId, Version version) { + networkDao.deleteAll(vspId, version); - nicDao.deleteByVspId(vspId, version); - artifactDao.delete(vspId, version); - enrichArtifactDao.delete(vspId, version); - ComponentArtifactEntity componentArtifactEntity = - new ComponentArtifactEntity(vspId, version, null, null); - ProcessEntity processEntity = new ProcessEntity(vspId, version, null, null); - componentArtifactDao.deleteAll(componentArtifactEntity); - processDao.deleteAll(processEntity); + //nicDao.deleteByVspId(vspId, version); + //artifactDao.delete(vspId, version); + //templateDao.deleteAll(vspId, version); + enrichedServiceModelDao.deleteAll(vspId, version); + serviceModelDao.deleteAll(vspId, version); + //processDao.deleteVspAll(vspId,version); componentDao.deleteAll(vspId, version); - uploadDataDao.deleteContentDataAndValidationData(vspId, version); + vspInfoDao.deleteAll(vspId, version); + +// uploadDataDao.deleteContentDataAndValidationData(vspId, version); + +// enrichArtifactDao.deleteAll(vspId, version); +// artifactDao.deleteAll(vspId, version); } - @Override - public void updateVspLatestModificationTime(String vspId, Version version) { - if (Objects.isNull(vspId) || Objects.isNull(version)) { + /* @Override + public void updateVspLatestModificationTime(String vspId, Version version) { + *//* if (Objects.isNull(vspId) || Objects.isNull(version)) { return; } VspDetails retrieved = getVendorSoftwareProductInfo(new VspDetails(vspId, version)); - updateVendorSoftwareProductInfo(retrieved); + updateVendorSoftwareProductInfo(retrieved);*//* + } +*/ + @Override + public void createComponentDependencyModel(List + componentDependencyModel, String vspId, + Version version) { + componentDependencyModelDao.deleteAll(vspId, version); + for (ComponentDependencyModelEntity entity : componentDependencyModel) { + entity.setId(CommonMethods.nextUuId()); + componentDependencyModelDao.create(entity); + } + } + + @Override + public Collection listComponentDependencies(String vspId, + Version version) { + return componentDependencyModelDao.list(new ComponentDependencyModelEntity(vspId, version, + 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/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 1dcb3f4c66..a5f9d17431 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 @@ -20,12 +20,15 @@ package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; +import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.VendorSoftwareProductInfoDaoZusammenImpl; public class VendorSoftwareProductInfoDaoFactoryImpl extends VendorSoftwareProductInfoDaoFactory { private static final VendorSoftwareProductInfoDao INSTANCE = - new VendorSoftwareProductInfoDaoImpl(); + new VendorSoftwareProductInfoDaoZusammenImpl( + ZusammenAdaptorFactory.getInstance().createInterface()); @Override public VendorSoftwareProductInfoDao 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/VendorSoftwareProductInfoDaoImpl.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/VendorSoftwareProductInfoDaoImpl.java index c3096dab29..5a8635cf98 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/VendorSoftwareProductInfoDaoImpl.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/VendorSoftwareProductInfoDaoImpl.java @@ -30,6 +30,7 @@ import org.openecomp.core.nosqldb.api.NoSqlDb; import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspQuestionnaireEntity; import org.openecomp.sdc.versioning.VersioningManagerFactory; import org.openecomp.sdc.versioning.dao.types.Version; import org.openecomp.sdc.versioning.types.VersionableEntityMetadata; @@ -71,13 +72,39 @@ public class VendorSoftwareProductInfoDaoImpl extends CassandraBaseDao listAll(); - } } 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/VspQuestionnaireDaoCassandraImpl.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/VspQuestionnaireDaoCassandraImpl.java deleted file mode 100644 index ef4dd0de74..0000000000 --- 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/VspQuestionnaireDaoCassandraImpl.java +++ /dev/null @@ -1,72 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; - -import com.datastax.driver.core.ResultSet; -import com.datastax.driver.core.UDTValue; -import com.datastax.driver.mapping.Mapper; -import com.datastax.driver.mapping.UDTMapper; -import com.datastax.driver.mapping.annotations.Accessor; -import com.datastax.driver.mapping.annotations.Query; -import org.openecomp.core.nosqldb.api.NoSqlDb; -import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; -import org.openecomp.sdc.vendorsoftwareproduct.dao.VspQuestionnaireDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspQuestionnaireEntity; -import org.openecomp.sdc.versioning.VersioningManagerFactory; -import org.openecomp.sdc.versioning.dao.types.Version; -import org.openecomp.sdc.versioning.types.VersionableEntityMetadata; - -public class VspQuestionnaireDaoCassandraImpl implements VspQuestionnaireDao { - - private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); - private static final Mapper mapper = - noSqlDb.getMappingManager().mapper(VspQuestionnaireEntity.class); - private static final VspQuestionnaireAccessor accessor = - noSqlDb.getMappingManager().createAccessor(VspQuestionnaireAccessor.class); - private static final UDTMapper versionMapper = - noSqlDb.getMappingManager().udtMapper(Version.class); - - @Override - public void registerVersioning(String versionableEntityType) { - VersioningManagerFactory.getInstance().createInterface() - .register(versionableEntityType, new VersionableEntityMetadata( - mapper.getTableMetadata().getName(), - mapper.getTableMetadata().getPartitionKey().get(0).getName(), - mapper.getTableMetadata().getPartitionKey().get(1).getName())); - } - - @Override - public VspQuestionnaireEntity get(VspQuestionnaireEntity entity) { - return mapper.get(entity.getId(), versionMapper.toUDT(entity.getVersion())); - } - - @Override - public void updateQuestionnaireData(String id, Version version, String questionnaireData) { - accessor.updateQuestionnaireData(questionnaireData, id, versionMapper.toUDT(version)); - } - - @Accessor - interface VspQuestionnaireAccessor { - - @Query("update vsp_information set questionnaire_data=? where vsp_id=? and version=?") - ResultSet updateQuestionnaireData(String questionnaireData, String id, UDTValue version); - } -} 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/VspQuestionnaireDaoFactoryImpl.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/VspQuestionnaireDaoFactoryImpl.java deleted file mode 100644 index aa91302ca2..0000000000 --- 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/VspQuestionnaireDaoFactoryImpl.java +++ /dev/null @@ -1,33 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; - -import org.openecomp.sdc.vendorsoftwareproduct.dao.VspQuestionnaireDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.VspQuestionnaireDaoFactory; - -public class VspQuestionnaireDaoFactoryImpl extends VspQuestionnaireDaoFactory { - private static final VspQuestionnaireDao INSTANCE = new VspQuestionnaireDaoCassandraImpl(); - - @Override - public VspQuestionnaireDao 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/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 new file mode 100644 index 0000000000..8ef09ada7b --- /dev/null +++ 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 @@ -0,0 +1,244 @@ +package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen; + +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; +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 com.amdocs.zusammen.datatypes.item.Info; +import org.openecomp.core.utilities.file.FileUtils; +import org.openecomp.core.zusammen.api.ZusammenAdaptor; +import org.openecomp.core.zusammen.api.ZusammenUtil; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; +import org.openecomp.sdc.versioning.dao.types.Version; + +import java.io.ByteArrayInputStream; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Optional; +import java.util.stream.Collectors; + +public class ComponentDaoZusammenImpl implements ComponentDao { + + private ZusammenAdaptor zusammenAdaptor; + + public ComponentDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { + this.zusammenAdaptor = zusammenAdaptor; + } + + @Override + public void registerVersioning(String versionableEntityType) { + } + + @Override + public Collection list(ComponentEntity component) { + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(component.getVspId()); + ElementContext elementContext = new ElementContext(itemId, + VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor), + VspZusammenUtil.getVersionTag(component.getVersion())); + + return listComponents(zusammenAdaptor, context, elementContext, component.getVspId(), + component.getVersion()); + } + + static Collection listComponents(ZusammenAdaptor zusammenAdaptor, + SessionContext context, + ElementContext elementContext, + String vspId, Version version) { + return zusammenAdaptor + .listElementsByName(context, elementContext, null, StructureElement.Components.name()) + .stream().map(elementInfo -> mapElementInfoToComponent(vspId, version, elementInfo)) + .collect(Collectors.toList()); + } + + private static ComponentEntity mapElementInfoToComponent(String vspId, Version version, + ElementInfo elementInfo) { + ComponentEntity componentEntity = + new ComponentEntity(vspId, version, elementInfo.getId().getValue()); + componentEntity.setCompositionData( + elementInfo.getInfo().getProperty(ElementPropertyName.compositionData.name())); + return componentEntity; + } + + @Override + public void create(ComponentEntity component) { + ZusammenElement componentElement = componentToZusammen(component, Action.CREATE); + ZusammenElement componentsElement = + VspZusammenUtil.buildStructuralElement(StructureElement.Components, null); + componentsElement.getSubElements().add(componentElement); + + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(component.getVspId()); + Optional savedElement = zusammenAdaptor.saveElement(context, + new ElementContext(itemId, + VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)), + componentsElement, "Create component"); + savedElement.ifPresent(element -> + component.setId(element.getSubElements().iterator().next().getElementId().getValue())); + } + + @Override + public void update(ComponentEntity component) { + ZusammenElement componentElement = componentToZusammen(component, Action.UPDATE); + + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(component.getVspId()); + zusammenAdaptor.saveElement(context, + new ElementContext(itemId, + VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)), + componentElement, String.format("Update component with id %s", component.getId())); + } + + @Override + public ComponentEntity get(ComponentEntity component) { + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(component.getVspId()); + ElementContext elementContext = new ElementContext(itemId, + VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor), + VspZusammenUtil.getVersionTag(component.getVersion())); + + Optional element = + zusammenAdaptor.getElement(context, elementContext, component.getId()); + + if (element.isPresent()) { + component.setCompositionData(new String(FileUtils.toByteArray(element.get().getData()))); + return component; + } + return null; + } + + @Override + public void delete(ComponentEntity component) { + ZusammenElement componentElement = new ZusammenElement(); + componentElement.setElementId(new Id(component.getId())); + componentElement.setAction(Action.DELETE); + + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(component.getVspId()); + zusammenAdaptor.saveElement(context, + new ElementContext(itemId, + VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)), + componentElement, String.format("Delete component with id %s", component.getId())); + } + + @Override + public ComponentEntity getQuestionnaireData(String vspId, Version version, String componentId) { + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(vspId); + ElementContext elementContext = new ElementContext(itemId, + VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor), + VspZusammenUtil.getVersionTag(version)); + + return getQuestionnaire(context, elementContext, + new ComponentEntity(vspId, version, componentId)); + } + + private ComponentEntity getQuestionnaire(SessionContext context, ElementContext elementContext, + ComponentEntity component) { + Optional questionnaireElement = zusammenAdaptor + .getElementByName(context, elementContext, new Id(component.getId()), + StructureElement.Questionnaire.name()); + return questionnaireElement.map( + element -> element.getData() == null + ? null + : new String(FileUtils.toByteArray(element.getData()))) + .map(questionnaireData -> { + component.setQuestionnaireData(questionnaireData); + return component; + }) + .orElse(null); + } + + @Override + public void updateQuestionnaireData(String vspId, Version version, String componentId, + String questionnaireData) { + ZusammenElement questionnaireElement = + componentQuestionnaireToZusammen(questionnaireData, Action.UPDATE); + + ZusammenElement componentElement = new ZusammenElement(); + componentElement.setAction(Action.IGNORE); + componentElement.setElementId(new Id(componentId)); + componentElement.setSubElements(Collections.singletonList(questionnaireElement)); + + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(vspId); + zusammenAdaptor.saveElement(context, + new ElementContext(itemId, + VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)), + 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 = ZusammenUtil.createSessionContext(); + Id itemId = new Id(vspId); + ElementContext elementContext = new ElementContext(itemId, + VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor), + VspZusammenUtil.getVersionTag(version)); + + Collection components = + listComponents(zusammenAdaptor, context, elementContext, vspId, version); + + components.forEach(component -> getQuestionnaire(context, elementContext, component)); + return components; + } + + @Override + public void deleteAll(String vspId, Version version) { + ZusammenElement componentsElement = + VspZusammenUtil.buildStructuralElement(StructureElement.Components, Action.DELETE); + + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(vspId); + zusammenAdaptor.saveElement(context, + new ElementContext(itemId, + VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)), + componentsElement, "Delete all components"); + } + + private ZusammenElement componentToZusammen(ComponentEntity component, Action action) { + ZusammenElement componentElement = buildComponentElement(component, action); + if (action == Action.CREATE) { + componentElement + .setSubElements(Arrays.asList( + componentQuestionnaireToZusammen(component.getQuestionnaireData(), Action.CREATE), + VspZusammenUtil.buildStructuralElement(StructureElement.Nics, Action.CREATE), + VspZusammenUtil.buildStructuralElement(StructureElement.Processes, Action.CREATE), + VspZusammenUtil.buildStructuralElement(StructureElement.Mibs, Action.CREATE))); + } + return componentElement; + } + + private ZusammenElement componentQuestionnaireToZusammen(String questionnaireData, + Action action) { + ZusammenElement questionnaireElement = + VspZusammenUtil.buildStructuralElement(StructureElement.Questionnaire, action); + questionnaireElement.setData(new ByteArrayInputStream(questionnaireData.getBytes())); + return questionnaireElement; + } + + private ZusammenElement buildComponentElement(ComponentEntity component, Action action) { + ZusammenElement componentElement = new ZusammenElement(); + componentElement.setAction(action); + if (component.getId() != null) { + componentElement.setElementId(new Id(component.getId())); + } + Info info = new Info(); + info.addProperty(ElementPropertyName.type.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 new file mode 100644 index 0000000000..e36b6c7743 --- /dev/null +++ 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 @@ -0,0 +1,201 @@ +package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen; + +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; +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 com.amdocs.zusammen.datatypes.item.Info; +import org.openecomp.core.zusammen.api.ZusammenAdaptor; +import org.openecomp.core.zusammen.api.ZusammenUtil; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDependencyModelDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentDependencyModelEntity; +import org.openecomp.sdc.versioning.dao.types.Version; + +import java.util.Collection; +import java.util.Optional; +import java.util.stream.Collectors; + +/** + * Created by ayalaben on 5/16/2017. + */ +public class ComponentDependencyModelDaoZusammenImpl implements ComponentDependencyModelDao { + + private static final Logger logger = + LoggerFactory.getLogger(OrchestrationTemplateCandidateDaoZusammenImpl.class); + + private ZusammenAdaptor zusammenAdaptor; + + public ComponentDependencyModelDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { + this.zusammenAdaptor = zusammenAdaptor; + } + + @Override + public ComponentDependencyModelEntity get(ComponentDependencyModelEntity entity) { + + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(entity.getVspId()); // entity.getId()? + ElementContext elementContext = new ElementContext(itemId, + VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor), + VspZusammenUtil.getVersionTag(entity.getVersion())); + + Optional componentDependencyElement = + zusammenAdaptor.getElementInfo(context, elementContext, new Id(entity.getId())); + + if (componentDependencyElement.isPresent()) { + addComponentDependencyData(entity, componentDependencyElement.get()); + return entity; + } + + return null; + } + + @Override + public void create(ComponentDependencyModelEntity entity) { + + ZusammenElement componentDependencies = + VspZusammenUtil.buildStructuralElement(StructureElement.ComponentDependencies, null); + + ZusammenElement componentDependency = buildComponentDependencyElement(entity); + componentDependency.setAction(Action.CREATE); + + Id itemId = new Id(entity.getVspId()); + SessionContext context = ZusammenUtil.createSessionContext(); + ElementContext elementContext = new ElementContext(itemId, + VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)); + + Optional savedElement = zusammenAdaptor.saveElement(context, elementContext, + VspZusammenUtil.aggregateElements(componentDependencies, componentDependency), + "Create component dependency model"); + + savedElement.ifPresent(element -> + entity.setId(element.getSubElements().iterator().next().getElementId().getValue())); + } + + @Override + public void update(ComponentDependencyModelEntity entity) { + ZusammenElement componentDependencyElement = buildComponentDependencyElement(entity); + componentDependencyElement.setAction(Action.UPDATE); + + Id itemId = new Id(entity.getVspId()); + SessionContext context = ZusammenUtil.createSessionContext(); + ElementContext elementContext = new ElementContext(itemId, + VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)); + + zusammenAdaptor.saveElement(context, elementContext, + componentDependencyElement, + String.format("Update component dependency model with id %s", entity.getId())); + } + + @Override + public void delete(ComponentDependencyModelEntity entity) { + ZusammenElement componentDependencyElement = new ZusammenElement(); + componentDependencyElement.setElementId(new Id(entity.getId())); + componentDependencyElement.setAction(Action.DELETE); + + Id itemId = new Id(entity.getVspId()); + SessionContext context = ZusammenUtil.createSessionContext(); + ElementContext elementContext = new ElementContext(itemId, + VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)); + + + zusammenAdaptor.saveElement(context, elementContext, + componentDependencyElement, + String.format("Delete component dependency model with id %s", entity.getId())); + } + + @Override + public void deleteAll(String vspId, Version version) { + ZusammenElement componentDependenciesElement = + VspZusammenUtil + .buildStructuralElement(StructureElement.ComponentDependencies, Action.DELETE); + + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(vspId); + zusammenAdaptor.saveElement(context, new ElementContext(itemId, + VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)), + componentDependenciesElement, "Delete all component dependencies"); + } + + @Override + public void registerVersioning(String versionableEntityType) { + //not implemented? + } + + @Override + public Collection list(ComponentDependencyModelEntity entity) { + + Id itemId = new Id(entity.getVspId()); + SessionContext context = ZusammenUtil.createSessionContext(); + ElementContext elementContext = new ElementContext(itemId, + VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor), + VspZusammenUtil.getVersionTag(entity.getVersion())); + + return zusammenAdaptor.listElementsByName(context, elementContext, + null, StructureElement.ComponentDependencies.name()) + .stream().map(elementInfo -> mapElementInfoToComponentDependencyModel(entity.getVspId(), + entity.getVersion(), elementInfo)) + .collect(Collectors.toList()); + } + + private static ComponentDependencyModelEntity mapElementInfoToComponentDependencyModel( + String vspId, Version version, + ElementInfo elementInfo) { + ComponentDependencyModelEntity componentDependencyModelEntity = + new ComponentDependencyModelEntity(vspId, version, elementInfo.getId().getValue()); + componentDependencyModelEntity.setSourceComponentId(elementInfo.getInfo() + .getProperty(ComponentDependencyModelPropertyName.sourcecomponent_id.name())); + componentDependencyModelEntity.setTargetComponentId(elementInfo.getInfo() + .getProperty(ComponentDependencyModelPropertyName.targetcomponent_id.name())); + componentDependencyModelEntity.setRelation(elementInfo.getInfo() + .getProperty(ComponentDependencyModelPropertyName.relation.name())); + + return componentDependencyModelEntity; + } + + + private ZusammenElement buildComponentDependencyElement(ComponentDependencyModelEntity entity) { + ZusammenElement componentDependencyElement = new ZusammenElement(); + + if (entity.getId() != null) { + componentDependencyElement.setElementId(new Id(entity.getId())); + } + + Info info = new Info(); + info.addProperty(ComponentDependencyModelPropertyName.id.name(), entity.getId()); + info.addProperty(ComponentDependencyModelPropertyName.relation.name(), entity.getRelation()); + info.addProperty(ComponentDependencyModelPropertyName.sourcecomponent_id.name(), + entity.getSourceComponentId()); + info.addProperty(ComponentDependencyModelPropertyName.targetcomponent_id.name(), + entity.getTargetComponentId()); + + componentDependencyElement.setInfo(info); + + return componentDependencyElement; + } + + private void addComponentDependencyData(ComponentDependencyModelEntity componentDependency, + ElementInfo componentDependencyElement) { + componentDependency.setId(componentDependencyElement.getInfo() + .getProperty(ComponentDependencyModelPropertyName.id.name())); + componentDependency.setRelation(componentDependencyElement.getInfo() + .getProperty(ComponentDependencyModelPropertyName.id.name())); + componentDependency.setSourceComponentId(componentDependencyElement.getInfo() + .getProperty(ComponentDependencyModelPropertyName.sourcecomponent_id.name())); + componentDependency.setTargetComponentId(componentDependencyElement.getInfo() + .getProperty(ComponentDependencyModelPropertyName.targetcomponent_id.name())); + } + + + private 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/ElementPropertyName.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/ElementPropertyName.java new file mode 100644 index 0000000000..9ca0bf721a --- /dev/null +++ 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/ElementPropertyName.java @@ -0,0 +1,6 @@ +package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen; + +public enum ElementPropertyName { + type, + compositionData +} 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/ElementType.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/ElementType.java new file mode 100644 index 0000000000..b0313f5b14 --- /dev/null +++ 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/ElementType.java @@ -0,0 +1,9 @@ +package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen; + +public enum ElementType { + Network, + Component, + Nic, + Process, + LKG +} 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/MibDaoZusammenImpl.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/MibDaoZusammenImpl.java new file mode 100644 index 0000000000..10cdfbd9da --- /dev/null +++ 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/MibDaoZusammenImpl.java @@ -0,0 +1,171 @@ +package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen; + +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; +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 org.openecomp.core.enrichment.types.ArtifactType; +import org.openecomp.core.utilities.file.FileUtils; +import org.openecomp.core.zusammen.api.ZusammenAdaptor; +import org.openecomp.core.zusammen.api.ZusammenUtil; +import org.openecomp.sdc.vendorsoftwareproduct.dao.MibDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.MibEntity; +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 java.util.stream.Collectors; + +/** + * @author Avrahamg. + * @since March 21, 2017 + */ +public class MibDaoZusammenImpl implements MibDao { + + private static final String ARTIFACT_NAME = "name"; + + private ZusammenAdaptor zusammenAdaptor; + + public MibDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { + this.zusammenAdaptor = zusammenAdaptor; + } + + @Override + public void registerVersioning(String versionableEntityType) { + + } + + @Override + public Optional getByType(MibEntity mibEntity) { + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(mibEntity.getVspId()); + ElementContext elementContext = new ElementContext(itemId, + VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor), + VspZusammenUtil.getVersionTag(mibEntity.getVersion())); + + Optional mibsElement = + zusammenAdaptor.getElementByName(context, elementContext, new Id(mibEntity + .getComponentId()), StructureElement.Mibs.toString()); + if (mibsElement.isPresent()) { + Optional mibElement = zusammenAdaptor + .getElementByName(context, elementContext, mibsElement.get().getElementId(), + getMibStructuralElement(mibEntity.getType()).toString()); + if (mibElement.isPresent()) { + mibEntity.setId(mibElement.get().getElementId().getValue()); + mibEntity.setArtifactName((String) mibElement.get().getInfo().getProperties().get(ARTIFACT_NAME)); + mibEntity.setArtifact(ByteBuffer.wrap(FileUtils.toByteArray(mibElement.get().getData()))); + return Optional.of(mibEntity); + } + } + + return Optional.empty(); + } + + @Override + public void create(MibEntity mibEntity) { + ZusammenElement mibElement = buildMibElement(mibEntity); + + ZusammenElement mibsElement = + VspZusammenUtil.buildStructuralElement(StructureElement.Mibs, null); + + ZusammenElement componentElement = buildComponentElement(mibEntity); + + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(mibEntity.getVspId()); + ElementContext elementContext = new ElementContext(itemId, + VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)); + + Optional savedElement = zusammenAdaptor.saveElement(context, elementContext, + VspZusammenUtil.aggregateElements(componentElement, mibsElement, mibElement), + "Create mib"); + savedElement.ifPresent(element -> + mibEntity.setId(element.getSubElements().iterator().next() + .getSubElements().iterator().next().getElementId().getValue())); + } + + @Override + public void delete(MibEntity mibEntity) { + ZusammenElement mibElement = new ZusammenElement(); + mibElement.setElementId(new Id(mibEntity.getId())); + mibElement.setAction(Action.DELETE); + + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(mibEntity.getVspId()); + ElementContext elementContext = new ElementContext(itemId, + VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)); + + zusammenAdaptor.saveElement(context, elementContext, mibElement, + String.format("Delete mib with id %s", mibEntity.getId())); + } + + @Override + public Collection list(MibEntity mib) { + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(mib.getVspId()); + ElementContext elementContext = new ElementContext(itemId, + VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor), + VspZusammenUtil.getVersionTag(mib.getVersion())); + + return zusammenAdaptor.listElementsByName(context, elementContext, new Id(mib.getComponentId()), + StructureElement.Mibs.toString()).stream() + .map(elementInfo -> + mapElementInfoToMib(mib.getVspId(), mib.getVersion(), mib.getComponentId(), + elementInfo)) + .collect(Collectors.toList()); + } + + @Override + public void deleteAll(MibEntity mibEntity) { + ZusammenElement mibsElement = + VspZusammenUtil.buildStructuralElement(StructureElement.Mibs, Action.DELETE); + + ZusammenElement componentElement = buildComponentElement(mibEntity); + + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(mibEntity.getVspId()); + ElementContext elementContext = new ElementContext(itemId, + VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)); + + zusammenAdaptor.saveElement(context, elementContext, + VspZusammenUtil.aggregateElements(componentElement, mibsElement), "Delete mibs"); + } + + private ZusammenElement buildComponentElement(MibEntity mibEntity) { + ZusammenElement componentElement = new ZusammenElement(); + componentElement.setElementId(new Id(mibEntity.getComponentId())); + componentElement.setAction(Action.IGNORE); + return componentElement; + } + + private ZusammenElement buildMibElement(MibEntity mib) { + ZusammenElement mibElement = VspZusammenUtil + .buildStructuralElement(getMibStructuralElement(mib.getType()), Action.UPDATE); + mibElement.getInfo().getProperties().put(ARTIFACT_NAME, mib.getArtifactName()); + mibElement.setData(new ByteArrayInputStream(mib.getArtifact().array())); + return mibElement; + } + + private MibEntity mapElementInfoToMib(String vspId, Version version, String componentId, + ElementInfo elementInfo) { + MibEntity mib = new MibEntity(vspId, version, componentId, elementInfo.getId().getValue()); + mib.setArtifactName((String) elementInfo.getInfo().getProperties().get(ARTIFACT_NAME)); + mib.setType(ArtifactType.valueOf(elementInfo.getInfo().getName())); + return mib; + } + + private StructureElement getMibStructuralElement(ArtifactType type) { + switch (type) { + case SNMP_POLL: + return StructureElement.SNMP_POLL; + case SNMP_TRAP: + return StructureElement.SNMP_TRAP; + 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/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 new file mode 100644 index 0000000000..898ee434e8 --- /dev/null +++ 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 @@ -0,0 +1,150 @@ +package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen; + +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; +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 com.amdocs.zusammen.datatypes.item.Info; +import org.openecomp.core.utilities.file.FileUtils; +import org.openecomp.core.zusammen.api.ZusammenAdaptor; +import org.openecomp.core.zusammen.api.ZusammenUtil; +import org.openecomp.sdc.vendorsoftwareproduct.dao.NetworkDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.sdc.versioning.dao.types.VersionStatus; + +import java.io.ByteArrayInputStream; +import java.util.Collection; +import java.util.Collections; +import java.util.Optional; +import java.util.stream.Collectors; + +public class NetworkDaoZusammenImpl implements NetworkDao { + + private ZusammenAdaptor zusammenAdaptor; + + public NetworkDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { + this.zusammenAdaptor = zusammenAdaptor; + } + + @Override + public void registerVersioning(String versionableEntityType) { + + } + + @Override + public Collection list(NetworkEntity network) { + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(network.getVspId()); + ElementContext elementContext = new ElementContext(itemId, + VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor), + VspZusammenUtil.getVersionTag(network.getVersion())); + + return zusammenAdaptor + .listElementsByName(context, elementContext, null, StructureElement.Networks.name()) + .stream().map(elementInfo -> + mapElementInfoToNetwork(network.getVspId(), network.getVersion(), elementInfo)) + .collect(Collectors.toList()); + } + + private NetworkEntity mapElementInfoToNetwork(String vspId, Version version, + ElementInfo elementInfo) { + NetworkEntity networkEntity = + new NetworkEntity(vspId, version, elementInfo.getId().getValue()); + networkEntity.setCompositionData( + elementInfo.getInfo().getProperty(ElementPropertyName.compositionData.name())); + return networkEntity; + } + + @Override + public void create(NetworkEntity network) { + ZusammenElement networkElement = buildNetworkElement(network, Action.CREATE); + ZusammenElement networksElement = + VspZusammenUtil.buildStructuralElement(StructureElement.Networks, null); + networksElement.setSubElements(Collections.singletonList(networkElement)); + + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(network.getVspId()); + ElementContext elementContext = new ElementContext(itemId, + VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)); + Optional savedElement = + zusammenAdaptor.saveElement(context, elementContext, networksElement, "Create network"); + savedElement.ifPresent(element -> + network.setId(element.getSubElements().iterator().next().getElementId().getValue())); + } + + @Override + public void update(NetworkEntity network) { + ZusammenElement networkElement = buildNetworkElement(network, Action.UPDATE); + + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(network.getVspId()); + ElementContext elementContext = new ElementContext(itemId, + VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)); + zusammenAdaptor.saveElement(context, elementContext, networkElement, + String.format("Update network with id %s", network.getId())); + } + + @Override + public NetworkEntity get(NetworkEntity network) { + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(network.getVspId()); + ElementContext elementContext = new ElementContext(itemId, + VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor), + VspZusammenUtil.getVersionTag(network.getVersion())); + + Optional element = + zusammenAdaptor.getElement(context, elementContext, network.getId()); + + if (element.isPresent()) { + network.setCompositionData(new String(FileUtils.toByteArray(element.get().getData()))); + return network; + } else { + return null; + } + } + + @Override + public void delete(NetworkEntity network) { + ZusammenElement networkElement = new ZusammenElement(); + networkElement.setElementId(new Id(network.getId())); + networkElement.setAction(Action.DELETE); + + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(network.getVspId()); + ElementContext elementContext = new ElementContext(itemId, + VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)); + zusammenAdaptor.saveElement(context, elementContext, + networkElement, String.format("Delete network with id %s", network.getId())); + } + + + @Override + public void deleteAll(String vspId, Version version) { + ZusammenElement networksElement = + VspZusammenUtil.buildStructuralElement(StructureElement.Networks, Action.DELETE); + + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(vspId); + ElementContext elementContext = new ElementContext(itemId, + VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)); + zusammenAdaptor.saveElement(context, elementContext, networksElement, "Delete all networks"); + } + + private ZusammenElement buildNetworkElement(NetworkEntity network, Action action) { + ZusammenElement networkElement = new ZusammenElement(); + networkElement.setAction(action); + if (network.getId() != null) { + networkElement.setElementId(new Id(network.getId())); + } + Info info = new Info(); + info.addProperty(ElementPropertyName.type.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 new file mode 100644 index 0000000000..e597068d87 --- /dev/null +++ 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 @@ -0,0 +1,257 @@ +package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen; + +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; +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 com.amdocs.zusammen.datatypes.item.Info; +import org.openecomp.core.utilities.file.FileUtils; +import org.openecomp.core.zusammen.api.ZusammenAdaptor; +import org.openecomp.core.zusammen.api.ZusammenUtil; +import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity; +import org.openecomp.sdc.versioning.dao.types.Version; + +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 { + + private ZusammenAdaptor zusammenAdaptor; + + public NicDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { + this.zusammenAdaptor = zusammenAdaptor; + } + + @Override + public void registerVersioning(String versionableEntityType) { + + } + + @Override + public Collection list(NicEntity nic) { + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(nic.getVspId()); + ElementContext elementContext = new ElementContext(itemId, + VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor), + VspZusammenUtil.getVersionTag(nic.getVersion())); + + return listNics(context, elementContext, nic); + } + + private Collection listNics(SessionContext context, ElementContext elementContext, + NicEntity nic) { + return zusammenAdaptor + .listElementsByName(context, elementContext, new Id(nic.getComponentId()), + StructureElement.Nics.name()) + .stream().map(elementInfo -> mapElementInfoToNic( + nic.getVspId(), nic.getVersion(), nic.getComponentId(), elementInfo)) + .collect(Collectors.toList()); + } + + private NicEntity mapElementInfoToNic(String vspId, Version version, + String componentId, ElementInfo elementInfo) { + NicEntity nicEntity = + new NicEntity(vspId, version, componentId, elementInfo.getId().getValue()); + nicEntity.setCompositionData( + elementInfo.getInfo().getProperty(ElementPropertyName.compositionData.name())); + return nicEntity; + } + + @Override + public void create(NicEntity nic) { + ZusammenElement nicElement = nicToZusammen(nic, Action.CREATE); + + ZusammenElement nicsElement = + VspZusammenUtil.buildStructuralElement(StructureElement.Nics, null); + nicsElement.setSubElements(Collections.singletonList(nicElement)); + + ZusammenElement componentElement = + buildZusammenElement(new Id(nic.getComponentId()), Action.IGNORE); + componentElement.setSubElements(Collections.singletonList(nicsElement)); + + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(nic.getVspId()); + ElementContext elementContext = new ElementContext(itemId, + VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)); + + Optional savedElement = + zusammenAdaptor.saveElement(context, elementContext, componentElement, "Create nic"); + savedElement.ifPresent(element -> + nic.setId(element.getSubElements().iterator().next() + .getSubElements().iterator().next().getElementId().getValue())); + } + + @Override + public void update(NicEntity nic) { + ZusammenElement nicElement = nicToZusammen(nic, Action.UPDATE); + + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(nic.getVspId()); + ElementContext elementContext = new ElementContext(itemId, + VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)); + zusammenAdaptor.saveElement(context, elementContext, nicElement, + String.format("Update nic with id %s", nic.getId())); + } + + @Override + public NicEntity get(NicEntity nic) { + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(nic.getVspId()); + ElementContext elementContext = new ElementContext(itemId, + VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor), + VspZusammenUtil.getVersionTag(nic.getVersion())); + Optional element = zusammenAdaptor.getElement(context, elementContext, nic.getId()); + + if (element.isPresent()) { + nic.setCompositionData(new String(FileUtils.toByteArray(element.get().getData()))); + return nic; + } else { + return null; + } + } + + @Override + public void delete(NicEntity nic) { + ZusammenElement nicElement = buildZusammenElement(new Id(nic.getId()), Action.DELETE); + + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(nic.getVspId()); + ElementContext elementContext = new ElementContext(itemId, + VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)); + zusammenAdaptor.saveElement(context, elementContext, nicElement, + String.format("Delete nic with id %s", nic.getId())); + } + + @Override + public NicEntity getQuestionnaireData(String vspId, Version version, String componentId, + String nicId) { + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(vspId); + ElementContext elementContext = new ElementContext(itemId, + VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor), + VspZusammenUtil.getVersionTag(version)); + + return getQuestionnaire(context, elementContext, + 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()), + StructureElement.Questionnaire.name()); + return questionnaireElement.map( + element -> element.getData() == null + ? null + : new String(FileUtils.toByteArray(element.getData()))) + .map(questionnaireData -> { + nic.setQuestionnaireData(questionnaireData); + return nic; + }) + .orElse(null); + } + + @Override + public void updateQuestionnaireData(String vspId, Version version, String componentId, + String nicId, String questionnaireData) { + ZusammenElement questionnaireElement = + nicQuestionnaireToZusammen(questionnaireData, Action.UPDATE); + + ZusammenElement nicElement = new ZusammenElement(); + nicElement.setAction(Action.IGNORE); + nicElement.setElementId(new Id(nicId)); + nicElement.setSubElements(Collections.singletonList(questionnaireElement)); + + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(vspId); + ElementContext elementContext = new ElementContext(itemId, + VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)); + zusammenAdaptor.saveElement(context, elementContext, nicElement, "Update nic questionnaire"); + } + + @Override + public Collection listByVsp(String vspId, Version version) { + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(vspId); + ElementContext elementContext = new ElementContext(itemId, + VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor), + VspZusammenUtil.getVersionTag(version)); + + Collection components = ComponentDaoZusammenImpl + .listComponents(zusammenAdaptor, context, elementContext, vspId, version); + + return components.stream() + .map(component -> + listNics(context, elementContext, + new NicEntity(vspId, version, component.getId(), null)).stream() + .map(nic -> getQuestionnaire(context, elementContext, nic)) + .collect(Collectors.toList())) + .flatMap(Collection::stream) + .collect(Collectors.toList()); + } + + @Override + public void deleteByComponentId(String vspId, Version version, String componentId) { + ZusammenElement componentElement = buildZusammenElement(new Id(componentId), Action.IGNORE); + componentElement.setSubElements(Collections.singletonList( + VspZusammenUtil.buildStructuralElement(StructureElement.Nics, Action.DELETE))); + + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(vspId); + ElementContext elementContext = new ElementContext(itemId, + VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)); + zusammenAdaptor.saveElement(context, elementContext, componentElement, + String.format("Delete all nics of component %s", componentId)); + } + + @Override + public void deleteByVspId(String vspId, Version version) { + + } + + 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 = + VspZusammenUtil.buildStructuralElement(StructureElement.Questionnaire, action); + questionnaireElement.setData(new ByteArrayInputStream(questionnaireData.getBytes())); + return questionnaireElement; + } + + private ZusammenElement buildZusammenElement(Id elementId, Action action) { + ZusammenElement element = new ZusammenElement(); + element.setElementId(elementId); + element.setAction(action); + return element; + } + + private ZusammenElement buildNicElement(NicEntity nic, Action action) { + ZusammenElement nicElement = new ZusammenElement(); + nicElement.setAction(action); + if (nic.getId() != null) { + nicElement.setElementId(new Id(nic.getId())); + } + Info info = new Info(); + info.addProperty(ElementPropertyName.type.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 new file mode 100644 index 0000000000..c101955292 --- /dev/null +++ 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 @@ -0,0 +1,134 @@ +package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen; + +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 com.amdocs.zusammen.utils.fileutils.FileUtils; +import org.openecomp.core.utilities.json.JsonUtil; +import org.openecomp.core.zusammen.api.ZusammenAdaptor; +import org.openecomp.core.zusammen.api.ZusammenUtil; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateCandidateDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData; +import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.FilesDataStructure; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.sdc.versioning.dao.types.VersionStatus; + +import java.io.ByteArrayInputStream; +import java.nio.ByteBuffer; +import java.util.Optional; + +public class OrchestrationTemplateCandidateDaoZusammenImpl + implements OrchestrationTemplateCandidateDao { + private static final Logger logger = + LoggerFactory.getLogger(OrchestrationTemplateCandidateDaoZusammenImpl.class); + + private ZusammenAdaptor zusammenAdaptor; + + public OrchestrationTemplateCandidateDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { + this.zusammenAdaptor = zusammenAdaptor; + } + + @Override + public void registerVersioning(String versionableEntityType) { + + } + + @Override + public OrchestrationTemplateCandidateData get(String vspId, Version version) { + logger.info("Getting orchestration template for vsp id -> " + vspId); + + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(vspId); + Id versionId = VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor); + ElementContext elementContext = new ElementContext(itemId, versionId, + VspZusammenUtil.getVersionTag(version)); + + Optional candidateElement = + zusammenAdaptor.getElementByName(context, elementContext, null, + StructureElement.OrchestrationTemplateCandidate.name()); + if (candidateElement.isPresent()) { + OrchestrationTemplateCandidateData candidateData = new OrchestrationTemplateCandidateData(); + candidateData.setFilesDataStructure( + new String(FileUtils.toByteArray(candidateElement.get().getData()))); + + zusammenAdaptor + .getElementByName(context, elementContext, candidateElement.get().getElementId(), + StructureElement.OrchestrationTemplateCandidateContent.name()) + .ifPresent(candidateContentElement -> candidateData.setContentData( + ByteBuffer.wrap(FileUtils.toByteArray(candidateContentElement.getData())))); + logger.info("Finished getting orchestration template for vsp id -> " + vspId); + return candidateData; + } + logger.info(String.format("Orchestration template for vsp id %s does not exist", vspId)); + return null; + } + + @Override + public void update(String vspId, OrchestrationTemplateCandidateData candidateData) { + logger.info("Uploading candidate data entity for vsp id -> " + vspId); + + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(vspId); + Id versionId = VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor); + ElementContext elementContext = new ElementContext(itemId, versionId); + + ZusammenElement candidateElement = VspZusammenUtil + .buildStructuralElement(StructureElement.OrchestrationTemplateCandidate, Action.UPDATE); + candidateElement + .setData(new ByteArrayInputStream(candidateData.getFilesDataStructure().getBytes())); + ZusammenElement candidateContentElement = VspZusammenUtil + .buildStructuralElement(StructureElement.OrchestrationTemplateCandidateContent, Action.UPDATE); + candidateContentElement + .setData(new ByteArrayInputStream(candidateData.getContentData().array())); + candidateElement.addSubElement(candidateContentElement); + + zusammenAdaptor.saveElement(context, elementContext, candidateElement, + "Update Orchestration Template Candidate"); + logger.info("Finished uploading candidate data entity for vsp id -> " + vspId); + } + + @Override + public void updateStructure(String vspId, Version version, FilesDataStructure fileDataStructure) { + logger.info("Updating orchestration template for VSP id -> " + vspId); + + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(vspId); + Id versionId = VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor); + ElementContext elementContext = new ElementContext(itemId, versionId); + + ZusammenElement candidateElement = VspZusammenUtil + .buildStructuralElement(StructureElement.OrchestrationTemplateCandidate, Action.UPDATE); + candidateElement + .setData(new ByteArrayInputStream(JsonUtil.object2Json(fileDataStructure).getBytes())); + 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 structure for vsp id -> " + vspId); + + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(vspId); + Id versionId = VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor); + ElementContext elementContext = new ElementContext(itemId, versionId, + VspZusammenUtil.getVersionTag(version)); + + logger.info("Finished getting orchestration template structure for vsp id -> " + vspId); + Optional element = zusammenAdaptor.getElementByName(context, elementContext, null, + StructureElement.OrchestrationTemplateCandidate.name()); + if (element.isPresent()) { + return Optional.of(new String(FileUtils.toByteArray(element.get().getData()))); + } else { + return Optional.empty(); + } + + } +} 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 new file mode 100644 index 0000000000..83a78bc705 --- /dev/null +++ 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 @@ -0,0 +1,111 @@ +package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen; + +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; +import com.amdocs.zusammen.datatypes.Id; +import com.amdocs.zusammen.datatypes.SessionContext; +import com.amdocs.zusammen.datatypes.item.ElementContext; +import com.amdocs.zusammen.utils.fileutils.FileUtils; +import org.openecomp.core.zusammen.api.ZusammenAdaptor; +import org.openecomp.core.zusammen.api.ZusammenUtil; +import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.UploadData; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.UploadDataEntity; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.sdc.versioning.dao.types.VersionStatus; + +import java.io.ByteArrayInputStream; +import java.nio.ByteBuffer; +import java.util.Optional; + +public class OrchestrationTemplateDaoZusammenImpl implements OrchestrationTemplateDao { + + private ZusammenAdaptor zusammenAdaptor; + + public OrchestrationTemplateDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { + this.zusammenAdaptor = zusammenAdaptor; + } + + @Override + public void registerVersioning(String versionableEntityType) { + + } + + @Override + public String getValidationData(String vspId, Version version) { + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(vspId); + ElementContext elementContext = new ElementContext(itemId, + VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor), + VspZusammenUtil.getVersionTag(version)); + + Optional elementInfo = zusammenAdaptor + .getElementInfoByName(context, elementContext, null, + StructureElement.OrchestrationTemplate.name()); + if (elementInfo.isPresent()) { + Optional element = + zusammenAdaptor.getElementByName(context, elementContext, elementInfo.get().getId(), + StructureElement.OrchestrationTemplateValidationData.name()); + if (element.isPresent()) { + return new String(FileUtils.toByteArray(element.get().getData())); + } + } + + return null; + } + + @Override + public UploadDataEntity getOrchestrationTemplate(String vspId, Version version) { + + UploadDataEntity uploadData = new UploadDataEntity(); + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(vspId); + ElementContext elementContext = new ElementContext(itemId, + VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor), + VspZusammenUtil.getVersionTag(version)); + + Optional elementInfo = zusammenAdaptor + .getElementInfoByName(context, elementContext, null, + StructureElement.OrchestrationTemplate.name()); + if (elementInfo.isPresent()) { + Optional element = + zusammenAdaptor.getElementByName(context, elementContext, elementInfo.get().getId(), + StructureElement.OrchestrationTemplateValidationData.name()); + element.ifPresent(element1 -> uploadData + .setValidationData(new String(FileUtils.toByteArray(element1.getData())))); + element = + zusammenAdaptor.getElementByName(context, elementContext, elementInfo.get().getId(), + StructureElement.OrchestrationTemplateContent.name()); + element.ifPresent(element1 -> uploadData + .setContentData(ByteBuffer.wrap(FileUtils.toByteArray(element1.getData())))); + } + return uploadData; + } + + @Override + public void updateOrchestrationTemplateData(String vspId, UploadData uploadData) { + ZusammenElement orchestrationTemplateElement = + VspZusammenUtil.buildStructuralElement(StructureElement.OrchestrationTemplate, null); + ZusammenElement orchestrationTemplateValidationDataElement = + VspZusammenUtil + .buildStructuralElement(StructureElement.OrchestrationTemplateValidationData, null); + orchestrationTemplateValidationDataElement.setData(new ByteArrayInputStream(uploadData + .getValidationData().getBytes())); + ZusammenElement orchestrationTemplateContent = + VspZusammenUtil.buildStructuralElement(StructureElement.OrchestrationTemplateContent, null); + orchestrationTemplateContent + .setData(new ByteArrayInputStream(uploadData.getContentData().array())); + orchestrationTemplateElement.addSubElement(orchestrationTemplateValidationDataElement); + orchestrationTemplateElement.addSubElement(orchestrationTemplateContent); + + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(vspId); + ElementContext elementContext = new ElementContext(itemId, + VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)); + + zusammenAdaptor.saveElement(context, elementContext, orchestrationTemplateElement, "Update " + + "Orchestration Template"); + } + +} 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 new file mode 100644 index 0000000000..ffc9cb2901 --- /dev/null +++ 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 @@ -0,0 +1,229 @@ +package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen; + +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; +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 com.amdocs.zusammen.datatypes.item.Info; +import org.openecomp.core.utilities.file.FileUtils; +import org.openecomp.core.zusammen.api.ZusammenAdaptor; +import org.openecomp.core.zusammen.api.ZusammenUtil; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessType; +import org.openecomp.sdc.versioning.dao.types.Version; + +import java.io.ByteArrayInputStream; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Objects; +import java.util.Optional; +import java.util.stream.Collectors; + +/** + * @author Avrahamg. + * @since March 23, 2017 + */ +public class ProcessDaoZusammenImpl implements ProcessDao { + + private static final String NAME = "name"; + private static final String ELEMENT_TYPE = "type"; + private static final String ARTIFACT_NAME = "artifactName"; + private static final String DESCRIPTION = "description"; + private static final String PROCESS_TYPE = "processType"; + + private ZusammenAdaptor zusammenAdaptor; + + public ProcessDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { + this.zusammenAdaptor = zusammenAdaptor; + } + + @Override + public void registerVersioning(String versionableEntityType) { + + } + + @Override + public void create(ProcessEntity processEntity) { + ZusammenElement processElement = buildProcessElement(processEntity, Action.CREATE); + + ZusammenElement processesElement = + VspZusammenUtil.buildStructuralElement(StructureElement.Processes, null); + ZusammenElement aggregatedElement = VspZusammenUtil.aggregateElements(processesElement, + processElement); + ZusammenElement componentElement; + if (processEntity.getComponentId() != null) { + componentElement = createParentElement(processEntity); + aggregatedElement = + VspZusammenUtil.aggregateElements(componentElement, aggregatedElement); + } + + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(processEntity.getVspId()); + ElementContext elementContext = new ElementContext(itemId, + VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)); + + Optional savedElement = + zusammenAdaptor.saveElement(context, elementContext, aggregatedElement, "Create process"); + savedElement.ifPresent(element -> { + if (processEntity.getComponentId() == null) { + processEntity.setId(element.getSubElements().iterator().next() + .getElementId().getValue()); + } else { + processEntity.setId(element.getSubElements().iterator().next() + .getSubElements().iterator().next().getElementId().getValue()); + } + }); + } + + @Override + public ProcessEntity get(ProcessEntity process) { + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(process.getVspId()); + ElementContext elementContext = new ElementContext(itemId, + VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor), + VspZusammenUtil.getVersionTag(process.getVersion())); + + Optional elementOptional = + zusammenAdaptor.getElement(context, elementContext, process.getId()); + + if (elementOptional.isPresent()) { + Element element = elementOptional.get(); + process.setName(element.getInfo().getProperty(NAME)); + process.setArtifactName(element.getInfo().getProperty(ARTIFACT_NAME)); + process.setDescription(element.getInfo().getProperty(DESCRIPTION)); + process.setType(element.getInfo().getProperty + (PROCESS_TYPE) != null ? ProcessType.valueOf(element.getInfo().getProperty + (PROCESS_TYPE)) : null); + + process.setArtifact(ByteBuffer.wrap(FileUtils.toByteArray(element.getData()))); + return process; + } else { + return null; + } + } + + @Override + public void update(ProcessEntity processEntity) { + ZusammenElement processElement = buildProcessElement(processEntity, Action.UPDATE); + + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(processEntity.getVspId()); + ElementContext elementContext = new ElementContext(itemId, + VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)); + + Optional element = + zusammenAdaptor.saveElement(context, elementContext, processElement, "Create process"); + System.out.println(element.get().getElementId()); + } + + @Override + public void delete(ProcessEntity processEntity) { + ZusammenElement processElement = new ZusammenElement(); + processElement.setElementId(new Id(processEntity.getId())); + processElement.setAction(Action.DELETE); + + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(processEntity.getVspId()); + ElementContext elementContext = new ElementContext(itemId, + VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)); + + zusammenAdaptor.saveElement(context, elementContext, processElement, + String.format("Delete process with id %s", processEntity.getId())); + } + + @Override + public void deleteAll(ProcessEntity processEntity) { + ZusammenElement aggregatedElement = + VspZusammenUtil.buildStructuralElement(StructureElement.Processes, Action.DELETE); + + if (processEntity.getComponentId() != null) { + ZusammenElement componentElement = createParentElement(processEntity); + aggregatedElement = VspZusammenUtil.aggregateElements(componentElement, + aggregatedElement); + } + + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(processEntity.getVspId()); + ElementContext elementContext = new ElementContext(itemId, + VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)); + zusammenAdaptor.saveElement(context, elementContext, aggregatedElement, "Delete All processes"); + } + + @Override + public void deleteVspAll(String vspId, Version version) { + ProcessEntity processEntity = new ProcessEntity(); + processEntity.setVersion(version); + processEntity.setVspId(vspId); + deleteAll(processEntity); + } + + @Override + public Collection list(ProcessEntity process) { + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(process.getVspId()); + ElementContext elementContext = new ElementContext(itemId, + VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor), + VspZusammenUtil.getVersionTag(process.getVersion())); + + Optional processesOptional = + zusammenAdaptor.getElementInfoByName(context, elementContext, + extractParentElementId(process), StructureElement.Processes.name()); + if (!processesOptional.isPresent()) { + return new ArrayList<>(); + } + return zusammenAdaptor.listElements(context, elementContext, processesOptional.get().getId()) + .stream() + .map(elementInfo -> mapElementInfoToProcess( + process.getVspId(), process.getVersion(), process.getComponentId(), + elementInfo)) + .collect(Collectors.toList()); + } + + private Id extractParentElementId(ProcessEntity processEntity) { + return processEntity.getComponentId() == null ? null : new Id(processEntity.getComponentId()); + } + + private ProcessEntity mapElementInfoToProcess(String vspId, Version version, + String componentId, + ElementInfo elementInfo) { + ProcessEntity processEntity = new ProcessEntity(vspId, version, componentId, elementInfo + .getId().getValue()); + processEntity.setName((String) elementInfo.getInfo().getProperties().get(NAME)); + processEntity + .setArtifactName((String) elementInfo.getInfo().getProperties().get(ARTIFACT_NAME)); + processEntity.setDescription((String) elementInfo.getInfo().getProperties().get(DESCRIPTION)); + return processEntity; + } + + private ZusammenElement buildProcessElement(ProcessEntity process, Action action) { + + Info info = new Info(); + info.setName(process.getName()); + info.addProperty(NAME, process.getName()); + info.addProperty(ELEMENT_TYPE, 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 = new ZusammenElement(); + processElement.setElementId(new Id(process.getId())); + processElement.setAction(action); + processElement.setInfo(info); + if (Objects.nonNull(process.getArtifact())) { + processElement.setData(new ByteArrayInputStream(process.getArtifact().array())); + } + return processElement; + } + + private ZusammenElement createParentElement(ProcessEntity entity) { + ZusammenElement componentElement = new ZusammenElement(); + componentElement.setElementId(new Id(entity.getComponentId())); + componentElement.setAction(Action.IGNORE); + 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/StructureElement.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/StructureElement.java new file mode 100644 index 0000000000..5d53741ebf --- /dev/null +++ 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/StructureElement.java @@ -0,0 +1,20 @@ +package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen; + +public enum StructureElement { + General, + OrchestrationTemplateCandidate, + OrchestrationTemplate, + OrchestrationTemplateValidationData, + OrchestrationTemplateContent, + OrchestrationTemplateCandidateValidationData, + OrchestrationTemplateCandidateContent, + Networks, + Components, + Nics, + Processes, + Mibs, + SNMP_TRAP, + SNMP_POLL, + Questionnaire, + ComponentDependencies, +} 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 new file mode 100644 index 0000000000..65a41330a7 --- /dev/null +++ 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 @@ -0,0 +1,228 @@ +package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen; + +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 com.amdocs.zusammen.datatypes.item.Info; +import com.amdocs.zusammen.datatypes.item.ItemVersion; +import com.amdocs.zusammen.utils.fileutils.FileUtils; +import org.openecomp.core.zusammen.api.ZusammenAdaptor; +import org.openecomp.core.zusammen.api.ZusammenUtil; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspQuestionnaireEntity; +import org.openecomp.sdc.versioning.VersioningManagerFactory; +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.Date; +import java.util.stream.Collectors; + +public class VendorSoftwareProductInfoDaoZusammenImpl implements VendorSoftwareProductInfoDao { + private ZusammenAdaptor zusammenAdaptor; + + public VendorSoftwareProductInfoDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { + this.zusammenAdaptor = zusammenAdaptor; + } + + @Override + public void registerVersioning(String versionableEntityType) { + VersionableEntityMetadata metadata = + new VersionableEntityMetadata(VersionableEntityStoreType.Zusammen, "vsp", null, null); + + VersioningManagerFactory.getInstance().createInterface() + .register(versionableEntityType, metadata); + } + + @Override + public Collection list(VspDetails entity) { + return zusammenAdaptor.listItems(ZusammenUtil.createSessionContext()).stream().filter + (vspEntity-> "vsp".equals(vspEntity.getInfo().getProperty("type"))) + .map(item -> mapInfoToVspDetails( + item.getId().getValue(), null, item.getInfo(), + item.getModificationTime(), item.getCreationTime())) + .collect(Collectors.toList()); + } + + @Override + public void create(VspDetails vspDetails) { + SessionContext context = ZusammenUtil.createSessionContext(); + + Id itemId = zusammenAdaptor.createItem(context, mapVspDetailsToZusammenItemInfo(vspDetails)); + Id versionId = + zusammenAdaptor.createVersion(context, itemId, null, ZusammenUtil.createFirstVersionData()); + + ZusammenElement generalElement = mapVspDetailsToZusammenElement(vspDetails, Action.CREATE); + zusammenAdaptor.saveElement(context, new ElementContext(itemId, versionId), + generalElement, "Create VSP General Info Element"); + + vspDetails.setId(itemId.getValue());//set id for caller + } + + @Override + public void update(VspDetails vspDetails) { + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(vspDetails.getId()); + Id versionId = VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor); + + zusammenAdaptor.updateItem(context, itemId, mapVspDetailsToZusammenItemInfo(vspDetails)); + + ZusammenElement generalElement = mapVspDetailsToZusammenElement(vspDetails, Action.UPDATE); + zusammenAdaptor.saveElement(context, new ElementContext(itemId, versionId), + generalElement, "Update VSP General Info Element"); + } + + @Override + public VspDetails get(VspDetails vspDetails) { + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(vspDetails.getId()); + ItemVersion itemVersion = VspZusammenUtil.getFirstVersion(context, itemId, zusammenAdaptor); + ElementContext elementContext = new ElementContext(itemId, itemVersion.getId(), + VspZusammenUtil.getVersionTag(vspDetails.getVersion())); + + return zusammenAdaptor + .getElementInfoByName(context, elementContext, null, StructureElement.General.name()) + .map(generalElementInfo -> mapInfoToVspDetails( + vspDetails.getId(), vspDetails.getVersion(), generalElementInfo.getInfo(), + itemVersion.getModificationTime(), itemVersion.getCreationTime())) + .orElse(null); + } + + + @Override + public void delete(VspDetails entity) { + + } + + @Override + public void updateOldVersionIndication(VspDetails vspDetails) { + VspDetails retrieved = get(vspDetails); + if (retrieved != null) { + retrieved.setOldVersion(vspDetails.getOldVersion()); + update(retrieved); + } + } + + @Override + public void updateQuestionnaireData(String vspId, Version version, String questionnaireData) { + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(vspId); + Id versionId = VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor); + + ZusammenElement questionnaireElement = mapQuestionnaireToZusammenElement(questionnaireData); + zusammenAdaptor.saveElement(context, new ElementContext(itemId, versionId), + questionnaireElement, "Update VSP Questionnaire"); + } + + + @Override + public String getQuestionnaireData(String vspId, Version version) { + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(vspId); + Id versionId = VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor); + + return zusammenAdaptor.getElementByName(context, + new ElementContext(itemId, versionId, VspZusammenUtil.getVersionTag(version)), null, + StructureElement.Questionnaire.name()) + .map(questionnaireElement -> + new String(FileUtils.toByteArray(questionnaireElement.getData()))) + .orElse(null); + } + + @Override + public VspQuestionnaireEntity getQuestionnaire(String vspId, Version version) { + VspQuestionnaireEntity entity = new VspQuestionnaireEntity(); + entity.setId(vspId); + entity.setVersion(version); + entity.setQuestionnaireData(getQuestionnaireData(vspId, version)); + return entity; + } + + @Override + public void deleteAll(String vspId, Version version) { + + } + + private Info mapVspDetailsToZusammenItemInfo(VspDetails vspDetails) { + Info info = new Info(); + info.setName(vspDetails.getName()); + info.setDescription(vspDetails.getDescription()); + info.addProperty("type", "vsp"); + addVspDetailsToInfo(info, vspDetails); + return info; + } + + private ZusammenElement mapVspDetailsToZusammenElement(VspDetails vspDetails, Action action) { + ZusammenElement generalElement = + VspZusammenUtil.buildStructuralElement(StructureElement.General, action); + addVspDetailsToInfo(generalElement.getInfo(), vspDetails); + return generalElement; + } + + private ZusammenElement mapQuestionnaireToZusammenElement(String questionnaireData) { + ZusammenElement questionnaireElement = + VspZusammenUtil.buildStructuralElement(StructureElement.Questionnaire, Action.UPDATE); + questionnaireElement.setData(new ByteArrayInputStream(questionnaireData.getBytes())); + return questionnaireElement; + } + + private void addVspDetailsToInfo(Info info, VspDetails vspDetails) { + info.addProperty(InfoPropertyName.name.name(), vspDetails.getName()); + info.addProperty(InfoPropertyName.description.name(), vspDetails.getDescription()); + info.addProperty(InfoPropertyName.icon.name(), vspDetails.getIcon()); + info.addProperty(InfoPropertyName.category.name(), vspDetails.getCategory()); + info.addProperty(InfoPropertyName.subCategory.name(), vspDetails.getSubCategory()); + info.addProperty(InfoPropertyName.vendorId.name(), vspDetails.getVendorId()); + info.addProperty(InfoPropertyName.vendorName.name(), vspDetails.getVendorName()); + if (vspDetails.getVlmVersion() != null) { + info.addProperty( + InfoPropertyName.vendorVersion.name(), vspDetails.getVlmVersion().toString()); + } + info.addProperty(InfoPropertyName.licenseAgreement.name(), vspDetails.getLicenseAgreement()); + info.addProperty(InfoPropertyName.featureGroups.name(), vspDetails.getFeatureGroups()); + info.addProperty(InfoPropertyName.oldVersion.name(), vspDetails.getOldVersion()); + } + + private VspDetails mapInfoToVspDetails(String vspId, Version version, Info info, + Date modificationTime, Date creationTime) { + VspDetails vspDetails = new VspDetails(vspId, version); + vspDetails.setName(info.getProperty(InfoPropertyName.name.name())); + vspDetails.setDescription(info.getProperty(InfoPropertyName.description.name())); + vspDetails.setCategory(info.getProperty(InfoPropertyName.category.name())); + vspDetails.setSubCategory(info.getProperty(InfoPropertyName.subCategory.name())); + vspDetails.setVendorId(info.getProperty(InfoPropertyName.vendorId.name())); + vspDetails.setVendorName(info.getProperty(InfoPropertyName.vendorName.name())); + vspDetails.setVlmVersion( + Version.valueOf(info.getProperty(InfoPropertyName.vendorVersion.name()))); + vspDetails.setLicenseAgreement(info.getProperty(InfoPropertyName.licenseAgreement.name())); + vspDetails.setFeatureGroups(info.getProperty(InfoPropertyName.featureGroups.name())); + vspDetails.setWritetimeMicroSeconds( + modificationTime == null ? creationTime.getTime() : modificationTime.getTime()); + vspDetails.setVersion(version); + String oldVersion = info.getProperty(InfoPropertyName.oldVersion.name()); + + //Boolean oldVersion = ind == null || "true".equals( ind.toLowerCase()); + vspDetails.setOldVersion(oldVersion); + return vspDetails; + } + + private enum InfoPropertyName { + name, + description, + icon, + category, + subCategory, + vendorId, + vendorName, + vendorVersion, + licenseAgreement, + featureGroups, + oldVersion + } + +} 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 new file mode 100644 index 0000000000..dde3603896 --- /dev/null +++ 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 @@ -0,0 +1,61 @@ +package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen; + +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.ItemVersion; +import org.openecomp.core.zusammen.api.ZusammenAdaptor; +import org.openecomp.core.zusammen.api.ZusammenUtil; +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.vendorsoftwareproduct.dao.errors.VendorSoftwareProductNotFoundErrorBuilder; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.sdc.versioning.dao.types.VersionStatus; + +import java.util.Objects; +import java.util.Optional; + +class VspZusammenUtil { + + static ItemVersion getFirstVersion(SessionContext context, Id itemId, ZusammenAdaptor + zusammenAdaptor) { + + Optional itemVersion = zusammenAdaptor.getFirstVersion(context, itemId); + + if (!itemVersion.isPresent()) { + throw new CoreException( + new VendorSoftwareProductNotFoundErrorBuilder(itemId.getValue()).build()); + } + return itemVersion.get(); + } + + static Id getFirstVersionId(SessionContext context, Id itemId, ZusammenAdaptor zusammenAdaptor) { + return getFirstVersion(context, itemId, zusammenAdaptor).getId(); + } + + // TODO: 4/25/2017 remove upon working with more than one single version + static String getVersionTag(Version version) { + return version.getStatus() == VersionStatus.Locked + ? null + : version.toString(); + } + + static ZusammenElement buildStructuralElement(StructureElement structureElement, Action action) { + return ZusammenUtil.buildStructuralElement(structureElement.name(), action); + } + + static ZusammenElement aggregateElements(ZusammenElement... elements) { + ZusammenElement head = null; + ZusammenElement father = null; + for (ZusammenElement element : elements) { + if (Objects.isNull(head)) { + head = father = element; + } else { + father.getSubElements().add(element); + father = element; + } + } + + return head; + } +} 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 new file mode 100644 index 0000000000..2a50f33349 --- /dev/null +++ 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 @@ -0,0 +1,62 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.errors; + +/** + * Created by TALIO on 4/24/2016. + */ +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 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 MIB_UPLOAD_INVALID = "MIB_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"; + +} 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 new file mode 100644 index 0000000000..df5e44122d --- /dev/null +++ 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 @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * 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(); + } +} 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 new file mode 100644 index 0000000000..5c569dbf08 --- /dev/null +++ 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 @@ -0,0 +1,35 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.factory; + + +import org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.InformationArtifactGenerator; +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(); + } +} 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 new file mode 100644 index 0000000000..b98605a53d --- /dev/null +++ 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 @@ -0,0 +1,37 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.factory.impl; + +import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.OrchestrationTemplateCandidateDaoFactoryImpl; +import org.openecomp.sdc.vendorsoftwareproduct.factory.CandidateServiceFactory; +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()); + } +} 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 new file mode 100644 index 0000000000..21b0d9c0a8 --- /dev/null +++ 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 @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.factory.impl; + +import org.openecomp.sdc.vendorsoftwareproduct.factory.CompositionDataExtractorFactory; +import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionDataExtractor; +import org.openecomp.sdc.vendorsoftwareproduct.services.impl.composition.CompositionDataExtractorImpl; + +public class CompositionDataExtractorFactoryImpl extends CompositionDataExtractorFactory { + + @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/CompositionEntityDataManagerFactoryImpl.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/CompositionEntityDataManagerFactoryImpl.java new file mode 100644 index 0000000000..54d67e60fe --- /dev/null +++ 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/CompositionEntityDataManagerFactoryImpl.java @@ -0,0 +1,41 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.factory.impl; + +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.NetworkDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.factory.CompositionEntityDataManagerFactory; +import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; +import org.openecomp.sdc.vendorsoftwareproduct.services.impl.composition.CompositionEntityDataManagerImpl; + +public class CompositionEntityDataManagerFactoryImpl extends CompositionEntityDataManagerFactory { + + @Override + public CompositionEntityDataManager createInterface() { + return new CompositionEntityDataManagerImpl( + VendorSoftwareProductInfoDaoFactory.getInstance().createInterface(), + ComponentDaoFactory.getInstance().createInterface(), + NicDaoFactory.getInstance().createInterface(), + NetworkDaoFactory.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/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 new file mode 100644 index 0000000000..c7d088408e --- /dev/null +++ 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 @@ -0,0 +1,36 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.factory.impl; + +import org.openecomp.sdc.vendorsoftwareproduct.factory.ManifestCreatorFactory; +import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.ManifestCreator; +import org.openecomp.sdc.vendorsoftwareproduct.services.impl.filedatastructuremodule.ManifestCreatorNamingConventionImpl; + +/** + * Created by Talio on 12/15/2016. + */ +public class ManifestCreatorFactoryImpl extends ManifestCreatorFactory { + + @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 new file mode 100644 index 0000000000..f99d3814e6 --- /dev/null +++ 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 @@ -0,0 +1,105 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * 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 HEADER = "AT&T Proprietary (Restricted)\n" + + "Only for use by authorized individuals or any above-designated team(s)\n" + + "within the AT&T companies and not for general distribution" + NL + NL + NL; + + public static final String FOOTER = NL + NL + NL + "AT&T Proprietary (Restricted)\n" + + "Only for use by authorized individuals or any above-designated team(s)\n" + + "within the AT&T companies and not for general distribution"; + + + 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 new file mode 100644 index 0000000000..d15014286f --- /dev/null +++ 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 @@ -0,0 +1,304 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl; + +import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.factory.QuestionnnaireDataServiceFactory; +import org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.InformationArtifactData; +import org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.InformationArtifactGenerator; +import org.openecomp.sdc.vendorsoftwareproduct.questionnaire.QuestionnaireDataService; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.ComponentQuestionnaire; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.compute.Compute; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.compute.GuestOS; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.compute.NumOfVMs; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.general.Hypervisor; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.general.Recovery; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.nic.IpConfiguration; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.nic.Network; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.nic.NicQuestionnaire; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.vsp.VspQuestionnaire; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.vsp.general.Availability; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.vsp.general.General; +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; + private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); + + @Override + public String generate(String vspId, Version version) { + InformationArtifactData informationArtifactData = + questionnaireDataService.generateQuestionnaireDataForInformationArtifact(vspId, version); + return createTxtArtifact(informationArtifactData); + } + + private String createTxtArtifact(InformationArtifactData informationArtifactData) { + + + mdcDataDebugMessage.debugEntryMessage(null); + + textArtifact = new StringBuilder(TxtInformationArtifactConstants.HEADER); + 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); + } + textArtifact.append(TxtInformationArtifactConstants.FOOTER); + + mdcDataDebugMessage.debugExitMessage(null); + return textArtifact.toString(); + + } + + private void addDataEntries(InformationArtifactData informationArtifactData) { + + + mdcDataDebugMessage.debugEntryMessage(null); + + 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)); + + mdcDataDebugMessage.debugExitMessage(null); + } + + private void addAvailabilityEntries() { + mdcDataDebugMessage.debugEntryMessage(null); + + 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)); + + mdcDataDebugMessage.debugExitMessage(null); + } + + private void addVspVlmEntries(InformationArtifactData informationArtifactData) { + mdcDataDebugMessage.debugEntryMessage(null); + + 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)); + + mdcDataDebugMessage.debugExitMessage(null); + } + + static String roundVersionAsNeeded(Version version) { + if (version.isFinal()) { + return version.toString(); + } else { + return String.valueOf(Math.ceil(Double.valueOf(version.toString()))); + } + } + + private void addRecoveryEntriesPerComponent(ComponentQuestionnaire componentQuestionnaire) { + + mdcDataDebugMessage.debugEntryMessage(null); + + 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)); + + mdcDataDebugMessage.debugExitMessage(null); + } + + private void addEntriesPerNic(NicQuestionnaire nicQuestionnaire) { + + + mdcDataDebugMessage.debugEntryMessage(null); + + 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().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)); + + mdcDataDebugMessage.debugExitMessage(null); + } + + private void addEntriesPerComponent(ComponentQuestionnaire componentQuestionnaire) { + + + mdcDataDebugMessage.debugEntryMessage(null); + + 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)); + + + mdcDataDebugMessage.debugExitMessage(null); + } + + 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); + } +} 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 new file mode 100644 index 0000000000..76d8210ca5 --- /dev/null +++ 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 @@ -0,0 +1,113 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.quiestionnaire; + + +import org.openecomp.core.utilities.json.JsonUtil; +import org.openecomp.sdc.common.utils.CommonUtil; +import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.*; +import org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.InformationArtifactData; +import org.openecomp.sdc.vendorsoftwareproduct.questionnaire.QuestionnaireDataService; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.ComponentQuestionnaire; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.nic.NicQuestionnaire; +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 VendorSoftwareProductDao vendorSoftwareProductDao = + VendorSoftwareProductDaoFactory.getInstance().createInterface(); + private static final VendorSoftwareProductInfoDao vspInfoDao = + VendorSoftwareProductInfoDaoFactory.getInstance().createInterface(); + private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); + + + public InformationArtifactData generateQuestionnaireDataForInformationArtifact(String vspId, + Version version) { + + + mdcDataDebugMessage.debugEntryMessage("VSP Id", vspId); + + VspDetails vspDetails = + vspInfoDao.get(new VspDetails(vspId, version)); + Collection componentEntities = + vendorSoftwareProductDao.listComponentsQuestionnaire(vspId, version); + Collection nicEntities = vendorSoftwareProductDao.listNicsByVsp(vspId, version); + + VspQuestionnaire vspQuestionnaire = getVspQuestionnaireFromJson(vspId, version); + List componentQuestionnaireList = + getListOfComponentQuestionnaireFromJson(componentEntities); + List nicQuestionnaireList = getListOfNicQuestionnaireFromJson(nicEntities); + + mdcDataDebugMessage.debugExitMessage("VSP Id", vspId); + 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; + } + + 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)); + } + + return componentQuestionnaireList; + } + + + 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/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 new file mode 100644 index 0000000000..d72a0dbe23 --- /dev/null +++ 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 @@ -0,0 +1,470 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.services.impl.composition; + +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.MapUtils; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.datatypes.error.ErrorLevel; +import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage; +import org.openecomp.sdc.logging.context.impl.MdcDataErrorMessage; +import org.openecomp.sdc.logging.types.LoggerConstants; +import org.openecomp.sdc.logging.types.LoggerErrorCode; +import org.openecomp.sdc.logging.types.LoggerErrorDescription; +import org.openecomp.sdc.logging.types.LoggerTragetServiceName; +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.datatypes.model.NodeTemplate; +import org.openecomp.sdc.tosca.datatypes.model.ParameterDefinition; +import org.openecomp.sdc.tosca.datatypes.model.RequirementAssignment; +import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate; +import org.openecomp.sdc.tosca.errors.ToscaInvalidEntryNotFoundErrorBuilder; +import org.openecomp.sdc.tosca.errors.ToscaInvalidSubstituteNodeTemplateErrorBuilder; +import org.openecomp.sdc.tosca.errors.ToscaMissingSubstitutionMappingForReqCapErrorBuilder; +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.tosca.services.yamlutil.ToscaExtensionYamlUtil; +import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionDataExtractor; +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.ExtractCompositionDataContext; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Network; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +public class CompositionDataExtractorImpl implements CompositionDataExtractor { + + protected static Logger logger; + private static ToscaAnalyzerService toscaAnalyzerService; + private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); + + static { + logger = LoggerFactory.getLogger(CompositionDataExtractorImpl.class); + toscaAnalyzerService = new ToscaAnalyzerServiceImpl(); + } + + /** + * Extract service composition data composition data. + * + * @param toscaServiceModel the tosca service model + * @return the composition data + */ + public CompositionData extractServiceCompositionData(ToscaServiceModel toscaServiceModel) { + + + mdcDataDebugMessage.debugEntryMessage(null); + + 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()); + + mdcDataDebugMessage.debugExitMessage(null); + return compositionData; + } + + 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); + } + + private void handleSubstitution(ServiceTemplate serviceTemplate, + ToscaServiceModel toscaServiceModel, + ExtractCompositionDataContext context) { + + + mdcDataDebugMessage.debugEntryMessage(null); + + Map substitutableNodeTemplates = + toscaAnalyzerService.getSubstitutableNodeTemplates(serviceTemplate); + + if (substitutableNodeTemplates != null) { + for (String substitutableNodeTemplateId : substitutableNodeTemplates.keySet()) { + handleSubstitutableNodeTemplate(serviceTemplate, toscaServiceModel, + substitutableNodeTemplateId, + substitutableNodeTemplates.get(substitutableNodeTemplateId), context); + } + } + + mdcDataDebugMessage.debugExitMessage(null); + } + + private void handleSubstitutableNodeTemplate(ServiceTemplate serviceTemplate, + ToscaServiceModel toscaServiceModel, + String substitutableNodeTemplateId, + NodeTemplate substitutableNodeTemplate, + ExtractCompositionDataContext context) { + + + mdcDataDebugMessage.debugEntryMessage(null); + + ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil(); + Optional substituteServiceTemplateFileName = toscaAnalyzerService + .getSubstituteServiceTemplateName(substitutableNodeTemplateId, substitutableNodeTemplate); + if (!substituteServiceTemplateFileName.isPresent()) { + MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_API, + LoggerTragetServiceName.EXTRACT_COMPOSITION_DATA, ErrorLevel.ERROR.name(), + LoggerErrorCode.DATA_ERROR.getErrorCode(), + LoggerErrorDescription.EXTRACT_COMPOSITION_DATA); + 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 + mdcDataDebugMessage.debugExitMessage(null); + return; + } + + ServiceTemplate substituteServiceTemplate = + toscaServiceModel.getServiceTemplates().get(substituteServiceTemplateFileName.get()); + extractServiceCompositionData(substituteServiceTemplateFileName.get(), + substituteServiceTemplate, toscaServiceModel, context); + + List> substitutableRequirements = + substitutableNodeTemplate.getRequirements(); + + if (CollectionUtils.isEmpty(substitutableRequirements)) { + mdcDataDebugMessage.debugExitMessage(null); + return; + } + + for (Map substitutableReq : substitutableRequirements) { + substitutableReq.keySet().stream().filter(reqId -> { + RequirementAssignment reqAssignment = toscaExtensionYamlUtil + .yamlToObject(toscaExtensionYamlUtil.objectToYaml(substitutableReq.get(reqId)), + RequirementAssignment.class); + + mdcDataDebugMessage.debugExitMessage(null); + 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()) { + MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_API, + LoggerTragetServiceName.EXTRACT_COMPOSITION_DATA, ErrorLevel.ERROR.name(), + LoggerErrorCode.DATA_ERROR.getErrorCode(), + LoggerErrorDescription.EXTRACT_COMPOSITION_DATA); + 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()) { + MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_API, + LoggerTragetServiceName.EXTRACT_COMPOSITION_DATA, ErrorLevel.ERROR.name(), + LoggerErrorCode.DATA_ERROR.getErrorCode(), + LoggerErrorDescription.EXTRACT_COMPOSITION_DATA); + 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) { + + + mdcDataDebugMessage.debugEntryMessage(null); + + List linkRequirementsToNetwork = + toscaAnalyzerService.getRequirements(portNodeTemplate, ToscaConstants.LINK_REQUIREMENT_ID); + + //port is connected to one network + for (RequirementAssignment linkRequirementToNetwork : linkRequirementsToNetwork) { + port.setNetworkName(linkRequirementToNetwork.getNode()); + } + + mdcDataDebugMessage.debugExitMessage(null); + } + + /* + return Map with key - compute node template id, value - list of connected port node template id + */ + private Map> getComputeToPortsConnection( + Map portNodeTemplates) { + + + mdcDataDebugMessage.debugEntryMessage(null); + + Map> computeToPortConnection = new HashMap<>(); + if (MapUtils.isEmpty(portNodeTemplates)) { + return computeToPortConnection; + } + 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); + } + } + + mdcDataDebugMessage.debugExitMessage(null); + return computeToPortConnection; + } + + private void extractComponents(ServiceTemplate serviceTemplate, + ToscaServiceModel toscaServiceModel, + ExtractCompositionDataContext context) { + + + mdcDataDebugMessage.debugEntryMessage(null); + + Map computeNodeTemplates = toscaAnalyzerService + .getNodeTemplatesByType(serviceTemplate, ToscaNodeType.NATIVE_COMPUTE, + toscaServiceModel); + if (MapUtils.isEmpty(computeNodeTemplates)) { + return; + } + 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, nodeType, context)); + + mdcDataDebugMessage.debugExitMessage(null); + } + + private void extractComponent(ServiceTemplate serviceTemplate, + Map> computeToPortsConnection, + Map> computesGroupedByType, + String computeNodeType, + ExtractCompositionDataContext context) { + ComponentData component = new ComponentData(); + component.setName(computeNodeType); + component.setDisplayName(getComponentDisplayName(component.getName())); + component.setVfcCode(component.getDisplayName()); + Component componentModel = new Component(); + componentModel.setData(component); + + String computeId = computesGroupedByType.get(computeNodeType).get(0); + List connectedPortIds = computeToPortsConnection.get(computeId); + + if (connectedPortIds != null) { + componentModel.setNics(new ArrayList<>()); + for (String portId : connectedPortIds) { + Nic port = extractPort(serviceTemplate, portId); + componentModel.getNics().add(port); + context.addNic(portId, port); + } + } + 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 { + MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_API, + LoggerTragetServiceName.EXTRACT_COMPOSITION_DATA, ErrorLevel.ERROR.name(), + LoggerErrorCode.DATA_ERROR.getErrorCode(), + LoggerErrorDescription.EXTRACT_COMPOSITION_DATA); + throw new CoreException( + new ToscaInvalidEntryNotFoundErrorBuilder("Node Template", portNodeTemplateId).build()); + } + } + + + private Map> getNodeTemplatesGroupedByType( + Map nodeTemplates) { + + + mdcDataDebugMessage.debugEntryMessage(null); + + 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); + } + + mdcDataDebugMessage.debugExitMessage(null); + return nodeTemplatesGrouped; + } + + private List extractNetworks(ServiceTemplate serviceTemplate, + ToscaServiceModel toscaServiceModel) { + + + mdcDataDebugMessage.debugEntryMessage(null); + + List networks = new ArrayList<>(); + Map networkNodeTemplates = toscaAnalyzerService + .getNodeTemplatesByType(serviceTemplate, ToscaNodeType.NATIVE_NETWORK, + toscaServiceModel); + if (MapUtils.isEmpty(networkNodeTemplates)) { + mdcDataDebugMessage.debugExitMessage(null); + return networks; + } + for (String networkId : networkNodeTemplates.keySet()) { + Network network = new Network(); + network.setName(networkId); + Optional networkDhcpValue = + getNetworkDhcpValue(serviceTemplate, networkNodeTemplates.get(networkId)); + network.setDhcp(networkDhcpValue.isPresent() ? networkDhcpValue.get() : true); + networks.add(network); + } + + mdcDataDebugMessage.debugExitMessage(null); + return networks; + } + + //dhcp default value is true + private Optional getNetworkDhcpValue(ServiceTemplate serviceTemplate, + NodeTemplate networkNodeTemplate) { + + + mdcDataDebugMessage.debugEntryMessage(null); + + if (networkNodeTemplate == null) { + return Optional.empty(); + } + if (networkNodeTemplate.getProperties() == null + || networkNodeTemplate.getProperties().get(ToscaConstants.DHCP_ENABLED_PROPERTY_NAME) + == null) { + mdcDataDebugMessage.debugExitMessage(null); + return Optional.of(true); + } + + Object dhcp = + networkNodeTemplate.getProperties().get(ToscaConstants.DHCP_ENABLED_PROPERTY_NAME); + if (dhcp instanceof String) { + mdcDataDebugMessage.debugExitMessage(null); + return Optional.of(Boolean.valueOf((String) dhcp)); + } else if (dhcp instanceof Boolean) { + mdcDataDebugMessage.debugExitMessage(null); + return Optional.of((Boolean) dhcp); + } else if (dhcp instanceof Map) { + String inputParameterName = + (String) ((Map) dhcp).get(ToscaFunctions.GET_INPUT.getDisplayName()); + if (inputParameterName != null) { + ParameterDefinition inputParameterDefinition = + serviceTemplate.getTopology_template().getInputs().get(inputParameterName); + if (inputParameterDefinition != null) { + if (inputParameterDefinition.get_default() != null) { + mdcDataDebugMessage.debugExitMessage(null); + return Optional.of(Boolean.valueOf(inputParameterDefinition.get_default().toString())); + } + } else { + MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_API, + LoggerTragetServiceName.EXTRACT_COMPOSITION_DATA, ErrorLevel.ERROR.name(), + LoggerErrorCode.DATA_ERROR.getErrorCode(), + LoggerErrorDescription.EXTRACT_COMPOSITION_DATA); + throw new CoreException( + new ToscaInvalidEntryNotFoundErrorBuilder("Input Parameter", inputParameterName) + .build()); + } + } + } + + mdcDataDebugMessage.debugExitMessage(null); + 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/composition/CompositionEntityDataManagerImpl.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/CompositionEntityDataManagerImpl.java new file mode 100644 index 0000000000..81cacf75ac --- /dev/null +++ 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/CompositionEntityDataManagerImpl.java @@ -0,0 +1,585 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.services.impl.composition; + +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.MapUtils; +import org.openecomp.core.utilities.json.JsonSchemaDataGenerator; +import org.openecomp.core.utilities.json.JsonUtil; +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.common.errors.ErrorCategory; +import org.openecomp.sdc.common.errors.ErrorCode; +import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.NetworkDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.CompositionEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity; +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.services.composition.CompositionEntityDataManager; +import org.openecomp.sdc.vendorsoftwareproduct.services.schemagenerator.SchemaGenerator; +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.CompositionEntityId; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityValidationData; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Network; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic; +import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.SchemaTemplateContext; +import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.SchemaTemplateInput; +import org.openecomp.sdc.versioning.dao.types.Version; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; + +public class CompositionEntityDataManagerImpl implements CompositionEntityDataManager { + + private static final String COMPOSITION_ENTITY_DATA_MANAGER_ERR = + "COMPOSITION_ENTITY_DATA_MANAGER_ERR"; + private static final String COMPOSITION_ENTITY_DATA_MANAGER_ERR_MSG = + "Invalid input: %s may not be null"; + + private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); + + private Map entities = new HashMap<>(); + private Map nonDynamicSchemas = new HashMap<>(); + private List roots = new ArrayList<>(); + + private VendorSoftwareProductInfoDao vspInfoDao; + private ComponentDao componentDao; + private NicDao nicDao; + private NetworkDao networkDao; + + public CompositionEntityDataManagerImpl(VendorSoftwareProductInfoDao vspInfoDao, + ComponentDao componentDao, + NicDao nicDao, NetworkDao networkDao) { + this.vspInfoDao = vspInfoDao; + this.componentDao = componentDao; + this.nicDao = nicDao; + this.networkDao = networkDao; + } + + /** + * Validate entity composition entity validation data. + * + * @param entity the entity + * @param schemaTemplateContext the schema template context + * @param schemaTemplateInput the schema template input + * @return the composition entity validation data + */ + @Override + public CompositionEntityValidationData validateEntity(CompositionEntity entity, + SchemaTemplateContext schemaTemplateContext, + SchemaTemplateInput schemaTemplateInput) { + mdcDataDebugMessage.debugEntryMessage(null); + + if (entity == null) { + throw new CoreException( + new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION) + .withId(COMPOSITION_ENTITY_DATA_MANAGER_ERR).withMessage( + String.format(COMPOSITION_ENTITY_DATA_MANAGER_ERR_MSG, "composition entity")) + .build()); + } + if (schemaTemplateContext == null) { + throw new CoreException( + new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION) + .withId(COMPOSITION_ENTITY_DATA_MANAGER_ERR).withMessage( + String.format(COMPOSITION_ENTITY_DATA_MANAGER_ERR_MSG, "schema template context")) + .build()); + } + + CompositionEntityValidationData validationData = + new CompositionEntityValidationData(entity.getType(), entity.getId()); + String json = + schemaTemplateContext == SchemaTemplateContext.composition ? entity.getCompositionData() + : entity.getQuestionnaireData(); + validationData.setErrors(JsonUtil.validate( + json == null ? JsonUtil.object2Json(new Object()) : json, + generateSchema(schemaTemplateContext, entity.getType(), schemaTemplateInput))); + + mdcDataDebugMessage.debugExitMessage(null); + return validationData; + } + + /** + * Add entity. + * + * @param entity the entity + * @param schemaTemplateInput the schema template input + */ + @Override + public void addEntity(CompositionEntity entity, SchemaTemplateInput schemaTemplateInput) { + if (entity == null) { + throw new CoreException( + new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION) + .withId(COMPOSITION_ENTITY_DATA_MANAGER_ERR).withMessage( + String.format(COMPOSITION_ENTITY_DATA_MANAGER_ERR_MSG, "composition entity")) + .build()); + } + entities.put(entity.getCompositionEntityId(), + new CompositionEntityData(entity, schemaTemplateInput)); + } + + /** + * Validate entities questionnaire map. + * + * @return the map + */ + @Override + public Map> validateEntitiesQuestionnaire() { + mdcDataDebugMessage.debugEntryMessage(null); + + Map> errorsByEntityId = new HashMap<>(); + entities.entrySet().forEach(entry -> { + Collection errors = validateQuestionnaire(entry.getValue()); + if (errors != null) { + errorsByEntityId.put(entry.getKey(), errors); + } + }); + + mdcDataDebugMessage.debugExitMessage(null); + return errorsByEntityId; + } + + /** + * Build trees. + */ + @Override + public void buildTrees() { + Map entitiesValidationData = + new HashMap<>(); + entities.entrySet().forEach( + entry -> addValidationDataEntity(entitiesValidationData, entry.getKey(), + entry.getValue().entity)); + } + + public Collection getTrees() { + return roots; + } + + @Override + public void saveCompositionData(String vspId, Version version, CompositionData compositionData) { + mdcDataDebugMessage.debugEntryMessage(null); + + if (Objects.isNull(compositionData)) { + return; + } + + Map networkIdByName = saveNetworks(vspId, version, compositionData); + saveComponents(vspId, version, compositionData, networkIdByName); + + mdcDataDebugMessage.debugExitMessage(null); + } + + @Override + public Set getAllErrorsByVsp(String vspId) { + CompositionEntityValidationData matchVsp = null; + Set entitiesWithErrors = new HashSet<>(); + for (CompositionEntityValidationData root : roots) { + if (root.getEntityId().equals(vspId)) { + matchVsp = root; + break; + } + } + + getEntityListWithErrors(matchVsp, entitiesWithErrors); + if (CollectionUtils.isNotEmpty(entitiesWithErrors)) { + updateValidationCompositionEntityName(entitiesWithErrors); + return entitiesWithErrors; + } + + return null; + } + + private boolean isThereErrorsInSubTree(CompositionEntityValidationData entity) { + if (Objects.isNull(entity)) { + return false; + } + + if (CollectionUtils.isNotEmpty(entity.getErrors())) { + return true; + } + + Collection subEntitiesValidationData = + entity.getSubEntitiesValidationData(); + return !CollectionUtils.isEmpty(subEntitiesValidationData) && + checkForErrorsInChildren(subEntitiesValidationData); + + } + + private boolean checkForErrorsInChildren( + Collection subEntitiesValidationData) { + boolean result = false; + for (CompositionEntityValidationData subEntity : subEntitiesValidationData) { + if (CollectionUtils.isNotEmpty(subEntity.getErrors())) { + return true; + } + + result = result || isThereErrorsInSubTree(subEntity); + if (result) { + return true; + } + } + return false; + } + + public void saveComponents(String vspId, Version version, CompositionData compositionData, + Map networkIdByName) { + + + mdcDataDebugMessage.debugEntryMessage(null); + + if (CollectionUtils.isNotEmpty(compositionData.getComponents())) { + for (Component component : compositionData.getComponents()) { + ComponentEntity componentEntity = new ComponentEntity(vspId, version, null); + componentEntity.setComponentCompositionData(component.getData()); + + String componentId = createComponent(componentEntity).getId(); + + saveNicsByComponent(vspId, version, networkIdByName, component, componentId); + } + } + + mdcDataDebugMessage.debugExitMessage(null); + } + + public void saveNicsByComponent(String vspId, Version version, + Map networkIdByName, Component component, + String componentId) { + if (CollectionUtils.isNotEmpty(component.getNics())) { + for (Nic nic : component.getNics()) { + if (nic.getNetworkName() != null && MapUtils.isNotEmpty(networkIdByName)) { + nic.setNetworkId(networkIdByName.get(nic.getNetworkName())); + } + nic.setNetworkName(null); + + NicEntity nicEntity = new NicEntity(vspId, version, componentId, null); + nicEntity.setNicCompositionData(nic); + createNic(nicEntity); + } + } + } + + public Map saveNetworks(String vspId, Version version, + CompositionData compositionData) { + mdcDataDebugMessage.debugEntryMessage(null); + + Map networkIdByName = new HashMap<>(); + if (CollectionUtils.isNotEmpty(compositionData.getNetworks())) { + for (Network network : compositionData.getNetworks()) { + + NetworkEntity networkEntity = new NetworkEntity(vspId, version, null); + networkEntity.setNetworkCompositionData(network); + + if (network.getName() != null) { + networkIdByName.put(network.getName(), createNetwork(networkEntity).getId()); + } + } + } + + mdcDataDebugMessage.debugExitMessage(null); + return networkIdByName; + } + + @Override + public NetworkEntity createNetwork(NetworkEntity network) { + mdcDataDebugMessage.debugEntryMessage(null); + + //network.setId(CommonMethods.nextUuId()); will be set by the dao + networkDao.create(network); + mdcDataDebugMessage.debugExitMessage(null); + return network; + } + + @Override + public ComponentEntity createComponent(ComponentEntity component) { + mdcDataDebugMessage.debugEntryMessage(null); + + //component.setId(CommonMethods.nextUuId()); will be set by the dao + component.setQuestionnaireData( + new JsonSchemaDataGenerator( + generateSchema(SchemaTemplateContext.questionnaire, CompositionEntityType.component, + null)) + .generateData()); + + componentDao.create(component); + + mdcDataDebugMessage.debugExitMessage(null); + return component; + } + + @Override + public NicEntity createNic(NicEntity nic) { + mdcDataDebugMessage.debugEntryMessage(null); + + //nic.setId(CommonMethods.nextUuId()); will be set by the dao + nic.setQuestionnaireData( + new JsonSchemaDataGenerator( + generateSchema(SchemaTemplateContext.questionnaire, CompositionEntityType.nic, null)) + .generateData()); + + nicDao.create(nic); + + mdcDataDebugMessage.debugExitMessage(null); + return nic; + } + + + public void addErrorsToTrees(Map> errors) { + roots.forEach(root -> addErrorsToTree(root, null, errors)); + } + + /* * + * get a flat list of all questionnaire entities that have validation errors + * */ + public Set getEntityListWithErrors() { + mdcDataDebugMessage.debugEntryMessage(null); + Set treeAsList = new HashSet<>(); + + for (CompositionEntityValidationData entity : roots) { + if (CollectionUtils.isNotEmpty(entity.getErrors())) { + addNodeWithErrors(entity, treeAsList); + } + getEntityListWithErrors(entity, treeAsList); + } + + updateValidationCompositionEntityName(treeAsList); + + mdcDataDebugMessage.debugExitMessage(null); + return treeAsList; + } + + public void getEntityListWithErrors(CompositionEntityValidationData entity, + Set compositionSet) { + Collection childNodes = + entity.getSubEntitiesValidationData(); + + if (CollectionUtils.isEmpty(childNodes)) { + return; + } + + for (CompositionEntityValidationData child : childNodes) { + if (CollectionUtils.isNotEmpty(child.getErrors())) { + addNodeWithErrors(child, compositionSet); + } + getEntityListWithErrors(child, compositionSet); + } + } + + + public void addNodeWithErrors(CompositionEntityValidationData node, + Set entitiesWithErrors) { + CompositionEntityValidationData compositionNodeToAdd = new CompositionEntityValidationData(node + .getEntityType(), node.getEntityId()); + compositionNodeToAdd.setErrors(node.getErrors()); + compositionNodeToAdd.setSubEntitiesValidationData(null); + + entitiesWithErrors.add(compositionNodeToAdd); + } + + public void removeNodesWithoutErrors() { + roots.forEach(root -> removeNodesWithoutErrors(root, null)); + } + + + private CompositionEntityData getCompositionEntityDataById(CompositionEntityValidationData + entity) { + for (Map.Entry entityEntry : entities + .entrySet()) { + if (entityEntry.getKey().getId().equals(entity.getEntityId())) { + return entityEntry.getValue(); + } + } + return null; + } + + + private void updateValidationCompositionEntityName(Set + compositionSet) { + for (CompositionEntityValidationData entity : compositionSet) { + String compositionData = getCompositionDataAsString(entity); + if (entity.getEntityType().equals(CompositionEntityType.vsp) || + Objects.nonNull(compositionData)) { + entity.setEntityName(getEntityNameByEntityType(compositionData, entity)); + } + } + } + + private String getCompositionDataAsString(CompositionEntityValidationData entity) { + CompositionEntityData compositionEntityData = getCompositionEntityDataById(entity); + return compositionEntityData == null ? null : compositionEntityData.entity.getCompositionData(); + } + + + private String getEntityNameByEntityType(String compositionData, + CompositionEntityValidationData entity) { + switch (entity.getEntityType()) { + case component: + ComponentData component = JsonUtil.json2Object(compositionData, ComponentData.class); + return component.getDisplayName(); + + case nic: + Nic nic = JsonUtil.json2Object(compositionData, Nic.class); + return nic.getName(); + + case network: + Network network = JsonUtil.json2Object(compositionData, Network.class); + return network.getName(); + + case vsp: + CompositionEntityData vspEntity = getCompositionEntityDataById(entity); + VspQuestionnaireEntity vspQuestionnaireEntity = (VspQuestionnaireEntity) vspEntity.entity; + VspDetails vspDetails = + vspInfoDao.get(new VspDetails(vspQuestionnaireEntity.getId(), + vspQuestionnaireEntity.getVersion())); + return vspDetails.getName(); + } + + return null; + } + + private void removeNodesWithoutErrors(CompositionEntityValidationData node, + CompositionEntityValidationData parent) { + + if (Objects.isNull(node)) { + return; + } + + if (hasChildren(node)) { + Collection subNodes = + new ArrayList<>(node.getSubEntitiesValidationData()); + subNodes.forEach(subNode -> removeNodesWithoutErrors(subNode, node)); + node.setSubEntitiesValidationData(subNodes); + + if (canNodeGetRemovedFromValidationDataTree(node)) { + removeNodeFromChildren(parent, node); + } + } else if (canNodeGetRemovedFromValidationDataTree(node)) { + removeNodeFromChildren(parent, node); + } + } + + private void removeNodeFromChildren(CompositionEntityValidationData parent, + CompositionEntityValidationData childToRemove) { + if (!Objects.isNull(parent)) { + parent.getSubEntitiesValidationData().remove(childToRemove); + } + } + + private boolean hasChildren(CompositionEntityValidationData node) { + return !CollectionUtils.isEmpty(node.getSubEntitiesValidationData()); + } + + private boolean canNodeGetRemovedFromValidationDataTree(CompositionEntityValidationData node) { + return !hasChildren(node) && CollectionUtils.isEmpty(node.getErrors()); + } + + + private void addValidationDataEntity( + Map entitiesValidationData, + CompositionEntityId entityId, CompositionEntity entity) { + if (entitiesValidationData.containsKey(entityId)) { + return; + } + + CompositionEntityValidationData validationData = + new CompositionEntityValidationData(entity.getType(), entity.getId()); + entitiesValidationData.put(entityId, validationData); + + CompositionEntityId parentEntityId = entityId.getParentId(); + if (parentEntityId == null) { + roots.add(validationData); + } else { + CompositionEntityData parentEntity = entities.get(parentEntityId); + if (parentEntity == null) { + roots.add(validationData); + } else { + addValidationDataEntity(entitiesValidationData, parentEntityId, parentEntity.entity); + entitiesValidationData.get(parentEntityId).addSubEntityValidationData(validationData); + } + } + } + + private void addErrorsToTree(CompositionEntityValidationData node, + CompositionEntityId parentNodeId, + Map> errors) { + if (node == null) { + return; + } + CompositionEntityId nodeId = new CompositionEntityId(node.getEntityId(), parentNodeId); + node.setErrors(errors.get(nodeId)); + + if (node.getSubEntitiesValidationData() != null) { + node.getSubEntitiesValidationData() + .forEach(subNode -> addErrorsToTree(subNode, nodeId, errors)); + } + } + + private Collection validateQuestionnaire(CompositionEntityData compositionEntityData) { + return JsonUtil.validate( + compositionEntityData.entity.getQuestionnaireData() == null + ? JsonUtil.object2Json(new Object()) + : compositionEntityData.entity.getQuestionnaireData(), + getSchema(compositionEntityData.entity.getType(), SchemaTemplateContext.questionnaire, + compositionEntityData.schemaTemplateInput)); + } + + private String getSchema(CompositionEntityType compositionEntityType, + SchemaTemplateContext schemaTemplateContext, + SchemaTemplateInput schemaTemplateInput) { + return schemaTemplateInput == null + ? nonDynamicSchemas.computeIfAbsent(compositionEntityType, + k -> generateSchema(schemaTemplateContext, compositionEntityType, null)) + : generateSchema(schemaTemplateContext, compositionEntityType, schemaTemplateInput); + } + + private static class CompositionEntityData { + private CompositionEntity entity; + private SchemaTemplateInput schemaTemplateInput; + + CompositionEntityData(CompositionEntity entity, SchemaTemplateInput schemaTemplateInput) { + this.entity = entity; + this.schemaTemplateInput = schemaTemplateInput; + } + + } + + // todo - make SchemaGenerator non static and mock it in UT instead of mocking this method (and + // make the method private + + protected String generateSchema(SchemaTemplateContext schemaTemplateContext, + CompositionEntityType compositionEntityType, + SchemaTemplateInput schemaTemplateInput) { + return SchemaGenerator + .generate(schemaTemplateContext, compositionEntityType, schemaTemplateInput); + } +} 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 new file mode 100644 index 0000000000..2822d958d0 --- /dev/null +++ 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 @@ -0,0 +1,621 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.services.impl.filedatastructuremodule; + +import org.apache.commons.collections4.CollectionUtils; +import org.openecomp.core.utilities.file.FileContentHandler; +import org.openecomp.core.utilities.json.JsonUtil; +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.common.errors.ErrorCategory; +import org.openecomp.sdc.common.errors.ErrorCode; +import org.openecomp.sdc.common.errors.Messages; +import org.openecomp.sdc.common.utils.SdcCommon; +import org.openecomp.sdc.datatypes.error.ErrorLevel; +import org.openecomp.sdc.datatypes.error.ErrorMessage; +import org.openecomp.sdc.heat.datatypes.manifest.FileData; +import org.openecomp.sdc.heat.datatypes.manifest.ManifestContent; +import org.openecomp.sdc.heat.datatypes.structure.Artifact; +import org.openecomp.sdc.heat.datatypes.structure.HeatStructureTree; +import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage; +import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateCandidateDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateCandidateDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.errors.utils.ErrorsUtil; +import org.openecomp.sdc.vendorsoftwareproduct.services.HeatFileAnalyzer; +import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService; +import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.ManifestCreator; +import org.openecomp.sdc.vendorsoftwareproduct.services.utils.CandidateServiceValidator; +import org.openecomp.sdc.vendorsoftwareproduct.types.CandidateDataEntityTo; +import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.AnalyzedZipHeatFiles; +import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.FilesDataStructure; +import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.Module; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +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.stream.Collectors; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; +import java.util.zip.ZipOutputStream; + +public class CandidateServiceImpl implements CandidateService { + protected static final Logger logger = LoggerFactory.getLogger(CandidateServiceImpl.class); + private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); + + private CandidateServiceValidator candidateServiceValidator = new CandidateServiceValidator(); + private ManifestCreator manifestCreator; + private OrchestrationTemplateCandidateDao orchestrationTemplateCandidateDataDao; + + public CandidateServiceImpl(ManifestCreator manifestCreator, + OrchestrationTemplateCandidateDao orchestrationTemplateCandidateDataDao) { + this.manifestCreator = manifestCreator; + this.orchestrationTemplateCandidateDataDao = orchestrationTemplateCandidateDataDao; + + } + + public CandidateServiceImpl() { + } + + @Override + public Optional validateNonEmptyFileToUpload(InputStream heatFileToUpload) { + + + mdcDataDebugMessage.debugEntryMessage(null); + + if (Objects.isNull(heatFileToUpload)) { + return Optional.of(new ErrorMessage(ErrorLevel.ERROR, + Messages.NO_ZIP_FILE_WAS_UPLOADED_OR_ZIP_NOT_EXIST.getErrorMessage())); + } else { + try { + int available = heatFileToUpload.available(); + if (available == 0) { + mdcDataDebugMessage.debugExitMessage(null); + return Optional.of(new ErrorMessage(ErrorLevel.ERROR, + Messages.NO_ZIP_FILE_WAS_UPLOADED_OR_ZIP_NOT_EXIST.getErrorMessage())); + } + } catch (IOException e) { + mdcDataDebugMessage.debugExitMessage(null); + return Optional.of(new ErrorMessage(ErrorLevel.ERROR, + Messages.NO_ZIP_FILE_WAS_UPLOADED_OR_ZIP_NOT_EXIST.getErrorMessage())); + } + } + + mdcDataDebugMessage.debugExitMessage(null); + return Optional.empty(); + } + + @Override + public Optional validateRawZipData(byte[] uploadedFileData) { + if (Objects.isNull(uploadedFileData)) { + return Optional.of(new ErrorMessage(ErrorLevel.ERROR, + Messages.NO_ZIP_FILE_WAS_UPLOADED_OR_ZIP_NOT_EXIST.getErrorMessage())); + } + return Optional.empty(); + } + + private String heatStructureTreeToFileDataStructure(HeatStructureTree tree, + FileContentHandler zipContentMap, + Map> uploadErrors, + AnalyzedZipHeatFiles analyzedZipHeatFiles) + throws Exception { + FilesDataStructure structure = new FilesDataStructure(); + Set usedEnvFiles = new HashSet<>(); + addHeatsToFileDataStructure(tree, usedEnvFiles, structure, uploadErrors, + analyzedZipHeatFiles); + handleOtherResources(tree, usedEnvFiles, structure); + FilesDataStructure fileDataStructureFromManifest = + createFileDataStructureFromManifest(zipContentMap.getFileContent + (SdcCommon.MANIFEST_NAME)); + structure.getArtifacts().addAll(fileDataStructureFromManifest.getArtifacts()); + handleArtifactsFromTree(tree, structure); + + return JsonUtil.object2Json(structure); + } + + @Override + public OrchestrationTemplateCandidateData createCandidateDataEntity( + CandidateDataEntityTo candidateDataEntityTo, InputStream zipFileManifest, + AnalyzedZipHeatFiles analyzedZipHeatFiles) throws Exception { + + + mdcDataDebugMessage.debugEntryMessage(null); + + 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); + } + + mdcDataDebugMessage.debugExitMessage(null); + return new OrchestrationTemplateCandidateData( + ByteBuffer.wrap(candidateDataEntityTo.getUploadedFileData()), dataStructureJson); + } + + private void balanceManifestFilesWithZipFiles( + FilesDataStructure filesDataStructure, + FileContentHandler fileContentHandler, AnalyzedZipHeatFiles analyzedZipHeatFiles) + throws Exception { + 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().stream().collect(Collectors.toSet())); + fileNames.addAll(filesDataStructure.getNested().stream().collect(Collectors.toSet())); + fileNames.addAll(filesDataStructure.getUnassigned().stream().collect(Collectors.toSet())); + + return fileNames; + } + + private FilesDataStructure createFileDataStructureFromManifest(InputStream isManifestContent) { + + + mdcDataDebugMessage.debugEntryMessage(null); + + 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.setYaml(fileData.getFile()); + module.setIsBase(fileData.getBase()); + addHeatDependenciesToModule(module, fileData.getData()); + 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()); + } + } + + mdcDataDebugMessage.debugExitMessage(null); + 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(OrchestrationTemplateCandidateData uploadData, + String itemId) { + mdcDataDebugMessage.debugEntryMessage(null); + + //vendorSoftwareProductDao.updateCandidateUploadData(uploadData); + orchestrationTemplateCandidateDataDao.update(itemId, uploadData); + + mdcDataDebugMessage.debugExitMessage(null); + } + + @Override + public Optional getOrchestrationTemplateCandidateFileDataStructure( + String vspId, Version version) { + + mdcDataDebugMessage.debugEntryMessage("VSP Id", vspId); + + Optional jsonFileDataStructure = + orchestrationTemplateCandidateDataDao.getStructure(vspId, version); + + if (jsonFileDataStructure.isPresent()) { + mdcDataDebugMessage.debugExitMessage("VSP Id", vspId); + return Optional + .of(JsonUtil.json2Object(jsonFileDataStructure.get(), FilesDataStructure.class)); + } else { + mdcDataDebugMessage.debugExitMessage("VSP Id", vspId); + return Optional.empty(); + } + } + + @Override + public void updateOrchestrationTemplateCandidateFileDataStructure(String vspId, Version version, + FilesDataStructure fileDataStructure) { + OrchestrationTemplateCandidateDaoFactory.getInstance().createInterface() + .updateStructure(vspId, version, fileDataStructure); + } + + @Override + public OrchestrationTemplateCandidateData getOrchestrationTemplateCandidate(String vspId, + Version version) { + mdcDataDebugMessage.debugEntryMessage("VSP Id", vspId); + mdcDataDebugMessage.debugExitMessage("VSP Id", vspId); + + return orchestrationTemplateCandidateDataDao.get(vspId, version); + } + + @Override + public String createManifest(VspDetails vspDetails, FilesDataStructure structure) { + + mdcDataDebugMessage.debugEntryMessage("VSP Id", vspDetails.getId()); + + Optional manifest = manifestCreator.createManifest(vspDetails, structure); + if (!manifest.isPresent()) { + throw new RuntimeException(Messages.CREATE_MANIFEST_FROM_ZIP.getErrorMessage()); + } + + mdcDataDebugMessage.debugExitMessage("VSP Id", vspDetails.getId()); + return JsonUtil.object2Json(manifest.get()); + } + + @Override + public Optional createManifest(VspDetails vspDetails, + FileContentHandler fileContentHandler, + AnalyzedZipHeatFiles analyzedZipHeatFiles) { + + + mdcDataDebugMessage.debugEntryMessage("VSP Id", vspDetails.getId()); + + mdcDataDebugMessage.debugExitMessage("VSP Id", vspDetails.getId()); + return manifestCreator.createManifest(vspDetails, fileContentHandler, analyzedZipHeatFiles); + } + + @Override + public Optional fetchZipFileByteArrayInputStream(String vspId, + OrchestrationTemplateCandidateData candidateDataEntity, + String manifest, + Map> uploadErrors) { + byte[] file; + ByteArrayInputStream byteArrayInputStream = null; + try { + file = replaceManifestInZip(candidateDataEntity.getContentData(), manifest, vspId); + 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, String vspId) + 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, zos); + } + zos.closeEntry(); + } + if (!manifestWritten) { + writeManifest(manifest, zos); + zos.closeEntry(); + } + } + return baos.toByteArray(); + } + + @Override + public Optional> validateFileDataStructure( + FilesDataStructure filesDataStructure) { + return candidateServiceValidator.validateFileDataStructure(filesDataStructure); + } + + private void writeManifest(String manifest, ZipOutputStream zos) throws IOException { + 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 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 boolean isEnvFileUsedByHeatFile(Set usedEnvFiles, HeatStructureTree other) { + if (HeatFileAnalyzer.isEnvFile(other.getFileName())) { + if (usedEnvFiles.contains(other.getFileName())) { + return true; + } + } + return false; + } + + private void addHeatsToFileDataStructure(HeatStructureTree tree, Set usedEnvFiles, + FilesDataStructure structure, + Map> uploadErrors, + AnalyzedZipHeatFiles analyzedZipHeatFiles) + throws Exception { + 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); + + } + + 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) { + + + mdcDataDebugMessage.debugEntryMessage(null); + + 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); + + mdcDataDebugMessage.debugExitMessage(null); + } + + private void handleVolumes(Module module, Set volumeSet, + FilesDataStructure structure, int inx, + Map> uploadErrors) { + + + mdcDataDebugMessage.debugEntryMessage(null); + + for (HeatStructureTree volume : volumeSet) { + 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); + } + + mdcDataDebugMessage.debugExitMessage(null); + } + + private void handleEnv(Module module, HeatStructureTree tree, boolean isVolEnv, + FilesDataStructure structure) { + + + mdcDataDebugMessage.debugEntryMessage(null); + + if (Objects.nonNull(tree.getEnv())) { + if (isVolEnv) { + module.setVolEnv(tree.getEnv().getFileName()); + } else { + module.setEnv(tree.getEnv().getFileName()); + } + handleArtifactsFromTree(tree.getEnv(), structure); + } + + mdcDataDebugMessage.debugExitMessage(null); + } + + 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 new file mode 100644 index 0000000000..eed575ff02 --- /dev/null +++ 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 @@ -0,0 +1,309 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.services.impl.filedatastructuremodule; + +import org.apache.commons.collections4.CollectionUtils; +import org.openecomp.core.utilities.file.FileContentHandler; +import org.openecomp.sdc.heat.datatypes.manifest.FileData; +import org.openecomp.sdc.heat.datatypes.manifest.ManifestContent; +import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.services.HeatFileAnalyzer; +import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.ManifestCreator; +import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.AnalyzedZipHeatFiles; +import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.Constants; +import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.FilesDataStructure; +import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.Module; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +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; + +public class ManifestCreatorNamingConventionImpl implements ManifestCreator { + protected static final Logger logger = + LoggerFactory.getLogger(ManifestCreatorNamingConventionImpl.class); + private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); + + + @Override + public Optional createManifest( + VspDetails vspDetails, FilesDataStructure filesDataStructure) { + + + mdcDataDebugMessage.debugEntryMessage(null, null); + + 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); + + mdcDataDebugMessage.debugExitMessage(null, null); + return Optional.of(manifestContent); + } + + private void addNestedToManifest( + FilesDataStructure filesDataStructure, List fileDataList) { + + + mdcDataDebugMessage.debugEntryMessage(null, null); + + if (CollectionUtils.isNotEmpty(filesDataStructure.getNested())) { + for (String nested : filesDataStructure.getNested()) { + fileDataList.add(createBaseFileData(FileData.Type.HEAT, nested)); + } + } + + mdcDataDebugMessage.debugExitMessage(null, null); + } + + @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); + } + + 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 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 boolean doesHeatTemplateVersionExist(byte[] value) { + return false; + } + + 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); + } + + + private void addArtifactsToManifestFileDataList( + FilesDataStructure filesDataStructure, List fileDataList) { + + + mdcDataDebugMessage.debugEntryMessage(null, null); + + Collection forArtifacts = CollectionUtils + .union(filesDataStructure.getArtifacts(), filesDataStructure.getUnassigned()); + if (CollectionUtils.isNotEmpty(forArtifacts)) { + for (String artifact : forArtifacts) { + fileDataList.add(createBaseFileData(FileData.Type.OTHER, artifact)); + } + } + + mdcDataDebugMessage.debugExitMessage(null, null); + } + + private void addModulesToManifestFileDataList( + FilesDataStructure filesDataStructure, List fileDataList) { + + + mdcDataDebugMessage.debugEntryMessage(null, null); + + if (CollectionUtils.isNotEmpty(filesDataStructure.getModules())) { + for (Module module : filesDataStructure.getModules()) { + FileData fileData = createBaseFileData(FileData.Type.HEAT, module.getYaml()); + fileData.setBase(module.getIsBase()); + addEnv(module, fileData); + addVolume(module, fileData); + fileDataList.add(fileData); + } + } + + mdcDataDebugMessage.debugExitMessage(null, null); + } + + 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 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); + } + 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"); + + if (fileNames.contains(volFile1stExt)) { + return Optional.of(volFile1stExt); + } + if (fileNames.contains(volFile2ndExt)) { + return Optional.of(volFile2ndExt); + } + return Optional.empty(); + } + + 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); + } +} 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 new file mode 100644 index 0000000000..05c95a7596 --- /dev/null +++ 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 @@ -0,0 +1,97 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.services.utils; + +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang.StringUtils; +import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder; +import org.openecomp.sdc.common.errors.Messages; +import org.openecomp.sdc.datatypes.error.ErrorLevel; +import org.openecomp.sdc.datatypes.error.ErrorMessage; +import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage; +import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.FilesDataStructure; +import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.Module; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.Optional; + +/** + * Created by Talio on 12/6/2016. + */ +public class CandidateServiceValidator { + private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); + + 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); + } + + + private boolean validateAtLeaseOneModuleExist(FilesDataStructure filesDataStructure) { + + mdcDataDebugMessage.debugEntryMessage(null, null); + + mdcDataDebugMessage.debugExitMessage(null, null); + return CollectionUtils.isEmpty(filesDataStructure.getModules()); + } + + private void validateNoVolEnvWithoutVol(List errors, Module module) { + + mdcDataDebugMessage.debugEntryMessage(null, null); + + 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()))); + } + + mdcDataDebugMessage.debugExitMessage(null, null); + } + + private void validateModuleHaveYaml(List errors, Module module) { + + mdcDataDebugMessage.debugEntryMessage(null, null); + + if (StringUtils.isEmpty(module.getYaml())) { + errors.add(new ErrorMessage(ErrorLevel.ERROR, ErrorMessagesFormatBuilder + .getErrorWithParameters(Messages.MODULE_IN_MANIFEST_NO_YAML.getErrorMessage(), + module.getName()))); + } + + mdcDataDebugMessage.debugExitMessage(null, null); + } +} diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/dao/ServiceModelDaoFactoryTest.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/dao/ServiceModelDaoFactoryTest.java index 2c8ffb1ded..5cfe33ba90 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/dao/ServiceModelDaoFactoryTest.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/dao/ServiceModelDaoFactoryTest.java @@ -1,18 +1,56 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + package org.openecomp.sdc.vendorsoftwareproduct.dao; +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; +import com.amdocs.zusammen.datatypes.Id; +import com.amdocs.zusammen.datatypes.SessionContext; +import com.amdocs.zusammen.datatypes.UserInfo; +import com.amdocs.zusammen.datatypes.item.ElementContext; +import com.amdocs.zusammen.datatypes.item.Info; +import com.amdocs.zusammen.datatypes.item.Item; +import com.amdocs.zusammen.datatypes.item.ItemVersion; +import com.amdocs.zusammen.datatypes.item.ItemVersionData; +import com.amdocs.zusammen.datatypes.itemversion.Tag; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.openecomp.core.utilities.CommonMethods; +import org.openecomp.core.utilities.file.FileContentHandler; +import org.openecomp.core.utilities.yaml.YamlUtil; +import org.openecomp.core.zusammen.api.ZusammenAdaptor; +import org.openecomp.sdc.model.impl.zusammen.ServiceModelDaoZusammenImpl; +import org.openecomp.sdc.model.impl.zusammen.StructureElement; import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate; - import org.openecomp.sdc.versioning.dao.types.Version; -import org.openecomp.core.model.dao.ServiceModelDaoFactory; -import org.openecomp.core.model.types.ServiceArtifact; -import org.openecomp.core.utilities.CommonMethods; -import org.openecomp.core.utilities.file.FileContentHandler; import org.testng.Assert; import org.testng.annotations.Test; +import java.io.ByteArrayInputStream; +import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.Map; +import java.util.Optional; public class ServiceModelDaoFactoryTest { @@ -22,19 +60,64 @@ public class ServiceModelDaoFactoryTest { private static String artifact001; -// @Test + @Test public void storeServiceModelTest() { + ItemVersion itemVersionmock = new ItemVersion(); + itemVersionmock.setId(new Id()); + ZusammenAdaptorMock zusammenAdaptor = new ZusammenAdaptorMock(); + ServiceModelDaoZusammenImpl serviceModelDaoZusammen = new ServiceModelDaoZusammenImpl( + zusammenAdaptor); + + zusammenAdaptor.setItemVersion(itemVersionmock); ToscaServiceModel model = getToscaServiceModel(); - ServiceModelDaoFactory.getInstance().createInterface().storeServiceModel(vspId, version, model); + serviceModelDaoZusammen.storeServiceModel(vspId, version, model); + } + + private SessionContext getSessionContext() { + SessionContext context = new SessionContext(); + context.setUser(new UserInfo("USER_A")); + context.setTenant("asdc"); + return context; } -// @Test(dependsOnMethods = "storeServiceModelTest") + @Test public void getServiceModelTest() { + + ItemVersion itemVersionmock = new ItemVersion(); + itemVersionmock.setId(new Id()); + + ElementInfo elementInfo = new ElementInfo(); + Info info = new Info(); + info.addProperty("base","baseElement"); + elementInfo.setInfo(info); + + ElementInfo artifactElementInfo = new ElementInfo(); + artifactElementInfo.setInfo(info); + ElementInfo templateElementInfo = new ElementInfo(); + artifactElementInfo.setInfo(info); + + ZusammenElement element = new ZusammenElement(); + ServiceTemplate serviceTemplate = new ServiceTemplate(); + YamlUtil yamlUtil = new YamlUtil(); + element.setData(new ByteArrayInputStream(yamlUtil.objectToYaml(serviceTemplate).getBytes())); + info = new Info(); + info.setName("dataFileName"); + element.setInfo(info); + ZusammenAdaptorMock zusammenAdaptor = new ZusammenAdaptorMock(); + ServiceModelDaoZusammenImpl serviceModelDaoZusammen = new ServiceModelDaoZusammenImpl( + zusammenAdaptor); + + zusammenAdaptor.setItemVersion(itemVersionmock); + zusammenAdaptor.addElementInfo("null"+StructureElement.ServiceModel.name(),elementInfo); + zusammenAdaptor.addElementInfo("null"+StructureElement.Artifacts.name(),artifactElementInfo); + zusammenAdaptor.addElementInfo("null"+StructureElement.Templates.name(),templateElementInfo); + zusammenAdaptor.addElement(element); + Object model = - ServiceModelDaoFactory.getInstance().createInterface().getServiceModel(vspId, version); + serviceModelDaoZusammen.getServiceModel(vspId, version); Assert.assertNotNull(model); Assert.assertTrue(model instanceof ToscaServiceModel); if (model instanceof ToscaServiceModel) { @@ -44,16 +127,6 @@ public class ServiceModelDaoFactoryTest { } } -// @Test(dependsOnMethods = "getServiceModelTest") - public void getServiceModelInfoTest() { - Object info = ServiceModelDaoFactory.getInstance().createInterface() - .getServiceModelInfo(vspId, version, artifact001); - Assert.assertNotNull(info); - Assert.assertTrue(info instanceof ServiceArtifact); - if (info instanceof ServiceArtifact) { - Assert.assertEquals(((ServiceArtifact) info).getName(), artifact001); - } - } private ToscaServiceModel getToscaServiceModel() { @@ -94,4 +167,119 @@ public class ServiceModelDaoFactoryTest { serviceTemplate.setDescription(CommonMethods.nextUuId()); return serviceTemplate; } + + private class ZusammenAdaptorMock implements ZusammenAdaptor + { + + private ItemVersion itemVersion; + private Map elementInfoMap = new HashMap(); + private Collection elements = new ArrayList<>(); + + public void setItemVersion(ItemVersion itemVersion){ + this.itemVersion = itemVersion; + } + + public void addElementInfo(String key,ElementInfo elementInfo){ + elementInfoMap.put(key,elementInfo); + } + public void addElement(Element element){ + elements.add(element); + } + @Override + public Optional getFirstVersion(SessionContext context, Id itemId) { + + return Optional.ofNullable(itemVersion); + } + + @Override + public Optional getElement(SessionContext context, ElementContext elementContext, + String elementId) { + return null; + } + + @Override + public Optional getElementByName(SessionContext context, + ElementContext elementContext, + Id parentElementId, String elementName) { + return null; + } + + @Override + public Collection listElements(SessionContext context, + ElementContext elementContext, + Id parentElementId) { + return null; + } + + @Override + public Collection listElementData(SessionContext context, + ElementContext elementContext, + Id parentElementId) { + return elements; + } + + @Override + public Collection listElementsByName(SessionContext context, + ElementContext elementContext, + Id parentElementId, String elementName) { + return null; + } + + @Override + public Optional getElementInfoByName(SessionContext context, + ElementContext elementContext, + Id parentElementId, String elementName) { + return Optional.ofNullable(elementInfoMap.get(parentElementId+elementName)); + } + + @Override + public Optional saveElement(SessionContext context, ElementContext elementContext, + ZusammenElement element, String message) { + return null; + } + + @Override + public Id createItem(SessionContext context, Info info) { + return null; + } + + @Override + public void updateItem(SessionContext context, Id itemId, Info info) { + + } + + @Override + public Id createVersion(SessionContext context, Id itemId, Id baseVersionId, + ItemVersionData itemVersionData) { + return null; + } + + @Override + public void updateVersion(SessionContext context, Id itemId, Id versionId, + ItemVersionData itemVersionData) { + + } + + @Override + public void tagVersion(SessionContext context, Id itemId, Id versionId, Tag tag) { + + } + + @Override + public void resetVersionHistory(SessionContext context, Id itemId, Id versionId, String changeRef) { + + } + + @Override + public Optional getElementInfo(SessionContext context, + ElementContext elementContext, + Id elementId) { + return null; + } + + @Override + public Collection listItems(SessionContext context) { + return null; + } + } } diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/informationArtifact/impl/TxtInformationArtifactGeneratorImplTest.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/informationArtifact/impl/TxtInformationArtifactGeneratorImplTest.java new file mode 100644 index 0000000000..6652c271ac --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/informationArtifact/impl/TxtInformationArtifactGeneratorImplTest.java @@ -0,0 +1,252 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl; + + +import org.junit.Assert; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.InformationArtifactData; +import org.openecomp.sdc.vendorsoftwareproduct.questionnaire.QuestionnaireDataService; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.ComponentQuestionnaire; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.compute.Compute; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.compute.GuestOS; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.compute.NumOfVMs; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.general.Hypervisor; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.general.Recovery; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.network.NetworkCapacity; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.storage.Backup; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.storage.Storage; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.nic.IpConfiguration; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.nic.Network; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.nic.NicQuestionnaire; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.nic.Protocols; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.vsp.VspQuestionnaire; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.vsp.general.Availability; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.vsp.general.General; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.vsp.general.StorageDataReplication; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import javax.annotation.processing.SupportedAnnotationTypes; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import static org.mockito.Matchers.anyObject; +import static org.mockito.Matchers.anyString; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.HEADER; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.VFC_COMPUTE_CPU_OVER_SUBSCRIPTION; + + +/** + * @author KATYR + * @since December 07, 2016 + */ + +public class TxtInformationArtifactGeneratorImplTest { + + private static final String NETWORK_DESC = "\"network desc\""; + private static final String HYPERVIZOR_NAME = "\"hyper hyper hypervizor\""; + private static final String TOOLS ="all tools possible" ; + @Mock + QuestionnaireDataService questionnaireDataServiceMock; + @InjectMocks + TxtInformationArtifactGeneratorImpl informationArtifactGenerator; + + @BeforeMethod(alwaysRun = true) + public void injectDoubles() { + MockitoAnnotations.initMocks(this); + +// InformationArtifactData returnedQuestionnaire = new InformationArtifactData(); +// Mockito.when(questionnaireDataServiceMock.generateQuestionnaireDataForInformationArtifact +// (anyString(), anyObject())) +// .thenReturn(returnedQuestionnaire); +// + + } + + @Test + public void testRoundVersion(){ + Version version = new Version(2,1); + String rounded = TxtInformationArtifactGeneratorImpl.roundVersionAsNeeded(version); + Assert.assertEquals("3.0",rounded); + + version = Version.valueOf("2.0"); + rounded = TxtInformationArtifactGeneratorImpl.roundVersionAsNeeded(version); + Assert.assertEquals("2.0",rounded); + + } + + @Test + public void testArtifactCreation() throws IOException { + InformationArtifactData informationArtifactData = initArtifactData(); + Mockito.when(questionnaireDataServiceMock.generateQuestionnaireDataForInformationArtifact + (anyString(), anyObject())) + .thenReturn(informationArtifactData); + + + String result = informationArtifactGenerator.generate("vsp", new Version(0, 1)); + System.out.println("result = \n" + result); + + Assert.assertTrue(result.contains(HYPERVIZOR_NAME)); + Assert.assertTrue(result.contains(HEADER)); + Assert.assertTrue(result.contains(VFC_COMPUTE_CPU_OVER_SUBSCRIPTION)); + Assert.assertTrue(result.contains(TOOLS)); + Assert.assertTrue(result.contains(TxtInformationArtifactConstants.LICENSE_AGREEMENT_NAME)); + Assert.assertTrue(result.contains(TxtInformationArtifactConstants.LIST_OF_FEATURE_GROUPS)); + + } + + private InformationArtifactData initArtifactData() { + InformationArtifactData informationArtifactData = new InformationArtifactData(); + + informationArtifactData.setVspDetails(initVspDetails()); + + informationArtifactData.setVspQuestionnaire(initVspQuestionnaire()); + informationArtifactData.setComponentQuestionnaires(initComponentQuestionnaires()); + informationArtifactData.setNicQuestionnaires(initNicQuestionnaires()); + return informationArtifactData; + } + + private List initNicQuestionnaires() { + List nicQuestionnaires = new ArrayList<>(); + NicQuestionnaire nic1 = new NicQuestionnaire(); + NicQuestionnaire nic2 = new NicQuestionnaire(); + nic1 = initNicQuestionnaire(); + nic2 = initNicQuestionnaire(); + nicQuestionnaires.add(nic1); + nicQuestionnaires.add(nic2); + return nicQuestionnaires; + + } + + private NicQuestionnaire initNicQuestionnaire() { + NicQuestionnaire nic = new NicQuestionnaire(); + Network network = new Network(); + network.setNetworkDescription(NETWORK_DESC); + nic.setNetwork(network); + + IpConfiguration ipconfig = new IpConfiguration(); + ipconfig.setIpv4Required(true); + ipconfig.setIpv6Required(false); + + nic.setIpConfiguration(ipconfig); + + Protocols protocols = new Protocols(); + List protocolsList = new ArrayList<>(); + protocolsList.add("45"); + protocolsList.add("55"); + protocolsList.add("HTTP"); + protocols.setProtocols(protocolsList); + + nic.setProtocols(protocols); + + return nic; + } + + private List initComponentQuestionnaires() { + List componentQuestionnaires = new ArrayList<>(); + ComponentQuestionnaire componentQuestionnaire1 = new ComponentQuestionnaire(); + ComponentQuestionnaire componentQuestionnaire2 = new ComponentQuestionnaire(); + + componentQuestionnaire1 = initComponent(); + componentQuestionnaire2 = initComponent(); + + componentQuestionnaires.add(componentQuestionnaire1); + componentQuestionnaires.add(componentQuestionnaire2); + + return componentQuestionnaires; + } + + private ComponentQuestionnaire initComponent() { + ComponentQuestionnaire componentQuestionnaire = new ComponentQuestionnaire(); + org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.general.General general = + new org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.general.General(); + Hypervisor hypervisor = new Hypervisor(); + hypervisor.setDrivers("driving drivers"); + hypervisor.setHypervisor(HYPERVIZOR_NAME); + general.setHypervisor(hypervisor); + Recovery recovery = new Recovery(); + recovery.setPointObjective(22); + recovery.setTimeObjective(33); + general.setRecovery(recovery); + componentQuestionnaire.setGeneral( + general); + org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.network.Network net = + new org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.network.Network(); + net.setNetworkCapacity(new NetworkCapacity()); + componentQuestionnaire.setNetwork(net); + Compute compute = new Compute(); + GuestOS guestOS = new GuestOS(); + guestOS.setBitSize(32); + guestOS.setTools(TOOLS); + guestOS.setName("Ubuntu"); + compute.setGuestOS(guestOS); + NumOfVMs numOfVMs = new NumOfVMs(); + numOfVMs.setMaximum(256); + numOfVMs.setMinimum(2); + compute.setNumOfVMs(numOfVMs); + componentQuestionnaire.setCompute(compute); + + return componentQuestionnaire; + } + + private VspQuestionnaire initVspQuestionnaire() { + VspQuestionnaire vspQuestionnaire = new VspQuestionnaire(); + Availability availability = new Availability(); + availability.setUseAvailabilityZonesForHighAvailability(true); + General general = new General(); + general.setAvailability(availability); + + StorageDataReplication storageDataReplication = new StorageDataReplication(); + storageDataReplication.setStorageReplicationAcrossRegion(true); + storageDataReplication.setStorageReplicationDestination("in a galaxy far, far away"); + storageDataReplication.setStorageReplicationFrequency(6); + storageDataReplication.setStorageReplicationSize(128); + storageDataReplication.setStorageReplicationSource("here below"); + general.setStorageDataReplication(storageDataReplication); + vspQuestionnaire.setGeneral(general); + return vspQuestionnaire; + } + + private VspDetails initVspDetails() { + VspDetails vspDetails = new VspDetails(); + vspDetails.setCategory("vspCategory"); + vspDetails.setDescription("described"); + vspDetails.setName("vsp named Alice"); + vspDetails.setVendorName("Fortigate"); + vspDetails.setVersion(new Version(0, 79)); + vspDetails.setVlmVersion(new Version(0, 1)); + vspDetails.setLicenseAgreement("the usual license agreement"); + List featureGroups = new ArrayList<>(); + featureGroups.add("first feature group"); + featureGroups.add("one too many feature group"); + featureGroups.add("the very last feature group"); + vspDetails.setFeatureGroups(featureGroups); + return vspDetails; + } + +} diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/resources/logback.xml b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/resources/logback.xml new file mode 100644 index 0000000000..03ce9d1243 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + + %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n + + + + + + + \ No newline at end of file -- cgit 1.2.3-korg