View Javadoc
1   /*
2    * Copyright 2011 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.ole.select.document.validation.impl;
17  
18  import org.kuali.ole.select.OleSelectConstant;
19  import org.kuali.ole.select.businessobject.OleDefaultTableColumn;
20  import org.kuali.ole.select.constants.OleSelectPropertyConstants;
21  import org.kuali.ole.sys.context.SpringContext;
22  import org.kuali.rice.kns.document.MaintenanceDocument;
23  import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
24  import org.kuali.rice.krad.service.BusinessObjectService;
25  
26  import java.util.HashMap;
27  import java.util.List;
28  import java.util.Map;
29  
30  public class OleDefaultTableColumnRule extends MaintenanceDocumentRuleBase {
31  
32      @Override
33      protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
34  
35          boolean valid = processValidation(document);
36          return valid & super.processCustomRouteDocumentBusinessRules(document);
37      }
38  
39      private boolean processValidation(MaintenanceDocument document) {
40          boolean valid = true;
41          valid &= processDocumentTypeValidation(document);
42          return valid;
43      }
44  
45      private boolean processDocumentTypeValidation(MaintenanceDocument document) {
46          boolean valid = true;
47          OleDefaultTableColumn oleDefaultTableColumn = (OleDefaultTableColumn) document.getNewMaintainableObject().getBusinessObject();
48          String documentTypeId = oleDefaultTableColumn.getDocumentTypeId();
49          Map<String, Object> documentTypes = new HashMap<String, Object>();
50          documentTypes.put("documentTypeId", documentTypeId);
51          List<OleDefaultTableColumn> documentTypeList = (List) SpringContext.getBean(BusinessObjectService.class).findMatching(OleDefaultTableColumn.class, documentTypes);
52          if (documentTypeList.size() > 0) {
53              for (int i = 0; i < documentTypeList.size(); i++) {
54                  if (documentTypeList.get(i).getDocumentTypeId().toString().equalsIgnoreCase(oleDefaultTableColumn.getDocumentTypeId().toString()) && documentTypeList.get(i).getDocumentColumn().equalsIgnoreCase(oleDefaultTableColumn.getDocumentColumn())) {
55                      valid = false;
56                      putFieldError(OleSelectConstant.DEFAULT_TABLE_COLUMN_DOCUMENTTYPE, OleSelectPropertyConstants.ERROR_DOCUMENTTYPE_EXIST);
57                  }
58              }
59          }
60          return valid;
61      }
62  }