-
Notifications
You must be signed in to change notification settings - Fork 221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support name filter at get workflows #1525
Changes from 6 commits
8afc292
e71ba3d
49492fd
af05bb1
983b31a
601788e
3ea375a
102cb3a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,8 +39,6 @@ | |
import org.skife.jdbi.v2.sqlobject.stringtemplate.UseStringTemplate3StatementLocator; | ||
import org.skife.jdbi.v2.tweak.ResultSetMapper; | ||
|
||
import javax.activation.DataSource; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.security.MessageDigest; | ||
import java.security.NoSuchAlgorithmException; | ||
|
@@ -53,8 +51,8 @@ | |
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
import static java.util.Locale.ENGLISH; | ||
import static java.nio.charset.StandardCharsets.UTF_8; | ||
import static java.util.Locale.ENGLISH; | ||
|
||
public class DatabaseProjectStoreManager | ||
extends BasicDatabaseStoreManager<DatabaseProjectStoreManager.Dao> | ||
|
@@ -292,10 +290,17 @@ public StoredWorkflowDefinitionWithProject getLatestWorkflowDefinitionByName(int | |
public List<StoredWorkflowDefinitionWithProject> getLatestActiveWorkflowDefinitions( | ||
int pageSize, | ||
Optional<Long> lastId, | ||
Optional<String> namePattern, | ||
AccessController.ListFilter acFilter) | ||
throws ResourceNotFoundException | ||
{ | ||
return autoCommit((handle, dao) -> dao.getLatestActiveWorkflowDefinitions(siteId, pageSize, lastId.or(0L), acFilter.getSql())); | ||
return autoCommit((handle, dao) -> dao.getLatestActiveWorkflowDefinitions( | ||
siteId, | ||
pageSize, | ||
lastId.or(0L), | ||
generatePartialMatchPattern(namePattern), | ||
acFilter.getSql()) | ||
); | ||
} | ||
|
||
@DigdagTimed(value = "dpst_", category = "db", appendMethodName = true) | ||
|
@@ -355,6 +360,19 @@ public TimeZoneMap getWorkflowTimeZonesByIdList(List<Long> defIdList) | |
Map<Long, ZoneId> map = IdTimeZone.listToMap(list); | ||
return new TimeZoneMap(map); | ||
} | ||
|
||
private String generatePartialMatchPattern(Optional<String> pattern) | ||
{ | ||
// If provided pattern is absent or empty string, just set '%' | ||
// so that the pattern does not affect to a where clause. | ||
return pattern.isPresent() && !pattern.get().isEmpty() ? "%" + escapeLikePattern(pattern.get()) + "%" : "%"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed at 3ea375a |
||
} | ||
|
||
private String escapeLikePattern(String pattern) | ||
{ | ||
return pattern.replace("%", "\\%") | ||
.replace("_", "\\_"); | ||
} | ||
} | ||
|
||
private static class IdTimeZone | ||
|
@@ -571,13 +589,20 @@ public interface H2Dao | |
" join projects proj on a.project_id = proj.id" + | ||
" join workflow_configs wc on wc.id = wd.config_id" + | ||
" where wd.id \\> :lastId" + | ||
// `workflow_definitions` table has a composite index | ||
// for `revision_id` and `name` (`workflow_definitions_on_revision_id_and_name`). | ||
// And the index is used for filter by `revision_id` and `name`. | ||
// Since this query always limits the records by `revision_id` (the latest revision's one), | ||
// partial matching of `name` (e.g. '%test%') can be accepted. | ||
" and wd.name like :name" + | ||
" and <acFilter>" + | ||
" order by wd.id" + | ||
" limit :limit") | ||
List<StoredWorkflowDefinitionWithProject> getLatestActiveWorkflowDefinitions( | ||
@Bind("siteId") int siteId, | ||
@Bind("limit") int limit, | ||
@Bind("lastId") long lastId, | ||
@Bind("name") String name, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. renamed at 601788e There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm... I can't see the change on this code review.... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry. Now I fixed at 102cb3a |
||
@Define("acFilter") String acFilter); | ||
} | ||
|
||
|
@@ -613,6 +638,12 @@ public interface PgDao | |
" group by r.project_id" + | ||
" )) " + | ||
" and wf.id \\> :lastId" + | ||
// `workflow_definitions` table has a composite index | ||
// for `revision_id` and `name` (`workflow_definitions_on_revision_id_and_name`). | ||
// And the index is used for filter by `revision_id` and `name`. | ||
// Since this query always limits the records by `revision_id` (the latest revision's one), | ||
// partial matching of `name` (e.g. '%test%') can be accepted. | ||
" and wf.name like :name" + | ||
" and <acFilter>" + | ||
" order by wf.id" + | ||
" limit :limit" + | ||
|
@@ -625,6 +656,7 @@ List<StoredWorkflowDefinitionWithProject> getLatestActiveWorkflowDefinitions( | |
@Bind("siteId") int siteId, | ||
@Bind("limit") int limit, | ||
@Bind("lastId") long lastId, | ||
@Bind("name") String name, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. renamed at 601788e There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry. Now I fixed at 102cb3a |
||
@Define("acFilter") String acFilter); | ||
} | ||
|
||
|
@@ -728,7 +760,7 @@ List<StoredProject> getProjects( | |
" limit 1") | ||
StoredWorkflowDefinitionWithProject getLatestWorkflowDefinitionByName(@Bind("siteId") int siteId, @Bind("projId") int projId, @Bind("name") String name); | ||
|
||
List<StoredWorkflowDefinitionWithProject> getLatestActiveWorkflowDefinitions(int siteId, int limit, long lastId, String acFilter); | ||
List<StoredWorkflowDefinitionWithProject> getLatestActiveWorkflowDefinitions(int siteId, int limit, long lastId, String name, String acFilter); | ||
|
||
// getWorkflowDetailsById is same with getWorkflowDetailsByIdInternal | ||
// excepting site_id check | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