diff options
Diffstat (limited to 'catalog-be')
12 files changed, 103 insertions, 17 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 4ce08ea74a..04a8fc88db 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 @@ -22,12 +22,15 @@ package org.openecomp.sdc.be.components.impl; import fj.data.Either; import java.util.List; 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.dao.api.ActionStatus; import org.openecomp.sdc.be.model.CapabilityTypeDefinition; +import org.openecomp.sdc.be.model.Model; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.model.operations.impl.CapabilityTypeOperation; +import org.openecomp.sdc.be.model.operations.impl.ModelOperation; import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder; import org.openecomp.sdc.be.model.utils.TypeCompareUtils; import org.openecomp.sdc.be.utils.TypeUtils; @@ -42,11 +45,13 @@ public class CapabilityTypeImportManager { private static final Logger log = Logger.getLogger(CapabilityTypeImportManager.class.getName()); private final CapabilityTypeOperation capabilityTypeOperation; private final CommonImportManager commonImportManager; + private final ModelOperation modelOperation; @Autowired - public CapabilityTypeImportManager(CapabilityTypeOperation capabilityTypeOperation, CommonImportManager commonImportManager) { + 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) { @@ -57,7 +62,12 @@ public class CapabilityTypeImportManager { 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)){ - capabilityTypes.left().value().forEach(capabilityType -> capabilityType.setModel(modelName)); + final Optional<Model> modelOptional = modelOperation.findModelByName(modelName); + if (modelOptional.isPresent()) { + capabilityTypes.left().value().forEach(capabilityType -> capabilityType.setModel(modelName)); + return capabilityTypes; + } + return Either.right(ActionStatus.INVALID_MODEL); } return capabilityTypes; } 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 6343eb9b3d..95ef74e93c 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 @@ -24,6 +24,7 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; import javax.annotation.Resource; @@ -34,9 +35,11 @@ import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition; 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; import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder; import org.openecomp.sdc.be.model.tosca.ToscaPropertyType; @@ -55,6 +58,8 @@ public class DataTypeImportManager { private ComponentsUtils componentsUtils; @Resource private CommonImportManager commonImportManager; + @Resource + private ModelOperation modelOperation; public Either<List<ImmutablePair<DataTypeDefinition, Boolean>>, ResponseFormat> createDataTypes(final String dataTypeYml, final String modelName) { return commonImportManager @@ -64,7 +69,12 @@ public class DataTypeImportManager { 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)){ - dataTypes.left().value().forEach(dataType -> dataType.setModel(modelName)); + final Optional<Model> modelOptional = modelOperation.findModelByName(modelName); + if (modelOptional.isPresent()) { + dataTypes.left().value().forEach(dataType -> dataType.setModel(modelName)); + return dataTypes; + } + return Either.right(ActionStatus.INVALID_MODEL); } return dataTypes; } 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 321ed99ae7..e57c46bbe6 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 @@ -23,6 +23,7 @@ import fj.data.Either; import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.stream.Collectors; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; @@ -35,10 +36,12 @@ import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.model.CapabilityDefinition; import org.openecomp.sdc.be.model.ComponentInstanceProperty; import org.openecomp.sdc.be.model.GroupTypeDefinition; +import org.openecomp.sdc.be.model.Model; 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.ModelOperation; import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder; import org.openecomp.sdc.be.model.utils.TypeCompareUtils; import org.openecomp.sdc.be.utils.TypeUtils; @@ -55,13 +58,15 @@ public class GroupTypeImportManager { private final ComponentsUtils componentsUtils; private final ToscaOperationFacade toscaOperationFacade; private final CommonImportManager commonImportManager; + private final ModelOperation modelOperation; public GroupTypeImportManager(GroupTypeOperation groupTypeOperation, ComponentsUtils componentsUtils, ToscaOperationFacade toscaOperationFacade, - CommonImportManager commonImportManager) { + CommonImportManager commonImportManager, ModelOperation modelOperation) { this.groupTypeOperation = groupTypeOperation; this.componentsUtils = componentsUtils; this.toscaOperationFacade = toscaOperationFacade; this.commonImportManager = commonImportManager; + this.modelOperation = modelOperation; } public Either<List<ImmutablePair<GroupTypeDefinition, Boolean>>, ResponseFormat> createGroupTypes(ToscaTypeImportData toscaTypeImportData, String modelName) { @@ -71,7 +76,12 @@ public class GroupTypeImportManager { 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)); + final Optional<Model> modelOptional = modelOperation.findModelByName(modelName); + if (modelOptional.isPresent()) { + groupTypes.left().value().forEach(groupType -> groupType.setModel(modelName)); + return groupTypes; + } + return Either.right(ActionStatus.INVALID_MODEL); } return groupTypes; } 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 eb8df50d70..ef00d9a92d 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 @@ -26,6 +26,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Optional; import java.util.stream.Collectors; import javax.annotation.Resource; @@ -36,9 +37,11 @@ import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields; import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.model.InterfaceDefinition; +import org.openecomp.sdc.be.model.Model; 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; @@ -57,6 +60,8 @@ public class InterfaceLifecycleTypeImportManager { private ComponentsUtils componentsUtils; @Resource private CommonImportManager commonImportManager; + @Resource + private ModelOperation modelOperation; public Either<List<InterfaceDefinition>, ResponseFormat> createLifecycleTypes(String interfaceLifecycleTypesYml, final String modelName) { Either<List<InterfaceDefinition>, ActionStatus> interfaces = createInterfaceTypeFromYml(interfaceLifecycleTypesYml, modelName); @@ -71,7 +76,12 @@ public class InterfaceLifecycleTypeImportManager { private Either<List<InterfaceDefinition>, ActionStatus> createInterfaceTypeFromYml(final String interfaceTypesYml, final String modelName) { final Either<List<InterfaceDefinition>, ActionStatus> interfaceTypes = commonImportManager.createElementTypesFromYml(interfaceTypesYml, this::createInterfaceDefinition); if (interfaceTypes.isLeft() && StringUtils.isNotEmpty(modelName)){ - interfaceTypes.left().value().forEach(interfaceType -> interfaceType.setModel(modelName)); + final Optional<Model> modelOptional = modelOperation.findModelByName(modelName); + if (modelOptional.isPresent()) { + interfaceTypes.left().value().forEach(interfaceType -> interfaceType.setModel(modelName)); + return interfaceTypes; + } + return Either.right(ActionStatus.INVALID_MODEL); } return interfaceTypes; } 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 9fa8e303ac..a3a2c013eb 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 @@ -22,6 +22,7 @@ package org.openecomp.sdc.be.components.impl; import fj.data.Either; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.function.Consumer; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; @@ -32,12 +33,14 @@ 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.Model; import org.openecomp.sdc.be.model.PolicyTypeDefinition; import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade; 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.ModelOperation; import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder; import org.openecomp.sdc.be.utils.TypeUtils; import org.openecomp.sdc.exception.ResponseFormat; @@ -52,16 +55,18 @@ public class PolicyTypeImportManager { private final ToscaOperationFacade toscaOperationFacade; private final CommonImportManager commonImportManager; private final GroupTypeOperation groupTypeOperation; + private final ModelOperation modelOperation; public PolicyTypeImportManager(IPolicyTypeOperation policyTypeOperation, ComponentsUtils componentsUtils, GroupOperation groupOperation, ToscaOperationFacade toscaOperationFacade, CommonImportManager commonImportManager, - GroupTypeOperation groupTypeOperation) { + GroupTypeOperation groupTypeOperation, ModelOperation modelOperation) { this.policyTypeOperation = policyTypeOperation; this.componentsUtils = componentsUtils; this.groupOperation = groupOperation; this.toscaOperationFacade = toscaOperationFacade; this.commonImportManager = commonImportManager; this.groupTypeOperation = groupTypeOperation; + this.modelOperation = modelOperation; } public Either<List<ImmutablePair<PolicyTypeDefinition, Boolean>>, ResponseFormat> createPolicyTypes(ToscaTypeImportData toscaTypeImportData, String modelName) { @@ -71,7 +76,12 @@ public class PolicyTypeImportManager { 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)); + final Optional<Model> modelOptional = modelOperation.findModelByName(modelName); + if (modelOptional.isPresent()) { + policyTypes.left().value().forEach(policyType -> policyType.setModel(modelName)); + return policyTypes; + } + return Either.right(ActionStatus.INVALID_MODEL); } return policyTypes; } 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 dafd7919c1..2165b9f7d1 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 @@ -18,12 +18,16 @@ package org.openecomp.sdc.be.components.impl; import fj.data.Either; import java.util.List; 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.impl.ComponentsUtils; +import org.openecomp.sdc.be.model.Model; import org.openecomp.sdc.be.model.RelationshipTypeDefinition; import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter; +import org.openecomp.sdc.be.model.operations.impl.ModelOperation; import org.openecomp.sdc.be.model.operations.impl.RelationshipTypeOperation; import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder; import org.openecomp.sdc.be.utils.TypeUtils; @@ -37,13 +41,15 @@ public class RelationshipTypeImportManager { private final RelationshipTypeOperation relationshipTypeOperation; private final CommonImportManager commonImportManager; private final ComponentsUtils componentsUtils; + private final ModelOperation modelOperation; @Autowired public RelationshipTypeImportManager(RelationshipTypeOperation relationshipTypeOperation, CommonImportManager commonImportManager, - ComponentsUtils componentsUtils) { + ComponentsUtils componentsUtils, ModelOperation modelOperation) { this.relationshipTypeOperation = relationshipTypeOperation; this.commonImportManager = commonImportManager; this.componentsUtils = componentsUtils; + this.modelOperation = modelOperation; } public Either<List<ImmutablePair<RelationshipTypeDefinition, Boolean>>, ResponseFormat> createRelationshipTypes(final String relationshipYml, final String modelName) { @@ -60,8 +66,13 @@ public class RelationshipTypeImportManager { 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()){ - relationshipTypes.left().value().forEach(relationshipType -> relationshipType.setModel(modelName)); + if (relationshipTypes.isLeft() && StringUtils.isNotEmpty(modelName)){ + final Optional<Model> modelOptional = modelOperation.findModelByName(modelName); + if (modelOptional.isPresent()) { + relationshipTypes.left().value().forEach(relationshipType -> relationshipType.setModel(modelName)); + return relationshipTypes; + } + return Either.right(ActionStatus.INVALID_MODEL); } return relationshipTypes; } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java index 9d3817431f..1c7fe2d470 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java @@ -65,6 +65,7 @@ import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.api.Constants; 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; @@ -197,6 +198,7 @@ public class TypesFetchServlet extends AbstractValidationsServlet { try { init(); validateUserExist(responseWrapper, userWrapper, userId); + modelName = ValidationUtils.sanitizeInputString(modelName); if (responseWrapper.isEmpty()) { String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {} | modifier id is {}", url, userId); @@ -240,6 +242,7 @@ public class TypesFetchServlet extends AbstractValidationsServlet { try { init(); validateUserExist(responseWrapper, userWrapper, userId); + modelName = ValidationUtils.sanitizeInputString(modelName); if (responseWrapper.isEmpty()) { String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {} | modifier id is {}", url, userId); 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 0fd4206cd6..79982eaa3a 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 @@ -80,6 +80,7 @@ import org.openecomp.sdc.common.datastructure.FunctionalInterfaces.ConsumerThree 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; @@ -132,9 +133,10 @@ public class TypesUploadServlet extends AbstractValidationsServlet { 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, modelName)); - return uploadElementTypeServletLogic(createElementsMethod, file, request, creator, NodeTypeEnum.CapabilityType.name(), modelName); + () -> capabilityTypeImportManager.createCapabilityTypes(ymlPayload, sanitizedModelName)); + return uploadElementTypeServletLogic(createElementsMethod, file, request, creator, NodeTypeEnum.CapabilityType.name(), sanitizedModelName); } @POST @@ -149,6 +151,7 @@ public class TypesUploadServlet extends AbstractValidationsServlet { 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); } @@ -164,8 +167,9 @@ public class TypesUploadServlet extends AbstractValidationsServlet { 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, modelName)); + () -> interfaceLifecycleTypeImportManager.createLifecycleTypes(ymlPayload, sanitizedModelName)); return uploadElementTypeServletLogic(createElementsMethod, file, request, creator, "Interface Types"); } @@ -197,6 +201,7 @@ public class TypesUploadServlet extends AbstractValidationsServlet { 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); } @@ -213,6 +218,7 @@ public class TypesUploadServlet extends AbstractValidationsServlet { @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); Map<String, ToscaTypeMetadata> typesMetadata = getTypesMetadata(toscaTypesMetaData); return uploadTypesWithMetaData(this::createGroupTypes, typesMetadata, file, request, creator, NodeTypeEnum.GroupType.getName(), modelName); } @@ -230,6 +236,7 @@ public class TypesUploadServlet extends AbstractValidationsServlet { @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); Map<String, ToscaTypeMetadata> typesMetadata = getTypesMetadata(toscaTypesMetaData); return uploadTypesWithMetaData(this::createPolicyTypes, typesMetadata, file, request, creator, NodeTypeEnum.PolicyType.getName(), modelName); } 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 a684e21ce1..f8b1800951 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 @@ -21,6 +21,7 @@ package org.openecomp.sdc.be.components.impl; import fj.data.Either; +import java.util.Optional; import org.apache.commons.lang3.tuple.ImmutablePair; import org.junit.Before; import org.junit.BeforeClass; @@ -32,8 +33,10 @@ import org.mockito.stubbing.Answer; 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.Model; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.model.operations.impl.CapabilityTypeOperation; +import org.openecomp.sdc.be.model.operations.impl.ModelOperation; import org.openecomp.sdc.be.model.operations.impl.PropertyOperation; import org.openecomp.sdc.common.util.CapabilityTypeNameEnum; import org.openecomp.sdc.exception.ResponseFormat; @@ -57,7 +60,8 @@ public class CapabilityTypeImportManagerTest { 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 CapabilityTypeImportManager manager = new CapabilityTypeImportManager(capabilityTypeOperation, commonImportManager); + private ModelOperation modelOperation = mock(ModelOperation.class); + private CapabilityTypeImportManager manager = new CapabilityTypeImportManager(capabilityTypeOperation, commonImportManager, modelOperation); @BeforeClass public static void beforeClass() { @@ -81,6 +85,7 @@ public class CapabilityTypeImportManagerTest { @Test 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"); assertTrue(createCapabilityTypes.isLeft()); 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 33cd971c14..a6ee23b392 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 @@ -28,6 +28,7 @@ import org.openecomp.sdc.be.components.impl.model.ToscaTypeImportData; import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade; import org.openecomp.sdc.be.model.operations.impl.GroupTypeOperation; +import org.openecomp.sdc.be.model.operations.impl.ModelOperation; @RunWith(MockitoJUnitRunner.class) public class GroupTypeImportManagerTest { @@ -41,12 +42,14 @@ public class GroupTypeImportManagerTest { @Mock CommonImportManager commonImportManager; @Mock + ModelOperation modelOperation; + @Mock private ToscaTypeImportData data; @Test public void shouldInvokeCreateElementTypes() { GroupTypeImportManager groupTypeImportManager = new GroupTypeImportManager(groupTypeOperation, componentsUtils, - toscaOperationFacade, commonImportManager); + toscaOperationFacade, commonImportManager, modelOperation); groupTypeImportManager.createGroupTypes(data, null); Mockito.verify(commonImportManager).createElementTypes(Mockito.any(ToscaTypeImportData.class), Mockito.any(), Mockito.any(), Mockito.any()); } 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 9cd18bc9a2..0595a4c24d 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 @@ -35,8 +35,10 @@ import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.model.InterfaceDefinition; +import org.openecomp.sdc.be.model.Model; 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.exception.ResponseFormat; import java.io.IOException; @@ -61,6 +63,7 @@ public class InterfaceLifecycleTypeImportManagerTest { public static final CommonImportManager commonImportManager = Mockito.mock(CommonImportManager.class); public static final IInterfaceLifecycleOperation interfaceLifecycleOperation = Mockito.mock(IInterfaceLifecycleOperation.class); public static final ComponentsUtils componentsUtils = Mockito.mock(ComponentsUtils.class); + public static final ModelOperation modelOperation = Mockito.mock(ModelOperation.class); @BeforeClass public static void beforeClass() throws IOException { @@ -83,6 +86,7 @@ public class InterfaceLifecycleTypeImportManagerTest { @Test public void createLifecycleTypesTest() throws IOException { final String ymlContent = getYmlContent(); + when(modelOperation.findModelByName("test")).thenReturn(Optional.of(new Model("test"))); final Either<List<InterfaceDefinition>, ResponseFormat> createCapabilityTypes = importManager.createLifecycleTypes(ymlContent, "test"); assertTrue(createCapabilityTypes.isLeft()); 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 3495159153..06be58d584 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 @@ -25,6 +25,7 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; import org.openecomp.sdc.be.impl.ComponentsUtils; +import org.openecomp.sdc.be.model.operations.impl.ModelOperation; import org.openecomp.sdc.be.model.operations.impl.RelationshipTypeOperation; @RunWith(MockitoJUnitRunner.class) @@ -36,11 +37,13 @@ public class RelationshipTypeImportManagerTest { private CommonImportManager commonImportManager; @Mock private ComponentsUtils componentsUtils; + @Mock + private ModelOperation modelOperation; @Test public void shouldInvokeCreateElementTypes() { RelationshipTypeImportManager relationshipTypeImportManager = - new RelationshipTypeImportManager(relationshipTypeOperation, commonImportManager, componentsUtils); + new RelationshipTypeImportManager(relationshipTypeOperation, commonImportManager, componentsUtils, modelOperation); relationshipTypeImportManager.createRelationshipTypes("anyYaml", "anyModel"); Mockito.verify(commonImportManager).createElementTypes((String) Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()); |