1 | |
package org.kuali.student.core.subjectcode.document.validation.impl; |
2 | |
|
3 | |
import java.util.Collection; |
4 | |
import java.util.HashMap; |
5 | |
import java.util.Map; |
6 | |
|
7 | |
import org.kuali.rice.kns.document.MaintenanceDocument; |
8 | |
import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase; |
9 | |
import org.kuali.rice.kns.service.BusinessObjectService; |
10 | |
import org.kuali.rice.kns.service.KNSServiceLocator; |
11 | |
import org.kuali.student.core.subjectcode.bo.SubjectCode; |
12 | |
|
13 | 0 | public class SubjectCodeRule extends MaintenanceDocumentRuleBase{ |
14 | |
private BusinessObjectService businessObjectService; |
15 | |
|
16 | |
protected BusinessObjectService getBusinessObjectService() { |
17 | 0 | if (businessObjectService == null) { |
18 | 0 | businessObjectService = KNSServiceLocator.getBusinessObjectService(); |
19 | |
} |
20 | 0 | return businessObjectService; |
21 | |
} |
22 | |
@Override |
23 | |
protected boolean isDocumentValidForSave( |
24 | |
MaintenanceDocument maintenanceDocument) { |
25 | 0 | SubjectCode newSubjectCode = (SubjectCode) super.getNewBo(); |
26 | 0 | SubjectCode oldSubjectCode = (SubjectCode) super.getOldBo(); |
27 | 0 | if(newSubjectCode!=null && (oldSubjectCode==null||!newSubjectCode.getCode().equals(oldSubjectCode.getCode()))){ |
28 | 0 | Map fieldValues = new HashMap(); |
29 | 0 | fieldValues.put("code", newSubjectCode.getCode()); |
30 | 0 | Collection results = getBusinessObjectService().findMatching(SubjectCode.class, fieldValues); |
31 | 0 | if(results!=null&&results.size()>0){ |
32 | 0 | putFieldError("code", "error.duplicate.entry", "Subject Code"); |
33 | 0 | return false; |
34 | |
} |
35 | |
} |
36 | 0 | return super.isDocumentValidForSave(maintenanceDocument); |
37 | |
} |
38 | |
} |