1 | |
package org.kuali.student.r2.core.class1.atp.dao; |
2 | |
|
3 | |
import java.util.Date; |
4 | |
import java.util.List; |
5 | |
|
6 | |
import javax.persistence.Query; |
7 | |
|
8 | |
import org.kuali.student.enrollment.dao.GenericEntityDao; |
9 | |
import org.kuali.student.r2.core.class1.atp.model.MilestoneEntity; |
10 | |
|
11 | 0 | public class MilestoneDao extends GenericEntityDao<MilestoneEntity> { |
12 | |
|
13 | |
@SuppressWarnings("unchecked") |
14 | |
public List<MilestoneEntity> getByMilestoneTypeId(String milestoneType) { |
15 | 0 | return em.createQuery("from MilestoneEntity m where m.atpType=:mstoneType").setParameter("mstoneType", milestoneType).getResultList(); |
16 | |
} |
17 | |
private static final String OVERLAP_LOGIC = "m.startDate between :startRange and :endRange or :startRange between m.startDate and m.endDate"; |
18 | |
|
19 | |
@SuppressWarnings("unchecked") |
20 | |
public List<MilestoneEntity> getByDateRange(Date startRange, Date endRange) { |
21 | |
|
22 | 0 | return em.createQuery( |
23 | |
"from MilestoneEntity m where " + OVERLAP_LOGIC).setParameter("startRange", startRange).setParameter("endRange", endRange).getResultList(); |
24 | |
} |
25 | |
|
26 | |
@SuppressWarnings("unchecked") |
27 | |
public List<MilestoneEntity> getByDateRangeAndType(Date startRange, Date endRange, String milestoneType) { |
28 | 0 | Query query = em.createQuery("from MilestoneEntity m where m.milestoneType=:mstoneType and (" + OVERLAP_LOGIC + ")"); |
29 | 0 | query.setParameter("startRange", startRange); |
30 | 0 | query.setParameter("endRange", endRange); |
31 | 0 | query.setParameter("mstoneType", milestoneType); |
32 | 0 | return query.getResultList(); |
33 | |
} |
34 | |
|
35 | |
@SuppressWarnings("unchecked") |
36 | |
public List<String> getIdsByAtp(String atpId) { |
37 | 0 | Query query = em.createQuery("select m.milestoneId from AtpMilestoneRelationEntity m where m.atpId = :atpId"); |
38 | 0 | query.setParameter("atpId", atpId); |
39 | 0 | return query.getResultList(); |
40 | |
} |
41 | |
|
42 | |
@SuppressWarnings("unchecked") |
43 | |
public List<MilestoneEntity> getByDatesForAtp(String atpId, Date startRange, Date endRange) { |
44 | 0 | return em.createQuery( |
45 | |
"select m.milestoneId from AtpMilestoneRelationEntity m where m.atpId = :atpId and (" + OVERLAP_LOGIC + ")"). |
46 | |
setParameter("atpId", atpId). |
47 | |
setParameter("startRange", startRange). |
48 | |
setParameter("startRange", endRange). |
49 | |
getResultList(); |
50 | |
} |
51 | |
|
52 | |
@SuppressWarnings("unchecked") |
53 | |
public List<MilestoneEntity> getImpactedMilestones(String milestoneId) { |
54 | 0 | return em.createQuery("from MilestoneEntity m where m.relativeAnchorMilestoneId=:milestoneId"). |
55 | |
setParameter("milestoneId", milestoneId). |
56 | |
getResultList(); |
57 | |
} |
58 | |
} |