Coverage Report - org.kuali.rice.kns.web.struts.action.DisplayInactivationBlockersAction
 
Classes in this File Line Coverage Branch Coverage Complexity
DisplayInactivationBlockersAction
0%
0/25
0%
0/10
6
 
 1  
 /*
 2  
  * Copyright 2007-2008 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.kns.web.struts.action;
 17  
 
 18  
 import java.util.List;
 19  
 import java.util.Map;
 20  
 import java.util.Set;
 21  
 import java.util.TreeMap;
 22  
 
 23  
 import javax.servlet.http.HttpServletRequest;
 24  
 import javax.servlet.http.HttpServletResponse;
 25  
 
 26  
 import org.apache.commons.lang.StringUtils;
 27  
 import org.apache.struts.action.ActionForm;
 28  
 import org.apache.struts.action.ActionForward;
 29  
 import org.apache.struts.action.ActionMapping;
 30  
 import org.kuali.rice.core.util.RiceConstants;
 31  
 import org.kuali.rice.kns.bo.BusinessObject;
 32  
 import org.kuali.rice.kns.datadictionary.InactivationBlockingMetadata;
 33  
 import org.kuali.rice.kns.service.DataDictionaryService;
 34  
 import org.kuali.rice.kns.service.InactivationBlockingDisplayService;
 35  
 import org.kuali.rice.kns.service.KNSServiceLocatorInternal;
 36  
 import org.kuali.rice.kns.service.KNSServiceLocatorWeb;
 37  
 import org.kuali.rice.kns.util.ObjectUtils;
 38  
 import org.kuali.rice.kns.web.struts.form.DisplayInactivationBlockersForm;
 39  
 
 40  
 /**
 41  
  * This is a description of what this class does - wliang don't forget to fill this in. 
 42  
  * 
 43  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 44  
  *
 45  
  */
 46  0
 public class DisplayInactivationBlockersAction extends KualiAction {
 47  
         
 48  
         public ActionForward displayAllInactivationBlockers(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 49  0
                 DisplayInactivationBlockersForm displayInactivationBlockersForm = (DisplayInactivationBlockersForm) form;
 50  0
                 DataDictionaryService dataDictionaryService = KNSServiceLocatorWeb.getDataDictionaryService();
 51  0
                 InactivationBlockingDisplayService inactivationBlockingDisplayService = KNSServiceLocatorInternal.getInactivationBlockingDisplayService();
 52  
                 
 53  0
                 Class blockedBoClass = Class.forName(displayInactivationBlockersForm.getBusinessObjectClassName());
 54  0
                 BusinessObject blockedBo = (BusinessObject) blockedBoClass.newInstance();
 55  0
                 for (String key : displayInactivationBlockersForm.getPrimaryKeyFieldValues().keySet()) {
 56  0
                         ObjectUtils.setObjectProperty(blockedBo, key, displayInactivationBlockersForm.getPrimaryKeyFieldValues().get(key));
 57  
                 }
 58  
                 
 59  0
                 Map<String, List<String>> allBlockers = new TreeMap<String, List<String>>();
 60  
                 
 61  0
                 Set<InactivationBlockingMetadata> inactivationBlockers = dataDictionaryService.getAllInactivationBlockingDefinitions(blockedBoClass);
 62  0
                 for (InactivationBlockingMetadata inactivationBlockingMetadata : inactivationBlockers) {
 63  0
                         String blockingBoLabel = dataDictionaryService.getDataDictionary().getBusinessObjectEntry(inactivationBlockingMetadata.getBlockingReferenceBusinessObjectClass().getName()).getObjectLabel();
 64  0
                         String relationshipLabel = inactivationBlockingMetadata.getRelationshipLabel();
 65  
                         String displayLabel;
 66  0
                         if (StringUtils.isEmpty(relationshipLabel)) {
 67  0
                                 displayLabel = blockingBoLabel;
 68  
                         }
 69  
                         else {
 70  0
                                 displayLabel = blockingBoLabel + " (" + relationshipLabel + ")";
 71  
                         }
 72  0
                         List<String> blockerObjectList = inactivationBlockingDisplayService.listAllBlockerRecords(blockedBo, inactivationBlockingMetadata);
 73  
                         
 74  0
                         if (!blockerObjectList.isEmpty()) {
 75  0
                                 List<String> existingList = allBlockers.get(displayLabel);
 76  0
                                 if (existingList != null) {
 77  0
                                         existingList.addAll(blockerObjectList);
 78  
                                 }
 79  
                                 else {
 80  0
                                         allBlockers.put(displayLabel, blockerObjectList);
 81  
                                 }
 82  
                         }
 83  0
                 }
 84  
                 
 85  0
                 displayInactivationBlockersForm.setBlockingValues(allBlockers);
 86  
                 
 87  0
                 return mapping.findForward(RiceConstants.MAPPING_BASIC);
 88  
         }
 89  
 }