aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java6
-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/PolicyTypeImportManager.java18
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java20
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManagerTest.java4
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/RelationshipTypeImportManagerTest.java2
6 files changed, 43 insertions, 25 deletions
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 326022d806..8c309bd835 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
@@ -380,9 +380,9 @@ public class CommonImportManager {
}
public <T extends ToscaTypeDataDefinition> Either<List<ImmutablePair<T, Boolean>>, ResponseFormat> createElementTypes(
- ToscaTypeImportData toscaTypeImportData, Function<String, Either<List<T>, ActionStatus>> elementTypeFromYmlCreater,
- Function<List<T>, Either<List<ImmutablePair<T, Boolean>>, ResponseFormat>> elementTypeDaoCreater) {
- Either<List<T>, ActionStatus> elementTypes = elementTypeFromYmlCreater.apply(toscaTypeImportData.getToscaTypesYml());
+ ToscaTypeImportData toscaTypeImportData, BiFunction<String, String, Either<List<T>, ActionStatus>> elementTypeFromYmlCreater,
+ Function<List<T>, Either<List<ImmutablePair<T, Boolean>>, ResponseFormat>> elementTypeDaoCreater, String modelName) {
+ Either<List<T>, ActionStatus> elementTypes = elementTypeFromYmlCreater.apply(toscaTypeImportData.getToscaTypesYml(), modelName);
return elementTypes
.right()
.map(err -> componentsUtils.getResponseFormat(err, ""))
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 d3640a71a7..8015685403 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
@@ -24,11 +24,13 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
+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.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.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.CapabilityDefinition;
import org.openecomp.sdc.be.model.ComponentInstanceProperty;
@@ -37,6 +39,7 @@ import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.GroupTypeOperation;
+import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
import org.openecomp.sdc.be.model.utils.TypeCompareUtils;
import org.openecomp.sdc.be.utils.TypeUtils;
import org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum;
@@ -61,18 +64,23 @@ public class GroupTypeImportManager {
this.commonImportManager = commonImportManager;
}
- public Either<List<ImmutablePair<GroupTypeDefinition, Boolean>>, ResponseFormat> createGroupTypes(ToscaTypeImportData toscaTypeImportData) {
- return commonImportManager.createElementTypes(toscaTypeImportData, this::createGroupTypesFromYml, this::upsertGroupTypesByDao);
+ public Either<List<ImmutablePair<GroupTypeDefinition, Boolean>>, ResponseFormat> createGroupTypes(ToscaTypeImportData toscaTypeImportData, String modelName) {
+ return commonImportManager.createElementTypes(toscaTypeImportData, this::createGroupTypesFromYml, this::upsertGroupTypesByDao, modelName);
}
- private Either<List<GroupTypeDefinition>, ActionStatus> createGroupTypesFromYml(String groupTypesYml) {
- return commonImportManager.createElementTypesFromYml(groupTypesYml, this::createGroupType);
+ 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)){
+ groupTypes.left().value().forEach(groupType -> groupType.setModel(modelName));
+ }
+ return groupTypes;
}
private Either<List<ImmutablePair<GroupTypeDefinition, Boolean>>, ResponseFormat> upsertGroupTypesByDao(
List<GroupTypeDefinition> groupTypesToCreate) {
return commonImportManager.createElementTypesByDao(groupTypesToCreate, this::validateGroupType,
- groupType -> new ImmutablePair<>(ElementTypeEnum.GROUP_TYPE, groupType.getType()), groupTypeOperation::getLatestGroupTypeByType,
+ groupType -> new ImmutablePair<>(ElementTypeEnum.GROUP_TYPE, UniqueIdBuilder.buildGroupTypeUid(groupType.getModel(),
+ groupType.getType(), groupType.getVersion(), NodeTypeEnum.GroupType.getName()).toLowerCase()), groupTypeOperation::getLatestGroupTypeByType,
groupTypeOperation::addGroupType, this::updateGroupType);
}
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 2b9f58ce51..48519d9abe 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
@@ -23,11 +23,13 @@ import fj.data.Either;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
+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.components.impl.model.ToscaTypeImportData;
import org.openecomp.sdc.be.components.impl.utils.PolicyTypeImportUtils;
import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.GroupTypeDefinition;
import org.openecomp.sdc.be.model.PolicyTypeDefinition;
@@ -36,6 +38,7 @@ import org.openecomp.sdc.be.model.operations.api.IPolicyTypeOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.GroupOperation;
import org.openecomp.sdc.be.model.operations.impl.GroupTypeOperation;
+import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
import org.openecomp.sdc.be.utils.TypeUtils;
import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.stereotype.Component;
@@ -61,18 +64,23 @@ public class PolicyTypeImportManager {
this.groupTypeOperation = groupTypeOperation;
}
- public Either<List<ImmutablePair<PolicyTypeDefinition, Boolean>>, ResponseFormat> createPolicyTypes(ToscaTypeImportData toscaTypeImportData) {
- return commonImportManager.createElementTypes(toscaTypeImportData, this::createPolicyTypesFromYml, this::upsertPolicyTypesByDao);
+ public Either<List<ImmutablePair<PolicyTypeDefinition, Boolean>>, ResponseFormat> createPolicyTypes(ToscaTypeImportData toscaTypeImportData, String modelName) {
+ return commonImportManager.createElementTypes(toscaTypeImportData, this::createPolicyTypesFromYml, this::upsertPolicyTypesByDao, modelName);
}
- private Either<List<PolicyTypeDefinition>, ActionStatus> createPolicyTypesFromYml(String policyTypesYml) {
- return commonImportManager.createElementTypesFromYml(policyTypesYml, this::createPolicyType);
+ 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)){
+ policyTypes.left().value().forEach(policyType -> policyType.setModel(modelName));
+ }
+ return policyTypes;
}
private Either<List<ImmutablePair<PolicyTypeDefinition, Boolean>>, ResponseFormat> upsertPolicyTypesByDao(
List<PolicyTypeDefinition> policyTypesToCreate) {
return commonImportManager.createElementTypesByDao(policyTypesToCreate, this::validatePolicyType,
- policyType -> new ImmutablePair<>(ElementTypeEnum.POLICY_TYPE, policyType.getType()), policyTypeOperation::getLatestPolicyTypeByType,
+ policyType -> new ImmutablePair<>(ElementTypeEnum.POLICY_TYPE, UniqueIdBuilder.buildPolicyTypeUid(policyType.getModel(),
+ policyType.getType(), policyType.getVersion(), NodeTypeEnum.PolicyType.getName()).toLowerCase()), policyTypeOperation::getLatestPolicyTypeByType,
policyTypeOperation::addPolicyType, this::updatePolicyType);
}
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 9656550f95..396cb42d47 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
@@ -209,10 +209,11 @@ public class TypesUploadServlet extends AbstractValidationsServlet {
@ApiResponse(responseCode = "409", description = "group types already exist")})
@PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
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) {
Map<String, ToscaTypeMetadata> typesMetadata = getTypesMetadata(toscaTypesMetaData);
- return uploadTypesWithMetaData(this::createGroupTypes, typesMetadata, file, request, creator, NodeTypeEnum.GroupType.getName());
+ return uploadTypesWithMetaData(this::createGroupTypes, typesMetadata, file, request, creator, NodeTypeEnum.GroupType.getName(), modelName);
}
@POST
@@ -225,10 +226,11 @@ public class TypesUploadServlet extends AbstractValidationsServlet {
@ApiResponse(responseCode = "409", description = "policy types already exist")})
@PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
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) {
Map<String, ToscaTypeMetadata> typesMetadata = getTypesMetadata(toscaTypesMetaData);
- return uploadTypesWithMetaData(this::createPolicyTypes, typesMetadata, file, request, creator, NodeTypeEnum.PolicyType.getName());
+ return uploadTypesWithMetaData(this::createPolicyTypes, typesMetadata, file, request, creator, NodeTypeEnum.PolicyType.getName(), modelName);
}
private Map<String, ToscaTypeMetadata> getTypesMetadata(String toscaTypesMetaData) {
@@ -297,9 +299,9 @@ public class TypesUploadServlet extends AbstractValidationsServlet {
return responseWrapper;
}
- private Response uploadTypesWithMetaData(ConsumerTwoParam<Wrapper<Response>, ToscaTypeImportData> createElementsMethod,
+ private Response uploadTypesWithMetaData(ConsumerThreeParam<Wrapper<Response>, ToscaTypeImportData, String> createElementsMethod,
Map<String, ToscaTypeMetadata> typesMetaData, File file, final HttpServletRequest request,
- String creator, String elementTypeName) {
+ String creator, String elementTypeName, String modelName) {
init();
String userId = initHeaderParam(creator, request, Constants.USER_ID_HEADER);
Wrapper<String> yamlStringWrapper = new Wrapper<>();
@@ -310,7 +312,7 @@ public class TypesUploadServlet extends AbstractValidationsServlet {
}
if (responseWrapper.isEmpty()) {
ToscaTypeImportData toscaTypeImportData = new ToscaTypeImportData(yamlStringWrapper.getInnerElement(), typesMetaData);
- createElementsMethod.accept(responseWrapper, toscaTypeImportData);
+ createElementsMethod.accept(responseWrapper, toscaTypeImportData, modelName);
}
return responseWrapper.getInnerElement();
} catch (Exception e) {
@@ -347,17 +349,17 @@ public class TypesUploadServlet extends AbstractValidationsServlet {
}
// group types
- private void createGroupTypes(Wrapper<Response> responseWrapper, ToscaTypeImportData toscaTypeImportData) {
+ private void createGroupTypes(Wrapper<Response> responseWrapper, ToscaTypeImportData toscaTypeImportData, String modelName) {
final Supplier<Either<List<ImmutablePair<GroupTypeDefinition, Boolean>>, ResponseFormat>> generateElementTypeFromYml = () -> groupTypeImportManager
- .createGroupTypes(toscaTypeImportData);
+ .createGroupTypes(toscaTypeImportData, modelName);
buildStatusForElementTypeCreate(responseWrapper, generateElementTypeFromYml, ActionStatus.GROUP_TYPE_ALREADY_EXIST,
NodeTypeEnum.GroupType.name());
}
// policy types
- private void createPolicyTypes(Wrapper<Response> responseWrapper, ToscaTypeImportData toscaTypeImportData) {
+ private void createPolicyTypes(Wrapper<Response> responseWrapper, ToscaTypeImportData toscaTypeImportData, String modelName) {
final Supplier<Either<List<ImmutablePair<PolicyTypeDefinition, Boolean>>, ResponseFormat>> generateElementTypeFromYml = () -> policyTypeImportManager
- .createPolicyTypes(toscaTypeImportData);
+ .createPolicyTypes(toscaTypeImportData, modelName);
buildStatusForElementTypeCreate(responseWrapper, generateElementTypeFromYml, ActionStatus.POLICY_TYPE_ALREADY_EXIST,
NodeTypeEnum.PolicyType.name());
}
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 5de1f23181..33cd971c14 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
@@ -47,7 +47,7 @@ public class GroupTypeImportManagerTest {
public void shouldInvokeCreateElementTypes() {
GroupTypeImportManager groupTypeImportManager = new GroupTypeImportManager(groupTypeOperation, componentsUtils,
toscaOperationFacade, commonImportManager);
- groupTypeImportManager.createGroupTypes(data);
- Mockito.verify(commonImportManager).createElementTypes(Mockito.any(ToscaTypeImportData.class), Mockito.any(), Mockito.any());
+ groupTypeImportManager.createGroupTypes(data, null);
+ 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/RelationshipTypeImportManagerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/RelationshipTypeImportManagerTest.java
index a4ee779052..3495159153 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
@@ -42,7 +42,7 @@ public class RelationshipTypeImportManagerTest {
RelationshipTypeImportManager relationshipTypeImportManager =
new RelationshipTypeImportManager(relationshipTypeOperation, commonImportManager, componentsUtils);
relationshipTypeImportManager.createRelationshipTypes("anyYaml", "anyModel");
- Mockito.verify(commonImportManager).createElementTypes(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any());
+ Mockito.verify(commonImportManager).createElementTypes((String) Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any());
}
} \ No newline at end of file