Hela event och projektstruktur
git-svn-id: svn://svn.dsv.su.se/scipro/scipro/trunk@100 73ecded7-942e-4092-bab0-0e58ef0ee984
This commit is contained in:
parent
9948354893
commit
6c97acb6ce
src/main/java/se/su/dsv/scipro/data/dao/jpa
@ -1,7 +1,21 @@
|
||||
package se.su.dsv.scipro.data.dao.jpa;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.NoResultException;
|
||||
import javax.persistence.PersistenceException;
|
||||
import javax.persistence.TypedQuery;
|
||||
|
||||
import org.springframework.orm.jpa.JpaCallback;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import se.su.dsv.scipro.data.dao.interfaces.EventDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.Event;
|
||||
import se.su.dsv.scipro.data.dataobjects.Project;
|
||||
import se.su.dsv.scipro.data.dataobjects.User;
|
||||
|
||||
/**
|
||||
* @author Richard Wilkinson - richard.wilkinson@jweekend.com
|
||||
@ -12,5 +26,111 @@ public class EventDaoJPAImp extends LazyDeleteAbstractDaoJPAImp<Event> implement
|
||||
public EventDaoJPAImp() {
|
||||
super(Event.class);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
private List<Event> getEvents(final User u, final Project p,
|
||||
final Boolean isDone, final Date fromDate, final Date toDate,
|
||||
final Integer limit) {
|
||||
return getJpaTemplate().execute(new JpaCallback<List<Event>>() {
|
||||
public List<Event> doInJpa(EntityManager em) throws PersistenceException {
|
||||
|
||||
String selectClause = "select distinct e ";
|
||||
|
||||
String fromClause = "from Event e, GroupEvent ge, ProjectEvent pe, User u ";
|
||||
|
||||
String joinClause = "join ge.projectSchedules ps " +
|
||||
"join u.roles role " +
|
||||
"join pe.participants evPart ";
|
||||
|
||||
String conditions = "where u = :user " +
|
||||
"and e.deleted = false ";
|
||||
|
||||
if(fromDate != null) {
|
||||
conditions += "and e.dueDate > :fromDate ";
|
||||
}
|
||||
|
||||
if(toDate != null){
|
||||
conditions += "and e.dueDate < :toDate ";
|
||||
}
|
||||
|
||||
String projectEventConditions = "e = pe " +
|
||||
"and evPart = role " +
|
||||
"and pe.projectSchedule.project = :project ";
|
||||
|
||||
if(isDone != null){
|
||||
projectEventConditions += "and pe.done = :isDone ";
|
||||
}
|
||||
|
||||
String groupEventConditions = "e = ge " +
|
||||
"and ps.project = :project ";
|
||||
|
||||
String q = selectClause +
|
||||
fromClause +
|
||||
joinClause +
|
||||
conditions +
|
||||
"and ((" + projectEventConditions + ") or " + "(" + groupEventConditions + ")) ";
|
||||
|
||||
q += "order by e.dueDate asc ";
|
||||
|
||||
if(limit != null){
|
||||
q += " limit :limit ";
|
||||
}
|
||||
|
||||
TypedQuery<Event> query = em.createQuery(q, Event.class);
|
||||
|
||||
query.setParameter("project", p)
|
||||
.setParameter("user", u);
|
||||
|
||||
if(isDone != null){
|
||||
query.setParameter("isDone", isDone);
|
||||
}
|
||||
|
||||
if(fromDate != null) {
|
||||
query.setParameter("fromDate", fromDate);
|
||||
}
|
||||
|
||||
if(toDate != null){
|
||||
query.setParameter("toDate", toDate);
|
||||
}
|
||||
|
||||
if(limit != null){
|
||||
query.setParameter("limit", limit);
|
||||
}
|
||||
|
||||
try{
|
||||
return query.getResultList();
|
||||
} catch (NoResultException e) {
|
||||
return new ArrayList<Event>();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public List<Event> getEventsByUserAndProject(final User u, final Project p,
|
||||
final Boolean isDone, final Date fromDate, final Date toDate,
|
||||
final Integer limit){
|
||||
return getEvents(u, p, isDone, fromDate, toDate, limit);
|
||||
}
|
||||
|
||||
public List<Event> getAllEventsByUserAndProject(final User u, final Project p){
|
||||
return getEvents(u, p, null, null, null, null);
|
||||
}
|
||||
|
||||
public List<Event> getUpcomingEventsByUserAndProject(final User u, final Project p){
|
||||
return getEvents(u, p, null, new Date(), null, null);
|
||||
}
|
||||
|
||||
public List<Event> getOverDueEventsByUserAndProject(final User u, final Project p) {
|
||||
return getEvents(u, p, false, null, new Date(), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* For now this is not a count-query due to the inconvenience on having to maintain 2 query strings
|
||||
*/
|
||||
public int countOverDueEventsByUserAndProject(final User u, final Project p) {
|
||||
return getEvents(u, p, false, null, new Date(), null).size();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,11 @@
|
||||
package se.su.dsv.scipro.data.dao.jpa;
|
||||
|
||||
import se.su.dsv.scipro.data.dao.interfaces.GroupEventDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.GroupEvent;
|
||||
|
||||
public class GroupEventDaoJPAImp extends LazyDeleteAbstractDaoJPAImp<GroupEvent> implements GroupEventDao {
|
||||
|
||||
public GroupEventDaoJPAImp(){
|
||||
super(GroupEvent.class);
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package se.su.dsv.scipro.data.dao.jpa;
|
||||
|
||||
import se.su.dsv.scipro.data.dao.interfaces.ProjectEventDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.ProjectEvent;
|
||||
|
||||
public class ProjectEventDaoJPAImp extends LazyDeleteAbstractDaoJPAImp<ProjectEvent> implements ProjectEventDao {
|
||||
|
||||
public ProjectEventDaoJPAImp() {
|
||||
super(ProjectEvent.class);
|
||||
}
|
||||
|
||||
}
|
@ -17,94 +17,10 @@ import se.su.dsv.scipro.data.dataobjects.ProjectSchedule;
|
||||
|
||||
public class ProjectScheduleDaoJPAImp extends AbstractDaoJPAImp<ProjectSchedule>
|
||||
implements ProjectScheduleDao {
|
||||
|
||||
private static final int ALL_EVENTS = 0;
|
||||
private static final int OLD_EVENTS = 1;
|
||||
private static final int UPCOMING_EVENTS = 2;
|
||||
private static final int UPCOMING_AND_NOT_DONE_EVENTS = 3;
|
||||
|
||||
public ProjectScheduleDaoJPAImp() {
|
||||
super(ProjectSchedule.class);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public List<Event> getEventsByProjectSchedule(final ProjectSchedule ps, final int eventCode, final Boolean eventIsDone) {
|
||||
return getJpaTemplate().execute(new JpaCallback<List<Event>>() {
|
||||
public List<Event> doInJpa(EntityManager em) throws PersistenceException {
|
||||
|
||||
String q = "Select e " +
|
||||
"from Event e " +
|
||||
"where e.projectSchedule = :ps " +
|
||||
"and e.deleted = false ";
|
||||
|
||||
switch(eventCode){
|
||||
case OLD_EVENTS:
|
||||
q += "and e.dueDate < now() ";
|
||||
break;
|
||||
case UPCOMING_AND_NOT_DONE_EVENTS:
|
||||
q += "and (e.dueDate > now() or e.done = false) ";
|
||||
break;
|
||||
case UPCOMING_EVENTS:
|
||||
q += "and e.dueDate > now() ";
|
||||
break;
|
||||
case ALL_EVENTS:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if(eventIsDone != null){
|
||||
q += String.format("and e.done = %s ", eventIsDone);
|
||||
}
|
||||
|
||||
q += "order by e.dueDate asc";
|
||||
|
||||
System.out.println(q);
|
||||
|
||||
TypedQuery<Event> query = em.createQuery(q, Event.class);
|
||||
query.setParameter("ps", ps);
|
||||
|
||||
try {
|
||||
return query.getResultList();
|
||||
} catch (NoResultException e){
|
||||
return new ArrayList<Event>(1);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public List<Event> getUpcomingEventsByProjectSchedule(final ProjectSchedule ps, boolean includeOldNotDoneEvents) {
|
||||
if(includeOldNotDoneEvents)
|
||||
return getEventsByProjectSchedule(ps, UPCOMING_AND_NOT_DONE_EVENTS, null);
|
||||
else
|
||||
return getEventsByProjectSchedule(ps, UPCOMING_EVENTS, null);
|
||||
}
|
||||
|
||||
public List<Event> getAllEventsByProjectSchedule(final ProjectSchedule ps) {
|
||||
return getEventsByProjectSchedule(ps, ALL_EVENTS, null);
|
||||
}
|
||||
|
||||
public List<Event> getOldEventsByProjectSchedule(final ProjectSchedule ps, final Boolean done) {
|
||||
return getEventsByProjectSchedule(ps, OLD_EVENTS, done);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public int countOverDueEvents(final ProjectSchedule ps) {
|
||||
return getJpaTemplate().execute(new JpaCallback<Integer>() {
|
||||
public Integer doInJpa(EntityManager em) throws PersistenceException {
|
||||
|
||||
String q = "select count(e) " +
|
||||
"from Event e " +
|
||||
"where e.projectSchedule = :ps " +
|
||||
"and e.done = false " +
|
||||
"and e.dueDate < now() " +
|
||||
"and e.deleted = false ";
|
||||
|
||||
TypedQuery<Long> query = em.createQuery(q, Long.class);
|
||||
query.setParameter("ps", ps);
|
||||
|
||||
return (query.getSingleResult()).intValue();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user