#159: get routes on a document

This commit is contained in:
Benjamin Gamard 2018-02-01 23:26:29 +01:00
parent 6e6f892cb0
commit 8a854bb37d
11 changed files with 494 additions and 52 deletions

View File

@ -67,13 +67,13 @@ public class AclDao {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public List<AclDto> getBySourceId(String sourceId, AclType type) { public List<AclDto> getBySourceId(String sourceId, AclType type) {
EntityManager em = ThreadLocalContext.get().getEntityManager(); EntityManager em = ThreadLocalContext.get().getEntityManager();
StringBuilder sb = new StringBuilder("select a.ACL_ID_C, a.ACL_PERM_C, a.ACL_TARGETID_C, "); StringBuilder sb = new StringBuilder("select a.ACL_ID_C, a.ACL_PERM_C, a.ACL_TARGETID_C, ")
sb.append(" u.USE_USERNAME_C, s.SHA_ID_C, s.SHA_NAME_C, g.GRP_NAME_C "); .append(" u.USE_USERNAME_C, s.SHA_ID_C, s.SHA_NAME_C, g.GRP_NAME_C ")
sb.append(" from T_ACL a "); .append(" from T_ACL a ")
sb.append(" left join T_USER u on u.USE_ID_C = a.ACL_TARGETID_C "); .append(" left join T_USER u on u.USE_ID_C = a.ACL_TARGETID_C ")
sb.append(" left join T_SHARE s on s.SHA_ID_C = a.ACL_TARGETID_C "); .append(" left join T_SHARE s on s.SHA_ID_C = a.ACL_TARGETID_C ")
sb.append(" left join T_GROUP g on g.GRP_ID_C = a.ACL_TARGETID_C "); .append(" left join T_GROUP g on g.GRP_ID_C = a.ACL_TARGETID_C ")
sb.append(" where a.ACL_DELETEDATE_D is null and a.ACL_SOURCEID_C = :sourceId and a.ACL_TYPE_C = :type "); .append(" where a.ACL_DELETEDATE_D is null and a.ACL_SOURCEID_C = :sourceId and a.ACL_TYPE_C = :type ");
// Perform the query // Perform the query
Query q = em.createNativeQuery(sb.toString()); Query q = em.createNativeQuery(sb.toString());

View File

@ -1,13 +1,19 @@
package com.sismics.docs.core.dao.jpa; package com.sismics.docs.core.dao.jpa;
import com.google.common.base.Joiner;
import com.sismics.docs.core.constant.AuditLogType; import com.sismics.docs.core.constant.AuditLogType;
import com.sismics.docs.core.dao.jpa.criteria.RouteCriteria;
import com.sismics.docs.core.dao.jpa.dto.RouteDto;
import com.sismics.docs.core.model.jpa.Route; import com.sismics.docs.core.model.jpa.Route;
import com.sismics.docs.core.util.AuditLogUtil; import com.sismics.docs.core.util.AuditLogUtil;
import com.sismics.docs.core.util.jpa.QueryParam;
import com.sismics.docs.core.util.jpa.QueryUtil;
import com.sismics.docs.core.util.jpa.SortCriteria;
import com.sismics.util.context.ThreadLocalContext; import com.sismics.util.context.ThreadLocalContext;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import java.util.Date; import java.sql.Timestamp;
import java.util.UUID; import java.util.*;
/** /**
* Route DAO. * Route DAO.
@ -36,4 +42,48 @@ public class RouteDao {
return route.getId(); return route.getId();
} }
/**
* Returns the list of all routes.
*
* @param criteria Search criteria
* @param sortCriteria Sort criteria
* @return List of routes
*/
public List<RouteDto> findByCriteria(RouteCriteria criteria, SortCriteria sortCriteria) {
Map<String, Object> parameterMap = new HashMap<String, Object>();
List<String> criteriaList = new ArrayList<>();
StringBuilder sb = new StringBuilder("select r.RTE_ID_C c0, r.RTE_NAME_C c1, r.RTE_CREATEDATE_D c2");
sb.append(" from T_ROUTE r ");
// Add search criterias
if (criteria.getDocumentId() != null) {
criteriaList.add("r.RTE_IDDOCUMENT_C = :documentId");
parameterMap.put("documentId", criteria.getDocumentId());
}
criteriaList.add("r.RTE_DELETEDATE_D is null");
if (!criteriaList.isEmpty()) {
sb.append(" where ");
sb.append(Joiner.on(" and ").join(criteriaList));
}
// Perform the search
QueryParam queryParam = QueryUtil.getSortedQueryParam(new QueryParam(sb.toString(), parameterMap), sortCriteria);
@SuppressWarnings("unchecked")
List<Object[]> l = QueryUtil.getNativeQuery(queryParam).getResultList();
// Assemble results
List<RouteDto> dtoList = new ArrayList<>();
for (Object[] o : l) {
int i = 0;
RouteDto dto = new RouteDto();
dto.setId((String) o[i++]);
dto.setName((String) o[i++]);
dto.setCreateTimestamp(((Timestamp) o[i++]).getTime());
dtoList.add(dto);
}
return dtoList;
}
} }

View File

@ -1,17 +1,21 @@
package com.sismics.docs.core.dao.jpa; package com.sismics.docs.core.dao.jpa;
import com.google.common.base.Joiner;
import com.sismics.docs.core.constant.AclTargetType;
import com.sismics.docs.core.constant.RouteStepTransition; import com.sismics.docs.core.constant.RouteStepTransition;
import com.sismics.docs.core.constant.RouteStepType; import com.sismics.docs.core.constant.RouteStepType;
import com.sismics.docs.core.dao.jpa.criteria.RouteStepCriteria;
import com.sismics.docs.core.dao.jpa.dto.RouteStepDto; import com.sismics.docs.core.dao.jpa.dto.RouteStepDto;
import com.sismics.docs.core.model.jpa.RouteStep; import com.sismics.docs.core.model.jpa.RouteStep;
import com.sismics.docs.core.util.jpa.QueryParam;
import com.sismics.docs.core.util.jpa.QueryUtil;
import com.sismics.docs.core.util.jpa.SortCriteria;
import com.sismics.util.context.ThreadLocalContext; import com.sismics.util.context.ThreadLocalContext;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.Query; import javax.persistence.Query;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.Date; import java.util.*;
import java.util.List;
import java.util.UUID;
/** /**
* Route step DAO. * Route step DAO.
@ -43,35 +47,86 @@ public class RouteStepDao {
* @param documentId Document ID * @param documentId Document ID
* @return Current route step * @return Current route step
*/ */
@SuppressWarnings("unchecked")
public RouteStepDto getCurrentStep(String documentId) { public RouteStepDto getCurrentStep(String documentId) {
EntityManager em = ThreadLocalContext.get().getEntityManager(); List<RouteStepDto> routeStepDtoList = findByCriteria(new RouteStepCriteria()
StringBuilder sb = new StringBuilder("select rs.RTP_ID_C, rs.RTP_NAME_C, rs.RTP_TYPE_C, rs.RTP_TRANSITION_C, rs.RTP_COMMENT_C, rs.RTP_IDTARGET_C, rs.RTP_ENDDATE_D"); .setDocumentId(documentId)
sb.append(" from T_ROUTE_STEP rs "); .setEndDateIsNull(true), new SortCriteria(6, true));
sb.append(" join T_ROUTE r on r.RTE_ID_C = rs.RTP_IDROUTE_C "); if (routeStepDtoList.isEmpty()) {
sb.append(" where r.RTE_IDDOCUMENT_C = :documentId and rs.RTP_ENDDATE_D is null ");
sb.append(" order by rs.RTP_ORDER_N asc ");
Query q = em.createNativeQuery(sb.toString());
q.setParameter("documentId", documentId);
List<Object[]> l = q.getResultList();
if (l.isEmpty()) {
return null; return null;
} }
Object[] o = l.get(0); return routeStepDtoList.get(0);
}
/**
* Returns the list of all route steps.
*
* @param criteria Search criteria
* @param sortCriteria Sort criteria
* @return List of route steps
*/
public List<RouteStepDto> findByCriteria(RouteStepCriteria criteria, SortCriteria sortCriteria) {
Map<String, Object> parameterMap = new HashMap<>();
List<String> criteriaList = new ArrayList<>();
StringBuilder sb = new StringBuilder("select rs.RTP_ID_C, rs.RTP_NAME_C c0, rs.RTP_TYPE_C c1, rs.RTP_TRANSITION_C c2, rs.RTP_COMMENT_C c3, rs.RTP_IDTARGET_C c4, u.USE_USERNAME_C as targetUsername, g.GRP_NAME_C, rs.RTP_ENDDATE_D c5, uv.USE_USERNAME_C as validatorUsername, rs.RTP_ORDER_N c6")
.append(" from T_ROUTE_STEP rs ")
.append(" join T_ROUTE r on r.RTE_ID_C = rs.RTP_IDROUTE_C ")
.append(" left join T_USER uv on uv.USE_ID_C = rs.RTP_IDVALIDATORUSER_C ")
.append(" left join T_USER u on u.USE_ID_C = rs.RTP_IDTARGET_C ")
.append(" left join T_SHARE s on s.SHA_ID_C = rs.RTP_IDTARGET_C ")
.append(" left join T_GROUP g on g.GRP_ID_C = rs.RTP_IDTARGET_C ");
// Add search criterias
if (criteria.getDocumentId() != null) {
criteriaList.add("r.RTE_IDDOCUMENT_C = :documentId");
parameterMap.put("documentId", criteria.getDocumentId());
}
if (criteria.getRouteId() != null) {
criteriaList.add("rs.RTP_IDROUTE_C = :routeId");
parameterMap.put("routeId", criteria.getRouteId());
}
if (criteria.getEndDateIsNull() != null) {
criteriaList.add("RTP_ENDDATE_D is " + (criteria.getEndDateIsNull() ? "" : "not") + " null");
}
criteriaList.add("r.RTE_DELETEDATE_D is null");
if (!criteriaList.isEmpty()) {
sb.append(" where ");
sb.append(Joiner.on(" and ").join(criteriaList));
}
// Perform the search
QueryParam queryParam = QueryUtil.getSortedQueryParam(new QueryParam(sb.toString(), parameterMap), sortCriteria);
@SuppressWarnings("unchecked")
List<Object[]> l = QueryUtil.getNativeQuery(queryParam).getResultList();
// Assemble results
List<RouteStepDto> dtoList = new ArrayList<>();
for (Object[] o : l) {
int i = 0; int i = 0;
RouteStepDto routeStepDto = new RouteStepDto(); RouteStepDto dto = new RouteStepDto();
routeStepDto.setId((String) o[i++]); dto.setId((String) o[i++]);
routeStepDto.setName((String) o[i++]); dto.setName((String) o[i++]);
routeStepDto.setType(RouteStepType.valueOf((String) o[i++])); dto.setType(RouteStepType.valueOf((String) o[i++]));
String transition = (String) o[i++]; dto.setTransition((String) o[i++]);
routeStepDto.setTransition(transition == null ? null : RouteStepTransition.valueOf(transition)); dto.setComment((String) o[i++]);
routeStepDto.setComment((String) o[i++]); dto.setTargetId((String) o[i++]);
routeStepDto.setTargetId((String) o[i++]); String userName = (String) o[i++];
Timestamp endDateTimestamp = (Timestamp) o[i]; String groupName = (String) o[i++];
routeStepDto.setEndDateTimestamp(endDateTimestamp == null ? null : endDateTimestamp.getTime()); if (userName != null) {
return routeStepDto; dto.setTargetName(userName);
dto.setTargetType(AclTargetType.USER.name());
}
if (groupName != null) {
dto.setTargetName(groupName);
dto.setTargetType(AclTargetType.GROUP.name());
}
Timestamp endDateTimestamp = (Timestamp) o[i++];
dto.setEndDateTimestamp(endDateTimestamp == null ? null : endDateTimestamp.getTime());
dto.setValidatorUserName((String) o[i]);
dtoList.add(dto);
}
return dtoList;
} }
/** /**

View File

@ -0,0 +1,23 @@
package com.sismics.docs.core.dao.jpa.criteria;
/**
* Route criteria.
*
* @author bgamard
*/
public class RouteCriteria {
/**
* Document ID.
*/
private String documentId;
public String getDocumentId() {
return documentId;
}
public RouteCriteria setDocumentId(String documentId) {
this.documentId = documentId;
return this;
}
}

View File

@ -0,0 +1,51 @@
package com.sismics.docs.core.dao.jpa.criteria;
/**
* Route step criteria.
*
* @author bgamard
*/
public class RouteStepCriteria {
/**
* Document ID.
*/
private String documentId;
/**
* Route ID.
*/
private String routeId;
/**
* End date is null.
*/
private Boolean endDateIsNull;
public String getDocumentId() {
return documentId;
}
public RouteStepCriteria setDocumentId(String documentId) {
this.documentId = documentId;
return this;
}
public String getRouteId() {
return routeId;
}
public RouteStepCriteria setRouteId(String routeId) {
this.routeId = routeId;
return this;
}
public Boolean getEndDateIsNull() {
return endDateIsNull;
}
public RouteStepCriteria setEndDateIsNull(Boolean endDateIsNull) {
this.endDateIsNull = endDateIsNull;
return this;
}
}

View File

@ -0,0 +1,50 @@
package com.sismics.docs.core.dao.jpa.dto;
/**
* Route DTO.
*
* @author bgamard
*/
public class RouteDto {
/**
* Route ID.
*/
private String id;
/**
* Name.
*/
private String name;
/**
* Creation date.
*/
private Long createTimestamp;
public String getId() {
return id;
}
public RouteDto setId(String id) {
this.id = id;
return this;
}
public String getName() {
return name;
}
public RouteDto setName(String name) {
this.name = name;
return this;
}
public Long getCreateTimestamp() {
return createTimestamp;
}
public RouteDto setCreateTimestamp(Long createTimestamp) {
this.createTimestamp = createTimestamp;
return this;
}
}

View File

@ -1,6 +1,5 @@
package com.sismics.docs.core.dao.jpa.dto; package com.sismics.docs.core.dao.jpa.dto;
import com.sismics.docs.core.constant.RouteStepTransition;
import com.sismics.docs.core.constant.RouteStepType; import com.sismics.docs.core.constant.RouteStepType;
/** /**
@ -27,7 +26,7 @@ public class RouteStepDto {
/** /**
* Transition. * Transition.
*/ */
private RouteStepTransition transition; private String transition;
/** /**
* Comment. * Comment.
@ -39,11 +38,26 @@ public class RouteStepDto {
*/ */
private String targetId; private String targetId;
/**
* Target name.
*/
private String targetName;
/**
* Target type.
*/
private String targetType;
/** /**
* End date. * End date.
*/ */
private Long endDateTimestamp; private Long endDateTimestamp;
/**
* Validator's username.
*/
private String validatorUserName;
public String getId() { public String getId() {
return id; return id;
} }
@ -71,11 +85,11 @@ public class RouteStepDto {
return this; return this;
} }
public RouteStepTransition getTransition() { public String getTransition() {
return transition; return transition;
} }
public RouteStepDto setTransition(RouteStepTransition transition) { public RouteStepDto setTransition(String transition) {
this.transition = transition; this.transition = transition;
return this; return this;
} }
@ -98,6 +112,24 @@ public class RouteStepDto {
return this; return this;
} }
public String getTargetName() {
return targetName;
}
public RouteStepDto setTargetName(String targetName) {
this.targetName = targetName;
return this;
}
public String getTargetType() {
return targetType;
}
public RouteStepDto setTargetType(String targetType) {
this.targetType = targetType;
return this;
}
public Long getEndDateTimestamp() { public Long getEndDateTimestamp() {
return endDateTimestamp; return endDateTimestamp;
} }
@ -106,4 +138,13 @@ public class RouteStepDto {
this.endDateTimestamp = endDateTimestamp; this.endDateTimestamp = endDateTimestamp;
return this; return this;
} }
public String getValidatorUserName() {
return validatorUserName;
}
public RouteStepDto setValidatorUserName(String validatorUserName) {
this.validatorUserName = validatorUserName;
return this;
}
} }

