summaryrefslogtreecommitdiffstats
path: root/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main')
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/VendorSoftwareProductManager.java173
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/CreatePackageForNonFinalVendorSoftwareProductErrorBuilder.java59
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/FileCreationErrorBuilder.java56
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/MibUploadErrorBuilder.java59
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/PackageInvalidErrorBuilder.java60
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/PackageNotFoundErrorBuilder.java71
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/TranslationFileCreationErrorBuilder.java60
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/UploadInvalidErrorBuilder.java82
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/VendorSoftwareProductErrorCodes.java48
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/VendorSoftwareProductInvalidErrorBuilder.java60
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/VendorSoftwareProductNotFoundErrorBuilder.java54
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java1567
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/CompositionDataExtractor.java386
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/CompositionEntityDataManager.java257
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/SchemaGenerator.java70
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/SchemaGeneratorConfig.java184
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/CompositionEntityResponse.java53
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/CompositionEntityValidationData.java122
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/ExtractCompositionDataContext.java204
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/LicensingData.java45
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/QuestionnaireResponse.java42
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/QuestionnaireValidationResult.java39
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/UploadFileResponse.java143
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/UploadFileStatus.java26
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/UploadFileStructure.java40
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/ValidationResponse.java157
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/VersionedVendorSoftwareProductInfo.java53
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/schemagenerator/ComponentCompositionSchemaInput.java43
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/schemagenerator/ComponentQuestionnaireSchemaInput.java42
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/schemagenerator/MibUploadStatus.java51
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/schemagenerator/NetworkCompositionSchemaInput.java43
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/schemagenerator/NicCompositionSchemaInput.java55
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/schemagenerator/SchemaTemplateContext.java26
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/schemagenerator/SchemaTemplateInput.java25
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/util/CompilationUtil.java126
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/util/VendorSoftwareProductUtils.java254
36 files changed, 4835 insertions, 0 deletions
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/VendorSoftwareProductManager.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/VendorSoftwareProductManager.java
new file mode 100644
index 0000000000..0d38d165c2
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/VendorSoftwareProductManager.java
@@ -0,0 +1,173 @@
+/*-
+ * ============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;
+
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.PackageInfo;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
+import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityResponse;
+import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityValidationData;
+import org.openecomp.sdc.vendorsoftwareproduct.types.QuestionnaireResponse;
+import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
+import org.openecomp.sdc.vendorsoftwareproduct.types.ValidationResponse;
+import org.openecomp.sdc.vendorsoftwareproduct.types.VersionedVendorSoftwareProductInfo;
+import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentData;
+import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Network;
+import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic;
+import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.MibUploadStatus;
+import org.openecomp.sdc.versioning.dao.types.Version;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collection;
+import java.util.List;
+
+public interface VendorSoftwareProductManager {
+
+ Version checkout(String vendorSoftwareProductId, String user);
+
+ Version undoCheckout(String vendorSoftwareProductId, String user);
+
+ Version checkin(String vendorSoftwareProductId, String user);
+
+ ValidationResponse submit(String vendorSoftwareProductId, String user) throws IOException;
+
+
+ VspDetails createNewVsp(VspDetails vspDetails, String user);
+
+ List<VersionedVendorSoftwareProductInfo> getVspList(String versionFilter, String user);
+
+ void updateVsp(VspDetails vspDetails, String user);
+
+ VersionedVendorSoftwareProductInfo getVspDetails(String vspId, Version version, String user);
+
+ void deleteVsp(String vspIdToDelete, String user);
+
+
+ UploadFileResponse uploadFile(String vspId, InputStream heatFileToUpload, String user);
+
+ PackageInfo createPackage(String vspId, String user) throws IOException;
+
+ List<PackageInfo> listPackages(String category, String subCategory);
+
+ File getTranslatedFile(String vspId, Version version, String user);
+
+ File getLatestHeatPackage(String vspId, String user);
+
+ QuestionnaireResponse getVspQuestionnaire(String vspId, Version version, String user);
+
+ void updateVspQuestionnaire(String vspId, String questionnaireData, String user);
+
+
+ Collection<NetworkEntity> listNetworks(String vspId, Version version, String user);
+
+ NetworkEntity createNetwork(NetworkEntity network, String user);
+
+ CompositionEntityValidationData updateNetwork(NetworkEntity networkEntity, String user);
+
+ CompositionEntityResponse<Network> getNetwork(String vspId, Version version, String networkId,
+ String user);
+
+ void deleteNetwork(String vspId, String networkId, String user);
+
+
+ QuestionnaireResponse getComponentQuestionnaire(String vspId, Version version, String componentId,
+ String user);
+
+ void updateComponentQuestionnaire(String vspId, String componentId, String questionnaireData,
+ String user);
+
+
+ Collection<ComponentEntity> listComponents(String vspId, Version version, String user);
+
+ void deleteComponents(String vspId, String user);
+
+ ComponentEntity createComponent(ComponentEntity componentEntity, String user);
+
+ CompositionEntityValidationData updateComponent(ComponentEntity componentEntity, String user);
+
+ CompositionEntityResponse<ComponentData> getComponent(String vspId, Version version,
+ String componentId, String user);
+
+ void deleteComponent(String vspId, String componentId, String user);
+
+
+ Collection<org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity> listProcesses(
+ String vspId, Version version, String componentId,
+ String user);
+
+ void deleteProcesses(String vspId, String componentId, String user);
+
+ org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity createProcess(
+ org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity processEntity, String user);
+
+ org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity getProcess(String vspId,
+ Version version,
+ String componentId,
+ String processId,
+ String user);
+
+ void updateProcess(org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity processEntity,
+ String user);
+
+ void deleteProcess(String vspId, String componentId, String processId, String user);
+
+
+ File getProcessArtifact(String vspId, Version version, String componentId, String processId,
+ String user);
+
+ void deleteProcessArtifact(String vspId, String componentId, String processId, String user);
+
+ void uploadProcessArtifact(InputStream uploadFile, String fileName, String vspId,
+ String componentId, String processId, String user);
+
+
+ Collection<org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity> listNics(String vspId,
+ Version version,
+ String componentId,
+ String user);
+
+ org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity createNic(
+ org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity nic, String user);
+
+ CompositionEntityValidationData updateNic(
+ org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity nicEntity, String user);
+
+ CompositionEntityResponse<Nic> getNic(String vspId, Version version, String componentId,
+ String nicId, String user);
+
+ void deleteNic(String vspId, String componentId, String nicId, String user);
+
+ QuestionnaireResponse getNicQuestionnaire(String vspId, Version version, String componentId,
+ String nicId, String user);
+
+ void updateNicQuestionnaire(String vspId, String componentId, String nicId,
+ String questionnaireData, String user);
+
+ void deleteComponentMib(String vspId, String componentId, boolean isTrap, String user);
+
+ void uploadComponentMib(InputStream object, String filename, String vspId, String componentId,
+ boolean isTrap, String user);
+
+ MibUploadStatus listMibFilenames(String vspId, String componentId, String user);
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/CreatePackageForNonFinalVendorSoftwareProductErrorBuilder.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/CreatePackageForNonFinalVendorSoftwareProductErrorBuilder.java
new file mode 100644
index 0000000000..527530d4de
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/CreatePackageForNonFinalVendorSoftwareProductErrorBuilder.java
@@ -0,0 +1,59 @@
+/*-
+ * ============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;
+
+import org.openecomp.sdc.common.errors.ErrorCategory;
+import org.openecomp.sdc.common.errors.ErrorCode;
+import org.openecomp.sdc.versioning.dao.types.Version;
+
+/**
+ * The type Create package for non final vendor software product error builder.
+ */
+public class CreatePackageForNonFinalVendorSoftwareProductErrorBuilder {
+
+ private static final String CREATE_PACKAGE_FOR_NON_FINAL_VSP_MSG =
+ "Package creation for vendor software product with id %s and version %s is not allowed "
+ + "since it is not final (submitted).";
+ private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
+
+ /**
+ * Instantiates a new Create package for non final vendor software product error builder.
+ *
+ * @param vendorSoftwareProductId the vendor software product id
+ * @param version the version
+ */
+ public CreatePackageForNonFinalVendorSoftwareProductErrorBuilder(String vendorSoftwareProductId,
+ Version version) {
+ builder.withId(VendorSoftwareProductErrorCodes.CREATE_PACKAGE_FOR_NON_FINAL_VSP);
+ builder.withCategory(ErrorCategory.APPLICATION);
+ builder.withMessage(String
+ .format(CREATE_PACKAGE_FOR_NON_FINAL_VSP_MSG, vendorSoftwareProductId, version.toString()));
+ }
+
+ /**
+ * Build error code.
+ *
+ * @return the error code
+ */
+ public ErrorCode build() {
+ return builder.build();
+ }
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/FileCreationErrorBuilder.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/FileCreationErrorBuilder.java
new file mode 100644
index 0000000000..5a40609270
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/FileCreationErrorBuilder.java
@@ -0,0 +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.errors;
+
+import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes.HEAT_PACKAGE_FILE_CREATION;
+
+import org.openecomp.sdc.common.errors.ErrorCategory;
+import org.openecomp.sdc.common.errors.ErrorCode;
+
+/**
+ * The type File creation error builder.
+ */
+public class FileCreationErrorBuilder {
+ private static final String HEAT_PKG_FILE_CREATION_ERROR_MSG =
+ "Error while trying to create heat file from the package of vendor software product "
+ + "with Id %s.";
+ private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
+
+ /**
+ * Instantiates a new File creation error builder.
+ *
+ * @param vendorSoftwareProductId the vendor software product id
+ */
+ public FileCreationErrorBuilder(String vendorSoftwareProductId) {
+ builder.withId(HEAT_PACKAGE_FILE_CREATION);
+ builder.withCategory(ErrorCategory.SYSTEM);
+ builder.withMessage(String.format(HEAT_PKG_FILE_CREATION_ERROR_MSG, vendorSoftwareProductId));
+ }
+
+ /**
+ * Build error code.
+ *
+ * @return the error code
+ */
+ public ErrorCode build() {
+ return builder.build();
+ }
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/MibUploadErrorBuilder.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/MibUploadErrorBuilder.java
new file mode 100644
index 0000000000..75a4aa3ff7
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/MibUploadErrorBuilder.java
@@ -0,0 +1,59 @@
+/*-
+ * ============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;
+
+import org.openecomp.sdc.common.errors.BaseErrorBuilder;
+import org.openecomp.sdc.common.errors.ErrorCategory;
+
+/**
+ * The type Mib upload error builder.
+ */
+public class MibUploadErrorBuilder extends BaseErrorBuilder {
+ private static final String UPLOAD_INVALID_DETAILED_MSG =
+ "MIB uploaded for vendor software product with Id %s and version %s is invalid: %s";
+
+
+ /**
+ * Instantiates a new Mib upload error builder.
+ *
+ * @param vendorSoftwareProductId the vendor software product id
+ * @param version the version
+ * @param error the error
+ */
+ public MibUploadErrorBuilder(String vendorSoftwareProductId, org.openecomp.sdc.versioning.dao
+ .types.Version version, String error) {
+ getErrorCodeBuilder().withId(VendorSoftwareProductErrorCodes.MIB_UPLOAD_INVALID);
+ getErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION);
+ getErrorCodeBuilder().withMessage(String
+ .format(UPLOAD_INVALID_DETAILED_MSG, vendorSoftwareProductId, version.toString(), error));
+ }
+
+ /**
+ * Instantiates a new Mib upload error builder.
+ *
+ * @param errorMessage the error message
+ */
+ public MibUploadErrorBuilder(String errorMessage) {
+ getErrorCodeBuilder().withId(VendorSoftwareProductErrorCodes.MIB_UPLOAD_INVALID);
+ getErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION);
+ getErrorCodeBuilder().withMessage(errorMessage);
+ }
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/PackageInvalidErrorBuilder.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/PackageInvalidErrorBuilder.java
new file mode 100644
index 0000000000..279dbfe4ea
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/PackageInvalidErrorBuilder.java
@@ -0,0 +1,60 @@
+/*-
+ * ============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;
+
+import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes
+ .PACKAGE_INVALID;
+
+import org.openecomp.sdc.common.errors.ErrorCategory;
+import org.openecomp.sdc.common.errors.ErrorCode;
+import org.openecomp.sdc.versioning.dao.types.Version;
+
+/**
+ * The type Package invalid error builder.
+ */
+public class PackageInvalidErrorBuilder {
+ private static final String PACKAGE_INVALID_MSG =
+ "Package for vendor software product with Id %s and version %s is invalid "
+ + "(does not contain translated data).";
+ private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
+
+ /**
+ * Instantiates a new Package invalid error builder.
+ *
+ * @param vendorSoftwareProductId the vendor software product id
+ * @param version the version
+ */
+ public PackageInvalidErrorBuilder(String vendorSoftwareProductId, Version version) {
+ builder.withId(PACKAGE_INVALID);
+ builder.withCategory(ErrorCategory.APPLICATION);
+ builder.withMessage(
+ String.format(PACKAGE_INVALID_MSG, vendorSoftwareProductId, version.toString()));
+ }
+
+ /**
+ * Build error code.
+ *
+ * @return the error code
+ */
+ public ErrorCode build() {
+ return builder.build();
+ }
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/PackageNotFoundErrorBuilder.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/PackageNotFoundErrorBuilder.java
new file mode 100644
index 0000000000..3a32fa30b1
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/PackageNotFoundErrorBuilder.java
@@ -0,0 +1,71 @@
+/*-
+ * ============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;
+
+import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes.PACKAGE_NOT_FOUND;
+
+import org.openecomp.sdc.common.errors.ErrorCategory;
+import org.openecomp.sdc.common.errors.ErrorCode;
+import org.openecomp.sdc.versioning.dao.types.Version;
+
+/**
+ * The type Package not found error builder.
+ */
+public class PackageNotFoundErrorBuilder {
+ private static final String PACKAGE_VERSION_NOT_FOUND_MSG =
+ "Package for vendor software product with Id %s and version %s does not exist.";
+ private static final String PACKAGE_NOT_FOUND_MSG =
+ "Package for vendor software product with Id %s does not exist.";
+ private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
+
+ /**
+ * Instantiates a new Package not found error builder.
+ *
+ * @param vendorSoftwareProductId the vendor software product id
+ * @param version the version
+ */
+ public PackageNotFoundErrorBuilder(String vendorSoftwareProductId, Version version) {
+ builder.withId(PACKAGE_NOT_FOUND);
+ builder.withCategory(ErrorCategory.APPLICATION);
+ builder.withMessage(
+ String.format(PACKAGE_VERSION_NOT_FOUND_MSG, vendorSoftwareProductId, version.toString()));
+ }
+
+ /**
+ * Instantiates a new Package not found error builder.
+ *
+ * @param vendorSoftwareProductId the vendor software product id
+ */
+ public PackageNotFoundErrorBuilder(String vendorSoftwareProductId) {
+ builder.withId(PACKAGE_NOT_FOUND);
+ builder.withCategory(ErrorCategory.APPLICATION);
+ builder.withMessage(String.format(PACKAGE_NOT_FOUND_MSG, vendorSoftwareProductId));
+ }
+
+ /**
+ * Build error code.
+ *
+ * @return the error code
+ */
+ public ErrorCode build() {
+ return builder.build();
+ }
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/TranslationFileCreationErrorBuilder.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/TranslationFileCreationErrorBuilder.java
new file mode 100644
index 0000000000..2267e1d80a
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/TranslationFileCreationErrorBuilder.java
@@ -0,0 +1,60 @@
+/*-
+ * ============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;
+
+import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes
+ .TRANSLATION_FILE_CREATION;
+
+import org.openecomp.sdc.common.errors.ErrorCategory;
+import org.openecomp.sdc.common.errors.ErrorCode;
+import org.openecomp.sdc.versioning.dao.types.Version;
+
+/**
+ * The type Translation file creation error builder.
+ */
+public class TranslationFileCreationErrorBuilder {
+ private static final String TRANSLATION_FILE_CREATION_ERROR_MSG =
+ "Error while trying to create translation file from the package of vendor software "
+ + "product with Id %s and version %s.";
+ private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
+
+ /**
+ * Instantiates a new Translation file creation error builder.
+ *
+ * @param vendorSoftwareProductId the vendor software product id
+ * @param version the version
+ */
+ public TranslationFileCreationErrorBuilder(String vendorSoftwareProductId, Version version) {
+ builder.withId(TRANSLATION_FILE_CREATION);
+ builder.withCategory(ErrorCategory.SYSTEM);
+ builder.withMessage(String
+ .format(TRANSLATION_FILE_CREATION_ERROR_MSG, vendorSoftwareProductId, version.toString()));
+ }
+
+ /**
+ * Build error code.
+ *
+ * @return the error code
+ */
+ public ErrorCode build() {
+ return builder.build();
+ }
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/UploadInvalidErrorBuilder.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/UploadInvalidErrorBuilder.java
new file mode 100644
index 0000000000..0974af1c6a
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/UploadInvalidErrorBuilder.java
@@ -0,0 +1,82 @@
+/*-
+ * ============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;
+
+import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes
+ .UPLOAD_INVALID;
+
+import org.openecomp.sdc.common.errors.BaseErrorBuilder;
+import org.openecomp.sdc.common.errors.ErrorCategory;
+import org.openecomp.sdc.datatypes.error.ErrorMessage;
+import org.openecomp.sdc.versioning.dao.types.Version;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * The type Upload invalid error builder.
+ */
+public class UploadInvalidErrorBuilder extends BaseErrorBuilder {
+ private static final String UPLOAD_INVALID_DETAILED_MSG =
+ "File uploaded for vendor software product with Id %s and version %s is invalid: %s";
+ private static final String UPLOAD_INVALID_MSG = "Uploaded file is invalid";
+
+ /**
+ * Instantiates a new Upload invalid error builder.
+ *
+ * @param vendorSoftwareProductId the vendor software product id
+ * @param version the version
+ * @param errors the errors
+ */
+ public UploadInvalidErrorBuilder(String vendorSoftwareProductId, Version version,
+ Map<String, List<ErrorMessage>> errors) {
+ getErrorCodeBuilder().withId(UPLOAD_INVALID);
+ getErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION);
+ getErrorCodeBuilder().withMessage(String
+ .format(UPLOAD_INVALID_DETAILED_MSG, vendorSoftwareProductId, version.toString(),
+ toString(errors)));
+ }
+
+ /**
+ * Instantiates a new Upload invalid error builder.
+ */
+ public UploadInvalidErrorBuilder() {
+ getErrorCodeBuilder().withId(UPLOAD_INVALID);
+ getErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION);
+ getErrorCodeBuilder().withMessage(UPLOAD_INVALID_MSG);
+ }
+
+ private String toString(Map<String, List<ErrorMessage>> errors) {
+ StringBuffer sb = new StringBuffer();
+ errors.entrySet().stream()
+ .forEach(entry -> singleErrorToString(sb, entry.getKey(), entry.getValue()));
+ return sb.toString();
+ }
+
+ private void singleErrorToString(StringBuffer sb, String fileName, List<ErrorMessage> errors) {
+ sb.append(System.lineSeparator());
+ sb.append(fileName);
+ sb.append(sb.append(": "));
+ errors.stream().forEach(
+ error -> sb.append(error.getMessage()).append("[").append(error.getLevel()).append("], "));
+ }
+
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/VendorSoftwareProductErrorCodes.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/VendorSoftwareProductErrorCodes.java
new file mode 100644
index 0000000000..369e99d75f
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/VendorSoftwareProductErrorCodes.java
@@ -0,0 +1,48 @@
+/*-
+ * ============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;
+
+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 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";
+
+
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/VendorSoftwareProductInvalidErrorBuilder.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/VendorSoftwareProductInvalidErrorBuilder.java
new file mode 100644
index 0000000000..1439563b17
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/VendorSoftwareProductInvalidErrorBuilder.java
@@ -0,0 +1,60 @@
+/*-
+ * ============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;
+
+import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes.VSP_INVALID;
+
+import org.openecomp.sdc.common.errors.ErrorCategory;
+import org.openecomp.sdc.common.errors.ErrorCode;
+import org.openecomp.sdc.versioning.dao.types.Version;
+
+
+/**
+ * The type Vendor software product invalid error builder.
+ */
+public class VendorSoftwareProductInvalidErrorBuilder {
+ private static final String VSP_INVALID_MSG =
+ "Vendor software product with Id %s and version %s is invalid - does not contain "
+ + "service model.";
+ private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
+
+ /**
+ * Instantiates a new Vendor software product invalid error builder.
+ *
+ * @param vendorSoftwareProductId the vendor software product id
+ * @param version the version
+ */
+ public VendorSoftwareProductInvalidErrorBuilder(String vendorSoftwareProductId, Version version) {
+ builder.withId(VSP_INVALID);
+ builder.withCategory(ErrorCategory.APPLICATION);
+ builder
+ .withMessage(String.format(VSP_INVALID_MSG, vendorSoftwareProductId, version.toString()));
+ }
+
+ /**
+ * Build error code.
+ *
+ * @return the error code
+ */
+ public ErrorCode build() {
+ return builder.build();
+ }
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/VendorSoftwareProductNotFoundErrorBuilder.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/VendorSoftwareProductNotFoundErrorBuilder.java
new file mode 100644
index 0000000000..89fc08cdb0
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/VendorSoftwareProductNotFoundErrorBuilder.java
@@ -0,0 +1,54 @@
+/*-
+ * ============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;
+
+import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes.VSP_NOT_FOUND;
+
+import org.openecomp.sdc.common.errors.ErrorCategory;
+import org.openecomp.sdc.common.errors.ErrorCode;
+
+/**
+ * The type Vendor software product not found error builder.
+ */
+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));
+ }
+
+ /**
+ * Build error code.
+ *
+ * @return the error code
+ */
+ public ErrorCode build() {
+ return builder.build();
+ }
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java
new file mode 100644
index 0000000000..191c8d728c
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java
@@ -0,0 +1,1567 @@
+/*-
+ * ============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.impl;
+
+import static org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants.CSAR;
+import static org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants.GENERAL_COMPONENT_ID;
+import static org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants.UPLOAD_RAW_DATA;
+import static org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE;
+import static org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants.VSP_PACKAGE_ZIP;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.collections4.MapUtils;
+import org.openecomp.core.enrichment.EnrichmentArtifactsServiceFactory;
+import org.openecomp.core.enrichment.api.EnrichmentManager;
+import org.openecomp.core.enrichment.enrichmentartifacts.EnrichmentArtifactsService;
+import org.openecomp.core.enrichment.factory.EnrichmentManagerFactory;
+import org.openecomp.core.enrichment.types.ComponentArtifactType;
+import org.openecomp.core.model.dao.EnrichedServiceModelDao;
+import org.openecomp.core.model.dao.EnrichedServiceModelDaoFactory;
+import org.openecomp.core.model.dao.ServiceModelDao;
+import org.openecomp.core.model.dao.ServiceModelDaoFactory;
+import org.openecomp.core.model.types.ServiceElement;
+import org.openecomp.core.util.UniqueValueUtil;
+import org.openecomp.core.utilities.CommonMethods;
+import org.openecomp.core.utilities.file.FileContentHandler;
+import org.openecomp.core.utilities.file.FileUtils;
+import org.openecomp.core.utilities.json.JsonSchemaDataGenerator;
+import org.openecomp.core.utilities.json.JsonUtil;
+import org.openecomp.core.validation.api.ValidationManager;
+import org.openecomp.core.validation.errors.Messages;
+import org.openecomp.core.validation.types.MessageContainerUtil;
+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.ValidationErrorBuilder;
+import org.openecomp.sdc.common.utils.AsdcCommon;
+import org.openecomp.sdc.datatypes.error.ErrorLevel;
+import org.openecomp.sdc.datatypes.error.ErrorMessage;
+import org.openecomp.sdc.enrichment.impl.tosca.ComponentInfo;
+import org.openecomp.sdc.heat.datatypes.structure.HeatStructureTree;
+import org.openecomp.sdc.heat.datatypes.structure.ValidationStructureList;
+import org.openecomp.sdc.heat.services.tree.HeatTreeManager;
+import org.openecomp.sdc.heat.services.tree.HeatTreeManagerUtil;
+import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
+import org.openecomp.sdc.tosca.services.impl.ToscaFileOutputServiceCsarImpl;
+import org.openecomp.sdc.validation.utils.ValidationManagerUtil;
+import org.openecomp.sdc.vendorlicense.VendorLicenseArtifactServiceFactory;
+import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
+import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacadeFactory;
+import org.openecomp.sdc.vendorlicense.licenseartifacts.VendorLicenseArtifactsService;
+import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants;
+import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductManager;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentArtifactDao;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentArtifactDaoFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentArtifactEntity;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.PackageInfo;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessArtifactEntity;
+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.vendorsoftwareproduct.errors.CreatePackageForNonFinalVendorSoftwareProductErrorBuilder;
+import org.openecomp.sdc.vendorsoftwareproduct.errors.FileCreationErrorBuilder;
+import org.openecomp.sdc.vendorsoftwareproduct.errors.MibUploadErrorBuilder;
+import org.openecomp.sdc.vendorsoftwareproduct.errors.PackageInvalidErrorBuilder;
+import org.openecomp.sdc.vendorsoftwareproduct.errors.PackageNotFoundErrorBuilder;
+import org.openecomp.sdc.vendorsoftwareproduct.errors.TranslationFileCreationErrorBuilder;
+import org.openecomp.sdc.vendorsoftwareproduct.errors.UploadInvalidErrorBuilder;
+import org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes;
+import org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductInvalidErrorBuilder;
+import org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductNotFoundErrorBuilder;
+import org.openecomp.sdc.vendorsoftwareproduct.services.CompositionDataExtractor;
+import org.openecomp.sdc.vendorsoftwareproduct.services.CompositionEntityDataManager;
+import org.openecomp.sdc.vendorsoftwareproduct.services.SchemaGenerator;
+import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityResponse;
+import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityValidationData;
+import org.openecomp.sdc.vendorsoftwareproduct.types.QuestionnaireResponse;
+import org.openecomp.sdc.vendorsoftwareproduct.types.QuestionnaireValidationResult;
+import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
+import org.openecomp.sdc.vendorsoftwareproduct.types.ValidationResponse;
+import org.openecomp.sdc.vendorsoftwareproduct.types.VersionedVendorSoftwareProductInfo;
+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.Network;
+import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic;
+import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.ComponentCompositionSchemaInput;
+import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.ComponentQuestionnaireSchemaInput;
+import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.MibUploadStatus;
+import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.NetworkCompositionSchemaInput;
+import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.NicCompositionSchemaInput;
+import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.SchemaTemplateContext;
+import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.SchemaTemplateInput;
+import org.openecomp.sdc.vendorsoftwareproduct.util.CompilationUtil;
+import org.openecomp.sdc.vendorsoftwareproduct.util.VendorSoftwareProductUtils;
+import org.openecomp.sdc.versioning.VersioningManager;
+import org.openecomp.sdc.versioning.VersioningManagerFactory;
+import org.openecomp.sdc.versioning.VersioningUtil;
+import org.openecomp.sdc.versioning.dao.types.Version;
+import org.openecomp.sdc.versioning.dao.types.VersionStatus;
+import org.openecomp.sdc.versioning.errors.RequestedVersionInvalidErrorBuilder;
+import org.openecomp.sdc.versioning.types.VersionInfo;
+import org.openecomp.sdc.versioning.types.VersionableEntityAction;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+/**
+ * The type Vendor software product manager.
+ */
+public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductManager {
+
+ private static final String VSP_COMPOSITION_EDIT_NOT_ALLOWED_MSG =
+ "Composition entities may not be created / deleted for Vendor Software Product whose "
+ + "entities were uploaded";
+
+ private static final VersioningManager versioningManager =
+ VersioningManagerFactory.getInstance().createInterface();
+ private static final VendorSoftwareProductDao vendorSoftwareProductDao =
+ VendorSoftwareProductDaoFactory.getInstance().createInterface();
+ private static final VendorLicenseFacade vendorLicenseFacade =
+ VendorLicenseFacadeFactory.getInstance().createInterface();
+ private static final ComponentArtifactDao componentArtifactDao =
+ ComponentArtifactDaoFactory.getInstance().createInterface();
+ private static final ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDao =
+ ServiceModelDaoFactory.getInstance().createInterface();
+ private static final EnrichedServiceModelDao<ToscaServiceModel, ServiceElement>
+ enrichedServiceModelDao = EnrichedServiceModelDaoFactory.getInstance().createInterface();
+ private static VendorLicenseArtifactsService licenseArtifactsService =
+ VendorLicenseArtifactServiceFactory.getInstance().createInterface();
+ private static EnrichmentArtifactsService enrichmentArtifactsService =
+ EnrichmentArtifactsServiceFactory.getInstance().createInterface();
+
+
+ /**
+ * Instantiates a new Vendor software product manager.
+ */
+ public VendorSoftwareProductManagerImpl() {
+ vendorSoftwareProductDao.registerVersioning(VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE);
+ serviceModelDao.registerVersioning(VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE);
+ enrichedServiceModelDao.registerVersioning(VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE);
+ componentArtifactDao.registerVersioning(VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE);
+ }
+
+ private static List<ErrorCode> validateCompletedVendorSoftwareProduct(VspDetails vspDetails,
+ UploadDataEntity uploadData,
+ Object serviceModel) {
+ List<ErrorCode> errros = new ArrayList<>();
+
+ if (vspDetails.getName() == null) {
+ errros.add(createMissingMandatoryFieldError("name"));
+ }
+ if (vspDetails.getDescription() == null) {
+ errros.add(createMissingMandatoryFieldError("description"));
+ }
+ if (vspDetails.getVendorId() == null) {
+ errros.add(createMissingMandatoryFieldError("vendor Id"));
+ }
+ if (vspDetails.getVlmVersion() == null) {
+ errros.add(createMissingMandatoryFieldError(
+ "licensing version (in the format of: {integer}.{integer})"));
+ }
+ if (vspDetails.getCategory() == null) {
+ errros.add(createMissingMandatoryFieldError("category"));
+ }
+ if (vspDetails.getSubCategory() == null) {
+ errros.add(createMissingMandatoryFieldError("sub category"));
+ }
+ if (vspDetails.getLicenseAgreement() == null) {
+ errros.add(createMissingMandatoryFieldError("license agreement"));
+ }
+ if (CollectionUtils.isEmpty(vspDetails.getFeatureGroups())) {
+ errros.add(createMissingMandatoryFieldError("feature groups"));
+ }
+ if (uploadData == null || uploadData.getContentData() == null || serviceModel == null) {
+ errros.add(
+ new VendorSoftwareProductInvalidErrorBuilder(vspDetails.getId(), vspDetails.getVersion())
+ .build());
+ }
+
+ return errros.isEmpty() ? null : errros;
+ }
+
+ private static ErrorCode createMissingMandatoryFieldError(String fieldName) {
+ return new ValidationErrorBuilder("must be supplied", fieldName).build();
+ }
+
+ private static String getVspQuestionnaireSchema(SchemaTemplateInput schemaInput) {
+ return SchemaGenerator
+ .generate(SchemaTemplateContext.questionnaire, CompositionEntityType.vsp, schemaInput);
+ }
+
+ private static String getComponentQuestionnaireSchema(SchemaTemplateInput schemaInput) {
+ return SchemaGenerator
+ .generate(SchemaTemplateContext.questionnaire, CompositionEntityType.component,
+ schemaInput);
+ }
+
+ private static String getNicQuestionnaireSchema(SchemaTemplateInput schemaInput) {
+ return SchemaGenerator
+ .generate(SchemaTemplateContext.questionnaire, CompositionEntityType.nic, schemaInput);
+ }
+
+ private static void sortVspListByModificationTimeDescOrder(
+ List<VersionedVendorSoftwareProductInfo> vendorLicenseModels) {
+ Collections.sort(vendorLicenseModels, new Comparator<VersionedVendorSoftwareProductInfo>() {
+ @Override
+ public int compare(VersionedVendorSoftwareProductInfo o1,
+ VersionedVendorSoftwareProductInfo o2) {
+ return o2.getVspDetails().getWritetimeMicroSeconds()
+ .compareTo(o1.getVspDetails().getWritetimeMicroSeconds());
+ }
+ });
+ }
+
+ private boolean isManual(String vspId, Version version) {
+ return false;
+ }
+
+ @Override
+ public Version checkout(String vendorSoftwareProductId, String user) {
+ Version newVersion = versioningManager
+ .checkout(VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, vendorSoftwareProductId, user);
+ vendorSoftwareProductDao.updateVspLatestModificationTime(vendorSoftwareProductId, newVersion);
+ return newVersion;
+ }
+
+ @Override
+ public Version undoCheckout(String vendorSoftwareProductId, String user) {
+ Version newVersion = versioningManager
+ .undoCheckout(VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, vendorSoftwareProductId, user);
+ vendorSoftwareProductDao.updateVspLatestModificationTime(vendorSoftwareProductId, newVersion);
+ return newVersion;
+ }
+
+ @Override
+ public Version checkin(String vendorSoftwareProductId, String user) {
+ Version newVersion = versioningManager
+ .checkin(VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, vendorSoftwareProductId, user, null);
+ vendorSoftwareProductDao.updateVspLatestModificationTime(vendorSoftwareProductId, newVersion);
+ return newVersion;
+ }
+
+ @Override
+ public ValidationResponse submit(String vendorSoftwareProductId, String user) throws IOException {
+ VspDetails vspDetails = getVspDetails(vendorSoftwareProductId, null, user).getVspDetails();
+ UploadDataEntity uploadData = vendorSoftwareProductDao
+ .getUploadData(new UploadDataEntity(vendorSoftwareProductId, vspDetails.getVersion()));
+ ToscaServiceModel serviceModel =
+ serviceModelDao.getServiceModel(vendorSoftwareProductId, vspDetails.getVersion());
+ Version newVersion = null;
+
+ ValidationResponse validationResponse = new ValidationResponse();
+ validationResponse
+ .setVspErrors(validateCompletedVendorSoftwareProduct(vspDetails, uploadData, serviceModel));
+ validationResponse.setLicensingDataErrors(validateLicensingData(vspDetails));
+ validationResponse.setUploadDataErrors(validateUploadData(uploadData));
+ validationResponse.setQuestionnaireValidationResult(
+ validateQuestionnaire(vspDetails.getId(), vspDetails.getVersion()));
+ validationResponse.setCompilationErrors(
+ compile(vendorSoftwareProductId, vspDetails.getVersion(), serviceModel));
+
+ if (validationResponse.isValid()) {
+ newVersion = versioningManager
+ .submit(VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, vendorSoftwareProductId, user, null);
+ }
+ //vendorSoftwareProductDao.updateVspLatestModificationTime(vendorSoftwareProductId, newVersion);
+ return validationResponse;
+ }
+
+ private Map<String, List<ErrorMessage>> compile(String vendorSoftwareProductId, Version version,
+ ToscaServiceModel serviceModel) {
+ Collection<ComponentEntity> components = listComponents(vendorSoftwareProductId, version);
+ if (serviceModel == null) {
+ return null;
+ }
+ if (CollectionUtils.isEmpty(components)) {
+ enrichedServiceModelDao.storeServiceModel(vendorSoftwareProductId, version, serviceModel);
+ return null;
+ }
+ EnrichmentManager<ToscaServiceModel> enrichmentManager =
+ EnrichmentManagerFactory.getInstance().createInterface();
+ enrichmentManager.initInput(vendorSoftwareProductId, version);
+ enrichmentManager.addModel(serviceModel);
+
+ ComponentInfo componentInfo = new ComponentInfo();
+ Map<String, List<ErrorMessage>> compileErrors = new HashMap<>();
+ CompilationUtil.addMonitoringInfo(componentInfo, compileErrors);
+ for (ComponentEntity componentEntity : components) {
+ ComponentInfo currentEntityComponentInfo = new ComponentInfo();
+ currentEntityComponentInfo.setCeilometerInfo(componentInfo.getCeilometerInfo());
+ CompilationUtil
+ .addMibInfo(vendorSoftwareProductId, version, componentEntity, currentEntityComponentInfo,
+ compileErrors);
+ enrichmentManager.addEntityInput(componentEntity.getComponentCompositionData().getName(),
+ currentEntityComponentInfo);
+
+ }
+ Map<String, List<ErrorMessage>> enrichErrors;
+ enrichErrors = enrichmentManager.enrich();
+ enrichedServiceModelDao
+ .storeServiceModel(vendorSoftwareProductId, version, enrichmentManager.getModel());
+ if (enrichErrors != null) {
+ compileErrors.putAll(enrichErrors);
+ }
+
+ vendorSoftwareProductDao.updateVspLatestModificationTime(vendorSoftwareProductId, version);
+
+ return compileErrors;
+ }
+
+ private Collection<ErrorCode> validateLicensingData(VspDetails vspDetails) {
+ if (vspDetails.getVendorId() == null || vspDetails.getVlmVersion() == null
+ || vspDetails.getLicenseAgreement() == null
+ || CollectionUtils.isEmpty(vspDetails.getFeatureGroups())) {
+ return null;
+ }
+ return vendorLicenseFacade
+ .validateLicensingData(vspDetails.getVendorId(), vspDetails.getVlmVersion(),
+ vspDetails.getLicenseAgreement(), vspDetails.getFeatureGroups());
+ }
+
+ @Override
+ public VspDetails createNewVsp(VspDetails vspDetails, String user) {
+ UniqueValueUtil.validateUniqueValue(
+ VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME,
+ vspDetails.getName());
+ vspDetails.setId(CommonMethods.nextUuId());
+
+ // vspDetails.setLastModificationTime(new Date());
+
+ Version version = versioningManager
+ .create(VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, vspDetails.getId(), user);
+ vspDetails.setVersion(version);
+
+ // vspDetails.setLastModificationTime(new Date());
+
+ vendorSoftwareProductDao.createVendorSoftwareProductInfo(vspDetails);
+ vendorSoftwareProductDao.updateQuestionnaire(vspDetails.getId(), version,
+ new JsonSchemaDataGenerator(getVspQuestionnaireSchema(null)).generateData());
+ UniqueValueUtil
+ .createUniqueValue(VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME,
+ vspDetails.getName());
+
+ return vspDetails;
+ }
+
+ @Override
+ public List<VersionedVendorSoftwareProductInfo> getVspList(String versionFilter, String user) {
+ Map<String, VersionInfo> idToVersionsInfo = versioningManager
+ .listEntitiesVersionInfo(VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, user,
+ VersionableEntityAction.Read);
+
+ List<VersionedVendorSoftwareProductInfo> vsps = new ArrayList<>();
+ for (Map.Entry<String, VersionInfo> entry : idToVersionsInfo.entrySet()) {
+ VersionInfo versionInfo = entry.getValue();
+ if (versionFilter != null && versionFilter.equals(VersionStatus.Final.name())) {
+ if (versionInfo.getLatestFinalVersion() == null) {
+ continue;
+ }
+ versionInfo.setActiveVersion(versionInfo.getLatestFinalVersion());
+ versionInfo.setStatus(VersionStatus.Final);
+ versionInfo.setLockingUser(null);
+ }
+
+ VspDetails vsp = vendorSoftwareProductDao.getVendorSoftwareProductInfo(
+ new VspDetails(entry.getKey(), entry.getValue().getActiveVersion()));
+ if (vsp != null) {
+ vsp.setValidationDataStructure(null);
+ vsps.add(new VersionedVendorSoftwareProductInfo(vsp, entry.getValue()));
+ }
+ }
+
+ sortVspListByModificationTimeDescOrder(vsps);
+ return vsps;
+ }
+
+ @Override
+ public void updateVsp(VspDetails vspDetails, String user) {
+ Version activeVersion =
+ getVersionInfo(vspDetails.getId(), VersionableEntityAction.Write, user).getActiveVersion();
+ vspDetails.setVersion(activeVersion);
+ // vspDetails.setLastModificationTime(new Date());
+
+ VspDetails retrieved = vendorSoftwareProductDao.getVendorSoftwareProductInfo(vspDetails);
+ vspDetails.setValidationData(retrieved.getValidationData());
+ UniqueValueUtil
+ .updateUniqueValue(VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME,
+ retrieved.getName(), vspDetails.getName());
+ vendorSoftwareProductDao.updateVendorSoftwareProductInfo(vspDetails);
+
+ vendorSoftwareProductDao.updateVspLatestModificationTime(vspDetails.getId(), activeVersion);
+ }
+
+ @Override
+ public VersionedVendorSoftwareProductInfo getVspDetails(String vspId, Version version,
+ String user) {
+ VersionInfo versionInfo = getVersionInfo(vspId, VersionableEntityAction.Read, user);
+ if (version == null) {
+ version = versionInfo.getActiveVersion();
+ } else {
+ if (!versionInfo.getViewableVersions().contains(version)) {
+ throw new CoreException(new RequestedVersionInvalidErrorBuilder().build());
+ }
+ }
+
+ VspDetails vendorSoftwareProductInfo =
+ vendorSoftwareProductDao.getVendorSoftwareProductInfo(new VspDetails(vspId, version));
+ if (vendorSoftwareProductInfo == null) {
+ throw new CoreException(new VendorSoftwareProductNotFoundErrorBuilder(vspId).build());
+ }
+ return new VersionedVendorSoftwareProductInfo(vendorSoftwareProductInfo, versionInfo);
+ }
+
+ @Override
+ public void deleteVsp(String vspId, String user) {
+ throw new UnsupportedOperationException("Unsupported operation for 1607 release.");
+ }
+
+ @Override
+ public UploadFileResponse uploadFile(String vspId, InputStream heatFileToUpload, String user) {
+ Version activeVersion =
+ getVersionInfo(vspId, VersionableEntityAction.Write, user).getActiveVersion();
+ UploadFileResponse uploadFileResponse = new UploadFileResponse();
+
+ if (heatFileToUpload == null) {
+ uploadFileResponse.addStructureError(AsdcCommon.UPLOAD_FILE,
+ new ErrorMessage(ErrorLevel.ERROR,
+ Messages.NO_ZIP_FILE_WAS_UPLOADED_OR_ZIP_NOT_EXIST.getErrorMessage()));
+ return uploadFileResponse;
+ }
+
+ InputStream uploadedFileData;
+ FileContentHandler fileContentMap;
+ Map<String, List<ErrorMessage>> errors = new HashMap<>();
+ try {
+ fileContentMap = getContent(heatFileToUpload, errors);
+ if (!errors.isEmpty()) {
+ return addStructureErrorsToResponse(uploadFileResponse, errors);
+ }
+
+ uploadedFileData = fileContentMap.getFileContent(UPLOAD_RAW_DATA);
+ fileContentMap.remove(UPLOAD_RAW_DATA);
+
+ ValidationManagerUtil.handleMissingManifest(fileContentMap, errors);
+ if (!errors.isEmpty()) {
+ return addStructureErrorsToResponse(uploadFileResponse, errors);
+ }
+
+ } catch (CoreException ce) {
+ ErrorMessage.ErrorMessageUtil.addMessage(AsdcCommon.UPLOAD_FILE, errors)
+ .add(new ErrorMessage(ErrorLevel.ERROR, ce.getMessage()));
+ return addStructureErrorsToResponse(uploadFileResponse, errors);
+ }
+
+ HeatStructureTree tree = createAndValidateHeatTree(uploadFileResponse, fileContentMap);
+
+ deleteUploadDataAndContent(vspId, activeVersion);
+ saveHotData(vspId, activeVersion, uploadedFileData, fileContentMap, tree);
+
+ vendorSoftwareProductDao.updateVspLatestModificationTime(vspId, activeVersion);
+
+ ToscaServiceModel toscaServiceModel =
+ VendorSoftwareProductUtils.loadAndTranslateTemplateData(fileContentMap)
+ .getToscaServiceModel();
+ if (toscaServiceModel != null) {
+ serviceModelDao.storeServiceModel(vspId, activeVersion, toscaServiceModel);
+ saveCompositionData(vspId, activeVersion,
+ CompositionDataExtractor.extractServiceCompositionData(toscaServiceModel));
+ }
+
+ return uploadFileResponse;
+ }
+
+ private UploadFileResponse addStructureErrorsToResponse(UploadFileResponse uploadFileResponse,
+ Map<String, List<ErrorMessage>> errors) {
+ uploadFileResponse.addStructureErrors(errors);
+ return uploadFileResponse;
+ }
+
+ private HeatStructureTree createAndValidateHeatTree(UploadFileResponse uploadFileResponse,
+ FileContentHandler fileContentMap) {
+ VendorSoftwareProductUtils.addFileNamesToUploadFileResponse(fileContentMap, uploadFileResponse);
+ Map<String, List<ErrorMessage>> validationErrors =
+ ValidationManagerUtil.initValidationManager(fileContentMap).validate();
+ uploadFileResponse.getErrors().putAll(validationErrors);
+
+ HeatTreeManager heatTreeManager = HeatTreeManagerUtil.initHeatTreeManager(fileContentMap);
+ heatTreeManager.createTree();
+ heatTreeManager.addErrors(validationErrors);
+ return heatTreeManager.getTree();
+ }
+
+ private void saveHotData(String vspId, Version activeVersion, InputStream uploadedFileData,
+ FileContentHandler fileContentMap, HeatStructureTree tree) {
+ Map<String, Object> manifestAsMap = (Map<String, Object>) JsonUtil
+ .json2Object(fileContentMap.getFileContent(AsdcCommon.MANIFEST_NAME), Map.class);
+
+ UploadDataEntity uploadData = new UploadDataEntity(vspId, activeVersion);
+ uploadData.setPackageName((String) manifestAsMap.get("name"));
+ uploadData.setPackageVersion((String) manifestAsMap.get("version"));
+ uploadData.setContentData(ByteBuffer.wrap(FileUtils.toByteArray(uploadedFileData)));
+ uploadData.setValidationDataStructure(new ValidationStructureList(tree));
+ vendorSoftwareProductDao.updateUploadData(uploadData);
+ }
+
+ private FileContentHandler getContent(InputStream heatFileToUpload,
+ Map<String, List<ErrorMessage>> errors) {
+ FileContentHandler contentMap = null;
+ byte[] uploadedFileData;
+ try {
+ uploadedFileData = FileUtils.toByteArray(heatFileToUpload);
+ VendorSoftwareProductUtils.validateRawZipData(uploadedFileData, errors);
+ contentMap = VendorSoftwareProductUtils.loadUploadFileContent(uploadedFileData);
+ VendorSoftwareProductUtils.validateContentZipData(contentMap, errors);
+ contentMap.addFile(UPLOAD_RAW_DATA, uploadedFileData);
+ } catch (IOException e0) {
+ ErrorMessage.ErrorMessageUtil.addMessage(AsdcCommon.UPLOAD_FILE, errors)
+ .add(new ErrorMessage(ErrorLevel.ERROR, Messages.INVALID_ZIP_FILE.getErrorMessage()));
+ }
+ return contentMap;
+ }
+
+ private void validateMibZipContent(String vspId, Version version, byte[] uploadedFileData,
+ Map<String, List<ErrorMessage>> errors) {
+ FileContentHandler contentMap;
+ try {
+ contentMap = VendorSoftwareProductUtils.loadUploadFileContent(uploadedFileData);
+ VendorSoftwareProductUtils.validateContentZipData(contentMap, errors);
+ } catch (IOException e0) {
+ throw new CoreException(
+ new MibUploadErrorBuilder(vspId, version, Messages.INVALID_ZIP_FILE.getErrorMessage())
+ .build());
+ }
+ }
+
+ @Override
+ public List<PackageInfo> listPackages(String category, String subCategory) {
+ return vendorSoftwareProductDao.listPackages(category, subCategory);
+ }
+
+ @Override
+ public File getTranslatedFile(String vspId, Version version, String user) {
+ VersionInfo versionInfo = getVersionInfo(vspId, VersionableEntityAction.Read, user);
+ if (version == null) {
+ if (versionInfo.getLatestFinalVersion() == null) {
+ throw new CoreException(new PackageNotFoundErrorBuilder(vspId).build());
+ }
+ version = versionInfo.getLatestFinalVersion();
+ } else {
+ if (!version.isFinal() || !versionInfo.getViewableVersions().contains(version)) {
+ throw new CoreException(new RequestedVersionInvalidErrorBuilder().build());
+ }
+ }
+
+ PackageInfo packageInfo =
+ vendorSoftwareProductDao.getPackageInfo(new PackageInfo(vspId, version));
+ if (packageInfo == null) {
+ throw new CoreException(new PackageNotFoundErrorBuilder(vspId, version).build());
+ }
+
+ ByteBuffer translatedFileBuffer = packageInfo.getTranslatedFile();
+ if (translatedFileBuffer == null) {
+ throw new CoreException(new PackageInvalidErrorBuilder(vspId, version).build());
+ }
+
+ File translatedFile = new File(VSP_PACKAGE_ZIP);
+
+ try {
+ FileOutputStream fos = new FileOutputStream(translatedFile);
+ fos.write(translatedFileBuffer.array());
+ fos.close();
+ } catch (IOException e0) {
+ throw new CoreException(new TranslationFileCreationErrorBuilder(vspId, version).build(), e0);
+ }
+
+ return translatedFile;
+ }
+
+ @Override
+ public File getLatestHeatPackage(String vspId,
+ String user) { //todo remove the writing to file system..
+ VersionInfo versionInfo = getVersionInfo(vspId, VersionableEntityAction.Read, user);
+ Version version = versionInfo.getActiveVersion();
+
+ UploadDataEntity uploadData =
+ vendorSoftwareProductDao.getUploadData(new UploadDataEntity(vspId, version));
+
+ ByteBuffer contentData = uploadData.getContentData();
+ if (contentData == null) {
+ return null;
+ }
+
+ File heatPkgFile = new File(String.format("heats-for-%s.zip", vspId));
+
+ try {
+ FileOutputStream fos = new FileOutputStream(heatPkgFile);
+ fos.write(contentData.array());
+ fos.close();
+ } catch (IOException e0) {
+ throw new CoreException(new FileCreationErrorBuilder(vspId).build(), e0);
+ }
+ return heatPkgFile;
+ }
+
+ @Override
+ public PackageInfo createPackage(String vspId, String user) throws IOException {
+ VersionInfo versionInfo = getVersionInfo(vspId, VersionableEntityAction.Read, user);
+ Version activeVersion = versionInfo.getActiveVersion();
+ if (!activeVersion.isFinal()) {
+ throw new CoreException(
+ new CreatePackageForNonFinalVendorSoftwareProductErrorBuilder(vspId, activeVersion)
+ .build());
+ }
+
+ ToscaServiceModel toscaServiceModel =
+ enrichedServiceModelDao.getServiceModel(vspId, activeVersion);
+ VspDetails vspDetails =
+ vendorSoftwareProductDao.getVendorSoftwareProductInfo(new VspDetails(vspId, activeVersion));
+ Version vlmVersion = vspDetails.getVlmVersion();
+
+ PackageInfo packageInfo = createPackageInfo(vspId, vspDetails);
+
+ ToscaFileOutputServiceCsarImpl toscaServiceTemplateServiceCsar =
+ new ToscaFileOutputServiceCsarImpl();
+ FileContentHandler licenseArtifacts = licenseArtifactsService
+ .createLicenseArtifacts(vspDetails.getId(), vspDetails.getVendorId(), vlmVersion,
+ vspDetails.getFeatureGroups(), user);
+ //todo add tosca validation here
+ packageInfo.setTranslatedFile(ByteBuffer.wrap(
+ toscaServiceTemplateServiceCsar.createOutputFile(toscaServiceModel, licenseArtifacts)));
+
+ vendorSoftwareProductDao.insertPackageDetails(packageInfo);
+
+ vendorSoftwareProductDao.updateVspLatestModificationTime(vspId, vspDetails.getVersion());
+
+ return packageInfo;
+ }
+
+ private PackageInfo createPackageInfo(String vspId, VspDetails vspDetails) {
+ PackageInfo packageInfo = new PackageInfo();
+ packageInfo.setVspId(vspId);
+ packageInfo.setVersion(vspDetails.getVersion());
+ packageInfo.setDisplayName(vspDetails.getPackageName());
+ packageInfo.setVspName(vspDetails.getName());
+ packageInfo.setVspDescription(vspDetails.getDescription());
+ packageInfo.setCategory(vspDetails.getCategory());
+ packageInfo.setSubCategory(vspDetails.getSubCategory());
+ packageInfo.setVendorName(vspDetails.getVendorName());
+ packageInfo.setPackageType(CSAR);
+ packageInfo.setVendorRelease("1.0"); //todo TBD
+ return packageInfo;
+ }
+
+ @Override
+ public QuestionnaireResponse getVspQuestionnaire(String vspId, Version version, String user) {
+ version = VersioningUtil
+ .resolveVersion(version, getVersionInfo(vspId, VersionableEntityAction.Read, user));
+
+ QuestionnaireResponse questionnaireResponse = new QuestionnaireResponse();
+ questionnaireResponse.setData(getVspQuestionnaire(vspId, version).getQuestionnaireData());
+ questionnaireResponse.setSchema(getVspQuestionnaireSchema(null));
+
+ return questionnaireResponse;
+ }
+
+ private VspQuestionnaireEntity getVspQuestionnaire(String vspId, Version version) {
+ VspQuestionnaireEntity retrieved = vendorSoftwareProductDao.getQuestionnaire(vspId, version);
+ VersioningUtil.validateEntityExistence(retrieved, new VspQuestionnaireEntity(vspId, version),
+ VspDetails.ENTITY_TYPE);
+ return retrieved;
+ }
+
+ @Override
+ public void updateVspQuestionnaire(String vspId, String questionnaireData, String user) {
+ Version activeVersion =
+ getVersionInfo(vspId, VersionableEntityAction.Write, user).getActiveVersion();
+
+ vendorSoftwareProductDao.updateVspLatestModificationTime(vspId, activeVersion);
+
+ vendorSoftwareProductDao.updateQuestionnaire(vspId, activeVersion, questionnaireData);
+ }
+
+ @Override
+ public Collection<NetworkEntity> listNetworks(String vspId, Version version, String user) {
+ version = VersioningUtil
+ .resolveVersion(version, getVersionInfo(vspId, VersionableEntityAction.Read, user));
+ return listNetworks(vspId, version);
+ }
+
+ private Collection<NetworkEntity> listNetworks(String vspId, Version version) {
+ return vendorSoftwareProductDao.listNetworks(vspId, version);
+ }
+
+ @Override
+ public NetworkEntity createNetwork(NetworkEntity network, String user) {
+ Version activeVersion =
+ getVersionInfo(network.getVspId(), VersionableEntityAction.Write, user).getActiveVersion();
+ network.setVersion(activeVersion);
+ if (!isManual(network.getVspId(), activeVersion)) {
+ throw new CoreException(
+ new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION)
+ .withId(VendorSoftwareProductErrorCodes.VSP_COMPOSITION_EDIT_NOT_ALLOWED)
+ .withMessage(VSP_COMPOSITION_EDIT_NOT_ALLOWED_MSG).build());
+ }
+
+ vendorSoftwareProductDao.updateVspLatestModificationTime(network.getVspId(), activeVersion);
+ return null;
+ }
+
+ private NetworkEntity createNetwork(NetworkEntity network) {
+ network.setId(CommonMethods.nextUuId());
+ vendorSoftwareProductDao.createNetwork(network);
+
+ return network;
+ }
+
+ @Override
+ public CompositionEntityValidationData updateNetwork(NetworkEntity network, String user) {
+ Version activeVersion =
+ getVersionInfo(network.getVspId(), VersionableEntityAction.Write, user).getActiveVersion();
+ network.setVersion(activeVersion);
+ NetworkEntity retrieved = getNetwork(network.getVspId(), activeVersion, network.getId());
+
+ NetworkCompositionSchemaInput schemaInput = new NetworkCompositionSchemaInput();
+ schemaInput.setManual(isManual(network.getVspId(), activeVersion));
+ schemaInput.setNetwork(retrieved.getNetworkCompositionData());
+
+ CompositionEntityValidationData validationData = CompositionEntityDataManager
+ .validateEntity(network, SchemaTemplateContext.composition, schemaInput);
+ if (CollectionUtils.isEmpty(validationData.getErrors())) {
+ vendorSoftwareProductDao.updateNetwork(network);
+ }
+
+ vendorSoftwareProductDao.updateVspLatestModificationTime(network.getVspId(), activeVersion);
+
+ return validationData;
+ }
+
+ @Override
+ public CompositionEntityResponse<Network> getNetwork(String vspId, Version version,
+ String networkId, String user) {
+ version = VersioningUtil
+ .resolveVersion(version, getVersionInfo(vspId, VersionableEntityAction.Read, user));
+ NetworkEntity networkEntity = getNetwork(vspId, version, networkId);
+ Network network = networkEntity.getNetworkCompositionData();
+
+ NetworkCompositionSchemaInput schemaInput = new NetworkCompositionSchemaInput();
+ schemaInput.setManual(isManual(vspId, version));
+ schemaInput.setNetwork(network);
+
+ CompositionEntityResponse<Network> response = new CompositionEntityResponse<>();
+ response.setId(networkId);
+ response.setData(network);
+ response.setSchema(SchemaGenerator
+ .generate(SchemaTemplateContext.composition, CompositionEntityType.network, schemaInput));
+
+ return response;
+ }
+
+ private NetworkEntity getNetwork(String vspId, Version version, String networkId) {
+ NetworkEntity retrieved = vendorSoftwareProductDao.getNetwork(vspId, version, networkId);
+ VersioningUtil.validateEntityExistence(retrieved, new NetworkEntity(vspId, version, networkId),
+ VspDetails.ENTITY_TYPE);
+ return retrieved;
+ }
+
+ @Override
+ public void deleteNetwork(String vspId, String networkId, String user) {
+ Version activeVersion =
+ getVersionInfo(vspId, VersionableEntityAction.Write, user).getActiveVersion();
+ if (!isManual(vspId, activeVersion)) {
+ throw new CoreException(
+ new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION)
+ .withId(VendorSoftwareProductErrorCodes.VSP_COMPOSITION_EDIT_NOT_ALLOWED)
+ .withMessage(VSP_COMPOSITION_EDIT_NOT_ALLOWED_MSG).build());
+ }
+
+ vendorSoftwareProductDao.updateVspLatestModificationTime(vspId, activeVersion);
+ }
+
+ @Override
+ public QuestionnaireResponse getComponentQuestionnaire(String vspId, Version version,
+ String componentId, String user) {
+ version = VersioningUtil
+ .resolveVersion(version, getVersionInfo(vspId, VersionableEntityAction.Read, user));
+
+ QuestionnaireResponse questionnaireResponse = new QuestionnaireResponse();
+ questionnaireResponse.setData(getComponent(vspId, version, componentId).getQuestionnaireData());
+ List<String> nicNames = listNics(vspId, version, componentId).stream()
+ .map(nic -> nic.getNicCompositionData().getName()).collect(Collectors.toList());
+ questionnaireResponse.setSchema(getComponentQuestionnaireSchema(
+ new ComponentQuestionnaireSchemaInput(nicNames,
+ JsonUtil.json2Object(questionnaireResponse.getData(), Map.class))));
+
+ return questionnaireResponse;
+ }
+
+ @Override
+ public void updateComponentQuestionnaire(String vspId, String componentId,
+ String questionnaireData, String user) {
+ Version activeVersion =
+ getVersionInfo(vspId, VersionableEntityAction.Write, user).getActiveVersion();
+ getComponent(vspId, activeVersion, componentId);
+
+ vendorSoftwareProductDao
+ .updateComponentQuestionnaire(vspId, activeVersion, componentId, questionnaireData);
+
+ vendorSoftwareProductDao.updateVspLatestModificationTime(vspId, activeVersion);
+ }
+
+ @Override
+ public Collection<ComponentEntity> listComponents(String vspId, Version version, String user) {
+ version = VersioningUtil
+ .resolveVersion(version, getVersionInfo(vspId, VersionableEntityAction.Read, user));
+ return listComponents(vspId, version);
+ }
+
+ private Collection<ComponentEntity> listComponents(String vspId, Version version) {
+ return vendorSoftwareProductDao.listComponents(vspId, version);
+ }
+
+ @Override
+ public void deleteComponents(String vspId, String user) {
+ Version activeVersion =
+ getVersionInfo(vspId, VersionableEntityAction.Write, user).getActiveVersion();
+ if (!isManual(vspId, activeVersion)) {
+ throw new CoreException(
+ new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION)
+ .withId(VendorSoftwareProductErrorCodes.VSP_COMPOSITION_EDIT_NOT_ALLOWED)
+ .withMessage(VSP_COMPOSITION_EDIT_NOT_ALLOWED_MSG).build());
+ }
+
+ vendorSoftwareProductDao.updateVspLatestModificationTime(vspId, activeVersion);
+ }
+
+ @Override
+ public ComponentEntity createComponent(ComponentEntity component, String user) {
+ Version activeVersion =
+ getVersionInfo(component.getVspId(), VersionableEntityAction.Write, user)
+ .getActiveVersion();
+ component.setVersion(activeVersion);
+
+ if (!isManual(component.getVspId(), activeVersion)) {
+ throw new CoreException(
+ new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION)
+ .withId(VendorSoftwareProductErrorCodes.VSP_COMPOSITION_EDIT_NOT_ALLOWED)
+ .withMessage(VSP_COMPOSITION_EDIT_NOT_ALLOWED_MSG).build());
+
+ }
+
+ /* ComponentCompositionSchemaInput schemaInput = new ComponentCompositionSchemaInput();
+ schemaInput.setManual(true);
+ CompositionEntityValidationData validationData = CompositionEntityDataManager
+ .validateEntity(component, SchemaTemplateContext.composition, schemaInput);
+ if (CollectionUtils.isEmpty(validationData.getErrors())) {
+ return createComponent(component);
+ }
+ return validationData;*/
+
+ vendorSoftwareProductDao.updateVspLatestModificationTime(component.getVspId(), activeVersion);
+
+ return null;
+ }
+
+ private ComponentEntity createComponent(ComponentEntity component) {
+ component.setId(CommonMethods.nextUuId());
+ component.setQuestionnaireData(
+ new JsonSchemaDataGenerator(getComponentQuestionnaireSchema(null)).generateData());
+
+ vendorSoftwareProductDao.createComponent(component);
+
+ return component;
+ }
+
+ @Override
+ public CompositionEntityResponse<ComponentData> getComponent(String vspId, Version version,
+ String componentId, String user) {
+ version = VersioningUtil
+ .resolveVersion(version, getVersionInfo(vspId, VersionableEntityAction.Read, user));
+ ComponentEntity componentEntity = getComponent(vspId, version, componentId);
+ ComponentData component = componentEntity.getComponentCompositionData();
+
+ ComponentCompositionSchemaInput schemaInput = new ComponentCompositionSchemaInput();
+ schemaInput.setManual(isManual(vspId, version));
+ schemaInput.setComponent(component);
+
+ CompositionEntityResponse<ComponentData> response = new CompositionEntityResponse<>();
+ response.setId(componentId);
+ response.setData(component);
+ response.setSchema(SchemaGenerator
+ .generate(SchemaTemplateContext.composition, CompositionEntityType.component, schemaInput));
+
+ return response;
+ }
+
+ private ComponentEntity getComponent(String vspId, Version version, String componentId) {
+ ComponentEntity retrieved = vendorSoftwareProductDao.getComponent(vspId, version, componentId);
+ VersioningUtil
+ .validateEntityExistence(retrieved, new ComponentEntity(vspId, version, componentId),
+ VspDetails.ENTITY_TYPE);
+ return retrieved;
+ }
+
+ @Override
+ public CompositionEntityValidationData updateComponent(ComponentEntity component, String user) {
+ Version activeVersion =
+ getVersionInfo(component.getVspId(), VersionableEntityAction.Write, user)
+ .getActiveVersion();
+ component.setVersion(activeVersion);
+ ComponentEntity retrieved =
+ getComponent(component.getVspId(), activeVersion, component.getId());
+
+ ComponentCompositionSchemaInput schemaInput = new ComponentCompositionSchemaInput();
+ schemaInput.setManual(isManual(component.getVspId(), activeVersion));
+ schemaInput.setComponent(retrieved.getComponentCompositionData());
+
+ CompositionEntityValidationData validationData = CompositionEntityDataManager
+ .validateEntity(component, SchemaTemplateContext.composition, schemaInput);
+ if (CollectionUtils.isEmpty(validationData.getErrors())) {
+ vendorSoftwareProductDao.updateComponent(component);
+ }
+
+ vendorSoftwareProductDao.updateVspLatestModificationTime(component.getVspId(), activeVersion);
+
+ return validationData;
+ }
+
+ @Override
+ public void deleteComponent(String vspId, String componentId, String user) {
+ Version activeVersion =
+ getVersionInfo(vspId, VersionableEntityAction.Write, user).getActiveVersion();
+ if (!isManual(vspId, activeVersion)) {
+ throw new CoreException(
+ new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION)
+ .withId(VendorSoftwareProductErrorCodes.VSP_COMPOSITION_EDIT_NOT_ALLOWED)
+ .withMessage(VSP_COMPOSITION_EDIT_NOT_ALLOWED_MSG).build());
+ }
+
+ vendorSoftwareProductDao.updateVspLatestModificationTime(vspId, activeVersion);
+ }
+
+ @Override
+ public Collection<org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity> listProcesses(
+ String vspId, Version version, String componentId,
+ String user) {
+ version = VersioningUtil
+ .resolveVersion(version, getVersionInfo(vspId, VersionableEntityAction.Read, user));
+ if (!GENERAL_COMPONENT_ID.equals(componentId)) {
+ getComponent(vspId, version, componentId);
+ }
+ return vendorSoftwareProductDao.listProcesses(vspId, version, componentId);
+ }
+
+ @Override
+ public void deleteProcesses(String vspId, String componentId, String user) {
+ Version activeVersion =
+ getVersionInfo(vspId, VersionableEntityAction.Write, user).getActiveVersion();
+ if (!GENERAL_COMPONENT_ID.equals(componentId)) {
+ getComponent(vspId, activeVersion, componentId);
+ }
+
+ Collection<org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity> processes =
+ vendorSoftwareProductDao.listProcesses(vspId, activeVersion, componentId);
+ for (org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity process : processes) {
+ UniqueValueUtil.deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.PROCESS_NAME,
+ process.getVspId(), process.getVersion().toString(), process.getComponentId(),
+ process.getName());
+ }
+
+ vendorSoftwareProductDao.deleteProcesses(vspId, activeVersion, componentId);
+
+ vendorSoftwareProductDao.updateVspLatestModificationTime(vspId, activeVersion);
+ }
+
+ @Override
+ public org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity createProcess(
+ org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity process, String user) {
+ Version activeVersion =
+ getVersionInfo(process.getVspId(), VersionableEntityAction.Write, user).getActiveVersion();
+ process.setVersion(activeVersion);
+ UniqueValueUtil.validateUniqueValue(VendorSoftwareProductConstants.UniqueValues.PROCESS_NAME,
+ process.getVspId(), process.getVersion().toString(), process.getComponentId(),
+ process.getName());
+ process.setId(CommonMethods.nextUuId());
+ if (!GENERAL_COMPONENT_ID.equals(process.getComponentId())) {
+ getComponent(process.getVspId(), activeVersion, process.getComponentId());
+ }
+
+ vendorSoftwareProductDao.createProcess(process);
+ UniqueValueUtil.createUniqueValue(VendorSoftwareProductConstants.UniqueValues.PROCESS_NAME,
+ process.getVspId(), process.getVersion().toString(), process.getComponentId(),
+ process.getName());
+
+ vendorSoftwareProductDao.updateVspLatestModificationTime(process.getVspId(), activeVersion);
+ return process;
+ }
+
+ @Override
+ public org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity getProcess(String vspId,
+ Version version,
+ String componentId,
+ String processId,
+ String user) {
+ version = VersioningUtil
+ .resolveVersion(version, getVersionInfo(vspId, VersionableEntityAction.Read, user));
+ org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity retrieved =
+ vendorSoftwareProductDao.getProcess(vspId, version, componentId, processId);
+ validateProcessExistence(vspId, version, componentId, processId, retrieved);
+ return retrieved;
+ }
+
+ @Override
+ public void updateProcess(org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity process,
+ String user) {
+ Version activeVersion =
+ getVersionInfo(process.getVspId(), VersionableEntityAction.Write, user).getActiveVersion();
+ process.setVersion(activeVersion);
+
+ org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity retrieved =
+ vendorSoftwareProductDao
+ .getProcess(process.getVspId(), activeVersion, process.getComponentId(),
+ process.getId());
+ validateProcessExistence(process.getVspId(), activeVersion, process.getComponentId(),
+ process.getId(), retrieved);
+
+ UniqueValueUtil.updateUniqueValue(VendorSoftwareProductConstants.UniqueValues.PROCESS_NAME,
+ retrieved.getName(), process.getName(), process.getVspId(), process.getVersion().toString(),
+ process.getComponentId());
+ vendorSoftwareProductDao.updateProcess(process);
+
+ vendorSoftwareProductDao.updateVspLatestModificationTime(process.getVspId(), activeVersion);
+ }
+
+ @Override
+ public void deleteProcess(String vspId, String componentId, String processId, String user) {
+ Version activeVersion =
+ getVersionInfo(vspId, VersionableEntityAction.Write, user).getActiveVersion();
+ org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity retrieved =
+ vendorSoftwareProductDao.getProcess(vspId, activeVersion, componentId, processId);
+ validateProcessExistence(vspId, activeVersion, componentId, processId, retrieved);
+
+ vendorSoftwareProductDao.deleteProcess(vspId, activeVersion, componentId, processId);
+ UniqueValueUtil.deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.PROCESS_NAME,
+ retrieved.getVspId(), retrieved.getVersion().toString(), retrieved.getComponentId(),
+ retrieved.getName());
+
+ vendorSoftwareProductDao.updateVspLatestModificationTime(vspId, activeVersion);
+ }
+
+ @Override
+ public File getProcessArtifact(String vspId, Version version, String componentId,
+ String processId, String user) {
+ version = VersioningUtil
+ .resolveVersion(version, getVersionInfo(vspId, VersionableEntityAction.Read, user));
+ ProcessArtifactEntity retrieved =
+ vendorSoftwareProductDao.getProcessArtifact(vspId, version, componentId, processId);
+ validateProcessArtifactExistence(vspId, version, componentId, processId, retrieved);
+
+ File file = new File(String
+ .format("%s_%s_%s_%s", vspId, version.toString().replace('.', '_'), componentId,
+ processId));
+ try {
+ FileOutputStream fos = new FileOutputStream(file);
+ fos.write(retrieved.getArtifact().array());
+ fos.close();
+ } catch (IOException e0) {
+ throw new CoreException(new UploadInvalidErrorBuilder().build());
+ }
+
+ return file;
+ }
+
+ @Override
+ public void deleteProcessArtifact(String vspId, String componentId, String processId,
+ String user) {
+ Version activeVersion =
+ getVersionInfo(vspId, VersionableEntityAction.Write, user).getActiveVersion();
+ ProcessArtifactEntity retrieved =
+ vendorSoftwareProductDao.getProcessArtifact(vspId, activeVersion, componentId, processId);
+ validateProcessArtifactExistence(vspId, activeVersion, componentId, processId, retrieved);
+
+ vendorSoftwareProductDao.deleteProcessArtifact(vspId, activeVersion, componentId, processId);
+
+ vendorSoftwareProductDao.updateVspLatestModificationTime(vspId, activeVersion);
+ }
+
+ @Override
+ public void uploadProcessArtifact(InputStream artifactFile, String artifactFileName, String vspId,
+ String componentId, String processId, String user) {
+ Version activeVersion =
+ getVersionInfo(vspId, VersionableEntityAction.Write, user).getActiveVersion();
+ org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity retrieved =
+ vendorSoftwareProductDao.getProcess(vspId, activeVersion, componentId, processId);
+ validateProcessExistence(vspId, activeVersion, componentId, processId, retrieved);
+
+ if (artifactFile == null) {
+ throw new CoreException(new UploadInvalidErrorBuilder().build());
+ }
+
+ byte[] artifact;
+ try {
+ artifact = FileUtils.toByteArray(artifactFile);
+ } catch (RuntimeException e0) {
+ throw new CoreException(new UploadInvalidErrorBuilder().build());
+ }
+
+ vendorSoftwareProductDao
+ .uploadProcessArtifact(vspId, activeVersion, componentId, processId, artifact,
+ artifactFileName);
+
+ vendorSoftwareProductDao.updateVspLatestModificationTime(vspId, activeVersion);
+ }
+
+ @Override
+ public Collection<org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity> listNics(
+ String vspId, Version version, String componentId,
+ String user) {
+ version = VersioningUtil
+ .resolveVersion(version, getVersionInfo(vspId, VersionableEntityAction.Read, user));
+ Collection<org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity> nics =
+ listNics(vspId, version, componentId);
+
+ Map<String, String> networksNameById = listNetworksNameById(vspId, version);
+ nics.stream().forEach(nicEntity -> {
+ Nic nic = nicEntity.getNicCompositionData();
+ nic.setNetworkName(networksNameById.get(nic.getNetworkId()));
+ nicEntity.setNicCompositionData(nic);
+ });
+ return nics;
+ }
+
+ private Collection<org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity> listNics(
+ String vspId, Version version, String componentId) {
+ getComponent(vspId, version, componentId);
+
+ return vendorSoftwareProductDao.listNics(vspId, version, componentId);
+ }
+
+ private Map<String, String> listNetworksNameById(String vspId, Version version) {
+ Collection<NetworkEntity> networks = listNetworks(vspId, version);
+ return networks.stream().collect(Collectors.toMap(NetworkEntity::getId,
+ networkEntity -> networkEntity.getNetworkCompositionData().getName()));
+ }
+
+ @Override
+ public org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity createNic(
+ org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity nic, String user) {
+ Version activeVersion =
+ getVersionInfo(nic.getVspId(), VersionableEntityAction.Write, user).getActiveVersion();
+ nic.setVersion(activeVersion);
+ if (!isManual(nic.getVspId(), activeVersion)) {
+ throw new CoreException(
+ new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION)
+ .withId(VendorSoftwareProductErrorCodes.VSP_COMPOSITION_EDIT_NOT_ALLOWED)
+ .withMessage(VSP_COMPOSITION_EDIT_NOT_ALLOWED_MSG).build());
+ }
+
+ vendorSoftwareProductDao.updateVspLatestModificationTime(nic.getVspId(), activeVersion);
+
+ return null;
+ }
+
+ private org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity createNic(
+ org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity nic) {
+ nic.setId(CommonMethods.nextUuId());
+ nic.setQuestionnaireData(
+ new JsonSchemaDataGenerator(getNicQuestionnaireSchema(null)).generateData());
+
+ vendorSoftwareProductDao.createNic(nic);
+
+ return nic;
+ }
+
+ @Override
+ public CompositionEntityResponse<Nic> getNic(String vspId, Version version, String componentId,
+ String nicId, String user) {
+ version = VersioningUtil
+ .resolveVersion(version, getVersionInfo(vspId, VersionableEntityAction.Read, user));
+ org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity
+ nicEntity = getNic(vspId, version, componentId, nicId);
+ Nic nic = nicEntity.getNicCompositionData();
+
+ NicCompositionSchemaInput schemaInput = new NicCompositionSchemaInput();
+ schemaInput.setManual(isManual(vspId, version));
+ schemaInput.setNic(nic);
+ Map<String, String> networksNameById = listNetworksNameById(vspId, version);
+ nic.setNetworkName(networksNameById.get(nic.getNetworkId()));
+ schemaInput.setNetworkIds(networksNameById.keySet());
+
+ CompositionEntityResponse<Nic> response = new CompositionEntityResponse<>();
+ response.setId(nicId);
+ response.setData(nic);
+ response.setSchema(SchemaGenerator
+ .generate(SchemaTemplateContext.composition, CompositionEntityType.nic, schemaInput));
+
+ return response;
+ }
+
+ private org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity getNic(String vspId,
+ Version version,
+ String componentId,
+ String nicId) {
+ getComponent(vspId, version, componentId);
+ org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity
+ retrieved = vendorSoftwareProductDao.getNic(vspId, version, componentId, nicId);
+ VersioningUtil
+ .validateEntityExistence(retrieved,
+ new org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity(vspId, version,
+ componentId, nicId),
+ VspDetails.ENTITY_TYPE);
+ return retrieved;
+ }
+
+ @Override
+ public void deleteNic(String vspId, String componentId, String nicId, String user) {
+ Version activeVersion =
+ getVersionInfo(vspId, VersionableEntityAction.Write, user).getActiveVersion();
+ if (!isManual(vspId, activeVersion)) {
+ throw new CoreException(
+ new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION)
+ .withId(VendorSoftwareProductErrorCodes.VSP_COMPOSITION_EDIT_NOT_ALLOWED)
+ .withMessage(VSP_COMPOSITION_EDIT_NOT_ALLOWED_MSG).build());
+ }
+
+ vendorSoftwareProductDao.updateVspLatestModificationTime(vspId, activeVersion);
+ }
+
+ @Override
+ public CompositionEntityValidationData updateNic(
+ org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity nic, String user) {
+ Version activeVersion =
+ getVersionInfo(nic.getVspId(), VersionableEntityAction.Write, user).getActiveVersion();
+ nic.setVersion(activeVersion);
+ org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity
+ retrieved = getNic(nic.getVspId(), activeVersion, nic.getComponentId(), nic.getId());
+
+ NicCompositionSchemaInput schemaInput = new NicCompositionSchemaInput();
+ schemaInput.setManual(isManual(nic.getVspId(), activeVersion));
+ schemaInput.setNic(retrieved.getNicCompositionData());
+
+ CompositionEntityValidationData validationData = CompositionEntityDataManager
+ .validateEntity(nic, SchemaTemplateContext.composition, schemaInput);
+ if (CollectionUtils.isEmpty(validationData.getErrors())) {
+ vendorSoftwareProductDao.updateNic(nic);
+ }
+
+ vendorSoftwareProductDao.updateVspLatestModificationTime(nic.getVspId(), activeVersion);
+ return validationData;
+ }
+
+ @Override
+ public QuestionnaireResponse getNicQuestionnaire(String vspId, Version version,
+ String componentId, String nicId, String user) {
+ version = VersioningUtil
+ .resolveVersion(version, getVersionInfo(vspId, VersionableEntityAction.Read, user));
+
+ QuestionnaireResponse questionnaireResponse = new QuestionnaireResponse();
+ questionnaireResponse
+ .setData(getNic(vspId, version, componentId, nicId).getQuestionnaireData());
+ questionnaireResponse.setSchema(getNicQuestionnaireSchema(null));
+
+ return questionnaireResponse;
+ }
+
+ @Override
+ public void updateNicQuestionnaire(String vspId, String componentId, String nicId,
+ String questionnaireData, String user) {
+ Version activeVersion =
+ getVersionInfo(vspId, VersionableEntityAction.Write, user).getActiveVersion();
+ getNic(vspId, activeVersion, componentId, nicId);
+
+ vendorSoftwareProductDao
+ .updateNicQuestionnaire(vspId, activeVersion, componentId, nicId, questionnaireData);
+
+ vendorSoftwareProductDao.updateVspLatestModificationTime(vspId, activeVersion);
+ }
+
+ @Override
+ public void deleteComponentMib(String vspId, String componentId, boolean isTrap, String user) {
+ Version activeVersion =
+ getVersionInfo(vspId, VersionableEntityAction.Write, user).getActiveVersion();
+ ComponentArtifactEntity componentArtifactEntity =
+ setValuesForComponentArtifactEntityUpload(vspId, activeVersion, null, componentId, null,
+ isTrap, null);
+ ComponentArtifactEntity retrieved =
+ componentArtifactDao.getArtifactByType(componentArtifactEntity);
+
+ componentArtifactDao.delete(retrieved);
+
+ vendorSoftwareProductDao.updateVspLatestModificationTime(vspId, activeVersion);
+ }
+
+ @Override
+ public void uploadComponentMib(InputStream object, String filename, String vspId,
+ String componentId, boolean isTrap, String user) {
+ Version activeVersion =
+ getVersionInfo(vspId, VersionableEntityAction.Write, user).getActiveVersion();
+ ComponentArtifactEntity componentArtifactEntity;
+
+
+ if (object == null) {
+ throw new CoreException(new MibUploadErrorBuilder(
+ Messages.NO_ZIP_FILE_WAS_UPLOADED_OR_ZIP_NOT_EXIST.getErrorMessage()).build());
+ } else {
+ byte[] uploadedFileData;
+ Map<String, List<ErrorMessage>> errors = new HashMap<>();
+ try {
+ uploadedFileData = FileUtils.toByteArray(object);
+ validateMibZipContent(vspId, activeVersion, uploadedFileData, errors);
+ if (MapUtils.isNotEmpty(errors)) {
+ throw new CoreException(
+ new MibUploadErrorBuilder(errors.values().iterator().next().get(0).getMessage())
+ .build());
+ }
+
+ createArtifactInDatabase(vspId, activeVersion, filename, componentId, isTrap,
+ uploadedFileData);
+
+ } catch (Exception e0) {
+ throw new CoreException(new MibUploadErrorBuilder(e0.getMessage()).build());
+ }
+ }
+
+ vendorSoftwareProductDao.updateVspLatestModificationTime(vspId, activeVersion);
+ }
+
+ private void createArtifactInDatabase(String vspId, Version activeVersion, String filename,
+ String componentId, boolean isTrap,
+ byte[] uploadedFileData) {
+ ComponentArtifactEntity componentArtifactEntity;
+
+ String artifactId = CommonMethods.nextUuId();
+ componentArtifactEntity =
+ setValuesForComponentArtifactEntityUpload(vspId, activeVersion, filename, componentId,
+ artifactId, isTrap, uploadedFileData);
+ componentArtifactDao.update(componentArtifactEntity);
+ }
+
+ @Override
+ public MibUploadStatus listMibFilenames(String vspId, String componentId, String user) {
+ Version activeVersion =
+ getVersionInfo(vspId, VersionableEntityAction.Read, user).getActiveVersion();
+ ComponentArtifactEntity current =
+ new ComponentArtifactEntity(vspId, activeVersion, componentId, null);
+
+ return setMibUploadStatusValues(current);
+
+ }
+
+ private MibUploadStatus setMibUploadStatusValues(
+ ComponentArtifactEntity componentArtifactEntity) {
+ MibUploadStatus mibUploadStatus = new MibUploadStatus();
+
+ Collection<ComponentArtifactEntity> artifactNames =
+ componentArtifactDao.getArtifactNamesAndTypesForComponent(componentArtifactEntity);
+ Map<ComponentArtifactType, String> artifactTypeToFilename =
+ VendorSoftwareProductUtils.filterNonTrapOrPollArtifacts(artifactNames);
+
+ if (MapUtils.isNotEmpty(artifactTypeToFilename)) {
+ if (artifactTypeToFilename.containsKey(ComponentArtifactType.SNMP_TRAP)) {
+ mibUploadStatus.setSnmpTrap(artifactTypeToFilename.get(ComponentArtifactType.SNMP_TRAP));
+ }
+ if (artifactTypeToFilename.containsKey(ComponentArtifactType.SNMP_POLL)) {
+ mibUploadStatus.setSnmpPoll(artifactTypeToFilename.get(ComponentArtifactType.SNMP_POLL));
+ }
+ }
+
+ return mibUploadStatus;
+ }
+
+ private ComponentArtifactEntity setValuesForComponentArtifactEntityUpload(String vspId,
+ Version version,
+ String filename,
+ String componentId,
+ String artifactId,
+ boolean isTrap,
+ byte[]
+ uploadedFileData) {
+ ComponentArtifactEntity componentArtifactEntity = new ComponentArtifactEntity();
+
+ componentArtifactEntity.setVspId(vspId);
+ componentArtifactEntity.setVersion(version);
+ componentArtifactEntity.setComponentId(componentId);
+ componentArtifactEntity.setId(artifactId);
+ componentArtifactEntity.setType(ComponentArtifactType.getComponentArtifactType(isTrap));
+ componentArtifactEntity.setArtifactName(filename);
+
+ if (Objects.nonNull(uploadedFileData)) {
+ componentArtifactEntity.setArtifact(ByteBuffer.wrap(uploadedFileData));
+ }
+
+ return componentArtifactEntity;
+ }
+
+ private void validateProcessExistence(String vspId, Version version, String componentId,
+ String processId,
+ org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity retrieved) {
+ if (retrieved != null) {
+ return;
+ }
+ if (!GENERAL_COMPONENT_ID.equals(componentId)) {
+ getComponent(vspId, version, componentId);
+ }
+ VersioningUtil.validateEntityExistence(retrieved,
+ new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity(vspId, version,
+ componentId, processId),
+ VspDetails.ENTITY_TYPE);//todo retrieved is always null ??
+ }
+
+ private void validateProcessArtifactExistence(String vspId, Version version, String componentId,
+ String processId, ProcessArtifactEntity retrieved) {
+ if (retrieved != null) {
+ VersioningUtil.validateEntityExistence(retrieved.getArtifact(),
+ new ProcessArtifactEntity(vspId, version, componentId, processId),
+ VspDetails.ENTITY_TYPE);
+ } else {
+ if (!GENERAL_COMPONENT_ID.equals(componentId)) {
+ getComponent(vspId, version, componentId);
+ }
+ VersioningUtil.validateEntityExistence(retrieved,
+ new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity(vspId, version,
+ componentId, processId),
+ VspDetails.ENTITY_TYPE); //todo retrieved is always null ??
+ }
+ }
+
+ private Map<String, List<ErrorMessage>> validateUploadData(UploadDataEntity uploadData)
+ throws IOException {
+ if (uploadData == null || uploadData.getContentData() == null) {
+ return null;
+ }
+
+ FileContentHandler fileContentMap =
+ VendorSoftwareProductUtils.loadUploadFileContent(uploadData.getContentData().array());
+ ValidationManager validationManager =
+ ValidationManagerUtil.initValidationManager(fileContentMap);
+ Map<String, List<ErrorMessage>> validationErrors = validationManager.validate();
+
+ return
+ MapUtils.isEmpty(MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, validationErrors))
+ ? null : validationErrors;
+ }
+
+ private VersionInfo getVersionInfo(String vendorSoftwareProductId, VersionableEntityAction action,
+ String user) {
+ return versioningManager
+ .getEntityVersionInfo(VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, vendorSoftwareProductId,
+ user, action);
+ }
+
+ private void saveCompositionData(String vspId, Version version, CompositionData compositionData) {
+ Map<String, String> networkIdByName = new HashMap<>();
+ 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());
+ }
+ }
+
+ for (Component component : compositionData.getComponents()) {
+ ComponentEntity componentEntity = new ComponentEntity(vspId, version, null);
+ componentEntity.setComponentCompositionData(component.getData());
+
+ String componentId = createComponent(componentEntity).getId();
+
+ if (CollectionUtils.isNotEmpty(component.getNics())) {
+ for (Nic nic : component.getNics()) {
+ if (nic.getNetworkName() != null) {
+ nic.setNetworkId(networkIdByName.get(nic.getNetworkName()));
+ nic.setNetworkName(null);
+ }
+
+ org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity
+ nicEntity =
+ new org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity(vspId, version,
+ componentId, null);
+ nicEntity.setNicCompositionData(nic);
+ createNic(nicEntity);
+ }
+ }
+ }
+ }
+
+ private void deleteUploadDataAndContent(String vspId, Version version) {
+ vendorSoftwareProductDao.deleteUploadData(vspId, version);
+ }
+
+ private QuestionnaireValidationResult validateQuestionnaire(String vspId, Version version) {
+ CompositionEntityDataManager compositionEntityDataManager = new CompositionEntityDataManager();
+ compositionEntityDataManager
+ .addEntity(vendorSoftwareProductDao.getQuestionnaire(vspId, version), null);
+
+ Collection<org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity> nics =
+ vendorSoftwareProductDao.listNicsByVsp(vspId, version);
+
+ Map<String, List<String>> nicNamesByComponent = new HashMap<>();
+ for (org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity nicEntity : nics) {
+ compositionEntityDataManager.addEntity(nicEntity, null);
+
+ Nic nic = nicEntity.getNicCompositionData();
+ if (nic != null && nic.getName() != null) {
+ List<String> nicNames = nicNamesByComponent.get(nicEntity.getComponentId());
+ if (nicNames == null) {
+ nicNames = new ArrayList<>();
+ nicNamesByComponent.put(nicEntity.getComponentId(), nicNames);
+ }
+ nicNames.add(nic.getName());
+ }
+ }
+
+ Collection<ComponentEntity> components =
+ vendorSoftwareProductDao.listComponentsQuestionnaire(vspId, version);
+ components.stream().forEach(component -> compositionEntityDataManager.addEntity(component,
+ new ComponentQuestionnaireSchemaInput(nicNamesByComponent.get(component.getId()),
+ JsonUtil.json2Object(component.getQuestionnaireData(), Map.class))));
+
+ Map<CompositionEntityId, Collection<String>> errorsByEntityId =
+ compositionEntityDataManager.validateEntitiesQuestionnaire();
+ if (MapUtils.isNotEmpty(errorsByEntityId)) {
+ compositionEntityDataManager.buildTrees();
+ compositionEntityDataManager.addErrorsToTrees(errorsByEntityId);
+ Collection<CompositionEntityValidationData> roots = compositionEntityDataManager.getTrees();
+ return new QuestionnaireValidationResult(roots.iterator().next());
+ }
+
+ return null;
+ }
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/CompositionDataExtractor.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/CompositionDataExtractor.java
new file mode 100644
index 0000000000..f92b83532e
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/CompositionDataExtractor.java
@@ -0,0 +1,386 @@
+/*-
+ * ============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;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.collections4.MapUtils;
+import org.openecomp.sdc.common.errors.CoreException;
+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.types.ExtractCompositionDataContext;
+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.Network;
+import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+/**
+ * The type Composition data extractor.
+ */
+public class CompositionDataExtractor {
+
+ /**
+ * The constant logger.
+ */
+ protected static Logger logger;
+ private static ToscaAnalyzerService toscaAnalyzerService;
+
+ static {
+ logger = LoggerFactory.getLogger(CompositionDataExtractor.class);
+ toscaAnalyzerService = new ToscaAnalyzerServiceImpl();
+ }
+
+ /**
+ * Extract service composition data composition data.
+ *
+ * @param toscaServiceModel the tosca service model
+ * @return the composition data
+ */
+ public static CompositionData extractServiceCompositionData(ToscaServiceModel toscaServiceModel) {
+ ExtractCompositionDataContext context = new ExtractCompositionDataContext();
+ String entryDefinitionServiceTemplateFileName =
+ toscaServiceModel.getEntryDefinitionServiceTemplate();
+ ServiceTemplate entryDefinitionServiceTemplate =
+ toscaServiceModel.getServiceTemplates().get(entryDefinitionServiceTemplateFileName);
+ extractServiceCompositionData(entryDefinitionServiceTemplateFileName,
+ entryDefinitionServiceTemplate, toscaServiceModel, context);
+
+ CompositionData compositionData = new CompositionData();
+ compositionData.setNetworks(context.getNetworks());
+ compositionData.setComponents(context.getComponents());
+ return compositionData;
+ }
+
+ private static 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 static void handleSubstitution(ServiceTemplate serviceTemplate,
+ ToscaServiceModel toscaServiceModel,
+ ExtractCompositionDataContext context) {
+ Map<String, NodeTemplate> substitutableNodeTemplates =
+ toscaAnalyzerService.getSubstitutableNodeTemplates(serviceTemplate);
+
+ if (substitutableNodeTemplates != null) {
+ for (String substitutableNodeTemplateId : substitutableNodeTemplates.keySet()) {
+ handleSubstitutableNodeTemplate(serviceTemplate, toscaServiceModel,
+ substitutableNodeTemplateId,
+ substitutableNodeTemplates.get(substitutableNodeTemplateId), context);
+ }
+ }
+ }
+
+ private static void handleSubstitutableNodeTemplate(ServiceTemplate serviceTemplate,
+ ToscaServiceModel toscaServiceModel,
+ String substitutableNodeTemplateId,
+ NodeTemplate substitutableNodeTemplate,
+ ExtractCompositionDataContext context) {
+ ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
+ Optional<String> substituteServiceTemplateFileName = toscaAnalyzerService
+ .getSubstituteServiceTemplateName(substitutableNodeTemplateId, substitutableNodeTemplate);
+ if (!substituteServiceTemplateFileName.isPresent()) {
+ throw new CoreException(
+ new ToscaInvalidSubstituteNodeTemplateErrorBuilder(substitutableNodeTemplateId).build());
+ }
+ if (context.getHandledServiceTemplates().contains(substituteServiceTemplateFileName.get())) {
+ return;
+ }
+
+ ServiceTemplate substituteServiceTemplate =
+ toscaServiceModel.getServiceTemplates().get(substituteServiceTemplateFileName.get());
+ extractServiceCompositionData(substituteServiceTemplateFileName.get(),
+ substituteServiceTemplate, toscaServiceModel, context);
+
+ List<Map<String, RequirementAssignment>> substitutableRequirements =
+ substitutableNodeTemplate.getRequirements();
+
+ if (CollectionUtils.isEmpty(substitutableRequirements)) {
+ return;
+ }
+
+ for (Map<String, RequirementAssignment> substitutableReq : substitutableRequirements) {
+ substitutableReq.keySet().stream().filter(reqId -> {
+ RequirementAssignment reqAssignment = toscaExtensionYamlUtil
+ .yamlToObject(toscaExtensionYamlUtil.objectToYaml(substitutableReq.get(reqId)),
+ RequirementAssignment.class);
+ return isLinkToNetworkRequirementAssignment(reqAssignment);
+ }).forEach(reqId -> {
+ RequirementAssignment linkToNetworkRequirement = toscaExtensionYamlUtil
+ .yamlToObject(toscaExtensionYamlUtil.objectToYaml(substitutableReq.get(reqId)),
+ RequirementAssignment.class);
+ String connectedNodeId = linkToNetworkRequirement.getNode();
+ Optional<NodeTemplate> connectedNodeTemplate =
+ toscaAnalyzerService.getNodeTemplateById(serviceTemplate, connectedNodeId);
+
+ if (connectedNodeTemplate.isPresent() && toscaAnalyzerService
+ .isTypeOf(connectedNodeTemplate.get(), ToscaNodeType.NETWORK.getDisplayName(),
+ serviceTemplate, toscaServiceModel)) {
+ Optional<Map.Entry<String, NodeTemplate>> mappedNodeTemplate = toscaAnalyzerService
+ .getSubstitutionMappedNodeTemplateByExposedReq(
+ substituteServiceTemplateFileName.get(), substituteServiceTemplate, reqId);
+ if (!mappedNodeTemplate.isPresent()) {
+ throw new CoreException(new ToscaMissingSubstitutionMappingForReqCapErrorBuilder(
+ ToscaMissingSubstitutionMappingForReqCapErrorBuilder.MappingExposedEntry
+ .REQUIREMENT, connectedNodeId).build());
+ }
+
+ if (toscaAnalyzerService.isTypeOf(mappedNodeTemplate.get().getValue(),
+ ToscaNodeType.NETWORK_PORT.getDisplayName(), serviceTemplate, toscaServiceModel)) {
+ Nic port = context.getNics().get(mappedNodeTemplate.get().getKey());
+ if (port != null) {
+ port.setNetworkName(connectedNodeId);
+ } else {
+ logger.warn(
+ "Different ports define for the same component which is used in different "
+ + "substitution service templates.");
+ }
+ }
+ } else if (!connectedNodeTemplate.isPresent()) {
+ throw new CoreException(
+ new ToscaInvalidEntryNotFoundErrorBuilder("Node Template", connectedNodeId).build());
+ }
+ });
+ }
+ }
+
+ private static boolean isLinkToNetworkRequirementAssignment(RequirementAssignment requirement) {
+ return toscaAnalyzerService.isDesiredRequirementAssignment(requirement,
+ ToscaCapabilityType.NETWORK_LINKABLE.getDisplayName(), null,
+ ToscaRelationshipType.NETWORK_LINK_TO.getDisplayName());
+ }
+
+
+ private static void connectPortToNetwork(Nic port, NodeTemplate portNodeTemplate) {
+ List<RequirementAssignment> linkRequirementsToNetwork =
+ toscaAnalyzerService.getRequirements(portNodeTemplate, ToscaConstants.LINK_REQUIREMENT_ID);
+
+ //port is connected to one network
+ for (RequirementAssignment linkRequirementToNetwork : linkRequirementsToNetwork) {
+ port.setNetworkName(linkRequirementToNetwork.getNode());
+ }
+
+ }
+
+ /*
+ return Map with key - compute node template id, value - list of connected port node template id
+ */
+ private static Map<String, List<String>> getComputeToPortsConnection(
+ Map<String, NodeTemplate> portNodeTemplates) {
+ Map<String, List<String>> computeToPortConnection = new HashMap<>();
+ if (MapUtils.isEmpty(portNodeTemplates)) {
+ return computeToPortConnection;
+ }
+ for (String portId : portNodeTemplates.keySet()) {
+ List<RequirementAssignment> bindingRequirementsToCompute = toscaAnalyzerService
+ .getRequirements(portNodeTemplates.get(portId), ToscaConstants.BINDING_REQUIREMENT_ID);
+ for (RequirementAssignment bindingRequirementToCompute : bindingRequirementsToCompute) {
+ computeToPortConnection
+ .putIfAbsent(bindingRequirementToCompute.getNode(), new ArrayList<>());
+ computeToPortConnection.get(bindingRequirementToCompute.getNode()).add(portId);
+ }
+
+ }
+
+ return computeToPortConnection;
+ }
+
+ private static void extractComponents(ServiceTemplate serviceTemplate,
+ ToscaServiceModel toscaServiceModel,
+ ExtractCompositionDataContext context) {
+ Map<String, NodeTemplate> computeNodeTemplates = toscaAnalyzerService
+ .getNodeTemplatesByType(serviceTemplate, ToscaNodeType.COMPUTE.getDisplayName(),
+ toscaServiceModel);
+ if (MapUtils.isEmpty(computeNodeTemplates)) {
+ return;
+ }
+ Map<String, NodeTemplate> portNodeTemplates = toscaAnalyzerService
+ .getNodeTemplatesByType(serviceTemplate, ToscaNodeType.NETWORK_PORT.getDisplayName(),
+ toscaServiceModel);
+ Map<String, List<String>> computeToPortsConnection =
+ getComputeToPortsConnection(portNodeTemplates);
+ Map<String, List<String>> computesGroupedByType =
+ getNodeTemplatesGroupedByType(computeNodeTemplates);
+
+ computesGroupedByType.keySet()
+ .stream()
+ .filter(nodeType ->
+ !context.getCreatedComponents().contains(nodeType))
+ .forEach(nodeType -> extractComponent(serviceTemplate, computeToPortsConnection,
+ computesGroupedByType, nodeType, context));
+ }
+
+ private static void extractComponent(ServiceTemplate serviceTemplate,
+ Map<String, List<String>> computeToPortsConnection,
+ Map<String, List<String>> computesGroupedByType,
+ String computeNodeType,
+ ExtractCompositionDataContext context) {
+ ComponentData component = new ComponentData();
+ component.setName(computeNodeType);
+ component.setDisplayName(getComponentDisplayName(component.getName()));
+ Component componentModel = new Component();
+ componentModel.setData(component);
+
+ String computeId = computesGroupedByType.get(computeNodeType).get(0);
+ List<String> 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 static Nic extractPort(ServiceTemplate serviceTemplate, String portNodeTemplateId) {
+ Optional<NodeTemplate> portNodeTemplate =
+ toscaAnalyzerService.getNodeTemplateById(serviceTemplate, portNodeTemplateId);
+ if (portNodeTemplate.isPresent()) {
+ Nic port = new Nic();
+ port.setName(portNodeTemplateId);
+ connectPortToNetwork(port, portNodeTemplate.get());
+ return port;
+ } else {
+ throw new CoreException(
+ new ToscaInvalidEntryNotFoundErrorBuilder("Node Template", portNodeTemplateId).build());
+ }
+ }
+
+
+ private static Map<String, List<String>> getNodeTemplatesGroupedByType(
+ Map<String, NodeTemplate> nodeTemplates) {
+ Map<String, List<String>> nodeTemplatesGrouped =
+ new HashMap<>(); //key - node type, value - list of node ids with this type
+ for (String nodeId : nodeTemplates.keySet()) {
+ String nodeType = nodeTemplates.get(nodeId).getType();
+ nodeTemplatesGrouped.putIfAbsent(nodeType, new ArrayList<>());
+ nodeTemplatesGrouped.get(nodeType).add(nodeId);
+ }
+ return nodeTemplatesGrouped;
+ }
+
+ private static List<Network> extractNetworks(ServiceTemplate serviceTemplate,
+ ToscaServiceModel toscaServiceModel) {
+ List<Network> networks = new ArrayList<>();
+ Map<String, NodeTemplate> networkNodeTemplates = toscaAnalyzerService
+ .getNodeTemplatesByType(serviceTemplate, ToscaNodeType.NETWORK.getDisplayName(),
+ toscaServiceModel);
+ if (MapUtils.isEmpty(networkNodeTemplates)) {
+ return networks;
+ }
+ for (String networkId : networkNodeTemplates.keySet()) {
+ Network network = new Network();
+ network.setName(networkId);
+ Optional<Boolean> networkDhcpValue =
+ getNetworkDhcpValue(serviceTemplate, networkNodeTemplates.get(networkId));
+ network.setDhcp(networkDhcpValue.isPresent() ? networkDhcpValue.get() : true);
+ networks.add(network);
+ }
+
+ return networks;
+ }
+
+ //dhcp default value is true
+ private static Optional<Boolean> getNetworkDhcpValue(ServiceTemplate serviceTemplate,
+ NodeTemplate networkNodeTemplate) {
+ if (networkNodeTemplate == null) {
+ return Optional.empty();
+ }
+ if (networkNodeTemplate.getProperties() == null
+ || networkNodeTemplate.getProperties().get(ToscaConstants.DHCP_ENABLED_PROPERTY_NAME)
+ == null) {
+ return Optional.of(true);
+ }
+
+ Object dhcp =
+ networkNodeTemplate.getProperties().get(ToscaConstants.DHCP_ENABLED_PROPERTY_NAME);
+ if (dhcp instanceof String) {
+ return Optional.of(Boolean.valueOf((String) dhcp));
+ } else if (dhcp instanceof Boolean) {
+ return Optional.of((Boolean) dhcp);
+ } else if (dhcp instanceof Map) {
+ String inputParameterName =
+ (String) ((Map) dhcp).get(ToscaFunctions.GET_INPUT.getDisplayName());
+ if (inputParameterName != null) {
+ ParameterDefinition inputParameterDefinition =
+ serviceTemplate.getTopology_template().getInputs().get(inputParameterName);
+ if (inputParameterDefinition != null) {
+ if (inputParameterDefinition.get_default() != null) {
+ return Optional.of(Boolean.valueOf(inputParameterDefinition.get_default().toString()));
+ }
+ } else {
+ throw new CoreException(
+ new ToscaInvalidEntryNotFoundErrorBuilder("Input Parameter", inputParameterName)
+ .build());
+ }
+ }
+ }
+
+ return Optional.of(true);
+ }
+
+ private static 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/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/CompositionEntityDataManager.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/CompositionEntityDataManager.java
new file mode 100644
index 0000000000..e3f56a6578
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/CompositionEntityDataManager.java
@@ -0,0 +1,257 @@
+/*-
+ * ============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;
+
+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.vendorsoftwareproduct.types.CompositionEntityValidationData;
+import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.SchemaTemplateContext;
+import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.SchemaTemplateInput;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * The type Composition entity data manager.
+ */
+public class 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 Map<org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityId,
+ CompositionEntityData> entities = new HashMap<>();
+ private Map<org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType,
+ String> nonDynamicSchemas = new HashMap<>();
+ private List<CompositionEntityValidationData> roots = new ArrayList<>();
+
+ /**
+ * 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
+ */
+ public static CompositionEntityValidationData validateEntity(
+ org.openecomp.sdc.vendorsoftwareproduct.dao.type.CompositionEntity entity,
+ SchemaTemplateContext schemaTemplateContext,
+ 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());
+ }
+ 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,
+ SchemaGenerator.generate(schemaTemplateContext, entity.getType(), schemaTemplateInput)));
+
+ return validationData;
+ }
+
+ /**
+ * Add entity.
+ *
+ * @param entity the entity
+ * @param schemaTemplateInput the schema template input
+ */
+ public void addEntity(org.openecomp.sdc.vendorsoftwareproduct.dao.type.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
+ */
+ public Map<org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityId,
+ Collection<String>> validateEntitiesQuestionnaire() {
+ Map<org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityId,
+ Collection<String>>
+ errorsByEntityId = new HashMap<>();
+
+ entities.entrySet().stream().forEach(entry -> {
+ Collection<String> errors = validateQuestionnaire(entry.getValue());
+ if (errors != null) {
+ errorsByEntityId.put(entry.getKey(), errors);
+ }
+ });
+
+ return errorsByEntityId;
+ }
+
+ /**
+ * Build trees.
+ */
+ public void buildTrees() {
+ Map<org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityId,
+ CompositionEntityValidationData>
+ entitiesValidationData =
+ new HashMap<>();
+ entities.entrySet().stream().forEach(
+ entry -> addValidationDataEntity(entitiesValidationData, entry.getKey(),
+ entry.getValue().entity));
+ }
+
+ /**
+ * Gets trees.
+ *
+ * @return the trees
+ */
+ public Collection<CompositionEntityValidationData> getTrees() {
+ return roots;
+ }
+
+ /**
+ * Add errors to trees.
+ *
+ * @param errors the errors
+ */
+ public void addErrorsToTrees(
+ Map<org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityId,
+ Collection<String>> errors) {
+ roots.stream().forEach(root -> addErrorsToTree(root, null, errors));
+ }
+
+ private void addValidationDataEntity(
+ Map<org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityId,
+ CompositionEntityValidationData> entitiesValidationData,
+ org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityId entityId,
+ org.openecomp.sdc.vendorsoftwareproduct.dao.type.CompositionEntity entity) {
+ if (entitiesValidationData.containsKey(entityId)) {
+ return;
+ }
+
+ CompositionEntityValidationData validationData =
+ new CompositionEntityValidationData(entity.getType(), entity.getId());
+ entitiesValidationData.put(entityId, validationData);
+
+ org.openecomp.sdc.vendorsoftwareproduct.types.composition.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,
+ org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityId parentNodeId,
+ Map<org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityId,
+ Collection<String>> errors) {
+ if (node == null) {
+ return;
+ }
+ org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityId
+ nodeId = new org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityId(
+ node.getEntityId(), parentNodeId);
+ node.setErrors(errors.get(nodeId));
+
+ if (node.getSubEntitiesValidationData() != null) {
+ node.getSubEntitiesValidationData().stream()
+ .forEach(subNode -> addErrorsToTree(subNode, nodeId, errors));
+ }
+ }
+
+ private Collection<String> 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(
+ org.openecomp.sdc.vendorsoftwareproduct.types
+ .composition.CompositionEntityType compositionEntityType,
+ SchemaTemplateContext schemaTemplateContext,
+ SchemaTemplateInput schemaTemplateInput) {
+ return schemaTemplateInput == null ? getNonDynamicSchema(schemaTemplateContext,
+ compositionEntityType) : SchemaGenerator
+ .generate(schemaTemplateContext, compositionEntityType, schemaTemplateInput);
+ }
+
+ private String getNonDynamicSchema(SchemaTemplateContext schemaTemplateContext,
+ org.openecomp.sdc.vendorsoftwareproduct.types.composition
+ .CompositionEntityType compositionEntityType) {
+ String schema = nonDynamicSchemas.get(compositionEntityType);
+ if (schema == null) {
+ schema = SchemaGenerator.generate(schemaTemplateContext, compositionEntityType, null);
+ nonDynamicSchemas.put(compositionEntityType, schema);
+ }
+ return schema;
+ }
+
+ private static class CompositionEntityData {
+ private org.openecomp.sdc.vendorsoftwareproduct.dao.type.CompositionEntity entity;
+ private SchemaTemplateInput schemaTemplateInput;
+
+ /**
+ * Instantiates a new Composition entity data.
+ *
+ * @param entity the entity
+ * @param schemaTemplateInput the schema template input
+ */
+ public CompositionEntityData(
+ org.openecomp.sdc.vendorsoftwareproduct.dao.type.CompositionEntity entity,
+ SchemaTemplateInput schemaTemplateInput) {
+ this.entity = entity;
+ this.schemaTemplateInput = schemaTemplateInput;
+ }
+ }
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/SchemaGenerator.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/SchemaGenerator.java
new file mode 100644
index 0000000000..53fe5455fb
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/SchemaGenerator.java
@@ -0,0 +1,70 @@
+/*-
+ * ============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;
+
+import freemarker.template.Template;
+import freemarker.template.TemplateException;
+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.vendorsoftwareproduct.types.schemagenerator.SchemaTemplateContext;
+import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.SchemaTemplateInput;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+
+/**
+ * The type Schema generator.
+ */
+public class SchemaGenerator {
+ /**
+ * The constant SCHEMA_GENERATION_ERROR.
+ */
+ public static final String SCHEMA_GENERATION_ERROR = "SCHEMA_GENERATION_ERROR";
+
+ /**
+ * Generate string.
+ *
+ * @param schemaTemplateContext the schema template context
+ * @param entityType the entity type
+ * @param input the input
+ * @return the string
+ */
+ public static String generate(SchemaTemplateContext schemaTemplateContext,
+ org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType entityType,
+ SchemaTemplateInput input) {
+ Template schemaTemplate =
+ SchemaGeneratorConfig.getSchemaTemplate(schemaTemplateContext, entityType);
+ return processTemplate(input, schemaTemplate);
+ }
+
+ private static String processTemplate(SchemaTemplateInput input, Template schemaTemplate) {
+ try (Writer writer = new StringWriter(1024)) {
+ schemaTemplate.process(input, writer);
+ return writer.toString();
+ } catch (IOException | TemplateException exception) {
+ throw new CoreException(
+ new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION)
+ .withId(SCHEMA_GENERATION_ERROR).withMessage(exception.getMessage()).build());
+ }
+ }
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/SchemaGeneratorConfig.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/SchemaGeneratorConfig.java
new file mode 100644
index 0000000000..034d8520fb
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/SchemaGeneratorConfig.java
@@ -0,0 +1,184 @@
+/*-
+ * ============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;
+
+import freemarker.cache.StringTemplateLoader;
+import freemarker.template.Configuration;
+import freemarker.template.Template;
+import freemarker.template.TemplateExceptionHandler;
+import org.openecomp.core.utilities.applicationconfig.ApplicationConfig;
+import org.openecomp.core.utilities.applicationconfig.ApplicationConfigFactory;
+import org.openecomp.core.utilities.applicationconfig.type.ConfigurationData;
+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.vendorsoftwareproduct.types.schemagenerator.SchemaTemplateContext;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * The type Schema generator config.
+ */
+public class SchemaGeneratorConfig {
+ /**
+ * The constant SCHEMA_GENERATOR_INITIALIZATION_ERROR.
+ */
+ public static final String SCHEMA_GENERATOR_INITIALIZATION_ERROR =
+ "SCHEMA_GENERATOR_INITIALIZATION_ERROR";
+ /**
+ * The constant SCHEMA_GENERATOR_INITIALIZATION_ERROR_MSG.
+ */
+ public static final String SCHEMA_GENERATOR_INITIALIZATION_ERROR_MSG =
+ "Error occurred while loading questionnaire schema schemaTemplates";
+ private static final String CONFIGURATION_NAMESPACE = "vsp.schemaTemplates";
+ private static Map<SchemaTemplateId, SchemaTemplate> schemaTemplates = new HashMap<>();
+ private static ApplicationConfig applicationConfig =
+ ApplicationConfigFactory.getInstance().createInterface();
+
+ private static Configuration configuration = new Configuration(Configuration.VERSION_2_3_23);
+ private static StringTemplateLoader stringLoader = new StringTemplateLoader();
+
+ static {
+ configuration.setClassLoaderForTemplateLoading(SchemaGenerator.class.getClassLoader(),
+ File.pathSeparator);
+ configuration.setDefaultEncoding("UTF-8");
+ configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
+ configuration.setLogTemplateExceptions(true);
+ configuration.setTemplateLoader(stringLoader);
+ }
+
+ /**
+ * Insert schema template.
+ *
+ * @param schemaTemplateContext the schema template context
+ * @param entityType the entity type
+ * @param schemaTemplateString the schema template string
+ */
+ public static void insertSchemaTemplate(SchemaTemplateContext schemaTemplateContext,
+ org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType entityType,
+ String schemaTemplateString) {
+ applicationConfig.insertValue(CONFIGURATION_NAMESPACE,
+ new SchemaTemplateId(schemaTemplateContext, entityType).toString(), schemaTemplateString);
+ }
+
+ /**
+ * Gets schema template.
+ *
+ * @param schemaTemplateContext the schema template context
+ * @param entityType the entity type
+ * @return the schema template
+ */
+ public static Template getSchemaTemplate(SchemaTemplateContext schemaTemplateContext,
+ org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType entityType) {
+ SchemaTemplateId id = new SchemaTemplateId(schemaTemplateContext, entityType);
+ ConfigurationData configurationData =
+ applicationConfig.getConfigurationData(CONFIGURATION_NAMESPACE, id.toString());
+
+ SchemaTemplate schemaTemplate = schemaTemplates.get(id);
+ if (schemaTemplate == null || schemaTemplate.timestamp != configurationData.getTimeStamp()) {
+ stringLoader.putTemplate(id.toString(), configurationData.getValue());
+ Template template;
+ try {
+ template = configuration.getTemplate(id.toString());
+ } catch (IOException exception) {
+ throw new CoreException(
+ new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION)
+ .withId(SCHEMA_GENERATOR_INITIALIZATION_ERROR)
+ .withMessage(SCHEMA_GENERATOR_INITIALIZATION_ERROR_MSG).build(), exception);
+ }
+ schemaTemplate = new SchemaTemplate(template, configurationData.getTimeStamp());
+ schemaTemplates.put(id, schemaTemplate);
+ }
+ return schemaTemplate.template;
+ }
+
+ private static class SchemaTemplateId {
+ private SchemaTemplateContext context;
+ private org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType
+ entityType;
+
+ /**
+ * Instantiates a new Schema template id.
+ *
+ * @param context the context
+ * @param entityType the entity type
+ */
+ public SchemaTemplateId(SchemaTemplateContext context,
+ org.openecomp.sdc.vendorsoftwareproduct.types.composition
+ .CompositionEntityType entityType) {
+ this.context = context;
+ this.entityType = entityType;
+ }
+
+ @Override
+ public String toString() {
+ return context + "." + entityType;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null || getClass() != obj.getClass()) {
+ return false;
+ }
+
+ SchemaTemplateId that = (SchemaTemplateId) obj;
+
+ if (entityType != that.entityType) {
+ return false;
+ }
+ if (context != that.context) {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = entityType != null ? entityType.hashCode() : 0;
+ result = 31 * result + (context != null ? context.hashCode() : 0);
+ return result;
+ }
+ }
+
+ private static class SchemaTemplate {
+ private Template template;
+ private long timestamp;
+
+ /**
+ * Instantiates a new Schema template.
+ *
+ * @param template the template
+ * @param timestamp the timestamp
+ */
+ public SchemaTemplate(Template template, long timestamp) {
+ this.template = template;
+ this.timestamp = timestamp;
+ }
+ }
+
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/CompositionEntityResponse.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/CompositionEntityResponse.java
new file mode 100644
index 0000000000..6a71db041b
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/CompositionEntityResponse.java
@@ -0,0 +1,53 @@
+/*-
+ * ============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.types;
+
+public class CompositionEntityResponse<T extends org.openecomp.sdc
+ .vendorsoftwareproduct.types.composition.CompositionDataEntity> {
+
+ private String id;
+ private String schema;
+ private T data;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getSchema() {
+ return schema;
+ }
+
+ public void setSchema(String schema) {
+ this.schema = schema;
+ }
+
+ public T getData() {
+ return data;
+ }
+
+ public void setData(T data) {
+ this.data = data;
+ }
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/CompositionEntityValidationData.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/CompositionEntityValidationData.java
new file mode 100644
index 0000000000..d334e18637
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/CompositionEntityValidationData.java
@@ -0,0 +1,122 @@
+/*-
+ * ============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.types;
+
+import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+/**
+ * The type Composition entity validation data.
+ */
+public class CompositionEntityValidationData {
+ private CompositionEntityType entityType;
+ private String entityId;
+ private Collection<String> errors;
+ private Collection<CompositionEntityValidationData> subEntitiesValidationData;
+
+ /**
+ * Instantiates a new Composition entity validation data.
+ *
+ * @param entityType the entity type
+ * @param entityId the entity id
+ */
+ public CompositionEntityValidationData(CompositionEntityType entityType, String entityId) {
+ this.entityType = entityType;
+ this.entityId = entityId;
+ }
+
+ /**
+ * Gets entity type.
+ *
+ * @return the entity type
+ */
+ public CompositionEntityType getEntityType() {
+ return entityType;
+ }
+
+ /**
+ * Sets entity type.
+ *
+ * @param entityType the entity type
+ */
+ public void setEntityType(CompositionEntityType entityType) {
+ this.entityType = entityType;
+ }
+
+ /**
+ * Gets entity id.
+ *
+ * @return the entity id
+ */
+ public String getEntityId() {
+ return entityId;
+ }
+
+ /**
+ * Sets entity id.
+ *
+ * @param entityId the entity id
+ */
+ public void setEntityId(String entityId) {
+ this.entityId = entityId;
+ }
+
+ /**
+ * Gets errors.
+ *
+ * @return the errors
+ */
+ public Collection<String> getErrors() {
+ return errors;
+ }
+
+ /**
+ * Sets errors.
+ *
+ * @param errors the errors
+ */
+ public void setErrors(Collection<String> errors) {
+ this.errors = errors;
+ }
+
+ /**
+ * Gets sub entities validation data.
+ *
+ * @return the sub entities validation data
+ */
+ public Collection<CompositionEntityValidationData> getSubEntitiesValidationData() {
+ return subEntitiesValidationData;
+ }
+
+ /**
+ * Add sub entity validation data.
+ *
+ * @param subEntityValidationData the sub entity validation data
+ */
+ public void addSubEntityValidationData(CompositionEntityValidationData subEntityValidationData) {
+ if (subEntitiesValidationData == null) {
+ subEntitiesValidationData = new ArrayList<>();
+ }
+ subEntitiesValidationData.add(subEntityValidationData);
+ }
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/ExtractCompositionDataContext.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/ExtractCompositionDataContext.java
new file mode 100644
index 0000000000..0e34fc4e56
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/ExtractCompositionDataContext.java
@@ -0,0 +1,204 @@
+/*-
+ * ============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.types;
+
+import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * The type Extract composition data context.
+ */
+public class ExtractCompositionDataContext {
+ private List<org.openecomp.sdc.vendorsoftwareproduct.types.composition.Network> networks =
+ new ArrayList<>();
+ private List<org.openecomp.sdc.vendorsoftwareproduct.types.composition.Component> components =
+ new ArrayList<>();
+ private Map<String, Nic> nics = new HashMap<>();
+ private Set<String> handledServiceTemplates = new HashSet<>();
+ private Set<String> createdComponents = new HashSet<>();
+
+ /**
+ * Gets created components.
+ *
+ * @return the created components
+ */
+ public Set<String> getCreatedComponents() {
+ return createdComponents;
+ }
+
+ /**
+ * Sets created components.
+ *
+ * @param createdComponents the created components
+ */
+ public void setCreatedComponents(Set<String> createdComponents) {
+ this.createdComponents = createdComponents;
+ }
+
+ /**
+ * Gets handled service templates.
+ *
+ * @return the handled service templates
+ */
+ public Set<String> getHandledServiceTemplates() {
+ return handledServiceTemplates;
+ }
+
+ /**
+ * Sets handled service templates.
+ *
+ * @param handledServiceTemplates the handled service templates
+ */
+ public void setHandledServiceTemplates(Set<String> handledServiceTemplates) {
+ this.handledServiceTemplates = handledServiceTemplates;
+ }
+
+ /**
+ * Add handled service templates.
+ *
+ * @param handledServiceTemplate the handled service template
+ */
+ public void addHandledServiceTemplates(String handledServiceTemplate) {
+ this.handledServiceTemplates.add(handledServiceTemplate);
+ }
+
+ /**
+ * Gets networks.
+ *
+ * @return the networks
+ */
+ public List<org.openecomp.sdc.vendorsoftwareproduct.types.composition.Network> getNetworks() {
+ return networks;
+ }
+
+ /**
+ * Sets networks.
+ *
+ * @param networks the networks
+ */
+ public void setNetworks(
+ List<org.openecomp.sdc.vendorsoftwareproduct.types.composition.Network> networks) {
+ this.networks = networks;
+ }
+
+ /**
+ * Add network.
+ *
+ * @param network the network
+ */
+ public void addNetwork(
+ org.openecomp.sdc.vendorsoftwareproduct.types.composition.Network network) {
+ if (network != null) {
+ networks.add(network);
+ }
+ }
+
+ /**
+ * Add networks.
+ *
+ * @param network the network
+ */
+ public void addNetworks(
+ List<org.openecomp.sdc.vendorsoftwareproduct.types.composition.Network> network) {
+ if (networks != null) {
+ networks.addAll(network);
+ }
+ }
+
+ /**
+ * Gets components.
+ *
+ * @return the components
+ */
+ public List<org.openecomp.sdc.vendorsoftwareproduct.types.composition.Component> getComponents() {
+ return components;
+ }
+
+ /**
+ * Sets components.
+ *
+ * @param components the components
+ */
+ public void setComponents(
+ List<org.openecomp.sdc.vendorsoftwareproduct.types.composition.Component> components) {
+ this.components = components;
+ }
+
+ /**
+ * Add component.
+ *
+ * @param component the component
+ */
+ public void addComponent(
+ org.openecomp.sdc.vendorsoftwareproduct.types.composition.Component component) {
+ if (component != null) {
+ components.add(component);
+ }
+ }
+
+ /**
+ * Add components.
+ *
+ * @param components the components
+ */
+ public void addComponents(
+ List<org.openecomp.sdc.vendorsoftwareproduct.types.composition.Component> components) {
+ if (components != null) {
+ this.components.addAll(components);
+ }
+ }
+
+ /**
+ * Gets nics.
+ *
+ * @return the nics
+ */
+ public Map<String, Nic> getNics() {
+ return nics;
+ }
+
+ /**
+ * Sets nics.
+ *
+ * @param nics the nics
+ */
+ public void setNics(Map<String, Nic> nics) {
+ this.nics = nics;
+ }
+
+ /**
+ * Add nic.
+ *
+ * @param nicId the nic id
+ * @param nic the nic
+ */
+ public void addNic(String nicId, Nic nic) {
+ this.nics.put(nicId, nic);
+ }
+
+
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/LicensingData.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/LicensingData.java
new file mode 100644
index 0000000000..f0f6c095dd
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/LicensingData.java
@@ -0,0 +1,45 @@
+/*-
+ * ============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.types;
+
+import java.util.List;
+
+public class LicensingData {
+
+ private String licenseAgreement;
+ private List<String> featureGroups;
+
+ public String getLicenseAgreement() {
+ return licenseAgreement;
+ }
+
+ public void setLicenseAgreement(String licenseAgreement) {
+ this.licenseAgreement = licenseAgreement;
+ }
+
+ public List<String> getFeatureGroups() {
+ return featureGroups;
+ }
+
+ public void setFeatureGroups(List<String> featureGroups) {
+ this.featureGroups = featureGroups;
+ }
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/QuestionnaireResponse.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/QuestionnaireResponse.java
new file mode 100644
index 0000000000..84a2ed58f8
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/QuestionnaireResponse.java
@@ -0,0 +1,42 @@
+/*-
+ * ============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.types;
+
+public class QuestionnaireResponse {
+ private String schema;
+ private String data;
+
+ public String getSchema() {
+ return schema;
+ }
+
+ public void setSchema(String schema) {
+ this.schema = schema;
+ }
+
+ public String getData() {
+ return data;
+ }
+
+ public void setData(String data) {
+ this.data = data;
+ }
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/QuestionnaireValidationResult.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/QuestionnaireValidationResult.java
new file mode 100644
index 0000000000..d970e73a06
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/QuestionnaireValidationResult.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.types;
+
+public class QuestionnaireValidationResult {
+ private boolean valid;
+ private CompositionEntityValidationData validationData;
+
+ public QuestionnaireValidationResult(CompositionEntityValidationData validationData) {
+ this.validationData = validationData;
+ valid = validationData == null;
+ }
+
+ public boolean isValid() {
+ return valid;
+ }
+
+ public CompositionEntityValidationData getValidationData() {
+ return validationData;
+ }
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/UploadFileResponse.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/UploadFileResponse.java
new file mode 100644
index 0000000000..68389b6ed9
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/UploadFileResponse.java
@@ -0,0 +1,143 @@
+/*-
+ * ============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.types;
+
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class UploadFileResponse {
+ private List<String> fileNames;
+ private Map<String, List<org.openecomp.sdc.datatypes.error.ErrorMessage>> errors =
+ new HashMap<>();
+ private UploadFileStatus status = UploadFileStatus.Success;
+
+ /**
+ * Gets status.
+ *
+ * @return the status
+ */
+ public UploadFileStatus getStatus() {
+ return status;
+ }
+
+ /**
+ * Sets status.
+ *
+ * @param status the status
+ */
+ public void setStatus(UploadFileStatus status) {
+ this.status = status;
+ }
+
+ /**
+ * Gets file names.
+ *
+ * @return the file names
+ */
+ public List<String> getFileNames() {
+ return fileNames;
+ }
+
+ /**
+ * Sets file names.
+ *
+ * @param fileNames the file names
+ */
+ public void setFileNames(List<String> fileNames) {
+ this.fileNames = fileNames;
+ }
+
+ /**
+ * Add new file to list.
+ *
+ * @param filename the filename
+ */
+ public void addNewFileToList(String filename) {
+ this.fileNames.add(filename);
+ }
+
+ /**
+ * Remove file from list.
+ *
+ * @param toRemove the to remove
+ */
+ public void removeFileFromList(String toRemove) {
+ this.fileNames.remove(toRemove);
+ }
+
+ /**
+ * Add structure error.
+ *
+ * @param fileName the file name
+ * @param errorMessage the error message
+ */
+ public void addStructureError(String fileName,
+ org.openecomp.sdc.datatypes.error.ErrorMessage errorMessage) {
+ List<org.openecomp.sdc.datatypes.error.ErrorMessage> errorList = errors.get(fileName);
+ if (errorList == null) {
+ errorList = new ArrayList<>();
+ errors.put(fileName, errorList);
+ }
+ errorList.add(errorMessage);
+ if (org.openecomp.sdc.datatypes.error.ErrorLevel.ERROR.equals(errorMessage.getLevel())) {
+ status = UploadFileStatus.Failure;
+ }
+ }
+
+ /**
+ * Add structure errors.
+ *
+ * @param errorsByFileName the errors by file name
+ */
+ public void addStructureErrors(
+ Map<String, List<org.openecomp.sdc.datatypes.error.ErrorMessage>> errorsByFileName) {
+ if (errorsByFileName == null) {
+ return;
+ }
+
+ errors.putAll(errorsByFileName);
+
+ if (status == UploadFileStatus.Failure) {
+ return;
+ }
+ for (Map.Entry<String, List<org.openecomp.sdc.datatypes.error.ErrorMessage>> entry
+ : errorsByFileName.entrySet()) {
+ for (org.openecomp.sdc.datatypes.error.ErrorMessage errorMessage : entry.getValue()) {
+ if (errorMessage.getLevel() == org.openecomp.sdc.datatypes.error.ErrorLevel.ERROR) {
+ status = UploadFileStatus.Failure;
+ return;
+ }
+ }
+ }
+ }
+
+ /**
+ * Gets errors.
+ *
+ * @return the errors
+ */
+ public Map<String, List<org.openecomp.sdc.datatypes.error.ErrorMessage>> getErrors() {
+ return errors;
+ }
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/UploadFileStatus.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/UploadFileStatus.java
new file mode 100644
index 0000000000..2bd8d76a66
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/UploadFileStatus.java
@@ -0,0 +1,26 @@
+/*-
+ * ============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.types;
+
+public enum UploadFileStatus {
+ Success,
+ Failure
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/UploadFileStructure.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/UploadFileStructure.java
new file mode 100644
index 0000000000..1e21c60577
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/UploadFileStructure.java
@@ -0,0 +1,40 @@
+/*-
+ * ============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.types;
+
+import java.util.List;
+
+public class UploadFileStructure {
+
+ private List<String> fileNames;
+
+ public List<String> getFileNames() {
+ return fileNames;
+ }
+
+ public void setFileNames(List<String> fileNames) {
+ this.fileNames = fileNames;
+ }
+
+ public void addNewFileToList(String filename) {
+ this.fileNames.add(filename);
+ }
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/ValidationResponse.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/ValidationResponse.java
new file mode 100644
index 0000000000..29e5f73bce
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/ValidationResponse.java
@@ -0,0 +1,157 @@
+/*-
+ * ============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.types;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.collections4.MapUtils;
+import org.openecomp.sdc.common.errors.ErrorCode;
+import org.openecomp.sdc.datatypes.error.ErrorMessage;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * The type Validation response.
+ */
+public class ValidationResponse {
+ private boolean valid = true;
+ private Collection<ErrorCode> vspErrors;
+ private Collection<ErrorCode> licensingDataErrors;
+ private Map<String, List<ErrorMessage>> uploadDataErrors;
+ private Map<String, List<ErrorMessage>> compilationErrors;
+ private QuestionnaireValidationResult questionnaireValidationResult;
+
+ /**
+ * Is valid boolean.
+ *
+ * @return the boolean
+ */
+ public boolean isValid() {
+ return valid;
+ }
+
+ /**
+ * Gets vsp errors.
+ *
+ * @return the vsp errors
+ */
+ public Collection<ErrorCode> getVspErrors() {
+ return vspErrors;
+ }
+
+ /**
+ * Sets vsp errors.
+ *
+ * @param vspErrors the vsp errors
+ */
+ public void setVspErrors(Collection<ErrorCode> vspErrors) {
+ this.vspErrors = vspErrors;
+ if (CollectionUtils.isNotEmpty(vspErrors)) {
+ valid = false;
+ }
+ }
+
+ /**
+ * Gets licensing data errors.
+ *
+ * @return the licensing data errors
+ */
+ public Collection<ErrorCode> getLicensingDataErrors() {
+ return licensingDataErrors;
+ }
+
+ /**
+ * Sets licensing data errors.
+ *
+ * @param licensingDataErrors the licensing data errors
+ */
+ public void setLicensingDataErrors(Collection<ErrorCode> licensingDataErrors) {
+ this.licensingDataErrors = licensingDataErrors;
+ if (CollectionUtils.isNotEmpty(licensingDataErrors)) {
+ valid = false;
+ }
+ }
+
+ /**
+ * Gets upload data errors.
+ *
+ * @return the upload data errors
+ */
+ public Map<String, List<ErrorMessage>> getUploadDataErrors() {
+ return uploadDataErrors;
+ }
+
+ /**
+ * Sets upload data errors.
+ *
+ * @param uploadDataErrors the upload data errors
+ */
+ public void setUploadDataErrors(Map<String, List<ErrorMessage>> uploadDataErrors) {
+ this.uploadDataErrors = uploadDataErrors;
+ if (MapUtils.isNotEmpty(uploadDataErrors)) {
+ valid = false;
+ }
+ }
+
+ /**
+ * Gets compilation errors.
+ *
+ * @return the compilation errors
+ */
+ public Map<String, List<ErrorMessage>> getCompilationErrors() {
+ return compilationErrors;
+ }
+
+ /**
+ * Sets compilation errors.
+ *
+ * @param compilationErrors the compilation errors
+ */
+ public void setCompilationErrors(Map<String, List<ErrorMessage>> compilationErrors) {
+ this.compilationErrors = compilationErrors;
+ if (MapUtils.isNotEmpty(compilationErrors)) {
+ valid = false;
+ }
+ }
+
+ /**
+ * Gets questionnaire validation result.
+ *
+ * @return the questionnaire validation result
+ */
+ public QuestionnaireValidationResult getQuestionnaireValidationResult() {
+ return questionnaireValidationResult;
+ }
+
+ /**
+ * Sets questionnaire validation result.
+ *
+ * @param questionnaireValidationResult the questionnaire validation result
+ */
+ public void setQuestionnaireValidationResult(
+ QuestionnaireValidationResult questionnaireValidationResult) {
+ this.questionnaireValidationResult = questionnaireValidationResult;
+ if (questionnaireValidationResult != null && !questionnaireValidationResult.isValid()) {
+ valid = false;
+ }
+ }
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/VersionedVendorSoftwareProductInfo.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/VersionedVendorSoftwareProductInfo.java
new file mode 100644
index 0000000000..cbc81da1ee
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/VersionedVendorSoftwareProductInfo.java
@@ -0,0 +1,53 @@
+/*-
+ * ============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.types;
+
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
+
+public class VersionedVendorSoftwareProductInfo {
+ private VspDetails vspDetails;
+ private org.openecomp.sdc.versioning.types.VersionInfo versionInfo;
+
+ public VersionedVendorSoftwareProductInfo() {
+ }
+
+ public VersionedVendorSoftwareProductInfo(VspDetails vspDetails,
+ org.openecomp.sdc.versioning.types.VersionInfo versionInfo) {
+ this.vspDetails = vspDetails;
+ this.versionInfo = versionInfo;
+ }
+
+ public VspDetails getVspDetails() {
+ return vspDetails;
+ }
+
+ public void setVspDetails(VspDetails vspDetails) {
+ this.vspDetails = vspDetails;
+ }
+
+ public org.openecomp.sdc.versioning.types.VersionInfo getVersionInfo() {
+ return versionInfo;
+ }
+
+ public void setVersionInfo(org.openecomp.sdc.versioning.types.VersionInfo versionInfo) {
+ this.versionInfo = versionInfo;
+ }
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/schemagenerator/ComponentCompositionSchemaInput.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/schemagenerator/ComponentCompositionSchemaInput.java
new file mode 100644
index 0000000000..7fb5ec890b
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/schemagenerator/ComponentCompositionSchemaInput.java
@@ -0,0 +1,43 @@
+/*-
+ * ============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.types.schemagenerator;
+
+public class ComponentCompositionSchemaInput implements SchemaTemplateInput {
+ private boolean manual;
+ private org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentData component;
+
+ public boolean isManual() {
+ return manual;
+ }
+
+ public void setManual(boolean manual) {
+ this.manual = manual;
+ }
+
+ public org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentData getComponent() {
+ return component;
+ }
+
+ public void setComponent(
+ org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentData component) {
+ this.component = component;
+ }
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/schemagenerator/ComponentQuestionnaireSchemaInput.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/schemagenerator/ComponentQuestionnaireSchemaInput.java
new file mode 100644
index 0000000000..1f92e6d957
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/schemagenerator/ComponentQuestionnaireSchemaInput.java
@@ -0,0 +1,42 @@
+/*-
+ * ============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.types.schemagenerator;
+
+import java.util.List;
+import java.util.Map;
+
+public class ComponentQuestionnaireSchemaInput implements SchemaTemplateInput {
+ private List<String> nicNames;
+ private Map componentQuestionnaireData;
+
+ public ComponentQuestionnaireSchemaInput(List<String> nicNames, Map componentQuestionnaireData) {
+ this.nicNames = nicNames;
+ this.componentQuestionnaireData = componentQuestionnaireData;
+ }
+
+ public List<String> getNicNames() {
+ return nicNames;
+ }
+
+ public Map getComponentQuestionnaireData() {
+ return componentQuestionnaireData;
+ }
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/schemagenerator/MibUploadStatus.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/schemagenerator/MibUploadStatus.java
new file mode 100644
index 0000000000..046d53054e
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/schemagenerator/MibUploadStatus.java
@@ -0,0 +1,51 @@
+/*-
+ * ============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.types.schemagenerator;
+
+public class MibUploadStatus {
+ private String snmpTrap;
+ private String snmpPoll;
+
+
+ public MibUploadStatus(String snmpTrap, String snmpPoll) {
+ this.snmpTrap = snmpTrap;
+ this.snmpPoll = snmpPoll;
+ }
+
+ public MibUploadStatus() {
+ }
+
+ public String getSnmpTrap() {
+ return snmpTrap;
+ }
+
+ public void setSnmpTrap(String snmpTrap) {
+ this.snmpTrap = snmpTrap;
+ }
+
+ public String getSnmpPoll() {
+ return snmpPoll;
+ }
+
+ public void setSnmpPoll(String snmpPoll) {
+ this.snmpPoll = snmpPoll;
+ }
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/schemagenerator/NetworkCompositionSchemaInput.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/schemagenerator/NetworkCompositionSchemaInput.java
new file mode 100644
index 0000000000..456b4409fd
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/schemagenerator/NetworkCompositionSchemaInput.java
@@ -0,0 +1,43 @@
+/*-
+ * ============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.types.schemagenerator;
+
+public class NetworkCompositionSchemaInput implements SchemaTemplateInput {
+ private boolean manual;
+ private org.openecomp.sdc.vendorsoftwareproduct.types.composition.Network network;
+
+ public boolean isManual() {
+ return manual;
+ }
+
+ public void setManual(boolean manual) {
+ this.manual = manual;
+ }
+
+ public org.openecomp.sdc.vendorsoftwareproduct.types.composition.Network getNetwork() {
+ return network;
+ }
+
+ public void setNetwork(org.openecomp.sdc.vendorsoftwareproduct.types.composition
+ .Network network) {
+ this.network = network;
+ }
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/schemagenerator/NicCompositionSchemaInput.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/schemagenerator/NicCompositionSchemaInput.java
new file mode 100644
index 0000000000..87693a492c
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/schemagenerator/NicCompositionSchemaInput.java
@@ -0,0 +1,55 @@
+/*-
+ * ============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.types.schemagenerator;
+
+import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic;
+
+import java.util.Collection;
+
+public class NicCompositionSchemaInput implements SchemaTemplateInput {
+ private boolean manual;
+ private Nic nic;
+ private Collection<String> networkIds;
+
+ public boolean isManual() {
+ return manual;
+ }
+
+ public void setManual(boolean manual) {
+ this.manual = manual;
+ }
+
+ public Nic getNic() {
+ return nic;
+ }
+
+ public void setNic(Nic nic) {
+ this.nic = nic;
+ }
+
+ public Collection<String> getNetworkIds() {
+ return networkIds;
+ }
+
+ public void setNetworkIds(Collection<String> networkIds) {
+ this.networkIds = networkIds;
+ }
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/schemagenerator/SchemaTemplateContext.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/schemagenerator/SchemaTemplateContext.java
new file mode 100644
index 0000000000..3ee3e4a5e6
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/schemagenerator/SchemaTemplateContext.java
@@ -0,0 +1,26 @@
+/*-
+ * ============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.types.schemagenerator;
+
+public enum SchemaTemplateContext {
+ composition,
+ questionnaire
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/schemagenerator/SchemaTemplateInput.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/schemagenerator/SchemaTemplateInput.java
new file mode 100644
index 0000000000..93e614f98b
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/schemagenerator/SchemaTemplateInput.java
@@ -0,0 +1,25 @@
+/*-
+ * ============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.types.schemagenerator;
+
+public interface SchemaTemplateInput {
+
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/util/CompilationUtil.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/util/CompilationUtil.java
new file mode 100644
index 0000000000..54038bcd73
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/util/CompilationUtil.java
@@ -0,0 +1,126 @@
+/*-
+ * ============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.util;
+
+import org.openecomp.core.enrichment.types.ComponentArtifactType;
+import org.openecomp.core.enrichment.types.ComponentCeilometerInfo;
+import org.openecomp.core.enrichment.types.ComponentMibInfo;
+import org.openecomp.core.enrichment.types.MibInfo;
+import org.openecomp.core.utilities.applicationconfig.ApplicationConfig;
+import org.openecomp.core.utilities.applicationconfig.ApplicationConfigFactory;
+import org.openecomp.core.utilities.json.JsonUtil;
+import org.openecomp.sdc.datatypes.error.ErrorMessage;
+import org.openecomp.sdc.enrichment.impl.tosca.ComponentInfo;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentArtifactDao;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentArtifactDaoFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentArtifactEntity;
+import org.openecomp.sdc.versioning.dao.types.Version;
+
+import java.io.File;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * The type Compilation util.
+ */
+public class CompilationUtil {
+
+ private static final ApplicationConfig applicationConfig =
+ ApplicationConfigFactory.getInstance().createInterface();
+ private static final ComponentArtifactDao componentArtifactDao =
+ ComponentArtifactDaoFactory.getInstance().createInterface();
+
+ /**
+ * Add monitoring info.
+ *
+ * @param componentInfo the component info
+ * @param compileErrors the compile errors
+ */
+ public static void addMonitoringInfo(ComponentInfo componentInfo,
+ Map<String, List<ErrorMessage>> compileErrors) {
+
+ String ceilometerJson =
+ applicationConfig.getConfigurationData("vsp.monitoring", "component.ceilometer").getValue();
+ ComponentCeilometerInfo ceilometerInfo =
+ JsonUtil.json2Object(ceilometerJson, ComponentCeilometerInfo.class);
+ componentInfo.setCeilometerInfo(ceilometerInfo);
+ }
+
+ /**
+ * Add mib info.
+ *
+ * @param vspId the vsp id
+ * @param version the version
+ * @param componentEntity the component entity
+ * @param componentInfo the component info
+ * @param compileErrors the compile errors
+ */
+ public static void addMibInfo(String vspId, Version version, org.openecomp.sdc
+ .vendorsoftwareproduct.dao.type.ComponentEntity componentEntity,
+ ComponentInfo componentInfo,
+ Map<String, List<ErrorMessage>> compileErrors) {
+
+ String componentId = componentEntity.getId();
+
+ ComponentArtifactEntity entity = new ComponentArtifactEntity();
+ entity.setVspId(vspId);
+ entity.setVersion(version);
+ entity.setComponentId(componentId);
+
+ ComponentMibInfo componentMibInfo = new ComponentMibInfo();
+
+ extractAndInsertMibContentToComponentInfo(componentId, ComponentArtifactType.SNMP_POLL, entity,
+ componentMibInfo, compileErrors);
+ extractAndInsertMibContentToComponentInfo(componentId, ComponentArtifactType.SNMP_TRAP, entity,
+ componentMibInfo, compileErrors);
+ componentInfo.setMibInfo(componentMibInfo);
+ }
+
+ private static void extractAndInsertMibContentToComponentInfo(String componentId,
+ ComponentArtifactType type,
+ ComponentArtifactEntity componentArtifactEntity,
+ ComponentMibInfo componentMibInfo,
+ Map<String, List<ErrorMessage>> compileErrors) {
+ String path;
+ componentArtifactEntity.setType(type);
+ ComponentArtifactEntity artifact =
+ componentArtifactDao.getArtifactByType(componentArtifactEntity);
+
+ if (artifact == null) {
+ return;
+ }
+ path = componentId + File.separator + type.name();
+ MibInfo mibInfo = new MibInfo();
+ mibInfo.setName(path);
+ mibInfo.setContent(artifact.getArtifact().array());
+ switch (type) {
+ case SNMP_POLL:
+ componentMibInfo.setSnmpPoll(mibInfo);
+ break;
+ case SNMP_TRAP:
+ componentMibInfo.setSnmpTrap(mibInfo);
+ break;
+ default:
+ }
+
+
+ }
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/util/VendorSoftwareProductUtils.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/util/VendorSoftwareProductUtils.java
new file mode 100644
index 0000000000..62e8dd8b87
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/util/VendorSoftwareProductUtils.java
@@ -0,0 +1,254 @@
+/*-
+ * ============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.util;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.collections4.MapUtils;
+import org.openecomp.core.enrichment.types.ComponentArtifactType;
+import org.openecomp.core.translator.api.HeatToToscaTranslator;
+import org.openecomp.core.translator.datatypes.TranslatorOutput;
+import org.openecomp.core.translator.factory.HeatToToscaTranslatorFactory;
+import org.openecomp.core.utilities.file.FileContentHandler;
+import org.openecomp.core.utilities.file.FileUtils;
+import org.openecomp.core.validation.errors.Messages;
+import org.openecomp.core.validation.types.MessageContainerUtil;
+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.utils.AsdcCommon;
+import org.openecomp.sdc.datatypes.error.ErrorMessage;
+import org.openecomp.sdc.heat.datatypes.structure.HeatStructureTree;
+import org.openecomp.sdc.heat.datatypes.structure.ValidationStructureList;
+import org.openecomp.sdc.heat.services.tree.HeatTreeManager;
+import org.openecomp.sdc.heat.services.tree.HeatTreeManagerUtil;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentArtifactEntity;
+import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+/**
+ * The type Vendor software product utils.
+ */
+public class VendorSoftwareProductUtils {
+
+ private static org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao
+ vendorSoftwareProductDao =
+ VendorSoftwareProductDaoFactory.getInstance().createInterface();
+
+ /**
+ * Load upload file content file content handler.
+ *
+ * @param uploadedFileData the uploaded file data
+ * @return the file content handler
+ * @throws IOException the io exception
+ */
+ public static FileContentHandler loadUploadFileContent(byte[] uploadedFileData)
+ throws IOException {
+ return getFileContentMapFromZip(uploadedFileData);
+ }
+
+ private static FileContentHandler getFileContentMapFromZip(byte[] uploadFileData)
+ throws IOException, CoreException {
+ ZipEntry zipEntry;
+ List<String> folderList = new ArrayList<>();
+ FileContentHandler mapFileContent = new FileContentHandler();
+ try {
+ ZipInputStream inputZipStream;
+
+ byte[] fileByteContent;
+ String currentEntryName;
+ inputZipStream = new ZipInputStream(new ByteArrayInputStream(uploadFileData));
+
+ while ((zipEntry = inputZipStream.getNextEntry()) != null) {
+ currentEntryName = zipEntry.getName();
+ // else, get the file content (as byte array) and save it in a map.
+ fileByteContent = FileUtils.toByteArray(inputZipStream);
+
+ int index = lastIndexFileSeparatorIndex(currentEntryName);
+ String currSubstringWithoutSeparator =
+ currentEntryName.substring(index + 1, currentEntryName.length());
+ if (index != -1) { //todo ?
+ folderList.add(currentEntryName);
+ } else {
+ mapFileContent.addFile(currentEntryName, fileByteContent);
+ }
+
+ }
+
+ } catch (RuntimeException e0) {
+ throw new IOException(e0);
+ }
+
+ if (CollectionUtils.isNotEmpty(folderList)) {
+ throw new CoreException((new ErrorCode.ErrorCodeBuilder())
+ .withMessage(Messages.ZIP_SHOULD_NOT_CONTAIN_FOLDERS.getErrorMessage())
+ .withId(Messages.ZIP_SHOULD_NOT_CONTAIN_FOLDERS.getErrorMessage())
+ .withCategory(ErrorCategory.APPLICATION).build());
+ }
+
+ return mapFileContent;
+ }
+
+ /**
+ * Load and translate template data translator output.
+ *
+ * @param fileNameContentMap the file name content map
+ * @return the translator output
+ */
+ public static TranslatorOutput loadAndTranslateTemplateData(
+ FileContentHandler fileNameContentMap) {
+ HeatToToscaTranslator heatToToscaTranslator =
+ HeatToToscaTranslatorFactory.getInstance().createInterface();
+ InputStream fileContent = fileNameContentMap.getFileContent(AsdcCommon.MANIFEST_NAME);
+
+ heatToToscaTranslator.addManifest(AsdcCommon.MANIFEST_NAME, FileUtils.toByteArray(fileContent));
+
+ fileNameContentMap.getFileList().stream()
+ .filter(fileName -> !(fileName.equals(AsdcCommon.MANIFEST_NAME))).forEach(
+ fileName -> heatToToscaTranslator
+ .addFile(fileName, FileUtils.toByteArray(fileNameContentMap.getFileContent(fileName))));
+
+ Map<String, List<ErrorMessage>> errors = heatToToscaTranslator.validate();
+ if (MapUtils.isNotEmpty(MessageContainerUtil.getMessageByLevel(
+ org.openecomp.sdc.datatypes.error.ErrorLevel.ERROR, errors))) {
+ TranslatorOutput translatorOutput = new TranslatorOutput();
+ translatorOutput.setErrorMessages(errors);
+ return translatorOutput;
+ }
+
+ InputStream structureFile = getHeatStructureTreeFile(fileNameContentMap);
+ heatToToscaTranslator.addExternalArtifacts(AsdcCommon.HEAT_META, structureFile);
+ return heatToToscaTranslator.translate();
+ }
+
+ private static InputStream getHeatStructureTreeFile(FileContentHandler fileNameContentMap) {
+ HeatTreeManager heatTreeManager = HeatTreeManagerUtil.initHeatTreeManager(fileNameContentMap);
+ heatTreeManager.createTree();
+ HeatStructureTree tree = heatTreeManager.getTree();
+ ValidationStructureList validationStructureList = new ValidationStructureList(tree);
+ return FileUtils.convertToInputStream(validationStructureList, FileUtils.FileExtension.JSON);
+ }
+
+
+ private static int lastIndexFileSeparatorIndex(String filePath) {
+ int length = filePath.length() - 1;
+
+ for (int i = length; i >= 0; i--) {
+ char currChar = filePath.charAt(i);
+ if (currChar == '/' || currChar == File.separatorChar || currChar == File.pathSeparatorChar) {
+ return i;
+ }
+ }
+ // if we've reached to the start of the string and didn't find file separator - return -1
+ return -1;
+ }
+
+ /**
+ * Add file names to upload file response.
+ *
+ * @param fileContentMap the file content map
+ * @param uploadFileResponse the upload file response
+ */
+ public static void addFileNamesToUploadFileResponse(FileContentHandler fileContentMap,
+ UploadFileResponse uploadFileResponse) {
+ uploadFileResponse.setFileNames(new ArrayList<>());
+ for (String filename : fileContentMap.getFileList()) {
+ if (!new File(filename).isDirectory()) {
+ uploadFileResponse.addNewFileToList(filename);
+ }
+ }
+ uploadFileResponse.removeFileFromList(AsdcCommon.MANIFEST_NAME);
+ }
+
+ /**
+ * Validate raw zip data.
+ *
+ * @param uploadedFileData the uploaded file data
+ * @param errors the errors
+ */
+ public static void validateRawZipData(byte[] uploadedFileData,
+ Map<String, List<ErrorMessage>> errors) {
+ if (uploadedFileData.length == 0) {
+ ErrorMessage.ErrorMessageUtil.addMessage(AsdcCommon.UPLOAD_FILE, errors).add(
+ new ErrorMessage(org.openecomp.sdc.datatypes.error.ErrorLevel.ERROR,
+ Messages.NO_ZIP_FILE_WAS_UPLOADED_OR_ZIP_NOT_EXIST.getErrorMessage()));
+ }
+ }
+
+ /**
+ * Validate content zip data.
+ *
+ * @param contentMap the content map
+ * @param errors the errors
+ */
+ public static void validateContentZipData(FileContentHandler contentMap,
+ Map<String, List<ErrorMessage>> errors) {
+ if (contentMap == null) {
+ ErrorMessage.ErrorMessageUtil.addMessage(AsdcCommon.UPLOAD_FILE, errors).add(
+ new ErrorMessage(org.openecomp.sdc.datatypes.error.ErrorLevel.ERROR,
+ Messages.ZIP_SHOULD_NOT_CONTAIN_FOLDERS.getErrorMessage()));
+
+ } else if (contentMap.getFileList().size() == 0) {
+ ErrorMessage.ErrorMessageUtil.addMessage(AsdcCommon.UPLOAD_FILE, errors)
+ .add(new ErrorMessage(org.openecomp.sdc.datatypes.error.ErrorLevel.ERROR,
+ Messages.INVALID_ZIP_FILE.getErrorMessage()));
+ }
+ }
+
+
+ /**
+ * Filter non trap or poll artifacts map.
+ *
+ * @param artifacts the artifacts
+ * @return the map
+ */
+ public static Map<ComponentArtifactType, String> filterNonTrapOrPollArtifacts(
+ Collection<ComponentArtifactEntity> artifacts) {
+ Map<ComponentArtifactType, String> artifactTypeToFilename = new HashMap<>();
+
+ for (ComponentArtifactEntity entity : artifacts) {
+ if (isTrapOrPoll(entity.getType())) {
+ artifactTypeToFilename.put(entity.getType(), entity.getArtifactName());
+ }
+ }
+
+ return artifactTypeToFilename;
+ }
+
+
+ private static boolean isTrapOrPoll(ComponentArtifactType type) {
+ return type.equals(ComponentArtifactType.SNMP_POLL)
+ || type.equals(ComponentArtifactType.SNMP_TRAP);
+ }
+
+
+}