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 org.apache.commons.lang.StringUtils;
 19  
 import org.apache.struts.action.ActionForm;
 20  
 import org.apache.struts.action.ActionForward;
 21  
 import org.apache.struts.action.ActionMapping;
 22  
 import org.kuali.rice.core.api.util.RiceConstants;
 23  
 import org.kuali.rice.kns.web.struts.form.DisplayInactivationBlockersForm;
 24  
 import org.kuali.rice.krad.bo.BusinessObject;
 25  
 import org.kuali.rice.krad.datadictionary.InactivationBlockingMetadata;
 26  
 import org.kuali.rice.krad.service.DataDictionaryService;
 27  
 import org.kuali.rice.krad.service.InactivationBlockingDisplayService;
 28  
 import org.kuali.rice.krad.service.KRADServiceLocatorInternal;
 29  
 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
 30  
 import org.kuali.rice.krad.util.ObjectUtils;
 31  
 
 32  
 import javax.servlet.http.HttpServletRequest;
 33  
 import javax.servlet.http.HttpServletResponse;
 34  
 import java.util.List;
 35  
 import java.util.Map;
 36  
 import java.util.Set;
 37  
 import java.util.TreeMap;
 38  
 
 39  
 /**
 40  
  * This is a description of what this class does - wliang don't forget to fill this in. 
 41  
  * 
 42  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 43  
  *
 44  
  */
 45  0
 public class DisplayInactivationBlockersAction extends KualiAction {
 46  
         
 47  
         public ActionForward displayAllInactivationBlockers(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 48  0
                 DisplayInactivationBlockersForm displayInactivationBlockersForm = (DisplayInactivationBlockersForm) form;
 49  0
                 DataDictionaryService dataDictionaryService = KRADServiceLocatorWeb.getDataDictionaryService();
 50  0
                 InactivationBlockingDisplayService inactivationBlockingDisplayService = KRADServiceLocatorInternal.getInactivationBlockingDisplayService();
 51  
                 
 52  0
                 Class blockedBoClass = Class.forName(displayInactivationBlockersForm.getBusinessObjectClassName());
 53  0
                 BusinessObject blockedBo = (BusinessObject) blockedBoClass.newInstance();
 54  0
                 for (String key : displayInactivationBlockersForm.getPrimaryKeyFieldValues().keySet()) {
 55  0
                         ObjectUtils.setObjectProperty(blockedBo, key, displayInactivationBlockersForm.getPrimaryKeyFieldValues().get(key));
 56  
                 }
 57  
                 
 58  0
                 Map<String, List<String>> allBlockers = new TreeMap<String, List<String>>();
 59  
                 
 60  0
                 Set<InactivationBlockingMetadata> inactivationBlockers = dataDictionaryService.getAllInactivationBlockingDefinitions(blockedBoClass);
 61  0
                 for (InactivationBlockingMetadata inactivationBlockingMetadata : inactivationBlockers) {
 62  0
                         String blockingBoLabel = dataDictionaryService.getDataDictionary().getBusinessObjectEntry(inactivationBlockingMetadata.getBlockingReferenceBusinessObjectClass().getName()).getObjectLabel();
 63  0
                         String relationshipLabel = inactivationBlockingMetadata.getRelationshipLabel();
 64  
                         String displayLabel;
 65  0
                         if (StringUtils.isEmpty(relationshipLabel)) {
 66  0
                                 displayLabel = blockingBoLabel;
 67  
                         }
 68  
                         else {
 69  0
                                 displayLabel = blockingBoLabel + " (" + relationshipLabel + ")";
 70  
                         }
 71  0
                         List<String> blockerObjectList = inactivationBlockingDisplayService.listAllBlockerRecords(blockedBo, inactivationBlockingMetadata);
 72  
                         
 73  0
                         if (!blockerObjectList.isEmpty()) {
 74  0
                                 List<String> existingList = allBlockers.get(displayLabel);
 75  0
                                 if (existingList != null) {
 76  0
                                         existingList.addAll(blockerObjectList);
 77  
                                 }
 78  
                                 else {
 79  0
                                         allBlockers.put(displayLabel, blockerObjectList);
 80  
                                 }
 81  
                         }
 82  0
                 }
 83  
                 
 84  0
                 displayInactivationBlockersForm.setBlockingValues(allBlockers);
 85  
                 
 86  0
                 return mapping.findForward(RiceConstants.MAPPING_BASIC);
 87  
         }
 88  
 }