summaryrefslogtreecommitdiffstats
path: root/catalog-be
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2021-08-26 12:17:08 +0100
committerVasyl Razinkov <vasyl.razinkov@est.tech>2021-08-26 20:22:26 +0000
commit4701612ba26c4b8c7c7e9fbfa38f582a4b74669f (patch)
tree8516c4cffec989c90bf31601454625a47d270bdb /catalog-be
parent69cb5577bc59f8b25b0b267f5ea5e37c6aa20dbd (diff)
Add types to imports
Change-Id: Ifa1dea17841d8667044aff4e7a9a17b2a75b78e4 Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech> Issue-ID: SDC-3684
Diffstat (limited to 'catalog-be')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CapabilityTypeImportManager.java28
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java11
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DataTypeImportManager.java26
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java18
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceLifecycleTypeImportManager.java10
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogic.java6
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeImportManager.java19
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/RelationshipTypeImportManager.java27
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java144
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CapabilityTypeImportManagerTest.java50
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CommonImportManagerTest.java150
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManagerTest.java2
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceLifecycleTypeImportManagerTest.java48
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogicTest.java10
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/RelationshipTypeImportManagerTest.java2
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesUploadEndpointTest.java59
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesUploadServletTest.java7
17 files changed, 349 insertions, 268 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CapabilityTypeImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CapabilityTypeImportManager.java
index 04a8fc88db..c0188d79c3 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CapabilityTypeImportManager.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CapabilityTypeImportManager.java
@@ -25,6 +25,7 @@ import java.util.Map;
import java.util.Optional;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.openecomp.sdc.be.components.impl.CommonImportManager.ElementTypeEnum;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.model.CapabilityTypeDefinition;
import org.openecomp.sdc.be.model.Model;
@@ -48,20 +49,30 @@ public class CapabilityTypeImportManager {
private final ModelOperation modelOperation;
@Autowired
- public CapabilityTypeImportManager(CapabilityTypeOperation capabilityTypeOperation, CommonImportManager commonImportManager, ModelOperation modelOperation) {
+ public CapabilityTypeImportManager(CapabilityTypeOperation capabilityTypeOperation, CommonImportManager commonImportManager,
+ ModelOperation modelOperation) {
this.capabilityTypeOperation = capabilityTypeOperation;
this.commonImportManager = commonImportManager;
this.modelOperation = modelOperation;
}
- public Either<List<ImmutablePair<CapabilityTypeDefinition, Boolean>>, ResponseFormat> createCapabilityTypes(final String capabilityTypesYml, final String modelName) {
- return commonImportManager.createElementTypes(capabilityTypesYml, capabilityTypesFromYml -> createCapabilityTypesFromYml(capabilityTypesYml, modelName), this::upsertCapabilityTypesByDao,
- CommonImportManager.ElementTypeEnum.CAPABILITY_TYPE);
+ public Either<List<ImmutablePair<CapabilityTypeDefinition, Boolean>>, ResponseFormat> createCapabilityTypes(final String capabilityTypesYml,
+ final String modelName,
+ final boolean includeToModelDefaultImports) {
+ final Either<List<ImmutablePair<CapabilityTypeDefinition, Boolean>>, ResponseFormat> elementTypes = commonImportManager.createElementTypes(
+ capabilityTypesYml, capabilityTypesFromYml -> createCapabilityTypesFromYml(capabilityTypesYml, modelName),
+ this::upsertCapabilityTypesByDao, ElementTypeEnum.CAPABILITY_TYPE);
+ if (includeToModelDefaultImports && StringUtils.isNotEmpty(modelName)) {
+ commonImportManager.addTypesToDefaultImports(capabilityTypesYml, modelName);
+ }
+ return elementTypes;
}
- private Either<List<CapabilityTypeDefinition>, ActionStatus> createCapabilityTypesFromYml(final String capabilityTypesYml, final String modelName) {
- final Either<List<CapabilityTypeDefinition>, ActionStatus> capabilityTypes = commonImportManager.createElementTypesFromYml(capabilityTypesYml, this::createCapabilityType);
- if (capabilityTypes.isLeft() && StringUtils.isNotEmpty(modelName)){
+ private Either<List<CapabilityTypeDefinition>, ActionStatus> createCapabilityTypesFromYml(final String capabilityTypesYml,
+ final String modelName) {
+ final Either<List<CapabilityTypeDefinition>, ActionStatus> capabilityTypes = commonImportManager.createElementTypesFromYml(capabilityTypesYml,
+ this::createCapabilityType);
+ if (capabilityTypes.isLeft() && StringUtils.isNotEmpty(modelName)) {
final Optional<Model> modelOptional = modelOperation.findModelByName(modelName);
if (modelOptional.isPresent()) {
capabilityTypes.left().value().forEach(capabilityType -> capabilityType.setModel(modelName));
@@ -75,7 +86,8 @@ public class CapabilityTypeImportManager {
private Either<List<ImmutablePair<CapabilityTypeDefinition, Boolean>>, ResponseFormat> upsertCapabilityTypesByDao(
List<CapabilityTypeDefinition> capabilityTypesToCreate) {
return commonImportManager.createElementTypesByDao(capabilityTypesToCreate, capabilityType -> Either.left(ActionStatus.OK),
- capabilityType -> new ImmutablePair<>(CommonImportManager.ElementTypeEnum.CAPABILITY_TYPE, UniqueIdBuilder.buildCapabilityTypeUid(capabilityType.getModel(), capabilityType.getType())),
+ capabilityType -> new ImmutablePair<>(CommonImportManager.ElementTypeEnum.CAPABILITY_TYPE,
+ UniqueIdBuilder.buildCapabilityTypeUid(capabilityType.getModel(), capabilityType.getType())),
capabilityTypeOperation::getCapabilityType, capabilityTypeOperation::addCapabilityType, this::updateCapabilityType);
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java
index 9a77aad0b2..c0da9eb17b 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java
@@ -51,6 +51,7 @@ import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.normatives.ToscaTypeMetadata;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.api.TypeOperations;
+import org.openecomp.sdc.be.model.operations.impl.ModelOperation;
import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.exception.ResponseFormat;
@@ -64,11 +65,15 @@ public class CommonImportManager {
private static final Logger log = Logger.getLogger(CommonImportManager.class.getName());
private final ComponentsUtils componentsUtils;
private final PropertyOperation propertyOperation;
+ private final ModelOperation modelOperation;
@Autowired
- public CommonImportManager(ComponentsUtils componentsUtils, PropertyOperation propertyOperation) {
+ public CommonImportManager(final ComponentsUtils componentsUtils,
+ final PropertyOperation propertyOperation,
+ final ModelOperation modelOperation) {
this.componentsUtils = componentsUtils;
this.propertyOperation = propertyOperation;
+ this.modelOperation = modelOperation;
}
public static void setProperties(Map<String, Object> toscaJson, Consumer<List<PropertyDefinition>> consumer) {
@@ -529,6 +534,10 @@ public class CommonImportManager {
}
+ public void addTypesToDefaultImports(final String typesYaml, final String modelName) {
+ modelOperation.addTypesToDefaultImports(typesYaml, modelName);
+ }
+
public enum ElementTypeEnum {
POLICY_TYPE, GROUP_TYPE, DATA_TYPE, CAPABILITY_TYPE, INTERFACE_LIFECYCLE_TYPE, RELATIONSHIP_TYPE
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DataTypeImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DataTypeImportManager.java
index 95ef74e93c..b24d81bcbc 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DataTypeImportManager.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DataTypeImportManager.java
@@ -37,7 +37,6 @@ import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.Model;
import org.openecomp.sdc.be.model.PropertyDefinition;
-import org.openecomp.sdc.be.model.RelationshipTypeDefinition;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.ModelOperation;
import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
@@ -61,14 +60,21 @@ public class DataTypeImportManager {
@Resource
private ModelOperation modelOperation;
- public Either<List<ImmutablePair<DataTypeDefinition, Boolean>>, ResponseFormat> createDataTypes(final String dataTypeYml, final String modelName) {
- return commonImportManager
- .createElementTypes(dataTypeYml, dataTypesFromYml -> createDataTypesFromYml(dataTypeYml, modelName), this::createDataTypesByDao, ElementTypeEnum.DATA_TYPE);
+ public Either<List<ImmutablePair<DataTypeDefinition, Boolean>>, ResponseFormat> createDataTypes(final String dataTypeYml, final String modelName,
+ final boolean includeToModelDefaultImports) {
+ final var elementTypes = commonImportManager.createElementTypes(
+ dataTypeYml, dataTypesFromYml -> createDataTypesFromYml(dataTypeYml, modelName), this::createDataTypesByDao, ElementTypeEnum.DATA_TYPE);
+
+ if (includeToModelDefaultImports && StringUtils.isNotEmpty(modelName)) {
+ commonImportManager.addTypesToDefaultImports(dataTypeYml, modelName);
+ }
+ return elementTypes;
}
-
+
private Either<List<DataTypeDefinition>, ActionStatus> createDataTypesFromYml(final String dataTypesYml, final String modelName) {
- final Either<List<DataTypeDefinition>, ActionStatus> dataTypes = commonImportManager.createElementTypesFromYml(dataTypesYml, this::createDataType);
- if (dataTypes.isLeft() && StringUtils.isNotEmpty(modelName)){
+ final Either<List<DataTypeDefinition>, ActionStatus> dataTypes = commonImportManager.createElementTypesFromYml(dataTypesYml,
+ this::createDataType);
+ if (dataTypes.isLeft() && StringUtils.isNotEmpty(modelName)) {
final Optional<Model> modelOptional = modelOperation.findModelByName(modelName);
if (modelOptional.isPresent()) {
dataTypes.left().value().forEach(dataType -> dataType.setModel(modelName));
@@ -83,7 +89,8 @@ public class DataTypeImportManager {
List<DataTypeDefinition> dataTypesToCreate) {
return commonImportManager.createElementTypesByDao(dataTypesToCreate, this::validateDataType,
dataType -> new ImmutablePair<>(ElementTypeEnum.DATA_TYPE, UniqueIdBuilder.buildDataTypeUid(dataType.getModel(), dataType.getName())),
- dataTypeUid -> propertyOperation.getDataTypeByUidWithoutDerived(dataTypeUid, true), dataType -> propertyOperation.addDataType(dataType),
+ dataTypeUid -> propertyOperation.getDataTypeByUidWithoutDerived(dataTypeUid, true),
+ dataType -> propertyOperation.addDataType(dataType),
(newDataType, oldDataType) -> propertyOperation.updateDataType(newDataType, oldDataType));
}
@@ -136,7 +143,8 @@ public class DataTypeImportManager {
}
String derivedDataType = dataType.getDerivedFromName();
if (derivedDataType != null) {
- Either<DataTypeDefinition, StorageOperationStatus> derivedDataTypeByName = propertyOperation.getDataTypeByName(derivedDataType, dataType.getModel());
+ Either<DataTypeDefinition, StorageOperationStatus> derivedDataTypeByName = propertyOperation.getDataTypeByName(derivedDataType,
+ dataType.getModel());
if (derivedDataTypeByName.isRight()) {
StorageOperationStatus status = derivedDataTypeByName.right().value();
if (status == StorageOperationStatus.NOT_FOUND) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java
index e57c46bbe6..e043bc2619 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java
@@ -69,13 +69,20 @@ public class GroupTypeImportManager {
this.modelOperation = modelOperation;
}
- public Either<List<ImmutablePair<GroupTypeDefinition, Boolean>>, ResponseFormat> createGroupTypes(ToscaTypeImportData toscaTypeImportData, String modelName) {
- return commonImportManager.createElementTypes(toscaTypeImportData, this::createGroupTypesFromYml, this::upsertGroupTypesByDao, modelName);
+ public Either<List<ImmutablePair<GroupTypeDefinition, Boolean>>, ResponseFormat> createGroupTypes(ToscaTypeImportData toscaTypeImportData,
+ String modelName, final boolean includeToModelDefaultImports) {
+ final Either<List<ImmutablePair<GroupTypeDefinition, Boolean>>, ResponseFormat> elementTypes = commonImportManager.createElementTypes(
+ toscaTypeImportData, this::createGroupTypesFromYml, this::upsertGroupTypesByDao, modelName);
+ if (includeToModelDefaultImports && StringUtils.isNotEmpty(modelName)) {
+ commonImportManager.addTypesToDefaultImports(toscaTypeImportData.getToscaTypesYml(), modelName);
+ }
+ return elementTypes;
}
private Either<List<GroupTypeDefinition>, ActionStatus> createGroupTypesFromYml(String groupTypesYml, String modelName) {
- Either<List<GroupTypeDefinition>, ActionStatus> groupTypes = commonImportManager.createElementTypesFromYml(groupTypesYml, this::createGroupType);
- if (groupTypes.isLeft() && StringUtils.isNotEmpty(modelName)){
+ Either<List<GroupTypeDefinition>, ActionStatus> groupTypes = commonImportManager.createElementTypesFromYml(groupTypesYml,
+ this::createGroupType);
+ if (groupTypes.isLeft() && StringUtils.isNotEmpty(modelName)) {
final Optional<Model> modelOptional = modelOperation.findModelByName(modelName);
if (modelOptional.isPresent()) {
groupTypes.left().value().forEach(groupType -> groupType.setModel(modelName));
@@ -90,7 +97,8 @@ public class GroupTypeImportManager {
List<GroupTypeDefinition> groupTypesToCreate, String modelName) {
return commonImportManager.createElementTypesWithVersionByDao(groupTypesToCreate, this::validateGroupType,
groupType -> new ImmutablePair<>(ElementTypeEnum.GROUP_TYPE, UniqueIdBuilder.buildGroupTypeUid(groupType.getModel(),
- groupType.getType(), groupType.getVersion(), NodeTypeEnum.GroupType.getName()).toLowerCase()), groupTypeOperation::getLatestGroupTypeByType,
+ groupType.getType(), groupType.getVersion(), NodeTypeEnum.GroupType.getName()).toLowerCase()),
+ groupTypeOperation::getLatestGroupTypeByType,
groupTypeOperation::addGroupType, this::updateGroupType, modelName);
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceLifecycleTypeImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceLifecycleTypeImportManager.java
index ef00d9a92d..5cc8985b90 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceLifecycleTypeImportManager.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceLifecycleTypeImportManager.java
@@ -42,7 +42,6 @@ import org.openecomp.sdc.be.model.Operation;
import org.openecomp.sdc.be.model.operations.api.IInterfaceLifecycleOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.ModelOperation;
-import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
import org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.exception.ResponseFormat;
@@ -63,14 +62,19 @@ public class InterfaceLifecycleTypeImportManager {
@Resource
private ModelOperation modelOperation;
- public Either<List<InterfaceDefinition>, ResponseFormat> createLifecycleTypes(String interfaceLifecycleTypesYml, final String modelName) {
+ public Either<List<InterfaceDefinition>, ResponseFormat> createLifecycleTypes(String interfaceLifecycleTypesYml, final String modelName,
+ final boolean includeToModelDefaultImports) {
Either<List<InterfaceDefinition>, ActionStatus> interfaces = createInterfaceTypeFromYml(interfaceLifecycleTypesYml, modelName);
if (interfaces.isRight()) {
ActionStatus status = interfaces.right().value();
ResponseFormat responseFormat = componentsUtils.getResponseFormatByGroupType(status, null);
return Either.right(responseFormat);
}
- return createInterfacesByDao(interfaces.left().value());
+ final Either<List<InterfaceDefinition>, ResponseFormat> elementTypes = createInterfacesByDao(interfaces.left().value());
+ if (includeToModelDefaultImports && StringUtils.isNotEmpty(modelName)) {
+ commonImportManager.addTypesToDefaultImports(interfaceLifecycleTypesYml, modelName);
+ }
+ return elementTypes;
}
private Either<List<InterfaceDefinition>, ActionStatus> createInterfaceTypeFromYml(final String interfaceTypesYml, final String modelName) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogic.java
index 99349395b9..1d34f39b74 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogic.java
@@ -50,10 +50,10 @@ public class ModelBusinessLogic {
this.modelOperation = modelOperation;
this.dataTypeImportManager = dataTypeImportManager;
}
-
+
public Model createModel(final Model model, final String datatypesYaml) {
createModel(model);
- dataTypeImportManager.createDataTypes(datatypesYaml, model.getName());
+ dataTypeImportManager.createDataTypes(datatypesYaml, model.getName(), false);
return model;
}
@@ -119,4 +119,4 @@ public class ModelBusinessLogic {
throw ModelOperationExceptionSupplier.couldNotReadImports().get();
}
}
-} \ No newline at end of file
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeImportManager.java
index a3a2c013eb..54d57800be 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeImportManager.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeImportManager.java
@@ -69,13 +69,21 @@ public class PolicyTypeImportManager {
this.modelOperation = modelOperation;
}
- public Either<List<ImmutablePair<PolicyTypeDefinition, Boolean>>, ResponseFormat> createPolicyTypes(ToscaTypeImportData toscaTypeImportData, String modelName) {
- return commonImportManager.createElementTypes(toscaTypeImportData, this::createPolicyTypesFromYml, this::upsertPolicyTypesByDao, modelName);
+ public Either<List<ImmutablePair<PolicyTypeDefinition, Boolean>>, ResponseFormat> createPolicyTypes(final ToscaTypeImportData toscaTypeImportData,
+ final String modelName,
+ final boolean includeToModelDefaultImports) {
+ final Either<List<ImmutablePair<PolicyTypeDefinition, Boolean>>, ResponseFormat> elementTypes = commonImportManager.createElementTypes(
+ toscaTypeImportData, this::createPolicyTypesFromYml, this::upsertPolicyTypesByDao, modelName);
+ if (includeToModelDefaultImports && StringUtils.isNotEmpty(modelName)) {
+ commonImportManager.addTypesToDefaultImports(toscaTypeImportData.getToscaTypesYml(), modelName);
+ }
+ return elementTypes;
}
private Either<List<PolicyTypeDefinition>, ActionStatus> createPolicyTypesFromYml(String policyTypesYml, String modelName) {
- Either<List<PolicyTypeDefinition>, ActionStatus> policyTypes = commonImportManager.createElementTypesFromYml(policyTypesYml, this::createPolicyType);
- if (policyTypes.isLeft() && StringUtils.isNotEmpty(modelName)){
+ Either<List<PolicyTypeDefinition>, ActionStatus> policyTypes = commonImportManager.createElementTypesFromYml(policyTypesYml,
+ this::createPolicyType);
+ if (policyTypes.isLeft() && StringUtils.isNotEmpty(modelName)) {
final Optional<Model> modelOptional = modelOperation.findModelByName(modelName);
if (modelOptional.isPresent()) {
policyTypes.left().value().forEach(policyType -> policyType.setModel(modelName));
@@ -90,7 +98,8 @@ public class PolicyTypeImportManager {
List<PolicyTypeDefinition> policyTypesToCreate, String modelName) {
return commonImportManager.createElementTypesWithVersionByDao(policyTypesToCreate, this::validatePolicyType,
policyType -> new ImmutablePair<>(ElementTypeEnum.POLICY_TYPE, UniqueIdBuilder.buildPolicyTypeUid(policyType.getModel(),
- policyType.getType(), policyType.getVersion(), NodeTypeEnum.PolicyType.getName()).toLowerCase()), policyTypeOperation::getLatestPolicyTypeByType,
+ policyType.getType(), policyType.getVersion(), NodeTypeEnum.PolicyType.getName()).toLowerCase()),
+ policyTypeOperation::getLatestPolicyTypeByType,
policyTypeOperation::addPolicyType, this::updatePolicyType, modelName);
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/RelationshipTypeImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/RelationshipTypeImportManager.java
index 2165b9f7d1..564eb3a794 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/RelationshipTypeImportManager.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/RelationshipTypeImportManager.java
@@ -52,21 +52,31 @@ public class RelationshipTypeImportManager {
this.modelOperation = modelOperation;
}
- public Either<List<ImmutablePair<RelationshipTypeDefinition, Boolean>>, ResponseFormat> createRelationshipTypes(final String relationshipYml, final String modelName) {
- return createRelationshipTypes(relationshipYml, modelName, false);
+ public Either<List<ImmutablePair<RelationshipTypeDefinition, Boolean>>, ResponseFormat> createRelationshipTypes(final String relationshipYml,
+ final String modelName,
+ final boolean includeToModelDefaultImports) {
+ return createRelationshipTypes(relationshipYml, modelName, false, includeToModelDefaultImports);
}
private Either<List<ImmutablePair<RelationshipTypeDefinition, Boolean>>, ResponseFormat> createRelationshipTypes(final String relationshipTypeYml,
- final String modelName, final boolean inTransaction) {
- return commonImportManager
+ final String modelName,
+ final boolean inTransaction,
+ final boolean includeToModelDefaultImports) {
+ final Either<List<ImmutablePair<RelationshipTypeDefinition, Boolean>>, ResponseFormat> elementTypes = commonImportManager
.createElementTypes(relationshipTypeYml, relationshipTypesFromYml -> createRelationshipTypesFromYml(relationshipTypeYml, modelName),
relationshipTypesToCreate -> createRelationshipTypesByDao(relationshipTypesToCreate, inTransaction),
ElementTypeEnum.RELATIONSHIP_TYPE);
+ if (includeToModelDefaultImports && StringUtils.isNotEmpty(modelName)) {
+ commonImportManager.addTypesToDefaultImports(relationshipTypeYml, modelName);
+ }
+ return elementTypes;
}
- private Either<List<RelationshipTypeDefinition>, ActionStatus> createRelationshipTypesFromYml(final String relationshipTypeYml, final String modelName) {
- final Either<List<RelationshipTypeDefinition>, ActionStatus> relationshipTypes = commonImportManager.createElementTypesFromYml(relationshipTypeYml, this::createRelationshipType);
- if (relationshipTypes.isLeft() && StringUtils.isNotEmpty(modelName)){
+ private Either<List<RelationshipTypeDefinition>, ActionStatus> createRelationshipTypesFromYml(final String relationshipTypeYml,
+ final String modelName) {
+ final Either<List<RelationshipTypeDefinition>, ActionStatus> relationshipTypes = commonImportManager.createElementTypesFromYml(
+ relationshipTypeYml, this::createRelationshipType);
+ if (relationshipTypes.isLeft() && StringUtils.isNotEmpty(modelName)) {
final Optional<Model> modelOptional = modelOperation.findModelByName(modelName);
if (modelOptional.isPresent()) {
relationshipTypes.left().value().forEach(relationshipType -> relationshipType.setModel(modelName));
@@ -80,7 +90,8 @@ public class RelationshipTypeImportManager {
private Either<List<ImmutablePair<RelationshipTypeDefinition, Boolean>>, ResponseFormat> createRelationshipTypesByDao(
List<RelationshipTypeDefinition> relationshipTypesToCreate, boolean inTransaction) {
return commonImportManager.createElementTypesByDao(relationshipTypesToCreate, this::validateRelationshipType,
- relationshipType -> new ImmutablePair<>(ElementTypeEnum.RELATIONSHIP_TYPE, UniqueIdBuilder.buildRelationshipTypeUid(relationshipType.getModel(), relationshipType.getType())),
+ relationshipType -> new ImmutablePair<>(ElementTypeEnum.RELATIONSHIP_TYPE,
+ UniqueIdBuilder.buildRelationshipTypeUid(relationshipType.getModel(), relationshipType.getType())),
relationshipTypeUid -> relationshipTypeOperation.getRelationshipTypeByUid(relationshipTypeUid).right()
.map(DaoStatusConverter::convertJanusGraphStatusToStorageStatus),
relationshipType -> relationshipTypeOperation.addRelationshipType(relationshipType, inTransaction),
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java
index 79982eaa3a..b8917890d2 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java
@@ -29,9 +29,7 @@ import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.servers.Server;
-import io.swagger.v3.oas.annotations.servers.Servers;
import io.swagger.v3.oas.annotations.tags.Tag;
-import io.swagger.v3.oas.annotations.tags.Tags;
import java.io.File;
import java.io.IOException;
import java.util.List;
@@ -66,6 +64,7 @@ import org.openecomp.sdc.be.components.impl.model.ToscaTypeImportData;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.impl.ServletUtils;
import org.openecomp.sdc.be.model.DataTypeDefinition;
@@ -76,11 +75,10 @@ import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.normatives.ToscaTypeMetadata;
import org.openecomp.sdc.be.user.UserBusinessLogic;
import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.common.datastructure.FunctionalInterfaces.ConsumerThreeParam;
+import org.openecomp.sdc.common.datastructure.FunctionalInterfaces.ConsumerFourParam;
import org.openecomp.sdc.common.datastructure.FunctionalInterfaces.ConsumerTwoParam;
import org.openecomp.sdc.common.datastructure.Wrapper;
import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.common.util.ValidationUtils;
import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.stereotype.Controller;
@@ -88,12 +86,14 @@ import org.springframework.stereotype.Controller;
@Path("/v1/catalog/uploadType")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
-@Tags({@Tag(name = "SDCE-2 APIs")})
-@Servers({@Server(url = "/sdc2/rest")})
+@Tag(name = "SDCE-2 APIs")
+@Server(url = "/sdc2/rest")
@Controller
public class TypesUploadServlet extends AbstractValidationsServlet {
- public static final String CREATE = "Create ";
+ private static final String CREATE = "Create ";
+ private static final String START_HANDLE_REQUEST_OF = "Start handle request of {}";
+ private static final String CREATE_FAILED_WITH_EXCEPTION = "create {} failed with exception:";
private static final Logger log = Logger.getLogger(TypesUploadServlet.class);
private final CapabilityTypeImportManager capabilityTypeImportManager;
private final InterfaceLifecycleTypeImportManager interfaceLifecycleTypeImportManager;
@@ -132,11 +132,13 @@ public class TypesUploadServlet extends AbstractValidationsServlet {
@PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response uploadCapabilityType(@Parameter(description = "FileInputStream") @FormDataParam("capabilityTypeZip") File file,
@Context final HttpServletRequest request, @HeaderParam("USER_ID") String creator,
- @Parameter(description = "model") @FormDataParam("model") String modelName) {
- final String sanitizedModelName = ValidationUtils.sanitizeInputString(modelName);
- ConsumerThreeParam<Wrapper<Response>, String, String> createElementsMethod = (responseWrapper, ymlPayload, model) -> createElementsType(responseWrapper,
- () -> capabilityTypeImportManager.createCapabilityTypes(ymlPayload, sanitizedModelName));
- return uploadElementTypeServletLogic(createElementsMethod, file, request, creator, NodeTypeEnum.CapabilityType.name(), sanitizedModelName);
+ @Parameter(description = "model") @FormDataParam("model") String modelName,
+ @Parameter(description = "includeToModelImport") @FormDataParam("includeToModelImport") boolean includeToModelDefaultImports) {
+ ConsumerFourParam<Wrapper<Response>, String, String, Boolean> createElementsMethod = (responseWrapper, ymlPayload, model, includeToModelImport) ->
+ createElementsType(responseWrapper, () -> capabilityTypeImportManager.createCapabilityTypes(ymlPayload, modelName,
+ includeToModelDefaultImports));
+ return uploadElementTypeServletLogic(createElementsMethod, file, request, creator, NodeTypeEnum.CapabilityType.name(), modelName,
+ includeToModelDefaultImports);
}
@POST
@@ -150,9 +152,10 @@ public class TypesUploadServlet extends AbstractValidationsServlet {
@PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response uploadRelationshipType(@Parameter(description = "FileInputStream") @FormDataParam("relationshipTypeZip") File file,
@Context final HttpServletRequest request, @HeaderParam("USER_ID") String creator,
- @Parameter(description = "model") @FormDataParam("model") String modelName) {
- modelName = ValidationUtils.sanitizeInputString(modelName);
- return uploadElementTypeServletLogic(this::createRelationshipTypes, file, request, creator, NodeTypeEnum.RelationshipType.getName(), modelName);
+ @Parameter(description = "model") @FormDataParam("model") String modelName,
+ @Parameter(description = "includeToModelImport") @FormDataParam("includeToModelImport") boolean includeToModelDefaultImports) {
+ return uploadElementTypeServletLogic(
+ this::createRelationshipTypes, file, request, creator, NodeTypeEnum.RelationshipType.getName(), modelName, includeToModelDefaultImports);
}
@POST
@@ -166,10 +169,11 @@ public class TypesUploadServlet extends AbstractValidationsServlet {
@PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response uploadInterfaceLifecycleType(@Parameter(description = "FileInputStream") @FormDataParam("interfaceLifecycleTypeZip") File file,
@Context final HttpServletRequest request, @HeaderParam("USER_ID") String creator,
- @Parameter(description = "model") @FormDataParam("model") String modelName) {
- final String sanitizedModelName = ValidationUtils.sanitizeInputString(modelName);
- ConsumerTwoParam<Wrapper<Response>, String> createElementsMethod = (responseWrapper, ymlPayload) -> createElementsType(responseWrapper,
- () -> interfaceLifecycleTypeImportManager.createLifecycleTypes(ymlPayload, sanitizedModelName));
+ @Parameter(description = "model") @FormDataParam("model") String modelName,
+ @Parameter(description = "includeToModelImport") @FormDataParam("includeToModelImport") boolean includeToModelDefaultImports) {
+ ConsumerTwoParam<Wrapper<Response>, String> createElementsMethod = (responseWrapper, ymlPayload) ->
+ createElementsType(responseWrapper, () -> interfaceLifecycleTypeImportManager.createLifecycleTypes(ymlPayload, modelName,
+ includeToModelDefaultImports));
return uploadElementTypeServletLogic(createElementsMethod, file, request, creator, "Interface Types");
}
@@ -184,8 +188,8 @@ public class TypesUploadServlet extends AbstractValidationsServlet {
@PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response uploadCategories(@Parameter(description = "FileInputStream") @FormDataParam("categoriesZip") File file,
@Context final HttpServletRequest request, @HeaderParam("USER_ID") String creator) {
- ConsumerTwoParam<Wrapper<Response>, String> createElementsMethod = (responseWrapper, ymlPayload) -> createElementsType(responseWrapper,
- () -> categoriesImportManager.createCategories(ymlPayload));
+ ConsumerTwoParam<Wrapper<Response>, String> createElementsMethod = (responseWrapper, ymlPayload) ->
+ createElementsType(responseWrapper, () -> categoriesImportManager.createCategories(ymlPayload));
return uploadElementTypeServletLogic(createElementsMethod, file, request, creator, "categories");
}
@@ -200,9 +204,10 @@ public class TypesUploadServlet extends AbstractValidationsServlet {
@PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response uploadDataTypes(@Parameter(description = "FileInputStream") @FormDataParam("dataTypesZip") File file,
@Context final HttpServletRequest request, @HeaderParam("USER_ID") String creator,
- @Parameter(description = "model") @FormDataParam("model") String modelName) {
- modelName = ValidationUtils.sanitizeInputString(modelName);
- return uploadElementTypeServletLogic(this::createDataTypes, file, request, creator, NodeTypeEnum.DataType.getName(), modelName);
+ @Parameter(description = "model") @FormDataParam("model") String modelName,
+ @Parameter(description = "includeToModelImport") @FormDataParam("includeToModelImport") boolean includeToModelDefaultImports) {
+ return uploadElementTypeServletLogic(this::createDataTypes, file, request, creator, NodeTypeEnum.DataType.getName(), modelName,
+ includeToModelDefaultImports);
}
@POST
@@ -217,10 +222,11 @@ public class TypesUploadServlet extends AbstractValidationsServlet {
public Response uploadGroupTypes(@Parameter(description = "toscaTypeMetadata") @FormDataParam("toscaTypeMetadata") String toscaTypesMetaData,
@Parameter(description = "model") @FormDataParam("model") String modelName,
@Parameter(description = "FileInputStream") @FormDataParam("groupTypesZip") File file,
- @Context final HttpServletRequest request, @HeaderParam("USER_ID") String creator) {
- modelName = ValidationUtils.sanitizeInputString(modelName);
+ @Context final HttpServletRequest request, @HeaderParam("USER_ID") String creator,
+ @Parameter(description = "includeToModelImport") @FormDataParam("includeToModelImport") boolean includeToModelDefaultImports) {
Map<String, ToscaTypeMetadata> typesMetadata = getTypesMetadata(toscaTypesMetaData);
- return uploadTypesWithMetaData(this::createGroupTypes, typesMetadata, file, request, creator, NodeTypeEnum.GroupType.getName(), modelName);
+ return uploadTypesWithMetaData(this::createGroupTypes, typesMetadata, file, request, creator, NodeTypeEnum.GroupType.getName(), modelName,
+ includeToModelDefaultImports);
}
@POST
@@ -235,10 +241,11 @@ public class TypesUploadServlet extends AbstractValidationsServlet {
public Response uploadPolicyTypes(@Parameter(description = "toscaTypeMetadata") @FormDataParam("toscaTypeMetadata") String toscaTypesMetaData,
@Parameter(description = "model") @FormDataParam("model") String modelName,
@Parameter(description = "FileInputStream") @FormDataParam("policyTypesZip") File file,
- @Context final HttpServletRequest request, @HeaderParam("USER_ID") String creator) {
- modelName = ValidationUtils.sanitizeInputString(modelName);
+ @Context final HttpServletRequest request, @HeaderParam("USER_ID") String creator,
+ @Parameter(description = "includeToModelImport") @FormDataParam("includeToModelImport") boolean includeToModelDefaultImports) {
Map<String, ToscaTypeMetadata> typesMetadata = getTypesMetadata(toscaTypesMetaData);
- return uploadTypesWithMetaData(this::createPolicyTypes, typesMetadata, file, request, creator, NodeTypeEnum.PolicyType.getName(), modelName);
+ return uploadTypesWithMetaData(this::createPolicyTypes, typesMetadata, file, request, creator, NodeTypeEnum.PolicyType.getName(), modelName,
+ includeToModelDefaultImports);
}
private Map<String, ToscaTypeMetadata> getTypesMetadata(String toscaTypesMetaData) {
@@ -247,13 +254,13 @@ public class TypesUploadServlet extends AbstractValidationsServlet {
}
private Response uploadElementTypeServletLogic(ConsumerTwoParam<Wrapper<Response>, String> createElementsMethod, File file,
- final HttpServletRequest request, String creator, String elementTypeName) {
+ final HttpServletRequest request, String creator, String elementTypeName) {
init();
String userId = initHeaderParam(creator, request, Constants.USER_ID_HEADER);
try {
Wrapper<String> yamlStringWrapper = new Wrapper<>();
String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
+ log.debug(START_HANDLE_REQUEST_OF, url);
Wrapper<Response> responseWrapper = doUploadTypeValidations(request, userId, file);
if (responseWrapper.isEmpty()) {
fillZipContents(yamlStringWrapper, file);
@@ -263,30 +270,31 @@ public class TypesUploadServlet extends AbstractValidationsServlet {
}
return responseWrapper.getInnerElement();
} catch (Exception e) {
- log.debug("create {} failed with exception:", elementTypeName, e);
+ log.debug(CREATE_FAILED_WITH_EXCEPTION, elementTypeName, e);
BeEcompErrorManager.getInstance().logBeRestApiGeneralError(CREATE + elementTypeName);
return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
}
}
-
- private Response uploadElementTypeServletLogic(final ConsumerThreeParam<Wrapper<Response>, String, String> createElementsMethod,
- final File file, final HttpServletRequest request, final String creator, final String elementTypeName, final String modelName) {
+
+ private Response uploadElementTypeServletLogic(final ConsumerFourParam<Wrapper<Response>, String, String, Boolean> createElementsMethod,
+ final File file, final HttpServletRequest request, final String creator,
+ final String elementTypeName, final String modelName, final boolean includeToModelDefaultImports) {
init();
final String userId = initHeaderParam(creator, request, Constants.USER_ID_HEADER);
try {
final Wrapper<String> yamlStringWrapper = new Wrapper<>();
final String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
+ log.debug(START_HANDLE_REQUEST_OF, url);
final Wrapper<Response> responseWrapper = doUploadTypeValidations(request, userId, file);
if (responseWrapper.isEmpty()) {
fillZipContents(yamlStringWrapper, file);
}
if (responseWrapper.isEmpty()) {
- createElementsMethod.accept(responseWrapper, yamlStringWrapper.getInnerElement(), modelName);
+ createElementsMethod.accept(responseWrapper, yamlStringWrapper.getInnerElement(), modelName, includeToModelDefaultImports);
}
return responseWrapper.getInnerElement();
} catch (final Exception e) {
- log.debug("create {} failed with exception:", elementTypeName, e);
+ log.debug(CREATE_FAILED_WITH_EXCEPTION, elementTypeName, e);
BeEcompErrorManager.getInstance().logBeRestApiGeneralError(CREATE + elementTypeName);
return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
}
@@ -296,7 +304,7 @@ public class TypesUploadServlet extends AbstractValidationsServlet {
Wrapper<Response> responseWrapper = new Wrapper<>();
Wrapper<User> userWrapper = new Wrapper<>();
String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
+ log.debug(START_HANDLE_REQUEST_OF, url);
validateUserExist(responseWrapper, userWrapper, userId);
if (responseWrapper.isEmpty()) {
validateUserRole(responseWrapper, userWrapper.getInnerElement());
@@ -307,9 +315,9 @@ public class TypesUploadServlet extends AbstractValidationsServlet {
return responseWrapper;
}
- private Response uploadTypesWithMetaData(ConsumerThreeParam<Wrapper<Response>, ToscaTypeImportData, String> createElementsMethod,
+ private Response uploadTypesWithMetaData(ConsumerFourParam<Wrapper<Response>, ToscaTypeImportData, String, Boolean> createElementsMethod,
Map<String, ToscaTypeMetadata> typesMetaData, File file, final HttpServletRequest request,
- String creator, String elementTypeName, String modelName) {
+ String creator, String elementTypeName, String modelName, final boolean includeToModelDefaultImports) {
init();
String userId = initHeaderParam(creator, request, Constants.USER_ID_HEADER);
Wrapper<String> yamlStringWrapper = new Wrapper<>();
@@ -320,11 +328,11 @@ public class TypesUploadServlet extends AbstractValidationsServlet {
}
if (responseWrapper.isEmpty()) {
ToscaTypeImportData toscaTypeImportData = new ToscaTypeImportData(yamlStringWrapper.getInnerElement(), typesMetaData);
- createElementsMethod.accept(responseWrapper, toscaTypeImportData, modelName);
+ createElementsMethod.accept(responseWrapper, toscaTypeImportData, modelName, includeToModelDefaultImports);
}
return responseWrapper.getInnerElement();
} catch (Exception e) {
- log.debug("create {} failed with exception:", elementTypeName, e);
+ log.debug(CREATE_FAILED_WITH_EXCEPTION, elementTypeName, e);
BeEcompErrorManager.getInstance().logBeRestApiGeneralError(CREATE + elementTypeName);
return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
}
@@ -349,55 +357,54 @@ public class TypesUploadServlet extends AbstractValidationsServlet {
}
// data types
- private void createDataTypes(Wrapper<Response> responseWrapper, String dataTypesYml, final String modelName) {
- final Supplier<Either<List<ImmutablePair<DataTypeDefinition, Boolean>>, ResponseFormat>> generateElementTypeFromYml = () -> dataTypeImportManager
- .createDataTypes(dataTypesYml, modelName);
+ private void createDataTypes(Wrapper<Response> responseWrapper, String dataTypesYml, final String modelName, final boolean includeToModelDefaultImports) {
+ final Supplier<Either<List<ImmutablePair<DataTypeDefinition, Boolean>>, ResponseFormat>> generateElementTypeFromYml = () ->
+ dataTypeImportManager.createDataTypes(dataTypesYml, modelName, includeToModelDefaultImports);
buildStatusForElementTypeCreate(responseWrapper, generateElementTypeFromYml, ActionStatus.DATA_TYPE_ALREADY_EXIST,
NodeTypeEnum.DataType.name());
}
// group types
- private void createGroupTypes(Wrapper<Response> responseWrapper, ToscaTypeImportData toscaTypeImportData, String modelName) {
- final Supplier<Either<List<ImmutablePair<GroupTypeDefinition, Boolean>>, ResponseFormat>> generateElementTypeFromYml = () -> groupTypeImportManager
- .createGroupTypes(toscaTypeImportData, modelName);
+ private void createGroupTypes(Wrapper<Response> responseWrapper, ToscaTypeImportData toscaTypeImportData, String modelName,
+ final boolean includeToModelDefaultImports) {
+ final Supplier<Either<List<ImmutablePair<GroupTypeDefinition, Boolean>>, ResponseFormat>> generateElementTypeFromYml = () ->
+ groupTypeImportManager.createGroupTypes(toscaTypeImportData, modelName, includeToModelDefaultImports);
buildStatusForElementTypeCreate(responseWrapper, generateElementTypeFromYml, ActionStatus.GROUP_TYPE_ALREADY_EXIST,
NodeTypeEnum.GroupType.name());
}
// policy types
- private void createPolicyTypes(Wrapper<Response> responseWrapper, ToscaTypeImportData toscaTypeImportData, String modelName) {
- final Supplier<Either<List<ImmutablePair<PolicyTypeDefinition, Boolean>>, ResponseFormat>> generateElementTypeFromYml = () -> policyTypeImportManager
- .createPolicyTypes(toscaTypeImportData, modelName);
+ private void createPolicyTypes(Wrapper<Response> responseWrapper, ToscaTypeImportData toscaTypeImportData, String modelName,
+ final boolean includeToModelDefaultImports) {
+ final Supplier<Either<List<ImmutablePair<PolicyTypeDefinition, Boolean>>, ResponseFormat>> generateElementTypeFromYml = () ->
+ policyTypeImportManager.createPolicyTypes(toscaTypeImportData, modelName, includeToModelDefaultImports);
buildStatusForElementTypeCreate(responseWrapper, generateElementTypeFromYml, ActionStatus.POLICY_TYPE_ALREADY_EXIST,
NodeTypeEnum.PolicyType.name());
}
// data types
- private <ElementTypeDefinition> void buildStatusForElementTypeCreate(Wrapper<Response> responseWrapper,
- Supplier<Either<List<ImmutablePair<ElementTypeDefinition, Boolean>>, ResponseFormat>> generateElementTypeFromYml,
- ActionStatus alreadyExistStatus, String elementTypeName) {
- Either<List<ImmutablePair<ElementTypeDefinition, Boolean>>, ResponseFormat> eitherResult = generateElementTypeFromYml.get();
+ private <T extends ToscaDataDefinition> void buildStatusForElementTypeCreate(Wrapper<Response> responseWrapper,
+ Supplier<Either<List<ImmutablePair<T, Boolean>>, ResponseFormat>> generateElementTypeFromYml,
+ ActionStatus alreadyExistStatus, String elementTypeName) {
+ Either<List<ImmutablePair<T, Boolean>>, ResponseFormat> eitherResult = generateElementTypeFromYml.get();
if (eitherResult.isRight()) {
Response response = buildErrorResponse(eitherResult.right().value());
responseWrapper.setInnerElement(response);
} else {
Object representation;
try {
- List<ImmutablePair<ElementTypeDefinition, Boolean>> list = eitherResult.left().value();
+ List<ImmutablePair<T, Boolean>> list = eitherResult.left().value();
ActionStatus status = ActionStatus.OK;
if (list != null) {
// Group result by the right value - true or false.
-
- // I.e., get the number of data types which are new and
-
- // which are old.
- Map<Boolean, List<ImmutablePair<ElementTypeDefinition, Boolean>>> collect = list.stream()
- .collect(Collectors.groupingBy(ImmutablePair<ElementTypeDefinition, Boolean>::getRight));
+ // I.e., get the number of data types which are new and which are old.
+ Map<Boolean, List<ImmutablePair<T, Boolean>>> collect = list.stream()
+ .collect(Collectors.groupingBy(ImmutablePair<T, Boolean>::getRight));
if (collect != null) {
Set<Boolean> keySet = collect.keySet();
if (keySet.size() == 1) {
Boolean isNew = keySet.iterator().next();
- if (isNew) {
+ if (Boolean.TRUE.equals(isNew)) {
// all data types created at the first time
status = ActionStatus.CREATED;
} else {
@@ -420,9 +427,12 @@ public class TypesUploadServlet extends AbstractValidationsServlet {
}
// relationship types
- private void createRelationshipTypes(final Wrapper<Response> responseWrapper, final String relationshipTypesYml, final String modelName) {
+ private void createRelationshipTypes(final Wrapper<Response> responseWrapper,
+ final String relationshipTypesYml,
+ final String modelName,
+ final boolean includeToModelDefaultImports) {
final Supplier<Either<List<ImmutablePair<RelationshipTypeDefinition, Boolean>>, ResponseFormat>> generateElementTypeFromYml = () -> relationshipTypeImportManager
- .createRelationshipTypes(relationshipTypesYml, modelName);
+ .createRelationshipTypes(relationshipTypesYml, modelName, includeToModelDefaultImports);
buildStatusForElementTypeCreate(responseWrapper, generateElementTypeFromYml, ActionStatus.RELATIONSHIP_TYPE_ALREADY_EXIST,
NodeTypeEnum.RelationshipType.name());
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CapabilityTypeImportManagerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CapabilityTypeImportManagerTest.java
index f8b1800951..a4d02e146c 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CapabilityTypeImportManagerTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CapabilityTypeImportManagerTest.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,7 +20,19 @@
package org.openecomp.sdc.be.components.impl;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
import fj.data.Either;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import java.util.Optional;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.junit.Before;
@@ -41,37 +53,26 @@ import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
import org.openecomp.sdc.common.util.CapabilityTypeNameEnum;
import org.openecomp.sdc.exception.ResponseFormat;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
public class CapabilityTypeImportManagerTest {
+
private static final CapabilityTypeOperation capabilityTypeOperation = mock(CapabilityTypeOperation.class);
private static final ComponentsUtils componentsUtils = mock(ComponentsUtils.class);
private static final JanusGraphGenericDao JANUS_GRAPH_GENERIC_DAO = mock(JanusGraphGenericDao.class);
private static final PropertyOperation propertyOperation = mock(PropertyOperation.class);
- private CommonImportManager commonImportManager = new CommonImportManager(componentsUtils, propertyOperation);
- private ModelOperation modelOperation = mock(ModelOperation.class);
+ private static final ModelOperation modelOperation = mock(ModelOperation.class);
+ private CommonImportManager commonImportManager = new CommonImportManager(componentsUtils, propertyOperation, modelOperation);
private CapabilityTypeImportManager manager = new CapabilityTypeImportManager(capabilityTypeOperation, commonImportManager, modelOperation);
@BeforeClass
public static void beforeClass() {
- when(capabilityTypeOperation.addCapabilityType(Mockito.any(CapabilityTypeDefinition.class))).thenAnswer(new Answer<Either<CapabilityTypeDefinition, StorageOperationStatus>>() {
- public Either<CapabilityTypeDefinition, StorageOperationStatus> answer(InvocationOnMock invocation) {
- Object[] args = invocation.getArguments();
- return Either.left((CapabilityTypeDefinition) args[0]);
- }
+ when(capabilityTypeOperation.addCapabilityType(Mockito.any(CapabilityTypeDefinition.class))).thenAnswer(
+ new Answer<Either<CapabilityTypeDefinition, StorageOperationStatus>>() {
+ public Either<CapabilityTypeDefinition, StorageOperationStatus> answer(InvocationOnMock invocation) {
+ Object[] args = invocation.getArguments();
+ return Either.left((CapabilityTypeDefinition) args[0]);
+ }
- });
+ });
when(propertyOperation.getJanusGraphGenericDao()).thenReturn(JANUS_GRAPH_GENERIC_DAO);
when(capabilityTypeOperation.getCapabilityType(Mockito.anyString())).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
@@ -86,7 +87,8 @@ public class CapabilityTypeImportManagerTest {
public void testCreateCapabilityTypes() throws IOException {
String ymlContent = getCapabilityTypesYml();
when(modelOperation.findModelByName("testModel")).thenReturn(Optional.of(new Model("testModel")));
- Either<List<ImmutablePair<CapabilityTypeDefinition, Boolean>>, ResponseFormat> createCapabilityTypes = manager.createCapabilityTypes(ymlContent, "testModel");
+ Either<List<ImmutablePair<CapabilityTypeDefinition, Boolean>>, ResponseFormat> createCapabilityTypes = manager.createCapabilityTypes(
+ ymlContent, "testModel", false);
assertTrue(createCapabilityTypes.isLeft());
List<ImmutablePair<CapabilityTypeDefinition, Boolean>> capabilityTypesList = createCapabilityTypes.left().value();
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CommonImportManagerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CommonImportManagerTest.java
index 0527f372d4..b360a94862 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CommonImportManagerTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CommonImportManagerTest.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,7 +20,17 @@
package org.openecomp.sdc.be.components.impl;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
import fj.data.Either;
+import java.util.Arrays;
+import java.util.List;
+import java.util.function.BiFunction;
+import java.util.function.Function;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.junit.Before;
import org.junit.Test;
@@ -34,31 +44,24 @@ import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.CapabilityTypeDefinition;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.ModelOperation;
import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
import org.openecomp.sdc.exception.ResponseFormat;
import org.openecomp.sdc.exception.ServiceException;
-import java.util.Arrays;
-import java.util.List;
-import java.util.function.BiFunction;
-import java.util.function.Function;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
@RunWith(MockitoJUnitRunner.class)
public class CommonImportManagerTest {
+
private CommonImportManager commonImportManager;
@Mock
private ComponentsUtils componentsUtils;
@Mock
- PropertyOperation propertyOperation;
+ private PropertyOperation propertyOperation;
+ @Mock
+ private ModelOperation modelOperation;
@Mock
private JanusGraphGenericDao janusGraphGenericDao;
-
+
@Mock
private Function<Object, Either<ActionStatus, ResponseFormat>> validator;
@Mock
@@ -69,59 +72,60 @@ public class CommonImportManagerTest {
private Function<Object, Either<Object, StorageOperationStatus>> elementAdder;
@Mock
private BiFunction<Object, Object, Either<Object, StorageOperationStatus>> elementUpgrader;
-
+
@Before
public void startUp() {
- commonImportManager = new CommonImportManager(componentsUtils, propertyOperation);
-
+ commonImportManager = new CommonImportManager(componentsUtils, propertyOperation, modelOperation);
+
when(propertyOperation.getJanusGraphGenericDao()).thenReturn(janusGraphGenericDao);
}
-
+
@Test
public void testCreateElementTypesByDao_validationFailed() {
Object type1 = new Object();
List<Object> elementTypesToCreate = Arrays.asList(type1);
-
- ImmutablePair<ElementTypeEnum, String> elementInfo = new ImmutablePair<>(ElementTypeEnum.CAPABILITY_TYPE, "TestCapability");
+
+ ImmutablePair<ElementTypeEnum, String> elementInfo = new ImmutablePair<>(ElementTypeEnum.CAPABILITY_TYPE, "TestCapability");
when(elementInfoGetter.apply(type1)).thenReturn(elementInfo);
-
+
ResponseFormat responseFormat = new ResponseFormat();
responseFormat.setServiceException(new ServiceException());
when(validator.apply(type1)).thenReturn(Either.right(responseFormat));
+ Either<List<ImmutablePair<Object, Boolean>>, ResponseFormat> result = commonImportManager.createElementTypesByDao(elementTypesToCreate,
+ validator, elementInfoGetter, elementFetcher, elementAdder, elementUpgrader);
- Either<List<ImmutablePair<Object, Boolean>>, ResponseFormat> result = commonImportManager.createElementTypesByDao(elementTypesToCreate , validator , elementInfoGetter, elementFetcher, elementAdder, elementUpgrader);
-
verify(elementAdder, never()).apply(Mockito.any());
verify(elementUpgrader, never()).apply(Mockito.any(), Mockito.any());
verify(janusGraphGenericDao).rollback();
assertThat(result.isRight()).isTrue();
}
-
+
@Test(expected = RuntimeException.class)
public void testCreateElementTypesByDao_RuntTimeExceptionInValidation() {
Object type1 = new Object();
List<Object> elementTypesToCreate = Arrays.asList(type1);
-
- ImmutablePair<ElementTypeEnum, String> elementInfo = new ImmutablePair<>(ElementTypeEnum.CAPABILITY_TYPE, "TestCapability");
+
+ ImmutablePair<ElementTypeEnum, String> elementInfo = new ImmutablePair<>(ElementTypeEnum.CAPABILITY_TYPE, "TestCapability");
when(elementInfoGetter.apply(type1)).thenReturn(elementInfo);
when(validator.apply(type1)).thenThrow(new RuntimeException("Test Exception"));
-
- commonImportManager.createElementTypesByDao(elementTypesToCreate , validator , elementInfoGetter, elementFetcher, elementAdder, elementUpgrader);
-
+
+ commonImportManager.createElementTypesByDao(elementTypesToCreate, validator, elementInfoGetter, elementFetcher, elementAdder,
+ elementUpgrader);
+
verify(elementAdder, never()).apply(Mockito.any());
verify(elementUpgrader, never()).apply(Mockito.any(), Mockito.any());
verify(janusGraphGenericDao).rollback();
}
-
+
@Test
public void testCreateElementTypesByDao_capabilityTypeFetcherFailed() {
CapabilityTypeDefinition type1 = new CapabilityTypeDefinition();
List<Object> elementTypesToCreate = Arrays.asList(type1);
-
- ImmutablePair<ElementTypeEnum, String> elementInfo = new ImmutablePair<>(ElementTypeEnum.CAPABILITY_TYPE, "TestCapability");
+
+ ImmutablePair<ElementTypeEnum, String> elementInfo = new ImmutablePair<>(ElementTypeEnum.CAPABILITY_TYPE, "TestCapability");
when(elementInfoGetter.apply(type1)).thenReturn(elementInfo);
-
+
when(validator.apply(type1)).thenReturn(Either.left(ActionStatus.OK));
when(elementFetcher.apply("TestCapability")).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
ResponseFormat responseFormat = new ResponseFormat();
@@ -129,34 +133,34 @@ public class CommonImportManagerTest {
when(componentsUtils.convertFromStorageResponseForCapabilityType(Mockito.any())).thenCallRealMethod();
when(componentsUtils.getResponseFormatByCapabilityType(ActionStatus.INVALID_CONTENT, type1)).thenReturn(responseFormat);
+ Either<List<ImmutablePair<Object, Boolean>>, ResponseFormat> result = commonImportManager.createElementTypesByDao(elementTypesToCreate,
+ validator, elementInfoGetter, elementFetcher, elementAdder, elementUpgrader);
- Either<List<ImmutablePair<Object, Boolean>>, ResponseFormat> result = commonImportManager.createElementTypesByDao(elementTypesToCreate , validator , elementInfoGetter, elementFetcher, elementAdder, elementUpgrader);
-
verify(elementAdder, never()).apply(Mockito.any());
verify(elementUpgrader, never()).apply(Mockito.any(), Mockito.any());
verify(janusGraphGenericDao).rollback();
assertThat(result.isRight()).isTrue();
}
-
+
@Test
public void testCreateElementTypesByDao_capabilityTypeNotFound_AddFailed() {
CapabilityTypeDefinition type1 = new CapabilityTypeDefinition();
List<Object> elementTypesToCreate = Arrays.asList(type1);
-
- ImmutablePair<ElementTypeEnum, String> elementInfo = new ImmutablePair<>(ElementTypeEnum.CAPABILITY_TYPE, "TestCapability");
+
+ ImmutablePair<ElementTypeEnum, String> elementInfo = new ImmutablePair<>(ElementTypeEnum.CAPABILITY_TYPE, "TestCapability");
when(elementInfoGetter.apply(type1)).thenReturn(elementInfo);
-
+
when(validator.apply(type1)).thenReturn(Either.left(ActionStatus.OK));
when(elementFetcher.apply("TestCapability")).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
when(elementAdder.apply(type1)).thenReturn(Either.right(StorageOperationStatus.SCHEMA_VIOLATION));
-
+
ResponseFormat responseFormat = new ResponseFormat();
responseFormat.setServiceException(new ServiceException());
when(componentsUtils.convertFromStorageResponseForCapabilityType(Mockito.any())).thenCallRealMethod();
when(componentsUtils.getResponseFormatByCapabilityType(ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST, type1)).thenReturn(responseFormat);
-
- Either<List<ImmutablePair<Object, Boolean>>, ResponseFormat> result = commonImportManager.createElementTypesByDao(elementTypesToCreate , validator , elementInfoGetter, elementFetcher, elementAdder, elementUpgrader);
+ Either<List<ImmutablePair<Object, Boolean>>, ResponseFormat> result = commonImportManager.createElementTypesByDao(elementTypesToCreate,
+ validator, elementInfoGetter, elementFetcher, elementAdder, elementUpgrader);
verify(elementAdder).apply(type1);
verify(elementUpgrader, never()).apply(Mockito.any(), Mockito.any());
@@ -164,99 +168,101 @@ public class CommonImportManagerTest {
assertThat(result.isRight()).isTrue();
}
-
+
@Test
public void testCreateElementTypesByDao_capabilityTypeNotFound_AddSucceeded() {
CapabilityTypeDefinition type1 = new CapabilityTypeDefinition();
List<Object> elementTypesToCreate = Arrays.asList(type1);
-
- ImmutablePair<ElementTypeEnum, String> elementInfo = new ImmutablePair<>(ElementTypeEnum.CAPABILITY_TYPE, "TestCapability");
+
+ ImmutablePair<ElementTypeEnum, String> elementInfo = new ImmutablePair<>(ElementTypeEnum.CAPABILITY_TYPE, "TestCapability");
when(elementInfoGetter.apply(type1)).thenReturn(elementInfo);
-
+
when(validator.apply(type1)).thenReturn(Either.left(ActionStatus.OK));
when(elementFetcher.apply("TestCapability")).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
when(elementAdder.apply(type1)).thenReturn(Either.left(type1));
-
-
- Either<List<ImmutablePair<Object, Boolean>>, ResponseFormat> result = commonImportManager.createElementTypesByDao(elementTypesToCreate , validator , elementInfoGetter, elementFetcher, elementAdder, elementUpgrader);
+
+ Either<List<ImmutablePair<Object, Boolean>>, ResponseFormat> result = commonImportManager.createElementTypesByDao(elementTypesToCreate,
+ validator, elementInfoGetter, elementFetcher, elementAdder, elementUpgrader);
verify(elementAdder).apply(type1);
verify(elementUpgrader, never()).apply(Mockito.any(), Mockito.any());
verify(janusGraphGenericDao).commit();
-
+
assertEquals(type1, result.left().value().get(0).getLeft());
assertEquals(true, result.left().value().get(0).getRight());
}
-
+
@Test
public void testCreateElementTypesByDao_capabilityTypeFound_UpgradeFailed() {
CapabilityTypeDefinition type1 = new CapabilityTypeDefinition();
CapabilityTypeDefinition type1_1 = new CapabilityTypeDefinition();
List<Object> elementTypesToCreate = Arrays.asList(type1_1);
-
- ImmutablePair<ElementTypeEnum, String> elementInfo = new ImmutablePair<>(ElementTypeEnum.CAPABILITY_TYPE, "TestCapability");
+
+ ImmutablePair<ElementTypeEnum, String> elementInfo = new ImmutablePair<>(ElementTypeEnum.CAPABILITY_TYPE, "TestCapability");
when(elementInfoGetter.apply(type1_1)).thenReturn(elementInfo);
-
+
when(validator.apply(type1_1)).thenReturn(Either.left(ActionStatus.OK));
when(elementFetcher.apply("TestCapability")).thenReturn(Either.left(type1));
when(elementUpgrader.apply(type1_1, type1)).thenReturn(Either.right(StorageOperationStatus.SCHEMA_VIOLATION));
-
+
ResponseFormat responseFormat = new ResponseFormat();
responseFormat.setServiceException(new ServiceException());
when(componentsUtils.convertFromStorageResponseForCapabilityType(Mockito.any())).thenCallRealMethod();
when(componentsUtils.getResponseFormatByCapabilityType(ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST, type1_1)).thenReturn(responseFormat);
-
- Either<List<ImmutablePair<Object, Boolean>>, ResponseFormat> result = commonImportManager.createElementTypesByDao(elementTypesToCreate , validator , elementInfoGetter, elementFetcher, elementAdder, elementUpgrader);
+ Either<List<ImmutablePair<Object, Boolean>>, ResponseFormat> result = commonImportManager.createElementTypesByDao(elementTypesToCreate,
+ validator, elementInfoGetter, elementFetcher, elementAdder, elementUpgrader);
verify(elementAdder, never()).apply(Mockito.any());
verify(elementUpgrader).apply(type1_1, type1);
verify(janusGraphGenericDao).rollback();
assertThat(result.isRight()).isTrue();
}
-
+
@Test
public void testCreateElementTypesByDao_capabilityTypeFound_UpgradeSucceeded() {
CapabilityTypeDefinition type1 = new CapabilityTypeDefinition();
CapabilityTypeDefinition type1_1 = new CapabilityTypeDefinition();
List<Object> elementTypesToCreate = Arrays.asList(type1_1);
-
- ImmutablePair<ElementTypeEnum, String> elementInfo = new ImmutablePair<>(ElementTypeEnum.CAPABILITY_TYPE, "TestCapability");
+
+ ImmutablePair<ElementTypeEnum, String> elementInfo = new ImmutablePair<>(ElementTypeEnum.CAPABILITY_TYPE, "TestCapability");
when(elementInfoGetter.apply(type1_1)).thenReturn(elementInfo);
-
+
when(validator.apply(type1_1)).thenReturn(Either.left(ActionStatus.OK));
when(elementFetcher.apply("TestCapability")).thenReturn(Either.left(type1));
when(elementUpgrader.apply(type1_1, type1)).thenReturn(Either.left(type1_1));
-
- Either<List<ImmutablePair<Object, Boolean>>, ResponseFormat> result = commonImportManager.createElementTypesByDao(elementTypesToCreate , validator , elementInfoGetter, elementFetcher, elementAdder, elementUpgrader);
+
+ Either<List<ImmutablePair<Object, Boolean>>, ResponseFormat> result = commonImportManager.createElementTypesByDao(elementTypesToCreate,
+ validator, elementInfoGetter, elementFetcher, elementAdder, elementUpgrader);
verify(elementAdder, never()).apply(Mockito.any());
verify(elementUpgrader).apply(type1_1, type1);
verify(janusGraphGenericDao).commit();
-
+
assertEquals(type1_1, result.left().value().get(0).getLeft());
assertEquals(true, result.left().value().get(0).getRight());
}
-
+
@Test
public void testCreateElementTypesByDao_capabilityTypeFound_UpgradeAlreadyExists() {
CapabilityTypeDefinition type1 = new CapabilityTypeDefinition();
CapabilityTypeDefinition type1_1 = new CapabilityTypeDefinition();
List<Object> elementTypesToCreate = Arrays.asList(type1_1);
-
- ImmutablePair<ElementTypeEnum, String> elementInfo = new ImmutablePair<>(ElementTypeEnum.CAPABILITY_TYPE, "TestCapability");
+
+ ImmutablePair<ElementTypeEnum, String> elementInfo = new ImmutablePair<>(ElementTypeEnum.CAPABILITY_TYPE, "TestCapability");
when(elementInfoGetter.apply(type1_1)).thenReturn(elementInfo);
-
+
when(validator.apply(type1_1)).thenReturn(Either.left(ActionStatus.OK));
when(elementFetcher.apply("TestCapability")).thenReturn(Either.left(type1));
when(elementUpgrader.apply(type1_1, type1)).thenReturn(Either.right(StorageOperationStatus.OK));
-
- Either<List<ImmutablePair<Object, Boolean>>, ResponseFormat> result = commonImportManager.createElementTypesByDao(elementTypesToCreate , validator , elementInfoGetter, elementFetcher, elementAdder, elementUpgrader);
+
+ Either<List<ImmutablePair<Object, Boolean>>, ResponseFormat> result = commonImportManager.createElementTypesByDao(elementTypesToCreate,
+ validator, elementInfoGetter, elementFetcher, elementAdder, elementUpgrader);
verify(elementAdder, never()).apply(Mockito.any());
verify(elementUpgrader).apply(type1_1, type1);
verify(janusGraphGenericDao).commit();
-
+
assertEquals(type1_1, result.left().value().get(0).getLeft());
assertEquals(false, result.left().value().get(0).getRight());
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManagerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManagerTest.java
index a6ee23b392..c288fa82cd 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManagerTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManagerTest.java
@@ -50,7 +50,7 @@ public class GroupTypeImportManagerTest {
public void shouldInvokeCreateElementTypes() {
GroupTypeImportManager groupTypeImportManager = new GroupTypeImportManager(groupTypeOperation, componentsUtils,
toscaOperationFacade, commonImportManager, modelOperation);
- groupTypeImportManager.createGroupTypes(data, null);
+ groupTypeImportManager.createGroupTypes(data, null, false);
Mockito.verify(commonImportManager).createElementTypes(Mockito.any(ToscaTypeImportData.class), Mockito.any(), Mockito.any(), Mockito.any());
}
} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceLifecycleTypeImportManagerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceLifecycleTypeImportManagerTest.java
index 0595a4c24d..9aa68d81cd 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceLifecycleTypeImportManagerTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceLifecycleTypeImportManagerTest.java
@@ -20,7 +20,21 @@
package org.openecomp.sdc.be.components.impl;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.hamcrest.Matchers.empty;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
import fj.data.Either;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
@@ -41,21 +55,6 @@ import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.ModelOperation;
import org.openecomp.sdc.exception.ResponseFormat;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.List;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.containsInAnyOrder;
-import static org.hamcrest.Matchers.empty;
-import static org.hamcrest.Matchers.hasSize;
-import static org.hamcrest.Matchers.not;
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.when;
-
public class InterfaceLifecycleTypeImportManagerTest {
@InjectMocks
@@ -67,13 +66,14 @@ public class InterfaceLifecycleTypeImportManagerTest {
@BeforeClass
public static void beforeClass() throws IOException {
- when(interfaceLifecycleOperation.createInterfaceType(Mockito.any(InterfaceDefinition.class))).thenAnswer(new Answer<Either<InterfaceDefinition, StorageOperationStatus>>() {
- public Either<InterfaceDefinition, StorageOperationStatus> answer(InvocationOnMock invocation) {
- Object[] args = invocation.getArguments();
- return Either.left((InterfaceDefinition) args[0]);
- }
+ when(interfaceLifecycleOperation.createInterfaceType(Mockito.any(InterfaceDefinition.class))).thenAnswer(
+ new Answer<Either<InterfaceDefinition, StorageOperationStatus>>() {
+ public Either<InterfaceDefinition, StorageOperationStatus> answer(InvocationOnMock invocation) {
+ Object[] args = invocation.getArguments();
+ return Either.left((InterfaceDefinition) args[0]);
+ }
- });
+ });
when(commonImportManager.createElementTypesFromYml(Mockito.anyString(), Mockito.any())).thenCallRealMethod();
when(commonImportManager.createElementTypesFromToscaJsonMap(Mockito.any(), Mockito.any())).thenCallRealMethod();
}
@@ -88,7 +88,7 @@ public class InterfaceLifecycleTypeImportManagerTest {
final String ymlContent = getYmlContent();
when(modelOperation.findModelByName("test")).thenReturn(Optional.of(new Model("test")));
final Either<List<InterfaceDefinition>, ResponseFormat> createCapabilityTypes =
- importManager.createLifecycleTypes(ymlContent, "test");
+ importManager.createLifecycleTypes(ymlContent, "test", false);
assertTrue(createCapabilityTypes.isLeft());
final List<InterfaceDefinition> interfaceDefinitionList = createCapabilityTypes.left().value();
assertThat("Interface definitions should not be empty", interfaceDefinitionList, is(not(empty())));
@@ -98,10 +98,10 @@ public class InterfaceLifecycleTypeImportManagerTest {
final String standardInterfaceType = "tosca.interfaces.node.lifecycle.Standard";
final String nslcmInterfaceType = "tosca.interfaces.nfv.Nslcm";
final Optional<InterfaceDefinition> standardInterfaceOpt = interfaceDefinitionList.stream().filter(
- interfaceDefinition -> standardInterfaceType.equals(interfaceDefinition.getType()))
+ interfaceDefinition -> standardInterfaceType.equals(interfaceDefinition.getType()))
.findFirst();
final Optional<InterfaceDefinition> nslcmInterfaceOpt = interfaceDefinitionList.stream().filter(
- interfaceDefinition -> nslcmInterfaceType.equals(interfaceDefinition.getType()))
+ interfaceDefinition -> nslcmInterfaceType.equals(interfaceDefinition.getType()))
.findFirst();
assertThat("", standardInterfaceOpt.isPresent(), is(true));
assertThat("", nslcmInterfaceOpt.isPresent(), is(true));
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogicTest.java
index 08d0787b27..5e9d4e7f5d 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogicTest.java
@@ -46,8 +46,8 @@ import org.mockito.MockitoAnnotations;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.exception.BusinessException;
import org.openecomp.sdc.be.model.Model;
-import org.openecomp.sdc.be.model.jsonjanusgraph.operations.exception.OperationException;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.exception.ModelOperationExceptionSupplier;
+import org.openecomp.sdc.be.model.jsonjanusgraph.operations.exception.OperationException;
import org.openecomp.sdc.be.model.operations.impl.ModelOperation;
import org.openecomp.sdc.common.zip.ZipUtils;
import org.openecomp.sdc.common.zip.exception.ZipException;
@@ -80,7 +80,7 @@ class ModelBusinessLogicTest {
assertThat(result).isNotNull();
assertThat(result.getName()).isEqualTo(model.getName());
}
-
+
@Test
void createModelWithDataTypesTest() {
final String dataTypes = "dummyString";
@@ -88,8 +88,8 @@ class ModelBusinessLogicTest {
final Model result = modelBusinessLogic.createModel(model, dataTypes);
assertThat(result).isNotNull();
assertThat(result.getName()).isEqualTo(model.getName());
-
- verify(dataTypeImportManager).createDataTypes(dataTypes, model.getName());
+
+ verify(dataTypeImportManager).createDataTypes(dataTypes, model.getName(), false);
}
@Test
@@ -220,4 +220,4 @@ class ModelBusinessLogicTest {
final List<Model> actualModelList = modelBusinessLogic.listModels();
assertTrue(actualModelList.isEmpty(), "The model list should be empty");
}
-} \ No newline at end of file
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/RelationshipTypeImportManagerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/RelationshipTypeImportManagerTest.java
index 06be58d584..5a8a704728 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/RelationshipTypeImportManagerTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/RelationshipTypeImportManagerTest.java
@@ -44,7 +44,7 @@ public class RelationshipTypeImportManagerTest {
public void shouldInvokeCreateElementTypes() {
RelationshipTypeImportManager relationshipTypeImportManager =
new RelationshipTypeImportManager(relationshipTypeOperation, commonImportManager, componentsUtils, modelOperation);
- relationshipTypeImportManager.createRelationshipTypes("anyYaml", "anyModel");
+ relationshipTypeImportManager.createRelationshipTypes("anyYaml", "anyModel", false);
Mockito.verify(commonImportManager).createElementTypes((String) Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any());
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesUploadEndpointTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesUploadEndpointTest.java
index c948910a67..72af772507 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesUploadEndpointTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesUploadEndpointTest.java
@@ -67,6 +67,7 @@ import org.openecomp.sdc.be.model.AnnotationTypeDefinition;
import org.openecomp.sdc.be.model.operations.StorageException;
import org.openecomp.sdc.be.model.operations.impl.AnnotationTypeOperations;
import org.openecomp.sdc.be.model.operations.impl.CommonTypeOperations;
+import org.openecomp.sdc.be.model.operations.impl.ModelOperation;
import org.openecomp.sdc.be.model.operations.impl.OperationUtils;
import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
import org.openecomp.sdc.be.resources.data.AnnotationTypeData;
@@ -84,40 +85,14 @@ class TypesUploadEndpointTest extends JerseySpringBaseTest {
private static PropertyOperation propertyOperation;
private static ComponentsUtils componentUtils;
private static OperationUtils operationUtils;
-
- @org.springframework.context.annotation.Configuration
- @Import(BaseTestConfig.class)
- static class TypesUploadTestConfig {
-
- @Bean
- TypesUploadEndpoint typesUploadEndpoint() {
- UserBusinessLogic userBusinessLogic = mock(UserBusinessLogic.class);
- ComponentsUtils componentsUtils = mock(ComponentsUtils.class);
- return new TypesUploadEndpoint(userBusinessLogic, componentsUtils, commonImportManager(),
- annotationTypeOperations(), accessValidations);
- }
-
- @Bean
- CommonImportManager commonImportManager() {
- return new CommonImportManager(componentUtils, propertyOperation);
- }
-
- @Bean
- AnnotationTypeOperations annotationTypeOperations() {
- return new AnnotationTypeOperations(commonTypeOperations());
- }
-
- @Bean
- CommonTypeOperations commonTypeOperations() {
- return new CommonTypeOperations(janusGraphGenericDao, propertyOperation, operationUtils);
- }
- }
+ private static ModelOperation modelOperation;
@BeforeAll
public static void initClass() {
janusGraphGenericDao = mock(HealingJanusGraphGenericDao.class);
accessValidations = mock(AccessValidations.class);
propertyOperation = mock(PropertyOperation.class);
+ modelOperation = mock(ModelOperation.class);
componentUtils = Mockito.mock(ComponentsUtils.class);
operationUtils = Mockito.mock(OperationUtils.class);
}
@@ -258,4 +233,32 @@ class TypesUploadEndpointTest extends JerseySpringBaseTest {
typeActionResults.add(new ImmutablePair(dummyDefition, null));
assertThat(TypesUploadEndpoint.getHttpStatus(typeActionResults).value()).isEqualTo(HttpStatus.BAD_REQUEST_400);
}
+
+ @org.springframework.context.annotation.Configuration
+ @Import(BaseTestConfig.class)
+ static class TypesUploadTestConfig {
+
+ @Bean
+ TypesUploadEndpoint typesUploadEndpoint() {
+ UserBusinessLogic userBusinessLogic = mock(UserBusinessLogic.class);
+ ComponentsUtils componentsUtils = mock(ComponentsUtils.class);
+ return new TypesUploadEndpoint(userBusinessLogic, componentsUtils, commonImportManager(),
+ annotationTypeOperations(), accessValidations);
+ }
+
+ @Bean
+ CommonImportManager commonImportManager() {
+ return new CommonImportManager(componentUtils, propertyOperation, modelOperation);
+ }
+
+ @Bean
+ AnnotationTypeOperations annotationTypeOperations() {
+ return new AnnotationTypeOperations(commonTypeOperations());
+ }
+
+ @Bean
+ CommonTypeOperations commonTypeOperations() {
+ return new CommonTypeOperations(janusGraphGenericDao, propertyOperation, operationUtils);
+ }
+ }
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesUploadServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesUploadServletTest.java
index 395bee3755..08191192b7 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesUploadServletTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesUploadServletTest.java
@@ -37,7 +37,6 @@ import org.apache.commons.lang3.tuple.ImmutablePair;
import org.eclipse.jetty.http.HttpStatus;
import org.glassfish.hk2.utilities.binding.AbstractBinder;
import org.glassfish.jersey.client.ClientConfig;
-import org.glassfish.jersey.media.multipart.FormDataBodyPart;
import org.glassfish.jersey.media.multipart.FormDataMultiPart;
import org.glassfish.jersey.media.multipart.MultiPart;
import org.glassfish.jersey.media.multipart.MultiPartFeature;
@@ -130,7 +129,7 @@ class TypesUploadServletTest extends JerseyTest {
@Test
void creatingCapabilityTypeSuccessTest() {
final Either<List<ImmutablePair<CapabilityTypeDefinition, Boolean>>, ResponseFormat> either = Either.left(emptyList());
- when(importManager.createCapabilityTypes(Mockito.anyString(), Mockito.isNull())).thenReturn(either);
+ when(importManager.createCapabilityTypes(Mockito.anyString(), Mockito.isNull(), Mockito.anyBoolean())).thenReturn(either);
final FileDataBodyPart filePart = new FileDataBodyPart("capabilityTypeZip", new File("src/test/resources/types/capabilityTypes.zip"));
MultiPart multipartEntity = new FormDataMultiPart();
multipartEntity.bodyPart(filePart);
@@ -140,11 +139,11 @@ class TypesUploadServletTest extends JerseyTest {
assertEquals(HttpStatus.CREATED_201, response.getStatus());
}
-
+
@Test
void creatingCapabilityTypeWithModelSuccessTest() {
final Either<List<ImmutablePair<CapabilityTypeDefinition, Boolean>>, ResponseFormat> either = Either.left(emptyList());
- when(importManager.createCapabilityTypes(Mockito.anyString(), Mockito.eq("testModel"))).thenReturn(either);
+ when(importManager.createCapabilityTypes(Mockito.anyString(), Mockito.eq("testModel"), Mockito.anyBoolean())).thenReturn(either);
final FileDataBodyPart filePart = new FileDataBodyPart("capabilityTypeZip", new File("src/test/resources/types/capabilityTypes.zip"));
FormDataMultiPart multipartEntity = new FormDataMultiPart();
multipartEntity.bodyPart(filePart);