001/**
002 * Copyright 2005-2016 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.kew.rule.dao.impl;
017
018import java.util.ArrayList;
019import java.util.Collection;
020import java.util.List;
021import java.util.Map;
022
023import javax.persistence.EntityManager;
024import javax.persistence.PersistenceContext;
025
026import org.kuali.rice.core.framework.persistence.jpa.OrmUtils;
027import org.kuali.rice.core.framework.persistence.jpa.criteria.Criteria;
028import org.kuali.rice.core.framework.persistence.jpa.criteria.QueryByCriteria;
029import org.kuali.rice.kew.rule.RuleDelegationBo;
030import org.kuali.rice.kew.rule.dao.RuleDelegationDAO;
031
032
033public class RuleDelegationDAOJpaImpl implements RuleDelegationDAO {
034
035        @PersistenceContext(unitName="kew-unit")
036        private EntityManager entityManager;
037
038    public List<RuleDelegationBo> findByDelegateRuleId(String ruleId) {
039        Criteria crit = new Criteria(RuleDelegationBo.class.getName());
040        crit.eq("delegateRuleId", ruleId);
041        return (List) new QueryByCriteria(entityManager, crit).toQuery().getResultList();
042    }
043
044    public void save(RuleDelegationBo ruleDelegation) {
045        if(ruleDelegation.getRuleDelegationId()==null){
046                entityManager.persist(ruleDelegation);
047        }else{
048                OrmUtils.merge(entityManager, ruleDelegation);
049        }
050    }
051    public List<RuleDelegationBo> findAllCurrentRuleDelegations(){
052        Criteria crit = new Criteria(RuleDelegationBo.class.getName());
053        crit.eq("delegationRuleBaseValues.currentInd", true);
054        return (List) new QueryByCriteria(entityManager, crit).toQuery().getResultList();
055    }
056
057    public RuleDelegationBo findByRuleDelegationId(String ruleDelegationId){
058        return entityManager.find(RuleDelegationBo.class, ruleDelegationId);
059
060    }
061    public void delete(String ruleDelegationId){
062        entityManager.remove(findByRuleDelegationId(ruleDelegationId));
063    }
064
065    public EntityManager getEntityManager() {
066        return this.entityManager;
067    }
068
069    public void setEntityManager(EntityManager entityManager) {
070        this.entityManager = entityManager;
071    }
072
073    public List<RuleDelegationBo> findByResponsibilityIdWithCurrentRule(String responsibilityId) {
074        Criteria crit = new Criteria(RuleDelegationBo.class.getName());
075        crit.eq("responsibilityId", responsibilityId);
076        crit.eq("delegationRuleBaseValues.currentInd", true);
077        Collection delegations = new QueryByCriteria(entityManager, crit).toQuery().getResultList();
078        return new ArrayList<RuleDelegationBo>(delegations);
079    }
080
081    /**
082     * This overridden method ...
083     *
084     * @see org.kuali.rice.kew.rule.dao.RuleDelegationDAO#search(java.lang.String, java.lang.Long, java.lang.Long, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.Boolean, java.util.Map, java.lang.String)
085     */
086    public List<RuleDelegationBo> search(String parentRuleBaseVaueId, String parentResponsibilityId, String docTypeName, String ruleId,
087            String ruleTemplateId, String ruleDescription, String workgroupId,
088            String workflowId, String delegationType, Boolean activeInd,
089            Map extensionValues, String workflowIdDirective) {
090        // TODO jjhanso - THIS METHOD NEEDS JAVADOCS
091        return null;
092    }
093
094    /**
095     * This overridden method ...
096     *
097     * @see org.kuali.rice.kew.rule.dao.RuleDelegationDAO#search(java.lang.String, java.lang.Long, java.lang.String, java.util.Collection, java.lang.String, java.lang.String, java.lang.Boolean, java.util.Map, java.util.Collection)
098     */
099    public List<RuleDelegationBo> search(String parentRuleBaseVaueId, String parentResponsibilityId, String docTypeName, String ruleTemplateId,
100            String ruleDescription, Collection<String> workgroupIds,
101            String workflowId, String delegationType, Boolean activeInd,
102            Map extensionValues, Collection actionRequestCodes) {
103        // TODO jjhanso - THIS METHOD NEEDS JAVADOCS
104        return null;
105    }
106
107}