mirror of
https://github.com/sismics/docs.git
synced 2025-12-14 18:26:17 +00:00
#202 Actions on route transition
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
package com.sismics.docs.core.constant;
|
||||
|
||||
/**
|
||||
* Action types.
|
||||
*
|
||||
* @author bgamard
|
||||
*/
|
||||
public enum ActionType {
|
||||
/**
|
||||
* Add a tag.
|
||||
*/
|
||||
ADD_TAG
|
||||
}
|
||||
@@ -68,7 +68,7 @@ public class RouteStepDao {
|
||||
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_IDROUTE_C, rs.RTP_ORDER_N c6")
|
||||
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_IDROUTE_C, rs.RTP_TRANSITIONS_C, 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 ")
|
||||
@@ -124,7 +124,8 @@ public class RouteStepDao {
|
||||
Timestamp endDateTimestamp = (Timestamp) o[i++];
|
||||
dto.setEndDateTimestamp(endDateTimestamp == null ? null : endDateTimestamp.getTime());
|
||||
dto.setValidatorUserName((String) o[i++]);
|
||||
dto.setRouteId((String) o[i]);
|
||||
dto.setRouteId((String) o[i++]);
|
||||
dto.setTransitions((String) o[i]);
|
||||
dtoList.add(dto);
|
||||
}
|
||||
return dtoList;
|
||||
|
||||
@@ -195,10 +195,6 @@ public class TagDao {
|
||||
criteriaList.add("dt.DOT_IDDOCUMENT_C = :documentId");
|
||||
parameterMap.put("documentId", criteria.getDocumentId());
|
||||
}
|
||||
if (criteria.getName() != null) {
|
||||
criteriaList.add("t.TAG_NAME_C = :name");
|
||||
parameterMap.put("name", criteria.getName());
|
||||
}
|
||||
|
||||
criteriaList.add("t.TAG_DELETEDATE_D is null");
|
||||
|
||||
|
||||
@@ -54,13 +54,4 @@ public class TagCriteria {
|
||||
this.documentId = documentId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public TagCriteria setName(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,6 +62,11 @@ public class RouteStepDto {
|
||||
*/
|
||||
private String validatorUserName;
|
||||
|
||||
/**
|
||||
* Transitions data.
|
||||
*/
|
||||
private String transitions;
|
||||
|
||||
/**
|
||||
* Route ID.
|
||||
*/
|
||||
@@ -166,6 +171,15 @@ public class RouteStepDto {
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getTransitions() {
|
||||
return transitions;
|
||||
}
|
||||
|
||||
public RouteStepDto setTransitions(String transitions) {
|
||||
this.transitions = transitions;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform in JSON.
|
||||
*
|
||||
|
||||
@@ -54,6 +54,12 @@ public class RouteStep {
|
||||
@Column(name = "RTP_COMMENT_C", length = 500)
|
||||
private String comment;
|
||||
|
||||
/**
|
||||
* Transitions JSON data.
|
||||
*/
|
||||
@Column(name = "RTP_TRANSITIONS_C", length = 2000)
|
||||
private String transitions;
|
||||
|
||||
/**
|
||||
* Target ID (user or group).
|
||||
*/
|
||||
@@ -198,6 +204,15 @@ public class RouteStep {
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getTransitions() {
|
||||
return transitions;
|
||||
}
|
||||
|
||||
public RouteStep setTransitions(String transitions) {
|
||||
this.transitions = transitions;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return MoreObjects.toStringHelper(this)
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.sismics.docs.core.util;
|
||||
|
||||
import com.sismics.docs.core.constant.ActionType;
|
||||
import com.sismics.docs.core.dao.jpa.dto.DocumentDto;
|
||||
import com.sismics.docs.core.util.action.Action;
|
||||
import com.sismics.docs.core.util.action.AddTagAction;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.json.JsonObject;
|
||||
|
||||
/**
|
||||
* Action utilities.
|
||||
*
|
||||
* @author bgamard
|
||||
*/
|
||||
public class ActionUtil {
|
||||
/**
|
||||
* Logger.
|
||||
*/
|
||||
private static final org.slf4j.Logger log = LoggerFactory.getLogger(LuceneUtil.class);
|
||||
|
||||
/**
|
||||
* Execute an action.
|
||||
*
|
||||
* @param actionType Action type
|
||||
* @param actionData Action data
|
||||
* @param documentDto Document DTO
|
||||
*/
|
||||
public static void executeAction(ActionType actionType, JsonObject actionData, DocumentDto documentDto) {
|
||||
Action action;
|
||||
switch (actionType) {
|
||||
case ADD_TAG:
|
||||
action = new AddTagAction();
|
||||
break;
|
||||
default:
|
||||
log.error("Action type not handled: " + actionType);
|
||||
return;
|
||||
}
|
||||
|
||||
action.execute(documentDto, actionData);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.sismics.docs.core.util.action;
|
||||
|
||||
import com.sismics.docs.core.dao.jpa.dto.DocumentDto;
|
||||
|
||||
import javax.json.JsonObject;
|
||||
|
||||
/**
|
||||
* Base action interface.
|
||||
*
|
||||
* @author bgamard
|
||||
*/
|
||||
public interface Action {
|
||||
/**
|
||||
* Execute the action.
|
||||
*
|
||||
* @param documentDto Document DTO
|
||||
* @param action Action data
|
||||
*/
|
||||
void execute(DocumentDto documentDto, JsonObject action);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.sismics.docs.core.util.action;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.sismics.docs.core.dao.jpa.TagDao;
|
||||
import com.sismics.docs.core.dao.jpa.criteria.TagCriteria;
|
||||
import com.sismics.docs.core.dao.jpa.dto.DocumentDto;
|
||||
import com.sismics.docs.core.dao.jpa.dto.TagDto;
|
||||
|
||||
import javax.json.JsonObject;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Action to add a tag.
|
||||
*
|
||||
* @author bgamard
|
||||
*/
|
||||
public class AddTagAction implements Action {
|
||||
@Override
|
||||
public void execute(DocumentDto documentDto, JsonObject action) {
|
||||
if (action.getString("tag") == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
TagDao tagDao = new TagDao();
|
||||
List<TagDto> tagAddDtoList = tagDao.findByCriteria(new TagCriteria().setId(action.getString("tag")), null);
|
||||
if (tagAddDtoList.isEmpty()) {
|
||||
// The tag has been deleted since the route model creation
|
||||
return;
|
||||
}
|
||||
|
||||
List<TagDto> tagDtoList = tagDao.findByCriteria(new TagCriteria().setDocumentId(documentDto.getId()), null);
|
||||
Set<String> tagIdSet = Sets.newHashSet(tagAddDtoList.get(0).getId());
|
||||
for (TagDto tagDto : tagDtoList) {
|
||||
tagIdSet.add(tagDto.getId());
|
||||
}
|
||||
|
||||
tagDao.updateTagList(documentDto.getId(), tagIdSet);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
alter table T_DOCUMENT add column DOC_UPDATEDATE_D datetime;
|
||||
update T_DOCUMENT set DOC_UPDATEDATE_D = DOC_CREATEDATE_D;
|
||||
alter table T_DOCUMENT alter column DOC_UPDATEDATE_D datetime not null;
|
||||
alter table T_ROUTE_STEP add column RTP_TRANSITIONS_C varchar(2000);
|
||||
update T_CONFIG set CFG_VALUE_C = '18' where CFG_ID_C = 'DB_VERSION';
|
||||
|
||||
Reference in New Issue
Block a user