Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
* text=auto
*.sh text eol=lf
*.env text eol=lf
* text eol=lf
*.png binary
*.bat text eol=crlf
9 changes: 8 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id 'war'
id 'war'
id "com.diffplug.spotless" version "6.25.0"
}
description = "Accelerator work map"
group 'org.jlab'
Expand Down Expand Up @@ -33,4 +34,10 @@ war {
String line -> line.replaceAll("@RELEASE_DATE@", releaseDate)
}
}
}

spotless {
java {
googleJavaFormat()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,63 +10,61 @@
import javax.persistence.criteria.Root;

/**
*
* @author ryans
*/
@DeclareRoles("workmap-admin")
public abstract class AbstractFacade<T> {
private final Class<T> entityClass;
private final Class<T> entityClass;

public AbstractFacade(Class<T> entityClass) {
this.entityClass = entityClass;
}
public AbstractFacade(Class<T> entityClass) {
this.entityClass = entityClass;
}

protected abstract EntityManager getEntityManager();
protected abstract EntityManager getEntityManager();

@RolesAllowed("workmap-admin")
public void create(T entity) {
getEntityManager().persist(entity);
}
@RolesAllowed("workmap-admin")
public void create(T entity) {
getEntityManager().persist(entity);
}

@RolesAllowed("workmap-admin")
public void edit(T entity) {
getEntityManager().merge(entity);
}
@RolesAllowed("workmap-admin")
public void edit(T entity) {
getEntityManager().merge(entity);
}

@RolesAllowed("workmap-admin")
public void remove(T entity) {
getEntityManager().remove(getEntityManager().merge(entity));
}
@RolesAllowed("workmap-admin")
public void remove(T entity) {
getEntityManager().remove(getEntityManager().merge(entity));
}

@PermitAll
public T find(Object id) {
return getEntityManager().find(entityClass, id);
}
@PermitAll
public T find(Object id) {
return getEntityManager().find(entityClass, id);
}

@PermitAll
public List<T> findAll() {
CriteriaQuery<T> cq = getEntityManager().getCriteriaBuilder().createQuery(entityClass);
cq.select(cq.from(entityClass));
return getEntityManager().createQuery(cq).getResultList();
}
@PermitAll
public List<T> findAll() {
CriteriaQuery<T> cq = getEntityManager().getCriteriaBuilder().createQuery(entityClass);
cq.select(cq.from(entityClass));
return getEntityManager().createQuery(cq).getResultList();
}

@PermitAll
public List<T> findRange(int[] range) {
CriteriaQuery<T> cq = getEntityManager().getCriteriaBuilder().createQuery(entityClass);
cq.select(cq.from(entityClass));
TypedQuery<T> q = getEntityManager().createQuery(cq);
q.setMaxResults(range[1] - range[0]);
q.setFirstResult(range[0]);
return q.getResultList();
}
@PermitAll
public List<T> findRange(int[] range) {
CriteriaQuery<T> cq = getEntityManager().getCriteriaBuilder().createQuery(entityClass);
cq.select(cq.from(entityClass));
TypedQuery<T> q = getEntityManager().createQuery(cq);
q.setMaxResults(range[1] - range[0]);
q.setFirstResult(range[0]);
return q.getResultList();
}

@PermitAll
public int count() {
CriteriaQuery<Long> cq = getEntityManager().getCriteriaBuilder().createQuery(Long.class);
Root<T> rt = cq.from(entityClass);
cq.select(getEntityManager().getCriteriaBuilder().count(rt));
TypedQuery<Long> q = getEntityManager().createQuery(cq);
return q.getSingleResult().intValue();
}

@PermitAll
public int count() {
CriteriaQuery<Long> cq = getEntityManager().getCriteriaBuilder().createQuery(Long.class);
Root<T> rt = cq.from(entityClass);
cq.select(getEntityManager().getCriteriaBuilder().count(rt));
TypedQuery<Long> q = getEntityManager().createQuery(cq);
return q.getSingleResult().intValue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,102 +13,100 @@
import org.jlab.atlis.workmap.persistence.entity.WorkMap;

/**
*
* @author ryans
*/
@Stateless
@DeclareRoles("workmap-admin")
public class WorkMapFacade extends AbstractFacade<WorkMap> {

@PersistenceContext(unitName = "workmapPU")
private EntityManager em;
@EJB
private WorkMapTaskFacade taskFacade;
@EJB
private WorkMapPssFacade pssFacade;
@PersistenceContext(unitName = "workmapPU")
private EntityManager em;

@Override
protected EntityManager getEntityManager() {
return em;
}
@EJB private WorkMapTaskFacade taskFacade;
@EJB private WorkMapPssFacade pssFacade;

public WorkMapFacade() {
super(WorkMap.class);
}
@Override
protected EntityManager getEntityManager() {
return em;
}

@PermitAll
public WorkMap findByYearMonthDay(Date yearMonthDay) {
TypedQuery<WorkMap> q = em.createNamedQuery("WorkMap.findByYearMonthDay", WorkMap.class);
public WorkMapFacade() {
super(WorkMap.class);
}

q.setParameter("yearMonthDay", yearMonthDay);
@PermitAll
public WorkMap findByYearMonthDay(Date yearMonthDay) {
TypedQuery<WorkMap> q = em.createNamedQuery("WorkMap.findByYearMonthDay", WorkMap.class);

List<WorkMap> results = q.getResultList();
q.setParameter("yearMonthDay", yearMonthDay);

WorkMap map = (results == null || results.isEmpty()) ? null : results.get(0);
List<WorkMap> results = q.getResultList();

return map;
}
WorkMap map = (results == null || results.isEmpty()) ? null : results.get(0);

@PermitAll
public WorkMap findByYearMonthDayEager(Date yearMonthDay) {
WorkMap map = findByYearMonthDay(yearMonthDay);
return map;
}

if (map != null) {
//map.getWorkMapTaskList().size();
//map.getWorkMapPssList().size();
em.detach(map);
map.setWorkMapTaskList(taskFacade.findByWorkMapIdEager(map.getWorkMapId()));
map.setWorkMapPssList(pssFacade.findByWorkMapIdEager(map.getWorkMapId()));
}
@PermitAll
public WorkMap findByYearMonthDayEager(Date yearMonthDay) {
WorkMap map = findByYearMonthDay(yearMonthDay);

return map;
if (map != null) {
// map.getWorkMapTaskList().size();
// map.getWorkMapPssList().size();
em.detach(map);
map.setWorkMapTaskList(taskFacade.findByWorkMapIdEager(map.getWorkMapId()));
map.setWorkMapPssList(pssFacade.findByWorkMapIdEager(map.getWorkMapId()));
}

private void clearLists(WorkMap map) {
if (map.getWorkMapId() != null) {
taskFacade.deleteByWorkMapId(map.getWorkMapId());
pssFacade.deleteByWorkMapId(map.getWorkMapId());
em.flush();
}
}
return map;
}

@RolesAllowed("workmap-admin")
public void save(WorkMap map) {
clearLists(map);
edit(map);
private void clearLists(WorkMap map) {
if (map.getWorkMapId() != null) {
taskFacade.deleteByWorkMapId(map.getWorkMapId());
pssFacade.deleteByWorkMapId(map.getWorkMapId());
em.flush();
}

@RolesAllowed("workmap-admin")
public void copy(Date from, Date to) {
WorkMap fromMap = findByYearMonthDayEager(from);
WorkMap toMap = findByYearMonthDay(to);

if (fromMap == null) {
if (toMap == null) {
toMap = new WorkMap();
toMap.setYearMonthDay(to);
toMap.setLastModified(new Date());
em.persist(toMap);
} else {
toMap.setLastModified(new Date());
toMap.setNote(null);
clearLists(toMap);
}
} else {
if (toMap == null) {
toMap = new WorkMap();
toMap.setYearMonthDay(to);
toMap.setLastModified(new Date());
toMap.setNote(fromMap.getNote());
em.persist(toMap); // Make it managed and persistent
} else {
toMap.setLastModified(new Date());
toMap.setNote(fromMap.getNote());
clearLists(toMap);
}

toMap.setWorkMapTaskList(fromMap.copyWorkMapTaskList(toMap));
toMap.setWorkMapPssList(fromMap.copyWorkMapPssList(toMap));
}
}

@RolesAllowed("workmap-admin")
public void save(WorkMap map) {
clearLists(map);
edit(map);
}

@RolesAllowed("workmap-admin")
public void copy(Date from, Date to) {
WorkMap fromMap = findByYearMonthDayEager(from);
WorkMap toMap = findByYearMonthDay(to);

if (fromMap == null) {
if (toMap == null) {
toMap = new WorkMap();
toMap.setYearMonthDay(to);
toMap.setLastModified(new Date());
em.persist(toMap);
} else {
toMap.setLastModified(new Date());
toMap.setNote(null);
clearLists(toMap);
}
} else {
if (toMap == null) {
toMap = new WorkMap();
toMap.setYearMonthDay(to);
toMap.setLastModified(new Date());
toMap.setNote(fromMap.getNote());
em.persist(toMap); // Make it managed and persistent
} else {
toMap.setLastModified(new Date());
toMap.setNote(fromMap.getNote());
clearLists(toMap);
}

toMap.setWorkMapTaskList(fromMap.copyWorkMapTaskList(toMap));
toMap.setWorkMapPssList(fromMap.copyWorkMapPssList(toMap));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,19 @@
import org.jlab.atlis.workmap.persistence.entity.WorkMapPssArea;

/**
*
* @author ryans
*/
@Stateless
public class WorkMapPssAreaFacade extends AbstractFacade<WorkMapPssArea> {
@PersistenceContext(unitName = "workmapPU")
private EntityManager em;
@PersistenceContext(unitName = "workmapPU")
private EntityManager em;

@Override
protected EntityManager getEntityManager() {
return em;
}
@Override
protected EntityManager getEntityManager() {
return em;
}

public WorkMapPssAreaFacade() {
super(WorkMapPssArea.class);
}

public WorkMapPssAreaFacade() {
super(WorkMapPssArea.class);
}
}
Loading