Log In | Get Help   
Home My Page Projects Code Snippets Project Openings Accounting and Billing Portal
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files
[abportal] View of /src/main/java/eu/smartlm/abs/portal/view/ajax/ListOptionServlet.java
[abportal] / src / main / java / eu / smartlm / abs / portal / view / ajax / ListOptionServlet.java Repository:
ViewVC logotype

View of /src/main/java/eu/smartlm/abs/portal/view/ajax/ListOptionServlet.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (download) (annotate)
Wed Jul 28 10:05:51 2010 UTC (13 years, 9 months ago) by dgarcia
File size: 8082 byte(s)
First code commit
package eu.smartlm.abs.portal.view.ajax;

import java.io.File;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.gridforum.x2003.urWg.HostDocument.Host;
import org.gridforum.x2003.urWg.ProjectNameDocument.ProjectName;
import org.gridforum.x2003.urWg.SubmitHostDocument.SubmitHost;
import org.gridforum.x2003.urWg.UserIdentityDocument.UserIdentity;

import eu.smartlm.abs.portal.data.query.QueryConstructorDummy;
import eu.smartlm.abs.portal.data.query.QueryConstructor;
import eu.smartlm.abs.portal.data.query.ws.EBSServiceClient;
import eu.smartlm.abs.portal.util.StringUtil;
import eu.smartlm.abs.portal.view.data.ABSQuery;
import eu.smartlm.schemas.x2009.x06.urec.ProductType;

public class ListOptionServlet extends HttpServlet {

   private static final long serialVersionUID = 6207446064054737981L;

   public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {

	   String ebsInterfaceURL = request.getParameter("ebs_interface_url");
	   QueryConstructor query; 
	   if (ebsInterfaceURL.equalsIgnoreCase("DEMO")) {
		   query = new QueryConstructorDummy();
	   } else {
		   query = new EBSServiceClient();

		   try {
			   
			   File rampartDirectory = new File("rampart");
			   File clientPropertiesFile = new File("client.properties");
			   query.setUpConnection(ebsInterfaceURL, rampartDirectory.getCanonicalPath(), clientPropertiesFile.getCanonicalPath());
		   } catch (Exception e) {
			   throw new ServletException("Unable to initialize ConfigurationContext.", e);
		   }
	   }

      // Extracts the necessary requested information
      String targetId = request.getParameter("id");
      String startDate = request.getParameter("start_date");
      String endDate = request.getParameter("end_date");

      // Retrieval of the data from the portlet
      Set<String> productsList = StringUtil.stringToListWithMarker(request.getParameter("products"));
      Set<String> usersList = StringUtil.stringToListWithMarker(request.getParameter("users"));
      Set<String> accountingGroupsList = StringUtil.stringToListWithMarker(request.getParameter("accounting_groups"));
      Set<String> projectsList = StringUtil.stringToListWithMarker(request.getParameter("projects"));
      Set<String> hostsList = StringUtil.stringToListWithMarker(request.getParameter("hosts"));
      Set<String> submitHostsList = StringUtil.stringToListWithMarker(request.getParameter("submithosts"));
      Set<String> securityUserFilter = StringUtil.stringToListWithMarker(request.getParameter("securityuserfilter"));
      Set<String> securityAccountingGroupFilter = StringUtil.stringToListWithMarker(request.getParameter("securityaccountingfilter"));
      
      // We add the security filters to the query:
      for(String userFilter : securityUserFilter) usersList.add(userFilter);
      for(String accountingGroupFilter : securityAccountingGroupFilter) accountingGroupsList.add(accountingGroupFilter);
      
      // Change this when implemented!!!!
      Set<String> features = new HashSet<String>();

      // Checks with information it needs.
      if (targetId != null) {

         response.setContentType("text/xml");
         response.setHeader("Cache-Control", "no-cache");
         String responseText = "<entries>";

         if (targetId.equals(ABSQuery.PRODUCT)) {
            Set<ProductType> products = query.getListOfProducts(
                    StringUtil.getDate(startDate, false),
                    StringUtil.getDate(endDate, true),
                    usersList,
                    productsList,
                    projectsList,
                    hostsList,
                    submitHostsList,
                    features,
                    accountingGroupsList);


            for (ProductType product : products) {
               responseText = responseText
                       + "<entry> <value>" + product.getProductId()
                       + "</value> <name>" + product.getName() + "</name> </entry>";
            }
         } else if (targetId.equals(ABSQuery.USER)) {
            Set<UserIdentity> users = query.getListOfUsers(
            		StringUtil.getDate(startDate, false),
                    StringUtil.getDate(endDate, true),
                    usersList,
                    productsList,
                    projectsList,
                    hostsList,
                    submitHostsList,
                    features,
                    accountingGroupsList);

            for (UserIdentity user : users) {
               responseText = responseText
                       + "<entry> <value>" + user.getLocalUserId()
                       + "</value> <name>" + user.getLocalUserId() + "</name> </entry>";
            }
         } else if (targetId.equals(ABSQuery.ACCOUNTINGGROUP)) {
            Set<String> accountingGroups = query.getListOfAccountingGroups(
            		StringUtil.getDate(startDate, false),
                    StringUtil.getDate(endDate, true),
                    usersList,
                    productsList,
                    projectsList,
                    hostsList,
                    submitHostsList,
                    features,
                    accountingGroupsList);

            for (String accountingGroup : accountingGroups) {
               responseText = responseText
                       + "<entry> <value>" + accountingGroup + "</value> <name>"
                       + accountingGroup + "</name> </entry>";
            }
         } else if (targetId.equals(ABSQuery.HOST)) {
            Set<Host> hosts = query.getListOfHosts(
            		StringUtil.getDate(startDate, false),
                    StringUtil.getDate(endDate, true),
                    usersList,
                    productsList,
                    projectsList,
                    hostsList,
                    submitHostsList,
                    features,
                    accountingGroupsList);

            for (Host host : hosts) {
               responseText = responseText
                       + "<entry> <value>" + host.getStringValue()
                       + "</value> <name>" + host.getStringValue() + "</name> </entry>";
            }
         } else if (targetId.equals(ABSQuery.SUBMITHOST)) {
            Set<SubmitHost> submitHosts = query.getListOfSubmitHosts(
            		StringUtil.getDate(startDate, false),
                    StringUtil.getDate(endDate, true),
                    usersList,
                    productsList,
                    projectsList,
                    hostsList,
                    submitHostsList,
                    features,
                    accountingGroupsList);

            for (SubmitHost submitHost : submitHosts) {
               responseText = responseText
                       + "<entry> <value>"
                       + submitHost.getStringValue()
                       + "</value> <name>" + submitHost.getStringValue() + "</name> </entry>";
            }
         } else if (targetId.equals(ABSQuery.PROJECT)) {
            Set<ProjectName> projects = query.getListOfProjects(
            		StringUtil.getDate(startDate, false),
                    StringUtil.getDate(endDate, true),
                    usersList,
                    productsList,
                    projectsList,
                    hostsList,
                    submitHostsList,
                    features,
                    accountingGroupsList);

            for (ProjectName project : projects) {
               responseText = responseText
                       + "<entry> <value>"
                       + project.getStringValue() + "</value> <name>"
                       + project.getStringValue() + "</name> </entry>";
            }
         }

         responseText = responseText + "</entries>";
         response.getWriter().write(responseText);
      }

   }
}

root@forge.cesga.es
ViewVC Help
Powered by ViewVC 1.0.0  

Powered By FusionForge