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.kim.impl.responsibility; 017 018import javax.persistence.EntityManager; 019import java.util.ArrayList; 020import java.util.List; 021 022public class ResponsibilityDaoJpa implements ResponsibilityDao { 023 024 private EntityManager entityManager; 025 026 @Override 027 public List<ResponsibilityBo> findWorkflowResponsibilities(String documentTypeName) { 028 // query the responsibility ids from the responsibility attributes table first, then load the responsibilities 029 // one by one. This avoids a bug where querying for responsibilities by attribute value (doucment type in this 030 // case) would return a responsibility with only a single attribute, not 4 as expected for responsibilities. 031 List<String> responsibilityIds = getEntityManager().createNamedQuery("Responsibility.workflowResponsibilities", String.class). 032 setParameter("documentTypeName", documentTypeName).getResultList(); 033 List<ResponsibilityBo> responsibilities = new ArrayList<>(); 034 for (String responsibilityId : responsibilityIds) { 035 responsibilities.add(entityManager.find(ResponsibilityBo.class, responsibilityId)); 036 } 037 return responsibilities; 038 } 039 040 @Override 041 public List<ResponsibilityBo> findWorkflowExceptionResponsibilities(String documentTypeName) { 042 // query the responsibility ids from the responsibility attributes table first, then load the responsibilities 043 // one by one. This avoids a bug where querying for responsibilities by attribute value (doucment type in this 044 // case) would return a responsibility with only a single attribute, not 4 as expected for responsibilities. 045 List<String> responsibilityIds = getEntityManager().createNamedQuery("Responsibility.workflowExceptionResponsibilities", String.class). 046 setParameter("documentTypeName", documentTypeName).getResultList(); 047 List<ResponsibilityBo> responsibilities = new ArrayList<>(); 048 for (String responsibilityId : responsibilityIds) { 049 responsibilities.add(entityManager.find(ResponsibilityBo.class, responsibilityId)); 050 } 051 return responsibilities; 052 } 053 054 public void setEntityManager(EntityManager entityManager) { 055 this.entityManager = entityManager; 056 } 057 058 public EntityManager getEntityManager() { 059 return entityManager; 060 } 061}