View File

@ -12,7 +12,6 @@ import com.sismics.docs.core.model.jpa.Acl;
* @author bgamard * @author bgamard
*/ */
public class RoutingUtil { public class RoutingUtil {
/** /**
* Update routing ACLs according to the current route step. * Update routing ACLs according to the current route step.
* *

View File

@ -34,4 +34,17 @@ public class JsonUtil {
} }
return Json.createObjectBuilder().add("_", value).build().get("_"); return Json.createObjectBuilder().add("_", value).build().get("_");
} }
/**
* Returns a JsonValue from an Long.
*
* @param value Value
* @return JsonValue
*/
public static JsonValue nullable(Long value) {
if (value == null) {
return JsonValue.NULL;
}
return Json.createObjectBuilder().add("_", value).build().get("_");
}
} }

View File

@ -4,27 +4,28 @@ import com.sismics.docs.core.constant.AclTargetType;
import com.sismics.docs.core.constant.PermType; import com.sismics.docs.core.constant.PermType;
import com.sismics.docs.core.constant.RouteStepTransition; import com.sismics.docs.core.constant.RouteStepTransition;
import com.sismics.docs.core.constant.RouteStepType; import com.sismics.docs.core.constant.RouteStepType;
import com.sismics.docs.core.dao.jpa.AclDao; import com.sismics.docs.core.dao.jpa.*;
import com.sismics.docs.core.dao.jpa.RouteDao; import com.sismics.docs.core.dao.jpa.criteria.RouteCriteria;
import com.sismics.docs.core.dao.jpa.RouteModelDao; import com.sismics.docs.core.dao.jpa.criteria.RouteStepCriteria;
import com.sismics.docs.core.dao.jpa.RouteStepDao; import com.sismics.docs.core.dao.jpa.dto.DocumentDto;
import com.sismics.docs.core.dao.jpa.dto.RouteDto;
import com.sismics.docs.core.dao.jpa.dto.RouteStepDto; import com.sismics.docs.core.dao.jpa.dto.RouteStepDto;
import com.sismics.docs.core.model.jpa.Route; import com.sismics.docs.core.model.jpa.Route;
import com.sismics.docs.core.model.jpa.RouteModel; import com.sismics.docs.core.model.jpa.RouteModel;
import com.sismics.docs.core.model.jpa.RouteStep; import com.sismics.docs.core.model.jpa.RouteStep;
import com.sismics.docs.core.util.RoutingUtil; import com.sismics.docs.core.util.RoutingUtil;
import com.sismics.docs.core.util.SecurityUtil; import com.sismics.docs.core.util.SecurityUtil;
import com.sismics.docs.core.util.jpa.SortCriteria;
import com.sismics.rest.exception.ClientException; import com.sismics.rest.exception.ClientException;
import com.sismics.rest.exception.ForbiddenClientException; import com.sismics.rest.exception.ForbiddenClientException;
import com.sismics.rest.util.JsonUtil;
import com.sismics.rest.util.ValidationUtil; import com.sismics.rest.util.ValidationUtil;
import javax.json.*; import javax.json.*;
import javax.ws.rs.FormParam; import javax.ws.rs.*;
import javax.ws.rs.NotFoundException;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.io.StringReader; import java.io.StringReader;
import java.util.List;
/** /**
* Route REST resources. * Route REST resources.
@ -178,4 +179,81 @@ public class RouteResource extends BaseResource {
.add("status", "ok"); .add("status", "ok");
return Response.ok().entity(response.build()).build(); return Response.ok().entity(response.build()).build();
} }
/**
* Returns the routes on a document.
*
* @api {get} /route Get the routes on a document
* @apiName GetRoutes
* @apiGroup Route
* @apiParam {String} id Document ID
* @apiSuccess {Object[]} routes List of routes
* @apiSuccess {String} routes.name Name
* @apiSuccess {Number} routes.create_date Create date (timestamp)
* @apiSuccess {Object[]} routes.steps Route steps
* @apiSuccess {String} routes.steps.name Route step name
* @apiSuccess {String="APPROVE", "VALIDATE"} routes.steps.type Route step type
* @apiSuccess {String} routes.steps.comment Route step comment
* @apiSuccess {Number} routes.steps.end_date Route step end date (timestamp)
* @apiSuccess {String="APPROVED","REJECTED","VALIDATED"} routes.steps.transition Route step transition
* @apiSuccess {Object} routes.steps.validator_username Validator username
* @apiSuccess {Object} routes.steps.target Route step target
* @apiSuccess {String} routes.steps.target.id Route step target ID
* @apiSuccess {String} routes.steps.target.name Route step target name
* @apiSuccess {String="USER","GROUP"} routes.steps.target.type Route step target type
* @apiError (client) NotFound Document not found
* @apiPermission none
* @apiVersion 1.5.0
*
* @param documentId Document ID
* @return Response
*/
@GET
public Response get(@QueryParam("documentId") String documentId) {
if (!authenticate()) {
throw new ForbiddenClientException();
}
DocumentDao documentDao = new DocumentDao();
DocumentDto documentDto = documentDao.getDocument(documentId, PermType.READ, getTargetIdList(null));
if (documentDto == null) {
throw new NotFoundException();
}
JsonArrayBuilder routes = Json.createArrayBuilder();
RouteDao routeDao = new RouteDao();
RouteStepDao routeStepDao = new RouteStepDao();
List<RouteDto> routeDtoList = routeDao.findByCriteria(new RouteCriteria()
.setDocumentId(documentId), new SortCriteria(2, false));
for (RouteDto routeDto : routeDtoList) {
List<RouteStepDto> routeStepDtoList = routeStepDao.findByCriteria(new RouteStepCriteria()
.setRouteId(routeDto.getId()), new SortCriteria(6, true));
JsonArrayBuilder steps = Json.createArrayBuilder();
for (RouteStepDto routeStepDto : routeStepDtoList) {
steps.add(Json.createObjectBuilder()
.add("name", routeStepDto.getName())
.add("type", routeStepDto.getType().name())
.add("comment", JsonUtil.nullable(routeStepDto.getComment()))
.add("end_date", JsonUtil.nullable(routeStepDto.getEndDateTimestamp()))
.add("validator_username", JsonUtil.nullable(routeStepDto.getValidatorUserName()))
.add("target", Json.createObjectBuilder()
.add("id", routeStepDto.getTargetId())
.add("name", JsonUtil.nullable(routeStepDto.getTargetName()))
.add("type", routeStepDto.getTargetType()))
.add("transition", JsonUtil.nullable(routeStepDto.getTransition())));
}
routes.add(Json.createObjectBuilder()
.add("name", routeDto.getName())
.add("create_date", routeDto.getCreateTimestamp())
.add("steps", steps));
}
JsonObjectBuilder json = Json.createObjectBuilder()
.add("routes", routes);
return Response.ok().entity(json.build()).build();
}
} }

