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.uif.RemotableAttributeField;
019import org.kuali.rice.kns.inquiry.KualiInquirableImpl;
020import org.kuali.rice.krad.data.DataObjectService;
021import org.kuali.rice.krad.service.KRADServiceLocator;
022import org.kuali.rice.krad.uif.container.Container;
023import org.kuali.rice.krad.uif.view.View;
024import org.kuali.rice.krad.web.form.InquiryForm;
025import org.kuali.rice.krms.impl.ui.AgendaEditor;
026import org.kuali.rice.krms.impl.util.KrmsRetriever;
027
028import java.util.Collections;
029import java.util.List;
030import java.util.Map;
031
032/**
033 * @author Kuali Rice Team (rice.collab@kuali.org)
034 */
035public class AgendaInquiryHelperServiceImpl extends KualiInquirableImpl {
036
037    private transient KrmsRetriever krmsRetriever = new KrmsRetriever();
038
039    private DataObjectService dataObjectService;
040
041    @Override
042    public AgendaEditor retrieveDataObject(Map fieldValues) {
043        AgendaEditor agendaEditor = null;
044
045        AgendaBo agenda = getDataObjectService().find(AgendaBo.class, fieldValues.get("id"));
046        if (agenda != null) {
047            agendaEditor = new AgendaEditor();
048            agendaEditor.setAgenda(agenda);
049            agendaEditor.setNamespace(agenda.getContext().getNamespace());
050            agendaEditor.setContextName(agenda.getContext().getName());
051            agendaEditor.setCustomAttributesMap(agenda.getAttributes());
052        }
053
054        return agendaEditor;
055    }
056
057    /**
058     * Returns the AgendaEditor from the given InquiryForm
059     *
060     * @param model InquiryFrom to retrieve the AgendaEditor from.
061     * @return AgendaEditor retrieved from the given InquiryForm.
062     */
063    private AgendaEditor retrieveAgendaEditor(InquiryForm model) {
064        InquiryForm inquiryForm = (InquiryForm) model;
065        return (AgendaEditor) inquiryForm.getDataObject();
066    }
067
068    /**
069     * Returns the Agenda's RemotableAttributeFields
070     *
071     * @param view
072     * @param model InquiryFrom to retrieve the AgendaEditor from.
073     * @param container
074     * @return List<RemotableAttributeField>
075     */
076    public List<RemotableAttributeField> retrieveAgendaCustomAttributes(View view, Object model, Container container) {
077        AgendaEditor agendaEditor = retrieveAgendaEditor((InquiryForm) model);
078        return krmsRetriever.retrieveAgendaCustomAttributes(agendaEditor);
079    }
080
081    /**
082     * Returns the Rule Action RemotableAttributeFields. This only supports a single action within a rule.
083     *
084     * @param view
085     * @param model InquiryFrom to retrieve the AgendaEditor from.
086     * @param container
087     * @return List<RemotableAttributeField>
088     */
089    public List<RemotableAttributeField> retrieveRuleActionCustomAttributes(View view, Object model,
090            Container container) {
091        AgendaEditor agendaEditor = retrieveAgendaEditor((InquiryForm) model);
092        return krmsRetriever.retrieveRuleActionCustomAttributes(agendaEditor);
093    }
094
095    /**
096     * Returns the Rule RemotableAttributeFields. This only supports a single action within a rule.
097     *
098     * @param view
099     * @param model InquiryFrom to retrieve the AgendaEditor from.
100     * @param container
101     * @return List<RemotableAttributeField>
102     */
103    public List<RemotableAttributeField> retrieveRuleCustomAttributes(View view, Object model, Container container) {
104        AgendaEditor agendaEditor = retrieveAgendaEditor((InquiryForm) model);
105        return krmsRetriever.retrieveRuleCustomAttributes(agendaEditor);
106    }
107
108    /**
109     * Retrieve a list of {@link RemotableAttributeField}s for the parameters (if any) required by the resolver for
110     * the selected term in the proposition that is under edit.  Since this method is part of the inquiry view,
111     * non of the propositions will ever be under edit when it is called, and an empty list will be returned.
112     *
113     * @param view
114     * @param model InquiryFrom to retrieve the AgendaEditor from.
115     * @param container
116     * @return List<RemotableAttributeField> Collections.emptyList()
117     */
118    public List<RemotableAttributeField> retrieveTermParameters(View view, Object model, Container container) {
119        return Collections.emptyList();
120    }
121
122    public DataObjectService getDataObjectService() {
123        if (dataObjectService == null) {
124            return KRADServiceLocator.getDataObjectService();
125        }
126        return dataObjectService;
127    }
128
129    public void setDataObjectService(DataObjectService dataObjectService) {
130        this.dataObjectService = dataObjectService;
131    }
132
133}