aboutsummaryrefslogtreecommitdiffstats
path: root/workflow-designer-be/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'workflow-designer-be/src/main/java')
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowVersionController.java22
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/exceptionshandlers/CustomizedResponseEntityExceptionHandler.java3
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/WorkflowVersionValidator.java34
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validator/WorkflowVersionValidator.java61
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionValidationException.java10
5 files changed, 54 insertions, 76 deletions
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowVersionController.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowVersionController.java
index df4c9fe3..1f0c4fec 100644
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowVersionController.java
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowVersionController.java
@@ -24,6 +24,7 @@ import io.swagger.annotations.ApiOperation;
import org.onap.sdc.workflow.api.types.CollectionResponse;
import org.onap.sdc.workflow.api.types.VersionStateDto;
import org.onap.sdc.workflow.api.types.VersionStatesFormatter;
+import org.onap.sdc.workflow.api.types.WorkflowVersionValidator;
import org.onap.sdc.workflow.persistence.types.ArtifactEntity;
import org.onap.sdc.workflow.persistence.types.WorkflowVersion;
import org.onap.sdc.workflow.services.WorkflowVersionManager;
@@ -35,12 +36,8 @@ import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
-import org.springframework.validation.Validator;
-import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
@@ -58,18 +55,13 @@ import springfox.documentation.annotations.ApiIgnore;
public class WorkflowVersionController {
private final WorkflowVersionManager workflowVersionManager;
- private Validator validator;
-
- @InitBinder("WorkflowVersion")
- private void initBinder(WebDataBinder binder) {
- binder.addValidators(validator);
- }
+ private final WorkflowVersionValidator versionValidator;
@Autowired
public WorkflowVersionController(@Qualifier("workflowVersionManager") WorkflowVersionManager workflowVersionManager,
- @Qualifier("workflowVersionValidator") Validator validator) {
+ @Qualifier("WorkflowVersionValidator") WorkflowVersionValidator versionValidator) {
this.workflowVersionManager = workflowVersionManager;
- this.validator = validator;
+ this.versionValidator = versionValidator;
}
@ApiImplicitParam(name = "state", dataType = "string", paramType = "query",
@@ -84,10 +76,11 @@ public class WorkflowVersionController {
@PostMapping
@ApiOperation("Create workflow version")
- public ResponseEntity<WorkflowVersion> create(@RequestBody @Validated WorkflowVersion version,
+ public ResponseEntity<WorkflowVersion> create(@RequestBody WorkflowVersion version,
@PathVariable("workflowId") String workflowId,
@RequestParam(value = "baseVersionId", required = false) String baseVersionId,
@RequestHeader(USER_ID_HEADER) String user) {
+ versionValidator.validate(workflowId,version);
WorkflowVersion createdVersion = workflowVersionManager.create(workflowId, baseVersionId, version);
return new ResponseEntity<>(createdVersion, HttpStatus.CREATED);
}
@@ -101,8 +94,9 @@ public class WorkflowVersionController {
@PutMapping("/{versionId}")
@ApiOperation("Update workflow version")
- public void update(@RequestBody @Validated WorkflowVersion version, @PathVariable("workflowId") String workflowId,
+ public void update(@RequestBody WorkflowVersion version, @PathVariable("workflowId") String workflowId,
@PathVariable("versionId") String versionId, @RequestHeader(USER_ID_HEADER) String user) {
+ versionValidator.validate(workflowId,version);
version.setId(versionId);
workflowVersionManager.update(workflowId, version);
}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/exceptionshandlers/CustomizedResponseEntityExceptionHandler.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/exceptionshandlers/CustomizedResponseEntityExceptionHandler.java
index ca6111df..e8622905 100644
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/exceptionshandlers/CustomizedResponseEntityExceptionHandler.java
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/exceptionshandlers/CustomizedResponseEntityExceptionHandler.java
@@ -28,6 +28,7 @@ import org.onap.sdc.workflow.services.exceptions.UniqueValueViolationException;
import org.onap.sdc.workflow.services.exceptions.VersionCreationException;
import org.onap.sdc.workflow.services.exceptions.VersionModificationException;
import org.onap.sdc.workflow.services.exceptions.VersionStateModificationException;
+import org.onap.sdc.workflow.services.exceptions.VersionValidationException;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@@ -82,7 +83,7 @@ public class CustomizedResponseEntityExceptionHandler extends ResponseEntityExce
@ExceptionHandler({InvalidArtifactException.class, VersionModificationException.class,
- VersionStateModificationException.class})
+ VersionStateModificationException.class, VersionValidationException.class})
public final ResponseEntity<String> handleInvalidArtifactException(
Exception exception) {
return new ResponseEntity<>(exception.getMessage(), UNPROCESSABLE_ENTITY);
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/WorkflowVersionValidator.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/WorkflowVersionValidator.java
new file mode 100644
index 00000000..ef5e06c9
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/WorkflowVersionValidator.java
@@ -0,0 +1,34 @@
+package org.onap.sdc.workflow.api.types;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Objects;
+import java.util.Set;
+import org.onap.sdc.workflow.persistence.types.ParameterEntity;
+import org.onap.sdc.workflow.persistence.types.WorkflowVersion;
+import org.onap.sdc.workflow.services.exceptions.VersionValidationException;
+import org.springframework.stereotype.Component;
+
+@Component("WorkflowVersionValidator")
+public class WorkflowVersionValidator {
+
+ public void validate(String workflowId, WorkflowVersion workflowVersion) {
+
+ if(containsDuplicates( workflowVersion.getInputs())){
+ throw new VersionValidationException(workflowId,"Input name must be unique");
+
+ }
+
+ if(containsDuplicates(workflowVersion.getOutputs())){
+ throw new VersionValidationException(workflowId ,"Output name must be unique");
+ }
+ }
+
+ private boolean containsDuplicates(Collection<ParameterEntity> parameters){
+ if(Objects.isNull(parameters) || parameters.size() < 2 ) {
+ return false;
+ }
+ Set<String> testSet = new HashSet<>();
+ return parameters.stream().anyMatch(s -> !testSet.add(s.getName()));
+ }
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validator/WorkflowVersionValidator.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validator/WorkflowVersionValidator.java
deleted file mode 100644
index 03101042..00000000
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validator/WorkflowVersionValidator.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright © 2018 European Support Limited
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onap.sdc.workflow.api.validator;
-
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Objects;
-import java.util.Set;
-import org.onap.sdc.workflow.persistence.types.ParameterEntity;
-import org.onap.sdc.workflow.persistence.types.WorkflowVersion;
-import org.springframework.stereotype.Component;
-import org.springframework.validation.Errors;
-import org.springframework.validation.Validator;
-
-
-@Component("workflowVersionValidator")
-public class WorkflowVersionValidator implements Validator{
-
- @Override
- public boolean supports(Class<?> aClass) {
- return WorkflowVersion.class.equals(aClass);
- }
-
- @Override
- public void validate(Object o, Errors errors) {
-
- WorkflowVersion workflowVersion = (WorkflowVersion) o;
- Collection<ParameterEntity> inputs = workflowVersion.getInputs();
- Collection<ParameterEntity> outputs = workflowVersion.getOutputs();
-
- if(containsDuplicates(inputs)){
- errors.rejectValue("inputs", "duplicateName", new Object[] {inputs}, "Input name must be unique");
- }
-
- if(containsDuplicates(outputs)){
- errors.rejectValue("outputs", "duplicateName", new Object[] {outputs}, "Output name must be unique");
- }
- }
-
- private boolean containsDuplicates(Collection<ParameterEntity> parameters){
- if(Objects.isNull(parameters) || parameters.size() < 2 ) {
- return false;
- }
- Set<String> testSet = new HashSet<>();
- return parameters.stream().anyMatch(s -> !testSet.add(s.getName()));
- }
-}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionValidationException.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionValidationException.java
new file mode 100644
index 00000000..bd7d61f2
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionValidationException.java
@@ -0,0 +1,10 @@
+package org.onap.sdc.workflow.services.exceptions;
+
+public class VersionValidationException extends RuntimeException{
+
+ private static final String MSG = "Error creating or modifying version for workflow with id %s: %s";
+
+ public VersionValidationException(String workflowId, String detailedMessage) {
+ super(String.format(MSG, workflowId, detailedMessage));
+ }
+}