View Javadoc
1   /**
2    * Copyright 2005-2015 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.kew.actionitem;
17  
18  import org.kuali.rice.core.api.delegation.DelegationType;
19  
20  import javax.persistence.Entity;
21  import javax.persistence.NamedQueries;
22  import javax.persistence.NamedQuery;
23  import javax.persistence.Table;
24  import java.util.ArrayList;
25  import java.util.Collection;
26  import java.util.List;
27  import java.util.Map;
28  
29  /**
30   * This is the model for action items. These are displayed as the action list as well.  Mapped to ActionItemService.
31   * NOTE: This object contains denormalized fields that have been copied from related ActionRequestValue and
32   * DocumentRouteHeaderValue
33   * objects for performance reasons.  These should be preserved and their related objects should not be added to the OJB
34   * mapping as we do not want them loaded for each ActionItem object.
35   *
36   * @author Kuali Rice Team (rice.collab@kuali.org)
37   */
38  @Entity
39  @Table(name = "KREW_ACTN_ITM_T")
40  @NamedQueries({@NamedQuery(name = "ActionItem.DistinctDocumentsForPrincipalId", query =
41          "SELECT COUNT(DISTINCT(ai.documentId)) FROM ActionItem ai"
42                  + "  WHERE ai.principalId = :principalId AND (ai.delegationType IS NULL OR ai.delegationType = 'P')"),
43          @NamedQuery(name = "ActionItem.GetMaxDateAndCountForPrincipalId", query =
44                  "SELECT MAX(ai.dateAssigned) AS max_date, COUNT(DISTINCT(ai.documentId)) AS total_records FROM ActionItem ai"
45                          + "  WHERE ai.principalId = :principalId"),
46          @NamedQuery(name = "ActionItem.GetQuickLinksDocumentTypeNameAndCount", query =
47                  "select ai.docName, COUNT(ai) from ActionItem ai where ai.principalId = :principalId " +
48                          "and (ai.delegationType is null or ai.delegationType != :delegationType)"
49                          + " group by ai.docName")})
50  public class ActionItem extends ActionItemBase {
51  
52      private static final long serialVersionUID = -1079562205125660151L;
53  
54      public ActionItem deepCopy(Map<Object, Object> visited) {
55          return super.deepCopy(visited, ActionItem.class);
56      }
57  
58      public static org.kuali.rice.kew.api.action.ActionItem to(ActionItem bo) {
59          if (bo == null) {
60              return null;
61          }
62          return org.kuali.rice.kew.api.action.ActionItem.Builder.create(bo).build();
63      }
64  
65      public static List<org.kuali.rice.kew.api.action.ActionItem> to(Collection<ActionItem> bos) {
66          if (bos == null) {
67              return null;
68          }
69          if (bos.isEmpty()) {
70              return new ArrayList<org.kuali.rice.kew.api.action.ActionItem>();
71          }
72  
73          List<org.kuali.rice.kew.api.action.ActionItem> dtos = new ArrayList<org.kuali.rice.kew.api.action.ActionItem>(
74                  bos.size());
75          for (ActionItem bo : bos) {
76              dtos.add(ActionItem.to(bo));
77          }
78          return dtos;
79      }
80  }