summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowController.java9
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/WorkflowManager.java6
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImpl.java19
-rw-r--r--workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowControllerTest.java22
-rw-r--r--workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImplTest.java34
5 files changed, 51 insertions, 39 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 18288e27..8cc1df4e 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
@@ -80,10 +80,13 @@ public class WorkflowController {
value = "Number of returned items"),
@ApiImplicitParam(name = SORT, dataType = "string", paramType = "query", defaultValue = "name:asc",
value = "Sorting criteria in the format: property:(asc|desc). Default sort order is ascending.",
- allowableValues = "name:asc,name:desc")})
- public Page<Workflow> list(@ApiIgnore VersionStatesFormatter versionStateFilter, @ApiIgnore Paging paging,
+ allowableValues = "name:asc,name:desc"),
+ @ApiImplicitParam(name = "searchNameFilter", dataType = "string", paramType = "query",
+ value = "Filter by workflow name")})
+ public Page<Workflow> list(@ApiIgnore String searchNameFilter,
+ @ApiIgnore VersionStatesFormatter versionStateFilter, @ApiIgnore Paging paging,
@ApiIgnore Sorting sorting, @RequestHeader(USER_ID_HEADER) String user) {
- return workflowManager.list(versionStateFilter.getVersionStates(), initRequestSpec(paging, sorting));
+ return workflowManager.list(searchNameFilter, versionStateFilter.getVersionStates(), initRequestSpec(paging, sorting));
}
@PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE)
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 3ef38d75..5190da14 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
@@ -17,14 +17,14 @@
package org.onap.sdc.workflow.services;
import java.util.Set;
-import org.onap.sdc.workflow.services.types.Workflow;
-import org.onap.sdc.workflow.services.types.WorkflowVersionState;
import org.onap.sdc.workflow.services.types.Page;
import org.onap.sdc.workflow.services.types.RequestSpec;
+import org.onap.sdc.workflow.services.types.Workflow;
+import org.onap.sdc.workflow.services.types.WorkflowVersionState;
public interface WorkflowManager {
- Page<Workflow> list(Set<WorkflowVersionState> versionStatesFilter, RequestSpec requestSpec);
+ Page<Workflow> list(String searchNameFilter, Set<WorkflowVersionState> versionStatesFilter, RequestSpec requestSpec);
Workflow get(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 e16c7b41..a8998cce 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
@@ -27,8 +27,6 @@ import java.util.List;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;
-import org.onap.sdc.workflow.services.types.Workflow;
-import org.onap.sdc.workflow.services.types.WorkflowVersionState;
import org.onap.sdc.workflow.services.UniqueValueService;
import org.onap.sdc.workflow.services.WorkflowManager;
import org.onap.sdc.workflow.services.exceptions.EntityNotFoundException;
@@ -39,6 +37,8 @@ import org.onap.sdc.workflow.services.types.PagingRequest;
import org.onap.sdc.workflow.services.types.RequestSpec;
import org.onap.sdc.workflow.services.types.Sort;
import org.onap.sdc.workflow.services.types.SortingRequest;
+import org.onap.sdc.workflow.services.types.Workflow;
+import org.onap.sdc.workflow.services.types.WorkflowVersionState;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdc.versioning.ItemManager;
@@ -78,7 +78,8 @@ public class WorkflowManagerImpl implements WorkflowManager {
}
@Override
- public Page<Workflow> list(Set<WorkflowVersionState> versionStatesFilter, RequestSpec requestSpec) {
+ public Page<Workflow> list(String searchNameFilter, Set<WorkflowVersionState> versionStatesFilter,
+ RequestSpec requestSpec) {
requestSpec = getRequestSpec(requestSpec);
Set<VersionStatus> versionStatusesFilter =
@@ -86,7 +87,8 @@ public class WorkflowManagerImpl implements WorkflowManager {
versionStatesFilter.stream().map(versionStateMapper::workflowVersionStateToVersionStatus)
.collect(Collectors.toSet());
- Collection<Item> workflowItems = itemManager.list(getFilter(versionStatusesFilter));
+ Predicate<Item> filter = addSearchNameFilter(WORKFLOW_ITEM_FILTER, searchNameFilter);
+ Collection<Item> workflowItems = itemManager.list(addVersionStatusFilter(filter, versionStatusesFilter));
List<Workflow> workflowsSlice = workflowItems.stream().map(workflowMapper::itemToWorkflow)
.sorted(getWorkflowComparator(requestSpec.getSorting()))
@@ -170,8 +172,13 @@ public class WorkflowManagerImpl implements WorkflowManager {
return byNameAscending ? byName : byName.reversed();
}
- private static Predicate<Item> getFilter(Set<VersionStatus> versionStatuses) {
- return WORKFLOW_ITEM_FILTER
+ private static Predicate<Item> addSearchNameFilter(Predicate<Item> filter, String searchNameFilter) {
+ return filter
+ .and(item -> searchNameFilter == null || item.getName().contains(searchNameFilter));
+ }
+
+ private static Predicate<Item> addVersionStatusFilter(Predicate<Item> filter, Set<VersionStatus> versionStatuses) {
+ return filter
.and(item -> versionStatuses == null || item.getVersionStatusCounters().keySet().stream()
.anyMatch(versionStatuses::contains));
}
diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowControllerTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowControllerTest.java
index f8f86f1f..258e9c51 100644
--- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowControllerTest.java
+++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowControllerTest.java
@@ -104,7 +104,7 @@ public class WorkflowControllerTest {
result.andExpect(jsonPath(String.format("$.items[%s].id", i), is(String.valueOf(i + 1))));
}
- verify(workflowManagerMock).list(any(), requestSpecArg.capture());
+ verify(workflowManagerMock).list(any(), any(), requestSpecArg.capture());
assertRequestSpec(requestSpecArg.getValue(), DEFAULT_OFFSET, DEFAULT_LIMIT, Collections.emptyList());
}
@@ -114,7 +114,7 @@ public class WorkflowControllerTest {
mockMvc.perform(get(RestPath.getWorkflowsPathAllQueryParams(DEFAULT_SORT_VALUE, "2", "1"))
.header(USER_ID_HEADER, USER_ID).contentType(APPLICATION_JSON)).andDo(print())
.andExpect(status().isOk()).andExpect(jsonPath("$.items", hasSize(3)));
- verify(workflowManagerMock).list(any(), requestSpecArg.capture());
+ verify(workflowManagerMock).list(any(), any(), requestSpecArg.capture());
assertRequestSpec(requestSpecArg.getValue(), 1, 2, Collections.singletonList(new Sort("name", true)));
}
@@ -124,7 +124,7 @@ public class WorkflowControllerTest {
mockMvc.perform(get(RestPath.getWorkflowsPathAllQueryParams(DEFAULT_SORT_VALUE, "-2", "1"))
.header(USER_ID_HEADER, USER_ID).contentType(APPLICATION_JSON)).andDo(print())
.andExpect(status().isOk()).andExpect(jsonPath("$.items", hasSize(3)));
- verify(workflowManagerMock).list(any(), requestSpecArg.capture());
+ verify(workflowManagerMock).list(any(), any(), requestSpecArg.capture());
assertRequestSpec(requestSpecArg.getValue(), 1, DEFAULT_LIMIT,
Collections.singletonList(new Sort("name", true)));
}
@@ -135,7 +135,7 @@ public class WorkflowControllerTest {
mockMvc.perform(get(RestPath.getWorkflowsPathAllQueryParams(DEFAULT_SORT_VALUE, "2", "-1"))
.header(USER_ID_HEADER, USER_ID).contentType(APPLICATION_JSON)).andDo(print())
.andExpect(status().isOk()).andExpect(jsonPath("$.items", hasSize(3)));
- verify(workflowManagerMock).list(any(), requestSpecArg.capture());
+ verify(workflowManagerMock).list(any(), any(), requestSpecArg.capture());
assertRequestSpec(requestSpecArg.getValue(), DEFAULT_OFFSET, 2,
Collections.singletonList(new Sort("name", true)));
}
@@ -146,7 +146,7 @@ public class WorkflowControllerTest {
mockMvc.perform(get(RestPath.getWorkflowsPathAllQueryParams(DEFAULT_SORT_VALUE, "abc", "0"))
.header(USER_ID_HEADER, USER_ID).contentType(APPLICATION_JSON)).andDo(print())
.andExpect(status().isOk()).andExpect(jsonPath("$.items", hasSize(3)));
- verify(workflowManagerMock).list(any(), requestSpecArg.capture());
+ verify(workflowManagerMock).list(any(), any(), requestSpecArg.capture());
assertRequestSpec(requestSpecArg.getValue(), 0, DEFAULT_LIMIT,
Collections.singletonList(new Sort("name", true)));
}
@@ -157,7 +157,7 @@ public class WorkflowControllerTest {
mockMvc.perform(get(RestPath.getWorkflowsPathAllQueryParams(DEFAULT_SORT_VALUE, "2", "abc"))
.header(USER_ID_HEADER, USER_ID).contentType(APPLICATION_JSON)).andDo(print())
.andExpect(jsonPath("$.items", hasSize(3)));
- verify(workflowManagerMock).list(any(), requestSpecArg.capture());
+ verify(workflowManagerMock).list(any(), any(), requestSpecArg.capture());
assertRequestSpec(requestSpecArg.getValue(), DEFAULT_OFFSET, 2,
Collections.singletonList(new Sort("name", true)));
}
@@ -168,7 +168,7 @@ public class WorkflowControllerTest {
mockMvc.perform(get(RestPath.getWorkflowsPathNoSortAndLimit("1")).header(USER_ID_HEADER, USER_ID)
.contentType(APPLICATION_JSON)).andDo(print())
.andExpect(jsonPath("$.items", hasSize(3)));
- verify(workflowManagerMock).list(any(), requestSpecArg.capture());
+ verify(workflowManagerMock).list(any(), any(), requestSpecArg.capture());
assertRequestSpec(requestSpecArg.getValue(), 1, DEFAULT_LIMIT, Collections.emptyList());
}
@@ -178,7 +178,7 @@ public class WorkflowControllerTest {
mockMvc.perform(get(RestPath.getWorkflowsPathNoSortAndOffset("1")).header(USER_ID_HEADER, USER_ID)
.contentType(APPLICATION_JSON)).andDo(print())
.andExpect(status().isOk()).andExpect(jsonPath("$.items", hasSize(3)));
- verify(workflowManagerMock).list(any(), requestSpecArg.capture());
+ verify(workflowManagerMock).list(any(), any(), requestSpecArg.capture());
assertRequestSpec(requestSpecArg.getValue(), DEFAULT_OFFSET, 1, Collections.emptyList());
}
@@ -251,8 +251,10 @@ public class WorkflowControllerTest {
}
private void mockManagerList3() {
- doReturn(new Page<>(Arrays.asList(createWorkflow(1, true), createWorkflow(2, true), createWorkflow(3, true)),
- new PagingRequest(DEFAULT_OFFSET, DEFAULT_LIMIT), 3)).when(workflowManagerMock).list(any(), any());
+ doReturn(new Page<>(Arrays.asList(createWorkflow(1, true),
+ createWorkflow(2, true), createWorkflow(3, true)),
+ new PagingRequest(DEFAULT_OFFSET, DEFAULT_LIMIT), 3)).when(workflowManagerMock)
+ .list(any(), any(), any());
}
private static void assertRequestSpec(RequestSpec actual, int expectedOffset, int expectedLimit,
diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImplTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImplTest.java
index 2b93075b..e2df4ec0 100644
--- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImplTest.java
+++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImplTest.java
@@ -25,8 +25,6 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
-import org.onap.sdc.workflow.services.types.Workflow;
-import org.onap.sdc.workflow.services.types.WorkflowVersionState;
import org.onap.sdc.workflow.services.UniqueValueService;
import org.onap.sdc.workflow.services.exceptions.EntityNotFoundException;
import org.onap.sdc.workflow.services.impl.mappers.VersionStateMapper;
@@ -37,6 +35,8 @@ import org.onap.sdc.workflow.services.types.PagingRequest;
import org.onap.sdc.workflow.services.types.RequestSpec;
import org.onap.sdc.workflow.services.types.Sort;
import org.onap.sdc.workflow.services.types.SortingRequest;
+import org.onap.sdc.workflow.services.types.Workflow;
+import org.onap.sdc.workflow.services.types.WorkflowVersionState;
import org.openecomp.sdc.versioning.ItemManager;
import org.openecomp.sdc.versioning.types.Item;
import org.openecomp.sdc.versioning.types.ItemStatus;
@@ -80,7 +80,7 @@ public class WorkflowManagerImplTest {
doReturn(ITEMS).when(itemManagerMock).list(any());
mockItemToWorkflowMaps();
RequestSpec requestSpec = createRequestSpec(0, 20, true);
- Page<Workflow> workflows = workflowManager.list(null, requestSpec);
+ Page<Workflow> workflows = workflowManager.list(null,null, requestSpec);
Map<String, Workflow> workflowById =
workflows.getItems().stream().collect(Collectors.toMap(Workflow::getId, Function.identity()));
@@ -102,7 +102,7 @@ public class WorkflowManagerImplTest {
RequestSpec requestSpec = createRequestSpec(0, 20, true);
Page<Workflow> workflows =
- workflowManager.list(Collections.singleton(WorkflowVersionState.CERTIFIED), requestSpec);
+ workflowManager.list(null,Collections.singleton(WorkflowVersionState.CERTIFIED), requestSpec);
Map<String, Workflow> workflowById =
workflows.getItems().stream().collect(Collectors.toMap(Workflow::getId, Function.identity()));
@@ -172,7 +172,7 @@ public class WorkflowManagerImplTest {
public void listWhenRequestSpecIsNull() {
doReturn(ITEMS).when(itemManagerMock).list(any());
mockItemToWorkflowMaps();
- Page<Workflow> workflows = workflowManager.list(null, null);
+ Page<Workflow> workflows = workflowManager.list(null,null, null);
assertEquals(ITEMS.size(), workflows.getItems().size());
assertPaging(workflows.getPaging(), DEFAULT_OFFSET, DEFAULT_LIMIT, ITEMS.size());
@@ -187,7 +187,7 @@ public class WorkflowManagerImplTest {
public void listWhenPagingIsNull() {
doReturn(ITEMS).when(itemManagerMock).list(any());
mockItemToWorkflowMaps();
- Page<Workflow> workflows = workflowManager.list(null, new RequestSpec(null,
+ Page<Workflow> workflows = workflowManager.list(null,null, new RequestSpec(null,
SortingRequest.builder().sort(new Sort(SORT_FIELD_NAME, true)).build()));
assertEquals(ITEMS.size(), workflows.getItems().size());
@@ -200,7 +200,7 @@ public class WorkflowManagerImplTest {
mockItemToWorkflowMaps();
RequestSpec requestSpec = new RequestSpec(new PagingRequest(-2, -8),
SortingRequest.builder().sort(new Sort(SORT_FIELD_NAME, true)).build());
- Page<Workflow> workflows = workflowManager.list(null, requestSpec);
+ Page<Workflow> workflows = workflowManager.list(null,null, requestSpec);
assertEquals(ITEMS.size(), workflows.getItems().size());
assertPaging(workflows.getPaging(), DEFAULT_OFFSET, DEFAULT_LIMIT, ITEMS.size());
@@ -211,7 +211,7 @@ public class WorkflowManagerImplTest {
doReturn(ITEMS).when(itemManagerMock).list(any());
mockItemToWorkflowMaps();
RequestSpec requestSpec = new RequestSpec(new PagingRequest(2, 8), null);
- Page<Workflow> workflows = workflowManager.list(null, requestSpec);
+ Page<Workflow> workflows = workflowManager.list(null,null, requestSpec);
assertEquals(3, workflows.getItems().size());
assertPaging(workflows.getPaging(), requestSpec.getPaging().getOffset(), requestSpec.getPaging().getLimit(),
@@ -228,7 +228,7 @@ public class WorkflowManagerImplTest {
doReturn(ITEMS).when(itemManagerMock).list(any());
mockItemToWorkflowMaps();
RequestSpec requestSpec = new RequestSpec(new PagingRequest(2, 8), SortingRequest.builder().build());
- Page<Workflow> workflows = workflowManager.list(null, requestSpec);
+ Page<Workflow> workflows = workflowManager.list(null,null, requestSpec);
assertEquals(3, workflows.getItems().size());
assertPaging(workflows.getPaging(), requestSpec.getPaging().getOffset(), requestSpec.getPaging().getLimit(),
@@ -245,7 +245,7 @@ public class WorkflowManagerImplTest {
RequestSpec requestSpec = createRequestSpec(0, 5, true);
doReturn(ITEMS).when(itemManagerMock).list(any());
mockItemToWorkflowMaps();
- Page<Workflow> workflows = workflowManager.list(null, requestSpec);
+ Page<Workflow> workflows = workflowManager.list(null,null, requestSpec);
assertEquals(5, workflows.getItems().size());
assertPaging(workflows.getPaging(), requestSpec.getPaging().getOffset(), requestSpec.getPaging().getLimit(),
@@ -257,7 +257,7 @@ public class WorkflowManagerImplTest {
RequestSpec requestSpec = createRequestSpec(0, 3, true);
doReturn(ITEMS).when(itemManagerMock).list(any());
mockItemToWorkflowMaps();
- Page<Workflow> workflows = workflowManager.list(null, requestSpec);
+ Page<Workflow> workflows = workflowManager.list(null,null, requestSpec);
assertEquals(3, workflows.getItems().size());
assertPaging(workflows.getPaging(), requestSpec.getPaging().getOffset(), requestSpec.getPaging().getLimit(),
ITEMS.size());
@@ -269,7 +269,7 @@ public class WorkflowManagerImplTest {
RequestSpec requestSpec = createRequestSpec(3, 1, true);
doReturn(ITEMS).when(itemManagerMock).list(any());
mockItemToWorkflowMaps();
- Page<Workflow> workflows = workflowManager.list(null, requestSpec);
+ Page<Workflow> workflows = workflowManager.list(null,null, requestSpec);
assertEquals(1, workflows.getItems().size());
assertPaging(workflows.getPaging(), requestSpec.getPaging().getOffset(), requestSpec.getPaging().getLimit(),
ITEMS.size());
@@ -280,7 +280,7 @@ public class WorkflowManagerImplTest {
RequestSpec requestSpec = createRequestSpec(0, 10, true);
doReturn(ITEMS).when(itemManagerMock).list(any());
mockItemToWorkflowMaps();
- Page<Workflow> workflows = workflowManager.list(null, requestSpec);
+ Page<Workflow> workflows = workflowManager.list(null,null, requestSpec);
assertEquals(5, workflows.getItems().size());
assertPaging(workflows.getPaging(), requestSpec.getPaging().getOffset(), requestSpec.getPaging().getLimit(),
ITEMS.size());
@@ -291,7 +291,7 @@ public class WorkflowManagerImplTest {
RequestSpec requestSpec = createRequestSpec(6, 3, true);
doReturn(ITEMS).when(itemManagerMock).list(any());
mockItemToWorkflowMaps();
- Page<Workflow> workflows = workflowManager.list(null, requestSpec);
+ Page<Workflow> workflows = workflowManager.list(null,null, requestSpec);
assertEquals(0, workflows.getItems().size());
assertPaging(workflows.getPaging(), requestSpec.getPaging().getOffset(), requestSpec.getPaging().getLimit(),
ITEMS.size());
@@ -302,7 +302,7 @@ public class WorkflowManagerImplTest {
doReturn(ITEMS).when(itemManagerMock).list(any());
mockItemToWorkflowMaps();
RequestSpec requestSpec = createRequestSpec(0, 5555, true);
- Page<Workflow> workflows = workflowManager.list(null, requestSpec);
+ Page<Workflow> workflows = workflowManager.list(null,null, requestSpec);
assertEquals(ITEMS.size(), workflows.getItems().size());
assertPaging(workflows.getPaging(), requestSpec.getPaging().getOffset(), MAX_LIMIT, ITEMS.size());
@@ -313,7 +313,7 @@ public class WorkflowManagerImplTest {
RequestSpec requestSpec = createRequestSpec(10, 10, true);
doReturn(ITEMS).when(itemManagerMock).list(any());
mockItemToWorkflowMaps();
- Page<Workflow> workflows = workflowManager.list(null, requestSpec);
+ Page<Workflow> workflows = workflowManager.list(null,null, requestSpec);
assertEquals(0, workflows.getItems().size());
assertPaging(workflows.getPaging(), requestSpec.getPaging().getOffset(), requestSpec.getPaging().getLimit(),
ITEMS.size());
@@ -324,7 +324,7 @@ public class WorkflowManagerImplTest {
RequestSpec requestSpec = createRequestSpec(2, 1, false);
doReturn(ITEMS).when(itemManagerMock).list(any());
mockItemToWorkflowMaps();
- Page<Workflow> workflows = workflowManager.list(null, requestSpec);
+ Page<Workflow> workflows = workflowManager.list(null,null, requestSpec);
assertEquals(1, workflows.getItems().size());
assertPaging(workflows.getPaging(), requestSpec.getPaging().getOffset(), requestSpec.getPaging().getLimit(),
ITEMS.size());