View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  
19  package org.apache.oodt.cas.curation.servlet;
20  
21  //OODT imports
22  import org.apache.oodt.cas.curation.policymgr.CurationPolicyManager;
23  import org.apache.oodt.cas.metadata.util.PathUtils;
24  
25  //JDK imports
26  import java.io.IOException;
27  import java.io.PrintWriter;
28  import javax.servlet.RequestDispatcher;
29  import javax.servlet.ServletConfig;
30  import javax.servlet.ServletException;
31  import javax.servlet.http.HttpServletRequest;
32  import javax.servlet.http.HttpServletResponse;
33  import javax.servlet.http.HttpSession;
34  
35  // Displays the contents of the staging area as an HTML unordered list (<ul></ul>): 
36  // This servlet is meant to be invoked via an AJAX call, the generated HTML output
37  // will be dynamically inserted into a DOM element on the requesting page.
38  //
39  
40  public class ShowExistingDatasetsByPolicyServlet extends
41      SSOConfiguredCuratorWebService {
42  
43    private String stagingAreaPath;
44    
45    private String policyDirPath;
46    
47    private static final long serialVersionUID = 4844652723865688280L;
48  
49    public ShowExistingDatasetsByPolicyServlet() {
50    }
51  
52    public void init(ServletConfig conf) throws ServletException {
53      super.init(conf);
54      this.stagingAreaPath = PathUtils.replaceEnvVariables(getServletContext().getInitParameter(STAGING_AREA_PATH));
55      this.policyDirPath = PathUtils.replaceEnvVariables(getServletContext().getInitParameter(POLICY_UPLOAD_PATH));    
56    }
57  
58    public void doPost(HttpServletRequest req, HttpServletResponse res)
59        throws ServletException, IOException {
60      HttpSession session = req.getSession();
61      session.setAttribute("errorMsg", "You must use GET to access this page");
62      RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(
63          "/error.jsp");
64      dispatcher.forward(req, res);
65  
66    }
67  
68    // Handle HTTP GET requests by forwarding to a common processor
69    public void doGet(HttpServletRequest req, HttpServletResponse res)
70        throws ServletException, IOException {
71  
72      this.configureSingleSignOn(req, res);
73  
74      // Redirect if no valid user logged in
75      if (!this.sso.isLoggedIn()) {
76        res.sendRedirect("/login.jsp?from=" + req.getRequestURL());
77        return;
78      }
79  
80      String policy = req.getParameter("policy");
81      PrintWriter out = res.getWriter();
82  
83      // we return with blank page with error
84      if (policy == null) {
85        out.println("");
86        return;
87      }
88  
89      CurationPolicyManager pm = new CurationPolicyManager(this.policyDirPath, this.stagingAreaPath);
90      out.println(pm.getDatasetsByPolicyAsJSON(policy));
91  
92      return;
93    }
94  }