1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.krms.impl.rule; |
17 | |
|
18 | |
import org.apache.commons.lang.StringUtils; |
19 | |
import org.kuali.rice.krad.document.MaintenanceDocument; |
20 | |
import org.kuali.rice.krad.rules.MaintenanceDocumentRuleBase; |
21 | |
import org.kuali.rice.krms.api.repository.term.TermSpecificationDefinition; |
22 | |
import org.kuali.rice.krms.impl.repository.KrmsRepositoryServiceLocator; |
23 | |
import org.kuali.rice.krms.impl.repository.TermBoService; |
24 | |
import org.kuali.rice.krms.impl.repository.TermSpecificationBo; |
25 | |
import org.kuali.rice.krms.impl.util.KRMSPropertyConstants; |
26 | |
|
27 | |
import java.util.HashMap; |
28 | |
import java.util.Map; |
29 | |
|
30 | 0 | public class TermSpecBusRule extends MaintenanceDocumentRuleBase { |
31 | |
|
32 | |
@Override |
33 | |
protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) { |
34 | 0 | boolean isValid = true; |
35 | |
|
36 | 0 | TermSpecificationBo termSpec = (TermSpecificationBo) document.getNewMaintainableObject().getDataObject(); |
37 | 0 | isValid &= validateId(termSpec); |
38 | 0 | isValid &= validateNameNamespace(termSpec); |
39 | |
|
40 | 0 | return isValid; |
41 | |
} |
42 | |
|
43 | |
private boolean validateId(TermSpecificationBo termSpec) { |
44 | 0 | if (StringUtils.isNotBlank(termSpec.getId())) { |
45 | 0 | TermSpecificationDefinition termSpecInDatabase = getTermBoService().getTermSpecificationById(termSpec.getId()); |
46 | 0 | if ((termSpecInDatabase != null) && (!StringUtils.equals(termSpecInDatabase.getId(), termSpec.getId()))) { |
47 | 0 | this.putFieldError(KRMSPropertyConstants.TermSpecification.TERM_SPECIFICATION_ID, "error.termSpecification.duplicateId"); |
48 | 0 | return false; |
49 | |
} |
50 | |
} |
51 | |
|
52 | 0 | return true; |
53 | |
} |
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
private boolean validateNameNamespace(TermSpecificationBo termSpec) { |
61 | 0 | if (StringUtils.isNotBlank(termSpec.getName()) && StringUtils.isNotBlank( |
62 | |
termSpec.getNamespace())) { |
63 | |
|
64 | 0 | Map<String, String> criteria = new HashMap<String, String>(); |
65 | |
|
66 | 0 | criteria.put("name", termSpec.getName()); |
67 | 0 | criteria.put("namespace", termSpec.getNamespace()); |
68 | |
|
69 | 0 | TermSpecificationBo termSpecInDatabase = getBoService().findByPrimaryKey(TermSpecificationBo.class, criteria); |
70 | |
|
71 | 0 | if((termSpecInDatabase != null) && (!StringUtils.equals(termSpecInDatabase.getId(), termSpec.getId()))) { |
72 | 0 | this.putFieldError(KRMSPropertyConstants.TermSpecification.NAME, "error.term.duplicateNameNamespace"); |
73 | 0 | return false; |
74 | |
} |
75 | |
} |
76 | |
|
77 | 0 | return true; |
78 | |
} |
79 | |
|
80 | |
public TermBoService getTermBoService() { |
81 | 0 | return KrmsRepositoryServiceLocator.getTermBoService(); |
82 | |
} |
83 | |
|
84 | |
} |