001package org.kuali.ole.deliver.rule;
002
003import org.apache.log4j.Logger;
004import org.kuali.ole.OLEConstants;
005import org.kuali.ole.deliver.bo.CopyFormat;
006import org.kuali.rice.krad.maintenance.MaintenanceDocument;
007import org.kuali.rice.krad.rules.MaintenanceDocumentRuleBase;
008import org.kuali.rice.krad.service.BusinessObjectService;
009import org.kuali.rice.krad.service.KRADServiceLocator;
010import org.kuali.rice.krad.util.GlobalVariables;
011
012import java.util.HashMap;
013import java.util.List;
014import java.util.Map;
015
016
017/**
018 * Created with IntelliJ IDEA.
019 * User: anithaa
020 * Date: 2/14/14
021 * Time: 12:29 PM
022 * To change this template use File | Settings | File Templates.
023 */
024public class OleCopyFormatRule extends MaintenanceDocumentRuleBase {
025
026    private static final Logger LOG = Logger.getLogger(OleBatchJobRule.class);
027
028    @Override
029    protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
030        boolean isValid = true;
031        CopyFormat copyformat = (CopyFormat) document.getNewMaintainableObject().getDataObject();
032        CopyFormat oldCopyformat = (CopyFormat) document.getOldMaintainableObject().getDataObject();
033        boolean processed = super.processCustomSaveDocumentBusinessRules(document);
034        Map<String, String> copyFormatMap = new HashMap<String, String>();
035        BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService();
036        copyFormatMap.put("code", copyformat.getCode());
037        List<CopyFormat> copyFormatList = (List<CopyFormat>) businessObjectService.findMatching(CopyFormat.class, copyFormatMap);
038        if ((copyFormatList.size()> 0)&& copyFormatList!=null ) {
039         if(copyformat.getCode().equalsIgnoreCase(oldCopyformat.getCode())) {
040            if(copyformat.getCopyFormatId()!=null){
041
042            }
043            else {
044                isValid = false;
045                GlobalVariables.getMessageMap().putError(OLEConstants.OleCirculationDesk.OLE_COPY_FORMAT_CODE, OLEConstants.OleCirculationDesk.OLE_COPY_FORMAT_CODE_ERROR);
046
047            }
048        }
049        else {
050            if (!copyformat.getCode().equalsIgnoreCase(oldCopyformat.getCode())) {
051                isValid = false;
052                GlobalVariables.getMessageMap().putError(OLEConstants.OleCirculationDesk.OLE_COPY_FORMAT_CODE, OLEConstants.OleCirculationDesk.OLE_COPY_FORMAT_CODE_ERROR);
053
054            }
055
056        }
057
058        }
059        return isValid;
060    }
061
062}