aboutsummaryrefslogtreecommitdiffstats
path: root/workflow-designer-be/src/main/java
diff options
context:
space:
mode:
authorvempo <vitaliy.emporopulo@amdocs.com>2018-07-24 17:34:04 +0300
committervempo <vitaliy.emporopulo@amdocs.com>2018-07-25 11:39:10 +0300
commita52d50e788792a63e97a9176ab319d53db7a2853 (patch)
treeb1c2222cacf4b8192aea16d1e0315b1f005c5347 /workflow-designer-be/src/main/java
parent3c2665debb400aef7f0ed9e235698d2ff9f859db (diff)
Replaced old implementation at root
Old project files and directories has been moved under 'deprecated-workflow-designer'. The old project is not built by the CI anymore, but can be still built manually. New modules/directories have been moved up and integrated with the CI system. Change-Id: I1528c792bcbcce9e50bfc294a1328a20e72c91cf Issue-ID: SDC-1559 Signed-off-by: vempo <vitaliy.emporopulo@amdocs.com>
Diffstat (limited to 'workflow-designer-be/src/main/java')
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/RestUtils.java31
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/SpringBootWebApplication.java37
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/RestConstants.java31
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowController.java119
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowVersionController.java150
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/exceptionshandlers/CustomizedResponseEntityExceptionHandler.java97
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/CollectionWrapper.java43
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/VersionStateDto.java36
-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/persistence/ArtifactRepository.java34
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/ParameterRepository.java39
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/UniqueValueRepository.java26
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryImpl.java119
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryImpl.java180
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ArtifactEntity.java32
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterEntity.java34
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterPropertyName.java23
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterRole.java24
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterType.java25
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/UniqueValueEntity.java39
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/Workflow.java39
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/WorkflowElementType.java26
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/WorkflowProperty.java25
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/WorkflowVersion.java46
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/WorkflowVersionState.java36
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/SwaggerConfig.java24
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/ZusammenConfig.java32
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/filters/SessionContextFilter.java64
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/UniqueValueService.java123
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/WorkflowManager.java34
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/WorkflowNameComparator.java32
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/WorkflowVersionManager.java46
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/EntityNotFoundException.java24
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/InvalidArtifactException.java24
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/InvalidPaginationParameterException.java24
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/UniqueValueViolationException.java27
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionCreationException.java31
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionModificationException.java26
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionStateModificationException.java28
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/CollaborationConfiguration.java38
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImpl.java159
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImpl.java277
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/VersionMapper.java35
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/VersionStateMapper.java47
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/WorkflowMapper.java38
45 files changed, 2485 insertions, 0 deletions
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/RestUtils.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/RestUtils.java
new file mode 100644
index 00000000..b6259ccc
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/RestUtils.java
@@ -0,0 +1,31 @@
+package org.onap.sdc.workflow;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.onap.sdc.workflow.persistence.types.WorkflowVersionState;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
+
+public class RestUtils {
+
+ private RestUtils() {
+ }
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(RestUtils.class);
+
+ public static Set<WorkflowVersionState> mapVersionStateFilter(String versionStateFilter) {
+ Set<WorkflowVersionState> filter;
+ try {
+ filter = versionStateFilter == null ? null :
+ Arrays.stream(versionStateFilter.split(",")).map(WorkflowVersionState::valueOf)
+ .collect(Collectors.toSet());
+ } catch (Exception e) {
+ LOGGER.info(
+ "version state filter value is invalid and cannot be mapped to a set of version states, therefore it is set to empty set");
+ filter = Collections.emptySet();
+ }
+ return filter;
+ }
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/SpringBootWebApplication.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/SpringBootWebApplication.java
new file mode 100644
index 00000000..0feafd2a
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/SpringBootWebApplication.java
@@ -0,0 +1,37 @@
+/*
+ * 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;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory;
+import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
+import org.springframework.context.annotation.Bean;
+
+@SpringBootApplication
+public class SpringBootWebApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(SpringBootWebApplication.class, args);
+ }
+
+ @Bean
+ public ConfigurableServletWebServerFactory webServerFactory() {
+ return new JettyServletWebServerFactory();
+ }
+
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/RestConstants.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/RestConstants.java
new file mode 100644
index 00000000..817bebe1
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/RestConstants.java
@@ -0,0 +1,31 @@
+/*
+ * 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;
+
+public class RestConstants {
+
+ private RestConstants() {
+ }
+
+ public static final String USER_ID_HEADER_PARAM = "USER_ID";
+ public static final String SIZE_PARAM = "size";
+ public static final String PAGE_PARAM = "page";
+ public static final String SORT_PARAM = "sort";
+ public static final String SORT_FIELD_NAME = "name";
+ public static final int SIZE_DEFAULT = 20;
+ public static final int PAGE_DEFAULT = 0;
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowController.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowController.java
new file mode 100644
index 00000000..7027985f
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowController.java
@@ -0,0 +1,119 @@
+/*
+ * 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;
+
+import static org.onap.sdc.workflow.RestUtils.mapVersionStateFilter;
+import static org.onap.sdc.workflow.api.RestConstants.SIZE_DEFAULT;
+import static org.onap.sdc.workflow.api.RestConstants.SORT_FIELD_NAME;
+import static org.onap.sdc.workflow.api.RestConstants.SORT_PARAM;
+import static org.onap.sdc.workflow.api.RestConstants.USER_ID_HEADER_PARAM;
+
+import com.google.common.collect.ImmutableSet;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import java.util.Arrays;
+import java.util.Set;
+import org.onap.sdc.workflow.api.types.CollectionWrapper;
+import org.onap.sdc.workflow.persistence.types.Workflow;
+import org.onap.sdc.workflow.services.WorkflowManager;
+import org.onap.sdc.workflow.services.exceptions.InvalidPaginationParameterException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.web.PageableDefault;
+import org.springframework.data.web.SortDefault;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestHeader;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+@RequestMapping("/workflows")
+@Api("Workflows")
+@RestController("workflowController")
+public class WorkflowController {
+
+ private final WorkflowManager workflowManager;
+
+ @Autowired
+ public WorkflowController(@Qualifier("workflowManager") WorkflowManager workflowManager) {
+ this.workflowManager = workflowManager;
+ }
+
+ @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
+ @ApiOperation("List workflows")
+ public CollectionWrapper<Workflow> list(
+ @ApiParam(value = "Filter by version state", allowableValues = "DRAFT,CERTIFIED")
+ @RequestParam(value = "versionState", required = false) String versionStateFilter,
+ @PageableDefault(size = SIZE_DEFAULT)
+ @SortDefault.SortDefaults({@SortDefault(sort = SORT_FIELD_NAME, direction = Sort.Direction.ASC)})
+ Pageable pageable, @RequestHeader(USER_ID_HEADER_PARAM) String user) {
+ PageRequest pageRequest = createPageRequest(pageable);
+ return new CollectionWrapper<>(pageRequest.getPageSize(), pageRequest.getPageNumber(),
+ workflowManager.list(mapVersionStateFilter(versionStateFilter), pageRequest));
+ }
+
+ @PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE)
+ @ApiOperation("Create workflow")
+ public ResponseEntity<Workflow> create(@Validated @RequestBody Workflow workflow,
+ @RequestHeader(USER_ID_HEADER_PARAM) String user) {
+ return new ResponseEntity<>(workflowManager.create(workflow), HttpStatus.CREATED);
+ }
+
+ @GetMapping(path = "/{workflowId}")
+ @ApiOperation("Get workflow")
+ public Workflow get(@PathVariable("workflowId") String workflowId,
+ @RequestHeader(USER_ID_HEADER_PARAM) String user) {
+ Workflow workflow = new Workflow();
+ workflow.setId(workflowId);
+ return workflowManager.get(workflow);
+ }
+
+ @PutMapping(path = "/{workflowId}", consumes = MediaType.APPLICATION_JSON_VALUE)
+ @ApiOperation("Update workflow")
+ public Workflow update(@RequestBody Workflow workflow, @PathVariable("workflowId") String workflowId,
+ @RequestHeader(USER_ID_HEADER_PARAM) String user) {
+ workflow.setId(workflowId);
+ workflowManager.update(workflow);
+ return workflow;
+ }
+
+
+ private PageRequest createPageRequest(Pageable pageable) {
+ Set<String> validSortFields = ImmutableSet.of(SORT_FIELD_NAME);
+ Sort sort = pageable.getSort();
+ for (Sort.Order order : sort) {
+ String sortFieldName = order.getProperty();
+ if (!sortFieldName.equalsIgnoreCase(SORT_FIELD_NAME)) {
+ throw new InvalidPaginationParameterException(SORT_PARAM, sortFieldName,
+ "is not supported. Supported values are: " + Arrays.toString(validSortFields.toArray()));
+ }
+ }
+ return PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), sort);
+ }
+}
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
new file mode 100644
index 00000000..91995bd0
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowVersionController.java
@@ -0,0 +1,150 @@
+/*
+ * 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;
+
+import static org.onap.sdc.workflow.RestUtils.mapVersionStateFilter;
+import static org.onap.sdc.workflow.api.RestConstants.USER_ID_HEADER_PARAM;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import org.onap.sdc.workflow.api.types.CollectionWrapper;
+import org.onap.sdc.workflow.api.types.VersionStateDto;
+import org.onap.sdc.workflow.persistence.types.ArtifactEntity;
+import org.onap.sdc.workflow.persistence.types.WorkflowVersion;
+import org.onap.sdc.workflow.services.WorkflowVersionManager;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.core.io.InputStreamResource;
+import org.springframework.core.io.Resource;
+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;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestHeader;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
+
+@RequestMapping("/workflows/{workflowId}/versions")
+@Api("Workflow versions")
+@RestController("workflowsVersionController")
+public class WorkflowVersionController {
+
+ private final WorkflowVersionManager workflowVersionManager;
+ private Validator validator;
+
+ @InitBinder
+ private void initBinder(WebDataBinder binder) {
+ binder.addValidators(validator);
+ }
+
+ @Autowired
+ public WorkflowVersionController(
+ @Qualifier("workflowVersionManager") WorkflowVersionManager workflowVersionManager,
+ @Qualifier("workflowVersionValidator") Validator validator ) {
+ this.workflowVersionManager = workflowVersionManager;
+ this.validator = validator;
+ }
+
+ @GetMapping
+ @ApiOperation("List workflow versions")
+ public CollectionWrapper<WorkflowVersion> list(@PathVariable("workflowId") String workflowId,
+ @ApiParam(value = "Filter by state", allowableValues = "DRAFT,CERTIFIED")
+ @RequestParam(value = "state", required = false) String stateFilter,
+ @RequestHeader(USER_ID_HEADER_PARAM) String user) {
+ return new CollectionWrapper<>(workflowVersionManager.list(workflowId, mapVersionStateFilter(stateFilter)));
+ }
+
+ @PostMapping
+ @ApiOperation("Create workflow version")
+ public ResponseEntity<WorkflowVersion> create(@RequestBody @Validated WorkflowVersion version,
+ @PathVariable("workflowId") String workflowId,
+ @RequestParam(value = "baseVersionId", required = false) String baseVersionId,
+ @RequestHeader(USER_ID_HEADER_PARAM) String user) {
+ WorkflowVersion createdVersion = workflowVersionManager.create(workflowId, baseVersionId, version);
+ return new ResponseEntity<>(createdVersion, HttpStatus.CREATED);
+ }
+
+ @GetMapping("/{versionId}")
+ @ApiOperation("Get workflow version")
+ public WorkflowVersion get(@PathVariable("workflowId") String workflowId,
+ @PathVariable("versionId") String versionId, @RequestHeader(USER_ID_HEADER_PARAM) String user) {
+ return workflowVersionManager.get(workflowId, versionId);
+ }
+
+ @PutMapping("/{versionId}")
+ @ApiOperation("Update workflow version")
+ public void update(@RequestBody @Validated WorkflowVersion version, @PathVariable("workflowId") String workflowId,
+ @PathVariable("versionId") String versionId, @RequestHeader(USER_ID_HEADER_PARAM) String user) {
+ version.setId(versionId);
+ workflowVersionManager.update(workflowId, version);
+ }
+
+ @GetMapping("/{versionId}/state")
+ @ApiOperation("Get workflow version state")
+ public VersionStateDto getState(@PathVariable("workflowId") String workflowId,
+ @PathVariable("versionId") String versionId, @RequestHeader(USER_ID_HEADER_PARAM) String user) {
+ return new VersionStateDto(workflowVersionManager.getState(workflowId, versionId));
+ }
+
+ @PostMapping("/{versionId}/state")
+ @ApiOperation("Update workflow version state")
+ public VersionStateDto updateState(@RequestBody VersionStateDto state,
+ @PathVariable("workflowId") String workflowId, @PathVariable("versionId") String versionId,
+ @RequestHeader(USER_ID_HEADER_PARAM) String user) {
+ workflowVersionManager.updateState(workflowId, versionId, state.getName());
+ return new VersionStateDto(state.getName());
+ }
+
+ @PutMapping("/{versionId}/artifact")
+ @ApiOperation("Create/update artifact of a version")
+ public void uploadArtifact(@RequestBody MultipartFile fileToUpload, @PathVariable("workflowId") String workflowId,
+ @PathVariable("versionId") String versionId, @RequestHeader(USER_ID_HEADER_PARAM) String user) {
+ workflowVersionManager.uploadArtifact(workflowId, versionId, fileToUpload);
+ }
+
+ @GetMapping("/{versionId}/artifact")
+ @ApiOperation("Download workflow version artifact")
+ public ResponseEntity<Resource> getArtifact(@PathVariable("workflowId") String workflowId,
+ @PathVariable("versionId") String versionId, @RequestHeader(USER_ID_HEADER_PARAM) String user) {
+ ArtifactEntity artifact = workflowVersionManager.getArtifact(workflowId, versionId);
+
+ return ResponseEntity.ok()
+ .header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + artifact.getFileName())
+ .contentType(MediaType.APPLICATION_OCTET_STREAM)
+ .body(new InputStreamResource(artifact.getArtifactData()));
+ }
+
+ @DeleteMapping("/{versionId}/artifact")
+ @ApiOperation("Delete workflow version artifact")
+ public void deleteArtifact(@PathVariable("workflowId") String workflowId,
+ @PathVariable("versionId") String versionId, @RequestHeader(USER_ID_HEADER_PARAM) String user) {
+ workflowVersionManager.deleteArtifact(workflowId, versionId);
+ }
+}
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
new file mode 100644
index 00000000..ca6111df
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/exceptionshandlers/CustomizedResponseEntityExceptionHandler.java
@@ -0,0 +1,97 @@
+/*
+ * 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.exceptionshandlers;
+
+import static org.springframework.http.HttpStatus.BAD_REQUEST;
+import static org.springframework.http.HttpStatus.FORBIDDEN;
+import static org.springframework.http.HttpStatus.NOT_FOUND;
+import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY;
+
+import org.onap.sdc.workflow.services.exceptions.EntityNotFoundException;
+import org.onap.sdc.workflow.services.exceptions.InvalidArtifactException;
+import org.onap.sdc.workflow.services.exceptions.InvalidPaginationParameterException;
+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.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.validation.FieldError;
+import org.springframework.web.bind.MethodArgumentNotValidException;
+import org.springframework.web.bind.ServletRequestBindingException;
+import org.springframework.web.bind.annotation.ControllerAdvice;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.context.request.WebRequest;
+import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
+
+@ControllerAdvice
+@RestController
+public class CustomizedResponseEntityExceptionHandler extends ResponseEntityExceptionHandler {
+
+ @ExceptionHandler(UniqueValueViolationException.class)
+ public final ResponseEntity<String> handleUniqueValueViolationException(
+ UniqueValueViolationException exception) {
+ return new ResponseEntity<>(exception.getMessage(), UNPROCESSABLE_ENTITY);
+ }
+
+ @ExceptionHandler(EntityNotFoundException.class)
+ public final ResponseEntity<String> handleWorkflowNotFoundException(
+ Exception exception) {
+ return new ResponseEntity<>(exception.getMessage(), NOT_FOUND);
+ }
+
+ @ExceptionHandler({InvalidPaginationParameterException.class})
+ public final ResponseEntity<String> handlePaginationException(InvalidPaginationParameterException exception) {
+ return new ResponseEntity<>(exception.getMessage(), BAD_REQUEST);
+ }
+
+ //For workflowVersionValidator exception
+ @Override
+ protected final ResponseEntity<Object> handleMethodArgumentNotValid(final MethodArgumentNotValidException e,
+ final HttpHeaders headers,
+ final HttpStatus status,
+ final WebRequest request) {
+
+ FieldError result = e.getBindingResult().getFieldError();
+ return new ResponseEntity<>(result.getDefaultMessage(), BAD_REQUEST);
+ }
+
+ //For missing header exceptions
+ @Override
+ public ResponseEntity<Object> handleServletRequestBindingException(ServletRequestBindingException ex,
+ HttpHeaders headers, HttpStatus status,
+ WebRequest request) {
+ return new ResponseEntity<>(ex.getMessage(), BAD_REQUEST);
+ }
+
+
+ @ExceptionHandler({InvalidArtifactException.class, VersionModificationException.class,
+ VersionStateModificationException.class})
+ public final ResponseEntity<String> handleInvalidArtifactException(
+ Exception exception) {
+ return new ResponseEntity<>(exception.getMessage(), UNPROCESSABLE_ENTITY);
+ }
+
+
+ @ExceptionHandler(VersionCreationException.class)
+ public final ResponseEntity<String> handleVersioningErrorException(
+ VersionCreationException exception) {
+ return new ResponseEntity<>(exception.getMessage(), FORBIDDEN);
+ }
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/CollectionWrapper.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/CollectionWrapper.java
new file mode 100644
index 00000000..1e11bc90
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/CollectionWrapper.java
@@ -0,0 +1,43 @@
+/*
+ * 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.types;
+
+import java.util.Collection;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@NoArgsConstructor
+public class CollectionWrapper<T> {
+
+ private int total;
+ private int size;
+ private int page;
+ private Collection<T> results;
+
+ public CollectionWrapper(int size, int page, Collection<T> results) {
+ this.results = results;
+ this.size = size;
+ this.page = page;
+ this.total = results.size();
+ }
+
+ public CollectionWrapper(Collection<T> results) {
+ this.results = results;
+ this.total = results.size();
+ }
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/VersionStateDto.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/VersionStateDto.java
new file mode 100644
index 00000000..a7f43cdd
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/VersionStateDto.java
@@ -0,0 +1,36 @@
+/*
+ * 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.types;
+
+import java.util.List;
+import lombok.Data;
+import org.onap.sdc.workflow.persistence.types.WorkflowVersionState;
+
+@Data
+public class VersionStateDto {
+
+ private WorkflowVersionState name;
+ private List<WorkflowVersionState> nextStates;
+
+ public VersionStateDto() {
+ }
+
+ public VersionStateDto(WorkflowVersionState state) {
+ name = state;
+ nextStates = state.getNextStates();
+ }
+}
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
new file mode 100644
index 00000000..03101042
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validator/WorkflowVersionValidator.java
@@ -0,0 +1,61 @@
+/*
+ * 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/persistence/ArtifactRepository.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/ArtifactRepository.java
new file mode 100644
index 00000000..ed9371e6
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/ArtifactRepository.java
@@ -0,0 +1,34 @@
+/*
+ * 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.persistence;
+
+
+import java.util.Optional;
+import org.onap.sdc.workflow.persistence.types.ArtifactEntity;
+
+
+public interface ArtifactRepository {
+
+ void update(String id, String versionId,ArtifactEntity artifactEntity);
+
+ Optional<ArtifactEntity> get(String id, String versionId);
+
+ void createStructure(String id, String versionId);
+
+ void delete(String id, String versionId);
+
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/ParameterRepository.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/ParameterRepository.java
new file mode 100644
index 00000000..9f7fb1ad
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/ParameterRepository.java
@@ -0,0 +1,39 @@
+/*
+ * 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.persistence;
+
+import java.util.Collection;
+import org.onap.sdc.workflow.persistence.types.ParameterEntity;
+import org.onap.sdc.workflow.persistence.types.ParameterRole;
+
+
+public interface ParameterRepository {
+
+ void createStructure(String id, String versionId);
+
+ Collection<ParameterEntity> list(String id, String versionId, ParameterRole role);
+
+ void deleteAll(String id, String versionId, ParameterRole role);
+
+ ParameterEntity get(String id, String versionId, String parameterId);
+
+ void delete(String id, String versionId, String parameterId);
+
+ ParameterEntity create(String id, String versionId , ParameterRole role, ParameterEntity parameter);
+
+ void update(String id, String versionId, ParameterRole role, ParameterEntity parameter);
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/UniqueValueRepository.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/UniqueValueRepository.java
new file mode 100644
index 00000000..cf7b0633
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/UniqueValueRepository.java
@@ -0,0 +1,26 @@
+/*
+ * 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.persistence;
+
+import org.onap.sdc.workflow.persistence.types.UniqueValueEntity;
+import org.springframework.data.cassandra.repository.CassandraRepository;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface UniqueValueRepository extends CassandraRepository<UniqueValueEntity, UniqueValueEntity> {
+
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryImpl.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryImpl.java
new file mode 100644
index 00000000..3c528db1
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryImpl.java
@@ -0,0 +1,119 @@
+/*
+ * 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.persistence.impl;
+
+import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement;
+import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext;
+
+import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element;
+import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement;
+import com.amdocs.zusammen.datatypes.SessionContext;
+import com.amdocs.zusammen.datatypes.item.Action;
+import com.amdocs.zusammen.datatypes.item.ElementContext;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.Optional;
+import org.apache.commons.io.IOUtils;
+import org.onap.sdc.workflow.persistence.ArtifactRepository;
+import org.onap.sdc.workflow.persistence.types.ArtifactEntity;
+import org.onap.sdc.workflow.persistence.types.WorkflowElementType;
+import org.openecomp.core.zusammen.api.ZusammenAdaptor;
+import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public class ArtifactRepositoryImpl implements ArtifactRepository {
+
+ private static final String FILE_NAME_PROPERTY = "fileName";
+ private static final String EMPTY_DATA = "{}";
+ private ZusammenAdaptor zusammenAdaptor = ZusammenAdaptorFactory.getInstance().createInterface();
+
+
+ @Override
+ public void update(String id, String versionId, ArtifactEntity artifactEntity) {
+
+ ZusammenElement artifactElement = buildStructuralElement(WorkflowElementType.ARTIFACT.name(), Action.UPDATE);
+ artifactElement.setData(artifactEntity.getArtifactData());
+ artifactElement.getInfo().addProperty(FILE_NAME_PROPERTY, artifactEntity.getFileName());
+
+ SessionContext context = createSessionContext();
+ ElementContext elementContext = new ElementContext(id, versionId);
+
+ zusammenAdaptor
+ .saveElement(context, elementContext, artifactElement, "Update WorkflowVersion Artifact Element");
+ }
+
+ @Override
+ public Optional<ArtifactEntity> get(String id, String versionId) {
+ SessionContext context = createSessionContext();
+ ElementContext elementContext = new ElementContext(id, versionId);
+
+ Optional<Element> elementOptional =
+ zusammenAdaptor.getElementByName(context, elementContext, null, WorkflowElementType.ARTIFACT.name());
+
+ if (!elementOptional.isPresent() || hasEmptyData(elementOptional.get().getData())) {
+ return Optional.empty();
+ }
+
+ Element artifactElement = elementOptional.get();
+
+ ArtifactEntity artifact = new ArtifactEntity(artifactElement.getInfo().getProperty(FILE_NAME_PROPERTY),
+ artifactElement.getData());
+
+ return Optional.of(artifact);
+ }
+
+ @Override
+ public void createStructure(String id, String versionId) {
+ SessionContext context = createSessionContext();
+ ElementContext elementContext = new ElementContext(id, versionId);
+
+ ZusammenElement artifactElement = buildStructuralElement(WorkflowElementType.ARTIFACT.name(), Action.CREATE);
+ artifactElement.setData(new ByteArrayInputStream(EMPTY_DATA.getBytes()));
+
+ zusammenAdaptor
+ .saveElement(context, elementContext, artifactElement, "Create WorkflowVersion Artifact Element");
+
+ }
+
+ @Override
+ public void delete(String id, String versionId) {
+ SessionContext context = createSessionContext();
+ ElementContext elementContext = new ElementContext(id, versionId);
+
+ ZusammenElement artifactElement = buildStructuralElement(WorkflowElementType.ARTIFACT.name(), Action.UPDATE);
+ artifactElement.setData(new ByteArrayInputStream(EMPTY_DATA.getBytes()));
+ artifactElement.getInfo().getProperties().remove(FILE_NAME_PROPERTY);
+
+ zusammenAdaptor
+ .saveElement(context, elementContext, artifactElement, "Delete WorkflowVersion Artifact Data");
+
+ }
+
+ private boolean hasEmptyData(InputStream elementData) {
+
+ byte[] byteElementData;
+ try {
+ byteElementData = IOUtils.toByteArray(elementData);
+ } catch (IOException ex) {
+ return false;
+ }
+ return Arrays.equals(EMPTY_DATA.getBytes(), byteElementData);
+ }
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryImpl.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryImpl.java
new file mode 100644
index 00000000..468e93fe
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryImpl.java
@@ -0,0 +1,180 @@
+/*
+ * 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.persistence.impl;
+
+import static org.openecomp.core.zusammen.api.ZusammenUtil.buildElement;
+import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement;
+import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext;
+
+import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element;
+import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo;
+import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement;
+import com.amdocs.zusammen.datatypes.Id;
+import com.amdocs.zusammen.datatypes.SessionContext;
+import com.amdocs.zusammen.datatypes.item.Action;
+import com.amdocs.zusammen.datatypes.item.ElementContext;
+import com.amdocs.zusammen.datatypes.item.Info;
+import java.util.Collection;
+import java.util.Optional;
+import java.util.stream.Collectors;
+import org.onap.sdc.workflow.persistence.ParameterRepository;
+import org.onap.sdc.workflow.persistence.types.ParameterEntity;
+import org.onap.sdc.workflow.persistence.types.ParameterPropertyName;
+import org.onap.sdc.workflow.persistence.types.ParameterRole;
+import org.onap.sdc.workflow.persistence.types.ParameterType;
+import org.onap.sdc.workflow.persistence.types.WorkflowElementType;
+import org.openecomp.core.zusammen.api.ZusammenAdaptor;
+import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory;
+import org.openecomp.types.ElementPropertyName;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public class ParameterRepositoryImpl implements ParameterRepository {
+
+ private ZusammenAdaptor zusammenAdaptor = ZusammenAdaptorFactory.getInstance().createInterface();
+
+ @Override
+ public void createStructure(String id, String versionId) {
+
+ SessionContext context = createSessionContext();
+ ElementContext elementContext = new ElementContext(id, versionId);
+
+ ZusammenElement inputsElement = buildStructuralElement(WorkflowElementType.INPUTS.name(), Action.CREATE);
+ ZusammenElement outputsElement = buildStructuralElement(WorkflowElementType.OUTPUTS.name(), Action.CREATE);
+
+ zusammenAdaptor.saveElement(context, elementContext, inputsElement, "Create WorkflowVersion INPUTS Element");
+ zusammenAdaptor.saveElement(context, elementContext, outputsElement, "Create WorkflowVersion OUTPUTS Element");
+ }
+
+ @Override
+ public Collection<ParameterEntity> list(String id, String versionId, ParameterRole role) {
+
+ SessionContext context = createSessionContext();
+ ElementContext elementContext = new ElementContext(id, versionId);
+
+ return zusammenAdaptor.listElementsByName(context, elementContext, null, getParentElementType(role)).stream()
+ .map(this::mapElementInfoToParameter).collect(Collectors.toList());
+
+ }
+
+ @Override
+ public void deleteAll(String id, String versionId, ParameterRole role) {
+
+ SessionContext context = createSessionContext();
+ ElementContext elementContext = new ElementContext(id, versionId);
+
+ Optional<ElementInfo> optionalParentElement =
+ zusammenAdaptor.getElementInfoByName(context, elementContext, null, getParentElementType(role));
+
+ if (!optionalParentElement.isPresent()) {
+ return;
+ }
+ ZusammenElement parentElement = buildElement(optionalParentElement.get().getId(), Action.IGNORE);
+ parentElement.setSubElements(optionalParentElement.get().getSubElements().stream()
+ .map(parameter -> buildElement(parameter.getId(),
+ Action.DELETE)).collect(Collectors.toList()));
+
+ zusammenAdaptor.saveElement(context, elementContext, parentElement, "Delete all " + role);
+ }
+
+ @Override
+ public ParameterEntity get(String id, String versionId, String parameterId) {
+
+ SessionContext context = createSessionContext();
+ ElementContext elementContext = new ElementContext(id, versionId);
+
+ Optional<ElementInfo> element = zusammenAdaptor.getElementInfo(context, elementContext, new Id(parameterId));
+
+ return element.map(this::mapElementInfoToParameter).orElse(null);
+ }
+
+ @Override
+ public void delete(String id, String versionId, String parameterId) {
+ SessionContext context = createSessionContext();
+ ElementContext elementContext = new ElementContext(id, versionId);
+
+ ZusammenElement parameterElement = buildElement(new Id(parameterId), Action.DELETE);
+
+ zusammenAdaptor.saveElement(context, elementContext, parameterElement,
+ String.format("Delete Parameter with id %s", parameterId));
+
+ }
+
+ @Override
+ public ParameterEntity create(String id, String versionId, ParameterRole role, ParameterEntity parameter) {
+
+ ZusammenElement parameterElement = parameterToZusammenElement(parameter, role, Action.CREATE);
+ ZusammenElement parentElement = buildStructuralElement(getParentElementType(role), Action.IGNORE);
+ parentElement.addSubElement(parameterElement);
+
+ SessionContext context = createSessionContext();
+ ElementContext elementContext = new ElementContext(id, versionId);
+
+ Element savedElement = zusammenAdaptor.saveElement(context, elementContext, parentElement,
+ "Create WorkflowVersion Parameter Element");
+
+ parameter.setId(savedElement.getSubElements().iterator().next().getElementId().getValue());
+ return parameter;
+ }
+
+ @Override
+ public void update(String id, String versionId, ParameterRole role, ParameterEntity parameter) {
+
+ SessionContext context = createSessionContext();
+ ElementContext elementContext = new ElementContext(id, versionId);
+
+ ZusammenElement parameterElement = parameterToZusammenElement(parameter, role, Action.UPDATE);
+
+ zusammenAdaptor.saveElement(context, elementContext, parameterElement, "Update WorkflowVersion Parameter");
+ }
+
+ private ZusammenElement parameterToZusammenElement(ParameterEntity parameter, ParameterRole role, Action action) {
+
+ ZusammenElement parameterElement =
+ buildElement(parameter.getId() == null ? null : new Id(parameter.getId()), action);
+ Info info = new Info();
+ info.setName(parameter.getName());
+ info.addProperty(ElementPropertyName.elementType.name(), WorkflowElementType.valueOf(role.name()));
+ info.addProperty(ParameterPropertyName.TYPE.name(), parameter.getType());
+ info.addProperty(ParameterPropertyName.mandatory.name(), parameter.isMandatory());
+ parameterElement.setInfo(info);
+
+ return parameterElement;
+ }
+
+ private ParameterEntity mapElementInfoToParameter(ElementInfo elementInfo) {
+ ParameterEntity parameterEntity = new ParameterEntity();
+ parameterEntity.setId(elementInfo.getId().getValue());
+ parameterEntity.setName(elementInfo.getInfo().getName());
+ parameterEntity
+ .setType(ParameterType.valueOf(elementInfo.getInfo().getProperty(ParameterPropertyName.TYPE.name())));
+ parameterEntity.setMandatory(elementInfo.getInfo().getProperty(ParameterPropertyName.mandatory.name()));
+ return parameterEntity;
+ }
+
+ private static String getParentElementType(ParameterRole role) {
+ switch (role) {
+ case INPUT:
+ return WorkflowElementType.INPUTS.name();
+ case OUTPUT:
+ return WorkflowElementType.OUTPUTS.name();
+ default:
+ throw new IllegalArgumentException("Wrong Element Type");
+ }
+ }
+
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ArtifactEntity.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ArtifactEntity.java
new file mode 100644
index 00000000..287acb45
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ArtifactEntity.java
@@ -0,0 +1,32 @@
+/*
+ * 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.persistence.types;
+
+import java.io.InputStream;
+import lombok.Data;
+
+@Data
+public class ArtifactEntity {
+
+ private String fileName;
+ private InputStream artifactData;
+
+ public ArtifactEntity(String fileName, InputStream artifactData) {
+ this.fileName = fileName;
+ this.artifactData = artifactData;
+ }
+}
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
new file mode 100644
index 00000000..7c957d85
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterEntity.java
@@ -0,0 +1,34 @@
+/*
+ * 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.persistence.types;
+
+import javax.validation.constraints.Pattern;
+import lombok.Data;
+import javax.validation.constraints.NotNull;
+
+@Data
+public class ParameterEntity {
+
+ private String id;
+ @NotNull(message = "Parameter name may not be null")
+ @Pattern(regexp = "[A-Za-z0-9_]*", message = "The field 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/persistence/types/ParameterPropertyName.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterPropertyName.java
new file mode 100644
index 00000000..fa17bf69
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterPropertyName.java
@@ -0,0 +1,23 @@
+/*
+ * 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.persistence.types;
+
+public enum ParameterPropertyName {
+
+ TYPE,
+ mandatory
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterRole.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterRole.java
new file mode 100644
index 00000000..9f5aacfe
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterRole.java
@@ -0,0 +1,24 @@
+/*
+ * 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.persistence.types;
+
+public enum ParameterRole {
+
+ INPUT,
+ OUTPUT
+
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterType.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterType.java
new file mode 100644
index 00000000..04d09c01
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterType.java
@@ -0,0 +1,25 @@
+/*
+ * 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.persistence.types;
+
+public enum ParameterType {
+ STRING,
+ INTEGER,
+ FLOAT,
+ BOOLEAN,
+ TIMESTAMP
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/UniqueValueEntity.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/UniqueValueEntity.java
new file mode 100644
index 00000000..ee7172b6
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/UniqueValueEntity.java
@@ -0,0 +1,39 @@
+/*
+ * 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.persistence.types;
+
+import static org.springframework.data.cassandra.core.cql.PrimaryKeyType.PARTITIONED;
+
+import lombok.Data;
+import org.springframework.data.cassandra.core.mapping.PrimaryKeyColumn;
+import org.springframework.data.cassandra.core.mapping.Table;
+
+@Table("unique_value")
+@Data
+public class UniqueValueEntity {
+
+ @PrimaryKeyColumn(ordinal = 0, type = PARTITIONED)
+ private String type;
+
+ @PrimaryKeyColumn(ordinal = 1, type = PARTITIONED)
+ private String value;
+
+ public UniqueValueEntity(String type, String value) {
+ this.type = type;
+ this.value = value;
+ }
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/Workflow.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/Workflow.java
new file mode 100644
index 00000000..72e62778
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/Workflow.java
@@ -0,0 +1,39 @@
+/*
+ * 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.persistence.types;
+
+
+import java.util.Collection;
+import java.util.Set;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Pattern;
+import javax.validation.constraints.Size;
+import lombok.Data;
+
+
+@Data
+public class Workflow {
+
+ private String id;
+ @NotNull(message = "Workflow name may not be null")
+ @Size(min = 6, max = 30, message = "The field must be at least 6 characters, and less than 30 characters")
+ @Pattern(regexp = "[A-Za-z0-9_]*", message = "The field must contain only letters, digits and underscores")
+ private String name;
+ private String description;
+ private Set<WorkflowVersionState> versionStates;
+ private Collection<WorkflowVersion> versions;
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/WorkflowElementType.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/WorkflowElementType.java
new file mode 100644
index 00000000..10de37e0
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/WorkflowElementType.java
@@ -0,0 +1,26 @@
+/*
+ * 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.persistence.types;
+
+public enum WorkflowElementType {
+
+ ARTIFACT,
+ INPUTS,
+ OUTPUTS,
+ INPUT,
+ OUTPUT
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/WorkflowProperty.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/WorkflowProperty.java
new file mode 100644
index 00000000..90fb3085
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/WorkflowProperty.java
@@ -0,0 +1,25 @@
+/*
+ * 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.persistence.types;
+
+public final class WorkflowProperty {
+
+ private WorkflowProperty() {
+ }
+
+ public static final String CATEGORY = "category";
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/WorkflowVersion.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/WorkflowVersion.java
new file mode 100644
index 00000000..1c828d43
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/WorkflowVersion.java
@@ -0,0 +1,46 @@
+/*
+ * 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.persistence.types;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import lombok.Data;
+
+
+@Data
+public class WorkflowVersion {
+
+ private String id;
+ private String name;
+ private String description;
+ private String baseId;
+ private WorkflowVersionState state;
+ private Collection<ParameterEntity> inputs = Collections.emptyList();
+ private Collection<ParameterEntity> outputs = Collections.emptyList();
+ private Date creationTime;
+ private Date modificationTime;
+
+
+ public WorkflowVersion(String id) {
+ this.id = id;
+ this.state = WorkflowVersionState.DRAFT;
+ }
+
+ public WorkflowVersion() {
+ }
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/WorkflowVersionState.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/WorkflowVersionState.java
new file mode 100644
index 00000000..2be1d4da
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/WorkflowVersionState.java
@@ -0,0 +1,36 @@
+/*
+ * 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.persistence.types;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+public enum WorkflowVersionState {
+
+ CERTIFIED, DRAFT(CERTIFIED);
+
+ private final List<WorkflowVersionState> nextStates;
+
+ WorkflowVersionState(WorkflowVersionState... nextStates) {
+ this.nextStates = Collections.unmodifiableList(Arrays.asList(nextStates));
+ }
+
+ public List<WorkflowVersionState> getNextStates() {
+ return nextStates;
+ }
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/SwaggerConfig.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/SwaggerConfig.java
new file mode 100644
index 00000000..5105114f
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/SwaggerConfig.java
@@ -0,0 +1,24 @@
+package org.onap.sdc.workflow.server.config;
+
+import static springfox.documentation.builders.PathSelectors.regex;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import springfox.documentation.builders.RequestHandlerSelectors;
+import springfox.documentation.spi.DocumentationType;
+import springfox.documentation.spring.web.plugins.Docket;
+import springfox.documentation.swagger2.annotations.EnableSwagger2;
+
+@Configuration
+@EnableSwagger2
+public class SwaggerConfig {
+
+ @Bean
+ public Docket api() {
+ return new Docket(DocumentationType.SWAGGER_2)
+ .select()
+ .apis(RequestHandlerSelectors.basePackage("org.onap.sdc.workflow.api"))
+ .paths(regex("/workflows.*"))
+ .build();
+ }
+} \ No newline at end of file
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/ZusammenConfig.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/ZusammenConfig.java
new file mode 100644
index 00000000..092c3464
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/ZusammenConfig.java
@@ -0,0 +1,32 @@
+package org.onap.sdc.workflow.server.config;
+
+import javax.annotation.PostConstruct;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class ZusammenConfig {
+
+ @Value("${zusammen-tenant:workflow}")
+ private String tenant;
+ @Value("${spring.data.cassandra.contact-points:localhost}")
+ private String cassandraAddress;
+ @Value("${spring.data.cassandra.username:}")
+ private String cassandraUser;
+ @Value("${spring.data.cassandra.password:}")
+ private String cassandraPassword;
+ @Value("${zusammen.cassandra.isAuthenticate:false}")
+ private String cassandraAuth;
+
+ @PostConstruct
+ public void init(){
+ System.setProperty("cassandra.nodes", cassandraAddress);
+ System.setProperty("cassandra.user", cassandraUser);
+ System.setProperty("cassandra.password", cassandraPassword);
+ System.setProperty("cassandra.authenticate", Boolean.toString(Boolean.valueOf(cassandraAuth)));
+ }
+
+ public String getTenant() {
+ return tenant;
+ }
+} \ No newline at end of file
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/filters/SessionContextFilter.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/filters/SessionContextFilter.java
new file mode 100644
index 00000000..07d8eee7
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/filters/SessionContextFilter.java
@@ -0,0 +1,64 @@
+package org.onap.sdc.workflow.server.filters;
+
+import static org.onap.sdc.workflow.api.RestConstants.USER_ID_HEADER_PARAM;
+
+import java.io.IOException;
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import org.onap.sdc.workflow.server.config.ZusammenConfig;
+import org.openecomp.sdc.common.session.SessionContextProvider;
+import org.openecomp.sdc.common.session.SessionContextProviderFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+public class SessionContextFilter implements Filter {
+
+ private ZusammenConfig zusammenConfig;
+
+ @Autowired
+ public SessionContextFilter(ZusammenConfig zusammenConfig) {
+ this.zusammenConfig = zusammenConfig;
+ }
+
+ @Override
+ public void init(FilterConfig filterConfig) {
+ // not implemented
+ }
+
+ @Override
+ public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
+ throws IOException, ServletException {
+ SessionContextProvider contextProvider = SessionContextProviderFactory.getInstance().createInterface();
+
+ try {
+ if (servletRequest instanceof HttpServletRequest) {
+ contextProvider.create(getUser(servletRequest), getTenant());
+ }
+
+ filterChain.doFilter(servletRequest, servletResponse);
+ } finally {
+ contextProvider.close();
+ }
+ }
+
+ @Override
+ public void destroy() {
+ // not implemented
+ }
+
+ private String getUser(ServletRequest servletRequest) {
+ return "GLOBAL_USER";
+ // TODO: 7/11/2018 get user from header when collaboration will be supported
+ //((HttpServletRequest) servletRequest).getHeader(USER_ID_HEADER_PARAM);
+ }
+
+ private String getTenant() {
+ return zusammenConfig.getTenant();
+ }
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/UniqueValueService.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/UniqueValueService.java
new file mode 100644
index 00000000..0a8b640a
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/UniqueValueService.java
@@ -0,0 +1,123 @@
+/*
+ * 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.services;
+
+import java.util.Optional;
+import org.apache.commons.lang.ArrayUtils;
+import org.onap.sdc.workflow.persistence.UniqueValueRepository;
+import org.onap.sdc.workflow.persistence.types.UniqueValueEntity;
+import org.onap.sdc.workflow.services.exceptions.UniqueValueViolationException;
+import org.openecomp.core.utilities.CommonMethods; // todo get rid of
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service("uniqueValueService")
+public class UniqueValueService {
+
+ private static final char FORMATTED_UNIQUE_VALUE_SEPARATOR = '_';
+
+ private final UniqueValueRepository uniqueValueRepository;
+
+ @Autowired
+ public UniqueValueService(UniqueValueRepository uniqueValueRepository) {
+ this.uniqueValueRepository = uniqueValueRepository;
+ }
+
+ /**
+ * Create unique value.
+ *
+ * @param type the type
+ * @param uniqueCombination the unique combination
+ */
+ public void createUniqueValue(String type, String[] uniqueCombination) {
+ formatValue(uniqueCombination).ifPresent(formattedValue -> {
+ validateUniqueValue(type, formattedValue, uniqueCombination);
+ uniqueValueRepository.insert(new UniqueValueEntity(type, formattedValue));
+ });
+ }
+
+ /**
+ * Delete unique value.
+ *
+ * @param type the type
+ * @param uniqueCombination the unique combination
+ */
+ public void deleteUniqueValue(String type, String[] uniqueCombination) {
+ formatValue(uniqueCombination)
+ .ifPresent(formattedValue -> uniqueValueRepository.delete(new UniqueValueEntity(type, formattedValue)));
+
+ }
+
+ /**
+ * Update unique value.
+ *
+ * @param type the type
+ * @param oldValue the old value
+ * @param newValue the new value
+ * @param uniqueContext the unique context
+ */
+ public void updateUniqueValue(String type, String oldValue, String newValue, String ... uniqueContext) {
+ if (newValue == null || !newValue.equalsIgnoreCase(oldValue)) {
+ createUniqueValue(type, CommonMethods.concat(uniqueContext, new String[] {newValue}));
+ deleteUniqueValue(type, CommonMethods.concat(uniqueContext, new String[] {oldValue}));
+ }
+ }
+
+ /**
+ * Validate unique value.
+ *
+ * @param type the type
+ * @param uniqueCombination the unique combination
+ */
+ public void validateUniqueValue(String type, String[] uniqueCombination) {
+ formatValue(uniqueCombination)
+ .ifPresent(formattedValue -> validateUniqueValue(type, formattedValue, uniqueCombination));
+ }
+
+ /**
+ * Checks if a unique value is taken.
+ *
+ * @return true if the unique value is occupied, false otherwise
+ */
+ public boolean isUniqueValueOccupied(String type, String[] uniqueCombination) {
+ return formatValue(uniqueCombination).map(formattedValue -> isUniqueValueOccupied(type, formattedValue))
+ .orElse(false);
+ }
+
+ private void validateUniqueValue(String type, String formattedValue, String[] uniqueCombination) {
+ if (isUniqueValueOccupied(type, formattedValue)) {
+ throw new UniqueValueViolationException(type, getValueWithoutContext(uniqueCombination));
+ }
+ }
+
+ private boolean isUniqueValueOccupied(String type, String formattedValue) {
+ return uniqueValueRepository.findById(new UniqueValueEntity(type, formattedValue)).isPresent();
+ }
+
+ private Optional<String> formatValue(String[] uniqueCombination) {
+ if (ArrayUtils.isEmpty(uniqueCombination) || getValueWithoutContext(uniqueCombination) == null) {
+ return Optional.empty();
+ }
+
+ uniqueCombination[uniqueCombination.length - 1] = getValueWithoutContext(uniqueCombination).toLowerCase();
+ return Optional.of(CommonMethods.arrayToSeparatedString(uniqueCombination, FORMATTED_UNIQUE_VALUE_SEPARATOR));
+ }
+
+ private String getValueWithoutContext(String[] uniqueCombination) {
+ return uniqueCombination[uniqueCombination.length - 1];
+ }
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/WorkflowManager.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/WorkflowManager.java
new file mode 100644
index 00000000..ca079d42
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/WorkflowManager.java
@@ -0,0 +1,34 @@
+/*
+ * 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.services;
+
+import java.util.Collection;
+import java.util.Set;
+import org.onap.sdc.workflow.persistence.types.Workflow;
+import org.onap.sdc.workflow.persistence.types.WorkflowVersionState;
+import org.springframework.data.domain.Pageable;
+
+public interface WorkflowManager {
+
+ Collection<Workflow> list(Set<WorkflowVersionState> versionStatesFilter, Pageable pageable);
+
+ Workflow get(Workflow workflow);
+
+ Workflow create(Workflow workflow);
+
+ void update(Workflow workflow);
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/WorkflowNameComparator.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/WorkflowNameComparator.java
new file mode 100644
index 00000000..1cb6cb1d
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/WorkflowNameComparator.java
@@ -0,0 +1,32 @@
+/*
+ * 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.services;
+
+import java.util.Comparator;
+
+import org.onap.sdc.workflow.persistence.types.Workflow;
+
+public class WorkflowNameComparator implements Comparator<Workflow>{
+
+ @Override
+ public int compare(Workflow workflow1, Workflow workflow2) {
+ String workflowName1 = workflow1.getName().toLowerCase();
+ String workflowName2 = workflow2.getName().toLowerCase();
+ //ascending order
+ return workflowName1.compareTo(workflowName2);
+ }
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/WorkflowVersionManager.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/WorkflowVersionManager.java
new file mode 100644
index 00000000..8effb647
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/WorkflowVersionManager.java
@@ -0,0 +1,46 @@
+/*
+ * 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.services;
+
+import java.util.Collection;
+import java.util.Set;
+import org.onap.sdc.workflow.persistence.types.ArtifactEntity;
+import org.onap.sdc.workflow.persistence.types.WorkflowVersion;
+import org.onap.sdc.workflow.persistence.types.WorkflowVersionState;
+import org.springframework.web.multipart.MultipartFile;
+
+
+public interface WorkflowVersionManager {
+
+ Collection<WorkflowVersion> list(String workflowId, Set<WorkflowVersionState> stateFilter);
+
+ WorkflowVersion create(String workflowId, String baseVersionId, WorkflowVersion version);
+
+ void update(String workflowId, WorkflowVersion version);
+
+ WorkflowVersion get(String workflowId, String versionId);
+
+ WorkflowVersionState getState(String workflowId, String versionId);
+
+ void updateState(String workflowId, String versionId, WorkflowVersionState state);
+
+ ArtifactEntity getArtifact(String workflowId, String versionId);
+
+ void deleteArtifact(String workflowId, String versionId);
+
+ void uploadArtifact(String workflowId, String versionId, MultipartFile artifact);
+} \ No newline at end of file
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/EntityNotFoundException.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/EntityNotFoundException.java
new file mode 100644
index 00000000..7fc3e81c
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/EntityNotFoundException.java
@@ -0,0 +1,24 @@
+/*
+ * 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.services.exceptions;
+
+public class EntityNotFoundException extends RuntimeException {
+
+ public EntityNotFoundException(String message) {
+ super(message);
+ }
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/InvalidArtifactException.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/InvalidArtifactException.java
new file mode 100644
index 00000000..c4584179
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/InvalidArtifactException.java
@@ -0,0 +1,24 @@
+/*
+ * 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.services.exceptions;
+
+public class InvalidArtifactException extends RuntimeException {
+
+ public InvalidArtifactException(String message) {
+ super("Invalid artifact file can not be processed. Error: " + message);
+ }
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/InvalidPaginationParameterException.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/InvalidPaginationParameterException.java
new file mode 100644
index 00000000..a4d4a5d6
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/InvalidPaginationParameterException.java
@@ -0,0 +1,24 @@
+/*
+ * 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.services.exceptions;
+
+public class InvalidPaginationParameterException extends RuntimeException {
+
+ public InvalidPaginationParameterException(String parameterName, String parameterValue, String message) {
+ super(String.format("Requested %s: %s %s", parameterName, parameterValue, message));
+ }
+} \ No newline at end of file
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/UniqueValueViolationException.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/UniqueValueViolationException.java
new file mode 100644
index 00000000..a3046a77
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/UniqueValueViolationException.java
@@ -0,0 +1,27 @@
+/*
+ * 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.services.exceptions;
+
+
+public class UniqueValueViolationException extends RuntimeException {
+
+ private static final String UNIQUE_VALUE_VIOLATION_MSG = "%s with the value '%s' already exists.";
+
+ public UniqueValueViolationException(String uniqueType, String value) {
+ super(String.format(UNIQUE_VALUE_VIOLATION_MSG, uniqueType, value));
+ }
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionCreationException.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionCreationException.java
new file mode 100644
index 00000000..31c88923
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionCreationException.java
@@ -0,0 +1,31 @@
+/*
+ * 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.services.exceptions;
+
+public class VersionCreationException extends RuntimeException {
+
+ private static final String MSG = "Error creating a new version for workflow with id %s";
+ private static final String MSG_WITH_BASE_ID = MSG + " based on version %s: %s";
+
+ public VersionCreationException(String workflowId, String baseVersionId, String detailedMessage) {
+ super(String.format(MSG_WITH_BASE_ID, workflowId, baseVersionId, detailedMessage));
+ }
+
+ public VersionCreationException(String workflowId) {
+ super(String.format(MSG, workflowId));
+ }
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionModificationException.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionModificationException.java
new file mode 100644
index 00000000..752d6bce
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionModificationException.java
@@ -0,0 +1,26 @@
+/*
+ * 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.services.exceptions;
+
+public class VersionModificationException extends RuntimeException {
+
+ public VersionModificationException(String workflowId, String versionId) {
+ super(String.format(
+ "Error while trying to modify version %s of workflow %s: Version is CERTIFIED and can not be edited",
+ versionId, workflowId));
+ }
+} \ No newline at end of file
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionStateModificationException.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionStateModificationException.java
new file mode 100644
index 00000000..87027a58
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionStateModificationException.java
@@ -0,0 +1,28 @@
+/*
+ * 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.services.exceptions;
+
+import org.onap.sdc.workflow.persistence.types.WorkflowVersionState;
+
+public class VersionStateModificationException extends RuntimeException {
+
+ public VersionStateModificationException(String workflowId, String versionId, WorkflowVersionState sourceState,
+ WorkflowVersionState targetState) {
+ super(String.format("Workflow %s, version %s: state can not be changed from %s to %s", workflowId, versionId,
+ sourceState.name(), targetState.name()));
+ }
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/CollaborationConfiguration.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/CollaborationConfiguration.java
new file mode 100644
index 00000000..80b969cf
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/CollaborationConfiguration.java
@@ -0,0 +1,38 @@
+/*
+ * 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.services.impl;
+
+import org.openecomp.sdc.versioning.ItemManager;
+import org.openecomp.sdc.versioning.ItemManagerFactory;
+import org.openecomp.sdc.versioning.VersioningManager;
+import org.openecomp.sdc.versioning.VersioningManagerFactory;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class CollaborationConfiguration {
+
+ @Bean
+ public ItemManager itemManager() {
+ return ItemManagerFactory.getInstance().createInterface();
+ }
+
+ @Bean
+ public VersioningManager versioningManager() {
+ return VersioningManagerFactory.getInstance().createInterface();
+ }
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImpl.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImpl.java
new file mode 100644
index 00000000..52dd8f17
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImpl.java
@@ -0,0 +1,159 @@
+/*
+ * 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.services.impl;
+
+import static org.onap.sdc.workflow.api.RestConstants.SORT_FIELD_NAME;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Set;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import org.onap.sdc.workflow.persistence.types.Workflow;
+import org.onap.sdc.workflow.persistence.types.WorkflowVersionState;
+import org.onap.sdc.workflow.services.UniqueValueService;
+import org.onap.sdc.workflow.services.WorkflowManager;
+import org.onap.sdc.workflow.services.WorkflowNameComparator;
+import org.onap.sdc.workflow.services.exceptions.EntityNotFoundException;
+import org.onap.sdc.workflow.services.impl.mappers.VersionStateMapper;
+import org.onap.sdc.workflow.services.impl.mappers.WorkflowMapper;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
+import org.openecomp.sdc.versioning.ItemManager;
+import org.openecomp.sdc.versioning.dao.types.VersionStatus;
+import org.openecomp.sdc.versioning.types.Item;
+import org.openecomp.sdc.versioning.types.ItemStatus;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
+import org.springframework.stereotype.Service;
+
+@Service("workflowManager")
+public class WorkflowManagerImpl implements WorkflowManager {
+
+ public static final String WORKFLOW_TYPE = "WORKFLOW";
+ private static final String WORKFLOW_NOT_FOUND_ERROR_MSG = "Workflow with id '%s' does not exist";
+ private static final String WORKFLOW_NAME_UNIQUE_TYPE = "WORKFLOW_NAME";
+ private static final Predicate<Item> WORKFLOW_ITEM_FILTER = item -> WORKFLOW_TYPE.equals(item.getType());
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(WorkflowManagerImpl.class);
+ private final ItemManager itemManager;
+ private final UniqueValueService uniqueValueService;
+ private final WorkflowMapper workflowMapper;
+ private final VersionStateMapper versionStateMapper;
+
+ @Autowired
+ public WorkflowManagerImpl(ItemManager itemManager,
+ @Qualifier("uniqueValueService") UniqueValueService uniqueValueService, WorkflowMapper workflowMapper,
+ VersionStateMapper versionStateMapper) {
+ this.itemManager = itemManager;
+ this.uniqueValueService = uniqueValueService;
+ this.workflowMapper = workflowMapper;
+ this.versionStateMapper = versionStateMapper;
+ }
+
+ @Override
+ public Collection<Workflow> list(Set<WorkflowVersionState> versionStatesFilter, Pageable pageRequest) {
+ Set<VersionStatus> versionStatusesFilter =
+ versionStatesFilter == null ? null :
+ versionStatesFilter.stream().map(versionStateMapper::workflowVersionStateToVersionStatus)
+ .collect(Collectors.toSet());
+
+
+ List<Workflow> workflows = itemManager.list(getFilter(versionStatusesFilter)).stream()
+ .map(workflowMapper::itemToWorkflow)
+ .sorted(pageRequest.getSort().getOrderFor(SORT_FIELD_NAME).getDirection()
+ == Sort.Direction.ASC ? getWorkflowsComparator() :
+ Collections.reverseOrder(getWorkflowsComparator()))
+ .collect(Collectors.toList());
+ return applyLimitAndOffset(workflows, pageRequest);
+ }
+
+ @Override
+ public Workflow get(Workflow workflow) {
+ Item retrievedItem = itemManager.get(workflow.getId());
+ if (retrievedItem == null) {
+ LOGGER.error(String.format("Workflow with id %s was not found",workflow.getId()));
+ throw new EntityNotFoundException(String.format(WORKFLOW_NOT_FOUND_ERROR_MSG, workflow.getId()));
+ }
+ return this.workflowMapper.itemToWorkflow(retrievedItem);
+ }
+
+ @Override
+ public Workflow create(Workflow workflow) {
+ Item item = workflowMapper.workflowToItem(workflow);
+ item.setStatus(ItemStatus.ACTIVE);
+
+ uniqueValueService.validateUniqueValue(WORKFLOW_NAME_UNIQUE_TYPE, new String[] {workflow.getName()});
+ Item createdItem = itemManager.create(item);
+ uniqueValueService.createUniqueValue(WORKFLOW_NAME_UNIQUE_TYPE, new String[] {workflow.getName()});
+
+ return workflowMapper.itemToWorkflow(createdItem);
+ }
+
+ @Override
+ public void update(Workflow workflow) {
+ Item retrievedItem = itemManager.get(workflow.getId());
+ if (retrievedItem == null) {
+ LOGGER.error(String.format("Workflow with id %s was not found",workflow.getId()));
+ throw new EntityNotFoundException(String.format(WORKFLOW_NOT_FOUND_ERROR_MSG, workflow.getId()));
+ }
+
+ uniqueValueService.updateUniqueValue(WORKFLOW_NAME_UNIQUE_TYPE, retrievedItem.getName(), workflow.getName());
+
+ Item item = workflowMapper.workflowToItem(workflow);
+ item.setId(workflow.getId());
+ item.setStatus(retrievedItem.getStatus());
+ item.setVersionStatusCounters(retrievedItem.getVersionStatusCounters());
+ itemManager.update(item);
+ }
+
+ private List<Workflow> applyLimitAndOffset(List<Workflow> workflowList, Pageable pageRequest) {
+ int limit = pageRequest.getPageSize();
+ int offset = pageRequest.getPageNumber();
+ int totalNumOfWorkflows = workflowList.size();
+ List<Workflow> selectedWorkflows;
+ try {
+ if (limit > totalNumOfWorkflows) {
+ limit = totalNumOfWorkflows;
+ }
+ int startIndex = offset * limit;
+ int endIndex = startIndex + limit;
+ if (endIndex > totalNumOfWorkflows) {
+ endIndex = totalNumOfWorkflows;
+ }
+ selectedWorkflows = workflowList.subList(startIndex, endIndex);
+ } catch (IndexOutOfBoundsException | IllegalArgumentException ex) {
+ selectedWorkflows = new ArrayList<>();
+ }
+ return selectedWorkflows;
+ }
+
+ private Comparator<Workflow> getWorkflowsComparator() {
+ //More comparators can be added if required based on sort field name
+ return new WorkflowNameComparator();
+ }
+
+ private static Predicate<Item> getFilter(Set<VersionStatus> versionStatuses) {
+ return WORKFLOW_ITEM_FILTER.and(item -> versionStatuses == null
+ || item.getVersionStatusCounters().keySet().stream()
+ .anyMatch(versionStatuses::contains));
+ }
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImpl.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImpl.java
new file mode 100644
index 00000000..484c598a
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImpl.java
@@ -0,0 +1,277 @@
+/*
+ * 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.services.impl;
+
+import static org.onap.sdc.workflow.persistence.types.WorkflowVersionState.CERTIFIED;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import org.onap.sdc.workflow.persistence.ArtifactRepository;
+import org.onap.sdc.workflow.persistence.ParameterRepository;
+import org.onap.sdc.workflow.persistence.types.ArtifactEntity;
+import org.onap.sdc.workflow.persistence.types.ParameterEntity;
+import org.onap.sdc.workflow.persistence.types.ParameterRole;
+import org.onap.sdc.workflow.persistence.types.WorkflowVersion;
+import org.onap.sdc.workflow.persistence.types.WorkflowVersionState;
+import org.onap.sdc.workflow.services.WorkflowVersionManager;
+import org.onap.sdc.workflow.services.exceptions.EntityNotFoundException;
+import org.onap.sdc.workflow.services.exceptions.InvalidArtifactException;
+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.impl.mappers.VersionMapper;
+import org.onap.sdc.workflow.services.impl.mappers.VersionStateMapper;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
+import org.openecomp.sdc.versioning.VersioningManager;
+import org.openecomp.sdc.versioning.dao.types.Version;
+import org.openecomp.sdc.versioning.dao.types.VersionStatus;
+import org.openecomp.sdc.versioning.types.VersionCreationMethod;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
+import org.springframework.web.multipart.MultipartFile;
+
+@Service("workflowVersionManager")
+public class WorkflowVersionManagerImpl implements WorkflowVersionManager {
+
+ private static final String VERSION_NOT_EXIST_MSG = "version with id '%s' does not exist for workflow with id '%s'";
+ private final VersioningManager versioningManager;
+ private final ArtifactRepository artifactRepository;
+ private final ParameterRepository parameterRepository;
+ private final VersionMapper versionMapper;
+ private final VersionStateMapper versionStateMapper;
+ private static final Logger LOGGER = LoggerFactory.getLogger(WorkflowVersionManagerImpl.class);
+
+ @Autowired
+ public WorkflowVersionManagerImpl(VersioningManager versioningManager, ArtifactRepository artifactRepository,
+ VersionMapper versionMapper, VersionStateMapper versionStateMapper,
+ ParameterRepository parameterRepository) {
+ this.versioningManager = versioningManager;
+ this.artifactRepository = artifactRepository;
+ this.parameterRepository = parameterRepository;
+ this.versionMapper = versionMapper;
+ this.versionStateMapper = versionStateMapper;
+ }
+
+ @Override
+ public Collection<WorkflowVersion> list(String workflowId, Set<WorkflowVersionState> stateFilter) {
+ Set<VersionStatus> versionStatusFilter =
+ stateFilter == null ? null :
+ stateFilter.stream().map(versionStateMapper::workflowVersionStateToVersionStatus)
+ .collect(Collectors.toSet());
+
+ return versioningManager.list(workflowId).stream()
+ .filter(version -> versionStatusFilter == null || versionStatusFilter.contains(
+ version.getStatus()))
+ .map(versionMapper::versionToWorkflowVersion)
+ .peek(workflowVersion -> loadAndAddParameters(workflowId, workflowVersion))
+ .collect(Collectors.toList());
+ }
+
+ @Override
+ public WorkflowVersion get(String workflowId, String versionId) {
+ WorkflowVersion workflowVersion = versionMapper.versionToWorkflowVersion(getVersion(workflowId, versionId));
+ loadAndAddParameters(workflowId, workflowVersion);
+ return workflowVersion;
+ }
+
+ @Override
+ public WorkflowVersion create(String workflowId, String baseVersionId, WorkflowVersion workflowVersion) {
+ List<Version> versions = versioningManager.list(workflowId);
+
+ if (baseVersionId != null) {
+ if (!workflowVersion.getInputs().isEmpty() || !workflowVersion.getOutputs().isEmpty()) {
+ throw new VersionCreationException(workflowId, baseVersionId, "Inputs/Outputs should not be supplied");
+ }
+ validateVersionExistAndCertified(workflowId, versions, baseVersionId);
+ } else if (!versions.isEmpty()) {
+ throw new VersionCreationException(workflowId);
+ }
+
+ Version version = new Version();
+ version.setDescription(workflowVersion.getDescription());
+ version.setBaseId(baseVersionId);
+ Version createdVersion = versioningManager.create(workflowId, version, VersionCreationMethod.major);
+
+ if (versions.isEmpty()) { // only for first version
+ artifactRepository.createStructure(workflowId, createdVersion.getId());
+ parameterRepository.createStructure(workflowId, createdVersion.getId());
+ updateParameters(workflowId, createdVersion.getId(), workflowVersion.getInputs(), workflowVersion.getOutputs());
+ versioningManager.publish(workflowId, createdVersion, "Add initial data");
+ }
+
+ return get(workflowId, createdVersion.getId());
+ }
+
+ @Override
+ public void update(String workflowId, WorkflowVersion workflowVersion) {
+ Version retrievedVersion = getVersion(workflowId, workflowVersion.getId());
+ if (CERTIFIED.equals(versionStateMapper.versionStatusToWorkflowVersionState(retrievedVersion.getStatus()))) {
+ throw new VersionModificationException(workflowId, workflowVersion.getId());
+ }
+
+ Version version = versionMapper.workflowVersionToVersion(workflowVersion);
+ version.setName(retrievedVersion.getName());
+ version.setStatus(retrievedVersion.getStatus());
+
+ updateParameters(workflowId, version.getId(), workflowVersion.getInputs(), workflowVersion.getOutputs());
+
+ versioningManager.updateVersion(workflowId, version);
+ versioningManager.publish(workflowId, version, "Update version");
+ }
+
+ @Override
+ public WorkflowVersionState getState(String workflowId, String versionId) {
+ return versionStateMapper.versionStatusToWorkflowVersionState(getVersion(workflowId, versionId).getStatus());
+ }
+
+ @Override
+ public void updateState(String workflowId, String versionId, WorkflowVersionState state) {
+ WorkflowVersionState retrievedState =
+ versionStateMapper.versionStatusToWorkflowVersionState(getVersion(workflowId, versionId).getStatus());
+
+ if (state == CERTIFIED) {
+ try {
+ versioningManager.submit(workflowId, new Version(versionId),
+ String.format("Update version state to %s", state.name()));
+ } catch (Exception e) {
+ throw new VersionStateModificationException(workflowId, versionId, retrievedState, state);
+ }
+ } else {
+ throw new VersionStateModificationException(workflowId, versionId, retrievedState, state);
+ }
+ }
+
+ @Override
+ public void uploadArtifact(String workflowId, String versionId, MultipartFile artifact) {
+ Version retrievedVersion = getVersion(workflowId, versionId);
+ if (CERTIFIED.equals(versionStateMapper.versionStatusToWorkflowVersionState(retrievedVersion.getStatus()))) {
+ throw new VersionModificationException(workflowId, versionId);
+ }
+
+ try (InputStream artifactData = artifact.getInputStream()) {
+ ArtifactEntity artifactEntity =
+ new ArtifactEntity(StringUtils.cleanPath(artifact.getOriginalFilename()), artifactData);
+ artifactRepository.update(workflowId, versionId, artifactEntity);
+ versioningManager.publish(workflowId, new Version(versionId), "Update Artifact");
+
+ } catch (IOException e) {
+ LOGGER.error(String.format("Upload Artifact failed for workflow id %s and version id %s",
+ workflowId, versionId),e);
+ throw new InvalidArtifactException(e.getMessage());
+ }
+ }
+
+ @Override
+ public ArtifactEntity getArtifact(String workflowId, String versionId) {
+ getVersion(workflowId, versionId);
+ Optional<ArtifactEntity> artifactOptional = artifactRepository.get(workflowId, versionId);
+ if (!artifactOptional.isPresent()) {
+ LOGGER.error(String.format("Workflow Version Artifact was not found for workflow id %s and version id %s",
+ workflowId, versionId));
+ throw new EntityNotFoundException(
+ String.format("Artifact for workflow id %S version id %S was not found", workflowId, versionId));
+ }
+ return artifactOptional.get();
+ }
+
+ @Override
+ public void deleteArtifact(String workflowId, String versionId) {
+ WorkflowVersion retrievedVersion = get(workflowId, versionId);
+ if (CERTIFIED.equals(retrievedVersion.getState())) {
+ LOGGER.error(String.format(
+ "Workflow Version is certified and can not be edited.Workflow id %s and version id %s", workflowId,
+ versionId));
+ throw new VersionModificationException(workflowId, versionId);
+ }
+
+ artifactRepository.delete(workflowId, versionId);
+ versioningManager.publish(workflowId, new Version(versionId), "Delete Artifact");
+ }
+
+ private void validateVersionExistAndCertified(String workflowId, List<Version> versions, String versionId) {
+ Version baseVersion = findVersion(versions, versionId).orElseThrow(
+ () -> new EntityNotFoundException(String.format(VERSION_NOT_EXIST_MSG, versionId, workflowId)));
+
+ if (CERTIFIED != versionStateMapper.versionStatusToWorkflowVersionState(baseVersion.getStatus())) {
+ throw new VersionCreationException(workflowId, versionId, "base version must be CERTIFIED");
+ }
+ }
+
+ private Version getVersion(String workflowId, String versionId) {
+ try {
+ Version version = versioningManager.get(workflowId, new Version(versionId));
+ if (version == null) {
+ throw new EntityNotFoundException(String.format(VERSION_NOT_EXIST_MSG, versionId, workflowId));
+ }
+ return version;
+ } catch (Exception e) {
+ LOGGER.error(String.format(
+ "Workflow Version was not found.Workflow id %s and version id %s", workflowId,
+ versionId),e);
+ throw new EntityNotFoundException(String.format(VERSION_NOT_EXIST_MSG, versionId, workflowId));
+ }
+ }
+
+ private void updateParameters(String workflowId, String versionId, Collection<ParameterEntity> inputs,
+ Collection<ParameterEntity> outputs) {
+ updateVersionParameters(workflowId, versionId, ParameterRole.INPUT, inputs);
+ updateVersionParameters(workflowId, versionId, ParameterRole.OUTPUT, outputs);
+ }
+
+ private void updateVersionParameters(String workflowId, String versionId, ParameterRole role,
+ Collection<ParameterEntity> parameters) {
+
+ Collection<ParameterEntity> retrievedParams = parameterRepository.list(workflowId, versionId, role);
+ Map<String, ParameterEntity> retrievedParamsByName =
+ retrievedParams.stream().collect(Collectors.toMap(ParameterEntity::getName, Function.identity()));
+
+ Set<String> namesOfParamsToKeep = new HashSet<>();
+ for (ParameterEntity parameter : parameters) {
+
+ ParameterEntity retrievedParam = retrievedParamsByName.get(parameter.getName());
+ if (retrievedParam == null) {
+ parameterRepository.create(workflowId, versionId, role, parameter);
+ } else {
+ parameterRepository.update(workflowId, versionId, role, parameter);
+ namesOfParamsToKeep.add(parameter.getName());
+ }
+ }
+
+ retrievedParams.stream().filter(retrievedParam -> !namesOfParamsToKeep.contains(retrievedParam.getName()))
+ .forEach(retrievedParam -> parameterRepository
+ .delete(workflowId, versionId, retrievedParam.getId()));
+ }
+
+ private void loadAndAddParameters(String workflowId, WorkflowVersion workflowVersion) {
+ workflowVersion.setInputs(parameterRepository.list(workflowId, workflowVersion.getId(), ParameterRole.INPUT));
+ workflowVersion.setOutputs(parameterRepository.list(workflowId, workflowVersion.getId(), ParameterRole.OUTPUT));
+ }
+
+ private static Optional<Version> findVersion(List<Version> versions, String versionId) {
+ return versions.stream().filter(version -> versionId.equals(version.getId())).findFirst();
+ }
+} \ No newline at end of file
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/VersionMapper.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/VersionMapper.java
new file mode 100644
index 00000000..a3a1cdcc
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/VersionMapper.java
@@ -0,0 +1,35 @@
+/*
+ * 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.services.impl.mappers;
+
+import org.mapstruct.InheritInverseConfiguration;
+import org.mapstruct.Mapper;
+import org.mapstruct.Mapping;
+import org.onap.sdc.workflow.persistence.types.WorkflowVersion;
+import org.openecomp.sdc.versioning.dao.types.Version;
+
+@Mapper(componentModel = "spring", uses = VersionStateMapper.class)
+public interface VersionMapper {
+
+
+ @Mapping(source = "status", target = "state")
+ WorkflowVersion versionToWorkflowVersion(Version version);
+
+ @InheritInverseConfiguration
+ Version workflowVersionToVersion(WorkflowVersion workflowVersion);
+
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/VersionStateMapper.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/VersionStateMapper.java
new file mode 100644
index 00000000..45012b57
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/VersionStateMapper.java
@@ -0,0 +1,47 @@
+/*
+ * 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.services.impl.mappers;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.mapstruct.InheritInverseConfiguration;
+import org.mapstruct.Mapper;
+import org.mapstruct.ValueMapping;
+import org.mapstruct.ValueMappings;
+import org.onap.sdc.workflow.persistence.types.WorkflowVersionState;
+import org.openecomp.sdc.versioning.dao.types.VersionStatus;
+
+@Mapper(componentModel = "spring")
+public interface VersionStateMapper {
+
+ @ValueMappings({@ValueMapping(source = "Certified", target = "CERTIFIED"),
+ @ValueMapping(source = "Draft", target = "DRAFT"),
+ @ValueMapping(source = "<ANY_REMAINING>", target = "DRAFT")})
+ WorkflowVersionState versionStatusToWorkflowVersionState(VersionStatus status);
+
+ @InheritInverseConfiguration
+ VersionStatus workflowVersionStateToVersionStatus(WorkflowVersionState status);
+
+ default Set<WorkflowVersionState> versionStatusCountersToWorkflowVersionStates(
+ Map<VersionStatus, Integer> versionStatusCounters) {
+ return versionStatusCounters.keySet().stream().map(this::versionStatusToWorkflowVersionState)
+ .collect(Collectors.toSet());
+ }
+
+
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/WorkflowMapper.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/WorkflowMapper.java
new file mode 100644
index 00000000..5cfcd7ed
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/WorkflowMapper.java
@@ -0,0 +1,38 @@
+/*
+ * 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.services.impl.mappers;
+
+import org.mapstruct.InheritInverseConfiguration;
+import org.mapstruct.Mapper;
+import org.mapstruct.Mapping;
+import org.mapstruct.Mappings;
+import org.onap.sdc.workflow.persistence.types.Workflow;
+import org.onap.sdc.workflow.services.impl.WorkflowManagerImpl;
+import org.openecomp.sdc.versioning.types.Item;
+
+@Mapper(componentModel = "spring", imports = WorkflowManagerImpl.class, uses = VersionStateMapper.class)
+public interface WorkflowMapper {
+
+ @Mapping(source = "versionStatusCounters", target = "versionStates")
+ Workflow itemToWorkflow(Item item);
+
+ @InheritInverseConfiguration
+ @Mappings({@Mapping(expression = "java(WorkflowManagerImpl.WORKFLOW_TYPE)", target = "type"),
+ @Mapping(target = "versionStatusCounters", ignore = true)})
+ Item workflowToItem(Workflow workflow);
+
+}