mirror of
https://github.com/sismics/docs.git
synced 2024-11-21 21:47:57 +01:00
#159: get routes on a document
This commit is contained in:
parent
6e6f892cb0
commit
8a854bb37d
@ -67,13 +67,13 @@ public class AclDao {
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<AclDto> getBySourceId(String sourceId, AclType type) {
|
||||
EntityManager em = ThreadLocalContext.get().getEntityManager();
|
||||
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 ");
|
||||
sb.append(" from T_ACL a ");
|
||||
sb.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 ");
|
||||
sb.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 ");
|
||||
StringBuilder sb = new StringBuilder("select a.ACL_ID_C, a.ACL_PERM_C, a.ACL_TARGETID_C, ")
|
||||
.append(" u.USE_USERNAME_C, s.SHA_ID_C, s.SHA_NAME_C, g.GRP_NAME_C ")
|
||||
.append(" from T_ACL a ")
|
||||
.append(" left join T_USER u on u.USE_ID_C = a.ACL_TARGETID_C ")
|
||||
.append(" left join T_SHARE s on s.SHA_ID_C = a.ACL_TARGETID_C ")
|
||||
.append(" left join T_GROUP g on g.GRP_ID_C = a.ACL_TARGETID_C ")
|
||||
.append(" where a.ACL_DELETEDATE_D is null and a.ACL_SOURCEID_C = :sourceId and a.ACL_TYPE_C = :type ");
|
||||
|
||||
// Perform the query
|
||||
Query q = em.createNativeQuery(sb.toString());
|
||||
|
@ -1,13 +1,19 @@
|
||||
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.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.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 javax.persistence.EntityManager;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Route DAO.
|
||||
@ -36,4 +42,48 @@ public class RouteDao {
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,21 @@
|
||||
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.RouteStepType;
|
||||
import com.sismics.docs.core.dao.jpa.criteria.RouteStepCriteria;
|
||||
import com.sismics.docs.core.dao.jpa.dto.RouteStepDto;
|
||||
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 javax.persistence.EntityManager;
|
||||
import javax.persistence.Query;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Route step DAO.
|
||||
@ -43,35 +47,86 @@ public class RouteStepDao {
|
||||
* @param documentId Document ID
|
||||
* @return Current route step
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public RouteStepDto getCurrentStep(String documentId) {
|
||||
EntityManager em = ThreadLocalContext.get().getEntityManager();
|
||||
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");
|
||||
sb.append(" from T_ROUTE_STEP rs ");
|
||||
sb.append(" join T_ROUTE r on r.RTE_ID_C = rs.RTP_IDROUTE_C ");
|
||||
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()) {
|
||||
List<RouteStepDto> routeStepDtoList = findByCriteria(new RouteStepCriteria()
|
||||
.setDocumentId(documentId)
|
||||
.setEndDateIsNull(true), new SortCriteria(6, true));
|
||||
if (routeStepDtoList.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
Object[] o = l.get(0);
|
||||
int i = 0;
|
||||
RouteStepDto routeStepDto = new RouteStepDto();
|
||||
routeStepDto.setId((String) o[i++]);
|
||||
routeStepDto.setName((String) o[i++]);
|
||||
routeStepDto.setType(RouteStepType.valueOf((String) o[i++]));
|
||||
String transition = (String) o[i++];
|
||||
routeStepDto.setTransition(transition == null ? null : RouteStepTransition.valueOf(transition));
|
||||
routeStepDto.setComment((String) o[i++]);
|
||||
routeStepDto.setTargetId((String) o[i++]);
|
||||
Timestamp endDateTimestamp = (Timestamp) o[i];
|
||||
routeStepDto.setEndDateTimestamp(endDateTimestamp == null ? null : endDateTimestamp.getTime());
|
||||
return routeStepDto;
|
||||
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;
|
||||
RouteStepDto dto = new RouteStepDto();
|
||||
dto.setId((String) o[i++]);
|
||||
dto.setName((String) o[i++]);
|
||||
dto.setType(RouteStepType.valueOf((String) o[i++]));
|
||||
dto.setTransition((String) o[i++]);
|
||||
dto.setComment((String) o[i++]);
|
||||
dto.setTargetId((String) o[i++]);
|
||||
String userName = (String) o[i++];
|
||||
String groupName = (String) o[i++];
|
||||
if (userName != null) {
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
package com.sismics.docs.core.dao.jpa.dto;
|
||||
|
||||
import com.sismics.docs.core.constant.RouteStepTransition;
|
||||
import com.sismics.docs.core.constant.RouteStepType;
|
||||
|
||||
/**
|
||||
@ -27,7 +26,7 @@ public class RouteStepDto {
|
||||
/**
|
||||
* Transition.
|
||||
*/
|
||||
private RouteStepTransition transition;
|
||||
private String transition;
|
||||
|
||||
/**
|
||||
* Comment.
|
||||
@ -39,11 +38,26 @@ public class RouteStepDto {
|
||||
*/
|
||||
private String targetId;
|
||||
|
||||
/**
|
||||
* Target name.
|
||||
*/
|
||||
private String targetName;
|
||||
|
||||
/**
|
||||
* Target type.
|
||||
*/
|
||||
private String targetType;
|
||||
|
||||
/**
|
||||
* End date.
|
||||
*/
|
||||
private Long endDateTimestamp;
|
||||
|
||||
/**
|
||||
* Validator's username.
|
||||
*/
|
||||
private String validatorUserName;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
@ -71,11 +85,11 @@ public class RouteStepDto {
|
||||
return this;
|
||||
}
|
||||
|
||||
public RouteStepTransition getTransition() {
|
||||
public String getTransition() {
|
||||
return transition;
|
||||
}
|
||||
|
||||
public RouteStepDto setTransition(RouteStepTransition transition) {
|
||||
public RouteStepDto setTransition(String transition) {
|
||||
this.transition = transition;
|
||||
return this;
|
||||
}
|
||||
@ -98,6 +112,24 @@ public class RouteStepDto {
|
||||
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() {
|
||||
return endDateTimestamp;
|
||||
}
|
||||
@ -106,4 +138,13 @@ public class RouteStepDto {
|
||||
this.endDateTimestamp = endDateTimestamp;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getValidatorUserName() {
|
||||
return validatorUserName;
|
||||
}
|
||||
|
||||
public RouteStepDto setValidatorUserName(String validatorUserName) {
|
||||
this.validatorUserName = validatorUserName;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ import com.sismics.docs.core.model.jpa.Acl;
|
||||
* @author bgamard
|
||||
*/
|
||||
public class RoutingUtil {
|
||||
|
||||
/**
|
||||
* Update routing ACLs according to the current route step.
|
||||
*
|
||||
|
@ -34,4 +34,17 @@ public class JsonUtil {
|
||||
}
|
||||
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("_");
|
||||
}
|
||||
}
|
||||
|
@ -4,27 +4,28 @@ import com.sismics.docs.core.constant.AclTargetType;
|
||||
import com.sismics.docs.core.constant.PermType;
|
||||
import com.sismics.docs.core.constant.RouteStepTransition;
|
||||
import com.sismics.docs.core.constant.RouteStepType;
|
||||
import com.sismics.docs.core.dao.jpa.AclDao;
|
||||
import com.sismics.docs.core.dao.jpa.RouteDao;
|
||||
import com.sismics.docs.core.dao.jpa.RouteModelDao;
|
||||
import com.sismics.docs.core.dao.jpa.RouteStepDao;
|
||||
import com.sismics.docs.core.dao.jpa.*;
|
||||
import com.sismics.docs.core.dao.jpa.criteria.RouteCriteria;
|
||||
import com.sismics.docs.core.dao.jpa.criteria.RouteStepCriteria;
|
||||
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.model.jpa.Route;
|
||||
import com.sismics.docs.core.model.jpa.RouteModel;
|
||||
import com.sismics.docs.core.model.jpa.RouteStep;
|
||||
import com.sismics.docs.core.util.RoutingUtil;
|
||||
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.ForbiddenClientException;
|
||||
import com.sismics.rest.util.JsonUtil;
|
||||
import com.sismics.rest.util.ValidationUtil;
|
||||
|
||||
import javax.json.*;
|
||||
import javax.ws.rs.FormParam;
|
||||
import javax.ws.rs.NotFoundException;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.io.StringReader;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Route REST resources.
|
||||
@ -178,4 +179,81 @@ public class RouteResource extends BaseResource {
|
||||
.add("status", "ok");
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -58,6 +58,31 @@ public class TestRouteResource extends BaseJerseyTest {
|
||||
.param("documentId", document1Id)
|
||||
.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
|
||||
json = target().path("/document/" + document1Id).request()
|
||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, route1Token)
|
||||
@ -83,6 +108,25 @@ public class TestRouteResource extends BaseJerseyTest {
|
||||
.param("documentId", document1Id)
|
||||
.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
|
||||
json = target().path("/document/" + document1Id).request()
|
||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||
@ -99,6 +143,25 @@ public class TestRouteResource extends BaseJerseyTest {
|
||||
.param("transition", "VALIDATED")
|
||||
.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
|
||||
json = target().path("/document/" + document1Id).request()
|
||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||
@ -114,13 +177,32 @@ public class TestRouteResource extends BaseJerseyTest {
|
||||
.param("documentId", document1Id)
|
||||
.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
|
||||
Response response = target().path("/document/" + document1Id).request()
|
||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||
.get();
|
||||
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()
|
||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, route1Token)
|
||||
.get(JsonObject.class);
|
||||
|
Loading…
Reference in New Issue
Block a user