aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be
diff options
context:
space:
mode:
authorshrikantawachar <shrikant.awachar@amdocs.com>2018-05-15 15:32:18 +0530
committershrikantawachar <shrikant.awachar@amdocs.com>2018-05-29 16:25:29 +0530
commite9966c94065f6a74d07578b8cee055c37594a0f7 (patch)
treeb793a40dabb934c5354b2d5ff72ad31a0985da86 /openecomp-be
parente1e4f69030a34ebdbe65e72f8ff5fa25ea8e82bc (diff)
Refactoring validation
Refactoring validation from Code to FTL Change-Id: Ic33a3719a021bb4c82565653fd8d95de38b7929e Issue-ID: SDC-1334 Signed-off-by: shrikantawachar <shrikant.awachar@amdocs.com>
Diffstat (limited to 'openecomp-be')
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComputeManagerImpl.java19
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ImageManagerImpl.java10
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/NicManagerImpl.java7
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComputeManagerImplTest.java21
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ImageManagerImplTest.java18
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/NicManagerImplTest.java12
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/json/JsonUtil.java34
-rw-r--r--openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/schemagenerator/ImageCompositionSchemaInput.java13
-rw-r--r--openecomp-be/tools/install/database/schemaTemplates/composition/image.ftl4
-rw-r--r--openecomp-be/tools/install/database/schemaTemplates/composition/nic.ftl16
10 files changed, 89 insertions, 65 deletions
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComputeManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComputeManagerImpl.java
index 6e462dc370..7f69baea9a 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComputeManagerImpl.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComputeManagerImpl.java
@@ -32,7 +32,6 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComputeEntity;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.DeploymentFlavorEntity;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
-import org.openecomp.sdc.vendorsoftwareproduct.errors.DuplicateComputeInComponentErrorBuilder;
import org.openecomp.sdc.vendorsoftwareproduct.errors.NotSupportedHeatOnboardMethodErrorBuilder;
import org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes;
import org.openecomp.sdc.vendorsoftwareproduct.services.schemagenerator.SchemaGenerator;
@@ -194,14 +193,10 @@ public class ComputeManagerImpl implements ComputeManager {
compute.getId());
boolean manual = vspInfoDao.isManual(compute.getVspId(), compute.getVersion());
- if (!manual) {
- validateHeatVspComputeUpdate("Name",
- compute.getComputeCompositionData().getName(),
- retrieved.getComputeCompositionData().getName());
- }
ComputeCompositionSchemaInput schemaInput = new ComputeCompositionSchemaInput();
- schemaInput.setCompute(compute.getComputeCompositionData());
+ schemaInput.setManual(manual);
+ schemaInput.setCompute(retrieved.getComputeCompositionData());
CompositionEntityValidationData validationData = compositionEntityDataManager
.validateEntity(compute, SchemaTemplateContext.composition, schemaInput);
@@ -214,16 +209,6 @@ public class ComputeManagerImpl implements ComputeManager {
return validationData;
}
- private void validateHeatVspComputeUpdate(String name, String value, String retrivedValue) {
-
- if (value != null && !value.equals(retrivedValue)) {
-
- final ErrorCode updateHeatComputeErrorBuilder =
- DuplicateComputeInComponentErrorBuilder.getComputeHeatReadOnlyErrorBuilder(name);
- throw new CoreException(updateHeatComputeErrorBuilder);
- }
- }
-
private ComputeEntity getComputeEntity(String vspId, Version version, String componentId,
String computeId) {
ComputeEntity computeEntity =
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ImageManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ImageManagerImpl.java
index 6451768119..66f9e97d04 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ImageManagerImpl.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ImageManagerImpl.java
@@ -146,13 +146,6 @@ public class ImageManagerImpl implements ImageManager {
getImageEntity(image.getVspId(), image.getVersion(), image.getComponentId(),
image.getId());
- if (!isManual) {
- final Image imageCompositionData = image.getImageCompositionData();
- final String fileName = imageCompositionData.getFileName();
- validateHeatVspImageUpdate("fileName", fileName, retrieved.getImageCompositionData()
- .getFileName());
- }
-
Collection<ImageEntity> vfcImageList = listImages(image.getVspId(),
image.getVersion(), image.getComponentId());
@@ -162,7 +155,8 @@ public class ImageManagerImpl implements ImageManager {
ImageCompositionSchemaInput schemaInput = new ImageCompositionSchemaInput();
- schemaInput.setImage(image.getImageCompositionData());
+ schemaInput.setManual(isManual);
+ schemaInput.setImage(retrieved.getImageCompositionData());
CompositionEntityValidationData validationData = compositionEntityDataManager
.validateEntity(image, SchemaTemplateContext.composition, schemaInput);
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/NicManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/NicManagerImpl.java
index a4fa6be1d8..24bf8dbe61 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/NicManagerImpl.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/NicManagerImpl.java
@@ -207,13 +207,6 @@ public class NicManagerImpl implements NicManager {
schemaInput.setManual(vspInfoDao.isManual(nic.getVspId(), nic.getVersion()));
schemaInput.setNic(retrieved.getNicCompositionData());
- if (schemaInput.isManual() && !nic.getNicCompositionData().getName()
- .matches(VendorSoftwareProductConstants.NAME_PATTERN)) {
- ErrorCode errorCode = NicErrorBuilder
- .getNicNameFormatErrorBuilder(VendorSoftwareProductConstants.NAME_PATTERN);
- throw new CoreException(errorCode);
- }
-
CompositionEntityValidationData validationData = compositionEntityDataManager
.validateEntity(nic, SchemaTemplateContext.composition, schemaInput);
if (CollectionUtils.isEmpty(validationData.getErrors())) {
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComputeManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComputeManagerImplTest.java
index 9479e08af8..217cdf585b 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComputeManagerImplTest.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComputeManagerImplTest.java
@@ -7,7 +7,6 @@ import org.mockito.Spy;
import org.openecomp.sdc.common.errors.CoreException;
import org.openecomp.sdc.common.errors.ErrorCategory;
import org.openecomp.sdc.common.errors.ErrorCode;
-import org.openecomp.sdc.common.session.SessionContextProviderFactory;
import org.openecomp.sdc.vendorsoftwareproduct.dao.ComputeDao;
import org.openecomp.sdc.vendorsoftwareproduct.dao.DeploymentFlavorDao;
import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao;
@@ -196,18 +195,24 @@ public class ComputeManagerImplTest {
public void testUpdateHEATComputeName() throws Exception {
doReturn(createCompute(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID))
.when(computeDao).get(anyObject());
+
+ String updatedName = COMPUTE1_ID + " name updated";
+ CompositionEntityValidationData toBeReturned =
+ new CompositionEntityValidationData(CompositionEntityType.compute, COMPUTE1_ID);
+
+ toBeReturned.setErrors(Arrays.asList("#/name: "+updatedName+" is not a valid value."+
+ COMPUTE1_ID+"is the only possible value for this field"));
+ doReturn(toBeReturned).when(compositionEntityDataManagerMock).validateEntity(anyObject(),anyObject(),anyObject());
+
ComputeEntity computeEntity = new ComputeEntity(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID);
ComputeData computeData = new ComputeData();
- computeData.setName(COMPUTE1_ID + " name updated");
+ computeData.setName(updatedName);
computeData.setDescription(COMPUTE1_ID + " desc updated");
computeEntity.setComputeCompositionData(computeData);
- try {
- computeManager.updateCompute(computeEntity);
- } catch (CoreException ex) {
- Assert
- .assertEquals(ex.code().id(), VendorSoftwareProductErrorCodes.UPDATE_COMPUTE_NOT_ALLOWED);
- }
+ CompositionEntityValidationData output = computeManager.updateCompute(computeEntity);
+
+ Assert.assertEquals(output.getErrors(), toBeReturned.getErrors());
}
@Test
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ImageManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ImageManagerImplTest.java
index 3a9af0d752..b44bf2d43d 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ImageManagerImplTest.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ImageManagerImplTest.java
@@ -184,17 +184,23 @@ public class ImageManagerImplTest {
public void testUpdateHEATImageFileName() throws Exception {
doReturn(createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID))
.when(imageDao).get(anyObject());
+
+ String updatedName = IMAGE1_ID +" name updated";
+ CompositionEntityValidationData toBeReturned =
+ new CompositionEntityValidationData(CompositionEntityType.image, IMAGE1_ID);
+
+ toBeReturned.setErrors(Arrays.asList("#/name: "+updatedName+" is not a valid value."+
+ IMAGE1_ID+"is the only possible value for this field"));
+ doReturn(toBeReturned).when(compositionEntityDataManagerMock).validateEntity(anyObject(),anyObject(),anyObject());
+
ImageEntity imageEntity = new ImageEntity(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID);
Image imageData = new Image();
- imageData.setFileName(IMAGE1_ID + " name updated");
+ imageData.setFileName(updatedName);
imageData.setDescription(IMAGE1_ID + " desc updated");
imageEntity.setImageCompositionData(imageData);
- try {
- imageManager.updateImage(imageEntity);
- } catch (CoreException ex) {
- Assert.assertEquals(ex.code().id(), VendorSoftwareProductErrorCodes.UPDATE_IMAGE_NOT_ALLOWED);
- }
+ CompositionEntityValidationData output = imageManager.updateImage(imageEntity);
+ Assert.assertEquals(output.getErrors(), toBeReturned.getErrors());
}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/NicManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/NicManagerImplTest.java
index 9efb9e1d11..6ce0f1876c 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/NicManagerImplTest.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/NicManagerImplTest.java
@@ -350,7 +350,7 @@ public class NicManagerImplTest {
CompositionEntityValidationData toBeReturned =
new CompositionEntityValidationData(CompositionEntityType.nic, NIC1_ID);
- toBeReturned.setErrors(Arrays.asList("error1", "error2"));
+ toBeReturned.setErrors(Arrays.asList("Field does not conform to predefined criteria:name : must match [a-zA-Z0-9_]*$"));
doReturn(toBeReturned)
.when(compositionEntityDataManagerMock)
.validateEntity(anyObject(), anyObject(), anyObject());
@@ -363,13 +363,9 @@ public class NicManagerImplTest {
nicData.setNetworkId(NETWORK1_ID);
nicEntity.setNicCompositionData(nicData);
- try {
- nicManager.updateNic(nicEntity);
- Assert.fail();
- } catch (CoreException ex) {
- Assert.assertEquals(VendorSoftwareProductErrorCodes.NIC_NAME_FORMAT_NOT_ALLOWED,
- ex.code().id());
- }
+ CompositionEntityValidationData output = nicManager.updateNic(nicEntity);
+ Assert.assertEquals(output.getErrors(),toBeReturned.getErrors());
+
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/json/JsonUtil.java b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/json/JsonUtil.java
index 92c590b5df..a975016db2 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/json/JsonUtil.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/json/JsonUtil.java
@@ -36,15 +36,15 @@ import java.util.stream.Collectors;
import org.apache.commons.collections4.CollectionUtils;
import org.everit.json.schema.EnumSchema;
import org.everit.json.schema.Schema;
+import org.everit.json.schema.StringSchema;
import org.everit.json.schema.ValidationException;
import org.everit.json.schema.loader.SchemaLoader;
import org.json.JSONObject;
-import org.onap.sdc.tosca.datatypes.model.RequirementDefinition;
import org.openecomp.core.utilities.CommonMethods;
import org.openecomp.core.utilities.deserializers.RequirementDefinitionDeserializer;
-
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
+import org.onap.sdc.tosca.datatypes.model.RequirementDefinition;
/**
@@ -157,9 +157,14 @@ public class JsonUtil {
}
private static String mapValidationExceptionToMessage(ValidationException exception) {
- if (exception.getViolatedSchema() instanceof EnumSchema) {
+ Object schema = exception.getViolatedSchema();
+
+ if (schema instanceof EnumSchema) {
return mapEnumViolationToMessage(exception);
+ } else if (schema instanceof StringSchema) {
+ return mapStringViolationToMessage(exception);
}
+
return exception.getMessage();
}
@@ -173,6 +178,15 @@ public class JsonUtil {
possibleValues.stream().map(Object::toString).collect(Collectors.toList()))));
}
+ private static String mapStringViolationToMessage(ValidationException validationException) {
+ if (ValidationType.PATTERN.getKeyword().equals(validationException.getKeyword())) {
+ String message = validationException.getMessage();
+ String value = message.substring(message.indexOf("["), message.indexOf("]") + 1);
+ return message.replace("string " + value, value + " is not valid value. It");
+ }
+ return validationException.getMessage();
+ }
+
private static List<ValidationException> validateUsingEverit(String json, String jsonSchema) {
LOGGER.debug(
String.format("validateUsingEverit start, json=%s, jsonSchema=%s", json, jsonSchema));
@@ -189,4 +203,18 @@ public class JsonUtil {
}
return null;
}
+
+ private enum ValidationType {
+ PATTERN("pattern");
+
+ private String keyword;
+
+ private ValidationType(String keyword) {
+ this.keyword = keyword;
+ }
+
+ String getKeyword() {
+ return keyword;
+ }
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/schemagenerator/ImageCompositionSchemaInput.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/schemagenerator/ImageCompositionSchemaInput.java
index add08a7020..9db298c86c 100644
--- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/schemagenerator/ImageCompositionSchemaInput.java
+++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/schemagenerator/ImageCompositionSchemaInput.java
@@ -4,6 +4,17 @@ import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Image;
public class ImageCompositionSchemaInput implements SchemaTemplateInput {
+ private boolean manual;
+ private Image image;
+
+ public boolean isManual() {
+ return manual;
+ }
+
+ public void setManual(boolean manual) {
+ this.manual = manual;
+ }
+
public Image getImage() {
return image;
}
@@ -12,7 +23,7 @@ public class ImageCompositionSchemaInput implements SchemaTemplateInput {
this.image = image;
}
- private Image image;
+
}
diff --git a/openecomp-be/tools/install/database/schemaTemplates/composition/image.ftl b/openecomp-be/tools/install/database/schemaTemplates/composition/image.ftl
index 8391390506..6d0fb3c890 100644
--- a/openecomp-be/tools/install/database/schemaTemplates/composition/image.ftl
+++ b/openecomp-be/tools/install/database/schemaTemplates/composition/image.ftl
@@ -3,7 +3,9 @@
"type": "object",
"properties": {
"fileName": {
- "type": "string"
+ "type": "string" <#if !manual>,
+ "enum":["${image.fileName}"]
+ </#if>
},
"description": {
"type": "string"
diff --git a/openecomp-be/tools/install/database/schemaTemplates/composition/nic.ftl b/openecomp-be/tools/install/database/schemaTemplates/composition/nic.ftl
index fec5b9cd64..15d34f2489 100644
--- a/openecomp-be/tools/install/database/schemaTemplates/composition/nic.ftl
+++ b/openecomp-be/tools/install/database/schemaTemplates/composition/nic.ftl
@@ -3,12 +3,16 @@
"type": "object",
"properties": {
"name": {
- "type": "string",
- "enum": [
- "${nic.name}"
- ],
- "default": "${nic.name}"
- },
+ "type": "string",
+ <#if manual>
+ {"pattern":"^[a-zA-Z0-9_]*$"}
+ <#else>
+ "enum": [
+ "${nic.name}"
+ ],
+ "default": "${nic.name}"
+ </#if>
+},
"description": {
"type": "string"
}<#if !manual><#if nic.networkId??>,