001package org.kuali.ole.batch.keyvalue;
002
003import org.kuali.ole.OLEConstants;
004import org.kuali.ole.describe.bo.OleLocation;
005import org.kuali.rice.core.api.util.ConcreteKeyValue;
006import org.kuali.rice.core.api.util.KeyValue;
007import org.kuali.rice.krad.keyvalues.KeyValuesBase;
008import org.kuali.rice.krad.service.KRADServiceLocator;
009
010import java.util.ArrayList;
011import java.util.Collection;
012import java.util.List;
013
014/**
015 * Created with IntelliJ IDEA.
016 * User: rajeshbabuk
017 * Date: 3/15/14
018 * Time: 5:08 PM
019 * To change this template use File | Settings | File Templates.
020 */
021public class OLEBatchConstantsLocationLevel1KeyValues extends KeyValuesBase {
022    @Override
023    public List<KeyValue> getKeyValues() {
024        List<KeyValue> keyValues = new ArrayList<KeyValue>();
025        keyValues = getLocationsByLocationLevel(OLEConstants.OLEBatchProcess.LOCATION_LEVEL_INSTITUTION);
026        return keyValues;
027    }
028
029    private List<KeyValue> getLocationsByLocationLevel(String locationLevel) {
030        List<KeyValue> keyValues = new ArrayList<KeyValue>();
031        Collection<OleLocation> oleLocations = KRADServiceLocator.getBusinessObjectService().findAll(OleLocation.class);
032        for (OleLocation oleLocation : oleLocations) {
033            if (locationLevel.equalsIgnoreCase(oleLocation.getLevelCode()))
034                keyValues.add(new ConcreteKeyValue(oleLocation.getLocationCode(), oleLocation.getLocationCode()));
035        }
036        return keyValues;
037    }
038}