예제 #1
0
  // Process the request
  private String processRequest(HttpServletRequest request, HttpServletResponse response) {
    HttpSession session = request.getSession();
    String userIDs = (String) session.getAttribute("user.id");
    userIDs = (userIDs != null && userIDs.compareTo(" ") > 0) ? userIDs : "0";
    long userID = Long.parseLong(userIDs);
    String command = request.getParameter("command");
    String template = request.getParameter("template");
    String pageHash = request.getParameter("pagehash");
    String pageTitle = request.getParameter("pagetitle");
    String pageDescription = request.getParameter("pagedescription");

    String outLine = "";
    String nextScript = request.getParameter("nextscript");
    OutputStream toClient;
    boolean success = false;

    // System.out.println("userid=" + userID + ", id=" + id + ", command=" + command);

    command = (command != null && command.compareTo(" ") > 0) ? command : "form";
    nextScript = (nextScript != null && nextScript.compareTo(" ") > 0) ? nextScript : "simple1.jsp";

    //    inputstring = (inputstring != null && inputstring.compareTo(" ") > 0) ? inputstring : "";

    DbConn myConn = null;
    try {

      Context initCtx = new InitialContext();
      // String csiSchema = (String) initCtx.lookup("java:comp/env/csi-schema-path");
      // String acronym = (String) initCtx.lookup("java:comp/env/SystemAcronym");
      myConn = new DbConn();
      String csiSchema = myConn.getSchemaPath();
      if (userID != 0) {
        if (command.equals("add")) {
          outLine = "";
        } else if (command.equals("update")) {
          outLine = "";
        } else if (command.equals("updatepage")) {
          UHash uPage = new UHash(pageHash, myConn);
          // System.out.println("Got Here 1");
          if (template.equals("simple1")) {
            TextItem title = new TextItem(uPage.get("title"), myConn);
            title.setText(pageTitle);
            title.save(myConn);
            TextItem description = new TextItem(uPage.get("description"), myConn);
            description.setText(pageDescription);
            description.save(myConn);
          } else if (template.equals("simple2")) {
          }

        } else if (command.equals("test")) {
          outLine = "test";
        }
        success = true;
      }

    } catch (IllegalArgumentException e) {
      outLine = outLine + "IllegalArgumentException caught: " + e.getMessage();
      ALog.logActivity(userID, "csi", 0, pageHash + " error: '" + outLine + "'");
      // log(outLine);
    } catch (NullPointerException e) {
      outLine = outLine + "NullPointerException caught: " + e.getMessage();
      ALog.logActivity(userID, "csi", 0, pageHash + " error: '" + outLine + "'");
      // log(outLine);
    }

    // catch (IOException e) {
    //    outLine = outLine + "IOException caught: " + e.getMessage();
    //    ALog.logActivity(userID, "csi", 0, pageHash + " error: '" + outLine + "'");
    //    //log(outLine);
    // }

    catch (Exception e) {
      outLine = outLine + "Exception caught: " + e.getMessage();
      ALog.logActivity(userID, "csi", 0, pageHash + " error: '" + outLine + "'");
      // log(outLine);
    } finally {
      try {
        generateResponse(outLine, command, nextScript, success, response);
      } catch (Exception i) {
      }

      myConn.release();
      // log("Test log message\n");
    }

    return outLine;
  }
예제 #2
0
 private void init() {
   DbConn tempDB = new DbConn("dummy");
   SCHEMA = "sat";
   SCHEMAPATH = "sat";
   DBTYPE = tempDB.getDBType();
 }
