mirror of
https://github.com/sismics/docs.git
synced 2025-12-14 02:06:25 +00:00
#159: get routes on a document
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user