aboutsummaryrefslogtreecommitdiffstats
path: root/workflow-designer-be/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'workflow-designer-be/src/main')
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowVersionController.java48
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/mappers/WorkflowVersionDtoMapper.java31
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/Parameter.java34
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/WorkflowVersionRequest.java36
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/WorkflowVersionResponse.java34
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/NoDuplicatesValidator.java10
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterEntity.java7
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/WorkflowVersion.java13
8 files changed, 172 insertions, 41 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 67bea00c..213cd713 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
@@ -19,10 +19,14 @@ package org.onap.sdc.workflow.api;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
+import java.util.stream.Collectors;
import javax.validation.Valid;
+import org.onap.sdc.workflow.api.mappers.WorkflowVersionDtoMapper;
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.WorkflowVersionRequest;
+import org.onap.sdc.workflow.api.types.WorkflowVersionResponse;
import org.onap.sdc.workflow.api.types.dto.ArtifactDeliveriesRequestDto;
import org.onap.sdc.workflow.persistence.types.ArtifactEntity;
import org.onap.sdc.workflow.services.WorkflowVersionManager;
@@ -53,13 +57,16 @@ import springfox.documentation.annotations.ApiIgnore;
@RestController("workflowsVersionController")
public class WorkflowVersionController {
- private final WorkflowVersionManager workflowVersionManager;
+ private final WorkflowVersionManager versionManager;
+ private final WorkflowVersionDtoMapper versionDtoMapper;
private final ArtifactAssociationService associationHandler;
@Autowired
- public WorkflowVersionController(@Qualifier("workflowVersionManager") WorkflowVersionManager workflowVersionManager,
+ public WorkflowVersionController(@Qualifier("workflowVersionManager") WorkflowVersionManager versionManager,
+ WorkflowVersionDtoMapper versionDtoMapper,
@Qualifier("ArtifactAssociationHandler") ArtifactAssociationService artifactAssociationHandler) {
- this.workflowVersionManager = workflowVersionManager;
+ this.versionManager = versionManager;
+ this.versionDtoMapper = versionDtoMapper;
this.associationHandler = artifactAssociationHandler;
}
@@ -67,40 +74,45 @@ public class WorkflowVersionController {
@ApiOperation("List workflow versions")
@ApiImplicitParam(name = "state", dataType = "string", paramType = "query", allowableValues = "DRAFT,CERTIFIED",
value = "Filter by state")
- public CollectionResponse<WorkflowVersion> list(@PathVariable("workflowId") String workflowId,
+ public CollectionResponse<WorkflowVersionResponse> list(@PathVariable("workflowId") String workflowId,
@ApiIgnore VersionStatesFormatter stateFilter, @UserId String user) {
- return new CollectionResponse<>(workflowVersionManager.list(workflowId, stateFilter.getVersionStates()));
+ return new CollectionResponse<>(versionManager.list(workflowId, stateFilter.getVersionStates()).stream()
+ .map(versionDtoMapper::workflowVersionToResponse)
+ .collect(Collectors.toList()));
}
@PostMapping
@ApiOperation("Create workflow version")
- public ResponseEntity<WorkflowVersion> create(@RequestBody @Valid WorkflowVersion version,
+ public ResponseEntity<WorkflowVersionResponse> create(@RequestBody @Valid WorkflowVersionRequest request,
@PathVariable("workflowId") String workflowId,
@RequestParam(value = "baseVersionId", required = false) String baseVersionId, @UserId String user) {
- WorkflowVersion createdVersion = workflowVersionManager.create(workflowId, baseVersionId, version);
+ WorkflowVersionResponse createdVersion = versionDtoMapper.workflowVersionToResponse(
+ versionManager.create(workflowId, baseVersionId, versionDtoMapper.requestToWorkflowVersion(request)));
return new ResponseEntity<>(createdVersion, HttpStatus.CREATED);
}
@GetMapping("/{versionId}")
@ApiOperation("Get workflow version")
- public WorkflowVersion get(@PathVariable("workflowId") String workflowId,
+ public WorkflowVersionResponse get(@PathVariable("workflowId") String workflowId,
@PathVariable("versionId") String versionId, @UserId String user) {
- return workflowVersionManager.get(workflowId, versionId);
+ return versionDtoMapper.workflowVersionToResponse(versionManager.get(workflowId, versionId));
}
@PutMapping("/{versionId}")
@ApiOperation("Update workflow version")
- public void update(@RequestBody @Valid WorkflowVersion version, @PathVariable("workflowId") String workflowId,
- @PathVariable("versionId") String versionId, @UserId String user) {
+ public void update(@RequestBody @Valid WorkflowVersionRequest request,
+ @PathVariable("workflowId") String workflowId, @PathVariable("versionId") String versionId,
+ @UserId String user) {
+ WorkflowVersion version = versionDtoMapper.requestToWorkflowVersion(request);
version.setId(versionId);
- workflowVersionManager.update(workflowId, version);
+ versionManager.update(workflowId, version);
}
@GetMapping("/{versionId}/state")
@ApiOperation("Get workflow version state")
public VersionStateDto getState(@PathVariable("workflowId") String workflowId,
@PathVariable("versionId") String versionId, @UserId String user) {
- return new VersionStateDto(workflowVersionManager.getState(workflowId, versionId));
+ return new VersionStateDto(versionManager.getState(workflowId, versionId));
}
@PostMapping("/{versionId}/state")
@@ -108,7 +120,7 @@ public class WorkflowVersionController {
public VersionStateDto updateState(@RequestBody VersionStateDto state,
@PathVariable("workflowId") String workflowId, @PathVariable("versionId") String versionId,
@UserId String user) {
- workflowVersionManager.updateState(workflowId, versionId, state.getName());
+ versionManager.updateState(workflowId, versionId, state.getName());
return new VersionStateDto(state.getName());
}
@@ -118,21 +130,21 @@ public class WorkflowVersionController {
@PathVariable("workflowId") String workflowId, @PathVariable("versionId") String versionId,
@UserId String user) {
return associationHandler
- .execute(user, deliveriesRequestDto, workflowVersionManager.getArtifact(workflowId, versionId));
+ .execute(user, deliveriesRequestDto, versionManager.getArtifact(workflowId, versionId));
}
@PutMapping("/{versionId}/artifact")
@ApiOperation("Create/update artifact of a version")
public void uploadArtifact(@RequestBody MultipartFile fileToUpload, @PathVariable("workflowId") String workflowId,
@PathVariable("versionId") String versionId, @UserId String user) {
- workflowVersionManager.uploadArtifact(workflowId, versionId, fileToUpload);
+ versionManager.uploadArtifact(workflowId, versionId, fileToUpload);
}
@GetMapping("/{versionId}/artifact")
@ApiOperation("Download workflow version artifact")
public ResponseEntity<Resource> getArtifact(@PathVariable("workflowId") String workflowId,
@PathVariable("versionId") String versionId, @UserId String user) {
- ArtifactEntity artifact = workflowVersionManager.getArtifact(workflowId, versionId);
+ ArtifactEntity artifact = versionManager.getArtifact(workflowId, versionId);
return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + artifact.getFileName())
@@ -144,6 +156,6 @@ public class WorkflowVersionController {
@ApiOperation("Delete workflow version artifact")
public void deleteArtifact(@PathVariable("workflowId") String workflowId,
@PathVariable("versionId") String versionId, @UserId String user) {
- workflowVersionManager.deleteArtifact(workflowId, versionId);
+ versionManager.deleteArtifact(workflowId, versionId);
}
}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/mappers/WorkflowVersionDtoMapper.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/mappers/WorkflowVersionDtoMapper.java
new file mode 100644
index 00000000..120b0d23
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/mappers/WorkflowVersionDtoMapper.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright © 2016-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.mappers;
+
+import org.mapstruct.Mapper;
+import org.onap.sdc.workflow.api.types.WorkflowVersionRequest;
+import org.onap.sdc.workflow.api.types.WorkflowVersionResponse;
+import org.onap.sdc.workflow.services.types.WorkflowVersion;
+
+@Mapper(componentModel = "spring")
+public interface WorkflowVersionDtoMapper {
+
+ WorkflowVersion requestToWorkflowVersion(WorkflowVersionRequest request);
+
+ WorkflowVersionResponse workflowVersionToResponse(WorkflowVersion workflowVersion);
+
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/Parameter.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/Parameter.java
new file mode 100644
index 00000000..f5bbecec
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/Parameter.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright © 2016-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.types;
+
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Pattern;
+import lombok.Data;
+import org.onap.sdc.workflow.persistence.types.ParameterType;
+
+@Data
+public class Parameter {
+ @NotBlank(message = "Parameter Name may not be blank")
+ @Pattern(regexp = "[A-Za-z0-9_ ]+", message = "Parameter name must contain only letters, digits and underscores")
+ private String name;
+ @NotNull
+ private ParameterType type;
+ @NotNull
+ private boolean mandatory;
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/WorkflowVersionRequest.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/WorkflowVersionRequest.java
new file mode 100644
index 00000000..090f129a
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/WorkflowVersionRequest.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright © 2016-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.types;
+
+import java.util.Collection;
+import java.util.Collections;
+import javax.validation.Valid;
+import lombok.Data;
+import org.onap.sdc.workflow.api.validation.NoDuplicates;
+
+@Data
+public class WorkflowVersionRequest {
+
+ private String name;
+ private String description;
+ @Valid
+ @NoDuplicates(message = "Inputs names must be unique")
+ private Collection<Parameter> inputs = Collections.emptyList();
+ @Valid
+ @NoDuplicates(message = "Outputs names must be unique")
+ private Collection<Parameter> outputs = Collections.emptyList();
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/WorkflowVersionResponse.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/WorkflowVersionResponse.java
new file mode 100644
index 00000000..460d3d63
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/WorkflowVersionResponse.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright © 2016-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.types;
+
+import java.util.Date;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import org.onap.sdc.workflow.services.types.WorkflowVersionState;
+
+@EqualsAndHashCode(callSuper = true)
+@Data
+public class WorkflowVersionResponse extends WorkflowVersionRequest {
+
+ private String id;
+ private String baseId;
+ private WorkflowVersionState state;
+ private boolean hasArtifact;
+ private Date creationTime;
+ private Date modificationTime;
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/NoDuplicatesValidator.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/NoDuplicatesValidator.java
index 2020bb83..7ade1ab0 100644
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/NoDuplicatesValidator.java
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/NoDuplicatesValidator.java
@@ -22,16 +22,16 @@ import java.util.Objects;
import java.util.Set;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
-import org.onap.sdc.workflow.persistence.types.ParameterEntity;
+import org.onap.sdc.workflow.api.types.Parameter;
-public class NoDuplicatesValidator implements ConstraintValidator<NoDuplicates, Collection<ParameterEntity>> {
+public class NoDuplicatesValidator implements ConstraintValidator<NoDuplicates, Collection<Parameter>> {
@Override
- public boolean isValid(Collection<ParameterEntity> parameterEntities, ConstraintValidatorContext context) {
- if (Objects.isNull(parameterEntities) || parameterEntities.size() < 2) {
+ public boolean isValid(Collection<Parameter> parameters, ConstraintValidatorContext context) {
+ if (Objects.isNull(parameters) || parameters.size() < 2) {
return true;
}
Set<String> testSet = new HashSet<>();
- return !parameterEntities.stream().anyMatch(s -> !testSet.add(s.getName()));
+ return parameters.stream().allMatch(parameter -> testSet.add(parameter.getName()));
}
}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterEntity.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterEntity.java
index bc813f24..4b57ba71 100644
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterEntity.java
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterEntity.java
@@ -16,20 +16,13 @@
package org.onap.sdc.workflow.persistence.types;
-import javax.validation.constraints.NotBlank;
-import javax.validation.constraints.NotNull;
-import javax.validation.constraints.Pattern;
import lombok.Data;
@Data
public class ParameterEntity {
private String id;
- @NotBlank(message = "Parameter Name may not be blank")
- @Pattern(regexp = "[A-Za-z0-9_ ]+", message = "Parameter name must contain only letters, digits and underscores")
private String name;
- @NotNull
private ParameterType type;
- @NotNull
private boolean mandatory;
}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/WorkflowVersion.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/WorkflowVersion.java
index 8a68db25..0699157f 100644
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/WorkflowVersion.java
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/WorkflowVersion.java
@@ -19,14 +19,13 @@ package org.onap.sdc.workflow.services.types;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
-import javax.validation.Valid;
import lombok.Data;
-import org.onap.sdc.workflow.api.validation.NoDuplicates;
+import lombok.NoArgsConstructor;
import org.onap.sdc.workflow.persistence.types.ParameterEntity;
-
@Data
+@NoArgsConstructor
public class WorkflowVersion {
private String id;
@@ -34,22 +33,14 @@ public class WorkflowVersion {
private String description;
private String baseId;
private WorkflowVersionState state;
- @Valid
- @NoDuplicates(message = "Inputs names must be unique")
private Collection<ParameterEntity> inputs = Collections.emptyList();
- @Valid
- @NoDuplicates(message = "Outputs names must be unique")
private Collection<ParameterEntity> outputs = Collections.emptyList();
private boolean hasArtifact;
private Date creationTime;
private Date modificationTime;
-
public WorkflowVersion(String id) {
this.id = id;
this.state = WorkflowVersionState.DRAFT;
}
-
- public WorkflowVersion() {
- }
}