001/**
002 * Copyright 2005-2014 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.actionrequest.dao.impl;
017
018import org.kuali.rice.kew.actionrequest.ActionRequestValue;
019import org.kuali.rice.kew.actionrequest.dao.ActionRequestDAO;
020import org.kuali.rice.kew.api.action.ActionRequestStatus;
021import org.kuali.rice.kew.api.action.RecipientType;
022
023import javax.persistence.EntityManager;
024import javax.persistence.TypedQuery;
025import java.util.List;
026
027/**
028 * This is a description of what this class does - sgibson don't forget to fill this in.
029 * 
030 * @author Kuali Rice Team (rice.collab@kuali.org)
031 */
032public class ActionRequestDAOJpaImpl implements ActionRequestDAO {
033    
034    private EntityManager entityManager;
035
036    /**
037         * @return the entityManager
038         */
039        public EntityManager getEntityManager() {
040                return this.entityManager;
041        }
042
043        /**
044         * @param entityManager the entityManager to set
045         */
046        public void setEntityManager(EntityManager entityManager) {
047                this.entityManager = entityManager;
048        }
049
050    public List<ActionRequestValue> findPendingRootRequestsByDocumentType(String documentTypeId) {
051        TypedQuery<ActionRequestValue> query =
052                entityManager.createNamedQuery("ActionRequestValue.FindPendingRootRequestsByDocumentType", ActionRequestValue.class);
053        query.setParameter("documentTypeId", documentTypeId);
054        query.setParameter("currentIndicator", Boolean.TRUE);
055        query.setParameter("actionRequestStatus1", ActionRequestStatus.INITIALIZED.getCode());
056        query.setParameter("actionRequestStatus2", ActionRequestStatus.ACTIVATED.getCode());
057        return query.getResultList();
058    }
059
060    public List<String> getRequestGroupIds(String documentId) {
061        TypedQuery<String> query = entityManager.createNamedQuery("ActionRequestValue.GetRequestGroupIds", String.class);
062        query.setParameter("documentId", documentId);
063        query.setParameter("currentIndicator", Boolean.TRUE);
064        query.setParameter("recipientTypeCd", RecipientType.GROUP.getCode());
065        return query.getResultList();
066    }
067
068}