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.apache.commons.lang.StringUtils;
019import org.kuali.rice.krad.lookup.LookupableImpl;
020import org.kuali.rice.krad.uif.UifConstants;
021import org.kuali.rice.krad.uif.UifParameters;
022import org.kuali.rice.krad.util.KRADConstants;
023import org.kuali.rice.krad.util.KRADUtils;
024import org.kuali.rice.krad.util.UrlFactory;
025import org.kuali.rice.krad.lookup.LookupForm;
026import org.kuali.rice.krms.api.KrmsConstants;
027import org.kuali.rice.krms.impl.ui.AgendaEditor;
028
029import java.util.List;
030import java.util.Map;
031import java.util.Properties;
032
033public 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 getMaintenanceActionUrl(LookupForm lookupForm, Object dataObject, String methodToCall,
065            List<String> pkNames) {
066        Properties props = new Properties();
067        props.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, methodToCall);
068
069        Map<String, String> primaryKeyValues = KRADUtils.getPropertyKeyValuesFromDataObject(pkNames, dataObject);
070        for (String primaryKey : primaryKeyValues.keySet()) {
071            String primaryKeyValue = primaryKeyValues.get(primaryKey);
072
073            props.put(primaryKey, primaryKeyValue);
074            props.put(KRADConstants.OVERRIDE_KEYS, primaryKey);
075        }
076
077        if (StringUtils.isNotBlank(lookupForm.getReturnLocation())) {
078            props.put(KRADConstants.RETURN_LOCATION_PARAMETER, lookupForm.getReturnLocation());
079        }
080
081        props.put(UifParameters.DATA_OBJECT_CLASS_NAME, AgendaEditor.class.getName());
082        props.put(UifParameters.VIEW_TYPE_NAME, UifConstants.ViewType.MAINTENANCE.name());
083
084        return UrlFactory.parameterizeUrl(org.kuali.rice.krms.impl.util.KrmsImplConstants.WebPaths.AGENDA_EDITOR_PATH, props);
085    }
086}