diff options
author | 2018-07-16 19:25:05 +0530 | |
---|---|---|
committer | 2018-07-16 19:25:07 +0530 | |
commit | 7e78cd19bbb2b0730fafc0b328a71c69f5730e16 (patch) | |
tree | 24b4b72ef67f64304bfee867076517c37896db5b /workflow-designer-be/src/main/java/org | |
parent | 39c01dd3ccb69f53d2e9350994e25f6e64412aa4 (diff) |
Workflow Docker containers
1. Implemented workflow init container.
2. Implemented workflow backend container.
3. Added a placeholder for frontend module container.
4. Modifiled directory structure and POM files.
5. Added a ReadMe with sample commands to detail how to run the containers.
Change-Id: Ib110fcc104ce72ff28fce514a1475a032cc2d82b
Issue-ID: SDC-1482
Signed-off-by: priyanshu <pagarwal@amdocs.com>
Signed-off-by: vempo <vitaliy.emporopulo@amdocs.com>
Signed-off-by: priyanshu <pagarwal@amdocs.com>
Diffstat (limited to 'workflow-designer-be/src/main/java/org')
35 files changed, 0 insertions, 1230 deletions
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 deleted file mode 100644 index b7e3b345..00000000 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/SpringBootWebApplication.java +++ /dev/null @@ -1,20 +0,0 @@ -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 deleted file mode 100644 index 8f02be0f..00000000 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/RestConstants.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.onap.sdc.workflow.api; - -public class RestConstants { - - private RestConstants() { - } - - public static final String USER_ID_HEADER_PARAM = "USER_ID"; -} 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 deleted file mode 100644 index bb4320cc..00000000 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowController.java +++ /dev/null @@ -1,66 +0,0 @@ -package org.onap.sdc.workflow.api; - -import static org.onap.sdc.workflow.api.RestConstants.USER_ID_HEADER_PARAM; - -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -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.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -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.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(@RequestHeader(USER_ID_HEADER_PARAM) String user) { - return new CollectionWrapper<>(workflowManager.list()); - } - - @PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE) - @ApiOperation("Create workflow") - public ResponseEntity<Workflow> create(@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; - } -} 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 deleted file mode 100644 index 6214f1bb..00000000 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowVersionController.java +++ /dev/null @@ -1,117 +0,0 @@ -package org.onap.sdc.workflow.api; - -import static org.onap.sdc.workflow.api.RestConstants.USER_ID_HEADER_PARAM; - -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import org.onap.sdc.workflow.api.types.CollectionWrapper; -import org.onap.sdc.workflow.api.types.VersionRequestDto; -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.web.bind.annotation.DeleteMapping; -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.RestController; -import org.springframework.web.multipart.MultipartFile; - -@RequestMapping("/workflows/{workflowId}/versions") -@Api("Workflow versions") -@RestController("workflowsVersionController") -public class WorkflowVersionController { - - private final WorkflowVersionManager workflowVersionManager; - - @Autowired - public WorkflowVersionController( - @Qualifier("workflowVersionManager") WorkflowVersionManager workflowVersionManager) { - this.workflowVersionManager = workflowVersionManager; - } - - @GetMapping - @ApiOperation("List workflow versions") - public CollectionWrapper<WorkflowVersion> list(@PathVariable("workflowId") String workflowId, - @RequestHeader(USER_ID_HEADER_PARAM) String user) { - return new CollectionWrapper<>(workflowVersionManager.list(workflowId)); - } - - @PostMapping - @ApiOperation("Create workflow version") - public ResponseEntity<WorkflowVersion> create(@RequestBody VersionRequestDto versionRequest, - @PathVariable("workflowId") String workflowId, @RequestHeader(USER_ID_HEADER_PARAM) String user) { - - WorkflowVersion createdVersion = workflowVersionManager.create(workflowId, versionRequest); - 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 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 deleted file mode 100644 index 68fd41a5..00000000 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/exceptionshandlers/CustomizedResponseEntityExceptionHandler.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.onap.sdc.workflow.api.exceptionshandlers; - -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.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.ResponseEntity; -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.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({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 deleted file mode 100644 index 653b0dcf..00000000 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/CollectionWrapper.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.onap.sdc.workflow.api.types; - -import java.util.Collection; -import lombok.Data; - -@Data -public class CollectionWrapper<T> { - - private int total; - private int limit; - private int offset; - private Collection<T> results; - - 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/VersionRequestDto.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/VersionRequestDto.java deleted file mode 100644 index 92ac3a73..00000000 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/VersionRequestDto.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.onap.sdc.workflow.api.types; - -import lombok.Data; - -@Data -public class VersionRequestDto { - - private String description; - private String baseVersionId; - -} 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 deleted file mode 100644 index 5963a2bf..00000000 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/VersionStateDto.java +++ /dev/null @@ -1,20 +0,0 @@ -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/persistence/ArtifactRepository.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/ArtifactRepository.java deleted file mode 100644 index a473f166..00000000 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/ArtifactRepository.java +++ /dev/null @@ -1,18 +0,0 @@ -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/UniqueValueRepository.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/UniqueValueRepository.java deleted file mode 100644 index d374a404..00000000 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/UniqueValueRepository.java +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index 9a449f0d..00000000 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryImpl.java +++ /dev/null @@ -1,104 +0,0 @@ -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.Map; -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.openecomp.core.zusammen.api.ZusammenAdaptor; -import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory; -import org.openecomp.sdc.datatypes.model.ElementType; -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(ElementType.Artifact, 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, ElementType.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(ElementType.Artifact, 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(ElementType.Artifact, Action.UPDATE); - artifactElement.setData(new ByteArrayInputStream(EMPTY_DATA.getBytes())); - artifactElement.getInfo().getProperties().remove(FILE_NAME_PROPERTY); - - zusammenAdaptor - .saveElement(context, elementContext, artifactElement, "Update WorkflowVersion Artifact Element"); - - } - - 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/types/ArtifactEntity.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ArtifactEntity.java deleted file mode 100644 index 8f24ecc9..00000000 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ArtifactEntity.java +++ /dev/null @@ -1,16 +0,0 @@ -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/UniqueValueEntity.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/UniqueValueEntity.java deleted file mode 100644 index 925ec5cb..00000000 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/UniqueValueEntity.java +++ /dev/null @@ -1,23 +0,0 @@ -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 deleted file mode 100644 index 8c66d820..00000000 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/Workflow.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.onap.sdc.workflow.persistence.types; - - -import lombok.Data; - -@Data -public class Workflow { - - private String id; - private String name; - private String description; -} 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 deleted file mode 100644 index 6c2d804d..00000000 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/WorkflowProperty.java +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index db0999b6..00000000 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/WorkflowVersion.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.onap.sdc.workflow.persistence.types; - -import java.util.Date; -import lombok.Data; - - -@Data -public class WorkflowVersion { - - private String id; - private String name; - private String description; - private String baseId; - private Date creationTime; - private Date modificationTime; - private WorkflowVersionState state; - - - 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 deleted file mode 100644 index 9414fa17..00000000 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/WorkflowVersionState.java +++ /dev/null @@ -1,20 +0,0 @@ -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 deleted file mode 100644 index 5105114f..00000000 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/SwaggerConfig.java +++ /dev/null @@ -1,24 +0,0 @@ -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 deleted file mode 100644 index 092c3464..00000000 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/ZusammenConfig.java +++ /dev/null @@ -1,32 +0,0 @@ -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 deleted file mode 100644 index 07d8eee7..00000000 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/filters/SessionContextFilter.java +++ /dev/null @@ -1,64 +0,0 @@ -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 deleted file mode 100644 index a9acb816..00000000 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/UniqueValueService.java +++ /dev/null @@ -1,107 +0,0 @@ -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 deleted file mode 100644 index 01c0b053..00000000 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/WorkflowManager.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.onap.sdc.workflow.services; - -import java.util.Collection; -import org.onap.sdc.workflow.persistence.types.Workflow; - -public interface WorkflowManager { - - Collection<Workflow> list(); - - 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/WorkflowVersionManager.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/WorkflowVersionManager.java deleted file mode 100644 index 30234526..00000000 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/WorkflowVersionManager.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.onap.sdc.workflow.services; - -import java.util.Collection; -import org.onap.sdc.workflow.api.types.VersionRequestDto; -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); - - WorkflowVersion create(String workflowId, VersionRequestDto versionRequest); - - void update(String id, 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); -} 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 deleted file mode 100644 index 1ed3df5a..00000000 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/EntityNotFoundException.java +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index 89c5fd5f..00000000 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/InvalidArtifactException.java +++ /dev/null @@ -1,8 +0,0 @@ -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/UniqueValueViolationException.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/UniqueValueViolationException.java deleted file mode 100644 index 82c97f94..00000000 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/UniqueValueViolationException.java +++ /dev/null @@ -1,11 +0,0 @@ -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 deleted file mode 100644 index af01c68f..00000000 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionCreationException.java +++ /dev/null @@ -1,15 +0,0 @@ -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"; - - public VersionCreationException(String workflowId, String baseVersionId) { - super(String.format(MSG_WITH_BASE_ID, workflowId, baseVersionId)); - } - - 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 deleted file mode 100644 index 64ab6103..00000000 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionModificationException.java +++ /dev/null @@ -1,10 +0,0 @@ -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)); - } -} 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 deleted file mode 100644 index 6c4606db..00000000 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionStateModificationException.java +++ /dev/null @@ -1,12 +0,0 @@ -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 deleted file mode 100644 index 2a4cd5aa..00000000 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/CollaborationConfiguration.java +++ /dev/null @@ -1,22 +0,0 @@ -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 deleted file mode 100644 index 8ac5025a..00000000 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImpl.java +++ /dev/null @@ -1,79 +0,0 @@ -package org.onap.sdc.workflow.services.impl; - -import java.util.Collection; -import java.util.function.Predicate; -import java.util.stream.Collectors; -import org.onap.sdc.workflow.persistence.types.Workflow; -import org.onap.sdc.workflow.services.UniqueValueService; -import org.onap.sdc.workflow.services.WorkflowManager; -import org.onap.sdc.workflow.services.exceptions.EntityNotFoundException; -import org.onap.sdc.workflow.services.impl.mappers.WorkflowMapper; -import org.openecomp.sdc.versioning.ItemManager; -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.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"; - static final Predicate<Item> ITEM_PREDICATE = item -> WORKFLOW_TYPE.equals(item.getType()); - - private final ItemManager itemManager; - private final UniqueValueService uniqueValueService; - private final WorkflowMapper workflowMapper; - - @Autowired - public WorkflowManagerImpl(ItemManager itemManager, - @Qualifier("uniqueValueService") UniqueValueService uniqueValueService, WorkflowMapper workflowMapper) { - this.itemManager = itemManager; - this.uniqueValueService = uniqueValueService; - this.workflowMapper = workflowMapper; - } - - @Override - public Collection<Workflow> list() { - return itemManager.list(ITEM_PREDICATE).stream().map(workflowMapper::itemToWorkflow) - .collect(Collectors.toList()); - } - - @Override - public Workflow get(Workflow workflow) { - Item retrievedItem = itemManager.get(workflow.getId()); - if (retrievedItem == null) { - 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()}); - workflow.setId(itemManager.create(item).getId()); - uniqueValueService.createUniqueValue(WORKFLOW_NAME_UNIQUE_TYPE, new String[] {workflow.getName()}); - return workflow; - } - - @Override - public void update(Workflow workflow) { - Item retrievedItem = itemManager.get(workflow.getId()); - if (retrievedItem == null) { - 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); - } -} 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 deleted file mode 100644 index d559f025..00000000 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImpl.java +++ /dev/null @@ -1,186 +0,0 @@ -package org.onap.sdc.workflow.services.impl; - -import static org.openecomp.sdc.versioning.dao.types.VersionStatus.Certified; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Collection; -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; -import org.onap.sdc.workflow.api.types.VersionRequestDto; -import org.onap.sdc.workflow.persistence.ArtifactRepository; -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.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.versioning.VersioningManager; -import org.openecomp.sdc.versioning.dao.types.Version; -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 VersionMapper versionMapper; - private final VersionStateMapper versionStateMapper; - - - @Autowired - public WorkflowVersionManagerImpl(VersioningManager versioningManager, ArtifactRepository artifactRepository, - VersionMapper versionMapper, VersionStateMapper versionStateMapper) { - this.versioningManager = versioningManager; - this.artifactRepository = artifactRepository; - this.versionMapper = versionMapper; - this.versionStateMapper = versionStateMapper; - } - - @Override - public Collection<WorkflowVersion> list(String workflowId) { - return versioningManager.list(workflowId).stream().map(versionMapper::versionToWorkflowVersion) - .collect(Collectors.toList()); - } - - @Override - public WorkflowVersion get(String workflowId, String versionId) { - return versionMapper.versionToWorkflowVersion(getVersion(workflowId, versionId)); - } - - @Override - public WorkflowVersion create(String workflowId, VersionRequestDto versionRequest) { - List<Version> versions = versioningManager.list(workflowId); - - if (versionRequest.getBaseVersionId() != null) { - validateVersionExistAndCertified(workflowId, versions, versionRequest.getBaseVersionId()); - } else if (!versions.isEmpty()) { - throw new VersionCreationException(workflowId); - } - - Version version = new Version(); - version.setDescription(versionRequest.getDescription()); - version.setBaseId(versionRequest.getBaseVersionId()); - Version createdVersion = versioningManager.create(workflowId, version, VersionCreationMethod.major); - - if (versions.isEmpty()) { // only for first version - artifactRepository.createStructure(workflowId, createdVersion.getId()); - versioningManager.publish(workflowId, createdVersion, "Add workflow structure"); - } - - return versionMapper.versionToWorkflowVersion(createdVersion); - } - - @Override - public void update(String workflowId, WorkflowVersion workflowVersion) { - Version retrievedVersion = getVersion(workflowId, workflowVersion.getId()); - if (WorkflowVersionState.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()); - - 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) { - Version retrievedVersion = getVersion(workflowId, versionId); - WorkflowVersionState retrievedState = - versionStateMapper.versionStatusToWorkflowVersionState(retrievedVersion.getStatus()); - if (WorkflowVersionState.CERTIFIED.equals(retrievedState) || retrievedState.equals(state)) { - throw new VersionStateModificationException(workflowId, versionId, retrievedState, state); - } - - retrievedVersion.setStatus(versionStateMapper.workflowVersionStateToVersionStatus(state)); - versioningManager.updateVersion(workflowId, retrievedVersion); - versioningManager.publish(workflowId, retrievedVersion, - String.format("Update version state from %s to %s", retrievedState.name(), state.name())); - } - - @Override - public void uploadArtifact(String workflowId, String versionId, MultipartFile artifact) { - Version retrievedVersion = getVersion(workflowId, versionId); - if (WorkflowVersionState.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) { - 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()) { - 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 (WorkflowVersionState.CERTIFIED.equals(retrievedVersion.getState())) { - 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.equals(baseVersion.getStatus())) { - throw new VersionCreationException(workflowId, versionId); - } - } - - 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) { - throw new EntityNotFoundException(String.format(VERSION_NOT_EXIST_MSG, versionId, workflowId)); - } - } - - private static Optional<Version> findVersion(List<Version> versions, String versionId) { - return versions.stream().filter(version -> versionId.equals(version.getId())).findFirst(); - } -} 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 deleted file mode 100644 index bcf89661..00000000 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/VersionMapper.java +++ /dev/null @@ -1,19 +0,0 @@ -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 deleted file mode 100644 index 0c2f5391..00000000 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/VersionStateMapper.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.onap.sdc.workflow.services.impl.mappers; - -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); - - -} 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 deleted file mode 100644 index 34327ce7..00000000 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/WorkflowMapper.java +++ /dev/null @@ -1,19 +0,0 @@ -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.Workflow; -import org.onap.sdc.workflow.services.impl.WorkflowManagerImpl; -import org.openecomp.sdc.versioning.types.Item; - -@Mapper(componentModel = "spring", imports = WorkflowManagerImpl.class) -public interface WorkflowMapper { - - Workflow itemToWorkflow(Item item); - - @InheritInverseConfiguration - @Mapping(expression = "java(WorkflowManagerImpl.WORKFLOW_TYPE)", target = "type") - Item workflowToItem(Workflow workflow); - -} |