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.uif.RemotableAttributeField;
019import org.kuali.rice.kns.inquiry.KualiInquirableImpl;
020import org.kuali.rice.krad.uif.container.Container;
021import org.kuali.rice.krad.uif.view.View;
022import org.kuali.rice.krad.web.form.InquiryForm;
023import org.kuali.rice.krms.impl.ui.AgendaEditor;
024import org.kuali.rice.krms.impl.util.KrmsRetriever;
025
026import java.util.Collections;
027import java.util.HashMap;
028import java.util.List;
029import java.util.Map;
030
031/**
032 * @author Kuali Rice Team (rice.collab@kuali.org)
033 */
034public class AgendaInquiryHelperServiceImpl extends KualiInquirableImpl {
035
036    private transient KrmsRetriever krmsRetriever = new KrmsRetriever();
037
038    @Override
039    public AgendaEditor retrieveDataObject(Map fieldValues) {
040        AgendaEditor agendaEditor = null;
041
042        Map<String, Object> primaryKeys = new HashMap<String, Object>();
043        primaryKeys.put("id", fieldValues.get("id"));
044//        String agendaId = (String) fieldValues.get("id");
045        AgendaBo agenda = getBusinessObjectService().findByPrimaryKey(AgendaBo.class, primaryKeys);
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     * @param model InquiryFrom to retrieve the AgendaEditor from.
060     * @return AgendaEditor retrieved from the given InquiryForm.
061     */
062    private AgendaEditor retrieveAgendaEditor(InquiryForm model) {
063        InquiryForm inquiryForm = (InquiryForm)model;
064        return (AgendaEditor)inquiryForm.getDataObject();
065    }
066
067    /**
068     * Returns the Agenda's RemotableAttributeFields
069     * @param view
070     * @param model InquiryFrom to retrieve the AgendaEditor from.
071     * @param container
072     * @return List<RemotableAttributeField>
073     */
074    public List<RemotableAttributeField> retrieveAgendaCustomAttributes(View view, Object model, Container container) {
075        AgendaEditor agendaEditor = retrieveAgendaEditor((InquiryForm) model);
076        return krmsRetriever.retrieveAgendaCustomAttributes(agendaEditor);
077    }
078
079    /**
080     * Returns the Rule Action RemotableAttributeFields. This only supports a single action within a rule.
081     * @param view
082     * @param model InquiryFrom to retrieve the AgendaEditor from.
083     * @param container
084     * @return List<RemotableAttributeField>
085     */
086    public List<RemotableAttributeField> retrieveRuleActionCustomAttributes(View view, Object model, Container container) {
087        AgendaEditor agendaEditor = retrieveAgendaEditor((InquiryForm)model);
088        return krmsRetriever.retrieveRuleActionCustomAttributes(agendaEditor);
089    }
090
091    /**
092     * Returns the Rule RemotableAttributeFields. This only supports a single action within a rule.
093     * @param view
094     * @param model InquiryFrom to retrieve the AgendaEditor from.
095     * @param container
096     * @return List<RemotableAttributeField>
097     */
098    public List<RemotableAttributeField> retrieveRuleCustomAttributes(View view, Object model, Container container) {
099        AgendaEditor agendaEditor = retrieveAgendaEditor((InquiryForm)model);
100        return krmsRetriever.retrieveRuleCustomAttributes(agendaEditor);
101    }
102
103
104    /**
105     * Retrieve a list of {@link RemotableAttributeField}s for the parameters (if any) required by the resolver for
106     * the selected term in the proposition that is under edit.  Since this method is part of the inquiry view,
107     * non of the propositions will ever be under edit when it is called, and an empty list will be returned.
108     * @param view
109     * @param model InquiryFrom to retrieve the AgendaEditor from.
110     * @param container
111     * @return List<RemotableAttributeField> Collections.emptyList()
112     */
113    public List<RemotableAttributeField> retrieveTermParameters(View view, Object model, Container container) {
114        return Collections.emptyList();
115    }
116}