001package org.kuali.ole.select.businessobject.options;
002
003import org.kuali.ole.OLEConstants;
004import org.kuali.ole.describe.bo.OleItemAvailableStatus;
005import org.kuali.rice.core.api.util.ConcreteKeyValue;
006import org.kuali.rice.core.api.util.KeyValue;
007import org.kuali.rice.coreservice.api.CoreServiceApiServiceLocator;
008import org.kuali.rice.coreservice.api.parameter.Parameter;
009import org.kuali.rice.coreservice.api.parameter.ParameterKey;
010import org.kuali.rice.krad.keyvalues.KeyValuesBase;
011import org.kuali.rice.krad.service.KRADServiceLocator;
012
013import java.util.*;
014
015/**
016 * ItemStatus used to render the values for ItemStatus dropdown control.
017 */
018public class OleItemStatusKeyValuesFinder extends KeyValuesBase {
019    /**
020     * This method returns the List of  ConcreteKeyValue,
021     * ConcreteKeyValue has two arguments itemAvailableStatusCode and
022     * itemAvailableStatusName.
023     * @return   List<KeyValue>
024     */
025    @Override
026    public List<KeyValue> getKeyValues() {
027
028        List<KeyValue> options = new ArrayList<KeyValue>();
029        Collection<OleItemAvailableStatus> oleItemAvailableStatuses = KRADServiceLocator.getBusinessObjectService().findAll(OleItemAvailableStatus.class);
030        options.add(new ConcreteKeyValue("", ""));
031        String excludeItemStatus = getParameter(OLEConstants.EXCLUDE_ITEM_STATUS);
032        Map<String,String> map = new HashMap<>();
033        if(excludeItemStatus!=null && !excludeItemStatus.isEmpty()){
034            String[] itemStatusList = excludeItemStatus.split(",");
035            for(String itemStatus : itemStatusList){
036                map.put(itemStatus,itemStatus);
037            }
038        }
039        for (OleItemAvailableStatus type : oleItemAvailableStatuses) {
040            if (type.isActive() && !map.containsKey(type.getItemAvailableStatusCode())) {
041                options.add(new ConcreteKeyValue(type.getItemAvailableStatusCode(), type.getItemAvailableStatusName()));
042            }
043        }
044        return options;
045    }
046
047    public String getParameter(String name){
048        ParameterKey parameterKey = ParameterKey.create(OLEConstants.APPL_ID, OLEConstants.SELECT_NMSPC, OLEConstants.SELECT_CMPNT,name);
049        Parameter parameter = CoreServiceApiServiceLocator.getParameterRepositoryService().getParameter(parameterKey);
050        return parameter!=null?parameter.getValue():null;
051    }
052}