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.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 */ 044public class DisplayInactivationBlockersAction extends KualiAction { 045 046 public ActionForward displayAllInactivationBlockers(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 047 DisplayInactivationBlockersForm displayInactivationBlockersForm = (DisplayInactivationBlockersForm) form; 048 DataDictionaryService dataDictionaryService = KRADServiceLocatorWeb.getDataDictionaryService(); 049 InactivationBlockingDisplayService inactivationBlockingDisplayService = KRADServiceLocatorWeb 050 .getInactivationBlockingDisplayService(); 051 052 Class blockedBoClass = Class.forName(displayInactivationBlockersForm.getBusinessObjectClassName()); 053 BusinessObject blockedBo = (BusinessObject) blockedBoClass.newInstance(); 054 for (String key : displayInactivationBlockersForm.getPrimaryKeyFieldValues().keySet()) { 055 ObjectUtils.setObjectProperty(blockedBo, key, displayInactivationBlockersForm.getPrimaryKeyFieldValues().get(key)); 056 } 057 058 Map<String, List<String>> allBlockers = new TreeMap<String, List<String>>(); 059 060 Set<InactivationBlockingMetadata> inactivationBlockers = dataDictionaryService.getAllInactivationBlockingDefinitions(blockedBoClass); 061 for (InactivationBlockingMetadata inactivationBlockingMetadata : inactivationBlockers) { 062 String blockingBoLabel = dataDictionaryService.getDataDictionary().getBusinessObjectEntry(inactivationBlockingMetadata.getBlockingReferenceBusinessObjectClass().getName()).getObjectLabel(); 063 String relationshipLabel = inactivationBlockingMetadata.getRelationshipLabel(); 064 String displayLabel; 065 if (StringUtils.isEmpty(relationshipLabel)) { 066 displayLabel = blockingBoLabel; 067 } 068 else { 069 displayLabel = blockingBoLabel + " (" + relationshipLabel + ")"; 070 } 071 List<String> blockerObjectList = inactivationBlockingDisplayService.listAllBlockerRecords(blockedBo, inactivationBlockingMetadata); 072 073 if (!blockerObjectList.isEmpty()) { 074 List<String> existingList = allBlockers.get(displayLabel); 075 if (existingList != null) { 076 existingList.addAll(blockerObjectList); 077 } 078 else { 079 allBlockers.put(displayLabel, blockerObjectList); 080 } 081 } 082 } 083 084 displayInactivationBlockersForm.setBlockingValues(allBlockers); 085 086 return mapping.findForward(RiceConstants.MAPPING_BASIC); 087 } 088}