/*
 * Copyright 2008 The Kuali Foundation.
 * 
 * Licensed under the Educational Community License, Version 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.opensource.org/licenses/ecl1.php
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.kuali.kfs.lookup;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.apache.ojb.broker.query.Criteria;
import org.kuali.core.bo.PersistableBusinessObject;
import org.kuali.core.dao.LookupDao;
import org.kuali.core.lookup.AbstractLookupableHelperServiceImpl;
import org.kuali.core.lookup.CollectionIncomplete;
import org.kuali.kfs.bo.ElectronicPaymentClaim;
import org.springframework.transaction.annotation.Transactional;

/**
 * A helper class that gives us the ability to do special lookups on electronic payment claims.
 */
@Transactional
public class ElectronicPaymentClaimLookupableHelperServiceImpl extends AbstractLookupableHelperServiceImpl {
    private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ElectronicPaymentClaimLookupableHelperServiceImpl.class);
    private LookupDao lookupDao;
    
    /**
     * 
     * @see org.kuali.core.lookup.AbstractLookupableHelperServiceImpl#getSearchResults(java.util.Map)
     */
    @Override
    public List<PersistableBusinessObject> getSearchResults(Map<String, String> fieldValues) {
        boolean unbounded = false;
        String claimingStatus = fieldValues.remove("paymentClaimStatusCode");
        Criteria additionalCriteria = new Criteria();
        if (claimingStatus != null && !claimingStatus.equals("A")) {
            if (claimingStatus.equals(ElectronicPaymentClaim.ClaimStatusCodes.CLAIMED)) {
                additionalCriteria.addEqualTo("paymentClaimStatusCode", ElectronicPaymentClaim.ClaimStatusCodes.CLAIMED);
            } else {
                additionalCriteria.addEqualTo("paymentClaimStatusCode", ElectronicPaymentClaim.ClaimStatusCodes.UNCLAIMED);
            }
        }
        return (List)lookupDao.findCollectionBySearchHelper(ElectronicPaymentClaim.class, fieldValues, unbounded, false, additionalCriteria);
    }

    /**
     * @see org.kuali.core.lookup.AbstractLookupableHelperServiceImpl#validateSearchParameters(java.util.Map)
     */
    @Override
    public void validateSearchParameters(Map fieldValues) {
        // grab the backLocation and the docFormKey
        this.setDocFormKey((String)fieldValues.get("docFormKey"));
        this.setBackLocation((String)fieldValues.get("backLocation"));
        super.validateSearchParameters(fieldValues);
    }

    /**
     * Sets the lookupDao attribute value.
     * @param lookupDao The lookupDao to set.
     */
    public void setLookupDao(LookupDao lookupDao) {
        this.lookupDao = lookupDao;
    }

}

@@ -665,13 +665,8 @@
 til.
-Array
 List
@@ -688,65 +688,57 @@
 til.
-Collection
+Map
 ;%0A
+%0A
 import 
-java.util.List;%0Aimport java.util.Map;%0A
+org.apache.commons.lang.StringUtils;
 %0Aimp
@@ -779,16 +779,57 @@
 iteria;%0A
+import org.kuali.core.bo.BusinessObject;%0A
 import o
@@ -979,59 +979,8 @@
 pl;%0A
-import org.kuali.core.lookup.CollectionIncomplete;%0A
 impo
@@ -1848,62 +1848,8 @@
 %22);%0A
-        Criteria additionalCriteria = new Criteria();%0A
     
@@ -2023,37 +2023,23 @@
     
-additionalCriteria.addEqualTo
+fieldValues.put
 (%22pa
@@ -2152,37 +2152,23 @@
     
-additionalCriteria.addEqualTo
+fieldValues.put
 (%22pa
@@ -2391,26 +2391,20 @@
 se, 
-additional
+new 
 Criteria
 );%0A 
@@ -2399,16 +2399,18 @@
 Criteria
+()
 );%0A    %7D
@@ -2853,32 +2853,690 @@
 Values);%0A    %7D%0A%0A
+    /**%0A     * @see org.kuali.core.lookup.AbstractLookupableHelperServiceImpl#isResultReturnable(org.kuali.core.bo.BusinessObject)%0A     */%0A    @Override%0A    public boolean isResultReturnable(BusinessObject claimAsBO) %7B%0A        boolean result = super.isResultReturnable(claimAsBO);%0A        ElectronicPaymentClaim claim = (ElectronicPaymentClaim)claimAsBO;%0A        if (result && ((claim.getPaymentClaimStatusCode() != null && claim.getPaymentClaimStatusCode().equals(ElectronicPaymentClaim.ClaimStatusCodes.CLAIMED)) %7C%7C (!StringUtils.isBlank(claim.getReferenceFinancialDocumentNumber())))) %7B%0A            result = false;%0A        %7D%0A        return result;%0A    %7D%0A%0A
     /**%0A     * S

Make claimed EFT records un-returnable