001/** 002 * Copyright 2005-2017 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.uif.control.UifKeyValuesFinderBase; 021import org.kuali.rice.krad.uif.view.ViewModel; 022import org.kuali.rice.krad.web.form.InquiryForm; 023import org.kuali.rice.krad.web.form.MaintenanceDocumentForm; 024import org.kuali.rice.krms.api.repository.type.KrmsTypeRepositoryService; 025import org.kuali.rice.krms.api.repository.typerelation.TypeTypeRelation; 026import org.kuali.rice.krms.impl.ui.AgendaEditor; 027 028import java.util.ArrayList; 029import java.util.Collection; 030import java.util.List; 031 032/** 033 * Helper class that returns all agenda types that are valid for a given context. 034 */ 035public class PropositionTypeValuesFinder extends UifKeyValuesFinderBase { 036 037 @Override 038 public List<KeyValue> getKeyValues(ViewModel model) { 039 List<KeyValue> keyValues = new ArrayList<KeyValue>(); 040 041 AgendaEditor agendaEditor; 042 if (model instanceof InquiryForm) { 043 InquiryForm inquiryForm = (InquiryForm) model; 044 agendaEditor = ((AgendaEditor) inquiryForm.getDataObject()); 045 046 } else { 047 MaintenanceDocumentForm maintenanceForm = (MaintenanceDocumentForm) model; 048 agendaEditor = ((AgendaEditor) maintenanceForm.getDocument().getNewMaintainableObject().getDataObject()); 049 } 050 051 RuleBo rule = agendaEditor.getAgendaItemLine().getRule(); 052 053 // if we have an agenda w/ a selected context 054 Collection<TypeTypeRelation> typeRelations = getTypeTypeRelationBoService().findTypeTypeRelationsByFromType(rule.getTypeId()); 055 for (TypeTypeRelation typeRelation : typeRelations) { 056 keyValues.add(new ConcreteKeyValue(typeRelation.getToTypeId(), getKrmsTypeRepositoryService().getTypeById(typeRelation.getToTypeId()).getName())); 057 } 058 059 return keyValues; 060 } 061 062 public KrmsTypeRepositoryService getKrmsTypeRepositoryService() { 063 return KrmsRepositoryServiceLocator.getKrmsTypeRepositoryService(); 064 } 065 066 public TypeTypeRelationBoService getTypeTypeRelationBoService() { 067 return KrmsRepositoryServiceLocator.getTypeTypeRelationBoService(); 068 } 069 070}