From 116f3841d36f5cfc2c03e4c9068a67566d9ac9c5 Mon Sep 17 00:00:00 2001 From: erjamni Date: Fri, 17 Jul 2020 16:31:43 +0200 Subject: [PATCH 01/11] Added lenientValidation support to REMReM generate --- .../eiffel/remrem/generate/cli/CLI.java | 4 +- .../remrem/generate/cli/CLIOptions.java | 5 ++- .../generate/cli/CliOptionsUnitTests.java | 7 +++ .../remrem/generate/cli/CliUnitTests.java | 13 ++++++ pom.xml | 4 +- .../RemremGenerateServiceConstants.java | 2 + .../controller/RemremGenerateController.java | 3 +- .../EiffelRemERLookupControllerUnitTest.java | 44 +++++++++---------- .../EiffelRemremControllerUnitTest.java | 33 ++++++++++---- .../src/test/resources/lv_successInput.json | 1 + 10 files changed, 79 insertions(+), 37 deletions(-) create mode 100644 service/src/test/resources/lv_successInput.json diff --git a/cli/src/main/java/com/ericsson/eiffel/remrem/generate/cli/CLI.java b/cli/src/main/java/com/ericsson/eiffel/remrem/generate/cli/CLI.java index 30cfd714..27a9f3b6 100644 --- a/cli/src/main/java/com/ericsson/eiffel/remrem/generate/cli/CLI.java +++ b/cli/src/main/java/com/ericsson/eiffel/remrem/generate/cli/CLI.java @@ -56,7 +56,6 @@ public class CLI implements CommandLineRunner { @Autowired private List msgServices; - //private MsgService[] msgServices; public CLI(List msgServices) { super(); @@ -176,7 +175,8 @@ private void handleJsonString(String jsonString, CommandLine commandLine) { JsonParser parser = new JsonParser(); JsonObject jsonContent = parser.parse(jsonString).getAsJsonObject(); MsgService msgService = getMessageService(commandLine); - String returnJsonStr = msgService.generateMsg(msgType, jsonContent); + Boolean lv = commandLine.hasOption("lv")? Boolean.getBoolean(commandLine.getOptionValue("lv")) : false; + String returnJsonStr = msgService.generateMsg(msgType, jsonContent, lv); returnJsonStr = "[" + returnJsonStr + "]"; if (responseFilePath != null) { try (PrintWriter out = new PrintWriter(responseFilePath)) { diff --git a/cli/src/main/java/com/ericsson/eiffel/remrem/generate/cli/CLIOptions.java b/cli/src/main/java/com/ericsson/eiffel/remrem/generate/cli/CLIOptions.java index 9a4fffe3..27ccae96 100644 --- a/cli/src/main/java/com/ericsson/eiffel/remrem/generate/cli/CLIOptions.java +++ b/cli/src/main/java/com/ericsson/eiffel/remrem/generate/cli/CLIOptions.java @@ -71,7 +71,10 @@ public static Options createCLIOptions() { options.addOption("r", "response_file", true, "file to store the response in, optional"); options.addOption("d", "debug", false, "enable debug traces"); options.addOption("mp", "messaging_protocol", true, - "name of messaging protocol to be used, e.g. eiffel3, eiffelsemantics"); + "name of messaging protocol to be used, e.g. eiffelsemantics"); + options.addOption("lv", "lenientValidation", true, + "lenientValidation will perform the only mandatory field validation and non-mandatory validation failures will place in Eiffel message as a new property(remremGenerateFailures)" + + ""); contentGroup = new OptionGroup(); contentGroup.addOption(new Option("f", "content_file", true, "message content file")); contentGroup.addOption(new Option("json", "json_content", true, "json content")); diff --git a/cli/src/test/java/com/ericsson/eiffel/remrem/generate/cli/CliOptionsUnitTests.java b/cli/src/test/java/com/ericsson/eiffel/remrem/generate/cli/CliOptionsUnitTests.java index 79a7dc92..51fb9cc6 100644 --- a/cli/src/test/java/com/ericsson/eiffel/remrem/generate/cli/CliOptionsUnitTests.java +++ b/cli/src/test/java/com/ericsson/eiffel/remrem/generate/cli/CliOptionsUnitTests.java @@ -94,4 +94,11 @@ public void testRequiredOptionsGiven() throws Exception { assertTrue(CLIOptions.getErrorCodes().isEmpty()); } + @Test + public void testlenientValidationGiven() throws Exception { + String[] args = {"-f", "input_file", "-t", "artifactpublished", "-lv", "true"}; + CLIOptions.parse(args); + assertTrue(CLIOptions.getErrorCodes().isEmpty()); + } + } \ No newline at end of file diff --git a/cli/src/test/java/com/ericsson/eiffel/remrem/generate/cli/CliUnitTests.java b/cli/src/test/java/com/ericsson/eiffel/remrem/generate/cli/CliUnitTests.java index 14253de6..8909481e 100644 --- a/cli/src/test/java/com/ericsson/eiffel/remrem/generate/cli/CliUnitTests.java +++ b/cli/src/test/java/com/ericsson/eiffel/remrem/generate/cli/CliUnitTests.java @@ -116,4 +116,17 @@ public void testHandleMsgTypeEventArgsPass() throws Exception { assertTrue(CLIOptions.getErrorCodes().isEmpty()); } + @Test + public void testHandlelenientValidationArgsPass() throws Exception { + URL url = getClass().getClassLoader().getResource("jsonTest.json"); + String path = url.getPath().replace("%20"," "); + File file = new File(path); + String filePath = file.getAbsolutePath(); + + String[] args = {"-t", "eiffelactivityfinished", "-f", filePath, "-lv" , "true"}; + CLIOptions.parse(args); + cli.run(args); + assertTrue(CLIOptions.getErrorCodes().isEmpty()); + } + } \ No newline at end of file diff --git a/pom.xml b/pom.xml index 9ae5d2a5..8ca1d98e 100644 --- a/pom.xml +++ b/pom.xml @@ -10,9 +10,9 @@ - 2.0.17 + 2.0.18 2.0.4 - 2.0.13 + 2.0.14 eiffel-remrem-generate ${eiffel-remrem-generate.version} diff --git a/service/src/main/java/com/ericsson/eiffel/remrem/generate/constants/RemremGenerateServiceConstants.java b/service/src/main/java/com/ericsson/eiffel/remrem/generate/constants/RemremGenerateServiceConstants.java index c09bc7f7..7223d5fd 100644 --- a/service/src/main/java/com/ericsson/eiffel/remrem/generate/constants/RemremGenerateServiceConstants.java +++ b/service/src/main/java/com/ericsson/eiffel/remrem/generate/constants/RemremGenerateServiceConstants.java @@ -45,4 +45,6 @@ public final class RemremGenerateServiceConstants { public static final String LOOKUP_IN_EXTERNAL_ERS = "Determines if external ER's should be used to compile the results of query." + "Use true to use External ER's."; + public static final String LenientValidation = "Lenient Validation true will perform the validation only on mandatory fields, non-mandatory validation failures add into eiffel message as property remremGenerateFailures"; + } diff --git a/service/src/main/java/com/ericsson/eiffel/remrem/generate/controller/RemremGenerateController.java b/service/src/main/java/com/ericsson/eiffel/remrem/generate/controller/RemremGenerateController.java index 91ce04ad..a1e3c692 100644 --- a/service/src/main/java/com/ericsson/eiffel/remrem/generate/controller/RemremGenerateController.java +++ b/service/src/main/java/com/ericsson/eiffel/remrem/generate/controller/RemremGenerateController.java @@ -101,6 +101,7 @@ public ResponseEntity generate( @ApiParam(value = "ER lookup result none found, Generate will fail") @RequestParam(value = "failIfNoneFound", required = false, defaultValue = "false") final Boolean failIfNoneFound, @ApiParam(value = RemremGenerateServiceConstants.LOOKUP_IN_EXTERNAL_ERS) @RequestParam(value = "lookupInExternalERs", required = false, defaultValue = "false") final Boolean lookupInExternalERs, @ApiParam(value = RemremGenerateServiceConstants.LOOKUP_LIMIT) @RequestParam(value = "lookupLimit", required = false, defaultValue = "1") final int lookupLimit, + @ApiParam(value = RemremGenerateServiceConstants.LenientValidation) @RequestParam(value = "lenientValidation", required = false, defaultValue = "false") final Boolean lenientValidation, @ApiParam(value = "JSON message", required = true) @RequestBody JsonObject bodyJson) { try { @@ -108,7 +109,7 @@ public ResponseEntity generate( MsgService msgService = getMessageService(msgProtocol); String response; if (msgService != null) { - response = msgService.generateMsg(msgType, bodyJson); + response = msgService.generateMsg(msgType, bodyJson, lenientValidation); JsonElement parsedResponse = parser.parse(response); if (!parsedResponse.getAsJsonObject().has(RemremGenerateServiceConstants.JSON_ERROR_MESSAGE_FIELD)) { return new ResponseEntity<>(parsedResponse, HttpStatus.OK); diff --git a/service/src/test/java/com/ericsson/eiffel/remrem/generate/service/EiffelRemERLookupControllerUnitTest.java b/service/src/test/java/com/ericsson/eiffel/remrem/generate/service/EiffelRemERLookupControllerUnitTest.java index 56acbaaf..081929e2 100644 --- a/service/src/test/java/com/ericsson/eiffel/remrem/generate/service/EiffelRemERLookupControllerUnitTest.java +++ b/service/src/test/java/com/ericsson/eiffel/remrem/generate/service/EiffelRemERLookupControllerUnitTest.java @@ -142,37 +142,37 @@ public void setUp() throws Exception { String erlookupOptionsWithNoneFoundOutput = FileUtils .readFileToString(new File(TEST_RESOURCES_PATH+"ErlookupOptionsWithNoneFoundOutput.json"), ENCODING); - Mockito.when(service.generateMsg(Mockito.eq("eiffelConfidenceLevelModified"), Mockito.anyObject())) + Mockito.when(service.generateMsg(Mockito.eq("eiffelConfidenceLevelModified"), Mockito.anyObject(), Mockito.anyBoolean())) .thenReturn(erlookupOptionsWithNoneFoundOutput); - Mockito.when(service.generateMsg(Mockito.eq("eiffelconfidencelevel"), Mockito.anyObject())) + Mockito.when(service.generateMsg(Mockito.eq("eiffelconfidencelevel"), Mockito.anyObject(), Mockito.anyBoolean())) .thenReturn(confidenceLevelOutput); - Mockito.when(service.generateMsg(Mockito.eq("eiffelartifactpublished"), Mockito.anyObject())) + Mockito.when(service.generateMsg(Mockito.eq("eiffelartifactpublished"), Mockito.anyObject(), Mockito.anyBoolean())) .thenReturn(artifactPublishedOutput); - Mockito.when(service.generateMsg(Mockito.eq("eiffelcompositiondefined"), Mockito.anyObject())) + Mockito.when(service.generateMsg(Mockito.eq("eiffelcompositiondefined"), Mockito.anyObject(), Mockito.anyBoolean())) .thenReturn(compositionDefinedOutput); - Mockito.when(service.generateMsg(Mockito.eq("eiffelCompositionDefined"), Mockito.anyObject())) + Mockito.when(service.generateMsg(Mockito.eq("eiffelCompositionDefined"), Mockito.anyObject(), Mockito.anyBoolean())) .thenReturn(compositionDefinedSCCreatedOutput); - Mockito.when(service.generateMsg(Mockito.eq("eiffelCompositionDefinedEvent"), Mockito.anyObject())) + Mockito.when(service.generateMsg(Mockito.eq("eiffelCompositionDefinedEvent"), Mockito.anyObject(), Mockito.anyBoolean())) .thenReturn(compositionDefinedSCSubmittedOutput); - Mockito.when(service.generateMsg(Mockito.eq("eiffelSCSubmitted"), Mockito.anyObject())) + Mockito.when(service.generateMsg(Mockito.eq("eiffelSCSubmitted"), Mockito.anyObject(), Mockito.anyBoolean())) .thenReturn(SCSubmittedOutput); - Mockito.when(service.generateMsg(Mockito.eq("eiffelEnvironmentDefined"), Mockito.anyObject())) + Mockito.when(service.generateMsg(Mockito.eq("eiffelEnvironmentDefined"), Mockito.anyObject(), Mockito.anyBoolean())) .thenReturn(erLookupWithOptionsOutput); - Mockito.when(service.generateMsg(Mockito.eq("eiffelEnvironmentDefinedEvent"), Mockito.anyObject())) + Mockito.when(service.generateMsg(Mockito.eq("eiffelEnvironmentDefinedEvent"), Mockito.anyObject(), Mockito.anyBoolean())) .thenReturn(erlookupOptionsWithEmptyResponseOutput); - Mockito.when(service.generateMsg(Mockito.eq("eiffelCompositionDefinedEventt"), Mockito.anyObject())) + Mockito.when(service.generateMsg(Mockito.eq("eiffelCompositionDefinedEventt"), Mockito.anyObject(), Mockito.anyBoolean())) .thenReturn(compositionDefinedOutput); - Mockito.when(service.generateMsg(Mockito.eq("eiffelTestCaseStarted"), Mockito.anyObject())) + Mockito.when(service.generateMsg(Mockito.eq("eiffelTestCaseStarted"), Mockito.anyObject(), Mockito.anyBoolean())) .thenReturn(ErlookupFailedWithOptionsOutput); ResponseEntity erresponse = new ResponseEntity(response, HttpStatus.OK); @@ -222,7 +222,7 @@ public void testErlookupSuccesswithMultipleIds() throws Exception { JsonParser parser = new JsonParser(); JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject(); - ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelconfidencelevel", false, false, true, 1, json); + ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelconfidencelevel", false, false, true, 1, false, json); assertEquals(elem.getStatusCode(), HttpStatus.OK); } @@ -233,7 +233,7 @@ public void testErlookupMultipleFound() throws Exception { JsonParser parser = new JsonParser(); JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject(); - ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelcompositiondefined", true, false, true, 1, json); + ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelcompositiondefined", true, false, true, 1, false, json); assertEquals(elem.getStatusCode(), HttpStatus.EXPECTATION_FAILED); } @@ -243,7 +243,7 @@ public void testErlookupMultipleTraces() throws Exception { JsonParser parser = new JsonParser(); JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject(); - ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelartifactpublished", false, true, true, 1, json); + ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelartifactpublished", false, true, true, 1, false, json); assertEquals(elem.getStatusCode(), HttpStatus.BAD_REQUEST); } @@ -253,7 +253,7 @@ public void testErlookupSuccesswithOneId() throws Exception { JsonParser parser = new JsonParser(); JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject(); - ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelCompositionDefined", true, true, true, 1, json); + ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelCompositionDefined", true, true, true, 1, false, json); assertEquals(elem.getStatusCode(), HttpStatus.OK); } @@ -263,7 +263,7 @@ public void testErlookupNoneFound() throws Exception { JsonParser parser = new JsonParser(); JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject(); - ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelCompositionDefinedEvent", true, true, true, 1, json); + ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelCompositionDefinedEvent", true, true, true, 1, false, json); assertEquals(elem.getStatusCode(), HttpStatus.NOT_ACCEPTABLE); } @@ -273,7 +273,7 @@ public void testErlookupMultipleTrace() throws Exception { JsonParser parser = new JsonParser(); JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject(); - ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelSCSubmitted", false, true, true, 1, json); + ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelSCSubmitted", false, true, true, 1, false, json); assertEquals(elem.getStatusCode(), HttpStatus.BAD_REQUEST); } @@ -283,7 +283,7 @@ public void testErlookupOptions() throws Exception { JsonParser parser = new JsonParser(); JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject(); - ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelEnvironmentDefined", false, false, true, 2, json); + ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelEnvironmentDefined", false, false, true, 2, false, json); assertEquals(elem.getStatusCode(), HttpStatus.OK); } @@ -293,7 +293,7 @@ public void testErlookupOptionsWithEmptyResponse() throws Exception { JsonParser parser = new JsonParser(); JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject(); - ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelEnvironmentDefinedEvent", true, true, true, 2, json); + ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelEnvironmentDefinedEvent", true, true, true, 2, false, json); assertEquals(elem.getStatusCode(), HttpStatus.OK); } @@ -303,7 +303,7 @@ public void testErlookupOptionsWithMultipleFound() throws Exception { JsonParser parser = new JsonParser(); JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject(); - ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelCompositionDefinedEventt", false, false, true, 2, json); + ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelCompositionDefinedEventt", false, false, true, 2, false, json); assertEquals(elem.getStatusCode(), HttpStatus.EXPECTATION_FAILED); } @@ -313,7 +313,7 @@ public void testErlookupOptionsWithNoneFound() throws Exception { JsonParser parser = new JsonParser(); JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject(); - ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelConfidenceLevelModified", false, false, true, 2, json); + ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelConfidenceLevelModified", false, false, true, 2, false, json); assertEquals(elem.getStatusCode(), HttpStatus.NOT_ACCEPTABLE); } @@ -323,7 +323,7 @@ public void testErlookupFailedWithOptions() throws Exception { JsonParser parser = new JsonParser(); JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject(); - ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelTestCaseStarted", false, false, true, 2, json); + ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelTestCaseStarted", false, false, true, 2, false, json); assertEquals(elem.getStatusCode(), HttpStatus.UNPROCESSABLE_ENTITY); } } \ No newline at end of file diff --git a/service/src/test/java/com/ericsson/eiffel/remrem/generate/service/EiffelRemremControllerUnitTest.java b/service/src/test/java/com/ericsson/eiffel/remrem/generate/service/EiffelRemremControllerUnitTest.java index 42b7550e..ffcf9bce 100644 --- a/service/src/test/java/com/ericsson/eiffel/remrem/generate/service/EiffelRemremControllerUnitTest.java +++ b/service/src/test/java/com/ericsson/eiffel/remrem/generate/service/EiffelRemremControllerUnitTest.java @@ -81,53 +81,68 @@ public void setUp() throws Exception { inputFilePath = jsonInputURL.getPath().replace("%20"," "); jsonFile = new File(inputFilePath); String errorOutput = new BufferedReader(new FileReader(jsonFile)).readLine(); + + URL lv_jsonInputURL = getClass().getClassLoader().getResource("lv_successInput.json"); + String lv_inputFilePath = lv_jsonInputURL.getPath().replace("%20"," "); + File lv_jsonFile = new File(lv_inputFilePath); + String lv_successOutput = new BufferedReader(new FileReader(lv_jsonFile)).readLine(); Mockito.when(service.generateMsg( Mockito.eq("eiffelactivityfinished"), - Mockito.anyObject())).thenReturn(successOutput); + Mockito.anyObject(), Mockito.anyBoolean())).thenReturn(successOutput); Mockito.when(service.generateMsg( Mockito.eq("EiffelActivityFinished"), - Mockito.anyObject())).thenReturn(errorOutput); + Mockito.anyObject(), Mockito.anyBoolean())).thenReturn(errorOutput); Mockito.when(service2.generateMsg( Mockito.eq("eiffelartifactnew"), - Mockito.anyObject())).thenReturn(successOutput); + Mockito.anyObject(), Mockito.anyBoolean())).thenReturn(successOutput); Mockito.when(service2.generateMsg( Mockito.eq("eiffelartifactnewevent"), - Mockito.anyObject())).thenReturn(errorOutput); + Mockito.anyObject(), Mockito.anyBoolean())).thenReturn(errorOutput); + + Mockito.when(service.generateMsg( + Mockito.eq("EiffelArtifactCreatedEvent"), + Mockito.anyObject(), Mockito.anyBoolean())).thenReturn(lv_successOutput); } @Test public void testSemanticsSuccessEvent() throws Exception { - ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelactivityfinished", false, false, true, 1, body.getAsJsonObject()); + ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelactivityfinished", false, false, true, 1, false, body.getAsJsonObject()); assertEquals(elem.getStatusCode(), HttpStatus.OK); } @Test public void testSemanticsFailureEvent() throws Exception { - ResponseEntity elem = unit.generate("eiffelsemantics", "EiffelActivityFinished", false, false, true, 1, body.getAsJsonObject()); + ResponseEntity elem = unit.generate("eiffelsemantics", "EiffelActivityFinished", false, false, true, 1, false, body.getAsJsonObject()); assertEquals(elem.getStatusCode(), HttpStatus.BAD_REQUEST); } @Test public void testEiffel3SuccessEvent() throws Exception { - ResponseEntity elem = unit.generate("eiffel3", "eiffelartifactnew", false, false, true, 1, body.getAsJsonObject()); + ResponseEntity elem = unit.generate("eiffel3", "eiffelartifactnew", false, false, true, 1, false, body.getAsJsonObject()); assertEquals(elem.getStatusCode(), HttpStatus.OK); } @Test public void testEiffel3FailureEvent() throws Exception { - ResponseEntity elem = unit.generate("eiffel3", "eiffelartifactnewevent", false, false, true, 1, body.getAsJsonObject()); + ResponseEntity elem = unit.generate("eiffel3", "eiffelartifactnewevent", false, false, true, 1, false, body.getAsJsonObject()); assertEquals(elem.getStatusCode(), HttpStatus.BAD_REQUEST); } @Test public void testMessageServiceUnavailableEvent() throws Exception { - ResponseEntity elem = unit.generate("other", "EiffelActivityFinishedEvent", false, false, true, 1, body.getAsJsonObject()); + ResponseEntity elem = unit.generate("other", "EiffelActivityFinishedEvent", false, false, true, 1, false, body.getAsJsonObject()); assertEquals(elem.getStatusCode(), HttpStatus.SERVICE_UNAVAILABLE); } + + @Test + public void testlenientValidation() throws Exception { + ResponseEntity elem = unit.generate("eiffelsemantics", "EiffelArtifactCreatedEvent", false, false, true, 1, true, body.getAsJsonObject()); + assertEquals(elem.getStatusCode(), HttpStatus.OK); + } } diff --git a/service/src/test/resources/lv_successInput.json b/service/src/test/resources/lv_successInput.json new file mode 100644 index 00000000..6ee8acb9 --- /dev/null +++ b/service/src/test/resources/lv_successInput.json @@ -0,0 +1 @@ +{"meta":{"id":"800ce624-e640-4ca7-a23e-173b9da8b446","type":"EiffelArtifactCreatedEvent","version":"3.0.0","time":1594978923338,"tags":["123","tag2"],"source":{"domainId":"domainID","host":"host","name":"name","serializer":"pkg:maven","uri":"http:\/\/java.sun.com\/j2se\/1.3\/"},"security":{"authorIdentity":"test","sequenceProtection":[]}},"data":{"identity":"pkg:abc","fileInformation":[{"name":"name","tags":[]}],"buildCommand":"trigger","requiresImplementation":"NONE","dependsOn":[],"implements":[],"name":"event","customData":[{"key":"firstLog","value":"http:\/\/myHost.com\/firstLog"},{"key":"otherLog","value":"http:\/\/myHost.com\/firstLog33"},{"remremGenerateFailures":[{"type":"pattern","message":"ECMA 262 regex \"^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$\" does not match input string \"aaaaaaaa\"","path":"\/links\/2\/target"}]}]},"links":[{"type":"CAUSE","target":"aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee1"},{"type":"PREVIOUS_VERSION","target":"aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee2"},{"type":"ENVIRONMENT","target":"aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee3"}]} \ No newline at end of file From 6c70260567ed9fe14bc77d77543d624493d789f4 Mon Sep 17 00:00:00 2001 From: erjamni Date: Mon, 20 Jul 2020 12:25:53 +0200 Subject: [PATCH 02/11] version uplifted(Minor version uplift). --- CHANGELOG.md | 3 +++ pom.xml | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1860cd99..f6128238 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2.1.0 +- Updated REMReM Generate to support lenient validation for Eiffel Protocol. + ## 2.0.17 - Fixed failed testcase in EiffelRemERLookupControllerUnitTest class. diff --git a/pom.xml b/pom.xml index 8ca1d98e..e7b5c7a0 100644 --- a/pom.xml +++ b/pom.xml @@ -10,9 +10,9 @@ - 2.0.18 + 2.1.0 2.0.4 - 2.0.14 + 2.1.0 eiffel-remrem-generate ${eiffel-remrem-generate.version} From 78d6a8dd00d4ebab8d23970665441aa4da4700f6 Mon Sep 17 00:00:00 2001 From: erjamni Date: Tue, 21 Jul 2020 13:19:02 +0200 Subject: [PATCH 03/11] CLI issue resolved. --- .../main/java/com/ericsson/eiffel/remrem/generate/cli/CLI.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/src/main/java/com/ericsson/eiffel/remrem/generate/cli/CLI.java b/cli/src/main/java/com/ericsson/eiffel/remrem/generate/cli/CLI.java index 27a9f3b6..f19aa87b 100644 --- a/cli/src/main/java/com/ericsson/eiffel/remrem/generate/cli/CLI.java +++ b/cli/src/main/java/com/ericsson/eiffel/remrem/generate/cli/CLI.java @@ -175,7 +175,7 @@ private void handleJsonString(String jsonString, CommandLine commandLine) { JsonParser parser = new JsonParser(); JsonObject jsonContent = parser.parse(jsonString).getAsJsonObject(); MsgService msgService = getMessageService(commandLine); - Boolean lv = commandLine.hasOption("lv")? Boolean.getBoolean(commandLine.getOptionValue("lv")) : false; + Boolean lv = commandLine.hasOption("lv")? Boolean.parseBoolean(commandLine.getOptionValue("lv")) : false; String returnJsonStr = msgService.generateMsg(msgType, jsonContent, lv); returnJsonStr = "[" + returnJsonStr + "]"; if (responseFilePath != null) { From 75ff2cadee1b0bd5348c3e10c77999494aadc3b3 Mon Sep 17 00:00:00 2001 From: erjamni Date: Wed, 22 Jul 2020 10:52:34 +0200 Subject: [PATCH 04/11] documentation added --- wiki/markdown/usage/generate-cli.md | 14 ++ wiki/markdown/usage/lenientvalidation.md | 199 +++++++++++++++++++++++ wiki/markdown/usage/service.md | 4 +- 3 files changed, 216 insertions(+), 1 deletion(-) create mode 100644 wiki/markdown/usage/lenientvalidation.md diff --git a/wiki/markdown/usage/generate-cli.md b/wiki/markdown/usage/generate-cli.md index eb37fcbe..f38720f2 100644 --- a/wiki/markdown/usage/generate-cli.md +++ b/wiki/markdown/usage/generate-cli.md @@ -20,6 +20,8 @@ usage: java -jar -mp,--messaging_protocol name of messaging protocol to be used, e.g. eiffelsemantics + -lv,--lenientValidation lenientValidation will perform the only mandatory field validation and non-mandatory validation failures will place in Eiffel message as a new property(remremGenerateFailures) + -r,--response_file file to store the response in, optional -t,--message_type message type, mandatory if -f or -json is given @@ -96,6 +98,18 @@ $ java -jar generate-cli.jar -f eiffelactivityfinished.json -t eiffelactivityfin $ java -jar generate-cli.jar -t eiffelactivityfinished -json {"msgParams":{"meta":{"type":"EiffelActivityFinishedEvent","tags":["tag1","tag2"],"source":{"domainId":"example.domain","host":"host","name":"name","uri":"http://java.sun.com/j2se/1.3/","serializer":"pkg:maven/com.github.eiffel-community/eiffel-remrem-semantics@2.0.0"},"security":{"sdm":{"authorIdentity":"test","encryptedDigest":"sample"}}}},"eventParams":{"data":{"outcome":{"conclusion":"SUCCESSFUL"},"persistentLogs":[{"name":"firstLog","uri":"http://myHost.com/firstLog"},{"name":"otherLog","uri":"isbn:0-486-27557-4"}]},"links":[{"type":"ACTIVITY_EXECUTION","target":"aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee1"}]}} ``` +##### Lenient Validation example: + +#### Input +``` +$ java -jar generate-cli.jar -t EiffelArtifactCreatedEvent -lv true -json "{'msgParams':{'meta':{'type':'EiffelArtifactCreatedEvent','version':'3.0.0','tags':[123,'tag2'],'source':{'domainId':'domainID','host':'host','name':'name','uri':'http:\/\/java.sun.com\/j2se\/1.3\/','serializer':'pkg:maven'},'security':{'authorIdentity':'test','encryptedDigest':'sample'}}},'eventParams':{'data':{'gav':{'groupId':'G','artifactId':'A','version':'V'},'fileInformation':[{'name':'name'}],'buildCommand':'trigger','requiresImplementation':'NONE','name':'event','dependsOn':[],'implement':[],'identity':'pkg:abc','customData':[{'key':'firstLog','value':'http:\/\/myHost.com\/firstLog'},{'key':'otherLog','value':'http:\/\/myHost.com\/firstLog33'}]},'links':[{'type':'CAUSE','target':'aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee1'},{'type':'PREVIOUS_VERSION','target':'aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee2'},{'type':'COMPOSITION','target':'aaaaaaaa'},{'type':'ENVIRONMENT','target':'aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee3'}]}}" +``` +#### Output + +``` +[{"meta":{"id":"8afff3b8-96b3-405c-85a5-366bc5f59cc6","type":"EiffelArtifactCreatedEvent","version":"3.0.0","time":1595395508961,"tags":["123","tag2"],"source":{"domainId":"domainID","host":"host","name":"name","serializer":"pkg:maven","uri":"http://java.sun.com/j2se/1.3/"},"security":{"authorIdentity":"test","sequenceProtection":[]}},"data":{"identity":"pkg:abc","fileInformation":[{"name":"name","tags":[]}],"buildCommand":"trigger","requiresImplementation":"NONE","dependsOn":[],"implements":[],"name":"event","customData":[{"key":"firstLog","value":"http://myHost.com/firstLog"},{"key":"otherLog","value":"http://myHost.com/firstLog33"},{"remremGenerateFailures":[{"type":"pattern","message":"ECMA 262 regex \"^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$\" does not match input string \"aaaaaaaa\"","path":"/links/2/target"}]}]},"links":[{"type":"CAUSE","target":"aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee1"},{"type":"PREVIOUS_VERSION","target":"aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee2"},{"type":"ENVIRONMENT","target":"aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee3"}]}] +``` + ##### For loading protocol jars other than _eiffelsemantics_: ``` diff --git a/wiki/markdown/usage/lenientvalidation.md b/wiki/markdown/usage/lenientvalidation.md new file mode 100644 index 00000000..513f7dc4 --- /dev/null +++ b/wiki/markdown/usage/lenientvalidation.md @@ -0,0 +1,199 @@ +## Lenient Validation +The Lenient validation introduced in REMReM Generate science the version 2.1.0 + +Using the lenient validation user continue the Eiffel generate with non-fatal fields in the message. +This validation fexibility is applicable on only Eiffel message optional fields. see + [Eiffel REMReM semantics](https://github.com/eiffel-community/eiffel/tree/master/schemas) +for more about mandatory and optional fields. + +The Lenient validation will perform the only mandatory field validation and non-mandatory validation failures will place in Eiffel message as a new property(remremGenerateFailures) + +The lenientValidation is optional parameter to CLI and service and possible inputs are true and false. The default lenientValidation is false. + +#### Example 1: lenientValidation = true and Input invalid optional field (links.type.COMPOSITION) +``` +{ + "msgParams":{ + "meta":{ + "type":"EiffelArtifactCreatedEvent", + "version":"3.0.0", + "tags":[ + 123, + "tag2" + ], + "source":{ + "domainId":"domainID", + "host":"host", + "name":"name", + "uri":"http://java.sun.com/j2se/1.3/", + "serializer":"pkg:maven" + }, + "security":{ + "authorIdentity":"test", + "encryptedDigest":"sample" + } + } + }, + "eventParams":{ + "data":{ + "gav":{ + "groupId":"G", + "artifactId":"A", + "version":"V" + }, + "fileInformation":[ + { + "name":"name" + } + ], + "buildCommand":"trigger", + "requiresImplementation":"NONE", + "name":"event", + "dependsOn":[ + + ], + "implement":[ + + ], + "identity":"pkg:abc", + "customData":[ + { + "key":"firstLog", + "value":"http://myHost.com/firstLog" + }, + { + "key":"otherLog", + "value":"http://myHost.com/firstLog33" + } + ] + }, + "links":[ + { + "type":"CAUSE", + "target":"aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee1" + }, + { + "type":"PREVIOUS_VERSION", + "target":"aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee2" + }, + { + "type":"COMPOSITION", + "target":"aaaaaaaa" + }, + { + "type":"ENVIRONMENT", + "target":"aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee3" + } + ] + } +} +``` + +#### Output + +``` +[ + { + "meta":{ + "id":"8afff3b8-96b3-405c-85a5-366bc5f59cc6", + "type":"EiffelArtifactCreatedEvent", + "version":"3.0.0", + "time":1595395508961, + "tags":[ + "123", + "tag2" + ], + "source":{ + "domainId":"domainID", + "host":"host", + "name":"name", + "serializer":"pkg:maven", + "uri":"http://java.sun.com/j2se/1.3/" + }, + "security":{ + "authorIdentity":"test", + "sequenceProtection":[ + + ] + } + }, + "data":{ + "identity":"pkg:abc", + "fileInformation":[ + { + "name":"name", + "tags":[ + + ] + } + ], + "buildCommand":"trigger", + "requiresImplementation":"NONE", + "dependsOn":[ + + ], + "implements":[ + + ], + "name":"event", + "customData":[ + { + "key":"firstLog", + "value":"http://myHost.com/firstLog" + }, + { + "key":"otherLog", + "value":"http://myHost.com/firstLog33" + }, + { + "remremGenerateFailures":[ + { + "type":"pattern", + "message":"ECMA 262 regex \"^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$\" does not match input string \"aaaaaaaa\"", + "path":"/links/2/target" + } + ] + } + ] + }, + "links":[ + { + "type":"CAUSE", + "target":"aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee1" + }, + { + "type":"PREVIOUS_VERSION", + "target":"aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee2" + }, + { + "type":"ENVIRONMENT", + "target":"aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee3" + } + ] + } +] +``` + +The lenient validation created new message property with "remremGenerateFailures" +``` +"remremGenerateFailures":[ + { + "type":"pattern", + "message":"ECMA 262 regex \"^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$\" does not match input string \"aaaaaaaa\"", + "path":"/links/2/target" + } + ] +``` + +#### Example 2: lenientValidation = true and Input invalid optional field (links.type.COMPOSITION) +Input same as example1 + +##### output +``` +[ + { + "message":"Cannot validate given JSON string", + "cause":"com.ericsson.eiffel.remrem.semantics.validator.EiffelValidationException: [ECMA 262 regex \"^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$\" does not match input string \"aaaaaaaa\"]" + } +] +``` diff --git a/wiki/markdown/usage/service.md b/wiki/markdown/usage/service.md index 1541ba9c..cab5176e 100644 --- a/wiki/markdown/usage/service.md +++ b/wiki/markdown/usage/service.md @@ -29,7 +29,7 @@ Available REST resources for REMReM Generate Service are described below: | Resource | Method | Parameters | Request body | Description | |-----------------------|--------|---------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| /mp | POST | mp - message protocol, required msgType - Eiffel event type, required failIfMultipleFound - default: false failIfNoneFound - default: false, lookupInExternalERs - default: false, lookupLimit - default: 1| { "msgParams": {"meta": {# Matches the meta object }},"eventParams": {"data": {# Matches the data object},"links": { # Matches the links object } }} | This endpoint is used to generate Eiffel events and then the obtained event could be published by [Eiffel REMReM Publish](https://github.com/eiffel-community/eiffel-remrem-publish). | +| /mp | POST | mp - message protocol, required msgType - Eiffel event type, required failIfMultipleFound - default: false failIfNoneFound - default: false, lookupInExternalERs - default: false, lenientValidation - default: false, lookupLimit - default: 1| { "msgParams": {"meta": {# Matches the meta object }},"eventParams": {"data": {# Matches the data object},"links": { # Matches the links object } }} | This endpoint is used to generate Eiffel events and then the obtained event could be published by [Eiffel REMReM Publish](https://github.com/eiffel-community/eiffel-remrem-publish). | | /event_types/{mp} | GET | mp - message protocol, required | | This endpoint is used to obtain Eiffel event types implemented in [Eiffel REMReM Semantics](https://github.com/eiffel-community/eiffel-remrem-semantics). | | /template/{type}/{mp} | GET | type - Eiffel event type mp - message protocol, required | | This endpoint is used to obtain Eiffel event templates implemented in [Eiffel REMReM Semantics](https://github.com/eiffel-community/eiffel-remrem-semantics). | | /versions | GET | | | This endpoint is used to get versions of generate service and all loaded protocols versions in JSON format. | @@ -300,3 +300,5 @@ If the failIfNoneFound and failIfMultipleFound are available in lookup then it w } ] ``` +### Lenient Validation: +[Lenient Validation](../usage/lenientValidation.md). From 509510486c00c7c1d607af13da66fb6e38928381 Mon Sep 17 00:00:00 2001 From: erjamni Date: Wed, 22 Jul 2020 10:57:53 +0200 Subject: [PATCH 05/11] documentation added --- wiki/markdown/usage/lenientvalidation.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wiki/markdown/usage/lenientvalidation.md b/wiki/markdown/usage/lenientvalidation.md index 513f7dc4..66e73beb 100644 --- a/wiki/markdown/usage/lenientvalidation.md +++ b/wiki/markdown/usage/lenientvalidation.md @@ -1,14 +1,14 @@ ## Lenient Validation -The Lenient validation introduced in REMReM Generate science the version 2.1.0 +The Lenient validation introduced in REMReM Generate since the version 2.1.0 Using the lenient validation user continue the Eiffel generate with non-fatal fields in the message. -This validation fexibility is applicable on only Eiffel message optional fields. see +This validation flexibility applies to only Eiffel's message optional fields. see [Eiffel REMReM semantics](https://github.com/eiffel-community/eiffel/tree/master/schemas) for more about mandatory and optional fields. The Lenient validation will perform the only mandatory field validation and non-mandatory validation failures will place in Eiffel message as a new property(remremGenerateFailures) -The lenientValidation is optional parameter to CLI and service and possible inputs are true and false. The default lenientValidation is false. +The lenientValidation is an optional parameter to CLI and service and possible inputs are true and false. The default lenientValidation is false. #### Example 1: lenientValidation = true and Input invalid optional field (links.type.COMPOSITION) ``` From ee3c1fa222f7f48e00371693a3ddc15b22180da6 Mon Sep 17 00:00:00 2001 From: erjamni Date: Thu, 6 Aug 2020 08:26:10 +0200 Subject: [PATCH 06/11] Changed Lenient validation control REST option to configurable option --- .../eiffel/remrem/generate/cli/CLI.java | 4 +- .../remrem/generate/cli/CLIOptions.java | 4 +- .../cli/SpringLoggingInitializer.java | 32 +++++------ .../generate/cli/CliOptionsUnitTests.java | 4 +- .../remrem/generate/cli/CliUnitTests.java | 4 +- .../RemremGenerateServiceConstants.java | 3 -- .../controller/RemremGenerateController.java | 16 ++++-- .../src/main/resources/application.properties | 5 +- .../main/resources/config.template.properties | 5 +- .../EiffelRemERLookupControllerUnitTest.java | 23 ++++---- .../EiffelRemremControllerUnitTest.java | 54 +++++++++---------- wiki/markdown/usage/configuration.md | 9 +++- wiki/markdown/usage/generate-cli.md | 8 +-- wiki/markdown/usage/lenientvalidation.md | 22 +++++--- 14 files changed, 113 insertions(+), 80 deletions(-) diff --git a/cli/src/main/java/com/ericsson/eiffel/remrem/generate/cli/CLI.java b/cli/src/main/java/com/ericsson/eiffel/remrem/generate/cli/CLI.java index f19aa87b..e9fbe04c 100644 --- a/cli/src/main/java/com/ericsson/eiffel/remrem/generate/cli/CLI.java +++ b/cli/src/main/java/com/ericsson/eiffel/remrem/generate/cli/CLI.java @@ -175,8 +175,8 @@ private void handleJsonString(String jsonString, CommandLine commandLine) { JsonParser parser = new JsonParser(); JsonObject jsonContent = parser.parse(jsonString).getAsJsonObject(); MsgService msgService = getMessageService(commandLine); - Boolean lv = commandLine.hasOption("lv")? Boolean.parseBoolean(commandLine.getOptionValue("lv")) : false; - String returnJsonStr = msgService.generateMsg(msgType, jsonContent, lv); + Boolean iov = commandLine.hasOption("iov")? Boolean.parseBoolean(commandLine.getOptionValue("iov")) : false; + String returnJsonStr = msgService.generateMsg(msgType, jsonContent, iov); returnJsonStr = "[" + returnJsonStr + "]"; if (responseFilePath != null) { try (PrintWriter out = new PrintWriter(responseFilePath)) { diff --git a/cli/src/main/java/com/ericsson/eiffel/remrem/generate/cli/CLIOptions.java b/cli/src/main/java/com/ericsson/eiffel/remrem/generate/cli/CLIOptions.java index 27ccae96..3487dfe9 100644 --- a/cli/src/main/java/com/ericsson/eiffel/remrem/generate/cli/CLIOptions.java +++ b/cli/src/main/java/com/ericsson/eiffel/remrem/generate/cli/CLIOptions.java @@ -72,8 +72,8 @@ public static Options createCLIOptions() { options.addOption("d", "debug", false, "enable debug traces"); options.addOption("mp", "messaging_protocol", true, "name of messaging protocol to be used, e.g. eiffelsemantics"); - options.addOption("lv", "lenientValidation", true, - "lenientValidation will perform the only mandatory field validation and non-mandatory validation failures will place in Eiffel message as a new property(remremGenerateFailures)" + + options.addOption("iov", "ignoreOptionalFieldValidationErrors", true, + "ignoreOptionalFieldValidationErrors will perform the only mandatory field validation and non-mandatory validation failures will place in Eiffel message as a new property(remremGenerateFailures)" + ""); contentGroup = new OptionGroup(); contentGroup.addOption(new Option("f", "content_file", true, "message content file")); diff --git a/cli/src/main/java/com/ericsson/eiffel/remrem/generate/cli/SpringLoggingInitializer.java b/cli/src/main/java/com/ericsson/eiffel/remrem/generate/cli/SpringLoggingInitializer.java index 97be41e7..a6fb5233 100644 --- a/cli/src/main/java/com/ericsson/eiffel/remrem/generate/cli/SpringLoggingInitializer.java +++ b/cli/src/main/java/com/ericsson/eiffel/remrem/generate/cli/SpringLoggingInitializer.java @@ -26,20 +26,20 @@ public class SpringLoggingInitializer implements ApplicationContextInitializer { - /* (non-Javadoc) - * @see org.springframework.context.ApplicationContextInitializer#initialize(org.springframework.context.ConfigurableApplicationContext) - * - * We need to turn off Spring logging since we want write the generated message to console. - */ - @Override - public void initialize(ConfigurableApplicationContext applicationContext) { - Class[] loggers = {SpringApplication.class, /*App.class,*/ ConfigFileApplicationListener.class, - ConditionEvaluationReportLoggingListener.class}; - Logger log = (Logger) LoggerFactory.getLogger("ROOT"); - log.setLevel(Level.ERROR); - for (Class logger : loggers) { - log = (Logger) LoggerFactory.getLogger(logger); - log.setLevel(Level.ERROR); - } - } + /* (non-Javadoc) + * @see org.springframework.context.ApplicationContextInitializer#initialize(org.springframework.context.ConfigurableApplicationContext) + * + * We need to turn off Spring logging since we want write the generated message to console. + */ + @Override + public void initialize(ConfigurableApplicationContext applicationContext) { + Class[] loggers = {SpringApplication.class, /*App.class,*/ ConfigFileApplicationListener.class, + ConditionEvaluationReportLoggingListener.class}; + Logger log = (Logger) LoggerFactory.getLogger("ROOT"); + log.setLevel(Level.ERROR); + for (Class logger : loggers) { + log = (Logger) LoggerFactory.getLogger(logger); + log.setLevel(Level.ERROR); + } + } } diff --git a/cli/src/test/java/com/ericsson/eiffel/remrem/generate/cli/CliOptionsUnitTests.java b/cli/src/test/java/com/ericsson/eiffel/remrem/generate/cli/CliOptionsUnitTests.java index 51fb9cc6..14147757 100644 --- a/cli/src/test/java/com/ericsson/eiffel/remrem/generate/cli/CliOptionsUnitTests.java +++ b/cli/src/test/java/com/ericsson/eiffel/remrem/generate/cli/CliOptionsUnitTests.java @@ -95,8 +95,8 @@ public void testRequiredOptionsGiven() throws Exception { } @Test - public void testlenientValidationGiven() throws Exception { - String[] args = {"-f", "input_file", "-t", "artifactpublished", "-lv", "true"}; + public void testIgnoreOptionalFieldValidationErrorsGiven() throws Exception { + String[] args = {"-f", "input_file", "-t", "artifactpublished", "-iov", "true"}; CLIOptions.parse(args); assertTrue(CLIOptions.getErrorCodes().isEmpty()); } diff --git a/cli/src/test/java/com/ericsson/eiffel/remrem/generate/cli/CliUnitTests.java b/cli/src/test/java/com/ericsson/eiffel/remrem/generate/cli/CliUnitTests.java index 8909481e..37a1ddd3 100644 --- a/cli/src/test/java/com/ericsson/eiffel/remrem/generate/cli/CliUnitTests.java +++ b/cli/src/test/java/com/ericsson/eiffel/remrem/generate/cli/CliUnitTests.java @@ -117,13 +117,13 @@ public void testHandleMsgTypeEventArgsPass() throws Exception { } @Test - public void testHandlelenientValidationArgsPass() throws Exception { + public void testHandleIgnoreOptionalFieldValidationErrorsArgsPass() throws Exception { URL url = getClass().getClassLoader().getResource("jsonTest.json"); String path = url.getPath().replace("%20"," "); File file = new File(path); String filePath = file.getAbsolutePath(); - String[] args = {"-t", "eiffelactivityfinished", "-f", filePath, "-lv" , "true"}; + String[] args = {"-t", "eiffelactivityfinished", "-f", filePath, "-iov" , "true"}; CLIOptions.parse(args); cli.run(args); assertTrue(CLIOptions.getErrorCodes().isEmpty()); diff --git a/service/src/main/java/com/ericsson/eiffel/remrem/generate/constants/RemremGenerateServiceConstants.java b/service/src/main/java/com/ericsson/eiffel/remrem/generate/constants/RemremGenerateServiceConstants.java index 7223d5fd..ddd369f9 100644 --- a/service/src/main/java/com/ericsson/eiffel/remrem/generate/constants/RemremGenerateServiceConstants.java +++ b/service/src/main/java/com/ericsson/eiffel/remrem/generate/constants/RemremGenerateServiceConstants.java @@ -44,7 +44,4 @@ public final class RemremGenerateServiceConstants { public static final String LOOKUP_IN_EXTERNAL_ERS = "Determines if external ER's should be used to compile the results of query." + "Use true to use External ER's."; - - public static final String LenientValidation = "Lenient Validation true will perform the validation only on mandatory fields, non-mandatory validation failures add into eiffel message as property remremGenerateFailures"; - } diff --git a/service/src/main/java/com/ericsson/eiffel/remrem/generate/controller/RemremGenerateController.java b/service/src/main/java/com/ericsson/eiffel/remrem/generate/controller/RemremGenerateController.java index a1e3c692..d4819281 100644 --- a/service/src/main/java/com/ericsson/eiffel/remrem/generate/controller/RemremGenerateController.java +++ b/service/src/main/java/com/ericsson/eiffel/remrem/generate/controller/RemremGenerateController.java @@ -69,6 +69,17 @@ public class RemremGenerateController { private ErLookUpConfig erlookupConfig; private static ResponseEntity response; + + @Value("${ignoreOptionalFieldValidationErrors:false}") + private boolean ignoreOptionalFieldValidationErrors; + + public void setIgnoreOptionalFieldValidationErrors(boolean ignoreOptionalFieldValidationErrors) { + this.ignoreOptionalFieldValidationErrors = ignoreOptionalFieldValidationErrors; + } + + public boolean isIgnoreOptionalFieldValidationErrors() { + return ignoreOptionalFieldValidationErrors; + } private static RestTemplate restTemplate = new RestTemplate(); @@ -99,9 +110,8 @@ public ResponseEntity generate( @ApiParam(value = "message type", required = true) @RequestParam("msgType") final String msgType, @ApiParam(value = "ER lookup result multiple found, Generate will fail") @RequestParam(value = "failIfMultipleFound", required = false, defaultValue = "false") final Boolean failIfMultipleFound, @ApiParam(value = "ER lookup result none found, Generate will fail") @RequestParam(value = "failIfNoneFound", required = false, defaultValue = "false") final Boolean failIfNoneFound, - @ApiParam(value = RemremGenerateServiceConstants.LOOKUP_IN_EXTERNAL_ERS) @RequestParam(value = "lookupInExternalERs", required = false, defaultValue = "false") final Boolean lookupInExternalERs, + @ApiParam(value = RemremGenerateServiceConstants.LOOKUP_IN_EXTERNAL_ERS) @RequestParam(value = "lookupInExternalERs", required = false, defaultValue = "false") final Boolean lookupInExternalERs, @ApiParam(value = RemremGenerateServiceConstants.LOOKUP_LIMIT) @RequestParam(value = "lookupLimit", required = false, defaultValue = "1") final int lookupLimit, - @ApiParam(value = RemremGenerateServiceConstants.LenientValidation) @RequestParam(value = "lenientValidation", required = false, defaultValue = "false") final Boolean lenientValidation, @ApiParam(value = "JSON message", required = true) @RequestBody JsonObject bodyJson) { try { @@ -109,7 +119,7 @@ public ResponseEntity generate( MsgService msgService = getMessageService(msgProtocol); String response; if (msgService != null) { - response = msgService.generateMsg(msgType, bodyJson, lenientValidation); + response = msgService.generateMsg(msgType, bodyJson, isIgnoreOptionalFieldValidationErrors()); JsonElement parsedResponse = parser.parse(response); if (!parsedResponse.getAsJsonObject().has(RemremGenerateServiceConstants.JSON_ERROR_MESSAGE_FIELD)) { return new ResponseEntity<>(parsedResponse, HttpStatus.OK); diff --git a/service/src/main/resources/application.properties b/service/src/main/resources/application.properties index 7289bcef..4ee798dd 100644 --- a/service/src/main/resources/application.properties +++ b/service/src/main/resources/application.properties @@ -25,4 +25,7 @@ activedirectory.userSearchFilter: #Event Repository configurations event-repository.enabled:false -event-repository.url :http://:/ \ No newline at end of file +event-repository.url :http://:/ + +# Ignore Optional Field Validation Errors true will perform the validation only on mandatory fields, non-mandatory validation failures add into Eiffel message as property remremGenerateFailures +ignoreOptionalFieldValidationErrors: false \ No newline at end of file diff --git a/service/src/main/resources/config.template.properties b/service/src/main/resources/config.template.properties index e4a1ff40..75fd28b7 100644 --- a/service/src/main/resources/config.template.properties +++ b/service/src/main/resources/config.template.properties @@ -25,4 +25,7 @@ #Event Repository configurations event-repository.enabled:(default value is false) - event-repository.url ::/<(optional to specify context-path)> \ No newline at end of file + event-repository.url ::/<(optional to specify context-path)> + +# Ignore Optional Field Validation Errors true will perform the validation only on mandatory fields, non-mandatory validation failures add into Eiffel message as property remremGenerateFailures +ignoreOptionalFieldValidationErrors: false \ No newline at end of file diff --git a/service/src/test/java/com/ericsson/eiffel/remrem/generate/service/EiffelRemERLookupControllerUnitTest.java b/service/src/test/java/com/ericsson/eiffel/remrem/generate/service/EiffelRemERLookupControllerUnitTest.java index 081929e2..d07e1400 100644 --- a/service/src/test/java/com/ericsson/eiffel/remrem/generate/service/EiffelRemERLookupControllerUnitTest.java +++ b/service/src/test/java/com/ericsson/eiffel/remrem/generate/service/EiffelRemERLookupControllerUnitTest.java @@ -82,6 +82,7 @@ public void setUp() throws Exception { msgServices.add(service); msgServices.add(service2); + Mockito.when(unit.isIgnoreOptionalFieldValidationErrors()).thenReturn(false); Mockito.when(service.getServiceName()).thenReturn("eiffelsemantics"); Mockito.when(service2.getServiceName()).thenReturn("eiffel3"); @@ -222,7 +223,7 @@ public void testErlookupSuccesswithMultipleIds() throws Exception { JsonParser parser = new JsonParser(); JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject(); - ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelconfidencelevel", false, false, true, 1, false, json); + ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelconfidencelevel", false, false, true, 1, json); assertEquals(elem.getStatusCode(), HttpStatus.OK); } @@ -233,7 +234,7 @@ public void testErlookupMultipleFound() throws Exception { JsonParser parser = new JsonParser(); JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject(); - ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelcompositiondefined", true, false, true, 1, false, json); + ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelcompositiondefined", true, false, true, 1, json); assertEquals(elem.getStatusCode(), HttpStatus.EXPECTATION_FAILED); } @@ -243,7 +244,7 @@ public void testErlookupMultipleTraces() throws Exception { JsonParser parser = new JsonParser(); JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject(); - ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelartifactpublished", false, true, true, 1, false, json); + ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelartifactpublished", false, true, true, 1, json); assertEquals(elem.getStatusCode(), HttpStatus.BAD_REQUEST); } @@ -253,7 +254,7 @@ public void testErlookupSuccesswithOneId() throws Exception { JsonParser parser = new JsonParser(); JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject(); - ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelCompositionDefined", true, true, true, 1, false, json); + ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelCompositionDefined", true, true, true, 1, json); assertEquals(elem.getStatusCode(), HttpStatus.OK); } @@ -263,7 +264,7 @@ public void testErlookupNoneFound() throws Exception { JsonParser parser = new JsonParser(); JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject(); - ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelCompositionDefinedEvent", true, true, true, 1, false, json); + ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelCompositionDefinedEvent", true, true, true, 1, json); assertEquals(elem.getStatusCode(), HttpStatus.NOT_ACCEPTABLE); } @@ -273,7 +274,7 @@ public void testErlookupMultipleTrace() throws Exception { JsonParser parser = new JsonParser(); JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject(); - ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelSCSubmitted", false, true, true, 1, false, json); + ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelSCSubmitted", false, true, true, 1, json); assertEquals(elem.getStatusCode(), HttpStatus.BAD_REQUEST); } @@ -283,7 +284,7 @@ public void testErlookupOptions() throws Exception { JsonParser parser = new JsonParser(); JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject(); - ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelEnvironmentDefined", false, false, true, 2, false, json); + ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelEnvironmentDefined", false, false, true, 2, json); assertEquals(elem.getStatusCode(), HttpStatus.OK); } @@ -293,7 +294,7 @@ public void testErlookupOptionsWithEmptyResponse() throws Exception { JsonParser parser = new JsonParser(); JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject(); - ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelEnvironmentDefinedEvent", true, true, true, 2, false, json); + ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelEnvironmentDefinedEvent", true, true, true, 2, json); assertEquals(elem.getStatusCode(), HttpStatus.OK); } @@ -303,7 +304,7 @@ public void testErlookupOptionsWithMultipleFound() throws Exception { JsonParser parser = new JsonParser(); JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject(); - ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelCompositionDefinedEventt", false, false, true, 2, false, json); + ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelCompositionDefinedEventt", false, false, true, 2, json); assertEquals(elem.getStatusCode(), HttpStatus.EXPECTATION_FAILED); } @@ -313,7 +314,7 @@ public void testErlookupOptionsWithNoneFound() throws Exception { JsonParser parser = new JsonParser(); JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject(); - ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelConfidenceLevelModified", false, false, true, 2, false, json); + ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelConfidenceLevelModified", false, false, true, 2, json); assertEquals(elem.getStatusCode(), HttpStatus.NOT_ACCEPTABLE); } @@ -323,7 +324,7 @@ public void testErlookupFailedWithOptions() throws Exception { JsonParser parser = new JsonParser(); JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject(); - ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelTestCaseStarted", false, false, true, 2, false, json); + ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelTestCaseStarted", false, false, true, 2, json); assertEquals(elem.getStatusCode(), HttpStatus.UNPROCESSABLE_ENTITY); } } \ No newline at end of file diff --git a/service/src/test/java/com/ericsson/eiffel/remrem/generate/service/EiffelRemremControllerUnitTest.java b/service/src/test/java/com/ericsson/eiffel/remrem/generate/service/EiffelRemremControllerUnitTest.java index ffcf9bce..136ab0ac 100644 --- a/service/src/test/java/com/ericsson/eiffel/remrem/generate/service/EiffelRemremControllerUnitTest.java +++ b/service/src/test/java/com/ericsson/eiffel/remrem/generate/service/EiffelRemremControllerUnitTest.java @@ -64,14 +64,15 @@ public class EiffelRemremControllerUnitTest { ErLookUpConfig erLookupConfig; @SuppressWarnings("resource") - @Before + @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); msgServices.add(service); msgServices.add(service2); + Mockito.when(unit.isIgnoreOptionalFieldValidationErrors()).thenReturn(false); Mockito.when(service.getServiceName()).thenReturn("eiffelsemantics"); Mockito.when(service2.getServiceName()).thenReturn("eiffel3"); - + URL jsonInputURL = getClass().getClassLoader().getResource("successInput.json"); String inputFilePath = jsonInputURL.getPath().replace("%20"," "); File jsonFile = new File(inputFilePath); @@ -81,7 +82,7 @@ public void setUp() throws Exception { inputFilePath = jsonInputURL.getPath().replace("%20"," "); jsonFile = new File(inputFilePath); String errorOutput = new BufferedReader(new FileReader(jsonFile)).readLine(); - + URL lv_jsonInputURL = getClass().getClassLoader().getResource("lv_successInput.json"); String lv_inputFilePath = lv_jsonInputURL.getPath().replace("%20"," "); File lv_jsonFile = new File(lv_inputFilePath); @@ -90,59 +91,58 @@ public void setUp() throws Exception { Mockito.when(service.generateMsg( Mockito.eq("eiffelactivityfinished"), Mockito.anyObject(), Mockito.anyBoolean())).thenReturn(successOutput); - + Mockito.when(service.generateMsg( Mockito.eq("EiffelActivityFinished"), Mockito.anyObject(), Mockito.anyBoolean())).thenReturn(errorOutput); - + Mockito.when(service2.generateMsg( Mockito.eq("eiffelartifactnew"), Mockito.anyObject(), Mockito.anyBoolean())).thenReturn(successOutput); - + Mockito.when(service2.generateMsg( Mockito.eq("eiffelartifactnewevent"), Mockito.anyObject(), Mockito.anyBoolean())).thenReturn(errorOutput); - + Mockito.when(service.generateMsg( Mockito.eq("EiffelArtifactCreatedEvent"), Mockito.anyObject(), Mockito.anyBoolean())).thenReturn(lv_successOutput); - } - + @Test - public void testSemanticsSuccessEvent() throws Exception { - ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelactivityfinished", false, false, true, 1, false, body.getAsJsonObject()); + public void testSemanticsSuccessEvent() throws Exception { + ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelactivityfinished", false, false, true, 1, body.getAsJsonObject()); assertEquals(elem.getStatusCode(), HttpStatus.OK); } - + @Test - public void testSemanticsFailureEvent() throws Exception { - ResponseEntity elem = unit.generate("eiffelsemantics", "EiffelActivityFinished", false, false, true, 1, false, body.getAsJsonObject()); + public void testSemanticsFailureEvent() throws Exception { + ResponseEntity elem = unit.generate("eiffelsemantics", "EiffelActivityFinished", false, false, true, 1, body.getAsJsonObject()); assertEquals(elem.getStatusCode(), HttpStatus.BAD_REQUEST); } - + @Test - public void testEiffel3SuccessEvent() throws Exception { - ResponseEntity elem = unit.generate("eiffel3", "eiffelartifactnew", false, false, true, 1, false, body.getAsJsonObject()); + public void testEiffel3SuccessEvent() throws Exception { + ResponseEntity elem = unit.generate("eiffel3", "eiffelartifactnew", false, false, true, 1, body.getAsJsonObject()); assertEquals(elem.getStatusCode(), HttpStatus.OK); } - + @Test - public void testEiffel3FailureEvent() throws Exception { - ResponseEntity elem = unit.generate("eiffel3", "eiffelartifactnewevent", false, false, true, 1, false, body.getAsJsonObject()); + public void testEiffel3FailureEvent() throws Exception { + ResponseEntity elem = unit.generate("eiffel3", "eiffelartifactnewevent", false, false, true, 1, body.getAsJsonObject()); assertEquals(elem.getStatusCode(), HttpStatus.BAD_REQUEST); } - + @Test - public void testMessageServiceUnavailableEvent() throws Exception { - ResponseEntity elem = unit.generate("other", "EiffelActivityFinishedEvent", false, false, true, 1, false, body.getAsJsonObject()); + public void testMessageServiceUnavailableEvent() throws Exception { + ResponseEntity elem = unit.generate("other", "EiffelActivityFinishedEvent", false, false, true, 1, body.getAsJsonObject()); assertEquals(elem.getStatusCode(), HttpStatus.SERVICE_UNAVAILABLE); } - + @Test - public void testlenientValidation() throws Exception { - ResponseEntity elem = unit.generate("eiffelsemantics", "EiffelArtifactCreatedEvent", false, false, true, 1, true, body.getAsJsonObject()); + public void testlenientValidation() throws Exception { + unit.setIgnoreOptionalFieldValidationErrors(true); + ResponseEntity elem = unit.generate("eiffelsemantics", "EiffelArtifactCreatedEvent", false, false, true, 1, body.getAsJsonObject()); assertEquals(elem.getStatusCode(), HttpStatus.OK); } - } diff --git a/wiki/markdown/usage/configuration.md b/wiki/markdown/usage/configuration.md index a09ab763..c9cb8560 100644 --- a/wiki/markdown/usage/configuration.md +++ b/wiki/markdown/usage/configuration.md @@ -156,4 +156,11 @@ If _event-repository.enabled_ is true then Event Repository URL should be mandat ``` event-repository.enabled : true event-repository.url : -``` \ No newline at end of file +``` + +### Lenient Validation Configurations + +More about [Lenient Validation](../usage/lenientValidation.md). +``` + ignoreOptionalFieldValidationErrors : +``` diff --git a/wiki/markdown/usage/generate-cli.md b/wiki/markdown/usage/generate-cli.md index f38720f2..128d40a2 100644 --- a/wiki/markdown/usage/generate-cli.md +++ b/wiki/markdown/usage/generate-cli.md @@ -20,7 +20,9 @@ usage: java -jar -mp,--messaging_protocol name of messaging protocol to be used, e.g. eiffelsemantics - -lv,--lenientValidation lenientValidation will perform the only mandatory field validation and non-mandatory validation failures will place in Eiffel message as a new property(remremGenerateFailures) + -iov,--ignoreOptionalFieldValidationErrors + + ignoreOptionalFieldValidationErrors will perform the only mandatory field validation and non-mandatory validation failures will place in Eiffel message as a new property(remremGenerateFailures) -r,--response_file file to store the response in, optional @@ -98,11 +100,11 @@ $ java -jar generate-cli.jar -f eiffelactivityfinished.json -t eiffelactivityfin $ java -jar generate-cli.jar -t eiffelactivityfinished -json {"msgParams":{"meta":{"type":"EiffelActivityFinishedEvent","tags":["tag1","tag2"],"source":{"domainId":"example.domain","host":"host","name":"name","uri":"http://java.sun.com/j2se/1.3/","serializer":"pkg:maven/com.github.eiffel-community/eiffel-remrem-semantics@2.0.0"},"security":{"sdm":{"authorIdentity":"test","encryptedDigest":"sample"}}}},"eventParams":{"data":{"outcome":{"conclusion":"SUCCESSFUL"},"persistentLogs":[{"name":"firstLog","uri":"http://myHost.com/firstLog"},{"name":"otherLog","uri":"isbn:0-486-27557-4"}]},"links":[{"type":"ACTIVITY_EXECUTION","target":"aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee1"}]}} ``` -##### Lenient Validation example: +##### Ignore Optional Field Validation Errors example: #### Input ``` -$ java -jar generate-cli.jar -t EiffelArtifactCreatedEvent -lv true -json "{'msgParams':{'meta':{'type':'EiffelArtifactCreatedEvent','version':'3.0.0','tags':[123,'tag2'],'source':{'domainId':'domainID','host':'host','name':'name','uri':'http:\/\/java.sun.com\/j2se\/1.3\/','serializer':'pkg:maven'},'security':{'authorIdentity':'test','encryptedDigest':'sample'}}},'eventParams':{'data':{'gav':{'groupId':'G','artifactId':'A','version':'V'},'fileInformation':[{'name':'name'}],'buildCommand':'trigger','requiresImplementation':'NONE','name':'event','dependsOn':[],'implement':[],'identity':'pkg:abc','customData':[{'key':'firstLog','value':'http:\/\/myHost.com\/firstLog'},{'key':'otherLog','value':'http:\/\/myHost.com\/firstLog33'}]},'links':[{'type':'CAUSE','target':'aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee1'},{'type':'PREVIOUS_VERSION','target':'aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee2'},{'type':'COMPOSITION','target':'aaaaaaaa'},{'type':'ENVIRONMENT','target':'aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee3'}]}}" +$ java -jar generate-cli.jar -t EiffelArtifactCreatedEvent -iov true -json "{'msgParams':{'meta':{'type':'EiffelArtifactCreatedEvent','version':'3.0.0','tags':[123,'tag2'],'source':{'domainId':'domainID','host':'host','name':'name','uri':'http:\/\/java.sun.com\/j2se\/1.3\/','serializer':'pkg:maven'},'security':{'authorIdentity':'test','encryptedDigest':'sample'}}},'eventParams':{'data':{'gav':{'groupId':'G','artifactId':'A','version':'V'},'fileInformation':[{'name':'name'}],'buildCommand':'trigger','requiresImplementation':'NONE','name':'event','dependsOn':[],'implement':[],'identity':'pkg:abc','customData':[{'key':'firstLog','value':'http:\/\/myHost.com\/firstLog'},{'key':'otherLog','value':'http:\/\/myHost.com\/firstLog33'}]},'links':[{'type':'CAUSE','target':'aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee1'},{'type':'PREVIOUS_VERSION','target':'aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee2'},{'type':'COMPOSITION','target':'aaaaaaaa'},{'type':'ENVIRONMENT','target':'aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee3'}]}}" ``` #### Output diff --git a/wiki/markdown/usage/lenientvalidation.md b/wiki/markdown/usage/lenientvalidation.md index 66e73beb..4c70be08 100644 --- a/wiki/markdown/usage/lenientvalidation.md +++ b/wiki/markdown/usage/lenientvalidation.md @@ -1,16 +1,26 @@ ## Lenient Validation The Lenient validation introduced in REMReM Generate since the version 2.1.0 -Using the lenient validation user continue the Eiffel generate with non-fatal fields in the message. +Using the lenient validation user can continue the Eiffel message generate with non-fatal error fields in the message. + This validation flexibility applies to only Eiffel's message optional fields. see [Eiffel REMReM semantics](https://github.com/eiffel-community/eiffel/tree/master/schemas) for more about mandatory and optional fields. -The Lenient validation will perform the only mandatory field validation and non-mandatory validation failures will place in Eiffel message as a new property(remremGenerateFailures) +The Lenient validation will perform the only mandatory and type field validation and other validation failures will place in Eiffel message as a new property(remremGenerateFailures) + +#### Other Validations are: +- pattern validations +- enum +- format + +The ignoreOptionalFieldValidationErrors is an optional parameter to CLI and service and possible inputs are true and false. The default ignoreOptionalFieldValidationErrors is false. + +The REMReM Generate CLI the ignoreOptionalFieldValidationErrors option user can pass through command line option -iov (true/false) -The lenientValidation is an optional parameter to CLI and service and possible inputs are true and false. The default lenientValidation is false. +The REMreM Generate service ignoreOptionalFieldValidationErrors is set through configuration file. -#### Example 1: lenientValidation = true and Input invalid optional field (links.type.COMPOSITION) +#### Example 1: ignoreOptionalFieldValidationErrors = true and Input invalid optional field (links.type.COMPOSITION) ``` { "msgParams":{ @@ -174,7 +184,7 @@ The lenientValidation is an optional parameter to CLI and service and possible i ] ``` -The lenient validation created new message property with "remremGenerateFailures" +The ignoreOptionalFieldValidationErrors = true created new message property with "remremGenerateFailures" ``` "remremGenerateFailures":[ { @@ -185,7 +195,7 @@ The lenient validation created new message property with "remremGenerateFailures ] ``` -#### Example 2: lenientValidation = true and Input invalid optional field (links.type.COMPOSITION) +#### Example 2: ignoreOptionalFieldValidationErrors = true and Input invalid optional field (links.type.COMPOSITION) Input same as example1 ##### output From 2b353cffe9e8085283f45e46b77d1e2f6d46a338 Mon Sep 17 00:00:00 2001 From: erjamni Date: Thu, 6 Aug 2020 08:31:34 +0200 Subject: [PATCH 07/11] documentation corrections --- wiki/markdown/usage/lenientvalidation.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wiki/markdown/usage/lenientvalidation.md b/wiki/markdown/usage/lenientvalidation.md index 4c70be08..0785c074 100644 --- a/wiki/markdown/usage/lenientvalidation.md +++ b/wiki/markdown/usage/lenientvalidation.md @@ -7,7 +7,7 @@ This validation flexibility applies to only Eiffel's message optional fields. se [Eiffel REMReM semantics](https://github.com/eiffel-community/eiffel/tree/master/schemas) for more about mandatory and optional fields. -The Lenient validation will perform the only mandatory and type field validation and other validation failures will place in Eiffel message as a new property(remremGenerateFailures) +The Lenient validation will perform the only on mandatory and type field validation and other validation failures will place in Eiffel message as a new customData property(remremGenerateFailures). #### Other Validations are: - pattern validations @@ -184,7 +184,7 @@ The REMreM Generate service ignoreOptionalFieldValidationErrors is set through c ] ``` -The ignoreOptionalFieldValidationErrors = true created new message property with "remremGenerateFailures" +The ignoreOptionalFieldValidationErrors = true created new element property with "remremGenerateFailures" ``` "remremGenerateFailures":[ { From a3bb00a9ea52c3500656092384eb99a5cb4c18f1 Mon Sep 17 00:00:00 2001 From: erjamni Date: Thu, 6 Aug 2020 14:01:16 +0200 Subject: [PATCH 08/11] documentation updated --- .../src/test/resources/lv_successInput.json | 2 +- wiki/markdown/usage/generate-cli.md | 3 +- wiki/markdown/usage/lenientvalidation.md | 144 ++++++++---------- 3 files changed, 69 insertions(+), 80 deletions(-) diff --git a/service/src/test/resources/lv_successInput.json b/service/src/test/resources/lv_successInput.json index 6ee8acb9..6835f686 100644 --- a/service/src/test/resources/lv_successInput.json +++ b/service/src/test/resources/lv_successInput.json @@ -1 +1 @@ -{"meta":{"id":"800ce624-e640-4ca7-a23e-173b9da8b446","type":"EiffelArtifactCreatedEvent","version":"3.0.0","time":1594978923338,"tags":["123","tag2"],"source":{"domainId":"domainID","host":"host","name":"name","serializer":"pkg:maven","uri":"http:\/\/java.sun.com\/j2se\/1.3\/"},"security":{"authorIdentity":"test","sequenceProtection":[]}},"data":{"identity":"pkg:abc","fileInformation":[{"name":"name","tags":[]}],"buildCommand":"trigger","requiresImplementation":"NONE","dependsOn":[],"implements":[],"name":"event","customData":[{"key":"firstLog","value":"http:\/\/myHost.com\/firstLog"},{"key":"otherLog","value":"http:\/\/myHost.com\/firstLog33"},{"remremGenerateFailures":[{"type":"pattern","message":"ECMA 262 regex \"^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$\" does not match input string \"aaaaaaaa\"","path":"\/links\/2\/target"}]}]},"links":[{"type":"CAUSE","target":"aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee1"},{"type":"PREVIOUS_VERSION","target":"aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee2"},{"type":"ENVIRONMENT","target":"aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee3"}]} \ No newline at end of file +{"meta":{"id":"ea2b6ef3-c03a-432c-9c9e-0eec5730fddb","type":"EiffelArtifactCreatedEvent","version":"3.0.0","time":1596708141578,"tags":["123","tag2"],"source":{"domainId":"domainID","host":"host","name":"name","serializer":"pkg:maven","uri":"http:\/\/java.sun.com\/j2se\/1.3\/"},"security":{"authorIdentity":"test","sequenceProtection":[]}},"data":{"identity":"pkg:abc","fileInformation":[{"name":"name","tags":[]}],"buildCommand":"trigger","requiresImplementation":"NONE","dependsOn":[],"implements":[],"name":"event","customData":[{"key":"firstLog","value":"http:\/\/myHost.com\/firstLog"},{"key":"otherLog","value":"http:\/\/myHost.com\/firstLog33"},{"key":"remremGenerateFailures","value":[{"type":"pattern","message":"ECMA 262 regex \"^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$\" does not match input string \"aaaaaaaa\"","path":"\/links\/2\/target"}]}]},"links":[{"type":"CAUSE","target":"aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee1"},{"type":"PREVIOUS_VERSION","target":"aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee2"},{"type":"ENVIRONMENT","target":"aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee3"}]} \ No newline at end of file diff --git a/wiki/markdown/usage/generate-cli.md b/wiki/markdown/usage/generate-cli.md index 128d40a2..ad6ab15c 100644 --- a/wiki/markdown/usage/generate-cli.md +++ b/wiki/markdown/usage/generate-cli.md @@ -109,7 +109,8 @@ $ java -jar generate-cli.jar -t EiffelArtifactCreatedEvent -iov true -json "{'ms #### Output ``` -[{"meta":{"id":"8afff3b8-96b3-405c-85a5-366bc5f59cc6","type":"EiffelArtifactCreatedEvent","version":"3.0.0","time":1595395508961,"tags":["123","tag2"],"source":{"domainId":"domainID","host":"host","name":"name","serializer":"pkg:maven","uri":"http://java.sun.com/j2se/1.3/"},"security":{"authorIdentity":"test","sequenceProtection":[]}},"data":{"identity":"pkg:abc","fileInformation":[{"name":"name","tags":[]}],"buildCommand":"trigger","requiresImplementation":"NONE","dependsOn":[],"implements":[],"name":"event","customData":[{"key":"firstLog","value":"http://myHost.com/firstLog"},{"key":"otherLog","value":"http://myHost.com/firstLog33"},{"remremGenerateFailures":[{"type":"pattern","message":"ECMA 262 regex \"^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$\" does not match input string \"aaaaaaaa\"","path":"/links/2/target"}]}]},"links":[{"type":"CAUSE","target":"aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee1"},{"type":"PREVIOUS_VERSION","target":"aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee2"},{"type":"ENVIRONMENT","target":"aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee3"}]}] +[{"meta":{"id":"61c4f2d5-2d08-4d00-b881-314253061e83","type":"EiffelArtifactCreatedEvent","version":"3.0.0","time":1596712126955,"tags":["123","tag2"],"source":{"domainId":"domainID","host":"host","name":"name","serializer":"pkg:maven","uri":"http://java.sun.com/j2se/1.3/"},"security":{"authorIdentity":"test","sequenceProtection":[]}},"data":{"identity":"pkg:abc","fileInformation":[{"name":"name","tags":[]}],"buildCommand":"trigger","requiresImplementation":"NONE","dependsOn":[],"implements":[],"name":"event","customData":[{"key":"firstLog","value":"http://myHost.com/firstLog"},{"key":"otherLog","value":"http://myHost.com/firstLog33"},{"key":"remremGenerateFailures","value":[{"type":"pattern","message":"ECMA 262 regex \"^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$\" does not match input string \"aaaaaaaa\"","path":"/links/2/target"}]}]},"links":[{"type":"CAUSE","target":"aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee1"},{"type":"PREVIOUS_VERSION","target":"aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee2"},{"type":"ENVIRONMENT","target":"aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee3"}]}] + ``` ##### For loading protocol jars other than _eiffelsemantics_: diff --git a/wiki/markdown/usage/lenientvalidation.md b/wiki/markdown/usage/lenientvalidation.md index 0785c074..2fcff412 100644 --- a/wiki/markdown/usage/lenientvalidation.md +++ b/wiki/markdown/usage/lenientvalidation.md @@ -102,97 +102,85 @@ The REMreM Generate service ignoreOptionalFieldValidationErrors is set through c #### Output ``` -[ - { - "meta":{ - "id":"8afff3b8-96b3-405c-85a5-366bc5f59cc6", - "type":"EiffelArtifactCreatedEvent", - "version":"3.0.0", - "time":1595395508961, - "tags":[ - "123", - "tag2" - ], - "source":{ - "domainId":"domainID", - "host":"host", +{ + "meta":{ + "id":"ea2b6ef3-c03a-432c-9c9e-0eec5730fddb", + "type":"EiffelArtifactCreatedEvent", + "version":"3.0.0", + "time":1596708141578, + "tags":[ + "123", + "tag2" + ], + "source":{ + "domainId":"domainID", + "host":"host", + "name":"name", + "serializer":"pkg:maven", + "uri":"http://java.sun.com/j2se/1.3/" + }, + "security":{ + "authorIdentity":"test", + "sequenceProtection":[ + + ] + } + }, + "data":{ + "identity":"pkg:abc", + "fileInformation":[ + { "name":"name", - "serializer":"pkg:maven", - "uri":"http://java.sun.com/j2se/1.3/" - }, - "security":{ - "authorIdentity":"test", - "sequenceProtection":[ + "tags":[ ] } - }, - "data":{ - "identity":"pkg:abc", - "fileInformation":[ - { - "name":"name", - "tags":[ - - ] - } - ], - "buildCommand":"trigger", - "requiresImplementation":"NONE", - "dependsOn":[ + ], + "buildCommand":"trigger", + "requiresImplementation":"NONE", + "dependsOn":[ - ], - "implements":[ + ], + "implements":[ - ], - "name":"event", - "customData":[ - { - "key":"firstLog", - "value":"http://myHost.com/firstLog" - }, - { - "key":"otherLog", - "value":"http://myHost.com/firstLog33" - }, - { - "remremGenerateFailures":[ - { - "type":"pattern", - "message":"ECMA 262 regex \"^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$\" does not match input string \"aaaaaaaa\"", - "path":"/links/2/target" - } - ] - } - ] - }, - "links":[ + ], + "name":"event", + "customData":[ { - "type":"CAUSE", - "target":"aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee1" + "key":"firstLog", + "value":"http://myHost.com/firstLog" }, { - "type":"PREVIOUS_VERSION", - "target":"aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee2" + "key":"otherLog", + "value":"http://myHost.com/firstLog33" }, { - "type":"ENVIRONMENT", - "target":"aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee3" + "key":"remremGenerateFailures", + "value":[ + { + "type":"pattern", + "message":"ECMA 262 regex \"^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$\" does not match input string \"aaaaaaaa\"", + "path":"/links/2/target" + } + ] } ] - } -] -``` - -The ignoreOptionalFieldValidationErrors = true created new element property with "remremGenerateFailures" -``` -"remremGenerateFailures":[ - { - "type":"pattern", - "message":"ECMA 262 regex \"^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$\" does not match input string \"aaaaaaaa\"", - "path":"/links/2/target" - } - ] + }, + "links":[ + { + "type":"CAUSE", + "target":"aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee1" + }, + { + "type":"PREVIOUS_VERSION", + "target":"aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee2" + }, + { + "type":"ENVIRONMENT", + "target":"aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee3" + } + ] +} ``` #### Example 2: ignoreOptionalFieldValidationErrors = true and Input invalid optional field (links.type.COMPOSITION) From 8f12e2d3566f9e653fa77be1a5dd97639c9aa611 Mon Sep 17 00:00:00 2001 From: erjamni Date: Wed, 12 Aug 2020 14:01:25 +0200 Subject: [PATCH 09/11] added code for REST param option to enable and disable the lenient validation. --- .../eiffel/remrem/generate/cli/CLI.java | 4 +-- .../remrem/generate/cli/CLIOptions.java | 4 +-- .../generate/cli/CliOptionsUnitTests.java | 2 +- .../remrem/generate/cli/CliUnitTests.java | 2 +- .../RemremGenerateServiceConstants.java | 7 ++-- .../controller/RemremGenerateController.java | 32 ++++++++++++------- .../src/main/resources/application.properties | 6 ++-- .../main/resources/config.template.properties | 4 +-- .../EiffelRemERLookupControllerUnitTest.java | 29 +++++++---------- .../EiffelRemremControllerUnitTest.java | 15 ++++----- wiki/markdown/usage/configuration.md | 2 +- wiki/markdown/usage/generate-cli.md | 8 ++--- wiki/markdown/usage/lenientvalidation.md | 21 ++++++++---- wiki/markdown/usage/service.md | 4 +-- 14 files changed, 78 insertions(+), 62 deletions(-) diff --git a/cli/src/main/java/com/ericsson/eiffel/remrem/generate/cli/CLI.java b/cli/src/main/java/com/ericsson/eiffel/remrem/generate/cli/CLI.java index e9fbe04c..f19aa87b 100644 --- a/cli/src/main/java/com/ericsson/eiffel/remrem/generate/cli/CLI.java +++ b/cli/src/main/java/com/ericsson/eiffel/remrem/generate/cli/CLI.java @@ -175,8 +175,8 @@ private void handleJsonString(String jsonString, CommandLine commandLine) { JsonParser parser = new JsonParser(); JsonObject jsonContent = parser.parse(jsonString).getAsJsonObject(); MsgService msgService = getMessageService(commandLine); - Boolean iov = commandLine.hasOption("iov")? Boolean.parseBoolean(commandLine.getOptionValue("iov")) : false; - String returnJsonStr = msgService.generateMsg(msgType, jsonContent, iov); + Boolean lv = commandLine.hasOption("lv")? Boolean.parseBoolean(commandLine.getOptionValue("lv")) : false; + String returnJsonStr = msgService.generateMsg(msgType, jsonContent, lv); returnJsonStr = "[" + returnJsonStr + "]"; if (responseFilePath != null) { try (PrintWriter out = new PrintWriter(responseFilePath)) { diff --git a/cli/src/main/java/com/ericsson/eiffel/remrem/generate/cli/CLIOptions.java b/cli/src/main/java/com/ericsson/eiffel/remrem/generate/cli/CLIOptions.java index 3487dfe9..53119b62 100644 --- a/cli/src/main/java/com/ericsson/eiffel/remrem/generate/cli/CLIOptions.java +++ b/cli/src/main/java/com/ericsson/eiffel/remrem/generate/cli/CLIOptions.java @@ -72,8 +72,8 @@ public static Options createCLIOptions() { options.addOption("d", "debug", false, "enable debug traces"); options.addOption("mp", "messaging_protocol", true, "name of messaging protocol to be used, e.g. eiffelsemantics"); - options.addOption("iov", "ignoreOptionalFieldValidationErrors", true, - "ignoreOptionalFieldValidationErrors will perform the only mandatory field validation and non-mandatory validation failures will place in Eiffel message as a new property(remremGenerateFailures)" + + options.addOption("lv", "lenientValidationEnabled", true, + "lenientValidationEnabled will perform the only mandatory field validation and non-mandatory validation failures will place in Eiffel message as a new property(remremGenerateFailures)" + ""); contentGroup = new OptionGroup(); contentGroup.addOption(new Option("f", "content_file", true, "message content file")); diff --git a/cli/src/test/java/com/ericsson/eiffel/remrem/generate/cli/CliOptionsUnitTests.java b/cli/src/test/java/com/ericsson/eiffel/remrem/generate/cli/CliOptionsUnitTests.java index 14147757..2e52dcad 100644 --- a/cli/src/test/java/com/ericsson/eiffel/remrem/generate/cli/CliOptionsUnitTests.java +++ b/cli/src/test/java/com/ericsson/eiffel/remrem/generate/cli/CliOptionsUnitTests.java @@ -96,7 +96,7 @@ public void testRequiredOptionsGiven() throws Exception { @Test public void testIgnoreOptionalFieldValidationErrorsGiven() throws Exception { - String[] args = {"-f", "input_file", "-t", "artifactpublished", "-iov", "true"}; + String[] args = {"-f", "input_file", "-t", "artifactpublished", "-lv", "true"}; CLIOptions.parse(args); assertTrue(CLIOptions.getErrorCodes().isEmpty()); } diff --git a/cli/src/test/java/com/ericsson/eiffel/remrem/generate/cli/CliUnitTests.java b/cli/src/test/java/com/ericsson/eiffel/remrem/generate/cli/CliUnitTests.java index 37a1ddd3..73b1d6ad 100644 --- a/cli/src/test/java/com/ericsson/eiffel/remrem/generate/cli/CliUnitTests.java +++ b/cli/src/test/java/com/ericsson/eiffel/remrem/generate/cli/CliUnitTests.java @@ -123,7 +123,7 @@ public void testHandleIgnoreOptionalFieldValidationErrorsArgsPass() throws Excep File file = new File(path); String filePath = file.getAbsolutePath(); - String[] args = {"-t", "eiffelactivityfinished", "-f", filePath, "-iov" , "true"}; + String[] args = {"-t", "eiffelactivityfinished", "-f", filePath, "-lv" , "true"}; CLIOptions.parse(args); cli.run(args); assertTrue(CLIOptions.getErrorCodes().isEmpty()); diff --git a/service/src/main/java/com/ericsson/eiffel/remrem/generate/constants/RemremGenerateServiceConstants.java b/service/src/main/java/com/ericsson/eiffel/remrem/generate/constants/RemremGenerateServiceConstants.java index ddd369f9..4d24304b 100644 --- a/service/src/main/java/com/ericsson/eiffel/remrem/generate/constants/RemremGenerateServiceConstants.java +++ b/service/src/main/java/com/ericsson/eiffel/remrem/generate/constants/RemremGenerateServiceConstants.java @@ -39,9 +39,12 @@ public final class RemremGenerateServiceConstants { + "\"message\":\"Link specific lookup options could not be fulfilled\"}"; public static final String LOOKUP_LIMIT = "The maximum number of events returned from a lookup. If more events " - + "are found they will be disregarded. The order of the events is undefined, which means that what events are " - + "disregarded is also undefined."; + + "are found they will be disregarded. The order of the events is undefined, which means that what events are " + + "disregarded is also undefined."; public static final String LOOKUP_IN_EXTERNAL_ERS = "Determines if external ER's should be used to compile the results of query." + "Use true to use External ER's."; + + public static final String LenientValidation = "Lenient Validation true will perform the validation only on mandatory fields, " + + "non-mandatory validation failures add into eiffel message as property remremGenerateFailures"; } diff --git a/service/src/main/java/com/ericsson/eiffel/remrem/generate/controller/RemremGenerateController.java b/service/src/main/java/com/ericsson/eiffel/remrem/generate/controller/RemremGenerateController.java index d4819281..002727e8 100644 --- a/service/src/main/java/com/ericsson/eiffel/remrem/generate/controller/RemremGenerateController.java +++ b/service/src/main/java/com/ericsson/eiffel/remrem/generate/controller/RemremGenerateController.java @@ -70,18 +70,14 @@ public class RemremGenerateController { private static ResponseEntity response; - @Value("${ignoreOptionalFieldValidationErrors:false}") - private boolean ignoreOptionalFieldValidationErrors; + @Value("${lenientValidationEnabledToUsers:false}") + private boolean lenientValidationEnabledToUsers; - public void setIgnoreOptionalFieldValidationErrors(boolean ignoreOptionalFieldValidationErrors) { - this.ignoreOptionalFieldValidationErrors = ignoreOptionalFieldValidationErrors; - } - - public boolean isIgnoreOptionalFieldValidationErrors() { - return ignoreOptionalFieldValidationErrors; - } + public void setLenientValidationEnabledToUsers(boolean lenientValidationEnabledToUsers) { + this.lenientValidationEnabledToUsers = lenientValidationEnabledToUsers; + } - private static RestTemplate restTemplate = new RestTemplate(); + private static RestTemplate restTemplate = new RestTemplate(); public void setRestTemplate(RestTemplate restTemplate) { this.restTemplate = restTemplate; @@ -112,6 +108,7 @@ public ResponseEntity generate( @ApiParam(value = "ER lookup result none found, Generate will fail") @RequestParam(value = "failIfNoneFound", required = false, defaultValue = "false") final Boolean failIfNoneFound, @ApiParam(value = RemremGenerateServiceConstants.LOOKUP_IN_EXTERNAL_ERS) @RequestParam(value = "lookupInExternalERs", required = false, defaultValue = "false") final Boolean lookupInExternalERs, @ApiParam(value = RemremGenerateServiceConstants.LOOKUP_LIMIT) @RequestParam(value = "lookupLimit", required = false, defaultValue = "1") final int lookupLimit, + @ApiParam(value = RemremGenerateServiceConstants.LenientValidation) @RequestParam(value = "okToLeaveOutInvalidOptionalFields", required = false, defaultValue = "false") final Boolean okToLeaveOutInvalidOptionalFields, @ApiParam(value = "JSON message", required = true) @RequestBody JsonObject bodyJson) { try { @@ -119,7 +116,7 @@ public ResponseEntity generate( MsgService msgService = getMessageService(msgProtocol); String response; if (msgService != null) { - response = msgService.generateMsg(msgType, bodyJson, isIgnoreOptionalFieldValidationErrors()); + response = msgService.generateMsg(msgType, bodyJson, isLenientEnabled(okToLeaveOutInvalidOptionalFields)); JsonElement parsedResponse = parser.parse(response); if (!parsedResponse.getAsJsonObject().has(RemremGenerateServiceConstants.JSON_ERROR_MESSAGE_FIELD)) { return new ResponseEntity<>(parsedResponse, HttpStatus.OK); @@ -137,6 +134,9 @@ public ResponseEntity generate( else if (e1.getMessage().contains(Integer.toString(HttpStatus.EXPECTATION_FAILED.value()))) { return new ResponseEntity<>(parser.parse(e1.getMessage()), HttpStatus.EXPECTATION_FAILED); } + else if (e1.getMessage().contains(Integer.toString(HttpStatus.EXPECTATION_FAILED.value()))) { + return new ResponseEntity<>(parser.parse(e1.getMessage()), HttpStatus.EXPECTATION_FAILED); + } else { return new ResponseEntity<>(parser.parse(e1.getMessage()), HttpStatus.UNPROCESSABLE_ENTITY); } @@ -341,4 +341,14 @@ private ResponseEntity presentResponse(final Object message, final HttpStatus return new ResponseEntity<>(message, status); } } + + public boolean isLenientEnabled(final boolean okToLeaveOutInvalidOptionalFields) throws REMGenerateException { + if(this.lenientValidationEnabledToUsers && okToLeaveOutInvalidOptionalFields) { + return true; + } + else if(!this.lenientValidationEnabledToUsers && okToLeaveOutInvalidOptionalFields) { + throw new REMGenerateException("Not Acceptable - Lenient validation is not enabled in configuration, your not alloed to use this option."); + } + return false; + } } \ No newline at end of file diff --git a/service/src/main/resources/application.properties b/service/src/main/resources/application.properties index 4ee798dd..27359be3 100644 --- a/service/src/main/resources/application.properties +++ b/service/src/main/resources/application.properties @@ -1,6 +1,6 @@ #This file is for reference only. Will not pick any values from this file. -server.port=8080 +server.port=8088 debug: false @@ -27,5 +27,5 @@ activedirectory.userSearchFilter: event-repository.enabled:false event-repository.url :http://:/ -# Ignore Optional Field Validation Errors true will perform the validation only on mandatory fields, non-mandatory validation failures add into Eiffel message as property remremGenerateFailures -ignoreOptionalFieldValidationErrors: false \ No newline at end of file +# lenientValidationEnabledToUsers true will perform the validation only on mandatory fields, non-mandatory validation failures add into Eiffel message as property remremGenerateFailures +lenientValidationEnabledToUsers: true \ No newline at end of file diff --git a/service/src/main/resources/config.template.properties b/service/src/main/resources/config.template.properties index 75fd28b7..97a680de 100644 --- a/service/src/main/resources/config.template.properties +++ b/service/src/main/resources/config.template.properties @@ -27,5 +27,5 @@ event-repository.enabled:(default value is false) event-repository.url ::/<(optional to specify context-path)> -# Ignore Optional Field Validation Errors true will perform the validation only on mandatory fields, non-mandatory validation failures add into Eiffel message as property remremGenerateFailures -ignoreOptionalFieldValidationErrors: false \ No newline at end of file +# lenientValidationEnabledToUsers true will perform the validation only on mandatory fields, non-mandatory validation failures add into Eiffel message as property remremGenerateFailures +lenientValidationEnabledToUsers: false \ No newline at end of file diff --git a/service/src/test/java/com/ericsson/eiffel/remrem/generate/service/EiffelRemERLookupControllerUnitTest.java b/service/src/test/java/com/ericsson/eiffel/remrem/generate/service/EiffelRemERLookupControllerUnitTest.java index d07e1400..4ba8765f 100644 --- a/service/src/test/java/com/ericsson/eiffel/remrem/generate/service/EiffelRemERLookupControllerUnitTest.java +++ b/service/src/test/java/com/ericsson/eiffel/remrem/generate/service/EiffelRemERLookupControllerUnitTest.java @@ -17,15 +17,10 @@ import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.when; -import java.io.BufferedReader; import java.io.File; import java.io.FileReader; -import java.net.URL; import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.apache.commons.io.FileUtils; import org.junit.Before; @@ -82,7 +77,7 @@ public void setUp() throws Exception { msgServices.add(service); msgServices.add(service2); - Mockito.when(unit.isIgnoreOptionalFieldValidationErrors()).thenReturn(false); + Mockito.when(unit.isLenientEnabled(false)).thenReturn(false); Mockito.when(service.getServiceName()).thenReturn("eiffelsemantics"); Mockito.when(service2.getServiceName()).thenReturn("eiffel3"); @@ -223,7 +218,7 @@ public void testErlookupSuccesswithMultipleIds() throws Exception { JsonParser parser = new JsonParser(); JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject(); - ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelconfidencelevel", false, false, true, 1, json); + ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelconfidencelevel", false, false, true, 1, false, json); assertEquals(elem.getStatusCode(), HttpStatus.OK); } @@ -234,7 +229,7 @@ public void testErlookupMultipleFound() throws Exception { JsonParser parser = new JsonParser(); JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject(); - ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelcompositiondefined", true, false, true, 1, json); + ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelcompositiondefined", true, false, true, 1, false, json); assertEquals(elem.getStatusCode(), HttpStatus.EXPECTATION_FAILED); } @@ -244,7 +239,7 @@ public void testErlookupMultipleTraces() throws Exception { JsonParser parser = new JsonParser(); JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject(); - ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelartifactpublished", false, true, true, 1, json); + ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelartifactpublished", false, true, true, 1, false, json); assertEquals(elem.getStatusCode(), HttpStatus.BAD_REQUEST); } @@ -254,7 +249,7 @@ public void testErlookupSuccesswithOneId() throws Exception { JsonParser parser = new JsonParser(); JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject(); - ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelCompositionDefined", true, true, true, 1, json); + ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelCompositionDefined", true, true, true, 1, false, json); assertEquals(elem.getStatusCode(), HttpStatus.OK); } @@ -264,7 +259,7 @@ public void testErlookupNoneFound() throws Exception { JsonParser parser = new JsonParser(); JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject(); - ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelCompositionDefinedEvent", true, true, true, 1, json); + ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelCompositionDefinedEvent", true, true, true, 1, false, json); assertEquals(elem.getStatusCode(), HttpStatus.NOT_ACCEPTABLE); } @@ -274,7 +269,7 @@ public void testErlookupMultipleTrace() throws Exception { JsonParser parser = new JsonParser(); JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject(); - ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelSCSubmitted", false, true, true, 1, json); + ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelSCSubmitted", false, true, true, 1, false, json); assertEquals(elem.getStatusCode(), HttpStatus.BAD_REQUEST); } @@ -284,7 +279,7 @@ public void testErlookupOptions() throws Exception { JsonParser parser = new JsonParser(); JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject(); - ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelEnvironmentDefined", false, false, true, 2, json); + ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelEnvironmentDefined", false, false, true, 2, false, json); assertEquals(elem.getStatusCode(), HttpStatus.OK); } @@ -294,7 +289,7 @@ public void testErlookupOptionsWithEmptyResponse() throws Exception { JsonParser parser = new JsonParser(); JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject(); - ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelEnvironmentDefinedEvent", true, true, true, 2, json); + ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelEnvironmentDefinedEvent", true, true, true, 2, false, json); assertEquals(elem.getStatusCode(), HttpStatus.OK); } @@ -304,7 +299,7 @@ public void testErlookupOptionsWithMultipleFound() throws Exception { JsonParser parser = new JsonParser(); JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject(); - ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelCompositionDefinedEventt", false, false, true, 2, json); + ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelCompositionDefinedEventt", false, false, true, 2, false, json); assertEquals(elem.getStatusCode(), HttpStatus.EXPECTATION_FAILED); } @@ -314,7 +309,7 @@ public void testErlookupOptionsWithNoneFound() throws Exception { JsonParser parser = new JsonParser(); JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject(); - ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelConfidenceLevelModified", false, false, true, 2, json); + ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelConfidenceLevelModified", false, false, true, 2, false, json); assertEquals(elem.getStatusCode(), HttpStatus.NOT_ACCEPTABLE); } @@ -324,7 +319,7 @@ public void testErlookupFailedWithOptions() throws Exception { JsonParser parser = new JsonParser(); JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject(); - ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelTestCaseStarted", false, false, true, 2, json); + ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelTestCaseStarted", false, false, true, 2, false, json); assertEquals(elem.getStatusCode(), HttpStatus.UNPROCESSABLE_ENTITY); } } \ No newline at end of file diff --git a/service/src/test/java/com/ericsson/eiffel/remrem/generate/service/EiffelRemremControllerUnitTest.java b/service/src/test/java/com/ericsson/eiffel/remrem/generate/service/EiffelRemremControllerUnitTest.java index 136ab0ac..eaa8355d 100644 --- a/service/src/test/java/com/ericsson/eiffel/remrem/generate/service/EiffelRemremControllerUnitTest.java +++ b/service/src/test/java/com/ericsson/eiffel/remrem/generate/service/EiffelRemremControllerUnitTest.java @@ -69,7 +69,6 @@ public void setUp() throws Exception { MockitoAnnotations.initMocks(this); msgServices.add(service); msgServices.add(service2); - Mockito.when(unit.isIgnoreOptionalFieldValidationErrors()).thenReturn(false); Mockito.when(service.getServiceName()).thenReturn("eiffelsemantics"); Mockito.when(service2.getServiceName()).thenReturn("eiffel3"); @@ -111,38 +110,38 @@ public void setUp() throws Exception { @Test public void testSemanticsSuccessEvent() throws Exception { - ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelactivityfinished", false, false, true, 1, body.getAsJsonObject()); + ResponseEntity elem = unit.generate("eiffelsemantics", "eiffelactivityfinished", false, false, true, 1, false, body.getAsJsonObject()); assertEquals(elem.getStatusCode(), HttpStatus.OK); } @Test public void testSemanticsFailureEvent() throws Exception { - ResponseEntity elem = unit.generate("eiffelsemantics", "EiffelActivityFinished", false, false, true, 1, body.getAsJsonObject()); + ResponseEntity elem = unit.generate("eiffelsemantics", "EiffelActivityFinished", false, false, true, 1, false, body.getAsJsonObject()); assertEquals(elem.getStatusCode(), HttpStatus.BAD_REQUEST); } @Test public void testEiffel3SuccessEvent() throws Exception { - ResponseEntity elem = unit.generate("eiffel3", "eiffelartifactnew", false, false, true, 1, body.getAsJsonObject()); + ResponseEntity elem = unit.generate("eiffel3", "eiffelartifactnew", false, false, true, 1, false, body.getAsJsonObject()); assertEquals(elem.getStatusCode(), HttpStatus.OK); } @Test public void testEiffel3FailureEvent() throws Exception { - ResponseEntity elem = unit.generate("eiffel3", "eiffelartifactnewevent", false, false, true, 1, body.getAsJsonObject()); + ResponseEntity elem = unit.generate("eiffel3", "eiffelartifactnewevent", false, false, true, 1, false, body.getAsJsonObject()); assertEquals(elem.getStatusCode(), HttpStatus.BAD_REQUEST); } @Test public void testMessageServiceUnavailableEvent() throws Exception { - ResponseEntity elem = unit.generate("other", "EiffelActivityFinishedEvent", false, false, true, 1, body.getAsJsonObject()); + ResponseEntity elem = unit.generate("other", "EiffelActivityFinishedEvent", false, false, true, 1, false, body.getAsJsonObject()); assertEquals(elem.getStatusCode(), HttpStatus.SERVICE_UNAVAILABLE); } @Test public void testlenientValidation() throws Exception { - unit.setIgnoreOptionalFieldValidationErrors(true); - ResponseEntity elem = unit.generate("eiffelsemantics", "EiffelArtifactCreatedEvent", false, false, true, 1, body.getAsJsonObject()); + unit.setLenientValidationEnabledToUsers(true); + ResponseEntity elem = unit.generate("eiffelsemantics", "EiffelArtifactCreatedEvent", false, false, true, 1, true, body.getAsJsonObject()); assertEquals(elem.getStatusCode(), HttpStatus.OK); } } diff --git a/wiki/markdown/usage/configuration.md b/wiki/markdown/usage/configuration.md index c9cb8560..90fd3425 100644 --- a/wiki/markdown/usage/configuration.md +++ b/wiki/markdown/usage/configuration.md @@ -162,5 +162,5 @@ If _event-repository.enabled_ is true then Event Repository URL should be mandat More about [Lenient Validation](../usage/lenientValidation.md). ``` - ignoreOptionalFieldValidationErrors : + lenientValidationEnabledToUsers : ``` diff --git a/wiki/markdown/usage/generate-cli.md b/wiki/markdown/usage/generate-cli.md index ad6ab15c..77ffa0af 100644 --- a/wiki/markdown/usage/generate-cli.md +++ b/wiki/markdown/usage/generate-cli.md @@ -20,9 +20,9 @@ usage: java -jar -mp,--messaging_protocol name of messaging protocol to be used, e.g. eiffelsemantics - -iov,--ignoreOptionalFieldValidationErrors + -lv,--lenientValidationEnabledToUsers - ignoreOptionalFieldValidationErrors will perform the only mandatory field validation and non-mandatory validation failures will place in Eiffel message as a new property(remremGenerateFailures) + lenientValidationEnabled will perform the only mandatory field validation and non-mandatory validation failures will place in Eiffel message as a new property(remremGenerateFailures) -r,--response_file file to store the response in, optional @@ -100,11 +100,11 @@ $ java -jar generate-cli.jar -f eiffelactivityfinished.json -t eiffelactivityfin $ java -jar generate-cli.jar -t eiffelactivityfinished -json {"msgParams":{"meta":{"type":"EiffelActivityFinishedEvent","tags":["tag1","tag2"],"source":{"domainId":"example.domain","host":"host","name":"name","uri":"http://java.sun.com/j2se/1.3/","serializer":"pkg:maven/com.github.eiffel-community/eiffel-remrem-semantics@2.0.0"},"security":{"sdm":{"authorIdentity":"test","encryptedDigest":"sample"}}}},"eventParams":{"data":{"outcome":{"conclusion":"SUCCESSFUL"},"persistentLogs":[{"name":"firstLog","uri":"http://myHost.com/firstLog"},{"name":"otherLog","uri":"isbn:0-486-27557-4"}]},"links":[{"type":"ACTIVITY_EXECUTION","target":"aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee1"}]}} ``` -##### Ignore Optional Field Validation Errors example: +##### Lenient Validation Enabled Errors example: #### Input ``` -$ java -jar generate-cli.jar -t EiffelArtifactCreatedEvent -iov true -json "{'msgParams':{'meta':{'type':'EiffelArtifactCreatedEvent','version':'3.0.0','tags':[123,'tag2'],'source':{'domainId':'domainID','host':'host','name':'name','uri':'http:\/\/java.sun.com\/j2se\/1.3\/','serializer':'pkg:maven'},'security':{'authorIdentity':'test','encryptedDigest':'sample'}}},'eventParams':{'data':{'gav':{'groupId':'G','artifactId':'A','version':'V'},'fileInformation':[{'name':'name'}],'buildCommand':'trigger','requiresImplementation':'NONE','name':'event','dependsOn':[],'implement':[],'identity':'pkg:abc','customData':[{'key':'firstLog','value':'http:\/\/myHost.com\/firstLog'},{'key':'otherLog','value':'http:\/\/myHost.com\/firstLog33'}]},'links':[{'type':'CAUSE','target':'aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee1'},{'type':'PREVIOUS_VERSION','target':'aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee2'},{'type':'COMPOSITION','target':'aaaaaaaa'},{'type':'ENVIRONMENT','target':'aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee3'}]}}" +$ java -jar generate-cli.jar -t EiffelArtifactCreatedEvent -lv true -json "{'msgParams':{'meta':{'type':'EiffelArtifactCreatedEvent','version':'3.0.0','tags':[123,'tag2'],'source':{'domainId':'domainID','host':'host','name':'name','uri':'http:\/\/java.sun.com\/j2se\/1.3\/','serializer':'pkg:maven'},'security':{'authorIdentity':'test','encryptedDigest':'sample'}}},'eventParams':{'data':{'gav':{'groupId':'G','artifactId':'A','version':'V'},'fileInformation':[{'name':'name'}],'buildCommand':'trigger','requiresImplementation':'NONE','name':'event','dependsOn':[],'implement':[],'identity':'pkg:abc','customData':[{'key':'firstLog','value':'http:\/\/myHost.com\/firstLog'},{'key':'otherLog','value':'http:\/\/myHost.com\/firstLog33'}]},'links':[{'type':'CAUSE','target':'aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee1'},{'type':'PREVIOUS_VERSION','target':'aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee2'},{'type':'COMPOSITION','target':'aaaaaaaa'},{'type':'ENVIRONMENT','target':'aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee3'}]}}" ``` #### Output diff --git a/wiki/markdown/usage/lenientvalidation.md b/wiki/markdown/usage/lenientvalidation.md index 2fcff412..e95df7f1 100644 --- a/wiki/markdown/usage/lenientvalidation.md +++ b/wiki/markdown/usage/lenientvalidation.md @@ -7,20 +7,29 @@ This validation flexibility applies to only Eiffel's message optional fields. se [Eiffel REMReM semantics](https://github.com/eiffel-community/eiffel/tree/master/schemas) for more about mandatory and optional fields. -The Lenient validation will perform the only on mandatory and type field validation and other validation failures will place in Eiffel message as a new customData property(remremGenerateFailures). +The Lenient validation will perform the only on mandatory field validation and other validation failures will place in Eiffel message as a new customData property(remremGenerateFailures). #### Other Validations are: - pattern validations - enum - format +- type -The ignoreOptionalFieldValidationErrors is an optional parameter to CLI and service and possible inputs are true and false. The default ignoreOptionalFieldValidationErrors is false. +The lenientValidationEnabledToUsers is an optional parameter to CLI and service and possible inputs are true and false. The default lenientValidationEnabledToUsers is false. -The REMReM Generate CLI the ignoreOptionalFieldValidationErrors option user can pass through command line option -iov (true/false) +The REMReM Generate CLI the lenientValidationEnabled option user can pass through command line option -lv (true/false) -The REMreM Generate service ignoreOptionalFieldValidationErrors is set through configuration file. +The REMreM Generate service the lenient validation is enable with two options one is lenientValidationEnabledToUsers is set through configuration file +and second one is REST endpoint(/generate) option okToLeaveOutInvalidOptionalFields -#### Example 1: ignoreOptionalFieldValidationErrors = true and Input invalid optional field (links.type.COMPOSITION) +The Configuration parameter for the whole REMReM Generate instance lenientValidationEnabledToUsers (default false) +REST parameter for each /generate call okToLeaveOutInvalidOptionalFields (default false) + +If the configuration parameter is set to false and the REST parameter is set to true REMReM /generate REST call return with an error code stating that it is not allowed to ask for lenient validation. + +If both parameters are true then REMReM will remove the optional event fields from the input event data that does not validate successfully, and add those removed field information added into customData. + +#### Example 1: Lenient Validation Enabled and Input invalid optional field (links.type.COMPOSITION) ``` { "msgParams":{ @@ -183,7 +192,7 @@ The REMreM Generate service ignoreOptionalFieldValidationErrors is set through c } ``` -#### Example 2: ignoreOptionalFieldValidationErrors = true and Input invalid optional field (links.type.COMPOSITION) +#### Example 2: Lenient Validation Disabled and Input invalid optional field (links.type.COMPOSITION) Input same as example1 ##### output diff --git a/wiki/markdown/usage/service.md b/wiki/markdown/usage/service.md index cab5176e..d6a7d6c5 100644 --- a/wiki/markdown/usage/service.md +++ b/wiki/markdown/usage/service.md @@ -29,7 +29,7 @@ Available REST resources for REMReM Generate Service are described below: | Resource | Method | Parameters | Request body | Description | |-----------------------|--------|---------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| /mp | POST | mp - message protocol, required msgType - Eiffel event type, required failIfMultipleFound - default: false failIfNoneFound - default: false, lookupInExternalERs - default: false, lenientValidation - default: false, lookupLimit - default: 1| { "msgParams": {"meta": {# Matches the meta object }},"eventParams": {"data": {# Matches the data object},"links": { # Matches the links object } }} | This endpoint is used to generate Eiffel events and then the obtained event could be published by [Eiffel REMReM Publish](https://github.com/eiffel-community/eiffel-remrem-publish). | +| /mp | POST | mp - message protocol, required msgType - Eiffel event type, required failIfMultipleFound - default: false failIfNoneFound - default: false, lookupInExternalERs - default: false, okToLeaveOutInvalidOptionalFields - default: false, lookupLimit - default: 1| { "msgParams": {"meta": {# Matches the meta object }},"eventParams": {"data": {# Matches the data object},"links": { # Matches the links object } }} | This endpoint is used to generate Eiffel events and then the obtained event could be published by [Eiffel REMReM Publish](https://github.com/eiffel-community/eiffel-remrem-publish). | | /event_types/{mp} | GET | mp - message protocol, required | | This endpoint is used to obtain Eiffel event types implemented in [Eiffel REMReM Semantics](https://github.com/eiffel-community/eiffel-remrem-semantics). | | /template/{type}/{mp} | GET | type - Eiffel event type mp - message protocol, required | | This endpoint is used to obtain Eiffel event templates implemented in [Eiffel REMReM Semantics](https://github.com/eiffel-community/eiffel-remrem-semantics). | | /versions | GET | | | This endpoint is used to get versions of generate service and all loaded protocols versions in JSON format. | @@ -120,7 +120,7 @@ Status codes are generated according to the below table. | 200 | OK | | Event generated successfully | | 400 | Bad Request | Could not read document: Unrecognized token | Malformed JSON (missing braces or wrong event type, etc..), client need to fix problem in event before submitting again | | 404 | Not Found | Requested template is not available | The endpoint is not found, or template for specified event type is not found | -| 406 | Not Acceptable | No event id found with ERLookup properties | Is returned if no event id fetched from configured event repository in REMReM generate. | +| 406 | Not Acceptable | No event id found with ERLookup properties, Lenient Validation disabled in configuration and user requested through REST call | Is returned if no event id fetched from configured event repository in REMReM generate., Lenient validation is not enabled in configuration, your not alloed to use this option. | | 417 | Expectation Failed | Multiple event ids found with ERLookup properties | Is returned if multiple event ids fetched from configured event repository in REMReM generate. | | 422 | Unprocessable Entity | Link specific lookup options could not be fulfilled | Is returned if Link specific lookup options could not be matched with failIfMultipleFound and failIfNoneFound. | | 500 | Internal Server Error | Internal server error | When REMReM Generate is down, possible to try again later when server is up | From b69a8de01b1fe5e4e68f3e5d357b9a6438541a8a Mon Sep 17 00:00:00 2001 From: erjamni Date: Wed, 12 Aug 2020 14:55:34 +0200 Subject: [PATCH 10/11] document changes --- service/src/main/resources/application.properties | 2 +- wiki/markdown/usage/configuration.md | 2 +- wiki/markdown/usage/generate-cli.md | 2 +- wiki/markdown/usage/lenientvalidation.md | 7 +++---- wiki/markdown/usage/service.md | 4 ++-- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/service/src/main/resources/application.properties b/service/src/main/resources/application.properties index 27359be3..a5b696e0 100644 --- a/service/src/main/resources/application.properties +++ b/service/src/main/resources/application.properties @@ -1,6 +1,6 @@ #This file is for reference only. Will not pick any values from this file. -server.port=8088 +server.port=8080 debug: false diff --git a/wiki/markdown/usage/configuration.md b/wiki/markdown/usage/configuration.md index 90fd3425..a1549286 100644 --- a/wiki/markdown/usage/configuration.md +++ b/wiki/markdown/usage/configuration.md @@ -160,7 +160,7 @@ If _event-repository.enabled_ is true then Event Repository URL should be mandat ### Lenient Validation Configurations -More about [Lenient Validation](../usage/lenientValidation.md). +More about [Lenient Validation](../usage/lenientvalidation.md). ``` lenientValidationEnabledToUsers : ``` diff --git a/wiki/markdown/usage/generate-cli.md b/wiki/markdown/usage/generate-cli.md index 77ffa0af..3220a79c 100644 --- a/wiki/markdown/usage/generate-cli.md +++ b/wiki/markdown/usage/generate-cli.md @@ -20,7 +20,7 @@ usage: java -jar -mp,--messaging_protocol name of messaging protocol to be used, e.g. eiffelsemantics - -lv,--lenientValidationEnabledToUsers + -lv,--lenientValidationEnabled lenientValidationEnabled will perform the only mandatory field validation and non-mandatory validation failures will place in Eiffel message as a new property(remremGenerateFailures) diff --git a/wiki/markdown/usage/lenientvalidation.md b/wiki/markdown/usage/lenientvalidation.md index e95df7f1..ce663cd1 100644 --- a/wiki/markdown/usage/lenientvalidation.md +++ b/wiki/markdown/usage/lenientvalidation.md @@ -15,15 +15,14 @@ The Lenient validation will perform the only on mandatory field validation and o - format - type -The lenientValidationEnabledToUsers is an optional parameter to CLI and service and possible inputs are true and false. The default lenientValidationEnabledToUsers is false. - The REMReM Generate CLI the lenientValidationEnabled option user can pass through command line option -lv (true/false) The REMreM Generate service the lenient validation is enable with two options one is lenientValidationEnabledToUsers is set through configuration file and second one is REST endpoint(/generate) option okToLeaveOutInvalidOptionalFields -The Configuration parameter for the whole REMReM Generate instance lenientValidationEnabledToUsers (default false) -REST parameter for each /generate call okToLeaveOutInvalidOptionalFields (default false) +The Configuration parameter(lenientValidationEnabledToUsers) for the whole REMReM Generate instance, the default value is false + +The REST parameter(okToLeaveOutInvalidOptionalFields) for each /generate call the default value is false If the configuration parameter is set to false and the REST parameter is set to true REMReM /generate REST call return with an error code stating that it is not allowed to ask for lenient validation. diff --git a/wiki/markdown/usage/service.md b/wiki/markdown/usage/service.md index d6a7d6c5..5e8b762f 100644 --- a/wiki/markdown/usage/service.md +++ b/wiki/markdown/usage/service.md @@ -120,7 +120,7 @@ Status codes are generated according to the below table. | 200 | OK | | Event generated successfully | | 400 | Bad Request | Could not read document: Unrecognized token | Malformed JSON (missing braces or wrong event type, etc..), client need to fix problem in event before submitting again | | 404 | Not Found | Requested template is not available | The endpoint is not found, or template for specified event type is not found | -| 406 | Not Acceptable | No event id found with ERLookup properties, Lenient Validation disabled in configuration and user requested through REST call | Is returned if no event id fetched from configured event repository in REMReM generate., Lenient validation is not enabled in configuration, your not alloed to use this option. | +| 406 | Not Acceptable | No event id found with ERLookup properties, Lenient Validation disabled in configuration and user requested through REST call | Is returned if no event id fetched from configured event repository in REMReM generate, Lenient validation is not enabled in configuration, your not alloed to use this option. | | 417 | Expectation Failed | Multiple event ids found with ERLookup properties | Is returned if multiple event ids fetched from configured event repository in REMReM generate. | | 422 | Unprocessable Entity | Link specific lookup options could not be fulfilled | Is returned if Link specific lookup options could not be matched with failIfMultipleFound and failIfNoneFound. | | 500 | Internal Server Error | Internal server error | When REMReM Generate is down, possible to try again later when server is up | @@ -301,4 +301,4 @@ If the failIfNoneFound and failIfMultipleFound are available in lookup then it w ] ``` ### Lenient Validation: -[Lenient Validation](../usage/lenientValidation.md). +[Lenient Validation](../usage/lenientvalidation.md). From 7201ab091fd1581cf72286a7ac855fd3b508317e Mon Sep 17 00:00:00 2001 From: erjamni Date: Wed, 12 Aug 2020 15:43:45 +0200 Subject: [PATCH 11/11] modified generate response failed message --- .../constants/RemremGenerateServiceConstants.java | 8 ++++++-- .../generate/controller/RemremGenerateController.java | 2 +- service/src/main/resources/application.properties | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/service/src/main/java/com/ericsson/eiffel/remrem/generate/constants/RemremGenerateServiceConstants.java b/service/src/main/java/com/ericsson/eiffel/remrem/generate/constants/RemremGenerateServiceConstants.java index 4d24304b..0026ff2d 100644 --- a/service/src/main/java/com/ericsson/eiffel/remrem/generate/constants/RemremGenerateServiceConstants.java +++ b/service/src/main/java/com/ericsson/eiffel/remrem/generate/constants/RemremGenerateServiceConstants.java @@ -34,6 +34,9 @@ public final class RemremGenerateServiceConstants { public static final String UNAVAILABLE_FOR_FAILIFNONEFOUND = "{\"status_code\": 406, \"result\": \"FAIL\", " + "\"message\":\"No event id found with ERLookup properties\"}"; + + public static final String NOT_ACCEPTABLE = "{\"status_code\": 406, \"result\": \"FAIL\", " + + "\"message\":\"Not Acceptable - Lenient validation is not enabled in the configuration, your not allowed to use this option\"}"; public static final String LOOKUP_OPTIONS_NOT_FULFILLED = "{\"status_code\": 422, \"result\": \"FAIL\", " + "\"message\":\"Link specific lookup options could not be fulfilled\"}"; @@ -45,6 +48,7 @@ public final class RemremGenerateServiceConstants { public static final String LOOKUP_IN_EXTERNAL_ERS = "Determines if external ER's should be used to compile the results of query." + "Use true to use External ER's."; - public static final String LenientValidation = "Lenient Validation true will perform the validation only on mandatory fields, " - + "non-mandatory validation failures add into eiffel message as property remremGenerateFailures"; + public static final String LenientValidation = "okToLeaveOutInvalidOptionalFields true will remove the optional " + + "event fields from the input event data that does not validate successfully, " + + "and add those removed field information into customData/remremGenerateFailures"; } diff --git a/service/src/main/java/com/ericsson/eiffel/remrem/generate/controller/RemremGenerateController.java b/service/src/main/java/com/ericsson/eiffel/remrem/generate/controller/RemremGenerateController.java index 002727e8..49cdc73f 100644 --- a/service/src/main/java/com/ericsson/eiffel/remrem/generate/controller/RemremGenerateController.java +++ b/service/src/main/java/com/ericsson/eiffel/remrem/generate/controller/RemremGenerateController.java @@ -347,7 +347,7 @@ public boolean isLenientEnabled(final boolean okToLeaveOutInvalidOptionalFields) return true; } else if(!this.lenientValidationEnabledToUsers && okToLeaveOutInvalidOptionalFields) { - throw new REMGenerateException("Not Acceptable - Lenient validation is not enabled in configuration, your not alloed to use this option."); + throw new REMGenerateException(RemremGenerateServiceConstants.NOT_ACCEPTABLE); } return false; } diff --git a/service/src/main/resources/application.properties b/service/src/main/resources/application.properties index a5b696e0..83963ec8 100644 --- a/service/src/main/resources/application.properties +++ b/service/src/main/resources/application.properties @@ -28,4 +28,4 @@ event-repository.enabled:false event-repository.url :http://:/ # lenientValidationEnabledToUsers true will perform the validation only on mandatory fields, non-mandatory validation failures add into Eiffel message as property remremGenerateFailures -lenientValidationEnabledToUsers: true \ No newline at end of file +lenientValidationEnabledToUsers: false \ No newline at end of file