View Javadoc
1   package org.kuali.ole.deliver.rule;
2   
3   import org.apache.log4j.Logger;
4   import org.kuali.ole.OLEConstants;
5   import org.kuali.ole.deliver.bo.CopyFormat;
6   import org.kuali.rice.krad.maintenance.MaintenanceDocument;
7   import org.kuali.rice.krad.rules.MaintenanceDocumentRuleBase;
8   import org.kuali.rice.krad.service.BusinessObjectService;
9   import org.kuali.rice.krad.service.KRADServiceLocator;
10  import org.kuali.rice.krad.util.GlobalVariables;
11  
12  import java.util.HashMap;
13  import java.util.List;
14  import java.util.Map;
15  
16  
17  /**
18   * Created with IntelliJ IDEA.
19   * User: anithaa
20   * Date: 2/14/14
21   * Time: 12:29 PM
22   * To change this template use File | Settings | File Templates.
23   */
24  public class OleCopyFormatRule extends MaintenanceDocumentRuleBase {
25  
26      private static final Logger LOG = Logger.getLogger(OleBatchJobRule.class);
27  
28      @Override
29      protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
30          boolean isValid = true;
31          CopyFormat copyformat = (CopyFormat) document.getNewMaintainableObject().getDataObject();
32          CopyFormat oldCopyformat = (CopyFormat) document.getOldMaintainableObject().getDataObject();
33          boolean processed = super.processCustomSaveDocumentBusinessRules(document);
34          Map<String, String> copyFormatMap = new HashMap<String, String>();
35          BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService();
36          copyFormatMap.put("code", copyformat.getCode());
37          List<CopyFormat> copyFormatList = (List<CopyFormat>) businessObjectService.findMatching(CopyFormat.class, copyFormatMap);
38          if ((copyFormatList.size()> 0)&& copyFormatList!=null ) {
39           if(copyformat.getCode().equalsIgnoreCase(oldCopyformat.getCode())) {
40              if(copyformat.getCopyFormatId()!=null){
41  
42              }
43              else {
44                  isValid = false;
45                  GlobalVariables.getMessageMap().putError(OLEConstants.OleCirculationDesk.OLE_COPY_FORMAT_CODE, OLEConstants.OleCirculationDesk.OLE_COPY_FORMAT_CODE_ERROR);
46  
47              }
48          }
49          else {
50              if (!copyformat.getCode().equalsIgnoreCase(oldCopyformat.getCode())) {
51                  isValid = false;
52                  GlobalVariables.getMessageMap().putError(OLEConstants.OleCirculationDesk.OLE_COPY_FORMAT_CODE, OLEConstants.OleCirculationDesk.OLE_COPY_FORMAT_CODE_ERROR);
53  
54              }
55  
56          }
57  
58          }
59          return isValid;
60      }
61  
62  }