001    /**
002     * Copyright 2005-2012 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     */
016    package org.kuali.rice.krms.impl.repository;
017    
018    import org.apache.commons.lang.StringUtils;
019    import org.kuali.rice.krad.lookup.LookupableImpl;
020    import org.kuali.rice.krad.uif.UifConstants;
021    import org.kuali.rice.krad.uif.UifParameters;
022    import org.kuali.rice.krad.util.KRADConstants;
023    import org.kuali.rice.krad.util.KRADUtils;
024    import org.kuali.rice.krad.util.UrlFactory;
025    import org.kuali.rice.krad.web.form.LookupForm;
026    import org.kuali.rice.krms.api.KrmsConstants;
027    import org.kuali.rice.krms.impl.ui.AgendaEditor;
028    
029    import java.util.List;
030    import java.util.Map;
031    import java.util.Properties;
032    
033    public class AgendaLookupableHelperServiceImpl extends LookupableImpl {
034    
035        @Override
036        public boolean allowsMaintenanceNewOrCopyAction() {
037            // The context is unknown on create so we need to let the user in
038            // TODO: maybe restrict it so only user that have rights to some contexts are allowed to create agendas.
039            return true;
040        }
041    
042        @Override
043        public boolean allowsMaintenanceEditAction(Object dataObject) {
044            boolean allowsEdit = false;
045    
046            AgendaBo agenda = (AgendaBo) dataObject;
047            allowsEdit = KrmsRepositoryServiceLocator.getAgendaAuthorizationService().isAuthorized(KrmsConstants.MAINTAIN_KRMS_AGENDA, agenda.getContextId());
048    
049            return allowsEdit;
050        }
051    
052        @Override
053        public boolean allowsMaintenanceDeleteAction(Object dataObject) {
054            boolean allowsMaintain = false;
055            boolean allowsDelete = false;
056    
057            AgendaBo agenda = (AgendaBo) dataObject;
058            allowsMaintain = KrmsRepositoryServiceLocator.getAgendaAuthorizationService().isAuthorized(KrmsConstants.MAINTAIN_KRMS_AGENDA, agenda.getContextId());
059    
060            return allowsDelete && allowsMaintain;
061        }
062    
063        @Override
064        protected String getActionUrlHref(LookupForm lookupForm, Object dataObject, String methodToCall, List<String> pkNames) {
065            Properties props = new Properties();
066            props.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, methodToCall);
067    
068            Map<String, String> primaryKeyValues = KRADUtils.getPropertyKeyValuesFromDataObject(pkNames, dataObject);
069            for (String primaryKey : primaryKeyValues.keySet()) {
070                String primaryKeyValue = primaryKeyValues.get(primaryKey);
071    
072                props.put(primaryKey, primaryKeyValue);
073                props.put(KRADConstants.OVERRIDE_KEYS, primaryKey);
074            }
075    
076            if (StringUtils.isNotBlank(lookupForm.getReturnLocation())) {
077                props.put(KRADConstants.RETURN_LOCATION_PARAMETER, lookupForm.getReturnLocation());
078            }
079    
080            props.put(UifParameters.DATA_OBJECT_CLASS_NAME, AgendaEditor.class.getName());
081            props.put(UifParameters.VIEW_TYPE_NAME, UifConstants.ViewType.MAINTENANCE.name());
082    
083            return UrlFactory.parameterizeUrl(org.kuali.rice.krms.impl.util.KrmsImplConstants.WebPaths.AGENDA_EDITOR_PATH, props);
084        }
085    }