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.kns.service.impl;
17  
18  import java.util.Collection;
19  
20  import org.kuali.rice.kew.api.KewApiServiceLocator;
21  import org.kuali.rice.kew.api.doctype.DocumentType;
22  import org.kuali.rice.kns.service.TransactionalDocumentDictionaryService;
23  import org.kuali.rice.krad.datadictionary.DataDictionary;
24  import org.kuali.rice.krad.datadictionary.TransactionalDocumentEntry;
25  import org.kuali.rice.krad.document.TransactionalDocument;
26  import org.kuali.rice.krad.rules.rule.BusinessRule;
27  import org.kuali.rice.krad.service.DataDictionaryService;
28  
29  /**
30   * This class is the service implementation for the TransactionalDocumentDictionary structure. Defines the API for the interacting
31   * with Document-related entries in the data dictionary. This is the default implementation that gets delivered with Kuali.
32   *
33   * @deprecated Only used by KNS classes, use KRAD.
34   */
35  @Deprecated
36  public class TransactionalDocumentDictionaryServiceImpl implements TransactionalDocumentDictionaryService {
37      private DataDictionaryService dataDictionaryService;
38  
39      /**
40       * @see org.kuali.rice.kns.service.TransactionalDocumentDictionaryService#getAllowsCopy(org.kuali.bo.TransactionalDocument)
41       */
42      public Boolean getAllowsCopy(TransactionalDocument document) {
43          Boolean allowsCopy = null;
44  
45          TransactionalDocumentEntry entry = getTransactionalDocumentEntry(document);
46          if (entry != null) {
47              allowsCopy = Boolean.valueOf(entry.getAllowsCopy());
48          }
49  
50          return allowsCopy;
51      }
52  
53      /**
54       * @see org.kuali.rice.kns.service.TransactionalDocumentDictionaryService#getDocumentClassByName(java.lang.String)
55       */
56      public Class getDocumentClassByName(String documentTypeName) {
57          Class documentClass = null;
58  
59          TransactionalDocumentEntry entry = getTransactionalDocumentEntryBydocumentTypeName(documentTypeName);
60          if (entry != null) {
61              documentClass = entry.getDocumentClass();
62          }
63  
64          return documentClass;
65      }
66  
67      /**
68       * @see org.kuali.rice.kns.service.TransactionalDocumentDictionaryService#getDescription(org.kuali.bo.TransactionalDocument)
69       */
70      public String getDescription(String transactionalDocumentTypeName) {
71          String description = null;
72  
73          DocumentType docType = getDocumentType(transactionalDocumentTypeName);
74          if (docType != null) {
75              description = docType.getDescription();
76          }
77  
78          return description;
79      }
80  
81      /**
82       * @see org.kuali.rice.kns.service.TransactionalDocumentDictionaryService#getDescription(org.kuali.bo.TransactionalDocument)
83       */
84      public String getLabel(String transactionalDocumentTypeName) {
85          String label = null;
86  
87          DocumentType docType = getDocumentType(transactionalDocumentTypeName);
88          if (docType != null) {
89              label = docType.getLabel();
90          }
91  
92          return label;
93      }
94  
95  
96      /**
97       * Sets the data dictionary instance.
98       * 
99       * @param dataDictionaryService
100      */
101     public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
102         this.dataDictionaryService = dataDictionaryService;
103     }
104 
105     /**
106      * Retrieves the data dictionary instance.
107      * 
108      * @return
109      */
110     public DataDictionary getDataDictionary() {
111         return this.dataDictionaryService.getDataDictionary();
112     }
113 
114     /**
115      * This method gets the workflow document type for the given documentTypeName
116      * 
117      * @param documentTypeName
118      * @return
119      */
120     protected DocumentType getDocumentType(String documentTypeName) {
121         return KewApiServiceLocator.getDocumentTypeService().getDocumentTypeByName(documentTypeName);
122     }
123 
124     /**
125      * Retrieves the document entry by transactional document class instance.
126      * 
127      * @param document
128      * @return TransactionalDocumentEntry
129      */
130     private TransactionalDocumentEntry getTransactionalDocumentEntry(TransactionalDocument document) {
131         if (document == null) {
132             throw new IllegalArgumentException("invalid (null) document");
133         }
134 
135         TransactionalDocumentEntry entry = (TransactionalDocumentEntry)getDataDictionary().getDocumentEntry(document.getClass().getName());
136 
137         return entry;
138     }
139 
140     /**
141      * Retrieves the document entry by transactional document type name.
142      * 
143      * @param documentTypeName
144      * @return
145      */
146     private TransactionalDocumentEntry getTransactionalDocumentEntryBydocumentTypeName(String documentTypeName) {
147         if (documentTypeName == null) {
148             throw new IllegalArgumentException("invalid (null) document type name");
149         }
150 
151         TransactionalDocumentEntry entry = (TransactionalDocumentEntry) getDataDictionary().getDocumentEntry(documentTypeName);
152 
153         return entry;
154     }
155 
156 	/**
157 	 * This overridden method ...
158 	 * 
159 	 * @see org.kuali.rice.kns.service.TransactionalDocumentDictionaryService#getDefaultExistenceChecks(java.lang.String)
160 	 */
161 	public Collection getDefaultExistenceChecks(String docTypeName) {
162         Collection defaultExistenceChecks = null;
163 
164         TransactionalDocumentEntry entry = getTransactionalDocumentEntryBydocumentTypeName(docTypeName);
165         if (entry != null) {
166             defaultExistenceChecks = entry.getDefaultExistenceChecks();
167         }
168 
169         return defaultExistenceChecks;
170 	}
171 
172 	/**
173 	 * This overridden method ...
174 	 * 
175 	 * @see org.kuali.rice.kns.service.TransactionalDocumentDictionaryService#getDefaultExistenceChecks(org.kuali.rice.krad.document.TransactionalDocument)
176 	 */
177 	public Collection getDefaultExistenceChecks(TransactionalDocument document) {
178 		return getDefaultExistenceChecks(getTransactionalDocumentEntry(document).getDocumentTypeName());
179 	}
180 }