CostLineRepositoryImpl.java

package com.tradecloud.repository.impl;

import java.util.List;
import org.apache.log4j.Logger;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.tradecloud.domain.common.Currency;
import com.tradecloud.domain.costing.*;
import com.tradecloud.repository.CostLineRepository;
import com.tradecloud.repository.base.impl.RepositoryBaseImpl;

/**
 *
 */
@Repository(value = "costLineRepository")
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT)
public class CostLineRepositoryImpl extends RepositoryBaseImpl<CostLine, Object> implements CostLineRepository {

    private static final long serialVersionUID = 1L;

    private static final Logger log = Logger.getLogger(CostLineRepositoryImpl.class);

    @Override
    public List<CostLine> findAll() {
        return super.findAll();
    }

    /***
     * @deprecated costline is unique within Cost definition.
     * @param template
     * @param payerType
     * @param transactionCurrency
     * @param costAllocationMethod
     * @return
     */
    @Deprecated
    @Override
    public CostLine findCostLine(CostLineTemplate template, CostLinePayerType payerType, Currency transactionCurrency,
                                 CostAllocationMethod costAllocationMethod) {
        Criteria searchCriteria = getSessionCustom().createCriteria(CostLine.class);
        searchCriteria.add(Restrictions.like("costLineTemplate", template));
        searchCriteria.add(Restrictions.like("costLinePayerType", payerType));
        if (transactionCurrency != null) {
            searchCriteria.add(Restrictions.eq("transactionCurrency", transactionCurrency));
        }
        searchCriteria.add(Restrictions.eq("costAllocationMethod", costAllocationMethod));
        List list = searchCriteria.list();
        if(list.isEmpty()){
            return null;
        }else{
            return (CostLine) list.get(0);
        }

    }

    @Override
    public CostLine findCostLine(CostLineTemplate costLineTemplate, CostAllocationMethod costAllocationMethod) {
        Criteria searchCriteria = getSessionCustom().createCriteria(CostLine.class);
        searchCriteria.add(Restrictions.like("costLineTemplate", costLineTemplate));
        searchCriteria.add(Restrictions.eq("costAllocationMethod", costAllocationMethod));
        List list = searchCriteria.list();
        if(list.isEmpty()){
            return null;
        }else{
            return (CostLine) list.get(0);
        }
    }

    /**
     * NOT CURRENTLY FUNCTIONAL!
     * @param costable
     * @param costLineTemplateCode
     * @return
     */
    @Override
    public CostAllocationMethod findCostAllocationMethod(Costable costable, String costLineTemplateCode) {
        List<CostLine> costLines = (List<CostLine>) findByNamedQueryAndNamedParam("cosatbleCostDefinition.costLine.costAllocation",
                new String[]{"code", "costable"}, new Object[]{costLineTemplateCode, costable});

        return costLines.get(0).getCostAllocationMethod();
    }
}