View Javadoc
1   /**
2    * Copyright 2005-2016 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kim.impl.responsibility;
17  
18  import javax.persistence.EntityManager;
19  import java.util.ArrayList;
20  import java.util.List;
21  
22  public class ResponsibilityDaoJpa implements ResponsibilityDao {
23  
24      private EntityManager entityManager;
25  
26      @Override
27      public List<ResponsibilityBo> findWorkflowResponsibilities(String documentTypeName) {
28          // query the responsibility ids from the responsibility attributes table first, then load the responsibilities
29          // one by one. This avoids a bug where querying for responsibilities by attribute value (doucment type in this
30          // case) would return a responsibility with only a single attribute, not 4 as expected for responsibilities.
31          List<String> responsibilityIds = getEntityManager().createNamedQuery("Responsibility.workflowResponsibilities", String.class).
32                  setParameter("documentTypeName", documentTypeName).getResultList();
33          List<ResponsibilityBo> responsibilities = new ArrayList<>();
34          for (String responsibilityId : responsibilityIds) {
35              responsibilities.add(entityManager.find(ResponsibilityBo.class, responsibilityId));
36          }
37          return responsibilities;
38      }
39  
40      @Override
41      public List<ResponsibilityBo> findWorkflowExceptionResponsibilities(String documentTypeName) {
42          // query the responsibility ids from the responsibility attributes table first, then load the responsibilities
43          // one by one. This avoids a bug where querying for responsibilities by attribute value (doucment type in this
44          // case) would return a responsibility with only a single attribute, not 4 as expected for responsibilities.
45          List<String> responsibilityIds = getEntityManager().createNamedQuery("Responsibility.workflowExceptionResponsibilities", String.class).
46                  setParameter("documentTypeName", documentTypeName).getResultList();
47          List<ResponsibilityBo> responsibilities = new ArrayList<>();
48          for (String responsibilityId : responsibilityIds) {
49              responsibilities.add(entityManager.find(ResponsibilityBo.class, responsibilityId));
50          }
51          return responsibilities;
52      }
53  
54      public void setEntityManager(EntityManager entityManager) {
55          this.entityManager = entityManager;
56      }
57  
58      public EntityManager getEntityManager() {
59          return entityManager;
60      }
61  }