aboutsummaryrefslogtreecommitdiffstats
path: root/workflow-designer-be/src/main/java
diff options
context:
space:
mode:
authorayalaben <ayala.benzvi@amdocs.com>2018-08-21 14:45:28 +0300
committerayalaben <ayala.benzvi@amdocs.com>2018-08-22 10:29:56 +0300
commit628397661a8b023a17316f9a501c8bd8af107a3d (patch)
treedd2d7864d0f85f4e4973ce5ac2da670a8ceb11a1 /workflow-designer-be/src/main/java
parent26103fb6434f652e98cb8943d9124a29a9f7c5d3 (diff)
Search Workflow by name
Change-Id: Ib45a028638293052865039a1f7bd6bf8b48e8e36 Issue-ID: SDC-1662 Signed-off-by: ayalaben <ayala.benzvi@amdocs.com>
Diffstat (limited to 'workflow-designer-be/src/main/java')
-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
3 files changed, 22 insertions, 12 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));
}