001/**
002 * Copyright 2005-2016 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.krms.impl.repository;
017
018import org.kuali.rice.core.api.util.ConcreteKeyValue;
019import org.kuali.rice.core.api.util.KeyValue;
020import org.kuali.rice.krad.service.KRADServiceLocator;
021import org.kuali.rice.krad.service.KeyValuesService;
022import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase;
023import org.kuali.rice.krad.uif.view.ViewModel;
024
025import java.util.ArrayList;
026import java.util.Collection;
027import java.util.HashMap;
028import java.util.List;
029import java.util.Map;
030
031/**
032 * Helper class that returns all valid types for contexts.
033 */
034public class ContextTypeValuesFinder extends UifKeyValuesFinderBase {
035
036    private boolean blankOption;
037
038    /**
039     * @return the blankOption
040     */
041    public boolean isBlankOption() {
042        return this.blankOption;
043    }
044
045    /**
046     * @param blankOption the blankOption to set
047     */
048    public void setBlankOption(boolean blankOption) {
049        this.blankOption = blankOption;
050    }
051
052    @Override
053    public List<KeyValue> getKeyValues(ViewModel model) {
054        List<KeyValue> keyValues = new ArrayList<KeyValue>();
055
056        if(blankOption){
057            keyValues.add(new ConcreteKeyValue("", ""));
058        }
059
060        // ToDo: Currently we hardcoded any types named "CONTEXT" to be valid with contexts.
061        KeyValuesService boService = KRADServiceLocator.getKeyValuesService();
062        Map<String,Object> fieldValues = new HashMap<String, Object>();
063        fieldValues.put("name", "CONTEXT");
064        Collection<KrmsTypeBo> types = boService.findMatching(KrmsTypeBo.class, fieldValues);
065
066        for (KrmsTypeBo type : types) {
067            keyValues.add(new ConcreteKeyValue(type.getId(), type.getName() + " [" + type.getNamespace() + "]"));
068        }
069
070        return keyValues;
071    }
072}