예제 #3
0
  // Process the request
  private String processRequest(HttpServletRequest request, HttpServletResponse response) {
    String command = request.getParameter("command");
    String id = request.getParameter("id");
    String description = request.getParameter("description");
    String status = request.getParameter("rstatus");
    status = (status != null && status.compareTo(" ") > 0) ? status : null;
    String outLine = "";
    // String nextScript = "home.jsp";
    String nextScript = request.getParameter("nextscript");
    OutputStream toClient;
    HttpSession session = request.getSession();
    boolean success = false;
    String userIDs = (String) session.getAttribute("user.id");
    long userID = Long.parseLong(userIDs);

    command = (command != null && command.compareTo(" ") > 0) ? command : "form";
    nextScript = (nextScript != null && nextScript.compareTo(" ") > 0) ? nextScript : "roles.jsp";

    //    inputstring = (inputstring != null && inputstring.compareTo(" ") > 0) ? inputstring : "";

    DbConn myConn = null;
    try {

      Context initCtx = new InitialContext();
      // String csiSchema = (String) initCtx.lookup("java:comp/env/csi-schema-path");
      String acronym = (String) initCtx.lookup("java:comp/env/SystemAcronym");
      myConn = new DbConn();
      String csiSchema = myConn.getSchemaPath();
      if (command.equals("add")) {
        Role item = new Role();
        item.setDescription(description);
        item.setStatus(status);
        getPermissions(request, item);
        getPositions(request, item);
        item.add(myConn, userID);
        GlobalMembership.refresh(myConn);
        success = true;
        outLine = "";

      } else if (command.equals("update")) {
        Role item = new Role(myConn, Long.parseLong(id));
        item.setDescription(description);
        item.setStatus(status);
        getPermissions(request, item);
        getPositions(request, item);
        item.save(myConn, userID);
        GlobalMembership.refresh(myConn);
        success = true;
        outLine = "";
      } else if (command.equals("drop")) {
        Role item = new Role(myConn, Long.parseLong(id));
        item.drop(myConn, userID);
        success = true;
        outLine = "Role " + item.getDescription() + " Removed";
      } else if (command.equals("test")) {
        outLine = "test";
      }

    } catch (IllegalArgumentException e) {
      outLine = outLine + "IllegalArgumentException caught: " + e.getMessage();
      ALog.logActivity(userID, "csi", 0, "Role error: '" + outLine + "'");
      // log(outLine);
    } catch (NullPointerException e) {
      outLine = outLine + "NullPointerException caught: " + e.getMessage();
      ALog.logActivity(userID, "csi", 0, "Role error: '" + outLine + "'");
      // log(outLine);
    }

    // catch (IOException e) {
    //    outLine = outLine + "IOException caught: " + e.getMessage();
    //    ALog.logActivity(userID, "csi", 0, "Role error: '" + outLine + "'");
    //    //log(outLine);
    // }

    catch (Exception e) {
      outLine = outLine + "Exception caught: " + e.getMessage();
      ALog.logActivity(userID, "csi", 0, "Role error: '" + outLine + "'");
      // log(outLine);
    } finally {
      try {
        generateResponse(outLine, command, nextScript, success, response);
      } catch (Exception i) {
      }

      myConn.release();
      // log("Test log message\n");
    }

    return outLine;
  }
