1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 }