001    /**
002     * Copyright 2004-2013 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.hr.time.calendar.service;
017    
018    import java.util.ArrayList;
019    import java.util.List;
020    import java.util.Properties;
021    
022    import org.apache.commons.lang.StringUtils;
023    import org.kuali.hr.time.calendar.CalendarEntries;
024    import org.kuali.hr.time.util.TKContext;
025    import org.kuali.rice.kns.lookup.HtmlData;
026    import org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl;
027    import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
028    import org.kuali.rice.krad.bo.BusinessObject;
029    import org.kuali.rice.krad.util.KRADConstants;
030    import org.kuali.rice.krad.util.UrlFactory;
031    
032    public class CalendarEntriesLookupableHelper extends KualiLookupableHelperServiceImpl {
033    
034            private static final long serialVersionUID = 6008647804840459542L;
035    
036            @Override
037            public List<HtmlData> getCustomActionUrls(BusinessObject businessObject, List pkNames) {
038                    List<HtmlData> customActionUrls = new ArrayList<HtmlData>();
039                    
040                    List<HtmlData> defaultCustomActionUrls = super.getCustomActionUrls(businessObject, pkNames);
041    
042                    CalendarEntries calendarEntries = (CalendarEntries) businessObject;
043                    String hrCalendarEntriesId = calendarEntries.getHrCalendarEntriesId();
044                    String calendarName = calendarEntries.getCalendarName();
045                    
046                    boolean systemAdmin = TKContext.getUser().isSystemAdmin();
047                    boolean locationAdmin = TKContext.getUser().isLocationAdmin();
048    
049                    for (HtmlData defaultCustomActionUrl : defaultCustomActionUrls){
050                            if (StringUtils.equals(defaultCustomActionUrl.getMethodToCall(), "edit")) {
051                                    if (systemAdmin || locationAdmin) {
052                                            customActionUrls.add(defaultCustomActionUrl);
053                                    }
054                            } else if (!StringUtils.equals(defaultCustomActionUrl.getMethodToCall(), "copy")){
055                                    customActionUrls.add(defaultCustomActionUrl);
056                            }
057                    }
058                    
059                    Properties params = new Properties();
060                    params.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, getBusinessObjectClass().getName());
061                    params.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.MAINTENANCE_NEW_METHOD_TO_CALL);
062                    params.put("hrCalendarEntriesId", hrCalendarEntriesId);
063                    params.put("calendarName", calendarName);
064                    AnchorHtmlData viewUrl = new AnchorHtmlData(UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, params), "view");
065                    viewUrl.setDisplayText("view");
066                    viewUrl.setTarget(AnchorHtmlData.TARGET_BLANK);
067                    customActionUrls.add(viewUrl);
068                    
069                    return customActionUrls;
070            }
071            
072    }