View File

@ -58,6 +58,31 @@ public class TestRouteResource extends BaseJerseyTest {
.param("documentId", document1Id) .param("documentId", document1Id)
.param("routeModelId", routeModels.getJsonObject(0).getString("id"))), JsonObject.class); .param("routeModelId", routeModels.getJsonObject(0).getString("id"))), JsonObject.class);
// Get the route on document 1
json = target().path("/route")
.queryParam("documentId", document1Id)
.request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, route1Token)
.get(JsonObject.class);
JsonArray routes = json.getJsonArray("routes");
Assert.assertEquals(1, routes.size());
JsonObject route = routes.getJsonObject(0);
Assert.assertEquals("Document review", route.getString("name"));
Assert.assertNotNull(route.getJsonNumber("create_date"));
JsonArray steps = route.getJsonArray("steps");
Assert.assertEquals(3, steps.size());
JsonObject step = steps.getJsonObject(0);
Assert.assertEquals("Check the document's metadata", step.getString("name"));
Assert.assertEquals("VALIDATE", step.getString("type"));
Assert.assertTrue(step.isNull("comment"));
Assert.assertTrue(step.isNull("end_date"));
Assert.assertTrue(step.isNull("validator_username"));
Assert.assertTrue(step.isNull("transition"));
JsonObject target = step.getJsonObject("target");
Assert.assertEquals("administrators", target.getString("id"));
Assert.assertEquals("administrators", target.getString("name"));
Assert.assertEquals("GROUP", target.getString("type"));
// Get document 1 as route1 // Get document 1 as route1
json = target().path("/document/" + document1Id).request() json = target().path("/document/" + document1Id).request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, route1Token) .cookie(TokenBasedSecurityFilter.COOKIE_NAME, route1Token)
@ -83,6 +108,25 @@ public class TestRouteResource extends BaseJerseyTest {
.param("documentId", document1Id) .param("documentId", document1Id)
.param("transition", "VALIDATED")), JsonObject.class); .param("transition", "VALIDATED")), JsonObject.class);
// Get the route on document 1
json = target().path("/route")
.queryParam("documentId", document1Id)
.request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, route1Token)
.get(JsonObject.class);
routes = json.getJsonArray("routes");
Assert.assertEquals(1, routes.size());
route = routes.getJsonObject(0);
Assert.assertNotNull(route.getJsonNumber("create_date"));
steps = route.getJsonArray("steps");
Assert.assertEquals(3, steps.size());
step = steps.getJsonObject(0);
Assert.assertEquals("VALIDATE", step.getString("type"));
Assert.assertTrue(step.isNull("comment"));
Assert.assertFalse(step.isNull("end_date"));
Assert.assertEquals("admin", step.getString("validator_username"));
Assert.assertEquals("VALIDATED", step.getString("transition"));
// Get document 1 as admin // Get document 1 as admin
json = target().path("/document/" + document1Id).request() json = target().path("/document/" + document1Id).request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken) .cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
@ -99,6 +143,25 @@ public class TestRouteResource extends BaseJerseyTest {
.param("transition", "VALIDATED") .param("transition", "VALIDATED")
.param("comment", "OK")), JsonObject.class); .param("comment", "OK")), JsonObject.class);
// Get the route on document 1
json = target().path("/route")
.queryParam("documentId", document1Id)
.request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, route1Token)
.get(JsonObject.class);
routes = json.getJsonArray("routes");
Assert.assertEquals(1, routes.size());
route = routes.getJsonObject(0);
Assert.assertNotNull(route.getJsonNumber("create_date"));
steps = route.getJsonArray("steps");
Assert.assertEquals(3, steps.size());
step = steps.getJsonObject(1);
Assert.assertEquals("VALIDATE", step.getString("type"));
Assert.assertEquals("OK", step.getString("comment"));
Assert.assertFalse(step.isNull("end_date"));
Assert.assertEquals("admin", step.getString("validator_username"));
Assert.assertEquals("VALIDATED", step.getString("transition"));
// Get document 1 as admin // Get document 1 as admin
json = target().path("/document/" + document1Id).request() json = target().path("/document/" + document1Id).request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken) .cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
@ -114,13 +177,32 @@ public class TestRouteResource extends BaseJerseyTest {
.param("documentId", document1Id) .param("documentId", document1Id)
.param("transition", "APPROVED")), JsonObject.class); .param("transition", "APPROVED")), JsonObject.class);
// Get the route on document 1
json = target().path("/route")
.queryParam("documentId", document1Id)
.request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, route1Token)
.get(JsonObject.class);
routes = json.getJsonArray("routes");
Assert.assertEquals(1, routes.size());
route = routes.getJsonObject(0);
Assert.assertNotNull(route.getJsonNumber("create_date"));
steps = route.getJsonArray("steps");
Assert.assertEquals(3, steps.size());
step = steps.getJsonObject(2);
Assert.assertEquals("APPROVE", step.getString("type"));
Assert.assertTrue(step.isNull("comment"));
Assert.assertFalse(step.isNull("end_date"));
Assert.assertEquals("admin", step.getString("validator_username"));
Assert.assertEquals("APPROVED", step.getString("transition"));
// Get document 1 as admin // Get document 1 as admin
Response response = target().path("/document/" + document1Id).request() Response response = target().path("/document/" + document1Id).request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken) .cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
.get(); .get();
Assert.assertEquals(Response.Status.NOT_FOUND, Response.Status.fromStatusCode(response.getStatus())); Assert.assertEquals(Response.Status.NOT_FOUND, Response.Status.fromStatusCode(response.getStatus()));
// Get document 1 as admin // Get document 1 as route1
json = target().path("/document/" + document1Id).request() json = target().path("/document/" + document1Id).request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, route1Token) .cookie(TokenBasedSecurityFilter.COOKIE_NAME, route1Token)
.get(JsonObject.class); .get(JsonObject.class);