001package org.kuali.student.enrollment.class1.lpr.dao;
002
003
004import java.util.HashSet;
005import java.util.List;
006import java.util.Set;
007
008import org.kuali.student.enrollment.class1.lpr.model.LprEntity;
009import org.kuali.student.r2.common.dao.GenericEntityDao;
010import org.kuali.student.enrollment.lpr.dto.LprInfo;
011import org.kuali.student.r2.common.exceptions.DoesNotExistException;
012
013
014public class LprDao extends GenericEntityDao<LprEntity> {
015
016    @SuppressWarnings({"unchecked"})
017    public List<LprEntity> getByLuiId(String luiId) {
018        return em.createQuery("from LprEntity lpr where lpr.luiId=:luiId").setParameter("luiId", luiId).getResultList();
019    }
020
021    @SuppressWarnings("unchecked")
022    public List<String> getLprIdsByLuiAndPerson(String personId, String luiId) {
023        return em.createQuery("select lpr.id from LprEntity lpr where lpr.personId=:personId and lpr.luiId=:luiId").setParameter("personId", personId).setParameter("luiId", luiId).getResultList();
024    }
025
026    @SuppressWarnings("unchecked")
027    public List<LprEntity> getLprsByPersonAndType(String personId,String typeKey){
028        return em.createQuery("from LprEntity lpr where lpr.personId=:personId and lpr.personRelationTypeId=:typeKey").setParameter("personId", personId).setParameter("typeKey", typeKey).getResultList();
029    }
030
031
032    @SuppressWarnings("unchecked")
033    public List<LprEntity> getLprsByPerson(String personId){
034        return em.createQuery("from LprEntity lpr where lpr.personId=:personId").setParameter("personId", personId).getResultList();
035    }
036
037    @SuppressWarnings("unchecked")
038    public List<String> getPersonIdsByLui(String luiId, String typeKey, String stateKey){
039        return em.createQuery("select lpr.personId from LprEntity lpr where lpr.luiId=:luiId and lpr.personRelationTypeId=:typeKey and lpr.personRelationStateId=:stateKey")
040                .setParameter("luiId", luiId)
041                .setParameter("typeKey", typeKey)
042                .setParameter("stateKey", stateKey)
043                .getResultList();
044    }
045
046    @SuppressWarnings("unchecked")
047    public List<LprEntity> getLprByLuiAndPerson(String personId, String luiId) {
048        return em.createQuery("from LprEntity lpr where lpr.personId=:personId and lpr.luiId=:luiId")
049                .setParameter("personId", personId)
050                .setParameter("luiId", luiId)
051                .getResultList();
052    }
053
054    @SuppressWarnings("unchecked")
055    public List<LprEntity> getLprsByLuiPersonAndState(String personId, String luiId, String stateKey) {
056        return em.createQuery("from LprEntity lpr where lpr.personId=:personId and lpr.luiId=:luiId and lpr.personRelationStateId=:stateKey")
057                .setParameter("personId", personId)
058                .setParameter("luiId", luiId)
059                .setParameter("stateKey", stateKey)
060                .getResultList();
061    }
062
063    @SuppressWarnings("unchecked")
064    public List<LprEntity> getLprsByLuiAndType(String luiId, String lprTypeKey) {
065        return em.createQuery("from LprEntity lpr where lpr.luiId=:luiId and lpr.personRelationTypeId=:lprTypeKey").setParameter("luiId", luiId).setParameter("lprTypeKey", lprTypeKey).getResultList();
066    }
067
068    public List<String> getLuiIdsByPersonAndTypeAndState(String personId, String luiPersonRelationType, String relationState) {
069        return em.createQuery("SELECT lpr.luiId FROM LprEntity lpr WHERE lpr.personId = :personId AND lpr.personRelationTypeId = :luiPersonRelationType AND lpr.personRelationStateId = :relationState")
070                .setParameter("personId", personId)
071                .setParameter("luiPersonRelationType", luiPersonRelationType)
072                .setParameter("relationState", relationState)
073                .getResultList();
074    }
075
076    @SuppressWarnings("unchecked")
077    public List<LprEntity> getLprsByLuis(List<String> luiIds) {
078        Set<String> luiIdSet = new HashSet<String>(luiIds.size());
079        // remove duplicates from the key list
080        luiIdSet.addAll(luiIds);
081        return (List<LprEntity>) em.createNamedQuery("Lpr.getLprsByLuis").setParameter("luiIds", luiIdSet).getResultList();
082    }
083}