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.krad.uif.service.impl;
017
018import java.util.HashMap;
019import java.util.Map;
020
021import org.kuali.rice.krad.uif.UifConstants;
022import org.kuali.rice.krad.uif.UifConstants.ViewType;
023import org.kuali.rice.krad.uif.UifParameters;
024import org.kuali.rice.krad.uif.util.ViewModelUtils;
025import org.kuali.rice.krad.uif.service.ViewTypeService;
026import org.springframework.beans.PropertyValues;
027
028/**
029 * Type service implementation for Lookup views
030 * 
031 * @author Kuali Rice Team (rice.collab@kuali.org)
032 */
033public class LookupViewTypeServiceImpl implements ViewTypeService {
034
035        /**
036         * @see org.kuali.rice.krad.uif.service.ViewTypeService#getViewTypeName()
037         */
038    @Override
039        public ViewType getViewTypeName() {
040                return ViewType.LOOKUP;
041        }
042        
043    /**
044     * @see org.kuali.rice.krad.uif.service.ViewTypeService#getParametersFromViewConfiguration(org.springframework.beans.PropertyValues)
045     */
046    @Override
047    public Map<String, String> getParametersFromViewConfiguration(PropertyValues propertyValues) {
048        Map<String, String> parameters = new HashMap<String, String>();
049
050        String viewName = ViewModelUtils.getStringValFromPVs(propertyValues, UifParameters.VIEW_NAME);
051        String dataObjectClassName = ViewModelUtils.getStringValFromPVs(propertyValues,
052                UifParameters.DATA_OBJECT_CLASS_NAME);
053
054        parameters.put(UifParameters.VIEW_NAME, viewName);
055        parameters.put(UifParameters.DATA_OBJECT_CLASS_NAME, dataObjectClassName);
056
057        return parameters;
058    }
059
060        /**
061         * @see org.kuali.rice.krad.uif.service.ViewTypeService#getParametersFromRequest(java.util.Map)
062         */
063    @Override
064        public Map<String, String> getParametersFromRequest(Map<String, String> requestParameters) {
065                Map<String, String> parameters = new HashMap<String, String>();
066
067                if (requestParameters.containsKey(UifParameters.VIEW_NAME)) {
068                        parameters.put(UifParameters.VIEW_NAME, requestParameters.get(UifParameters.VIEW_NAME));
069                }
070                else {
071                        parameters.put(UifParameters.VIEW_NAME, UifConstants.DEFAULT_VIEW_NAME);
072                }
073
074                if (requestParameters.containsKey(UifParameters.DATA_OBJECT_CLASS_NAME)) {
075                        parameters.put(UifParameters.DATA_OBJECT_CLASS_NAME,
076                                        requestParameters.get(UifParameters.DATA_OBJECT_CLASS_NAME));
077                }
078
079                return parameters;
080        }
081
082}