mirror of
https://github.com/sismics/docs.git
synced 2024-11-21 21:47:57 +01:00
#159: route model api
This commit is contained in:
parent
0ab6c8e4b0
commit
17a94395f3
@ -294,26 +294,26 @@ public class DocumentDao {
|
||||
// Get the document
|
||||
Query q = em.createQuery("select d from Document d where d.id = :id and d.deleteDate is null");
|
||||
q.setParameter("id", document.getId());
|
||||
Document documentFromDb = (Document) q.getSingleResult();
|
||||
Document documentDb = (Document) q.getSingleResult();
|
||||
|
||||
// Update the document
|
||||
documentFromDb.setTitle(document.getTitle());
|
||||
documentFromDb.setDescription(document.getDescription());
|
||||
documentFromDb.setSubject(document.getSubject());
|
||||
documentFromDb.setIdentifier(document.getIdentifier());
|
||||
documentFromDb.setPublisher(document.getPublisher());
|
||||
documentFromDb.setFormat(document.getFormat());
|
||||
documentFromDb.setSource(document.getSource());
|
||||
documentFromDb.setType(document.getType());
|
||||
documentFromDb.setCoverage(document.getCoverage());
|
||||
documentFromDb.setRights(document.getRights());
|
||||
documentFromDb.setCreateDate(document.getCreateDate());
|
||||
documentFromDb.setLanguage(document.getLanguage());
|
||||
documentDb.setTitle(document.getTitle());
|
||||
documentDb.setDescription(document.getDescription());
|
||||
documentDb.setSubject(document.getSubject());
|
||||
documentDb.setIdentifier(document.getIdentifier());
|
||||
documentDb.setPublisher(document.getPublisher());
|
||||
documentDb.setFormat(document.getFormat());
|
||||
documentDb.setSource(document.getSource());
|
||||
documentDb.setType(document.getType());
|
||||
documentDb.setCoverage(document.getCoverage());
|
||||
documentDb.setRights(document.getRights());
|
||||
documentDb.setCreateDate(document.getCreateDate());
|
||||
documentDb.setLanguage(document.getLanguage());
|
||||
|
||||
// Create audit log
|
||||
AuditLogUtil.create(documentFromDb, AuditLogType.UPDATE, userId);
|
||||
AuditLogUtil.create(documentDb, AuditLogType.UPDATE, userId);
|
||||
|
||||
return documentFromDb;
|
||||
return documentDb;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,18 +1,17 @@
|
||||
package com.sismics.docs.core.dao.jpa;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.NoResultException;
|
||||
import javax.persistence.Query;
|
||||
|
||||
import com.sismics.docs.core.constant.AuditLogType;
|
||||
import com.sismics.docs.core.model.jpa.File;
|
||||
import com.sismics.docs.core.util.AuditLogUtil;
|
||||
import com.sismics.util.context.ThreadLocalContext;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.NoResultException;
|
||||
import javax.persistence.Query;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* File DAO.
|
||||
*
|
||||
@ -137,13 +136,13 @@ public class FileDao {
|
||||
// Get the file
|
||||
Query q = em.createQuery("select f from File f where f.id = :id and f.deleteDate is null");
|
||||
q.setParameter("id", file.getId());
|
||||
File fileFromDb = (File) q.getSingleResult();
|
||||
File fileDb = (File) q.getSingleResult();
|
||||
|
||||
// Update the file
|
||||
fileFromDb.setDocumentId(file.getDocumentId());
|
||||
fileFromDb.setContent(file.getContent());
|
||||
fileFromDb.setOrder(file.getOrder());
|
||||
fileFromDb.setMimeType(file.getMimeType());
|
||||
fileDb.setDocumentId(file.getDocumentId());
|
||||
fileDb.setContent(file.getContent());
|
||||
fileDb.setOrder(file.getOrder());
|
||||
fileDb.setMimeType(file.getMimeType());
|
||||
|
||||
return file;
|
||||
}
|
||||
|
@ -1,18 +1,5 @@
|
||||
package com.sismics.docs.core.dao.jpa;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.NoResultException;
|
||||
import javax.persistence.Query;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.sismics.docs.core.constant.AuditLogType;
|
||||
import com.sismics.docs.core.dao.jpa.criteria.GroupCriteria;
|
||||
@ -25,6 +12,11 @@ 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.NoResultException;
|
||||
import javax.persistence.Query;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Group DAO.
|
||||
*
|
||||
@ -266,16 +258,16 @@ public class GroupDao {
|
||||
// Get the group
|
||||
Query q = em.createQuery("select g from Group g where g.id = :id and g.deleteDate is null");
|
||||
q.setParameter("id", group.getId());
|
||||
Group groupFromDb = (Group) q.getSingleResult();
|
||||
Group groupDb = (Group) q.getSingleResult();
|
||||
|
||||
// Update the group
|
||||
groupFromDb.setName(group.getName());
|
||||
groupFromDb.setParentId(group.getParentId());
|
||||
groupDb.setName(group.getName());
|
||||
groupDb.setParentId(group.getParentId());
|
||||
|
||||
// Create audit log
|
||||
AuditLogUtil.create(groupFromDb, AuditLogType.UPDATE, userId);
|
||||
AuditLogUtil.create(groupDb, AuditLogType.UPDATE, userId);
|
||||
|
||||
return groupFromDb;
|
||||
return groupDb;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,17 +1,21 @@
|
||||
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.RouteModelCriteria;
|
||||
import com.sismics.docs.core.dao.jpa.dto.RouteModelDto;
|
||||
import com.sismics.docs.core.model.jpa.RouteModel;
|
||||
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 javax.persistence.NoResultException;
|
||||
import javax.persistence.Query;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Route model DAO.
|
||||
@ -19,6 +23,92 @@ import java.util.Map;
|
||||
* @author bgamard
|
||||
*/
|
||||
public class RouteModelDao {
|
||||
/**
|
||||
* Creates a new route model.
|
||||
*
|
||||
* @param routeModel Route model
|
||||
* @param userId User ID
|
||||
* @return New ID
|
||||
*/
|
||||
public String create(RouteModel routeModel, String userId) {
|
||||
// Create the UUID
|
||||
routeModel.setId(UUID.randomUUID().toString());
|
||||
|
||||
// Create the route model
|
||||
EntityManager em = ThreadLocalContext.get().getEntityManager();
|
||||
routeModel.setCreateDate(new Date());
|
||||
em.persist(routeModel);
|
||||
|
||||
// Create audit log
|
||||
AuditLogUtil.create(routeModel, AuditLogType.CREATE, userId);
|
||||
|
||||
return routeModel.getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a route model.
|
||||
*
|
||||
* @param routeModel Route model to update
|
||||
* @param userId User ID
|
||||
* @return Updated route model
|
||||
*/
|
||||
public RouteModel update(RouteModel routeModel, String userId) {
|
||||
EntityManager em = ThreadLocalContext.get().getEntityManager();
|
||||
|
||||
// Get the route model
|
||||
Query q = em.createQuery("select r from RouteModel r where r.id = :id and r.deleteDate is null");
|
||||
q.setParameter("id", routeModel.getId());
|
||||
RouteModel routeModelDb = (RouteModel) q.getSingleResult();
|
||||
|
||||
// Update the group
|
||||
routeModelDb.setName(routeModel.getName());
|
||||
routeModelDb.setSteps(routeModel.getSteps());
|
||||
|
||||
// Create audit log
|
||||
AuditLogUtil.create(routeModelDb, AuditLogType.UPDATE, userId);
|
||||
|
||||
return routeModelDb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an active route model by its ID.
|
||||
*
|
||||
* @param id Route model ID
|
||||
* @return Route model
|
||||
*/
|
||||
public RouteModel getActiveById(String id) {
|
||||
EntityManager em = ThreadLocalContext.get().getEntityManager();
|
||||
try {
|
||||
Query q = em.createQuery("select r from RouteModel r where r.id = :id and r.deleteDate is null");
|
||||
q.setParameter("id", id);
|
||||
return (RouteModel) q.getSingleResult();
|
||||
} catch (NoResultException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a route model.
|
||||
*
|
||||
* @param id Route model ID
|
||||
* @param userId User ID
|
||||
*/
|
||||
public void delete(String id, String userId) {
|
||||
EntityManager em = ThreadLocalContext.get().getEntityManager();
|
||||
|
||||
// Get the route model
|
||||
Query q = em.createQuery("select r from RouteModel r where r.id = :id and r.deleteDate is null");
|
||||
q.setParameter("id", id);
|
||||
RouteModel routeModelDb = (RouteModel) q.getSingleResult();
|
||||
|
||||
// Delete the route model
|
||||
Date dateNow = new Date();
|
||||
routeModelDb.setDeleteDate(dateNow);
|
||||
|
||||
// Create audit log
|
||||
AuditLogUtil.create(routeModelDb, AuditLogType.DELETE, userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of all route models.
|
||||
*
|
||||
|
@ -148,17 +148,17 @@ public class TagDao {
|
||||
// Get the tag
|
||||
Query q = em.createQuery("select t from Tag t where t.id = :id and t.deleteDate is null");
|
||||
q.setParameter("id", tag.getId());
|
||||
Tag tagFromDb = (Tag) q.getSingleResult();
|
||||
Tag tagDb = (Tag) q.getSingleResult();
|
||||
|
||||
// Update the tag
|
||||
tagFromDb.setName(tag.getName());
|
||||
tagFromDb.setColor(tag.getColor());
|
||||
tagFromDb.setParentId(tag.getParentId());
|
||||
tagDb.setName(tag.getName());
|
||||
tagDb.setColor(tag.getColor());
|
||||
tagDb.setParentId(tag.getParentId());
|
||||
|
||||
// Create audit log
|
||||
AuditLogUtil.create(tagFromDb, AuditLogType.UPDATE, userId);
|
||||
AuditLogUtil.create(tagDb, AuditLogType.UPDATE, userId);
|
||||
|
||||
return tagFromDb;
|
||||
return tagDb;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -92,17 +92,17 @@ public class UserDao {
|
||||
// Get the user
|
||||
Query q = em.createQuery("select u from User u where u.id = :id and u.deleteDate is null");
|
||||
q.setParameter("id", user.getId());
|
||||
User userFromDb = (User) q.getSingleResult();
|
||||
User userDb = (User) q.getSingleResult();
|
||||
|
||||
// Update the user (except password)
|
||||
userFromDb.setEmail(user.getEmail());
|
||||
userFromDb.setStorageQuota(user.getStorageQuota());
|
||||
userFromDb.setStorageCurrent(user.getStorageCurrent());
|
||||
userFromDb.setTotpKey(user.getTotpKey());
|
||||
userFromDb.setDisableDate(user.getDisableDate());
|
||||
userDb.setEmail(user.getEmail());
|
||||
userDb.setStorageQuota(user.getStorageQuota());
|
||||
userDb.setStorageCurrent(user.getStorageCurrent());
|
||||
userDb.setTotpKey(user.getTotpKey());
|
||||
userDb.setDisableDate(user.getDisableDate());
|
||||
|
||||
// Create audit log
|
||||
AuditLogUtil.create(userFromDb, AuditLogType.UPDATE, userId);
|
||||
AuditLogUtil.create(userDb, AuditLogType.UPDATE, userId);
|
||||
|
||||
return user;
|
||||
}
|
||||
@ -118,10 +118,10 @@ public class UserDao {
|
||||
// Get the user
|
||||
Query q = em.createQuery("select u from User u where u.id = :id and u.deleteDate is null");
|
||||
q.setParameter("id", user.getId());
|
||||
User userFromDb = (User) q.getSingleResult();
|
||||
User userDb = (User) q.getSingleResult();
|
||||
|
||||
// Update the user
|
||||
userFromDb.setStorageQuota(user.getStorageQuota());
|
||||
userDb.setStorageQuota(user.getStorageQuota());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -137,13 +137,13 @@ public class UserDao {
|
||||
// Get the user
|
||||
Query q = em.createQuery("select u from User u where u.id = :id and u.deleteDate is null");
|
||||
q.setParameter("id", user.getId());
|
||||
User userFromDb = (User) q.getSingleResult();
|
||||
User userDb = (User) q.getSingleResult();
|
||||
|
||||
// Update the user
|
||||
userFromDb.setPassword(hashPassword(user.getPassword()));
|
||||
userDb.setPassword(hashPassword(user.getPassword()));
|
||||
|
||||
// Create audit log
|
||||
AuditLogUtil.create(userFromDb, AuditLogType.UPDATE, userId);
|
||||
AuditLogUtil.create(userDb, AuditLogType.UPDATE, userId);
|
||||
|
||||
return user;
|
||||
}
|
||||
@ -160,10 +160,10 @@ public class UserDao {
|
||||
// Get the user
|
||||
Query q = em.createQuery("select u from User u where u.id = :id and u.deleteDate is null");
|
||||
q.setParameter("id", user.getId());
|
||||
User userFromDb = (User) q.getSingleResult();
|
||||
User userDb = (User) q.getSingleResult();
|
||||
|
||||
// Update the user
|
||||
userFromDb.setPassword(user.getPassword());
|
||||
userDb.setPassword(user.getPassword());
|
||||
|
||||
return user;
|
||||
}
|
||||
@ -212,39 +212,39 @@ public class UserDao {
|
||||
// Get the user
|
||||
Query q = em.createQuery("select u from User u where u.username = :username and u.deleteDate is null");
|
||||
q.setParameter("username", username);
|
||||
User userFromDb = (User) q.getSingleResult();
|
||||
User userDb = (User) q.getSingleResult();
|
||||
|
||||
// Delete the user
|
||||
Date dateNow = new Date();
|
||||
userFromDb.setDeleteDate(dateNow);
|
||||
userDb.setDeleteDate(dateNow);
|
||||
|
||||
// Delete linked data
|
||||
q = em.createQuery("delete from AuthenticationToken at where at.userId = :userId");
|
||||
q.setParameter("userId", userFromDb.getId());
|
||||
q.setParameter("userId", userDb.getId());
|
||||
q.executeUpdate();
|
||||
|
||||
q = em.createQuery("update Document d set d.deleteDate = :dateNow where d.userId = :userId and d.deleteDate is null");
|
||||
q.setParameter("userId", userFromDb.getId());
|
||||
q.setParameter("userId", userDb.getId());
|
||||
q.setParameter("dateNow", dateNow);
|
||||
q.executeUpdate();
|
||||
|
||||
q = em.createQuery("update File f set f.deleteDate = :dateNow where f.userId = :userId and f.deleteDate is null");
|
||||
q.setParameter("userId", userFromDb.getId());
|
||||
q.setParameter("userId", userDb.getId());
|
||||
q.setParameter("dateNow", dateNow);
|
||||
q.executeUpdate();
|
||||
|
||||
q = em.createQuery("update Acl a set a.deleteDate = :dateNow where a.targetId = :userId and a.deleteDate is null");
|
||||
q.setParameter("userId", userFromDb.getId());
|
||||
q.setParameter("userId", userDb.getId());
|
||||
q.setParameter("dateNow", dateNow);
|
||||
q.executeUpdate();
|
||||
|
||||
q = em.createQuery("update Comment c set c.deleteDate = :dateNow where c.userId = :userId and c.deleteDate is null");
|
||||
q.setParameter("userId", userFromDb.getId());
|
||||
q.setParameter("userId", userDb.getId());
|
||||
q.setParameter("dateNow", dateNow);
|
||||
q.executeUpdate();
|
||||
|
||||
// Create audit log
|
||||
AuditLogUtil.create(userFromDb, AuditLogType.DELETE, userId);
|
||||
AuditLogUtil.create(userDb, AuditLogType.DELETE, userId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,14 +1,13 @@
|
||||
package com.sismics.docs.core.dao.jpa;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import com.sismics.docs.core.model.jpa.Vocabulary;
|
||||
import com.sismics.util.context.ThreadLocalContext;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.NoResultException;
|
||||
import javax.persistence.Query;
|
||||
|
||||
import com.sismics.docs.core.model.jpa.Vocabulary;
|
||||
import com.sismics.util.context.ThreadLocalContext;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Vocabulary DAO.
|
||||
@ -76,14 +75,14 @@ public class VocabularyDao {
|
||||
// Get the vocabulary entry
|
||||
Query q = em.createQuery("select v from Vocabulary v where v.id = :id");
|
||||
q.setParameter("id", vocabulary.getId());
|
||||
Vocabulary vocabularyFromDb = (Vocabulary) q.getSingleResult();
|
||||
Vocabulary vocabularyDb = (Vocabulary) q.getSingleResult();
|
||||
|
||||
// Update the vocabulary entry
|
||||
vocabularyFromDb.setName(vocabulary.getName());
|
||||
vocabularyFromDb.setValue(vocabulary.getValue());
|
||||
vocabularyFromDb.setOrder(vocabulary.getOrder());
|
||||
vocabularyDb.setName(vocabulary.getName());
|
||||
vocabularyDb.setValue(vocabulary.getValue());
|
||||
vocabularyDb.setOrder(vocabulary.getOrder());
|
||||
|
||||
return vocabularyFromDb;
|
||||
return vocabularyDb;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -15,7 +15,7 @@ import java.util.Date;
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "T_ROUTE_MODEL")
|
||||
public class RouteModel {
|
||||
public class RouteModel implements Loggable {
|
||||
/**
|
||||
* Route model ID.
|
||||
*/
|
||||
@ -32,8 +32,8 @@ public class RouteModel {
|
||||
/**
|
||||
* Data.
|
||||
*/
|
||||
@Column(name = "RTM_DATA_C", nullable = false, length = 5000)
|
||||
private String data;
|
||||
@Column(name = "RTM_STEPS_C", nullable = false, length = 5000)
|
||||
private String steps;
|
||||
|
||||
/**
|
||||
* Creation date.
|
||||
@ -65,12 +65,12 @@ public class RouteModel {
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getData() {
|
||||
return data;
|
||||
public String getSteps() {
|
||||
return steps;
|
||||
}
|
||||
|
||||
public RouteModel setData(String data) {
|
||||
this.data = data;
|
||||
public RouteModel setSteps(String steps) {
|
||||
this.steps = steps;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -99,4 +99,9 @@ public class RouteModel {
|
||||
.add("name", name)
|
||||
.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toMessage() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
create table T_ROUTE_MODEL ( RTM_ID_C varchar(36) not null, RTM_NAME_C varchar(50) not null, RTM_DATA_C varchar(5000) not null, RTM_CREATEDATE_D datetime not null, RTM_DELETEDATE_D datetime, primary key (RTM_ID_C) );
|
||||
create table T_ROUTE_MODEL ( RTM_ID_C varchar(36) not null, RTM_NAME_C varchar(50) not null, RTM_STEPS_C varchar(5000) not null, RTM_CREATEDATE_D datetime not null, RTM_DELETEDATE_D datetime, primary key (RTM_ID_C) );
|
||||
create cached table T_ROUTE ( RTE_ID_C varchar(36) not null, RTE_IDDOCUMENT_C varchar(36) not null, RTE_CREATEDATE_D datetime not null, RTE_DELETEDATE_D datetime, primary key (RTE_ID_C) );
|
||||
create cached table T_ROUTE_STEP ( RTP_ID_C varchar(36) not null, RTP_IDROUTE_C varchar(36) not null, RTP_NAME_C varchar(200) not null, RTP_TYPE_C varchar(50) not null, RTP_TRANSITION_C varchar(50), RTP_COMMENT_C varchar(500), RTP_IDTARGET_C varchar(36) not null, RTP_ORDER_N int not null, RTE_CREATEDATE_D datetime not null, RTP_ENDDATE_D datetime, RTP_DELETEDATE_D datetime, primary key (RTP_ID_C) );;
|
||||
alter table T_ROUTE add constraint FK_RTE_IDDOCUMENT_C foreign key (RTE_IDDOCUMENT_C) references T_DOCUMENT (DOC_ID_C) on delete restrict on update restrict;
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.sismics.docs.rest.util;
|
||||
|
||||
import com.sismics.util.filter.TokenBasedSecurityFilter;
|
||||
|
||||
import javax.json.JsonObject;
|
||||
import javax.ws.rs.client.Entity;
|
||||
import javax.ws.rs.client.WebTarget;
|
||||
@ -7,8 +9,6 @@ import javax.ws.rs.core.Form;
|
||||
import javax.ws.rs.core.NewCookie;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import com.sismics.util.filter.TokenBasedSecurityFilter;
|
||||
|
||||
/**
|
||||
* REST client utilities.
|
||||
*
|
||||
@ -75,7 +75,7 @@ public class ClientUtil {
|
||||
// Login admin to create the group
|
||||
String adminToken = login("admin", "admin", false);
|
||||
|
||||
// Create the gorup
|
||||
// Create the group
|
||||
resource.path("/group").request()
|
||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||
.put(Entity.form(new Form()
|
||||
|
@ -41,7 +41,7 @@ public class AuditLogResource extends BaseResource {
|
||||
* @apiSuccess {String} logs.id ID
|
||||
* @apiSuccess {String} logs.username Username
|
||||
* @apiSuccess {String} logs.target Entity ID
|
||||
* @apiSuccess {String="Acl","Comment","Document","File","Group","Tag","User"} logs.class Entity type
|
||||
* @apiSuccess {String="Acl","Comment","Document","File","Group","Tag","User","RouteModel"} logs.class Entity type
|
||||
* @apiSuccess {String="CREATE","UPDATE","DELETE"} logs.type Type
|
||||
* @apiSuccess {String} logs.message Message
|
||||
* @apiSuccess {Number} logs.create_date Create date (timestamp)
|
||||
|
@ -3,15 +3,16 @@ package com.sismics.docs.rest.resource;
|
||||
import com.sismics.docs.core.dao.jpa.RouteModelDao;
|
||||
import com.sismics.docs.core.dao.jpa.criteria.RouteModelCriteria;
|
||||
import com.sismics.docs.core.dao.jpa.dto.RouteModelDto;
|
||||
import com.sismics.docs.core.model.jpa.RouteModel;
|
||||
import com.sismics.docs.core.util.jpa.SortCriteria;
|
||||
import com.sismics.docs.rest.constant.BaseFunction;
|
||||
import com.sismics.rest.exception.ForbiddenClientException;
|
||||
import com.sismics.rest.util.ValidationUtil;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonArrayBuilder;
|
||||
import javax.json.JsonObjectBuilder;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.util.List;
|
||||
|
||||
@ -27,7 +28,7 @@ public class RouteModelResource extends BaseResource {
|
||||
*
|
||||
* @api {get} /routemodel Get route models
|
||||
* @apiName GetRouteModel
|
||||
* @apiGroup RouteModel
|
||||
* @apiRouteModel RouteModel
|
||||
* @apiParam {Number} sort_column Column index to sort on
|
||||
* @apiParam {Boolean} asc If true, sort in ascending order
|
||||
* @apiSuccess {Object[]} routemodels List of route models
|
||||
@ -48,20 +49,190 @@ public class RouteModelResource extends BaseResource {
|
||||
throw new ForbiddenClientException();
|
||||
}
|
||||
|
||||
JsonArrayBuilder groups = Json.createArrayBuilder();
|
||||
JsonArrayBuilder routeModels = Json.createArrayBuilder();
|
||||
SortCriteria sortCriteria = new SortCriteria(sortColumn, asc);
|
||||
|
||||
RouteModelDao routeModelDao = new RouteModelDao();
|
||||
List<RouteModelDto> routeModelDtoList = routeModelDao.findByCriteria(new RouteModelCriteria(), sortCriteria);
|
||||
for (RouteModelDto routeModelDto : routeModelDtoList) {
|
||||
groups.add(Json.createObjectBuilder()
|
||||
routeModels.add(Json.createObjectBuilder()
|
||||
.add("id", routeModelDto.getId())
|
||||
.add("name", routeModelDto.getName())
|
||||
.add("create_date", routeModelDto.getCreateTimestamp()));
|
||||
}
|
||||
|
||||
JsonObjectBuilder response = Json.createObjectBuilder()
|
||||
.add("routemodels", groups);
|
||||
.add("routemodels", routeModels);
|
||||
return Response.ok().entity(response.build()).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a route model.
|
||||
*
|
||||
* @api {put} /routemodel Add a route model
|
||||
* @apiName PutRouteModel
|
||||
* @apiRouteModel RouteModel
|
||||
* @apiParam {String} name Route model name
|
||||
* @apiParam {String} steps Steps data in JSON
|
||||
* @apiSuccess {String} id Route model ID
|
||||
* @apiError (client) ForbiddenError Access denied
|
||||
* @apiError (client) ValidationError Validation error
|
||||
* @apiPermission admin
|
||||
* @apiVersion 1.5.0
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
@PUT
|
||||
public Response add(@FormParam("name") String name, @FormParam("steps") String steps) {
|
||||
if (!authenticate()) {
|
||||
throw new ForbiddenClientException();
|
||||
}
|
||||
checkBaseFunction(BaseFunction.ADMIN);
|
||||
|
||||
// Validate input
|
||||
name = ValidationUtil.validateLength(name, "name", 1, 50, false);
|
||||
// TODO Validate steps data
|
||||
|
||||
// Create the route model
|
||||
RouteModelDao routeModelDao = new RouteModelDao();
|
||||
String id = routeModelDao.create(new RouteModel()
|
||||
.setName(name)
|
||||
.setSteps(steps), principal.getId());
|
||||
|
||||
// Always return OK
|
||||
JsonObjectBuilder response = Json.createObjectBuilder()
|
||||
.add("id", id);
|
||||
return Response.ok().entity(response.build()).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a route model.
|
||||
*
|
||||
* @api {post} /routemodel/:id Update a route model
|
||||
* @apiName PostRouteModel
|
||||
* @apiRouteModel RouteModel
|
||||
* @apiParam {String} name Route model name
|
||||
* @apiParam {String} steps Steps data in JSON
|
||||
* @apiSuccess {String} status Status OK
|
||||
* @apiError (client) ForbiddenError Access denied
|
||||
* @apiError (client) ValidationError Validation error
|
||||
* @apiError (client) NotFound Route model not found
|
||||
* @apiPermission admin
|
||||
* @apiVersion 1.5.0
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
@POST
|
||||
@Path("{id: [a-z0-9\\-]+}")
|
||||
public Response update(@PathParam("id") String id,
|
||||
@FormParam("name") String name,
|
||||
@FormParam("steps") String steps) {
|
||||
if (!authenticate()) {
|
||||
throw new ForbiddenClientException();
|
||||
}
|
||||
checkBaseFunction(BaseFunction.ADMIN);
|
||||
|
||||
// Validate input
|
||||
name = ValidationUtil.validateLength(name, "name", 1, 50, false);
|
||||
// TODO Validate steps data
|
||||
|
||||
// Get the route model
|
||||
RouteModelDao routeModelDao = new RouteModelDao();
|
||||
RouteModel routeModel = routeModelDao.getActiveById(id);
|
||||
if (routeModel == null) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
// Update the route model
|
||||
routeModelDao.update(routeModel.setName(name)
|
||||
.setSteps(steps), principal.getId());
|
||||
|
||||
// Always return OK
|
||||
JsonObjectBuilder response = Json.createObjectBuilder()
|
||||
.add("status", "ok");
|
||||
return Response.ok().entity(response.build()).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a route model.
|
||||
*
|
||||
* @api {delete} /routemodel/:id Delete a route model
|
||||
* @apiName DeleteRouteModel
|
||||
* @apiRouteModel RouteModel
|
||||
* @apiParam {String} id Route model ID
|
||||
* @apiSuccess {String} status Status OK
|
||||
* @apiError (client) ForbiddenError Access denied
|
||||
* @apiError (client) NotFound Route model not found
|
||||
* @apiPermission admin
|
||||
* @apiVersion 1.5.0
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
@DELETE
|
||||
@Path("{id: [a-z0-9\\-]+}")
|
||||
public Response delete(@PathParam("id") String id) {
|
||||
if (!authenticate()) {
|
||||
throw new ForbiddenClientException();
|
||||
}
|
||||
checkBaseFunction(BaseFunction.ADMIN);
|
||||
|
||||
// Get the route model
|
||||
RouteModelDao routeModelDao = new RouteModelDao();
|
||||
RouteModel routeModel = routeModelDao.getActiveById(id);
|
||||
if (routeModel == null) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
// Delete the route model
|
||||
routeModelDao.delete(routeModel.getId(), principal.getId());
|
||||
|
||||
// Always return OK
|
||||
JsonObjectBuilder response = Json.createObjectBuilder()
|
||||
.add("status", "ok");
|
||||
return Response.ok().entity(response.build()).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a route model.
|
||||
*
|
||||
* @api {get} /routemodel/:id Get a route model
|
||||
* @apiName GetRouteModel
|
||||
* @apiRouteModel RouteModel
|
||||
* @apiParam {String} id Route model ID
|
||||
* @apiSuccess {String} id Route model ID
|
||||
* @apiSuccess {String} name Route model name
|
||||
* @apiSuccess {String} create_date Create date (timestamp)
|
||||
* @apiSuccess {String} steps Steps data in JSON
|
||||
* @apiError (client) ForbiddenError Access denied
|
||||
* @apiError (client) NotFound Route model not found
|
||||
* @apiPermission admin
|
||||
* @apiVersion 1.5.0
|
||||
*
|
||||
* @param id RouteModel name
|
||||
* @return Response
|
||||
*/
|
||||
@GET
|
||||
@Path("{id: [a-z0-9\\-]+}")
|
||||
public Response get(@PathParam("id") String id) {
|
||||
if (!authenticate()) {
|
||||
throw new ForbiddenClientException();
|
||||
}
|
||||
checkBaseFunction(BaseFunction.ADMIN);
|
||||
|
||||
// Get the route model
|
||||
RouteModelDao routeModelDao = new RouteModelDao();
|
||||
RouteModel routeModel = routeModelDao.getActiveById(id);
|
||||
if (routeModel == null) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
// Build the response
|
||||
JsonObjectBuilder response = Json.createObjectBuilder()
|
||||
.add("id", routeModel.getId())
|
||||
.add("name", routeModel.getName())
|
||||
.add("create_date", routeModel.getCreateDate().getTime())
|
||||
.add("steps", routeModel.getSteps());
|
||||
|
||||
return Response.ok().entity(response.build()).build();
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ angular.module('docs').controller('SettingsWorkflow', function($scope, $state, R
|
||||
sort_column: 1,
|
||||
asc: true
|
||||
}).then(function(data) {
|
||||
$scope.workflows = data.workflows;
|
||||
$scope.workflows = data.routemodels;
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -43,7 +43,7 @@
|
||||
<a href="#/group/{{ log.message }}">{{ log.message }}</a>
|
||||
</span>
|
||||
<span ng-switch-when="RouteModel">
|
||||
<a href="#/settings/workflow/eidt/{{ log.target }}">{{ log.message }}</a>
|
||||
<a href="#/settings/workflow/edit/{{ log.target }}">{{ log.message }}</a>
|
||||
</span>
|
||||
</span>
|
||||
</td>
|
||||
|
@ -6,6 +6,8 @@ import org.junit.Test;
|
||||
|
||||
import javax.json.JsonArray;
|
||||
import javax.json.JsonObject;
|
||||
import javax.ws.rs.client.Entity;
|
||||
import javax.ws.rs.core.Form;
|
||||
|
||||
|
||||
/**
|
||||
@ -29,7 +31,68 @@ public class TestRouteModelResource extends BaseJerseyTest {
|
||||
.request()
|
||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||
.get(JsonObject.class);
|
||||
JsonArray groups = json.getJsonArray("routemodels");
|
||||
Assert.assertEquals(0, groups.size());
|
||||
JsonArray routeModels = json.getJsonArray("routemodels");
|
||||
Assert.assertEquals(0, routeModels.size());
|
||||
|
||||
// Create a route model
|
||||
json = target().path("/routemodel").request()
|
||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||
.put(Entity.form(new Form()
|
||||
.param("name", "Workflow validation 1")
|
||||
.param("steps", "[]")), JsonObject.class);
|
||||
String routeModelId = json.getString("id");
|
||||
|
||||
// Get all route models
|
||||
json = target().path("/routemodel")
|
||||
.queryParam("sort_column", "1")
|
||||
.queryParam("asc", "true")
|
||||
.request()
|
||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||
.get(JsonObject.class);
|
||||
routeModels = json.getJsonArray("routemodels");
|
||||
Assert.assertEquals(1, routeModels.size());
|
||||
Assert.assertEquals(routeModelId, routeModels.getJsonObject(0).getString("id"));
|
||||
Assert.assertEquals("Workflow validation 1", routeModels.getJsonObject(0).getString("name"));
|
||||
|
||||
// Get the route model
|
||||
json = target().path("/routemodel/" + routeModelId)
|
||||
.request()
|
||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||
.get(JsonObject.class);
|
||||
Assert.assertEquals(routeModelId, json.getString("id"));
|
||||
Assert.assertEquals("Workflow validation 1", json.getString("name"));
|
||||
Assert.assertEquals("[]", json.getString("steps"));
|
||||
|
||||
// Update the route model
|
||||
json = target().path("/routemodel/" + routeModelId).request()
|
||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||
.post(Entity.form(new Form()
|
||||
.param("name", "Workflow validation 2")
|
||||
.param("steps", "[{}]")), JsonObject.class);
|
||||
|
||||
// Get the route model
|
||||
json = target().path("/routemodel/" + routeModelId)
|
||||
.request()
|
||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||
.get(JsonObject.class);
|
||||
Assert.assertEquals(routeModelId, json.getString("id"));
|
||||
Assert.assertEquals("Workflow validation 2", json.getString("name"));
|
||||
Assert.assertEquals("[{}]", json.getString("steps"));
|
||||
|
||||
// Delete the route model
|
||||
target().path("/routemodel/" + routeModelId)
|
||||
.request()
|
||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||
.delete(JsonObject.class);
|
||||
|
||||
// Get all route models
|
||||
json = target().path("/routemodel")
|
||||
.queryParam("sort_column", "1")
|
||||
.queryParam("asc", "true")
|
||||
.request()
|
||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||
.get(JsonObject.class);
|
||||
routeModels = json.getJsonArray("routemodels");
|
||||
Assert.assertEquals(0, routeModels.size());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user