Coverage Report - org.kuali.rice.ksb.messaging.web.ServiceRegistryAction
 
Classes in this File Line Coverage Branch Coverage Complexity
ServiceRegistryAction
0%
0/34
0%
0/8
1.571
 
 1  
 /*
 2  
  * Copyright 2006-2011 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  
 
 17  
 package org.kuali.rice.ksb.messaging.web;
 18  
 
 19  
 import org.apache.struts.action.ActionForm;
 20  
 import org.apache.struts.action.ActionForward;
 21  
 import org.apache.struts.action.ActionMapping;
 22  
 import org.apache.struts.action.ActionMessages;
 23  
 import org.kuali.rice.core.api.config.property.ConfigContext;
 24  
 import org.kuali.rice.core.util.RiceUtilities;
 25  
 import org.kuali.rice.ksb.messaging.RemoteResourceServiceLocator;
 26  
 import org.kuali.rice.ksb.messaging.RemotedServiceHolder;
 27  
 import org.kuali.rice.ksb.messaging.RemotedServiceRegistry;
 28  
 import org.kuali.rice.ksb.messaging.ServerSideRemotedServiceHolder;
 29  
 import org.kuali.rice.ksb.messaging.ServiceInfo;
 30  
 import org.kuali.rice.ksb.messaging.resourceloader.KSBResourceLoaderFactory;
 31  
 import org.kuali.rice.ksb.messaging.service.ServiceRegistry;
 32  
 import org.kuali.rice.ksb.service.KSBServiceLocator;
 33  
 import org.kuali.rice.ksb.util.KSBConstants;
 34  
 
 35  
 import javax.servlet.ServletException;
 36  
 import javax.servlet.http.HttpServletRequest;
 37  
 import javax.servlet.http.HttpServletResponse;
 38  
 import javax.xml.namespace.QName;
 39  
 import java.io.IOException;
 40  
 import java.util.ArrayList;
 41  
 import java.util.List;
 42  
 import java.util.Map;
 43  
 
 44  
 
 45  
 /**
 46  
  * Struts action for interacting with the queue of messages.
 47  
  *
 48  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 49  
  */
 50  0
 public class ServiceRegistryAction extends KSBAction {
 51  
 
 52  
     public ActionForward start(ActionMapping mapping, ActionForm form, HttpServletRequest request,
 53  
             HttpServletResponse response) throws IOException, ServletException {
 54  0
         return mapping.findForward("basic");
 55  
     }
 56  
 
 57  
     public ActionForward refreshServiceRegistry(ActionMapping mapping, ActionForm form, HttpServletRequest request,
 58  
             HttpServletResponse response) throws IOException, ServletException {
 59  
         // TODO is this what really constitutes a "refresh" of the service registry?
 60  0
         KSBServiceLocator.getServiceDeployer().refresh();
 61  0
         KSBResourceLoaderFactory.getRemoteResourceLocator().refresh();
 62  0
         return mapping.findForward("basic");
 63  
     }
 64  
     
 65  
         /**
 66  
      * Enable deletion of localhost service registry entries.
 67  
      */
 68  
     public ActionForward deleteLocalhostEntries(ActionMapping mapping, ActionForm form, HttpServletRequest request,
 69  
                 HttpServletResponse response) throws IOException, ServletException {
 70  0
             ServiceRegistry registry = KSBServiceLocator.getServiceRegistry();
 71  0
         registry.removeLocallyPublishedServices("localhost",null);//Namespace unspecified to match all localhost records
 72  0
                 return mapping.findForward("basic");
 73  
     }
 74  
 
 75  
 
 76  
     public ActionMessages establishRequiredState(HttpServletRequest request, ActionForm actionForm) throws Exception {
 77  0
         ServiceRegistryForm form = (ServiceRegistryForm)actionForm;
 78  0
         form.setMyIpAddress(RiceUtilities.getIpNumber());
 79  0
         form.setMyServiceNamespace(ConfigContext.getCurrentContextConfig().getProperty(KSBConstants.Config.SERVICE_NAMESPACE));
 80  0
         form.setDevMode(ConfigContext.getCurrentContextConfig().getDevMode());
 81  0
         RemotedServiceRegistry registry = KSBServiceLocator.getServiceDeployer();
 82  0
         RemoteResourceServiceLocator remoteLocator = KSBResourceLoaderFactory.getRemoteResourceLocator();
 83  0
         form.setPublishedServices(getPublishedServices(registry));
 84  0
         form.setPublishedTempServices(getPublishedTempServices(registry));
 85  0
         form.setGlobalRegistryServices(getGlobalRegistryServices(remoteLocator));
 86  
 
 87  0
         return null;
 88  
     }
 89  
 
 90  
     private List<ServiceInfo> getPublishedServices(RemotedServiceRegistry registry) {
 91  0
         Map<QName, ServerSideRemotedServiceHolder> publishedServiceHolders = registry.getPublishedServices();
 92  0
         List<ServiceInfo> publishedServices = new ArrayList<ServiceInfo>();
 93  0
         for (ServerSideRemotedServiceHolder holder : publishedServiceHolders.values()) {
 94  0
             publishedServices.add(holder.getServiceInfo());
 95  
         }
 96  0
         return publishedServices;
 97  
     }
 98  
 
 99  
     private List<ServiceInfo> getPublishedTempServices(RemotedServiceRegistry registry) {
 100  0
         Map<QName, ServerSideRemotedServiceHolder> publishedTempServiceHolders = registry.getPublishedTempServices();
 101  0
         List<ServiceInfo> publishedTempServices = new ArrayList<ServiceInfo>();
 102  0
         for (ServerSideRemotedServiceHolder holder : publishedTempServiceHolders.values()) {
 103  0
             publishedTempServices.add(holder.getServiceInfo());
 104  
         }
 105  0
         return publishedTempServices;
 106  
     }
 107  
 
 108  
     private List<ServiceInfo> getGlobalRegistryServices(RemoteResourceServiceLocator remoteLocator) {
 109  0
         Map<QName, List<RemotedServiceHolder>> clients = remoteLocator.getClients();
 110  0
         List<ServiceInfo> globalRegistryServices = new ArrayList<ServiceInfo>();
 111  0
         for (List<RemotedServiceHolder> client : clients.values()) {
 112  0
             for (RemotedServiceHolder holder : client) {
 113  0
                 globalRegistryServices.add(holder.getServiceInfo());
 114  
             }
 115  
         }
 116  0
         return globalRegistryServices;
 117  
     }
 118  
 
 119  
 }