diff options
14 files changed, 56 insertions, 71 deletions
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 index 41f47674..2173c05a 100644 --- 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 @@ -1,7 +1,5 @@ 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; @@ -9,11 +7,8 @@ import org.onap.sdc.workflow.persistence.types.Workflow; 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; @RequestMapping("/workflows") @@ -26,13 +21,13 @@ public interface WorkflowController { @PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE) @ApiOperation("Create workflow") - ResponseEntity<?> create(Workflow workflow, String user); + ResponseEntity<Workflow> create(Workflow workflow, String user); - @GetMapping(path = "/{id}") + @GetMapping(path = "/{workflowId}") @ApiOperation("Get workflow") - Workflow get(String id, String user); + Workflow get(String workflowId, String user); - @PutMapping(path = "/{id}", consumes = MediaType.APPLICATION_JSON_VALUE) + @PutMapping(path = "/{workflowId}", consumes = MediaType.APPLICATION_JSON_VALUE) @ApiOperation("Update workflow") - Workflow update(Workflow workflow, String id, String user); + Workflow update(Workflow workflow, String workflowId, String user); } diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/impl/WorkflowControllerImpl.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/impl/WorkflowControllerImpl.java index f0b9f3ee..0d9ee4be 100644 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/impl/WorkflowControllerImpl.java +++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/impl/WorkflowControllerImpl.java @@ -31,22 +31,21 @@ public class WorkflowControllerImpl implements WorkflowController { } @Override - public ResponseEntity<?> create(@RequestBody Workflow workflow, @RequestHeader(USER_ID_HEADER_PARAM) String user) { - workflowManager.create(workflow); - return new ResponseEntity<>(workflow, HttpStatus.CREATED); + public ResponseEntity<Workflow> create(@RequestBody Workflow workflow, @RequestHeader(USER_ID_HEADER_PARAM) String user) { + return new ResponseEntity<>(workflowManager.create(workflow), HttpStatus.CREATED); } @Override - public Workflow get(@PathVariable("id") String id, @RequestHeader(USER_ID_HEADER_PARAM) String user) { + public Workflow get(@PathVariable("workflowId") String workflowId, @RequestHeader(USER_ID_HEADER_PARAM) String user) { Workflow workflow = new Workflow(); - workflow.setId(id); + workflow.setId(workflowId); return workflowManager.get(workflow); } @Override - public Workflow update(@RequestBody Workflow workflow, @PathVariable("id") String id, + public Workflow update(@RequestBody Workflow workflow, @PathVariable("workflowId") String workflowId, @RequestHeader(USER_ID_HEADER_PARAM) String user) { - workflow.setId(id); + workflow.setId(workflowId); workflowManager.update(workflow); return workflow; } 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 index d4dc8a80..07d8eee7 100644 --- 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 @@ -38,7 +38,6 @@ public class SessionContextFilter implements Filter { try { if (servletRequest instanceof HttpServletRequest) { - contextProvider.create(getUser(servletRequest), getTenant()); } @@ -54,7 +53,9 @@ public class SessionContextFilter implements Filter { } private String getUser(ServletRequest servletRequest) { - return ((HttpServletRequest) servletRequest).getHeader(USER_ID_HEADER_PARAM); + 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() { 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 index 565c4f5a..01c0b053 100644 --- 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 @@ -9,7 +9,7 @@ public interface WorkflowManager { Workflow get(Workflow workflow); - void create(Workflow workflow); + Workflow create(Workflow workflow); void update(Workflow workflow); } 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 index cf1a7e18..8ac5025a 100644 --- 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 @@ -3,11 +3,11 @@ 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.services.exceptions.EntityNotFoundException; -import org.onap.sdc.workflow.services.mappers.WorkflowMapper; 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; @@ -18,13 +18,14 @@ import org.springframework.stereotype.Service; @Service("workflowManager") public class WorkflowManagerImpl implements WorkflowManager { - private static final String WORKFLOW_TYPE = "WORKFLOW"; + public static final String WORKFLOW_TYPE = "WORKFLOW"; private static final String WORKFLOW_NOT_FOUND_ERROR_MSG = "Workflow with id '%s' does not exist"; - protected static final Predicate<Item> ITEM_PREDICATE = item -> WORKFLOW_TYPE.equals(item.getType()); 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 WorkflowMapper workflowMapper; + private final WorkflowMapper workflowMapper; @Autowired public WorkflowManagerImpl(ItemManager itemManager, @@ -36,8 +37,8 @@ public class WorkflowManagerImpl implements WorkflowManager { @Override public Collection<Workflow> list() { - return itemManager.list(ITEM_PREDICATE).stream() - .map(item -> workflowMapper.itemToWorkflow(item)).collect(Collectors.toList()); + return itemManager.list(ITEM_PREDICATE).stream().map(workflowMapper::itemToWorkflow) + .collect(Collectors.toList()); } @Override @@ -50,14 +51,14 @@ public class WorkflowManagerImpl implements WorkflowManager { } @Override - public void create(Workflow workflow) { + public Workflow create(Workflow workflow) { Item item = workflowMapper.workflowToItem(workflow); item.setStatus(ItemStatus.ACTIVE); - item.setType(WORKFLOW_TYPE); - uniqueValueService.validateUniqueValue(WORKFLOW_NAME_UNIQUE_TYPE, new String[]{workflow.getName()}); + 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()}); + uniqueValueService.createUniqueValue(WORKFLOW_NAME_UNIQUE_TYPE, new String[] {workflow.getName()}); + return workflow; } @Override @@ -73,7 +74,6 @@ public class WorkflowManagerImpl implements WorkflowManager { item.setId(workflow.getId()); item.setStatus(retrievedItem.getStatus()); item.setVersionStatusCounters(retrievedItem.getVersionStatusCounters()); - item.setType(retrievedItem.getType()); 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 index dfcc6c63..e934efd3 100644 --- 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 @@ -19,7 +19,7 @@ import org.onap.sdc.workflow.services.exceptions.CreateVersionException; import org.onap.sdc.workflow.services.exceptions.EntityNotFoundException; import org.onap.sdc.workflow.services.exceptions.InvalidArtifactException; import org.onap.sdc.workflow.services.exceptions.VersionModificationException; -import org.onap.sdc.workflow.services.mappers.VersionMapper; +import org.onap.sdc.workflow.services.impl.mappers.VersionMapper; import org.openecomp.sdc.versioning.VersioningManager; import org.openecomp.sdc.versioning.dao.types.Version; import org.openecomp.sdc.versioning.types.VersionCreationMethod; diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/mappers/VersionMapper.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/VersionMapper.java index e36193f9..6e0c3d6d 100644 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/mappers/VersionMapper.java +++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/VersionMapper.java @@ -1,16 +1,9 @@ -package org.onap.sdc.workflow.services.mappers; +package org.onap.sdc.workflow.services.impl.mappers; -import java.util.Collections; -import java.util.Map; import org.mapstruct.InheritInverseConfiguration; import org.mapstruct.Mapper; -import org.mapstruct.Mapping; -import org.mapstruct.Named; -import org.onap.sdc.workflow.persistence.types.WorkflowProperty; import org.onap.sdc.workflow.persistence.types.WorkflowVersion; -import org.onap.sdc.workflow.persistence.types.WorkflowVersionStatus; import org.openecomp.sdc.versioning.dao.types.Version; -import org.openecomp.sdc.versioning.dao.types.VersionStatus; @Mapper(componentModel = "spring", uses = VersionStatusMapper.class) public interface VersionMapper { diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/mappers/VersionStatusMapper.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/VersionStatusMapper.java index e9fe0a2e..1cdfd69e 100644 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/mappers/VersionStatusMapper.java +++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/VersionStatusMapper.java @@ -1,4 +1,4 @@ -package org.onap.sdc.workflow.services.mappers; +package org.onap.sdc.workflow.services.impl.mappers; import org.mapstruct.InheritInverseConfiguration; import org.mapstruct.Mapper; diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/mappers/WorkflowMapper.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/WorkflowMapper.java index f89441a7..34327ce7 100644 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/mappers/WorkflowMapper.java +++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/WorkflowMapper.java @@ -1,16 +1,19 @@ -package org.onap.sdc.workflow.services.mappers; +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") +@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); } diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowManagerTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowManagerTest.java index 11c50cde..5173b063 100644 --- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowManagerTest.java +++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowManagerTest.java @@ -17,7 +17,7 @@ import org.mockito.Mock; import org.onap.sdc.workflow.persistence.types.Workflow; import org.onap.sdc.workflow.services.UniqueValueService; import org.onap.sdc.workflow.services.exceptions.EntityNotFoundException; -import org.onap.sdc.workflow.services.mappers.WorkflowMapper; +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; diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerTest.java index 0d5b0ad5..a82b5f3d 100644 --- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerTest.java +++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerTest.java @@ -30,7 +30,7 @@ import org.onap.sdc.workflow.persistence.types.WorkflowVersion; import org.onap.sdc.workflow.persistence.types.WorkflowVersionStatus; import org.onap.sdc.workflow.services.exceptions.CreateVersionException; import org.onap.sdc.workflow.services.exceptions.EntityNotFoundException; -import org.onap.sdc.workflow.services.mappers.VersionMapper; +import org.onap.sdc.workflow.services.impl.mappers.VersionMapper; import org.openecomp.sdc.versioning.VersioningManager; import org.openecomp.sdc.versioning.dao.types.Version; import org.openecomp.sdc.versioning.dao.types.VersionStatus; diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/mapping/VersionMapperTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionMapperTest.java index e7566f34..f9d65bd3 100644 --- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/mapping/VersionMapperTest.java +++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionMapperTest.java @@ -1,4 +1,4 @@ -package org.onap.sdc.workflow.api.mapping; +package org.onap.sdc.workflow.services.impl.mappers; import static org.junit.Assert.assertEquals; @@ -7,8 +7,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.onap.sdc.workflow.persistence.types.WorkflowVersion; import org.onap.sdc.workflow.persistence.types.WorkflowVersionStatus; -import org.onap.sdc.workflow.services.mappers.VersionMapper; -import org.onap.sdc.workflow.services.mappers.VersionStatusMapper; import org.openecomp.sdc.versioning.dao.types.Version; import org.openecomp.sdc.versioning.dao.types.VersionStatus; import org.springframework.beans.factory.annotation.Autowired; @@ -30,31 +28,31 @@ public class VersionMapperTest { @Test - public void shouldMapVersionToWorkflowVersion(){ + public void shouldMapVersionToWorkflowVersion() { Version version = createVersion(); WorkflowVersion mappedWorkflowVersion = versionMapper.versionToWorkflowVersion(version); - assertEquals(mappedWorkflowVersion.getId(),version.getId()); - assertEquals(mappedWorkflowVersion.getBaseId(),version.getBaseId()); - assertEquals(mappedWorkflowVersion.getDescription(),version.getDescription()); - assertEquals(mappedWorkflowVersion.getName(),version.getName()); - assertEquals(mappedWorkflowVersion.getCreationTime(),version.getCreationTime()); - assertEquals(mappedWorkflowVersion.getModificationTime(),version.getModificationTime()); + assertEquals(mappedWorkflowVersion.getId(), version.getId()); + assertEquals(mappedWorkflowVersion.getBaseId(), version.getBaseId()); + assertEquals(mappedWorkflowVersion.getDescription(), version.getDescription()); + assertEquals(mappedWorkflowVersion.getName(), version.getName()); + assertEquals(mappedWorkflowVersion.getCreationTime(), version.getCreationTime()); + assertEquals(mappedWorkflowVersion.getModificationTime(), version.getModificationTime()); } @Test - public void shouldMapWorkflowVersionToVersion(){ + public void shouldMapWorkflowVersionToVersion() { WorkflowVersion workflowVersion = createWorkflowVersion(); Version mappedVersion = versionMapper.workflowVersionToVersion(workflowVersion); - assertEquals(mappedVersion.getId(),workflowVersion.getId()); - assertEquals(mappedVersion.getBaseId(),workflowVersion.getBaseId()); - assertEquals(mappedVersion.getDescription(),workflowVersion.getDescription()); - assertEquals(mappedVersion.getName(),workflowVersion.getName()); - assertEquals(mappedVersion.getCreationTime(),workflowVersion.getCreationTime()); - assertEquals(mappedVersion.getModificationTime(),workflowVersion.getModificationTime()); + assertEquals(mappedVersion.getId(), workflowVersion.getId()); + assertEquals(mappedVersion.getBaseId(), workflowVersion.getBaseId()); + assertEquals(mappedVersion.getDescription(), workflowVersion.getDescription()); + assertEquals(mappedVersion.getName(), workflowVersion.getName()); + assertEquals(mappedVersion.getCreationTime(), workflowVersion.getCreationTime()); + assertEquals(mappedVersion.getModificationTime(), workflowVersion.getModificationTime()); } - private Version createVersion(){ + private Version createVersion() { Version version = new Version("version_id"); version.setBaseId("base_version_id"); version.setName("1.0"); @@ -67,7 +65,7 @@ public class VersionMapperTest { } - private WorkflowVersion createWorkflowVersion(){ + private WorkflowVersion createWorkflowVersion() { WorkflowVersion workflowVersion = new WorkflowVersion(); workflowVersion.setId("wf_version_id"); workflowVersion.setBaseId("wf_base_version_id"); diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/mapping/VersionStatusMapperTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionStatusMapperTest.java index cb3444d4..0d4b6cd5 100644 --- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/mapping/VersionStatusMapperTest.java +++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionStatusMapperTest.java @@ -1,11 +1,10 @@ -package org.onap.sdc.workflow.api.mapping; +package org.onap.sdc.workflow.services.impl.mappers; import static org.junit.Assert.assertEquals; import org.junit.Test; import org.junit.runner.RunWith; import org.onap.sdc.workflow.persistence.types.WorkflowVersionStatus; -import org.onap.sdc.workflow.services.mappers.VersionStatusMapper; import org.openecomp.sdc.versioning.dao.types.VersionStatus; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.ComponentScan; diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/mapping/WorkflowMapperTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/WorkflowMapperTest.java index 53f63091..55802cc0 100644 --- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/mapping/WorkflowMapperTest.java +++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/WorkflowMapperTest.java @@ -1,4 +1,4 @@ -package org.onap.sdc.workflow.api.mapping; +package org.onap.sdc.workflow.services.impl.mappers; import static org.junit.Assert.assertEquals; @@ -6,12 +6,9 @@ import static org.junit.Assert.assertNotNull; import static org.onap.sdc.workflow.TestUtil.createItem; import static org.onap.sdc.workflow.TestUtil.createWorkflow; -import java.util.HashMap; import org.junit.Test; import org.junit.runner.RunWith; import org.onap.sdc.workflow.persistence.types.Workflow; -import org.onap.sdc.workflow.persistence.types.WorkflowProperty; -import org.onap.sdc.workflow.services.mappers.WorkflowMapper; import org.openecomp.sdc.versioning.types.Item; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.ComponentScan; |