mirror of
https://github.com/sismics/docs.git
synced 2025-12-13 09:46:17 +00:00
#18: Add/update/delete groups
This commit is contained in:
@@ -48,6 +48,23 @@ public class GroupDao {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a group by ID.
|
||||
*
|
||||
* @param id Group ID
|
||||
* @return Group
|
||||
*/
|
||||
public Group getActiveById(String id) {
|
||||
EntityManager em = ThreadLocalContext.get().getEntityManager();
|
||||
Query q = em.createQuery("select g from Group g where g.id = :id and g.deleteDate is null");
|
||||
q.setParameter("id", id);
|
||||
try {
|
||||
return (Group) q.getSingleResult();
|
||||
} catch (NoResultException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new group.
|
||||
*
|
||||
@@ -99,6 +116,10 @@ public class GroupDao {
|
||||
q.setParameter("dateNow", dateNow);
|
||||
q.executeUpdate();
|
||||
|
||||
q = em.createQuery("update Group g set g.parentId = null where g.parentId = :groupId and g.deleteDate is null");
|
||||
q.setParameter("groupId", groupDb.getId());
|
||||
q.executeUpdate();
|
||||
|
||||
// Create audit log
|
||||
AuditLogUtil.create(groupDb, AuditLogType.DELETE, userId);
|
||||
}
|
||||
@@ -211,7 +232,7 @@ public class GroupDao {
|
||||
|
||||
return groupDtoList;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Recursively search group's parents.
|
||||
*
|
||||
@@ -232,5 +253,30 @@ public class GroupDao {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a group.
|
||||
*
|
||||
* @param group Group to update
|
||||
* @param userId User ID
|
||||
* @return Updated group
|
||||
*/
|
||||
public Group update(Group group, String userId) {
|
||||
EntityManager em = ThreadLocalContext.get().getEntityManager();
|
||||
|
||||
// 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();
|
||||
|
||||
// Update the group
|
||||
groupFromDb.setName(group.getName());
|
||||
groupFromDb.setParentId(group.getParentId());
|
||||
|
||||
// Create audit log
|
||||
AuditLogUtil.create(groupFromDb, AuditLogType.UPDATE, userId);
|
||||
|
||||
return groupFromDb;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user