001/** 002 * Copyright 2005-2014 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.kns.web.struts.action; 017 018import org.apache.commons.lang.StringUtils; 019import org.apache.struts.action.ActionForm; 020import org.apache.struts.action.ActionForward; 021import org.apache.struts.action.ActionMapping; 022import org.kuali.rice.core.api.util.RiceConstants; 023import org.kuali.rice.kns.web.struts.form.DisplayInactivationBlockersForm; 024import org.kuali.rice.krad.bo.BusinessObject; 025import org.kuali.rice.krad.datadictionary.InactivationBlockingMetadata; 026import org.kuali.rice.krad.service.DataDictionaryService; 027import org.kuali.rice.krad.service.InactivationBlockingDisplayService; 028import org.kuali.rice.krad.service.KRADServiceLocatorWeb; 029import org.kuali.rice.krad.util.ObjectUtils; 030 031import javax.servlet.http.HttpServletRequest; 032import javax.servlet.http.HttpServletResponse; 033import java.util.List; 034import java.util.Map; 035import java.util.Set; 036import java.util.TreeMap; 037 038/** 039 * This is a description of what this class does - wliang don't forget to fill this in. 040 * 041 * @author Kuali Rice Team (rice.collab@kuali.org) 042 * 043 * @deprecated KNS Struts deprecated, use KRAD and the Spring MVC framework. 044 */ 045@Deprecated 046public class DisplayInactivationBlockersAction extends KualiAction { 047 @Deprecated 048 public ActionForward displayAllInactivationBlockers(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 049 DisplayInactivationBlockersForm displayInactivationBlockersForm = (DisplayInactivationBlockersForm) form; 050 DataDictionaryService dataDictionaryService = KRADServiceLocatorWeb.getDataDictionaryService(); 051 InactivationBlockingDisplayService inactivationBlockingDisplayService = KRADServiceLocatorWeb 052 .getInactivationBlockingDisplayService(); 053 054 Class blockedBoClass = Class.forName(displayInactivationBlockersForm.getBusinessObjectClassName()); 055 BusinessObject blockedBo = (BusinessObject) blockedBoClass.newInstance(); 056 for (String key : displayInactivationBlockersForm.getPrimaryKeyFieldValues().keySet()) { 057 ObjectUtils.setObjectProperty(blockedBo, key, displayInactivationBlockersForm.getPrimaryKeyFieldValues().get(key)); 058 } 059 060 Map<String, List<String>> allBlockers = new TreeMap<String, List<String>>(); 061 062 Set<InactivationBlockingMetadata> inactivationBlockers = dataDictionaryService.getAllInactivationBlockingDefinitions(blockedBoClass); 063 for (InactivationBlockingMetadata inactivationBlockingMetadata : inactivationBlockers) { 064 String blockingBoLabel = dataDictionaryService.getDataDictionary().getBusinessObjectEntry(inactivationBlockingMetadata.getBlockingReferenceBusinessObjectClass().getName()).getObjectLabel(); 065 String relationshipLabel = inactivationBlockingMetadata.getRelationshipLabel(); 066 String displayLabel; 067 if (StringUtils.isEmpty(relationshipLabel)) { 068 displayLabel = blockingBoLabel; 069 } 070 else { 071 displayLabel = blockingBoLabel + " (" + relationshipLabel + ")"; 072 } 073 List<String> blockerObjectList = inactivationBlockingDisplayService.listAllBlockerRecords(blockedBo, inactivationBlockingMetadata); 074 075 if (!blockerObjectList.isEmpty()) { 076 List<String> existingList = allBlockers.get(displayLabel); 077 if (existingList != null) { 078 existingList.addAll(blockerObjectList); 079 } 080 else { 081 allBlockers.put(displayLabel, blockerObjectList); 082 } 083 } 084 } 085 086 displayInactivationBlockersForm.setBlockingValues(allBlockers); 087 088 return mapping.findForward(RiceConstants.MAPPING_BASIC); 089 } 090}