1 package org.kuali.ole.describe.rule;
2
3 import org.kuali.ole.OLEConstants;
4 import org.kuali.ole.describe.bo.OleShelvingScheme;
5 import org.kuali.ole.describe.bo.ExternalDataSourceConfig;
6 import org.kuali.rice.krad.maintenance.MaintenanceDocument;
7 import org.kuali.rice.krad.rules.MaintenanceDocumentRuleBase;
8
9 import java.util.HashMap;
10 import java.util.List;
11 import java.util.Map;
12
13
14
15
16
17
18
19
20 public class OleExternalDatSourceConfigRule
21 extends MaintenanceDocumentRuleBase {
22
23
24 protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
25 boolean isValid = true;
26 ExternalDataSourceConfig externalDataSourceConfig = (ExternalDataSourceConfig) document
27 .getNewMaintainableObject().getDataObject();
28
29 isValid &= validateDuplicateDataSourceName(externalDataSourceConfig);
30 isValid &= validateEmptyDataSourceName(externalDataSourceConfig);
31 return isValid;
32 }
33
34
35
36
37
38
39
40 private boolean validateDuplicateDataSourceName(ExternalDataSourceConfig externalDataSourceConfig) {
41
42 if (externalDataSourceConfig.getName() != null) {
43 Map<String, String> criteria = new HashMap<String, String>();
44 criteria.put(OLEConstants.OleExternalDataSourceConfig.DATA_SOURCE_NM, externalDataSourceConfig.getName());
45 List<ExternalDataSourceConfig> dataSourceNameInDatabase = (List<ExternalDataSourceConfig>) getBoService()
46 .findMatching(ExternalDataSourceConfig.class, criteria);
47
48 if ((dataSourceNameInDatabase.size() > 0)) {
49 for (ExternalDataSourceConfig dataSourceObj : dataSourceNameInDatabase) {
50 Integer dataSourceId = dataSourceObj.getId();
51 if (null == externalDataSourceConfig.getId() || (externalDataSourceConfig.getId().intValue()
52 != dataSourceId.intValue())) {
53 this.putFieldError(OLEConstants.OleExternalDataSourceConfig.DATA_SOURCE_NAME,
54 "error.duplicate.name");
55 return false;
56 }
57
58 }
59 }
60
61 }
62 return true;
63 }
64
65
66
67
68
69
70
71
72 private boolean validateEmptyDataSourceName(ExternalDataSourceConfig externalDataSourceConfig) {
73
74 if (externalDataSourceConfig.getName() == null || externalDataSourceConfig.getName().equalsIgnoreCase("")
75 || externalDataSourceConfig.getName().length() == 0) {
76 this.putFieldError(OLEConstants.OleExternalDataSourceConfig.DATA_SOURCE_NAME, "error.empty.name");
77 return false;
78 }
79 return true;
80 }
81 }