예제 #4
0
  /** @param args */
  public static void main(String[] args) {
    System.out.println("TabSetsTest called!");

    DbConn myConn = new DbConn("csi");
    long personID;
    personID = (long) 0; // the user has not logged in...
    TabSet ts = null;
    long[] items = null;

    // retrieve home tabs
    System.out.println("~~~ retrieve home tabs");
    ts = new TabSet("OPG-TabSet-Home-Default", myConn);
    items = ts.getItemsArray();
    for (int i = 0; i < items.length; i++) {
      Tab t = null;
      t = new Tab(items[i], myConn);
      System.out.println(t.getText() + ", " + t.getLink());
    }
    System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");

    /*
    //retrieve favorites tabs
    System.out.println("~~~ retrieve favorites tabs");
    ts = new TabSet("OPG-TabSet-Favorites-Default",myConn);
    items = ts.getItemsArray();
    for (int i=0; i<items.length; i++) {
    	Tab t =	null;
    	t = new Tab(items[i],myConn);
    	System.out.println(t.getText()+", "+t.getLink());
    }
    System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
    */

    /*
    //create a new tabset for
    System.out.println("~~~ create a new custom tabset tabs");
    personID = (long)1214; //shuhei's id
    long [] itemsTmp = null;
    ts = new TabSet("OPG-TabSet-Home-"+personID,myConn);
    if (ts == null || ts.getID() == 0) {
    	TabSet tsDef = new TabSet("OPG-TabSet-Home-Default", myConn);
              ts = new TabSet(myConn, personID);
              ts.setDescription("OPG-TabSet-Home-" + personID);
              ts.setCreator(personID);
              itemsTmp = tsDef.getItemsArray();
              for (int i=0; i<itemsTmp.length; i++) {
                  ts.addItem(itemsTmp[i], myConn);
              }
              ts.save(myConn, personID);
          }else{
          	items = ts.getItemsArray();
          	if(items.length==0){
          		TabSet tsDef = new TabSet("OPG-TabSet-Home-Default", myConn);
          		itemsTmp = tsDef.getItemsArray();
          		for (int i=0; i<itemsTmp.length; i++) {
                      ts.addItem(itemsTmp[i], myConn);
                  }
          		ts.save(myConn, personID);
          	}
          	System.out.println("contents of OPG-TabSet-Home-" + personID + ": "+ts.getID());
          	items = ts.getItemsArray();
      		for (int i=0; i<items.length; i++) {
      			Tab t = null;
      			t = new Tab(items[i],myConn);
      			System.out.println(t.getText()+", "+t.getLink());
      		}
          }


    //drop a tabset
    //System.out.println("~~~ drop a tabset");
    	//System.out.println(ts.getID()+" wiil be dropped");
    	//ts.drop(myConn,personID);
    	//ts.save(myConn);


    //update a tabset
    System.out.println("~~~ update a tabset");
    	//first, delete tabset contents
    	System.out.println("~~~~~~ deleting tabset content");
    	items = ts.getItemsArray();
    	for (int i=0; i<items.length; i++) {
    		Tab t = null;
    		t = new Tab(items[i],myConn);
    		if(t.getOwner()==personID){
    			System.out.println(t.getID()+" will be deleted");
    			t.drop(myConn,personID);
    		}
    	}

    	//second, clear tabset associations
    	System.out.println("~~~~~~ clearing tabset associations");
    	System.out.println(ts.getID()+" will be cleared");
    	ts.clearItems();
    	ts.save(myConn, personID);

    	//finally, create tab objects -> register them to a tabset
    	System.out.println("~~~~~~ create tab objects -> register them to a tabset");
    		//create definitions
    		Object[][] tConf = {	//this part will be rewritten using json...
    							{"Director","/director/index.html"},
    							{"Favorite New","../portlets/favorites-redux/favorites.jsp"}
    						  };

    		//iterate thru the object
    		for(int i=0;i<tConf.length;i++){
    				Tab t = new Tab();
    				t.setOwner(personID);
    				t.setText(tConf[i][0].toString());
    				t.setLink(tConf[i][1].toString());
    				t.save(myConn,personID);
    				ts.addItem(t.getID(), myConn);
    			}
    		ts.save(myConn, personID);
    */

    // rearrange tabs

    // retrieve (or create) home tabset for higashis (1214)

    System.out.println("~~~ create a new custom tabset tabs");
    personID = (long) 3676; // shuhei's id
    long[] idArray = null; // empty array to hold item ids
    long[] itemsTmp = null;
    ts = new TabSet("OPG-TabSet-Home-" + personID, myConn);
    if (ts == null || ts.getID() == 0) {
      TabSet tsDef = new TabSet("OPG-TabSet-Home-Default", myConn);
      ts = new TabSet(myConn, personID);
      ts.setDescription("OPG-TabSet-Home-" + personID);
      ts.setCreator(personID);
      itemsTmp = tsDef.getItemsArray();
      for (int i = 0; i < itemsTmp.length; i++) {
        ts.addItem(itemsTmp[i], myConn);
      }
      ts.save(myConn, personID);
    } else {
      items = ts.getItemsArray();

      /*
      if(items.length==0){
      	TabSet tsDef = new TabSet("OPG-TabSet-Home-Default", myConn);
      	itemsTmp = tsDef.getItemsArray();
      	for (int i=0; i<itemsTmp.length; i++) {
                 ts.addItem(itemsTmp[i], myConn);
             }
      	ts.save(myConn, personID);
      }
      */

      System.out.println("contents of OPG-TabSet-Home-" + personID + ": " + ts.getID());
      items = ts.getItemsArray();
      idArray = new long[items.length];
      for (int i = 0; i < items.length; i++) {
        Tab t = null;
        t = new Tab(items[i], myConn);
        idArray[i] = t.getID();
        System.out.println("tab text:  " + items[i]);
        System.out.println(idArray[i] + ", " + t.getText() + ", " + t.getLink());
      }
    }

    System.out.println("~~~~~~ rearrange tabs");

    int[] oa = {2, 1, 4, 3, 6, 5};
    // int[] oa = {1,2,3,4,5,6};
    ts.rearrange(myConn, personID, idArray, oa);
    System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");

    TabSet tsNew = null;
    long[] itemsNew = null;
    long[] idArrayNew = null;
    tsNew = new TabSet("OPG-TabSet-Home-" + personID, myConn);
    itemsNew = tsNew.getItemsArray();
    idArrayNew = new long[itemsNew.length];
    for (int i = 0; i < items.length; i++) {
      Tab tNew = null;
      tNew = new Tab(itemsNew[i], myConn);
      idArrayNew[i] = tNew.getID();
      System.out.println(idArrayNew[i] + ", " + tNew.getText() + ", " + tNew.getLink());
    }

    // release DB connection object
    myConn.release();
  }