Skip to content

Commit

Permalink
Closes sismics#192: workflow active info + search criteria
Browse files Browse the repository at this point in the history
  • Loading branch information
jendib committed Mar 6, 2018
1 parent 71f15e1 commit 2c90df2
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,14 @@ public void findByCriteria(PaginatedList<DocumentDto> paginatedList, DocumentCri

StringBuilder sb = new StringBuilder("select distinct d.DOC_ID_C c0, d.DOC_TITLE_C c1, d.DOC_DESCRIPTION_C c2, d.DOC_CREATEDATE_D c3, d.DOC_LANGUAGE_C c4, ");
sb.append(" (select count(s.SHA_ID_C) from T_SHARE s, T_ACL ac where ac.ACL_SOURCEID_C = d.DOC_ID_C and ac.ACL_TARGETID_C = s.SHA_ID_C and ac.ACL_DELETEDATE_D is null and s.SHA_DELETEDATE_D is null) c5, ");
sb.append(" (select count(f.FIL_ID_C) from T_FILE f where f.FIL_DELETEDATE_D is null and f.FIL_IDDOC_C = d.DOC_ID_C) c6 ");
sb.append(" (select count(f.FIL_ID_C) from T_FILE f where f.FIL_DELETEDATE_D is null and f.FIL_IDDOC_C = d.DOC_ID_C) c6, ");
sb.append(" rs2.RTP_ID_C c7 ");
sb.append(" from T_DOCUMENT d ");

sb.append(" left join (select rs.*, rs3.idDocument\n" +
"from T_ROUTE_STEP rs \n" +
"join (select r.RTE_IDDOCUMENT_C idDocument, rs.RTP_IDROUTE_C idRoute, min(rs.RTP_ORDER_N) minOrder from T_ROUTE_STEP rs join T_ROUTE r on r.RTE_ID_C = rs.RTP_IDROUTE_C and r.RTE_DELETEDATE_D is null where rs.RTP_DELETEDATE_D is null and rs.RTP_ENDDATE_D is null group by rs.RTP_IDROUTE_C, r.RTE_IDDOCUMENT_C) rs3 on rs.RTP_IDROUTE_C = rs3.idRoute and rs.RTP_ORDER_N = rs3.minOrder \n" +
"where rs.RTP_IDTARGET_C in (:targetIdList)) rs2 on rs2.idDocument = d.DOC_ID_C ");

// Add search criterias
if (criteria.getTargetIdList() != null) {
// Read permission is enough for searching
Expand Down Expand Up @@ -251,7 +256,10 @@ public void findByCriteria(PaginatedList<DocumentDto> paginatedList, DocumentCri
criteriaList.add("d.DOC_IDUSER_C = :creatorId");
parameterMap.put("creatorId", criteria.getCreatorId());
}

if (criteria.getActiveRoute() != null && criteria.getActiveRoute()) {
criteriaList.add("rs2.RTP_ID_C is not null");
}

criteriaList.add("d.DOC_DELETEDATE_D is null");

if (!criteriaList.isEmpty()) {
Expand All @@ -274,7 +282,8 @@ public void findByCriteria(PaginatedList<DocumentDto> paginatedList, DocumentCri
documentDto.setCreateTimestamp(((Timestamp) o[i++]).getTime());
documentDto.setLanguage((String) o[i++]);
documentDto.setShared(((Number) o[i++]).intValue() > 0);
documentDto.setFileCount(((Number) o[i]).intValue());
documentDto.setFileCount(((Number) o[i++]).intValue());
documentDto.setActiveRoute(o[i] != null);
documentDtoList.add(documentDto);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public class DocumentCriteria {
* Creator ID.
*/
private String creatorId;

/**
* A route is active.
*/
private Boolean activeRoute;

public List<String> getTargetIdList() {
return targetIdList;
Expand Down Expand Up @@ -126,4 +131,13 @@ public String getCreatorId() {
public void setCreatorId(String creatorId) {
this.creatorId = creatorId;
}

public Boolean getActiveRoute() {
return activeRoute;
}

public DocumentCriteria setActiveRoute(Boolean activeRoute) {
this.activeRoute = activeRoute;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@ public class DocumentDto {
* Document creator.
*/
private String creator;


/**
* A route is active.
*/
private boolean activeRoute;

public String getId() {
return id;
}
Expand Down Expand Up @@ -213,4 +218,13 @@ public String getCreator() {
public void setCreator(String creator) {
this.creator = creator;
}

public boolean isActiveRoute() {
return activeRoute;
}

public DocumentDto setActiveRoute(boolean activeRoute) {
this.activeRoute = activeRoute;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ public void write(OutputStream outputStream) throws IOException, WebApplicationE
* @apiSuccess {Number} documents.create_date Create date (timestamp)
* @apiSuccess {String} documents.language Language
* @apiSuccess {Boolean} documents.shared True if the document is shared
* @apiSuccess {Boolean} documents.active_route True if a route is active on this document
* @apiSuccess {Number} documents.file_count Number of files in this document
* @apiSuccess {Object[]} documents.tags List of tags
* @apiSuccess {String} documents.tags.id ID
Expand Down Expand Up @@ -397,6 +398,7 @@ public Response list(
.add("create_date", documentDto.getCreateTimestamp())
.add("language", documentDto.getLanguage())
.add("shared", documentDto.getShared())
.add("active_route", documentDto.isActiveRoute())
.add("file_count", documentDto.getFileCount())
.add("tags", tags));
}
Expand Down Expand Up @@ -514,6 +516,12 @@ private DocumentCriteria parseSearchQuery(String search) {
documentCriteria.setCreatorId(user.getId());
}
break;
case "workflow":
// New shared state criteria
if (params[1].equals("me")) {
documentCriteria.setActiveRoute(true);
}
break;
case "full":
// New full content search criteria
fullQuery.add(params[1]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ angular.module('docs').controller('Document', function ($scope, $rootScope, $tim
return s + 'tag:' + t.name + ' ';
}, '');
}
if ($scope.advsearch.shared) {
search += 'shared:yes ';
}
if ($scope.advsearch.workflow) {
search += 'workflow:me ';
}
$scope.search = search;
$scope.searchOpened = false;
};
Expand Down
2 changes: 1 addition & 1 deletion docs-web/src/main/webapp/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
</div>

<div class="row" ng-controller="Footer">
<div class="col-md-12 footer text-center text-muted">
<div class="col-md-12 footer text-center text-muted small">
<div class="alert alert-danger" ng-show="app.global_storage_quota && app.global_storage_quota * 0.8 < app.global_storage_current"
translate="index.global_quota_warning"
translate-values="{ current: app.global_storage_current / 1000000, percent: app.global_storage_current / app.global_storage_quota * 100, total: app.global_storage_quota / 1000000 }">
Expand Down
3 changes: 3 additions & 0 deletions docs-web/src/main/webapp/src/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
"search_before_date": "Before this date",
"search_after_date": "After this date",
"search_tags": "Tags",
"search_shared": "Only shared documents",
"search_workflow": "Workflow assigned to me",
"search_clear": "Clear",
"any_language": "Any language",
"add_document": "Add a document",
Expand All @@ -56,6 +58,7 @@
"search": "Search",
"search_empty": "No matches for <strong>\"{{ search }}\"</strong>",
"shared": "Shared",
"active_route": "Workflow assigned to me",
"title": "Title",
"description": "Description",
"contributors": "Contributors",
Expand Down
13 changes: 13 additions & 0 deletions docs-web/src/main/webapp/src/partial/docs/document.html
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@
</div>
</div>

<div class="checkbox">
<label>
<input type="checkbox" ng-model="advsearch.shared"> {{ 'document.search_shared' | translate }}
</label>
</div>

<div class="checkbox">
<label>
<input type="checkbox" ng-model="advsearch.workflow"> {{ 'document.search_workflow' | translate }}
</label>
</div>

<div class="form-group text-center">
<button type="submit" ng-click="startSearch()" class="btn btn-primary">
<span class="glyphicon glyphicon-search"></span> {{ 'document.search' | translate }}
Expand Down Expand Up @@ -158,6 +170,7 @@
<td colspan="2">
{{ document.title }} ({{ document.file_count }})
<span class="glyphicon glyphicon-share" ng-if="document.shared" uib-tooltip="{{ 'document.shared' | translate }}"></span>
<span class="glyphicon glyphicon-random" ng-if="document.active_route" uib-tooltip="{{ 'document.active_route' | translate }}"></span>
<a href="#/document/view/{{ document.id }}" target="_blank" ng-click="$event.stopPropagation()"><span class="glyphicon glyphicon-link"></span></a>

<div class="pull-right text-muted small">{{ document.create_date | timeAgo: dateFormat }}</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ public void testDocumentResource() throws Exception {
Assert.assertEquals(tag1Id, tags.getJsonObject(0).getString("id"));
Assert.assertEquals("SuperTag", tags.getJsonObject(0).getString("name"));
Assert.assertEquals("#ffff00", tags.getJsonObject(0).getString("color"));

Assert.assertFalse(documents.getJsonObject(0).getBoolean("active_route"));

// List all documents from document3
json = target().path("/document/list")
.queryParam("sort_column", 3)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,28 @@ public void testRouteResource() throws Exception {
Assert.assertEquals("Check the document's metadata", step.getString("name"));
Assert.assertTrue(popEmail().contains("workflow step"));

// List all documents with route1
json = target().path("/document/list")
.queryParam("sort_column", 3)
.queryParam("asc", true)
.request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, route1Token)
.get(JsonObject.class);
JsonArray documents = json.getJsonArray("documents");
Assert.assertEquals(1, documents.size());
Assert.assertFalse(documents.getJsonObject(0).getBoolean("active_route"));

// List all documents with admin
json = target().path("/document/list")
.queryParam("sort_column", 3)
.queryParam("asc", true)
.request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
.get(JsonObject.class);
documents = json.getJsonArray("documents");
Assert.assertEquals(1, documents.size());
Assert.assertTrue(documents.getJsonObject(0).getBoolean("active_route"));

// Get the route on document 1
json = target().path("/route")
.queryParam("documentId", document1Id)
Expand Down Expand Up @@ -231,6 +253,23 @@ public void testRouteResource() throws Exception {
.get(JsonObject.class);
Assert.assertFalse(json.containsKey("route_step"));

// List all documents with route1
json = target().path("/document/list")
.request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, route1Token)
.get(JsonObject.class);
documents = json.getJsonArray("documents");
Assert.assertEquals(1, documents.size());
Assert.assertFalse(documents.getJsonObject(0).getBoolean("active_route"));

// List all documents with admin
json = target().path("/document/list")
.request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
.get(JsonObject.class);
documents = json.getJsonArray("documents");
Assert.assertEquals(0, documents.size());

// Start the default route on document 1
target().path("/route/start").request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, route1Token)
Expand All @@ -251,6 +290,33 @@ public void testRouteResource() throws Exception {
.get();
Assert.assertEquals(Response.Status.OK, Response.Status.fromStatusCode(response.getStatus()));

// List all documents with route1
json = target().path("/document/list")
.request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, route1Token)
.get(JsonObject.class);
documents = json.getJsonArray("documents");
Assert.assertEquals(1, documents.size());
Assert.assertFalse(documents.getJsonObject(0).getBoolean("active_route"));

// List all documents with admin
json = target().path("/document/list")
.request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
.get(JsonObject.class);
documents = json.getJsonArray("documents");
Assert.assertEquals(1, documents.size());
Assert.assertTrue(documents.getJsonObject(0).getBoolean("active_route"));

// Search documents with admin
json = target().path("/document/list")
.queryParam("search", "workflow:me")
.request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
.get(JsonObject.class);
documents = json.getJsonArray("documents");
Assert.assertEquals(1, documents.size());

// Cancel the route on document 1
target().path("/route")
.queryParam("documentId", document1Id)
Expand All @@ -269,5 +335,22 @@ public void testRouteResource() throws Exception {
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
.get();
Assert.assertEquals(Response.Status.NOT_FOUND, Response.Status.fromStatusCode(response.getStatus()));

// List all documents with route1
json = target().path("/document/list")
.request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, route1Token)
.get(JsonObject.class);
documents = json.getJsonArray("documents");
Assert.assertEquals(1, documents.size());
Assert.assertFalse(documents.getJsonObject(0).getBoolean("active_route"));

// List all documents with admin
json = target().path("/document/list")
.request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
.get(JsonObject.class);
documents = json.getJsonArray("documents");
Assert.assertEquals(0, documents.size());
}
}

0 comments on commit 2c90df2

Please sign in to comment.