From 0a83fed85182026706ed374a687f25464bef0151 Mon Sep 17 00:00:00 2001 From: talig Date: Mon, 15 Jan 2018 09:27:43 +0200 Subject: Move CompositionEntityDataManager to vsp-mgr Change-Id: I71d9126e6d32b57a0b7d8b93952992423632ef37 Issue-ID: SDC-873 Signed-off-by: talig --- .../CompositionEntityDataManager.java | 76 +++ .../CompositionEntityDataManagerFactory.java | 32 ++ .../impl/ComponentManagerFactoryImpl.java | 2 +- .../impl/ComponentManagerImpl.java | 4 +- .../CompositionEntityDataManagerFactoryImpl.java | 47 ++ .../impl/CompositionEntityDataManagerImpl.java | 636 ++++++++++++++++++++ .../impl/ComputeManagerFactoryImpl.java | 2 +- .../impl/ComputeManagerImpl.java | 5 +- .../impl/DeploymentFlavorManagerFactoryImpl.java | 2 +- .../impl/DeploymentFlavorManagerImpl.java | 3 +- .../impl/ImageManagerFactoryImpl.java | 2 +- .../impl/ImageManagerImpl.java | 4 +- .../impl/NetworkManagerFactoryImpl.java | 2 +- .../impl/NetworkManagerImpl.java | 5 +- .../impl/NicManagerFactoryImpl.java | 2 +- .../vendorsoftwareproduct/impl/NicManagerImpl.java | 3 +- .../impl/VendorSoftwareProductManagerImpl.java | 5 +- .../impl/orchestration/OrchestrationUtil.java | 4 +- .../src/main/resources/factoryConfiguration.json | 1 + .../sdc/vendorsoftwareproduct/ImagesTest.java | 1 - .../QuestionnaireDataServiceTest.java | 1 - .../impl/ComponentManagerImplTest.java | 2 +- .../impl/CompositionEntityDataManagerImplTest.java | 281 +++++++++ .../impl/ComputeManagerImplTest.java | 2 +- .../impl/DeploymentFlavorManagerImplTest.java | 2 +- .../impl/ImageManagerImplTest.java | 2 +- .../impl/NetworkManagerImplTest.java | 2 +- .../impl/NicManagerImplTest.java | 2 +- .../impl/VendorSoftwareProductManagerImplTest.java | 2 +- .../CompositionEntityDataManagerImplTest.java | 280 --------- .../vendorsoftwareproduct/tree/UploadFileTest.java | 2 +- .../CompositionEntityDataManagerFactory.java | 33 -- .../composition/CompositionEntityDataManager.java | 87 --- .../src/main/resources/factoryConfiguration.json | 1 - .../CompositionEntityDataManagerFactoryImpl.java | 48 -- .../CompositionEntityDataManagerImpl.java | 638 --------------------- 36 files changed, 1097 insertions(+), 1126 deletions(-) create mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/CompositionEntityDataManager.java create mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/CompositionEntityDataManagerFactory.java create mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/CompositionEntityDataManagerFactoryImpl.java create mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/CompositionEntityDataManagerImpl.java create mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/CompositionEntityDataManagerImplTest.java delete mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/composition/CompositionEntityDataManagerImplTest.java delete mode 100644 openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/factory/CompositionEntityDataManagerFactory.java delete mode 100644 openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/composition/CompositionEntityDataManager.java delete mode 100644 openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/factory/impl/CompositionEntityDataManagerFactoryImpl.java delete mode 100644 openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/composition/CompositionEntityDataManagerImpl.java diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/CompositionEntityDataManager.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/CompositionEntityDataManager.java new file mode 100644 index 0000000000..c4cb95808a --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/CompositionEntityDataManager.java @@ -0,0 +1,76 @@ +/*- + * ============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.CompositionEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.DeploymentFlavorEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ImageEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Component; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionData; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityId; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityValidationData; +import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.SchemaTemplateContext; +import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.SchemaTemplateInput; +import org.openecomp.sdc.versioning.dao.types.Version; + +import java.util.Collection; +import java.util.Map; +import java.util.Set; + +public interface CompositionEntityDataManager { + + Map> validateEntitiesQuestionnaire(); + + void addEntity(CompositionEntity entity, SchemaTemplateInput schemaTemplateInput); + + CompositionEntityValidationData validateEntity(CompositionEntity entity, + SchemaTemplateContext schemaTemplateContext, + SchemaTemplateInput schemaTemplateInput); + + void buildTrees(); + + void addErrorsToTrees(Map> errors); + + Set getEntityListWithErrors(); + + Collection getTrees(); + + void saveCompositionData(String vspId, Version version, CompositionData compositionData); + + Set getAllErrorsByVsp(String vspId); + + ComponentEntity createComponent(ComponentEntity component); + + NicEntity createNic(NicEntity nic); + + DeploymentFlavorEntity createDeploymentFlavor(DeploymentFlavorEntity deploymentFlavor); + + ImageEntity createImage(ImageEntity image); + + void saveComputesFlavorByComponent(String vspId, Version version, Component component, + String componentId); + + void saveImagesByComponent(String vspId, Version version, Component component, + String componentId); + +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/CompositionEntityDataManagerFactory.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/CompositionEntityDataManagerFactory.java new file mode 100644 index 0000000000..b8e2fd7b0c --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/CompositionEntityDataManagerFactory.java @@ -0,0 +1,32 @@ +/*- + * ============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.core.factory.api.AbstractComponentFactory; +import org.openecomp.core.factory.api.AbstractFactory; + +public abstract class CompositionEntityDataManagerFactory extends + AbstractComponentFactory { + + public static CompositionEntityDataManagerFactory getInstance() { + return AbstractFactory.getInstance(CompositionEntityDataManagerFactory.class); + } +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComponentManagerFactoryImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComponentManagerFactoryImpl.java index dac68b5c47..b1d9063966 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComponentManagerFactoryImpl.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComponentManagerFactoryImpl.java @@ -25,7 +25,7 @@ import org.openecomp.sdc.vendorsoftwareproduct.ComponentManagerFactory; import org.openecomp.sdc.vendorsoftwareproduct.NicManagerFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDaoFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDaoFactory; -import org.openecomp.sdc.vendorsoftwareproduct.factory.CompositionEntityDataManagerFactory; +import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManagerFactory; public class ComponentManagerFactoryImpl extends ComponentManagerFactory { private static final ComponentManager INSTANCE = diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComponentManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComponentManagerImpl.java index f509658b37..16f40d64e0 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComponentManagerImpl.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComponentManagerImpl.java @@ -38,7 +38,7 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; import org.openecomp.sdc.vendorsoftwareproduct.errors.CompositionEditNotAllowedErrorBuilder; import org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes; -import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; +import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManager; import org.openecomp.sdc.vendorsoftwareproduct.services.schemagenerator.SchemaGenerator; import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.QuestionnaireResponse; @@ -64,8 +64,6 @@ public class ComponentManagerImpl implements ComponentManager { private final CompositionEntityDataManager compositionEntityDataManager; private final NicManager nicManager; private final VendorSoftwareProductInfoDao vspInfoDao; - private static final String VSP_ID = "VSP id"; - private static final String VSP_ID_COMPONENT_ID = "VSP id, component id"; public ComponentManagerImpl(ComponentDao componentDao, CompositionEntityDataManager compositionEntityDataManager, diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/CompositionEntityDataManagerFactoryImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/CompositionEntityDataManagerFactoryImpl.java new file mode 100644 index 0000000000..cf38fe12f6 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/CompositionEntityDataManagerFactoryImpl.java @@ -0,0 +1,47 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.impl; + +import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManager; +import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManagerFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComputeDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.DeploymentFlavorDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ImageDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.NetworkDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDaoFactory; + +public class CompositionEntityDataManagerFactoryImpl extends CompositionEntityDataManagerFactory { + + @Override + public CompositionEntityDataManager createInterface() { + // this class is stateful! it must be recreated from scratch on every use!!! + return new CompositionEntityDataManagerImpl( + VendorSoftwareProductInfoDaoFactory.getInstance().createInterface(), + ComponentDaoFactory.getInstance().createInterface(), + NicDaoFactory.getInstance().createInterface(), + NetworkDaoFactory.getInstance().createInterface(), + ImageDaoFactory.getInstance().createInterface(), + ComputeDaoFactory.getInstance().createInterface(), + DeploymentFlavorDaoFactory.getInstance().createInterface()); + } +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/CompositionEntityDataManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/CompositionEntityDataManagerImpl.java new file mode 100644 index 0000000000..a00bd8e967 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/CompositionEntityDataManagerImpl.java @@ -0,0 +1,636 @@ +/*- + * ============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 org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.MapUtils; +import org.openecomp.core.utilities.CommonMethods; +import org.openecomp.core.utilities.json.JsonSchemaDataGenerator; +import org.openecomp.core.utilities.json.JsonUtil; +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.common.errors.ErrorCategory; +import org.openecomp.sdc.common.errors.ErrorCode; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; +import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManager; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComputeDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.DeploymentFlavorDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ImageDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.NetworkDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.CompositionEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComputeEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.DeploymentFlavorEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ImageEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspQuestionnaireEntity; +import org.openecomp.sdc.vendorsoftwareproduct.services.schemagenerator.SchemaGenerator; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Component; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentData; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionData; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityId; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityValidationData; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComputeData; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Image; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Network; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.NetworkType; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic; +import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.SchemaTemplateContext; +import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.SchemaTemplateInput; +import org.openecomp.sdc.versioning.dao.types.Version; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; + +public class CompositionEntityDataManagerImpl implements CompositionEntityDataManager { + + private static final String COMPOSITION_ENTITY_DATA_MANAGER_ERR = + "COMPOSITION_ENTITY_DATA_MANAGER_ERR"; + private static final String COMPOSITION_ENTITY_DATA_MANAGER_ERR_MSG = + "Invalid input: %s may not be null"; + private static final String MISSING_OR_INVALID_QUESTIONNAIRE_MSG = + "Data is missing/invalid for this %s. Please refill and resubmit."; + + private static final Logger logger = + LoggerFactory.getLogger(CompositionEntityDataManagerImpl.class); + private Map entities = new HashMap<>(); + private Map nonDynamicSchemas = new HashMap<>(); + private List roots = new ArrayList<>(); + + private VendorSoftwareProductInfoDao vspInfoDao; + private ComponentDao componentDao; + private NicDao nicDao; + private NetworkDao networkDao; + private ImageDao imageDao; + private ComputeDao computeDao; + private DeploymentFlavorDao deploymentFlavorDao; + + public CompositionEntityDataManagerImpl(VendorSoftwareProductInfoDao vspInfoDao, + ComponentDao componentDao, + NicDao nicDao, NetworkDao networkDao, + ImageDao imageDao, ComputeDao computeDao, + DeploymentFlavorDao deploymentFlavorDao) { + this.vspInfoDao = vspInfoDao; + this.componentDao = componentDao; + this.nicDao = nicDao; + this.networkDao = networkDao; + this.imageDao = imageDao; + this.computeDao = computeDao; + this.deploymentFlavorDao = deploymentFlavorDao; + } + + /** + * Validate entity composition entity validation data. + * + * @param entity the entity + * @param schemaTemplateContext the schema template context + * @param schemaTemplateInput the schema template input + * @return the composition entity validation data + */ + @Override + public CompositionEntityValidationData validateEntity(CompositionEntity entity, + SchemaTemplateContext schemaTemplateContext, + SchemaTemplateInput schemaTemplateInput) { + if (entity == null) { + throw new CoreException( + new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION) + .withId(COMPOSITION_ENTITY_DATA_MANAGER_ERR).withMessage( + String.format(COMPOSITION_ENTITY_DATA_MANAGER_ERR_MSG, "composition entity")) + .build()); + } + if (schemaTemplateContext == null) { + throw new CoreException( + new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION) + .withId(COMPOSITION_ENTITY_DATA_MANAGER_ERR).withMessage( + String.format(COMPOSITION_ENTITY_DATA_MANAGER_ERR_MSG, "schema template context")) + .build()); + } + + CompositionEntityValidationData validationData = + new CompositionEntityValidationData(entity.getType(), entity.getId()); + String json = + schemaTemplateContext == SchemaTemplateContext.composition ? entity.getCompositionData() + : entity.getQuestionnaireData(); + validationData.setErrors(JsonUtil.validate( + json == null ? JsonUtil.object2Json(new Object()) : json, + generateSchema(schemaTemplateContext, entity.getType(), schemaTemplateInput))); + return validationData; + } + + /** + * Add entity. + * + * @param entity the entity + * @param schemaTemplateInput the schema template input + */ + @Override + public void addEntity(CompositionEntity entity, SchemaTemplateInput schemaTemplateInput) { + if (entity == null) { + throw new CoreException( + new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION) + .withId(COMPOSITION_ENTITY_DATA_MANAGER_ERR).withMessage( + String.format(COMPOSITION_ENTITY_DATA_MANAGER_ERR_MSG, "composition entity")) + .build()); + } + entities.put(entity.getCompositionEntityId(), + new CompositionEntityData(entity, schemaTemplateInput)); + } + + /** + * Validate entities questionnaire map. + * + * @return the map + */ + @Override + public Map> validateEntitiesQuestionnaire() { + Map> errorsByEntityId = new HashMap<>(); + entities.entrySet().forEach(entry -> { + Collection errors = validateQuestionnaire(entry.getValue()); + if (errors != null) { + errorsByEntityId.put(entry.getKey(), errors); + } + }); + return errorsByEntityId; + } + + /** + * Build trees. + */ + @Override + public void buildTrees() { + Map entitiesValidationData = + new HashMap<>(); + entities.entrySet().forEach( + entry -> addValidationDataEntity(entitiesValidationData, entry.getKey(), + entry.getValue().entity)); + } + + public Collection getTrees() { + return roots; + } + + @Override + public void saveCompositionData(String vspId, Version version, CompositionData compositionData) { + if (Objects.isNull(compositionData)) { + return; + } + + Map networkIdByName = saveNetworks(vspId, version, compositionData); + saveComponents(vspId, version, compositionData, networkIdByName); + } + + @Override + public Set getAllErrorsByVsp(String vspId) { + CompositionEntityValidationData matchVsp = null; + Set entitiesWithErrors = new HashSet<>(); + for (CompositionEntityValidationData root : roots) { + if (root.getEntityId().equals(vspId)) { + matchVsp = root; + break; + } + } + + getEntityListWithErrors(matchVsp, entitiesWithErrors); + if (CollectionUtils.isNotEmpty(entitiesWithErrors)) { + updateValidationCompositionEntityName(entitiesWithErrors); + return entitiesWithErrors; + } + + return null; + } + + private boolean isThereErrorsInSubTree(CompositionEntityValidationData entity) { + if (Objects.isNull(entity)) { + return false; + } + + if (CollectionUtils.isNotEmpty(entity.getErrors())) { + return true; + } + + Collection subEntitiesValidationData = + entity.getSubEntitiesValidationData(); + return !CollectionUtils.isEmpty(subEntitiesValidationData) && + checkForErrorsInChildren(subEntitiesValidationData); + + } + + private boolean checkForErrorsInChildren( + Collection subEntitiesValidationData) { + boolean result = false; + for (CompositionEntityValidationData subEntity : subEntitiesValidationData) { + if (CollectionUtils.isNotEmpty(subEntity.getErrors())) { + return true; + } + + result = isThereErrorsInSubTree(subEntity) || result; + if (result) { + return true; + } + } + return false; + } + + private void saveComponents(String vspId, Version version, CompositionData compositionData, + Map networkIdByName) { + if (CollectionUtils.isNotEmpty(compositionData.getComponents())) { + for (Component component : compositionData.getComponents()) { + ComponentEntity componentEntity = new ComponentEntity(vspId, version, null); + componentEntity.setComponentCompositionData(component.getData()); + + String componentId = createComponent(componentEntity).getId(); + + saveImagesByComponent(vspId, version, component, componentId); + saveComputesFlavorByComponent(vspId, version, component, componentId); + + saveNicsByComponent(vspId, version, networkIdByName, component, componentId); + } + } + } + + private void saveNicsByComponent(String vspId, Version version, + Map networkIdByName, Component component, + String componentId) { + if (CollectionUtils.isNotEmpty(component.getNics())) { + for (Nic nic : component.getNics()) { + if (nic.getNetworkName() != null && MapUtils.isNotEmpty(networkIdByName)) { + nic.setNetworkId(networkIdByName.get(nic.getNetworkName())); + } + nic.setNetworkName(null); + //For heat flow set network type to be internal by default for NIC + nic.setNetworkType(NetworkType.Internal); + + NicEntity nicEntity = new NicEntity(vspId, version, componentId, null); + nicEntity.setNicCompositionData(nic); + createNic(nicEntity); + } + } + } + + private Map saveNetworks(String vspId, Version version, + CompositionData compositionData) { + Map networkIdByName = new HashMap<>(); + if (CollectionUtils.isNotEmpty(compositionData.getNetworks())) { + for (Network network : compositionData.getNetworks()) { + + NetworkEntity networkEntity = new NetworkEntity(vspId, version, null); + networkEntity.setNetworkCompositionData(network); + + if (network.getName() != null) { + networkIdByName.put(network.getName(), createNetwork(networkEntity).getId()); + } + } + } + return networkIdByName; + } + + private NetworkEntity createNetwork(NetworkEntity network) { + //network.setId(CommonMethods.nextUuId()); will be set by the dao + networkDao.create(network); + return network; + } + + @Override + public ComponentEntity createComponent(ComponentEntity component) { + //component.setId(CommonMethods.nextUuId()); will be set by the dao + component.setQuestionnaireData( + new JsonSchemaDataGenerator( + generateSchema(SchemaTemplateContext.questionnaire, CompositionEntityType.component, + null)) + .generateData()); + + componentDao.create(component); + return component; + } + + @Override + public NicEntity createNic(NicEntity nic) { + //nic.setId(CommonMethods.nextUuId()); will be set by the dao + nic.setQuestionnaireData( + new JsonSchemaDataGenerator( + generateSchema(SchemaTemplateContext.questionnaire, CompositionEntityType.nic, null)) + .generateData()); + + nicDao.create(nic); + return nic; + } + + + public void addErrorsToTrees(Map> errors) { + roots.forEach(root -> addErrorsToTree(root, null, errors)); + } + + /* * + * get a flat list of all questionnaire entities that have validation errors + * */ + public Set getEntityListWithErrors() { + Set treeAsList = new HashSet<>(); + + for (CompositionEntityValidationData entity : roots) { + if (CollectionUtils.isNotEmpty(entity.getErrors())) { + addNodeWithErrors(entity, treeAsList); + } + getEntityListWithErrors(entity, treeAsList); + } + + updateValidationCompositionEntityName(treeAsList); + return treeAsList; + } + + private void getEntityListWithErrors(CompositionEntityValidationData entity, + Set compositionSet) { + if (CollectionUtils.isNotEmpty(entity.getErrors())) { + addNodeWithErrors(entity, compositionSet); + } + + if (CollectionUtils.isEmpty(entity.getSubEntitiesValidationData())) { + return; + } + + for (CompositionEntityValidationData child : entity.getSubEntitiesValidationData()) { + getEntityListWithErrors(child, compositionSet); + } + } + + + private void addNodeWithErrors(CompositionEntityValidationData node, + Set entitiesWithErrors) { + CompositionEntityValidationData compositionNodeToAdd = new CompositionEntityValidationData(node + .getEntityType(), node.getEntityId()); + compositionNodeToAdd.setErrors(node.getErrors()); + compositionNodeToAdd.setSubEntitiesValidationData(null); + + entitiesWithErrors.add(compositionNodeToAdd); + } + + public void removeNodesWithoutErrors() { + roots.forEach(root -> removeNodesWithoutErrors(root, null)); + } + + + private CompositionEntityData getCompositionEntityDataById(CompositionEntityValidationData + entity) { + for (Map.Entry entityEntry : entities + .entrySet()) { + if (entityEntry.getKey().getId().equals(entity.getEntityId())) { + return entityEntry.getValue(); + } + } + return null; + } + + + private void updateValidationCompositionEntityName(Set + compositionSet) { + for (CompositionEntityValidationData entity : compositionSet) { + String compositionData = getCompositionDataAsString(entity); + if (entity.getEntityType().equals(CompositionEntityType.vsp) || + Objects.nonNull(compositionData)) { + entity.setEntityName(getEntityNameByEntityType(compositionData, entity)); + } + } + } + + private String getCompositionDataAsString(CompositionEntityValidationData entity) { + CompositionEntityData compositionEntityData = getCompositionEntityDataById(entity); + return compositionEntityData == null ? null : compositionEntityData.entity.getCompositionData(); + } + + + private String getEntityNameByEntityType(String compositionData, + CompositionEntityValidationData entity) { + switch (entity.getEntityType()) { + case component: + ComponentData component = JsonUtil.json2Object(compositionData, ComponentData.class); + return component.getDisplayName(); + + case nic: + Nic nic = JsonUtil.json2Object(compositionData, Nic.class); + return nic.getName(); + + case network: + Network network = JsonUtil.json2Object(compositionData, Network.class); + return network.getName(); + + case image: + Image image = JsonUtil.json2Object(compositionData, Image.class); + return image.getFileName(); + + case vsp: + CompositionEntityData vspEntity = getCompositionEntityDataById(entity); + VspQuestionnaireEntity vspQuestionnaireEntity = (VspQuestionnaireEntity) vspEntity.entity; + VspDetails vspDetails = + vspInfoDao.get(new VspDetails(vspQuestionnaireEntity.getId(), + vspQuestionnaireEntity.getVersion())); + return vspDetails.getName(); + } + + return null; + } + + private void removeNodesWithoutErrors(CompositionEntityValidationData node, + CompositionEntityValidationData parent) { + + if (Objects.isNull(node)) { + return; + } + + if (hasChildren(node)) { + Collection subNodes = + new ArrayList<>(node.getSubEntitiesValidationData()); + subNodes.forEach(subNode -> removeNodesWithoutErrors(subNode, node)); + node.setSubEntitiesValidationData(subNodes); + + if (canNodeGetRemovedFromValidationDataTree(node)) { + removeNodeFromChildren(parent, node); + } + } else if (canNodeGetRemovedFromValidationDataTree(node)) { + removeNodeFromChildren(parent, node); + } + } + + private void removeNodeFromChildren(CompositionEntityValidationData parent, + CompositionEntityValidationData childToRemove) { + if (!Objects.isNull(parent)) { + parent.getSubEntitiesValidationData().remove(childToRemove); + } + } + + private boolean hasChildren(CompositionEntityValidationData node) { + return !CollectionUtils.isEmpty(node.getSubEntitiesValidationData()); + } + + private boolean canNodeGetRemovedFromValidationDataTree(CompositionEntityValidationData node) { + return !hasChildren(node) && CollectionUtils.isEmpty(node.getErrors()); + } + + + private void addValidationDataEntity( + Map entitiesValidationData, + CompositionEntityId entityId, CompositionEntity entity) { + if (entitiesValidationData.containsKey(entityId)) { + return; + } + + CompositionEntityValidationData validationData = + new CompositionEntityValidationData(entity.getType(), entity.getId()); + entitiesValidationData.put(entityId, validationData); + + CompositionEntityId parentEntityId = entityId.getParentId(); + if (parentEntityId == null) { + roots.add(validationData); + } else { + CompositionEntityData parentEntity = entities.get(parentEntityId); + if (parentEntity == null) { + roots.add(validationData); + } else { + addValidationDataEntity(entitiesValidationData, parentEntityId, parentEntity.entity); + entitiesValidationData.get(parentEntityId).addSubEntityValidationData(validationData); + } + } + } + + private void addErrorsToTree(CompositionEntityValidationData node, + CompositionEntityId parentNodeId, + Map> errors) { + if (node == null) { + return; + } + CompositionEntityId nodeId = new CompositionEntityId(node.getEntityId(), parentNodeId); + node.setErrors(errors.get(nodeId)); + + if (node.getSubEntitiesValidationData() != null) { + node.getSubEntitiesValidationData() + .forEach(subNode -> addErrorsToTree(subNode, nodeId, errors)); + } + } + + private Collection validateQuestionnaire(CompositionEntityData compositionEntityData) { + logger.debug(String.format("validateQuestionnaire start: " + + "[entity.type]=%s, [entity.id]=%s, [entity.questionnaireString]=%s", + compositionEntityData.entity.getType().name(), + compositionEntityData.entity.getCompositionEntityId().toString(), + compositionEntityData.entity.getQuestionnaireData())); + + if (Objects.isNull(compositionEntityData.entity.getQuestionnaireData()) || + !JsonUtil.isValidJson(compositionEntityData.entity.getQuestionnaireData())) { + return Collections.singletonList(String + .format(MISSING_OR_INVALID_QUESTIONNAIRE_MSG, compositionEntityData.entity.getType())); + } + + return JsonUtil.validate( + compositionEntityData.entity.getQuestionnaireData() == null + ? JsonUtil.object2Json(new Object()) + : compositionEntityData.entity.getQuestionnaireData(), + getSchema(compositionEntityData.entity.getType(), SchemaTemplateContext.questionnaire, + compositionEntityData.schemaTemplateInput)); + } + + private String getSchema(CompositionEntityType compositionEntityType, + SchemaTemplateContext schemaTemplateContext, + SchemaTemplateInput schemaTemplateInput) { + return schemaTemplateInput == null + ? nonDynamicSchemas.computeIfAbsent(compositionEntityType, + k -> generateSchema(schemaTemplateContext, compositionEntityType, null)) + : generateSchema(schemaTemplateContext, compositionEntityType, schemaTemplateInput); + } + + private static class CompositionEntityData { + private CompositionEntity entity; + private SchemaTemplateInput schemaTemplateInput; + + CompositionEntityData(CompositionEntity entity, SchemaTemplateInput schemaTemplateInput) { + this.entity = entity; + this.schemaTemplateInput = schemaTemplateInput; + } + + } + + // todo - make SchemaGenerator non static and mock it in UT instead of mocking this method (and + // make the method private + protected String generateSchema(SchemaTemplateContext schemaTemplateContext, + CompositionEntityType compositionEntityType, + SchemaTemplateInput schemaTemplateInput) { + return SchemaGenerator + .generate(schemaTemplateContext, compositionEntityType, schemaTemplateInput); + } + + @Override + public DeploymentFlavorEntity createDeploymentFlavor(DeploymentFlavorEntity deploymentFlavor) { + deploymentFlavor.setId(CommonMethods.nextUuId()); + deploymentFlavorDao.create(deploymentFlavor); + return deploymentFlavor; + } + + @Override + public ImageEntity createImage(ImageEntity image) { + image.setId(CommonMethods.nextUuId()); + + image.setQuestionnaireData( + new JsonSchemaDataGenerator(SchemaGenerator + .generate(SchemaTemplateContext.questionnaire, CompositionEntityType.image, null)) + .generateData()); + + imageDao.create(image); + return image; + } + + public void saveComputesFlavorByComponent(String vspId, Version version, Component component, + String componentId) { + if (CollectionUtils.isNotEmpty(component.getCompute())) { + for (ComputeData flavor : component.getCompute()) { + ComputeEntity computeEntity = new ComputeEntity(vspId, version, componentId, null); + computeEntity.setComputeCompositionData(flavor); + computeEntity.setQuestionnaireData( + new JsonSchemaDataGenerator(SchemaGenerator + .generate(SchemaTemplateContext.questionnaire, CompositionEntityType.compute, + null)).generateData()); + + computeDao.create(computeEntity); + } + } + } + + public void saveImagesByComponent(String vspId, Version version, Component component, String + componentId) { + if (CollectionUtils.isNotEmpty(component.getImages())) { + for (Image img : component.getImages()) { + ImageEntity imageEntity = new ImageEntity(vspId, version, componentId, null); + imageEntity.setImageCompositionData(img); + createImage(imageEntity); + } + } + } + +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComputeManagerFactoryImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComputeManagerFactoryImpl.java index 598c45f323..cefc0dd0ef 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComputeManagerFactoryImpl.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComputeManagerFactoryImpl.java @@ -5,7 +5,7 @@ import org.openecomp.sdc.vendorsoftwareproduct.ComputeManagerFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.ComputeDaoFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.DeploymentFlavorDaoFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDaoFactory; -import org.openecomp.sdc.vendorsoftwareproduct.factory.CompositionEntityDataManagerFactory; +import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManagerFactory; public class ComputeManagerFactoryImpl extends ComputeManagerFactory { diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComputeManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComputeManagerImpl.java index 9641f3322e..32946a0aa9 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComputeManagerImpl.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComputeManagerImpl.java @@ -39,7 +39,7 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; import org.openecomp.sdc.vendorsoftwareproduct.errors.DuplicateComputeInComponentErrorBuilder; import org.openecomp.sdc.vendorsoftwareproduct.errors.NotSupportedHeatOnboardMethodErrorBuilder; import org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes; -import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; +import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManager; import org.openecomp.sdc.vendorsoftwareproduct.services.schemagenerator.SchemaGenerator; import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.ListComputeResponse; @@ -66,9 +66,6 @@ public class ComputeManagerImpl implements ComputeManager { private final CompositionEntityDataManager compositionEntityDataManager; private final VendorSoftwareProductInfoDao vspInfoDao; private final DeploymentFlavorDao deploymentFlavorDao; - private static final String VSP_ID_COMPONENT_ID = "VSP id, component id"; - private static final String VSP_ID_COMPONENT_ID_COMPUTE_ID - = "VSP id, component id, compute id"; public ComputeManagerImpl(VendorSoftwareProductInfoDao vspInfoDao, ComputeDao computeDao, diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/DeploymentFlavorManagerFactoryImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/DeploymentFlavorManagerFactoryImpl.java index dd46d60f7e..0eef5246c3 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/DeploymentFlavorManagerFactoryImpl.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/DeploymentFlavorManagerFactoryImpl.java @@ -22,7 +22,7 @@ import org.openecomp.sdc.vendorsoftwareproduct.DeploymentFlavorManagerFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.ComputeDaoFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.DeploymentFlavorDaoFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDaoFactory; -import org.openecomp.sdc.vendorsoftwareproduct.factory.CompositionEntityDataManagerFactory; +import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManagerFactory; public class DeploymentFlavorManagerFactoryImpl extends DeploymentFlavorManagerFactory { diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/DeploymentFlavorManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/DeploymentFlavorManagerImpl.java index 14c5044984..b32ed637e2 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/DeploymentFlavorManagerImpl.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/DeploymentFlavorManagerImpl.java @@ -33,7 +33,7 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.type.DeploymentFlavorEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; import org.openecomp.sdc.vendorsoftwareproduct.errors.DeploymentFlavorErrorBuilder; import org.openecomp.sdc.vendorsoftwareproduct.errors.NotSupportedHeatOnboardMethodErrorBuilder; -import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; +import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManager; import org.openecomp.sdc.vendorsoftwareproduct.services.schemagenerator.SchemaGenerator; import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentComputeAssociation; @@ -56,7 +56,6 @@ public class DeploymentFlavorManagerImpl implements DeploymentFlavorManager { private final DeploymentFlavorDao deploymentFlavorDao; private final CompositionEntityDataManager compositionEntityDataManager; private final ComputeDao computeDao; - private static final String VSP_ID_DEPLOYMENT_FLAVOR_ID = "VSP id, deployment flavor id"; public DeploymentFlavorManagerImpl(VendorSoftwareProductInfoDao vspInfoDao, DeploymentFlavorDao deploymentFlavorDao, diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ImageManagerFactoryImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ImageManagerFactoryImpl.java index 9689615c70..6eb8582fc1 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ImageManagerFactoryImpl.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ImageManagerFactoryImpl.java @@ -5,7 +5,7 @@ import org.openecomp.sdc.vendorsoftwareproduct.ImageManager; import org.openecomp.sdc.vendorsoftwareproduct.ImageManagerFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.ImageDaoFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDaoFactory; -import org.openecomp.sdc.vendorsoftwareproduct.factory.CompositionEntityDataManagerFactory; +import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManagerFactory; public class ImageManagerFactoryImpl extends ImageManagerFactory { diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ImageManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ImageManagerImpl.java index 228d244872..efc50908cf 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ImageManagerImpl.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ImageManagerImpl.java @@ -34,7 +34,7 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ImageEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; import org.openecomp.sdc.vendorsoftwareproduct.errors.ImageErrorBuilder; import org.openecomp.sdc.vendorsoftwareproduct.errors.NotSupportedHeatOnboardMethodErrorBuilder; -import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; +import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManager; import org.openecomp.sdc.vendorsoftwareproduct.services.schemagenerator.SchemaGenerator; import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.QuestionnaireResponse; @@ -56,8 +56,6 @@ public class ImageManagerImpl implements ImageManager { private final VendorSoftwareProductInfoDao vspInfoDao; private final ImageDao imageDao; private final CompositionEntityDataManager compositionEntityDataManager; - private static final String VSP_ID = "VSP id"; - private static final String VSP_ID_COMPONENT_ID = "VSP id, component id"; public ImageManagerImpl(VendorSoftwareProductInfoDao vspInfoDao, ImageDao imageDao, diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/NetworkManagerFactoryImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/NetworkManagerFactoryImpl.java index a427b74c4f..25b22598d7 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/NetworkManagerFactoryImpl.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/NetworkManagerFactoryImpl.java @@ -24,7 +24,7 @@ import org.openecomp.sdc.vendorsoftwareproduct.NetworkManager; import org.openecomp.sdc.vendorsoftwareproduct.NetworkManagerFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.NetworkDaoFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDaoFactory; -import org.openecomp.sdc.vendorsoftwareproduct.factory.CompositionEntityDataManagerFactory; +import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManagerFactory; public class NetworkManagerFactoryImpl extends NetworkManagerFactory { private static final NetworkManager INSTANCE = diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/NetworkManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/NetworkManagerImpl.java index 106adaa625..027d7a1664 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/NetworkManagerImpl.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/NetworkManagerImpl.java @@ -29,7 +29,7 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; import org.openecomp.sdc.vendorsoftwareproduct.errors.CompositionEditNotAllowedErrorBuilder; -import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; +import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManager; import org.openecomp.sdc.vendorsoftwareproduct.services.schemagenerator.SchemaGenerator; import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType; @@ -47,9 +47,6 @@ public class NetworkManagerImpl implements NetworkManager { private final CompositionEntityDataManager compositionEntityDataManager; private final VendorSoftwareProductInfoDao VSPInfoDao; - private static final String VSP_ID = "VSP id"; - private static final String VSP_ID_NETWORK_ID = "VSP id, network id"; - public NetworkManagerImpl(NetworkDao networkDao, CompositionEntityDataManager compositionEntityDataManager, VendorSoftwareProductInfoDao vendorSoftwareProductInfoDao) { diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/NicManagerFactoryImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/NicManagerFactoryImpl.java index 6110519d81..cd4e3eaae9 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/NicManagerFactoryImpl.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/NicManagerFactoryImpl.java @@ -25,7 +25,7 @@ import org.openecomp.sdc.vendorsoftwareproduct.NicManager; import org.openecomp.sdc.vendorsoftwareproduct.NicManagerFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDaoFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDaoFactory; -import org.openecomp.sdc.vendorsoftwareproduct.factory.CompositionEntityDataManagerFactory; +import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManagerFactory; public class NicManagerFactoryImpl extends NicManagerFactory { private static final NicManager INSTANCE = diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/NicManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/NicManagerImpl.java index 2a86042040..35157264aa 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/NicManagerImpl.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/NicManagerImpl.java @@ -38,7 +38,7 @@ import org.openecomp.sdc.vendorsoftwareproduct.errors.NicErrorBuilder; import org.openecomp.sdc.vendorsoftwareproduct.errors.NicInternalNetworkErrorBuilder; import org.openecomp.sdc.vendorsoftwareproduct.errors.NicNetworkIdNotAllowedExternalNetworkErrorBuilder; import org.openecomp.sdc.vendorsoftwareproduct.errors.NotSupportedHeatOnboardMethodErrorBuilder; -import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; +import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManager; import org.openecomp.sdc.vendorsoftwareproduct.services.schemagenerator.SchemaGenerator; import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.QuestionnaireResponse; @@ -61,7 +61,6 @@ public class NicManagerImpl implements NicManager { private final CompositionEntityDataManager compositionEntityDataManager; private final NetworkManager networkManager; private final VendorSoftwareProductInfoDao vspInfoDao; - private static final String VSP_ID_COMPONENT_ID = "VSP id, component id"; public NicManagerImpl(NicDao nicDao, CompositionEntityDataManager compositionEntityDataManager, diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java index 692f6f3db7..a022fb697e 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java @@ -82,9 +82,9 @@ 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.VendorSoftwareProductInvalidErrorBuilder; -import org.openecomp.sdc.vendorsoftwareproduct.factory.CompositionEntityDataManagerFactory; +import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManagerFactory; import org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.InformationArtifactGenerator; -import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; +import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManager; import org.openecomp.sdc.vendorsoftwareproduct.services.schemagenerator.SchemaGenerator; import org.openecomp.sdc.vendorsoftwareproduct.types.QuestionnaireResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.QuestionnaireValidationResult; @@ -134,7 +134,6 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa private final ComputeDao computeDao; private final ImageDao imageDao; private final ManualVspToscaManager manualVspToscaManager; - private static final String VSP_ID = "VSP id"; private static final String PACKAGE_NOT_FOUND = "Package not found"; public VendorSoftwareProductManagerImpl( diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationUtil.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationUtil.java index 73598a2aee..9031e926a4 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationUtil.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationUtil.java @@ -61,9 +61,9 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateEnt import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; import org.openecomp.sdc.vendorsoftwareproduct.factory.CompositionDataExtractorFactory; -import org.openecomp.sdc.vendorsoftwareproduct.factory.CompositionEntityDataManagerFactory; +import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManagerFactory; import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionDataExtractor; -import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; +import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManager; import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; import org.openecomp.sdc.versioning.dao.types.Version; diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/resources/factoryConfiguration.json b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/resources/factoryConfiguration.json index 71d42932d9..24c2f260d8 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/resources/factoryConfiguration.json +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/resources/factoryConfiguration.json @@ -1,5 +1,6 @@ { "org.openecomp.sdc.vendorsoftwareproduct.VspManagerFactory": "org.openecomp.sdc.vendorsoftwareproduct.impl.VspManagerFactoryImpl", + "org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManagerFactory": "org.openecomp.sdc.vendorsoftwareproduct.impl.CompositionEntityDataManagerFactoryImpl", "org.openecomp.sdc.vendorsoftwareproduct.ComponentManagerFactory": "org.openecomp.sdc.vendorsoftwareproduct.impl.ComponentManagerFactoryImpl", "org.openecomp.sdc.vendorsoftwareproduct.NetworkManagerFactory": "org.openecomp.sdc.vendorsoftwareproduct.impl.NetworkManagerFactoryImpl", "org.openecomp.sdc.vendorsoftwareproduct.NicManagerFactory": "org.openecomp.sdc.vendorsoftwareproduct.impl.NicManagerFactoryImpl", diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/ImagesTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/ImagesTest.java index 698afe62d4..52b154687b 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/ImagesTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/ImagesTest.java @@ -9,7 +9,6 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ImageEntity; import org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes; import org.openecomp.sdc.vendorsoftwareproduct.impl.ImageManagerImpl; -import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; import org.openecomp.sdc.versioning.dao.types.Version; import org.testng.Assert; import org.testng.annotations.AfterMethod; diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/QuestionnaireDataServiceTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/QuestionnaireDataServiceTest.java index e8e0f2c92b..58ac65953a 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/QuestionnaireDataServiceTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/QuestionnaireDataServiceTest.java @@ -38,7 +38,6 @@ import org.openecomp.sdc.vendorsoftwareproduct.impl.OrchestrationTemplateCandida import org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.InformationArtifactData; import org.openecomp.sdc.vendorsoftwareproduct.questionnaire.QuestionnaireDataService; import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionDataExtractor; -import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService; import org.openecomp.sdc.vendorsoftwareproduct.tree.UploadFileTest; import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComponentManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComponentManagerImplTest.java index 047015e16a..3652223e61 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComponentManagerImplTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComponentManagerImplTest.java @@ -11,7 +11,7 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity; import org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes; -import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; +import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManager; import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.QuestionnaireResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentData; diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/CompositionEntityDataManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/CompositionEntityDataManagerImplTest.java new file mode 100644 index 0000000000..2713b4ca2f --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/CompositionEntityDataManagerImplTest.java @@ -0,0 +1,281 @@ +/*- + * ============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 org.apache.commons.collections.CollectionUtils; +import org.mockito.InjectMocks; +import org.mockito.MockitoAnnotations; +import org.mockito.Spy; +import org.openecomp.core.utilities.file.FileUtils; +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspQuestionnaireEntity; +import org.openecomp.sdc.vendorsoftwareproduct.impl.CompositionEntityDataManagerImpl; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityId; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityValidationData; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Network; +import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.NetworkCompositionSchemaInput; +import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.SchemaTemplateContext; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.testng.Assert; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; + +import static org.mockito.Mockito.doReturn; + +public class CompositionEntityDataManagerImplTest { + private static final String VSP1 = "vsp1"; + private static final Version VERSION = new Version(0, 1); + private static final String COMPONENT1 = "component1"; + private static final String NIC1 = "nic1"; + private static final String SIMPLE_SCHEMA = "{\n" + + " \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n" + + " \"type\": \"object\",\n" + + " \"properties\": {\n" + + " \"a\": {\n" + + " \"type\": \"number\"\n" + + " }\n" + + " }\n" + + "}"; + private static final String NETWORK_COMPOSITION_SCHEMA = "{\n" + + " \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n" + + " \"type\": \"object\",\n" + + " \"properties\": {\n" + + " \"name\": {\n" + + " \"type\": \"string\",\n" + + " \"enum\": [\n" + + " \"network1 name\"\n" + + " ],\n" + + " \"default\": \"network1 name\"\n" + + " },\n" + + " \"dhcp\": {\n" + + " \"type\": \"boolean\",\n" + + " \"enum\": [\n" + + " true\n" + + " ],\n" + + " \"default\": true\n" + + " }\n" + + " },\n" + + " \"additionalProperties\": false,\n" + + " \"required\": [\n" + + " \"name\",\n" + + " \"dhcp\"\n" + + " ]\n" + + "}"; + + private Map> errorsById; + @InjectMocks + @Spy + private CompositionEntityDataManagerImpl compositionEntityDataManager; + + @BeforeMethod + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + } + + @Test(expectedExceptions = CoreException.class) + public void testAddNullEntity_negative() { + compositionEntityDataManager.addEntity(null, null); + } + + @Test + public void testAddEntity() { + compositionEntityDataManager + .addEntity(new VspQuestionnaireEntity(VSP1, VERSION), null); + + String invalidQuestionnaireData = "{\"a\": \"b\"}"; + + ComponentEntity component = new ComponentEntity(VSP1, VERSION, COMPONENT1); + component.setQuestionnaireData(invalidQuestionnaireData); + compositionEntityDataManager.addEntity(component, null); + + NicEntity nic = new NicEntity(VSP1, VERSION, COMPONENT1, NIC1); + nic.setQuestionnaireData(invalidQuestionnaireData); + compositionEntityDataManager.addEntity(nic, null); + } + + // TODO: 3/15/2017 fix and enable + //@Test(dependsOnMethods = "testAddEntity") + public void testValidateEntitiesQuestionnaire() { + doReturn(SIMPLE_SCHEMA).when(compositionEntityDataManager) + .generateSchema(SchemaTemplateContext.questionnaire, CompositionEntityType.vsp, null); + doReturn(SIMPLE_SCHEMA).when(compositionEntityDataManager) + .generateSchema(SchemaTemplateContext.questionnaire, CompositionEntityType.component, null); + doReturn(SIMPLE_SCHEMA).when(compositionEntityDataManager) + .generateSchema(SchemaTemplateContext.questionnaire, CompositionEntityType.nic, null); + + errorsById = compositionEntityDataManager.validateEntitiesQuestionnaire(); + Assert.assertNotNull(errorsById); + Assert.assertEquals(errorsById.size(), 2); // both component and nic data don't mach schemas + CompositionEntityId nicId = + new NicEntity(VSP1, VERSION, COMPONENT1, NIC1).getCompositionEntityId(); + Assert.assertTrue(errorsById.containsKey(nicId)); + Assert.assertTrue(errorsById.containsKey(nicId.getParentId())); + } + + @Test(dependsOnMethods = "testAddEntity") + public void testBuildTrees() { + compositionEntityDataManager.buildTrees(); + } + + // TODO: 3/15/2017 fix and enable + //@Test(dependsOnMethods = "testBuildTrees") + public void testAddErrorsToTrees() { + compositionEntityDataManager.addErrorsToTrees(errorsById); + } + + // TODO: 3/15/2017 fix and enable + //@Test(dependsOnMethods = "testAddErrorsToTrees") + public void testGetTrees() { + Collection trees = compositionEntityDataManager.getTrees(); + Assert.assertNotNull(trees); + Assert.assertEquals(trees.size(), 1); + + CompositionEntityValidationData vspValidationData = trees.iterator().next(); + assertValidationData(vspValidationData, VSP1, CompositionEntityType.vsp, false); + Assert.assertEquals(vspValidationData.getSubEntitiesValidationData().size(), 1); + + CompositionEntityValidationData componentValidationData = + vspValidationData.getSubEntitiesValidationData().iterator().next(); + assertValidationData(componentValidationData, COMPONENT1, CompositionEntityType.component, + true); + Assert.assertEquals(componentValidationData.getSubEntitiesValidationData().size(), 1); + + CompositionEntityValidationData nicValidationData = + componentValidationData.getSubEntitiesValidationData().iterator().next(); + assertValidationData(nicValidationData, NIC1, CompositionEntityType.nic, true); + Assert.assertNull(nicValidationData.getSubEntitiesValidationData()); + } + + @Test + public void testValidateValidEntity() { + NetworkEntity networkEntity = new NetworkEntity(VSP1, VERSION, "network1"); + Network network = new Network(); + network.setName("network1 name"); + network.setDhcp(true); + networkEntity.setNetworkCompositionData(network); + + NetworkCompositionSchemaInput schemaTemplateInput = new NetworkCompositionSchemaInput(); + schemaTemplateInput.setManual(false); + schemaTemplateInput.setNetwork(network); + + doReturn(NETWORK_COMPOSITION_SCHEMA).when(compositionEntityDataManager) + .generateSchema(SchemaTemplateContext.composition, CompositionEntityType.network, + schemaTemplateInput); + + CompositionEntityValidationData validationData = compositionEntityDataManager + .validateEntity(networkEntity, SchemaTemplateContext.composition, schemaTemplateInput); + assertValidationData(validationData, "network1", CompositionEntityType.network, false); + } + + @Test + public void testValidateInvalidEntity() { + NetworkEntity networkEntity = new NetworkEntity(VSP1, VERSION, "network1"); + Network network = new Network(); + network.setName("network1 name changed"); + network.setDhcp(false); + networkEntity.setNetworkCompositionData(network); + + NetworkCompositionSchemaInput schemaTemplateInput = new NetworkCompositionSchemaInput(); + schemaTemplateInput.setManual(false); + Network origNetwork = new Network(); + origNetwork.setName("network1 name"); + origNetwork.setDhcp(true); + schemaTemplateInput.setNetwork(origNetwork); + + doReturn(NETWORK_COMPOSITION_SCHEMA).when(compositionEntityDataManager) + .generateSchema(SchemaTemplateContext.composition, CompositionEntityType.network, + schemaTemplateInput); + + CompositionEntityValidationData validationData = compositionEntityDataManager + .validateEntity(networkEntity, SchemaTemplateContext.composition, schemaTemplateInput); + assertValidationData(validationData, "network1", CompositionEntityType.network, true); + Assert.assertEquals(validationData.getErrors().size(), 2); + } + + @Test + public void testNicAndComponentValidQuestionnaire() { + compositionEntityDataManager + .addEntity(new VspQuestionnaireEntity(VSP1, VERSION), null); + + ComponentEntity componentEntity = new ComponentEntity(VSP1, VERSION, COMPONENT1); + componentEntity.setQuestionnaireData(loadFileToString("quesionnaire/validComponent.json")); + compositionEntityDataManager.addEntity(componentEntity, null); + + NicEntity nicEntity = new NicEntity(VSP1, VERSION, COMPONENT1, NIC1); + nicEntity.setQuestionnaireData(loadFileToString("quesionnaire/validNic.json")); + compositionEntityDataManager.addEntity(nicEntity, null); + + doReturn(SIMPLE_SCHEMA) + .when(compositionEntityDataManager) + .generateSchema(SchemaTemplateContext.questionnaire, CompositionEntityType.vsp, null); + + doReturn(loadFileToString("quesionnaire/schema/componentQuestionnaire.json")) + .when(compositionEntityDataManager) + .generateSchema(SchemaTemplateContext.questionnaire, CompositionEntityType.component, null); + + doReturn(loadFileToString("quesionnaire/schema/nicQuestionnaire.json")) + .when(compositionEntityDataManager) + .generateSchema(SchemaTemplateContext.questionnaire, CompositionEntityType.nic, null); + + Map> errorsById = + compositionEntityDataManager.validateEntitiesQuestionnaire(); + Assert.assertEquals(errorsById.size(), 1); + } + + @Test(dependsOnMethods = "testNicAndComponentValidQuestionnaire") + public void testComponentInvalidQuestionnaire() { + ComponentEntity componentEntity = new ComponentEntity(VSP1, VERSION, COMPONENT1); + componentEntity.setQuestionnaireData(loadFileToString("quesionnaire/invalidComponent.json")); + compositionEntityDataManager.addEntity(componentEntity, null); + + Map> errorsById = + compositionEntityDataManager.validateEntitiesQuestionnaire(); + Assert.assertEquals(errorsById.size(), 2); + + CompositionEntityId component = new ArrayList<>(errorsById.keySet()).get(1); + List errors = (List) errorsById.get(component); + Assert.assertEquals(errors.size(), 1); + Assert.assertEquals(errors.get(0), + "#/general/recovery/pointObjective: 20.0 is not lower or equal to 15"); + } + + private static void assertValidationData(CompositionEntityValidationData validationData, + String id, CompositionEntityType type, + boolean hasErrors) { + Assert.assertNotNull(validationData); + Assert.assertEquals(validationData.getEntityId(), id); + Assert.assertEquals(validationData.getEntityType(), type); + Assert.assertTrue(CollectionUtils.isNotEmpty(validationData.getErrors()) == hasErrors); + } + + private static String loadFileToString(String path) { + return new String(FileUtils.toByteArray(FileUtils.loadFileToInputStream(path))); + } +} \ No newline at end of file diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComputeManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComputeManagerImplTest.java index 265ba007d4..9479e08af8 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComputeManagerImplTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComputeManagerImplTest.java @@ -13,7 +13,7 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.DeploymentFlavorDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComputeEntity; import org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes; -import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; +import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManager; import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.ListComputeResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.QuestionnaireResponse; diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/DeploymentFlavorManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/DeploymentFlavorManagerImplTest.java index 1c2aade1fe..3dce0d01cf 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/DeploymentFlavorManagerImplTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/DeploymentFlavorManagerImplTest.java @@ -16,7 +16,7 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComputeEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.DeploymentFlavorEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; import org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes; -import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; +import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManager; import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentComputeAssociation; import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType; import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityValidationData; diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ImageManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ImageManagerImplTest.java index 553e433ccb..3a9af0d752 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ImageManagerImplTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ImageManagerImplTest.java @@ -10,7 +10,7 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.ImageDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ImageEntity; import org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes; -import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; +import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManager; import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.QuestionnaireResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType; diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/NetworkManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/NetworkManagerImplTest.java index f3cb2035da..9e2cee6ace 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/NetworkManagerImplTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/NetworkManagerImplTest.java @@ -33,7 +33,7 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.NetworkDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity; import org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes; -import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; +import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManager; import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType; import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityValidationData; diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/NicManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/NicManagerImplTest.java index dd71073cbd..c63e5bd21b 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/NicManagerImplTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/NicManagerImplTest.java @@ -13,7 +13,7 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity; import org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes; -import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; +import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManager; import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.QuestionnaireResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType; diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImplTest.java index 4e22cf794e..cc262ed869 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImplTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImplTest.java @@ -57,7 +57,7 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.type.PackageInfo; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; import org.openecomp.sdc.vendorsoftwareproduct.impl.mock.EnrichmentManagerFactoryImpl; import org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.InformationArtifactGenerator; -import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; +import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManager; import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.ValidationResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.composition.DeploymentFlavor; diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/composition/CompositionEntityDataManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/composition/CompositionEntityDataManagerImplTest.java deleted file mode 100644 index 0d9245d779..0000000000 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/composition/CompositionEntityDataManagerImplTest.java +++ /dev/null @@ -1,280 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.vendorsoftwareproduct.services.impl.composition; - -import org.apache.commons.collections.CollectionUtils; -import org.mockito.InjectMocks; -import org.mockito.MockitoAnnotations; -import org.mockito.Spy; -import org.openecomp.core.utilities.file.FileUtils; -import org.openecomp.sdc.common.errors.CoreException; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspQuestionnaireEntity; -import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityId; -import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType; -import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityValidationData; -import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Network; -import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.NetworkCompositionSchemaInput; -import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.SchemaTemplateContext; -import org.openecomp.sdc.versioning.dao.types.Version; -import org.testng.Assert; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; - -import static org.mockito.Mockito.doReturn; - -public class CompositionEntityDataManagerImplTest { - private static final String VSP1 = "vsp1"; - private static final Version VERSION = new Version(0, 1); - private static final String COMPONENT1 = "component1"; - private static final String NIC1 = "nic1"; - private static final String SIMPLE_SCHEMA = "{\n" + - " \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n" + - " \"type\": \"object\",\n" + - " \"properties\": {\n" + - " \"a\": {\n" + - " \"type\": \"number\"\n" + - " }\n" + - " }\n" + - "}"; - private static final String NETWORK_COMPOSITION_SCHEMA = "{\n" + - " \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n" + - " \"type\": \"object\",\n" + - " \"properties\": {\n" + - " \"name\": {\n" + - " \"type\": \"string\",\n" + - " \"enum\": [\n" + - " \"network1 name\"\n" + - " ],\n" + - " \"default\": \"network1 name\"\n" + - " },\n" + - " \"dhcp\": {\n" + - " \"type\": \"boolean\",\n" + - " \"enum\": [\n" + - " true\n" + - " ],\n" + - " \"default\": true\n" + - " }\n" + - " },\n" + - " \"additionalProperties\": false,\n" + - " \"required\": [\n" + - " \"name\",\n" + - " \"dhcp\"\n" + - " ]\n" + - "}"; - - private Map> errorsById; - @InjectMocks - @Spy - private CompositionEntityDataManagerImpl compositionEntityDataManager; - - @BeforeMethod - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - } - - @Test(expectedExceptions = CoreException.class) - public void testAddNullEntity_negative() { - compositionEntityDataManager.addEntity(null, null); - } - - @Test - public void testAddEntity() { - compositionEntityDataManager - .addEntity(new VspQuestionnaireEntity(VSP1, VERSION), null); - - String invalidQuestionnaireData = "{\"a\": \"b\"}"; - - ComponentEntity component = new ComponentEntity(VSP1, VERSION, COMPONENT1); - component.setQuestionnaireData(invalidQuestionnaireData); - compositionEntityDataManager.addEntity(component, null); - - NicEntity nic = new NicEntity(VSP1, VERSION, COMPONENT1, NIC1); - nic.setQuestionnaireData(invalidQuestionnaireData); - compositionEntityDataManager.addEntity(nic, null); - } - - // TODO: 3/15/2017 fix and enable - //@Test(dependsOnMethods = "testAddEntity") - public void testValidateEntitiesQuestionnaire() { - doReturn(SIMPLE_SCHEMA).when(compositionEntityDataManager) - .generateSchema(SchemaTemplateContext.questionnaire, CompositionEntityType.vsp, null); - doReturn(SIMPLE_SCHEMA).when(compositionEntityDataManager) - .generateSchema(SchemaTemplateContext.questionnaire, CompositionEntityType.component, null); - doReturn(SIMPLE_SCHEMA).when(compositionEntityDataManager) - .generateSchema(SchemaTemplateContext.questionnaire, CompositionEntityType.nic, null); - - errorsById = compositionEntityDataManager.validateEntitiesQuestionnaire(); - Assert.assertNotNull(errorsById); - Assert.assertEquals(errorsById.size(), 2); // both component and nic data don't mach schemas - CompositionEntityId nicId = - new NicEntity(VSP1, VERSION, COMPONENT1, NIC1).getCompositionEntityId(); - Assert.assertTrue(errorsById.containsKey(nicId)); - Assert.assertTrue(errorsById.containsKey(nicId.getParentId())); - } - - @Test(dependsOnMethods = "testAddEntity") - public void testBuildTrees() { - compositionEntityDataManager.buildTrees(); - } - - // TODO: 3/15/2017 fix and enable - //@Test(dependsOnMethods = "testBuildTrees") - public void testAddErrorsToTrees() { - compositionEntityDataManager.addErrorsToTrees(errorsById); - } - - // TODO: 3/15/2017 fix and enable - //@Test(dependsOnMethods = "testAddErrorsToTrees") - public void testGetTrees() { - Collection trees = compositionEntityDataManager.getTrees(); - Assert.assertNotNull(trees); - Assert.assertEquals(trees.size(), 1); - - CompositionEntityValidationData vspValidationData = trees.iterator().next(); - assertValidationData(vspValidationData, VSP1, CompositionEntityType.vsp, false); - Assert.assertEquals(vspValidationData.getSubEntitiesValidationData().size(), 1); - - CompositionEntityValidationData componentValidationData = - vspValidationData.getSubEntitiesValidationData().iterator().next(); - assertValidationData(componentValidationData, COMPONENT1, CompositionEntityType.component, - true); - Assert.assertEquals(componentValidationData.getSubEntitiesValidationData().size(), 1); - - CompositionEntityValidationData nicValidationData = - componentValidationData.getSubEntitiesValidationData().iterator().next(); - assertValidationData(nicValidationData, NIC1, CompositionEntityType.nic, true); - Assert.assertNull(nicValidationData.getSubEntitiesValidationData()); - } - - @Test - public void testValidateValidEntity() { - NetworkEntity networkEntity = new NetworkEntity(VSP1, VERSION, "network1"); - Network network = new Network(); - network.setName("network1 name"); - network.setDhcp(true); - networkEntity.setNetworkCompositionData(network); - - NetworkCompositionSchemaInput schemaTemplateInput = new NetworkCompositionSchemaInput(); - schemaTemplateInput.setManual(false); - schemaTemplateInput.setNetwork(network); - - doReturn(NETWORK_COMPOSITION_SCHEMA).when(compositionEntityDataManager) - .generateSchema(SchemaTemplateContext.composition, CompositionEntityType.network, - schemaTemplateInput); - - CompositionEntityValidationData validationData = compositionEntityDataManager - .validateEntity(networkEntity, SchemaTemplateContext.composition, schemaTemplateInput); - assertValidationData(validationData, "network1", CompositionEntityType.network, false); - } - - @Test - public void testValidateInvalidEntity() { - NetworkEntity networkEntity = new NetworkEntity(VSP1, VERSION, "network1"); - Network network = new Network(); - network.setName("network1 name changed"); - network.setDhcp(false); - networkEntity.setNetworkCompositionData(network); - - NetworkCompositionSchemaInput schemaTemplateInput = new NetworkCompositionSchemaInput(); - schemaTemplateInput.setManual(false); - Network origNetwork = new Network(); - origNetwork.setName("network1 name"); - origNetwork.setDhcp(true); - schemaTemplateInput.setNetwork(origNetwork); - - doReturn(NETWORK_COMPOSITION_SCHEMA).when(compositionEntityDataManager) - .generateSchema(SchemaTemplateContext.composition, CompositionEntityType.network, - schemaTemplateInput); - - CompositionEntityValidationData validationData = compositionEntityDataManager - .validateEntity(networkEntity, SchemaTemplateContext.composition, schemaTemplateInput); - assertValidationData(validationData, "network1", CompositionEntityType.network, true); - Assert.assertEquals(validationData.getErrors().size(), 2); - } - - @Test - public void testNicAndComponentValidQuestionnaire() { - compositionEntityDataManager - .addEntity(new VspQuestionnaireEntity(VSP1, VERSION), null); - - ComponentEntity componentEntity = new ComponentEntity(VSP1, VERSION, COMPONENT1); - componentEntity.setQuestionnaireData(loadFileToString("quesionnaire/validComponent.json")); - compositionEntityDataManager.addEntity(componentEntity, null); - - NicEntity nicEntity = new NicEntity(VSP1, VERSION, COMPONENT1, NIC1); - nicEntity.setQuestionnaireData(loadFileToString("quesionnaire/validNic.json")); - compositionEntityDataManager.addEntity(nicEntity, null); - - doReturn(SIMPLE_SCHEMA) - .when(compositionEntityDataManager) - .generateSchema(SchemaTemplateContext.questionnaire, CompositionEntityType.vsp, null); - - doReturn(loadFileToString("quesionnaire/schema/componentQuestionnaire.json")) - .when(compositionEntityDataManager) - .generateSchema(SchemaTemplateContext.questionnaire, CompositionEntityType.component, null); - - doReturn(loadFileToString("quesionnaire/schema/nicQuestionnaire.json")) - .when(compositionEntityDataManager) - .generateSchema(SchemaTemplateContext.questionnaire, CompositionEntityType.nic, null); - - Map> errorsById = - compositionEntityDataManager.validateEntitiesQuestionnaire(); - Assert.assertEquals(errorsById.size(), 1); - } - - @Test(dependsOnMethods = "testNicAndComponentValidQuestionnaire") - public void testComponentInvalidQuestionnaire() { - ComponentEntity componentEntity = new ComponentEntity(VSP1, VERSION, COMPONENT1); - componentEntity.setQuestionnaireData(loadFileToString("quesionnaire/invalidComponent.json")); - compositionEntityDataManager.addEntity(componentEntity, null); - - Map> errorsById = - compositionEntityDataManager.validateEntitiesQuestionnaire(); - Assert.assertEquals(errorsById.size(), 2); - - CompositionEntityId component = new ArrayList<>(errorsById.keySet()).get(1); - List errors = (List) errorsById.get(component); - Assert.assertEquals(errors.size(), 1); - Assert.assertEquals(errors.get(0), - "#/general/recovery/pointObjective: 20.0 is not lower or equal to 15"); - } - - private static void assertValidationData(CompositionEntityValidationData validationData, - String id, CompositionEntityType type, - boolean hasErrors) { - Assert.assertNotNull(validationData); - Assert.assertEquals(validationData.getEntityId(), id); - Assert.assertEquals(validationData.getEntityType(), type); - Assert.assertTrue(CollectionUtils.isNotEmpty(validationData.getErrors()) == hasErrors); - } - - private static String loadFileToString(String path) { - return new String(FileUtils.toByteArray(FileUtils.loadFileToInputStream(path))); - } -} \ No newline at end of file diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/UploadFileTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/UploadFileTest.java index 2a475fe895..b8630a8c3b 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/UploadFileTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/UploadFileTest.java @@ -36,7 +36,7 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateEnt import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; import org.openecomp.sdc.vendorsoftwareproduct.impl.OrchestrationTemplateCandidateManagerImpl; import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionDataExtractor; -import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; +import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManager; import org.openecomp.sdc.vendorsoftwareproduct.services.impl.filedatastructuremodule.CandidateServiceImpl; import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; import org.openecomp.sdc.vendorsoftwareproduct.utils.VSPCommon; diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/factory/CompositionEntityDataManagerFactory.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/factory/CompositionEntityDataManagerFactory.java deleted file mode 100644 index bcb6174dce..0000000000 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/factory/CompositionEntityDataManagerFactory.java +++ /dev/null @@ -1,33 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.vendorsoftwareproduct.factory; - -import org.openecomp.core.factory.api.AbstractComponentFactory; -import org.openecomp.core.factory.api.AbstractFactory; -import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; - -public abstract class CompositionEntityDataManagerFactory extends - AbstractComponentFactory { - - public static CompositionEntityDataManagerFactory getInstance() { - return AbstractFactory.getInstance(CompositionEntityDataManagerFactory.class); - } -} diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/composition/CompositionEntityDataManager.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/composition/CompositionEntityDataManager.java deleted file mode 100644 index ff78fff689..0000000000 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/composition/CompositionEntityDataManager.java +++ /dev/null @@ -1,87 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.vendorsoftwareproduct.services.composition; - -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.CompositionEntity; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.DeploymentFlavorEntity; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ImageEntity; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity; -import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Component; -import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionData; -import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityId; -import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityValidationData; -import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.SchemaTemplateContext; -import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.SchemaTemplateInput; -import org.openecomp.sdc.versioning.dao.types.Version; - -import java.util.Collection; -import java.util.Map; -import java.util.Set; - -public interface CompositionEntityDataManager { - - Map> validateEntitiesQuestionnaire(); - - void addEntity(CompositionEntity entity, SchemaTemplateInput schemaTemplateInput); - - CompositionEntityValidationData validateEntity(CompositionEntity entity, - SchemaTemplateContext schemaTemplateContext, - SchemaTemplateInput schemaTemplateInput); - - void buildTrees(); - - void addErrorsToTrees(Map> errors); - - Set getEntityListWithErrors(); - - Collection getTrees(); - - void saveCompositionData(String vspId, Version version, CompositionData compositionData); - - Set getAllErrorsByVsp(String vspId); - - void saveComponents(String vspId, Version version, CompositionData compositionData, - Map networkIdByName); - - void saveNicsByComponent(String vspId, Version version, Map networkIdByName, - Component component, String componentId); - - Map saveNetworks(String vspId, Version version, CompositionData compositionData); - - NetworkEntity createNetwork(NetworkEntity network); - - ComponentEntity createComponent(ComponentEntity component); - - NicEntity createNic(NicEntity nic); - - DeploymentFlavorEntity createDeploymentFlavor(DeploymentFlavorEntity deploymentFlavor); - - ImageEntity createImage(ImageEntity image); - - void saveComputesFlavorByComponent(String vspId, Version version, Component component, - String componentId); - - void saveImagesByComponent(String vspId, Version version, Component component, - String componentId); - -} diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/resources/factoryConfiguration.json b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/resources/factoryConfiguration.json index 90160c4b12..ec51497d66 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/resources/factoryConfiguration.json +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/resources/factoryConfiguration.json @@ -16,7 +16,6 @@ "org.openecomp.sdc.vendorsoftwareproduct.factory.InformationArtifactGeneratorFactory":"org.openecomp.sdc.vendorsoftwareproduct.factory.InformationArtifactGeneratorFactoryImpl", "org.openecomp.sdc.vendorsoftwareproduct.factory.CandidateServiceFactory": "org.openecomp.sdc.vendorsoftwareproduct.factory.impl.CandidateServiceFactoryImpl", "org.openecomp.sdc.vendorsoftwareproduct.factory.CompositionDataExtractorFactory": "org.openecomp.sdc.vendorsoftwareproduct.factory.impl.CompositionDataExtractorFactoryImpl", - "org.openecomp.sdc.vendorsoftwareproduct.factory.CompositionEntityDataManagerFactory": "org.openecomp.sdc.vendorsoftwareproduct.factory.impl.CompositionEntityDataManagerFactoryImpl", "org.openecomp.sdc.vendorsoftwareproduct.factory.ManifestCreatorFactory": "org.openecomp.sdc.vendorsoftwareproduct.factory.impl.ManifestCreatorFactoryImpl", "org.openecomp.sdc.vendorsoftwareproduct.dao.DeploymentFlavorDaoFactory": "org.openecomp.sdc.vendorsoftwareproduct.dao.impl.DeploymentFlavorDaoFactoryImpl", "org.openecomp.sdc.vendorsoftwareproduct.dao.ComputeDaoFactory": "org.openecomp.sdc.vendorsoftwareproduct.dao.impl.ComputeDaoFactoryImpl", diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/factory/impl/CompositionEntityDataManagerFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/factory/impl/CompositionEntityDataManagerFactoryImpl.java deleted file mode 100644 index 08d911b686..0000000000 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/factory/impl/CompositionEntityDataManagerFactoryImpl.java +++ /dev/null @@ -1,48 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.vendorsoftwareproduct.factory.impl; - -import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDaoFactory; -import org.openecomp.sdc.vendorsoftwareproduct.dao.ComputeDaoFactory; -import org.openecomp.sdc.vendorsoftwareproduct.dao.DeploymentFlavorDaoFactory; -import org.openecomp.sdc.vendorsoftwareproduct.dao.ImageDaoFactory; -import org.openecomp.sdc.vendorsoftwareproduct.dao.NetworkDaoFactory; -import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDaoFactory; -import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDaoFactory; -import org.openecomp.sdc.vendorsoftwareproduct.factory.CompositionEntityDataManagerFactory; -import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; -import org.openecomp.sdc.vendorsoftwareproduct.services.impl.composition.CompositionEntityDataManagerImpl; - -public class CompositionEntityDataManagerFactoryImpl extends CompositionEntityDataManagerFactory { - - @Override - public CompositionEntityDataManager createInterface() { - // this class is stateful! it must be recreated from scratch on every use!!! - return new CompositionEntityDataManagerImpl( - VendorSoftwareProductInfoDaoFactory.getInstance().createInterface(), - ComponentDaoFactory.getInstance().createInterface(), - NicDaoFactory.getInstance().createInterface(), - NetworkDaoFactory.getInstance().createInterface(), - ImageDaoFactory.getInstance().createInterface(), - ComputeDaoFactory.getInstance().createInterface(), - DeploymentFlavorDaoFactory.getInstance().createInterface()); - } -} diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/composition/CompositionEntityDataManagerImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/composition/CompositionEntityDataManagerImpl.java deleted file mode 100644 index 51a3689943..0000000000 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/composition/CompositionEntityDataManagerImpl.java +++ /dev/null @@ -1,638 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.vendorsoftwareproduct.services.impl.composition; - -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.collections4.MapUtils; -import org.openecomp.core.utilities.CommonMethods; -import org.openecomp.core.utilities.json.JsonSchemaDataGenerator; -import org.openecomp.core.utilities.json.JsonUtil; -import org.openecomp.sdc.common.errors.CoreException; -import org.openecomp.sdc.common.errors.ErrorCategory; -import org.openecomp.sdc.common.errors.ErrorCode; -import org.openecomp.sdc.logging.api.Logger; -import org.openecomp.sdc.logging.api.LoggerFactory; -import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.ComputeDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.DeploymentFlavorDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.ImageDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.NetworkDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.CompositionEntity; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComputeEntity; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.DeploymentFlavorEntity; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ImageEntity; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspQuestionnaireEntity; -import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; -import org.openecomp.sdc.vendorsoftwareproduct.services.schemagenerator.SchemaGenerator; -import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Component; -import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentData; -import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionData; -import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityId; -import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType; -import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityValidationData; -import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComputeData; -import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Image; -import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Network; -import org.openecomp.sdc.vendorsoftwareproduct.types.composition.NetworkType; -import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic; -import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.SchemaTemplateContext; -import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.SchemaTemplateInput; -import org.openecomp.sdc.versioning.dao.types.Version; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Set; - -public class CompositionEntityDataManagerImpl implements CompositionEntityDataManager { - - private static final String COMPOSITION_ENTITY_DATA_MANAGER_ERR = - "COMPOSITION_ENTITY_DATA_MANAGER_ERR"; - private static final String COMPOSITION_ENTITY_DATA_MANAGER_ERR_MSG = - "Invalid input: %s may not be null"; - private static final String MISSING_OR_INVALID_QUESTIONNAIRE_MSG = - "Data is missing/invalid for this %s. Please refill and resubmit."; - - private static final Logger logger = - LoggerFactory.getLogger(CompositionEntityDataManagerImpl.class); - private Map entities = new HashMap<>(); - private Map nonDynamicSchemas = new HashMap<>(); - private List roots = new ArrayList<>(); - - private VendorSoftwareProductInfoDao vspInfoDao; - private ComponentDao componentDao; - private NicDao nicDao; - private NetworkDao networkDao; - private ImageDao imageDao; - private ComputeDao computeDao; - private DeploymentFlavorDao deploymentFlavorDao; - - public CompositionEntityDataManagerImpl(VendorSoftwareProductInfoDao vspInfoDao, - ComponentDao componentDao, - NicDao nicDao, NetworkDao networkDao, - ImageDao imageDao, ComputeDao computeDao, - DeploymentFlavorDao deploymentFlavorDao) { - this.vspInfoDao = vspInfoDao; - this.componentDao = componentDao; - this.nicDao = nicDao; - this.networkDao = networkDao; - this.imageDao = imageDao; - this.computeDao = computeDao; - this.deploymentFlavorDao = deploymentFlavorDao; - } - - /** - * Validate entity composition entity validation data. - * - * @param entity the entity - * @param schemaTemplateContext the schema template context - * @param schemaTemplateInput the schema template input - * @return the composition entity validation data - */ - @Override - public CompositionEntityValidationData validateEntity(CompositionEntity entity, - SchemaTemplateContext schemaTemplateContext, - SchemaTemplateInput schemaTemplateInput) { - if (entity == null) { - throw new CoreException( - new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION) - .withId(COMPOSITION_ENTITY_DATA_MANAGER_ERR).withMessage( - String.format(COMPOSITION_ENTITY_DATA_MANAGER_ERR_MSG, "composition entity")) - .build()); - } - if (schemaTemplateContext == null) { - throw new CoreException( - new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION) - .withId(COMPOSITION_ENTITY_DATA_MANAGER_ERR).withMessage( - String.format(COMPOSITION_ENTITY_DATA_MANAGER_ERR_MSG, "schema template context")) - .build()); - } - - CompositionEntityValidationData validationData = - new CompositionEntityValidationData(entity.getType(), entity.getId()); - String json = - schemaTemplateContext == SchemaTemplateContext.composition ? entity.getCompositionData() - : entity.getQuestionnaireData(); - validationData.setErrors(JsonUtil.validate( - json == null ? JsonUtil.object2Json(new Object()) : json, - generateSchema(schemaTemplateContext, entity.getType(), schemaTemplateInput))); - return validationData; - } - - /** - * Add entity. - * - * @param entity the entity - * @param schemaTemplateInput the schema template input - */ - @Override - public void addEntity(CompositionEntity entity, SchemaTemplateInput schemaTemplateInput) { - if (entity == null) { - throw new CoreException( - new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION) - .withId(COMPOSITION_ENTITY_DATA_MANAGER_ERR).withMessage( - String.format(COMPOSITION_ENTITY_DATA_MANAGER_ERR_MSG, "composition entity")) - .build()); - } - entities.put(entity.getCompositionEntityId(), - new CompositionEntityData(entity, schemaTemplateInput)); - } - - /** - * Validate entities questionnaire map. - * - * @return the map - */ - @Override - public Map> validateEntitiesQuestionnaire() { - Map> errorsByEntityId = new HashMap<>(); - entities.entrySet().forEach(entry -> { - Collection errors = validateQuestionnaire(entry.getValue()); - if (errors != null) { - errorsByEntityId.put(entry.getKey(), errors); - } - }); - return errorsByEntityId; - } - - /** - * Build trees. - */ - @Override - public void buildTrees() { - Map entitiesValidationData = - new HashMap<>(); - entities.entrySet().forEach( - entry -> addValidationDataEntity(entitiesValidationData, entry.getKey(), - entry.getValue().entity)); - } - - public Collection getTrees() { - return roots; - } - - @Override - public void saveCompositionData(String vspId, Version version, CompositionData compositionData) { - if (Objects.isNull(compositionData)) { - return; - } - - Map networkIdByName = saveNetworks(vspId, version, compositionData); - saveComponents(vspId, version, compositionData, networkIdByName); - } - - @Override - public Set getAllErrorsByVsp(String vspId) { - CompositionEntityValidationData matchVsp = null; - Set entitiesWithErrors = new HashSet<>(); - for (CompositionEntityValidationData root : roots) { - if (root.getEntityId().equals(vspId)) { - matchVsp = root; - break; - } - } - - getEntityListWithErrors(matchVsp, entitiesWithErrors); - if (CollectionUtils.isNotEmpty(entitiesWithErrors)) { - updateValidationCompositionEntityName(entitiesWithErrors); - return entitiesWithErrors; - } - - return null; - } - - private boolean isThereErrorsInSubTree(CompositionEntityValidationData entity) { - if (Objects.isNull(entity)) { - return false; - } - - if (CollectionUtils.isNotEmpty(entity.getErrors())) { - return true; - } - - Collection subEntitiesValidationData = - entity.getSubEntitiesValidationData(); - return !CollectionUtils.isEmpty(subEntitiesValidationData) && - checkForErrorsInChildren(subEntitiesValidationData); - - } - - private boolean checkForErrorsInChildren( - Collection subEntitiesValidationData) { - boolean result = false; - for (CompositionEntityValidationData subEntity : subEntitiesValidationData) { - if (CollectionUtils.isNotEmpty(subEntity.getErrors())) { - return true; - } - - result = isThereErrorsInSubTree(subEntity) || result; - if (result) { - return true; - } - } - return false; - } - - public void saveComponents(String vspId, Version version, CompositionData compositionData, - Map networkIdByName) { - if (CollectionUtils.isNotEmpty(compositionData.getComponents())) { - for (Component component : compositionData.getComponents()) { - ComponentEntity componentEntity = new ComponentEntity(vspId, version, null); - componentEntity.setComponentCompositionData(component.getData()); - - String componentId = createComponent(componentEntity).getId(); - - saveImagesByComponent(vspId, version, component, componentId); - saveComputesFlavorByComponent(vspId, version, component, componentId); - - saveNicsByComponent(vspId, version, networkIdByName, component, componentId); - } - } - } - - public void saveNicsByComponent(String vspId, Version version, - Map networkIdByName, Component component, - String componentId) { - if (CollectionUtils.isNotEmpty(component.getNics())) { - for (Nic nic : component.getNics()) { - if (nic.getNetworkName() != null && MapUtils.isNotEmpty(networkIdByName)) { - nic.setNetworkId(networkIdByName.get(nic.getNetworkName())); - } - nic.setNetworkName(null); - //For heat flow set network type to be internal by default for NIC - nic.setNetworkType(NetworkType.Internal); - - NicEntity nicEntity = new NicEntity(vspId, version, componentId, null); - nicEntity.setNicCompositionData(nic); - createNic(nicEntity); - } - } - } - - public Map saveNetworks(String vspId, Version version, - CompositionData compositionData) { - Map networkIdByName = new HashMap<>(); - if (CollectionUtils.isNotEmpty(compositionData.getNetworks())) { - for (Network network : compositionData.getNetworks()) { - - NetworkEntity networkEntity = new NetworkEntity(vspId, version, null); - networkEntity.setNetworkCompositionData(network); - - if (network.getName() != null) { - networkIdByName.put(network.getName(), createNetwork(networkEntity).getId()); - } - } - } - return networkIdByName; - } - - @Override - public NetworkEntity createNetwork(NetworkEntity network) { - //network.setId(CommonMethods.nextUuId()); will be set by the dao - networkDao.create(network); - return network; - } - - @Override - public ComponentEntity createComponent(ComponentEntity component) { - //component.setId(CommonMethods.nextUuId()); will be set by the dao - component.setQuestionnaireData( - new JsonSchemaDataGenerator( - generateSchema(SchemaTemplateContext.questionnaire, CompositionEntityType.component, - null)) - .generateData()); - - componentDao.create(component); - return component; - } - - @Override - public NicEntity createNic(NicEntity nic) { - //nic.setId(CommonMethods.nextUuId()); will be set by the dao - nic.setQuestionnaireData( - new JsonSchemaDataGenerator( - generateSchema(SchemaTemplateContext.questionnaire, CompositionEntityType.nic, null)) - .generateData()); - - nicDao.create(nic); - return nic; - } - - - public void addErrorsToTrees(Map> errors) { - roots.forEach(root -> addErrorsToTree(root, null, errors)); - } - - /* * - * get a flat list of all questionnaire entities that have validation errors - * */ - public Set getEntityListWithErrors() { - Set treeAsList = new HashSet<>(); - - for (CompositionEntityValidationData entity : roots) { - if (CollectionUtils.isNotEmpty(entity.getErrors())) { - addNodeWithErrors(entity, treeAsList); - } - getEntityListWithErrors(entity, treeAsList); - } - - updateValidationCompositionEntityName(treeAsList); - return treeAsList; - } - - private void getEntityListWithErrors(CompositionEntityValidationData entity, - Set compositionSet) { - if(CollectionUtils.isNotEmpty(entity.getErrors())){ - addNodeWithErrors(entity, compositionSet); - } - - if (CollectionUtils.isEmpty(entity.getSubEntitiesValidationData())) { - return; - } - - for (CompositionEntityValidationData child : entity.getSubEntitiesValidationData()) { - getEntityListWithErrors(child, compositionSet); - } - } - - - private void addNodeWithErrors(CompositionEntityValidationData node, - Set entitiesWithErrors) { - CompositionEntityValidationData compositionNodeToAdd = new CompositionEntityValidationData(node - .getEntityType(), node.getEntityId()); - compositionNodeToAdd.setErrors(node.getErrors()); - compositionNodeToAdd.setSubEntitiesValidationData(null); - - entitiesWithErrors.add(compositionNodeToAdd); - } - - public void removeNodesWithoutErrors() { - roots.forEach(root -> removeNodesWithoutErrors(root, null)); - } - - - private CompositionEntityData getCompositionEntityDataById(CompositionEntityValidationData - entity) { - for (Map.Entry entityEntry : entities - .entrySet()) { - if (entityEntry.getKey().getId().equals(entity.getEntityId())) { - return entityEntry.getValue(); - } - } - return null; - } - - - private void updateValidationCompositionEntityName(Set - compositionSet) { - for (CompositionEntityValidationData entity : compositionSet) { - String compositionData = getCompositionDataAsString(entity); - if (entity.getEntityType().equals(CompositionEntityType.vsp) || - Objects.nonNull(compositionData)) { - entity.setEntityName(getEntityNameByEntityType(compositionData, entity)); - } - } - } - - private String getCompositionDataAsString(CompositionEntityValidationData entity) { - CompositionEntityData compositionEntityData = getCompositionEntityDataById(entity); - return compositionEntityData == null ? null : compositionEntityData.entity.getCompositionData(); - } - - - private String getEntityNameByEntityType(String compositionData, - CompositionEntityValidationData entity) { - switch (entity.getEntityType()) { - case component: - ComponentData component = JsonUtil.json2Object(compositionData, ComponentData.class); - return component.getDisplayName(); - - case nic: - Nic nic = JsonUtil.json2Object(compositionData, Nic.class); - return nic.getName(); - - case network: - Network network = JsonUtil.json2Object(compositionData, Network.class); - return network.getName(); - - case image: - Image image = JsonUtil.json2Object(compositionData, Image.class); - return image.getFileName(); - - case vsp: - CompositionEntityData vspEntity = getCompositionEntityDataById(entity); - VspQuestionnaireEntity vspQuestionnaireEntity = (VspQuestionnaireEntity) vspEntity.entity; - VspDetails vspDetails = - vspInfoDao.get(new VspDetails(vspQuestionnaireEntity.getId(), - vspQuestionnaireEntity.getVersion())); - return vspDetails.getName(); - } - - return null; - } - - private void removeNodesWithoutErrors(CompositionEntityValidationData node, - CompositionEntityValidationData parent) { - - if (Objects.isNull(node)) { - return; - } - - if (hasChildren(node)) { - Collection subNodes = - new ArrayList<>(node.getSubEntitiesValidationData()); - subNodes.forEach(subNode -> removeNodesWithoutErrors(subNode, node)); - node.setSubEntitiesValidationData(subNodes); - - if (canNodeGetRemovedFromValidationDataTree(node)) { - removeNodeFromChildren(parent, node); - } - } else if (canNodeGetRemovedFromValidationDataTree(node)) { - removeNodeFromChildren(parent, node); - } - } - - private void removeNodeFromChildren(CompositionEntityValidationData parent, - CompositionEntityValidationData childToRemove) { - if (!Objects.isNull(parent)) { - parent.getSubEntitiesValidationData().remove(childToRemove); - } - } - - private boolean hasChildren(CompositionEntityValidationData node) { - return !CollectionUtils.isEmpty(node.getSubEntitiesValidationData()); - } - - private boolean canNodeGetRemovedFromValidationDataTree(CompositionEntityValidationData node) { - return !hasChildren(node) && CollectionUtils.isEmpty(node.getErrors()); - } - - - private void addValidationDataEntity( - Map entitiesValidationData, - CompositionEntityId entityId, CompositionEntity entity) { - if (entitiesValidationData.containsKey(entityId)) { - return; - } - - CompositionEntityValidationData validationData = - new CompositionEntityValidationData(entity.getType(), entity.getId()); - entitiesValidationData.put(entityId, validationData); - - CompositionEntityId parentEntityId = entityId.getParentId(); - if (parentEntityId == null) { - roots.add(validationData); - } else { - CompositionEntityData parentEntity = entities.get(parentEntityId); - if (parentEntity == null) { - roots.add(validationData); - } else { - addValidationDataEntity(entitiesValidationData, parentEntityId, parentEntity.entity); - entitiesValidationData.get(parentEntityId).addSubEntityValidationData(validationData); - } - } - } - - private void addErrorsToTree(CompositionEntityValidationData node, - CompositionEntityId parentNodeId, - Map> errors) { - if (node == null) { - return; - } - CompositionEntityId nodeId = new CompositionEntityId(node.getEntityId(), parentNodeId); - node.setErrors(errors.get(nodeId)); - - if (node.getSubEntitiesValidationData() != null) { - node.getSubEntitiesValidationData() - .forEach(subNode -> addErrorsToTree(subNode, nodeId, errors)); - } - } - - private Collection validateQuestionnaire(CompositionEntityData compositionEntityData) { - logger.debug(String.format("validateQuestionnaire start: " + - "[entity.type]=%s, [entity.id]=%s, [entity.questionnaireString]=%s", - compositionEntityData.entity.getType().name(), - compositionEntityData.entity.getCompositionEntityId().toString(), - compositionEntityData.entity.getQuestionnaireData())); - - if (Objects.isNull(compositionEntityData.entity.getQuestionnaireData()) || - !JsonUtil.isValidJson(compositionEntityData.entity.getQuestionnaireData())) { - return Collections.singletonList(String - .format(MISSING_OR_INVALID_QUESTIONNAIRE_MSG, compositionEntityData.entity.getType())); - } - - return JsonUtil.validate( - compositionEntityData.entity.getQuestionnaireData() == null - ? JsonUtil.object2Json(new Object()) - : compositionEntityData.entity.getQuestionnaireData(), - getSchema(compositionEntityData.entity.getType(), SchemaTemplateContext.questionnaire, - compositionEntityData.schemaTemplateInput)); - } - - private String getSchema(CompositionEntityType compositionEntityType, - SchemaTemplateContext schemaTemplateContext, - SchemaTemplateInput schemaTemplateInput) { - return schemaTemplateInput == null - ? nonDynamicSchemas.computeIfAbsent(compositionEntityType, - k -> generateSchema(schemaTemplateContext, compositionEntityType, null)) - : generateSchema(schemaTemplateContext, compositionEntityType, schemaTemplateInput); - } - - private static class CompositionEntityData { - private CompositionEntity entity; - private SchemaTemplateInput schemaTemplateInput; - - CompositionEntityData(CompositionEntity entity, SchemaTemplateInput schemaTemplateInput) { - this.entity = entity; - this.schemaTemplateInput = schemaTemplateInput; - } - - } - - // todo - make SchemaGenerator non static and mock it in UT instead of mocking this method (and - // make the method private - - protected String generateSchema(SchemaTemplateContext schemaTemplateContext, - CompositionEntityType compositionEntityType, - SchemaTemplateInput schemaTemplateInput) { - return SchemaGenerator - .generate(schemaTemplateContext, compositionEntityType, schemaTemplateInput); - } - - @Override - public DeploymentFlavorEntity createDeploymentFlavor(DeploymentFlavorEntity deploymentFlavor) { - deploymentFlavor.setId(CommonMethods.nextUuId()); - deploymentFlavorDao.create(deploymentFlavor); - return deploymentFlavor; - } - - @Override - public ImageEntity createImage(ImageEntity image) { - image.setId(CommonMethods.nextUuId()); - - image.setQuestionnaireData( - new JsonSchemaDataGenerator(SchemaGenerator - .generate(SchemaTemplateContext.questionnaire, CompositionEntityType.image, null)) - .generateData()); - - imageDao.create(image); - return image; - } - - public void saveComputesFlavorByComponent(String vspId, Version version, Component component, - String componentId) { - if (CollectionUtils.isNotEmpty(component.getCompute())) { - for (ComputeData flavor : component.getCompute()) { - ComputeEntity computeEntity = new ComputeEntity(vspId, version, componentId, null); - computeEntity.setComputeCompositionData(flavor); - computeEntity.setQuestionnaireData( - new JsonSchemaDataGenerator(SchemaGenerator - .generate(SchemaTemplateContext.questionnaire, CompositionEntityType.compute, - null)).generateData()); - - computeDao.create(computeEntity); - } - } - } - - public void saveImagesByComponent(String vspId, Version version, Component component, String - componentId) { - if (CollectionUtils.isNotEmpty(component.getImages())) { - for (Image img : component.getImages()) { - ImageEntity imageEntity = new ImageEntity(vspId, version, componentId, null); - imageEntity.setImageCompositionData(img); - createImage(imageEntity); - } - } - } - -} -- cgit 1.2.3-korg