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.kew.rule.bo;
017
018import org.kuali.rice.core.api.config.property.ConfigContext;
019import org.kuali.rice.kew.rule.RuleBaseValues;
020import org.kuali.rice.kew.rule.web.WebRuleUtils;
021import org.kuali.rice.kew.api.KewApiConstants;
022import org.kuali.rice.kns.inquiry.KualiInquirableImpl;
023import org.kuali.rice.kns.lookup.HtmlData;
024import org.kuali.rice.kns.web.ui.Section;
025import org.kuali.rice.krad.bo.BusinessObject;
026
027import java.util.List;
028import java.util.Map;
029
030/**
031 * Inquirable implementation for KEW routing rules.
032 * 
033 * @author Kuali Rice Team (rice.collab@kuali.org)
034 *
035 */
036public class RuleBaseValuesInquirableImpl extends KualiInquirableImpl {
037
038        public static final String DOCUMENT_ID = "documentId";
039
040        @Override
041        public Object retrieveDataObject(Map fieldValues){
042                RuleBaseValues rule = (RuleBaseValues)super.retrieveDataObject(fieldValues);
043                WebRuleUtils.populateRuleMaintenanceFields(rule);
044                return rule;
045    }
046        
047        /**
048         * This overridden method ...
049         * 
050         * @see org.kuali.rice.krad.inquiry.Inquirable#getBusinessObject(java.util.Map)
051         */
052        public BusinessObject getBusinessObject(Map fieldValues) {
053                RuleBaseValues rule = (RuleBaseValues)super.getBusinessObject(fieldValues);
054                WebRuleUtils.populateRuleMaintenanceFields(rule);
055                return rule;
056        }
057
058        /**
059         * This overridden method ...
060         * 
061         * @see org.kuali.rice.krad.inquiry.Inquirable#getSections(org.kuali.rice.krad.bo.BusinessObject)
062         */
063        public List<Section> getSections(BusinessObject bo) {
064                List<Section> sections = super.getSections(bo);
065
066                return WebRuleUtils.customizeSections((RuleBaseValues)bo, sections, false);
067
068        }
069        
070
071    @Override
072    public HtmlData getInquiryUrl(BusinessObject businessObject, String attributeName, boolean forceInquiry) {
073        
074                if(DOCUMENT_ID.equals(attributeName)) {
075
076                        HtmlData.AnchorHtmlData link = new HtmlData.AnchorHtmlData();
077                        RuleBaseValues rule = (RuleBaseValues)businessObject;
078
079                        String documentId = rule.getDocumentId();
080                        link.setDisplayText(documentId+"");
081
082                        String href = ConfigContext.getCurrentContextConfig().getKEWBaseURL() + "/" +
083                        KewApiConstants.DOC_HANDLER_REDIRECT_PAGE + "?" + KewApiConstants.COMMAND_PARAMETER + "=" +
084                        KewApiConstants.DOCSEARCH_COMMAND + "&" + KewApiConstants.DOCUMENT_ID_PARAMETER + "=" + documentId;
085
086                        link.setHref(href);
087
088                        return link;
089                }               
090        return super.getInquiryUrl(businessObject, attributeName, forceInquiry);
091    }
092
093}