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.context.ContextDefinition; |
22 | |
import org.kuali.rice.krms.impl.repository.ContextBo; |
23 | |
import org.kuali.rice.krms.impl.repository.ContextBoService; |
24 | |
import org.kuali.rice.krms.impl.repository.KrmsRepositoryServiceLocator; |
25 | |
import org.kuali.rice.krms.impl.util.KRMSPropertyConstants; |
26 | |
|
27 | 0 | public class ContextBusRule extends MaintenanceDocumentRuleBase { |
28 | |
@Override |
29 | |
protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) { |
30 | 0 | boolean isValid = true; |
31 | |
|
32 | 0 | ContextBo context = (ContextBo) document.getNewMaintainableObject().getDataObject(); |
33 | 0 | isValid &= validateId(context); |
34 | 0 | isValid &= validateNameNamespace(context); |
35 | |
|
36 | 0 | return isValid; |
37 | |
} |
38 | |
|
39 | |
private boolean validateId(ContextBo context) { |
40 | 0 | if (StringUtils.isNotBlank(context.getId())) { |
41 | 0 | ContextDefinition contextInDatabase = getContextBoService().getContextByContextId(context.getId()); |
42 | 0 | if ((contextInDatabase != null) && (!StringUtils.equals(contextInDatabase.getId(), context.getId()))) { |
43 | 0 | this.putFieldError(KRMSPropertyConstants.Context.CONTEXT_ID, "error.context.duplicateId"); |
44 | 0 | return false; |
45 | |
} |
46 | |
} |
47 | |
|
48 | 0 | return true; |
49 | |
} |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
private boolean validateNameNamespace(ContextBo context) { |
57 | 0 | if (StringUtils.isNotBlank(context.getName()) && StringUtils.isNotBlank(context.getNamespace())) { |
58 | 0 | ContextDefinition contextInDatabase = getContextBoService().getContextByNameAndNamespace(context.getName(), context.getNamespace()); |
59 | 0 | if((contextInDatabase != null) && (!StringUtils.equals(contextInDatabase.getId(), context.getId()))) { |
60 | 0 | this.putFieldError(KRMSPropertyConstants.Context.NAME, "error.context.duplicateNameNamespace"); |
61 | 0 | return false; |
62 | |
} |
63 | |
} |
64 | |
|
65 | 0 | return true; |
66 | |
} |
67 | |
|
68 | |
public ContextBoService getContextBoService() { |
69 | 0 | return KrmsRepositoryServiceLocator.getContextBoService(); |
70 | |
} |
71 | |
} |