Пример #1
0
  /**
   * @param request
   * @param tableCategoryId
   * @paqram includeAction if true, will load webactions also
   * @return elements are Table or WebAction
   */
  public List getChildrenOfTableCategory(
      HttpServletRequest request, int tableCategoryId, boolean includeAction) {
    TableManager manager = TableManager.getInstance();

    WebAction action;
    ArrayList cats = new ArrayList();
    Connection conn = null;
    HashMap webActionEnv = null;
    Table table;
    UserWebImpl userWeb =
        ((UserWebImpl)
            WebUtils.getSessionContextManager(request.getSession())
                .getActor(nds.util.WebKeys.USER));

    TableCategory tc = manager.getTableCategory(tableCategoryId);
    List children = tc.children();
    ArrayList catschild = new ArrayList();
    try {
      if (includeAction) {
        conn = QueryEngine.getInstance().getConnection();
        webActionEnv = new HashMap();
        webActionEnv.put("connection", conn);
        webActionEnv.put("httpservletrequest", request);
        webActionEnv.put("userweb", userWeb);
      }
      for (int j = 0; j < children.size(); j++) {
        if (children.get(j) instanceof Table) {
          table = (Table) children.get(j);
          if (!table.isMenuObject()) {
            continue;
          }
          try {
            WebUtils.checkTableQueryPermission(table.getName(), request);
          } catch (NDSSecurityException e) {
            continue;
          }
          // table is ok for current user to list
          catschild.add(table);
        } else if (children.get(j) instanceof WebAction) {
          if (includeAction) {
            action = (WebAction) children.get(j);
            if (action.canDisplay(webActionEnv)) catschild.add(action);
          }
        } else {
          throw new NDSRuntimeException(
              "Unsupported element in TableCategory children:" + children.get(j).getClass());
        }
      }
    } catch (Throwable t) {
      logger.error("Fail to load subsystem tree", t);
    } finally {
      try {
        if (conn != null) conn.close();
      } catch (Throwable e) {
      }
    }
    return catschild;
  }
Пример #2
0
  @Override
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    Long studentID = WebUtils.getStudentID(request);

    storage.delete(studentID);

    WebUtils.redirectToMainPage(request, response);
  }
Пример #3
0
  private void handleSignupPost(Request request, HttpServletResponse httpServletResponse)
      throws Exception {
    String userId = request.getParameter(PARAM_USER_ID);
    String userName = request.getParameter(PARAM_USER_NAME);
    String email = request.getParameter(PARAM_EMAIL);
    String stringPassword = request.getParameter(PARAM_PASSWORD);
    String stringPasswordConfirm = request.getParameter(PARAM_PASSWORD_CONFIRM);

    if (!stringPassword.equals(stringPasswordConfirm)) {
      WebUtils.redirectToError(
          "Mismatch between password and password confirmation", request, httpServletResponse);
      return;
    }

    SecureRandom secureRandom = new SecureRandom();
    String salt = "" + secureRandom.nextLong();
    byte[] password = User.computeHashedPassword(stringPassword, salt);
    User user = userDb.get(userId);
    if (user != null) {
      WebUtils.redirectToError(
          "There already exists a user with the ID " + userId, request, httpServletResponse);
      return;
    }

    user =
        new User(
            userId,
            userName,
            password,
            salt,
            email,
            new ArrayList<String>(),
            Config.getConfig().activateAccountsAtCreation,
            false);
    // ttt2 add confirmation by email, captcha, ...
    List<String> fieldErrors = user.checkFields();
    if (!fieldErrors.isEmpty()) {
      StringBuilder bld =
          new StringBuilder("Invalid values when trying to create user with ID ")
              .append(userId)
              .append("<br/>");
      for (String s : fieldErrors) {
        bld.append(s).append("<br/>");
      }
      WebUtils.redirectToError(bld.toString(), request, httpServletResponse);
      return;
    }

    // ttt2 2 clients can add the same userId simultaneously
    userDb.add(user);

    httpServletResponse.sendRedirect("/");
  }
Пример #4
0
 /**
  * MU_FAVORITE
  *
  * @throws Exception cyl
  * @param request
  * @return elements are Table or WebAction and menu list
  * @paqram includeAction if true?not now
  */
 public List getSubSystemsOfmufavorite(HttpServletRequest request) throws Exception {
   ArrayList mufavorite = new ArrayList();
   TableManager manager = TableManager.getInstance();
   // Table table;
   try {
     UserWebImpl userWeb =
         ((UserWebImpl)
             WebUtils.getSessionContextManager(request.getSession())
                 .getActor(nds.util.WebKeys.USER));
     int userid = userWeb.getUserId();
     List al =
         QueryEngine.getInstance()
             .doQueryList(
                 "select t.ad_table_id,t.fa_menu,t.menu_re,t.IS_REPORT from MU_FAVORITE t where t.ownerid="
                     + String.valueOf(userid)
                     + " group by t.ad_table_id,t.menu_no,t.fa_menu,t.menu_re,t.IS_REPORT,t.creationdate order by t.menu_no,t.creationdate asc");
     logger.debug("MU_FAVORITE size is " + String.valueOf(al.size()));
     if (al.size() > 0) {
       for (int i = 0; i < al.size(); i++) {
         // ArrayList catschild= new ArrayList();
         List als = (List) al.get(i);
         String fa_menu = (String) als.get(1);
         String menu_re = (String) als.get(2);
         String isreport = (String) als.get(3);
         int table_id = Tools.getInt(als.get(0), -1);
         Table table = manager.getTable(table_id);
         logger.debug(table.getName());
         /*
         if(!table.isMenuObject()){
                     	continue;
                     	//because many table is webaction not ismenuobject
                     }*/
         try {
           WebUtils.checkTableQueryPermission(table.getName(), request);
         } catch (NDSSecurityException e) {
           continue;
         }
         logger.debug("add_table    ->" + table.getName());
         ArrayList row = new ArrayList();
         row.add(fa_menu);
         row.add(menu_re);
         row.add(isreport);
         row.add(table);
         mufavorite.add(row);
       }
     }
   } catch (Throwable t) {
     logger.error("Fail to load mufavorite", t);
   }
   return mufavorite;
 }
Пример #5
0
  @Test
  public void findParameterValue() {
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("myKey1", "myValue1");
    params.put("myKey2_myValue2", "xxx");
    params.put("myKey3_myValue3.x", "xxx");
    params.put("myKey4_myValue4.y", new String[] {"yyy"});

    assertNull(WebUtils.findParameterValue(params, "myKey0"));
    assertEquals("myValue1", WebUtils.findParameterValue(params, "myKey1"));
    assertEquals("myValue2", WebUtils.findParameterValue(params, "myKey2"));
    assertEquals("myValue3", WebUtils.findParameterValue(params, "myKey3"));
    assertEquals("myValue4", WebUtils.findParameterValue(params, "myKey4"));
  }
Пример #6
0
  private void handleChangePasswordPost(Request request, HttpServletResponse httpServletResponse)
      throws Exception {

    LoginInfo loginInfo = userHelpers.getLoginInfo(request);
    if (loginInfo == null) {
      WebUtils.redirectToError("Couldn't determine the current user", request, httpServletResponse);
      return;
    }

    String userId = loginInfo.userId;
    String stringCrtPassword = request.getParameter(PARAM_CURRENT_PASSWORD);
    String stringNewPassword = request.getParameter(PARAM_PASSWORD);
    String stringNewPasswordConfirm = request.getParameter(PARAM_PASSWORD_CONFIRM);

    if (!stringNewPassword.equals(stringNewPasswordConfirm)) {
      showResult(
          "Mismatch between password and password confirmation",
          PATH_SETTINGS,
          request,
          httpServletResponse);
      return;
    }

    User user =
        userDb.get(
            userId); // ttt1 crashes for wrong ID; 2013.07.20 - no longer have an idea what this is
                     // about
    if (user == null) {
      WebUtils.redirectToError("Couldn't find the current user", request, httpServletResponse);
      return;
    }

    if (!user.checkPassword(stringCrtPassword)) {
      showResult("Incorrect current password", PATH_SETTINGS, request, httpServletResponse);
      return;
    }

    SecureRandom secureRandom = new SecureRandom();
    String salt = "" + secureRandom.nextLong();
    byte[] password = User.computeHashedPassword(stringNewPassword, salt);
    user.salt = salt;
    user.password = password;

    // ttt3 2 clients can change the password simultaneously
    userDb.add(user);

    // httpServletResponse.sendRedirect(PATH_SETTINGS);
    showResult("Password changed", PATH_SETTINGS, request, httpServletResponse);
  }
Пример #7
0
  /** Test of checkEmail method, of class WebUtils. */
  @Test
  public void testCheckEmail() {
    LOGGER.info("checkEmail");
    Assert.assertTrue(WebUtils.checkEmail("*****@*****.**"));
    Assert.assertTrue(WebUtils.checkEmail("*****@*****.**"));
    Assert.assertTrue(WebUtils.checkEmail("*****@*****.**"));
    Assert.assertTrue(WebUtils.checkEmail("*****@*****.**"));
    Assert.assertTrue(WebUtils.checkEmail("*****@*****.**"));

    Assert.assertFalse(WebUtils.checkEmail("*****@*****.**"));
    Assert.assertFalse(WebUtils.checkEmail("arturo@bipolar"));
    Assert.assertFalse(WebUtils.checkEmail("*****@*****.**"));
    Assert.assertFalse(WebUtils.checkEmail("*****@*****.**"));
    Assert.assertFalse(WebUtils.checkEmail("[email protected]."));
  }
Пример #8
0
  /**
   * @param request
   * @param subSystemId
   * @return
   */
  private boolean containsViewableActions(HttpServletRequest request, SubSystem ss) {
    List<WebAction> list = ss.getWebActions();
    Connection conn = null;
    try {
      UserWebImpl userWeb =
          ((UserWebImpl)
              WebUtils.getSessionContextManager(request.getSession())
                  .getActor(nds.util.WebKeys.USER));
      conn = QueryEngine.getInstance().getConnection();
      HashMap webActionEnv = new HashMap();
      webActionEnv.put("connection", conn);
      webActionEnv.put("httpservletrequest", request);
      webActionEnv.put("userweb", userWeb);

      for (int i = 0; i < list.size(); i++) {
        WebAction wa = list.get(i);
        if (wa.canDisplay(webActionEnv)) {
          return true;
        }
      }
    } catch (Throwable t) {
      logger.error("Fail to load subsystem webaction", t);
    } finally {
      try {
        if (conn != null) conn.close();
      } catch (Throwable te) {
      }
    }
    return false;
  }
Пример #9
0
  private void handleChangeSettingsPost(Request request, HttpServletResponse httpServletResponse)
      throws Exception {

    LoginInfo loginInfo = userHelpers.getLoginInfo(request);
    if (loginInfo == null) {
      WebUtils.redirectToError("Couldn't determine the current user", request, httpServletResponse);
      return;
    }

    String stringItemsPerPage = request.getParameter(PARAM_ITEMS_PER_PAGE);
    try {
      loginInfo.itemsPerPage = Integer.parseInt(stringItemsPerPage);
    } catch (Exception e) {
      showResult(
          "Error trying to set the items per page. Expected integer value but got "
              + stringItemsPerPage,
          PATH_SETTINGS,
          request,
          httpServletResponse);
      return;
    }
    loginInfo.style = request.getParameter(PARAM_STYLE);
    loginInfo.feedDateFormat =
        request.getParameter(PARAM_FEED_DATE_FORMAT); // ttt2 validate, better in JSP

    loginInfoDb.add(loginInfo);

    // httpServletResponse.sendRedirect(PATH_SETTINGS);
    showResult("Settings changed", "/", request, httpServletResponse);
  }
Пример #10
0
 private void handleOpenArticle(
     Request request, HttpServletResponse httpServletResponse, String target) throws Exception {
   try {
     int k1 = target.indexOf('/', 1);
     int k2 = target.indexOf('/', k1 + 1);
     String feedId = target.substring(k1 + 1, k2);
     String strSeq = target.substring(k2 + 1);
     int seq = Integer.parseInt(strSeq);
     Article article = articleDb.get(feedId, seq);
     LoginInfo loginInfo = userHelpers.getLoginInfo(request);
     // ttt2 using the link from a non-authenticated browser causes a NPE; maybe do something
     // better, e.g. sign up
     ReadArticlesColl readArticlesColl = readArticlesCollDb.get(loginInfo.userId, feedId);
     if (readArticlesColl == null) {
       readArticlesColl = new ReadArticlesColl(loginInfo.userId, feedId);
     }
     if (!readArticlesColl.isRead(seq)) {
       readArticlesColl.markRead(seq, Config.getConfig().maxSizeForReadArticles);
       readArticlesCollDb.add(readArticlesColl);
     }
     String s =
         URIUtil.encodePath(article.url)
             .replace("%3F", "?")
             .replace("%23", "#"); // ttt2 see how to do this right
     httpServletResponse.sendRedirect(s);
   } catch (Exception e) {
     WebUtils.showResult(
         String.format("Failed to get article for path %s. %s", target, e),
         "/",
         request,
         httpServletResponse);
   }
 }
Пример #11
0
  /**
   * Return the warmup log file (usually known only for already-finished jobs)
   *
   * @return the warmup log file, or null if not known or if it does not exist
   */
  public File getWarmupLogFile() {
    if (logFile == null) return null;

    String name = logFile.getName();
    String logFilePrefix = dbEngine;
    if (dbInstance != null) {
      logFilePrefix += "_" + dbInstance;
    }

    boolean ok = false;
    for (String logFilePrefixExt : WebUtils.getAllLogFilePrefixes(dbEngine, dbInstance)) {
      if (name.startsWith(logFilePrefixExt)) {
        name = logFilePrefix + "-warmup" + name.substring(logFilePrefixExt.length());
        ok = true;
        continue;
      }
    }
    if (!ok) {
      throw new IllegalStateException(
          "The log file does not have a valid prefix: " + logFile.getName());
    }

    File f = new File(logFile.getParentFile(), name);
    if (!f.exists()) f = null;
    if (f != null && !f.isFile()) f = null;

    return f;
  }
Пример #12
0
  /**
   * Get viewable subsystem list
   *
   * @param request
   * @return never null, elements are nds.schema.SubSystem
   */
  public List getSubSystems(HttpServletRequest request) {
    UserWebImpl userWeb =
        ((UserWebImpl)
            WebUtils.getSessionContextManager(request.getSession())
                .getActor(nds.util.WebKeys.USER));
    ArrayList subs = new ArrayList();
    if (userWeb.getUserId() == userWeb.GUEST_ID) {
      return subs;
    }
    List al = (List) userWeb.getProperty("subsystems"); // elements are subystem.id
    TableManager manager = TableManager.getInstance();
    if (al != null) {

      for (int i = 0; i < al.size(); i++) {
        int sid = ((Integer) al.get(i)).intValue();
        SubSystem ss = manager.getSubSystem(sid);
        if (ss != null) subs.add(ss);
      }
    } else {
      // search all tablecategoris for subsystem
      // add users subsystems param
      al = new ArrayList();
      String[] sub_list;
      try {
        String subsystems =
            (String)
                QueryEngine.getInstance()
                    .doQueryOne("SELECT subsystems from users where id=" + userWeb.getUserId());
        if (Validator.isNotNull(subsystems)) {
          sub_list = subsystems.split(",");
          for (int m = 0; m < sub_list.length; m++) {
            SubSystem usersub = manager.getSubSystem(sub_list[m].trim());

            if (usersub != null) {
              if (usersub.getId() == 10) continue;
              al.add(new Integer(usersub.getId()));
              subs.add(usersub);
            }
          }
          userWeb.setProperty("subsystems", al);
          return subs;
        }
      } catch (QueryException e) {
        logger.error("Fail to load subsystems from users", e);
      }

      for (int i = 0; i < manager.getSubSystems().size(); i++) {
        SubSystem ss = (SubSystem) manager.getSubSystems().get(i);
        if (containsViewableChildren(request, ss)) {
          al.add(new Integer(ss.getId()));
          subs.add(ss);
        }
      }
      userWeb.setProperty("subsystems", al);
    }
    return subs;
  }
  /**
   * Initialize log4j, including setting the web app root system property.
   *
   * @param servletContext the current ServletContext
   * @see WebUtils#setWebAppRootSystemProperty
   */
  public static void initLogging(ServletContext servletContext) {
    // Expose the web app root system property.
    if (exposeWebAppRoot(servletContext)) {
      WebUtils.setWebAppRootSystemProperty(servletContext);
    }

    // Only perform custom log4j initialization in case of a config file.
    String location = servletContext.getInitParameter(CONFIG_LOCATION_PARAM);
    if (location != null) {
      // Perform actual log4j initialization; else rely on log4j's default initialization.
      try {
        // Return a URL (e.g. "classpath:" or "file:") as-is;
        // consider a plain file path as relative to the web application root directory.
        if (!ResourceUtils.isUrl(location)) {
          // Resolve system property placeholders before resolving real path.
          location = SystemPropertyUtils.resolvePlaceholders(location);
          location = WebUtils.getRealPath(servletContext, location);
        }

        // Write log message to server log.
        servletContext.log("Initializing log4j from [" + location + "]");

        // Check whether refresh interval was specified.
        String intervalString = servletContext.getInitParameter(REFRESH_INTERVAL_PARAM);
        if (intervalString != null) {
          // Initialize with refresh interval, i.e. with log4j's watchdog thread,
          // checking the file in the background.
          try {
            long refreshInterval = Long.parseLong(intervalString);
            Log4jConfigurer.initLogging(location, refreshInterval);
          } catch (NumberFormatException ex) {
            throw new IllegalArgumentException(
                "Invalid 'log4jRefreshInterval' parameter: " + ex.getMessage());
          }
        } else {
          // Initialize without refresh check, i.e. without log4j's watchdog thread.
          Log4jConfigurer.initLogging(location);
        }
      } catch (FileNotFoundException ex) {
        throw new IllegalArgumentException(
            "Invalid 'log4jConfigLocation' parameter: " + ex.getMessage());
      }
    }
  }
Пример #14
0
 /** Test of generatePassword method, of class WebUtils. */
 @Test
 public void testGeneratePassword() {
   LOGGER.info("generatePassword");
   Pattern check = Pattern.compile("[A-Za-z0-9]{7}");
   Random random = new SecureRandom();
   for (int i = 0; i < 10000; i++) {
     String result = WebUtils.generatePassword(random);
     Assert.assertTrue(check.matcher(result).matches());
   }
 }
Пример #15
0
  /** Test of getWebAppUrl method, of class WebUtils. */
  @Test
  public void testGetWebAppUrl() {
    LOGGER.info("getWebAppUrl");

    String result = WebUtils.getWebAppUrl(hsrHttp80);
    Assert.assertEquals("http://www.bipolar.mx/bm", result);

    result = WebUtils.getWebAppUrl(hsrHttps443);
    Assert.assertEquals("https://www.bipolar.mx/bm", result);

    result = WebUtils.getWebAppUrl(hsrHttp8080);
    Assert.assertEquals("http://www.bipolar.mx:8080/bm", result);

    result = WebUtils.getWebAppUrl(hsrHttps8080);
    Assert.assertEquals("https://www.bipolar.mx:8080/bm", result);

    result = WebUtils.getWebAppUrl(hsrFtp21);
    Assert.assertEquals("ftp://www.bipolar.mx:21/bm", result);
  }
  /**
   * Befindet sich noch im Entwurfsstadium
   *
   * @throws InvalidPropertiesFormatException
   * @throws FileNotFoundException
   * @throws IOException
   */
  public RankingBean() throws InvalidPropertiesFormatException, FileNotFoundException, IOException {

    this.props =
        HelperMethods.loadPropertiesFromFileWithinWebcontainer(
            WebUtils.getWebappPath() + "/WEB-INF/userfrontend_gui.xml");

    // new list of oids (hits)
    this.listHitOID = new ArrayList<BigDecimal>();

    this.setupRankingList();
  }
 /**
  * Shut down log4j, properly releasing all file locks and resetting the web app root system
  * property.
  *
  * @param servletContext the current ServletContext
  * @see WebUtils#removeWebAppRootSystemProperty
  */
 public static void shutdownLogging(ServletContext servletContext) {
   servletContext.log("Shutting down log4j");
   try {
     Log4jConfigurer.shutdownLogging();
   } finally {
     // Remove the web app root system property.
     if (exposeWebAppRoot(servletContext)) {
       WebUtils.removeWebAppRootSystemProperty(servletContext);
     }
   }
 }
Пример #18
0
 private boolean checkOrigin(
     String serverName, int port, String originHeader, List<String> allowed) {
   MockHttpServletRequest servletRequest = new MockHttpServletRequest();
   ServerHttpRequest request = new ServletServerHttpRequest(servletRequest);
   servletRequest.setServerName(serverName);
   if (port != -1) {
     servletRequest.setServerPort(port);
   }
   request.getHeaders().set(HttpHeaders.ORIGIN, originHeader);
   return WebUtils.isValidOrigin(request, allowed);
 }
Пример #19
0
  /** Get localized text string */
  public final String getText(String key, String... values) {
    // Get string
    String string = WebUtils.getText(key);

    // Replace variables
    int param = 1;
    for (String v : values) {
      string = string.replace("{" + param + "}", v);
      ++param;
    }
    return string;
  }
Пример #20
0
  @Test
  public void parseMatrixVariablesString() {
    MultiValueMap<String, String> variables;

    variables = WebUtils.parseMatrixVariables(null);
    assertEquals(0, variables.size());

    variables = WebUtils.parseMatrixVariables("year");
    assertEquals(1, variables.size());
    assertEquals("", variables.getFirst("year"));

    variables = WebUtils.parseMatrixVariables("year=2012");
    assertEquals(1, variables.size());
    assertEquals("2012", variables.getFirst("year"));

    variables = WebUtils.parseMatrixVariables("year=2012;colors=red,blue,green");
    assertEquals(2, variables.size());
    assertEquals(Arrays.asList("red", "blue", "green"), variables.get("colors"));
    assertEquals("2012", variables.getFirst("year"));

    variables = WebUtils.parseMatrixVariables(";year=2012;colors=red,blue,green;");
    assertEquals(2, variables.size());
    assertEquals(Arrays.asList("red", "blue", "green"), variables.get("colors"));
    assertEquals("2012", variables.getFirst("year"));

    variables = WebUtils.parseMatrixVariables("colors=red;colors=blue;colors=green");
    assertEquals(1, variables.size());
    assertEquals(Arrays.asList("red", "blue", "green"), variables.get("colors"));
  }
Пример #21
0
  /**
   * Create an instance of a Job from a list of arguments
   *
   * @param arguments the arguments
   */
  public Job(final List<String> arguments) {
    this();

    this.arguments = new ArrayList<String>();
    this.arguments.add(Bench.graphdbBenchDir + "/runBenchmarkSuite.sh");

    // Copy the + arguments first

    for (int i = 0; i < arguments.size(); i++) {
      String a = arguments.get(i);
      if (a.startsWith("+")) this.arguments.add(a);
    }

    // Further arguments that we need to run the job through the web interface

    this.arguments.add("--dumb-terminal");

    // Copy the arguments and extract the database engine and instance names

    for (int i = 0; i < arguments.size(); i++) {
      String a = arguments.get(i);
      if (a.startsWith("+")) continue;

      if (a.startsWith("--")) {
        if (DatabaseEngine.ENGINES.containsKey(a.substring(2))) {
          if (dbEngine != null) {
            throw new IllegalArgumentException("Cannot specify more than one database engine");
          }
          dbEngine = a.substring(2);
        }
      }

      if (a.equals("--database") || a.equals("-d")) {
        if (i + 1 >= arguments.size() || arguments.get(i + 1).startsWith("-")) {
          throw new IllegalArgumentException("The " + a + " option requires an argument");
        }
        if (dbInstance != null) {
          throw new IllegalArgumentException("Cannot specify more than one database instance");
        }
        dbInstance = arguments.get(i + 1);
        WebUtils.asssertDatabaseInstanceNameValidity(dbInstance);
      }

      this.arguments.add(a);
    }

    if (dbEngine == null) {
      throw new IllegalArgumentException("No database engine is specified");
    }
  }
Пример #22
0
 @Test
 public void extractFilenameFromUrlPath() {
   assertEquals("index", WebUtils.extractFilenameFromUrlPath("index.html"));
   assertEquals("index", WebUtils.extractFilenameFromUrlPath("/index.html"));
   assertEquals("view", WebUtils.extractFilenameFromUrlPath("/products/view.html"));
   assertEquals("view", WebUtils.extractFilenameFromUrlPath("/products/view.html?param=a"));
   assertEquals("view", WebUtils.extractFilenameFromUrlPath("/products/view.html?param=/path/a"));
   assertEquals(
       "view", WebUtils.extractFilenameFromUrlPath("/products/view.html?param=/path/a.do"));
 }
 @Override
 public void addLink(Link link) throws RPCException {
   try {
     Map<String, String> m = WebUtils.pageInfo(link.getAddress());
     if (m.get("title") != null
         && !m.get("title").equals("")
         && (link.getName() == null || link.getName().equals(""))) {
       link.setName(m.get("title"));
     }
     if (m.get("description") != null
         && m.get("description").equals("")
         && (link.getDescription() == null || link.getDescription().equals(""))) {
       link.setDescription(m.get("description"));
     }
     if (link.getName() == null || link.getName().equals("")) {
       link.setName(link.getAddress());
     }
     log.info(link);
     linkDAO.add(link);
   } catch (Exception e) {
     throw new RPCException(e.getMessage());
   }
 }
  private Archive<?> handleArchive(
      WebArchive applicationArchive,
      Collection<Archive<?>> auxiliaryArchives,
      WebArchive protocol,
      Processor processor) {
    if (applicationArchive.contains(WEB_XML_PATH)) {
      WebAppDescriptor applicationWebXml =
          Descriptors.importAs(WebAppDescriptor.class)
              .from(applicationArchive.get(WEB_XML_PATH).getAsset().openStream());

      // SHRINKWRAP-187, to eager on not allowing overrides, delete it first
      applicationArchive.delete(WEB_XML_PATH);
      applicationArchive.setWebXML(
          new StringAsset(WebUtils.mergeWithDescriptor(applicationWebXml).exportAsString()));
      applicationArchive.merge(protocol, Filters.exclude(".*web\\.xml.*"));
    } else {
      applicationArchive.merge(protocol);
    }
    applicationArchive.addAsLibraries(auxiliaryArchives.toArray(new Archive<?>[0]));

    processor.process(applicationArchive);
    return applicationArchive;
  }
  private void setupRankingList() {

    RestMessage rms = WebUtils.prepareRestTransmission("UsageStatistics/").sendGetRestMessage();
    if ((rms == null)
        || (rms.getListEntrySets().isEmpty())
        || (rms.getStatus() != RestStatusEnum.OK)) {
      logger.warn("received no UsageData_Ranking data ");
      return;
    }
    listHitOID = new ArrayList<BigDecimal>();

    for (RestEntrySet res : rms.getListEntrySets()) {
      Iterator<String> it = res.getKeyIterator();
      String key = "";
      while (it.hasNext()) {
        key = (String) it.next();

        if ("object_id".equals(key)) {
          listHitOID.add(new BigDecimal(res.getValue(key)));
          logger.info("Key" + key + ": " + res.getValue(key) + "");
        }
      }
    }
  }
Пример #26
0
  /**
   * Return table categories and table that user has view permission
   *
   * @param request
   * @param subSystemId
   * @return never null, elements are List, containing 2 elements: 1)when first element is
   *     nds.schema.TableCategory, then second will be java.util.List (nds.schema.Table or
   *     nds.schema.WebAction) 2) when first element is nds.schema.WebAction, then second is null
   */
  public List getTableCategories(
      HttpServletRequest request, int subSystemId, boolean includeActions) {
    // Create categories and their tables in hashtable
    TableManager manager = TableManager.getInstance();
    // Iterator tables = manager.getAllTables().iterator();
    // Hashtable categories = new Hashtable(50,20); // key:Integer(category id), values :List of
    // table
    SubSystem ss;
    Integer tableCategoryId;
    Table table;
    WebAction action;
    ArrayList cats = new ArrayList();
    Connection conn = null;
    HashMap webActionEnv = null;
    try {
      UserWebImpl userWeb =
          ((UserWebImpl)
              WebUtils.getSessionContextManager(request.getSession())
                  .getActor(nds.util.WebKeys.USER));
      if (includeActions) {
        conn = QueryEngine.getInstance().getConnection();
        webActionEnv = new HashMap();
        webActionEnv.put("connection", conn);
        webActionEnv.put("httpservletrequest", request);
        webActionEnv.put("userweb", userWeb);
      }
      List categories = manager.getSubSystem(subSystemId).children();
      for (int i = 0; i < categories.size(); i++) {
        Object o = categories.get(i); // TableCategory or WebAction
        if (o instanceof TableCategory) {
          TableCategory tc = (TableCategory) o;
          List children = tc.children();
          ArrayList catschild = new ArrayList();
          for (int j = 0; j < children.size(); j++) {
            if (children.get(j) instanceof Table) {
              table = (Table) children.get(j);
              if (!table.isMenuObject()) {
                continue;
              }
              try {
                WebUtils.checkTableQueryPermission(table.getName(), request);
              } catch (NDSSecurityException e) {
                continue;
              }
              // table is ok for current user to list
              catschild.add(table);
            } else if (children.get(j) instanceof WebAction) {
              if (includeActions) {
                action = (WebAction) children.get(j);
                if (action.canDisplay(webActionEnv)) catschild.add(action);
              }
            } else {
              throw new NDSRuntimeException(
                  "Unsupported element in TableCategory children:" + children.get(j).getClass());
            }
          }
          if (catschild.size() > 0) {
            // show this category
            ArrayList row = new ArrayList();
            row.add(tc);
            row.add(catschild);
            cats.add(row);
          }
        } else if (o instanceof WebAction) {
          if (includeActions && ((WebAction) o).canDisplay(webActionEnv)) {
            ArrayList row = new ArrayList();
            row.add(o);
            row.add(Collections.EMPTY_LIST);
            cats.add(row);
          }
        } else {
          throw new NDSException(
              "Unexpected class in subsystem (id=" + subSystemId + "), class is " + o.getClass());
        }
      }
    } catch (Throwable t) {
      logger.error("Fail to load subsystem tree", t);
    } finally {
      try {
        if (conn != null) conn.close();
      } catch (Throwable e) {
      }
    }

    return cats;
  }
Пример #27
0
  /**
   * Load from an HTTP request
   *
   * @param request the HTTP request from which to create the job
   * @param _dbEngine a specific database engine name to use instead of the one from the request
   * @param _dbInstance a specific database instance to use instead of the one from the request
   */
  protected void loadFromRequest(HttpServletRequest request, String _dbEngine, String _dbInstance) {

    arguments = new ArrayList<String>();
    status = -1;
    executionCount = 0;
    executionTime = null;
    logFile = null;

    // Get the relevant configuration

    boolean provenanceEnabled = Bench.getBooleanProperty(Bench.CPL_ENABLED, true);
    boolean warmupEnabled = Bench.getBooleanProperty(Bench.WARMUP_ENABLED, true);

    // Get the request arguments

    dbEngine = WebUtils.getStringParameter(request, "database_name");
    dbInstance = WebUtils.getStringParameter(request, "database_instance");
    if (_dbEngine != null) {
      dbEngine = _dbEngine;
      dbInstance = _dbInstance;
      if (dbInstance != null) {
        if (dbInstance.equals("<new>")) {
          dbInstance = WebUtils.getStringParameter(request, "new_database_instance");
        }
      }
    }
    if (dbInstance != null) {
      if (dbInstance.equals("")) dbInstance = null;
    }
    if (!DatabaseEngine.ENGINES.containsKey(dbEngine)) {
      throw new IllegalArgumentException("Unknown database engine: " + dbEngine);
    }
    if (dbInstance != null) {
      WebUtils.asssertDatabaseInstanceNameValidity(dbInstance);
    }

    String s_annotation = WebUtils.getStringParameter(request, "annotation");
    String s_txBuffer = WebUtils.getStringParameter(request, "tx_buffer");
    String s_opCount = WebUtils.getStringParameter(request, "op_count");
    String s_warmupOpCount = WebUtils.getStringParameter(request, "warmup_op_count");
    String s_kHops = WebUtils.getStringParameter(request, "k_hops");

    boolean useJRockit = WebUtils.getBooleanParameter(request, "use_jrockit", false);
    boolean noProvenance = WebUtils.getBooleanParameter(request, "no_provenance", false);
    boolean forceBlueprints = WebUtils.getBooleanParameter(request, "force_blueprints", false);
    boolean useStoredProcedures =
        WebUtils.getBooleanParameter(request, "use_stored_procedures", false);
    boolean noWarmup = WebUtils.getBooleanParameter(request, "no_warmup", false);
    boolean noCachePollution = WebUtils.getBooleanParameter(request, "no_cache_pollution", false);
    boolean updateDirectly = WebUtils.getBooleanParameter(request, "update_directly", false);
    boolean iostat = WebUtils.getBooleanParameter(request, "iostat", false);
    String s_javaHeapSize = WebUtils.getStringParameter(request, "java_heap_size");
    String s_dbCacheSize = WebUtils.getStringParameter(request, "db_cache_size");

    boolean ingestAsUndirected =
        WebUtils.getBooleanParameter(request, "ingest_as_undirected", false);
    String s_ingestFile = WebUtils.getStringParameter(request, "ingest_file");
    String s_ingestWarmupFile = WebUtils.getStringParameter(request, "ingest_warmup_file");

    String s_generateModel = WebUtils.getStringParameter(request, "generate_model");
    String s_generateBarabasiN = WebUtils.getStringParameter(request, "generate_barabasi_n");
    String s_generateBarabasiM = WebUtils.getStringParameter(request, "generate_barabasi_m");

    String s_vertexPropertyKeys = WebUtils.getStringParameter(request, "vertex_property_keys");
    String s_edgePropertyKeys = WebUtils.getStringParameter(request, "edge_property_keys");
    String s_propertyKeys = combinePropertyKeys(s_vertexPropertyKeys, s_edgePropertyKeys);
    String s_edgeCondProp = WebUtils.getStringParameter(request, "edge_cond_prop");

    String s_edgeLabels = WebUtils.getStringParameter(request, "edge_labels");
    String s_edgeLabelsNormalized = combinePropertyKeys(s_edgeLabels, null);

    // Get the workloads

    String[] a_workloads = WebUtils.getStringParameterValues(request, "workloads");
    HashMap<String, Workload> workloads = new HashMap<String, Workload>();

    boolean usesOpCount = false;
    boolean hasUpdates = false;
    @SuppressWarnings("unused")
    boolean hasLoadUpdates = false;
    boolean hasNonLoadUpdates = false;

    if (a_workloads != null) {
      for (String w : a_workloads) {

        Workload workload = Workload.WORKLOADS.get(w);
        if (workload == null) throw new IllegalArgumentException("Unknown workload: " + w);

        workloads.put(w, workload);

        if (workload.isUsingOpCount()) usesOpCount = true;
        if (workload.isUpdate()) {
          hasUpdates = true;
          if (workload.getUpdateCategory() == Workload.UpdateCategory.LOAD_UPDATE)
            hasLoadUpdates = true;
          if (workload.getUpdateCategory() != Workload.UpdateCategory.LOAD_UPDATE)
            hasNonLoadUpdates = true;
        }
      }
    }

    // Build the list of command-line arguments

    arguments.add(Bench.graphdbBenchDir + "/runBenchmarkSuite.sh");

    if (useJRockit) {
      arguments.add("+jrockit");
    }

    if (s_javaHeapSize != null) {
      if (!s_javaHeapSize.equalsIgnoreCase(BenchmarkMicro.DEFAULT_JVM_HEAP_SIZE)) {
        arguments.add("+memory:" + s_javaHeapSize);
      }
    }

    arguments.add("--dumb-terminal");

    if (dbEngine != null) {
      arguments.add("--" + dbEngine);
    }
    if (dbInstance != null) {
      arguments.add("--database");
      arguments.add(dbInstance);
    }
    if (s_annotation != null) {
      arguments.add("--annotation");
      arguments.add(s_annotation);
    }

    if (s_dbCacheSize != null) {
      if (!s_dbCacheSize.equals(
          Bench.getProperty(Bench.DB_CACHE_SIZE, "" + GlobalConfig.databaseCacheSize))) {
        arguments.add("--db-cache-size");
        arguments.add(s_dbCacheSize);
      }
    }

    if (s_txBuffer != null) {
      if (!s_txBuffer.equals("" + BenchmarkMicro.DEFAULT_NUM_THREADS)) {
        arguments.add("--tx-buffer");
        arguments.add(s_txBuffer);
      }
    }

    if (noProvenance && provenanceEnabled) {
      arguments.add("--no-provenance");
    }

    if (noCachePollution) {
      arguments.add("--no-cache-pollution");
    }

    if (noWarmup && warmupEnabled) {
      arguments.add("--no-warmup");
    }

    if (forceBlueprints) {
      arguments.add("--force-blueprints");
    }

    if (useStoredProcedures) {
      arguments.add("--use-stored-procedures");
    }

    if (updateDirectly && hasUpdates && hasNonLoadUpdates) {
      arguments.add("--update-directly");
    }

    if (iostat) {
      arguments.add("--iostat");
    }

    if (a_workloads != null) {
      for (String s : a_workloads) {
        arguments.add("--" + s);
        if ("ingest".equals(s) && s_ingestFile != null) {
          arguments.add(s_ingestFile);
        }
        if ("incr-ingest".equals(s) && s_ingestFile != null) {
          arguments.add(s_ingestFile);
        }
        if ("generate".equals(s) && s_generateModel != null) {
          arguments.add(s_generateModel);
        }
        if ("create-index".equals(s)
            && s_propertyKeys != null
            && !BenchmarkMicro.DEFAULT_PROPERTY_KEYS.equals(s_propertyKeys)) {
          arguments.add(s_propertyKeys);
        }
        if ("get-index".equals(s)
            && s_propertyKeys != null
            && !BenchmarkMicro.DEFAULT_PROPERTY_KEYS.equals(s_propertyKeys)) {
          arguments.add(s_propertyKeys);
        }
        if ("get-property".equals(s)
            && s_propertyKeys != null
            && !BenchmarkMicro.DEFAULT_PROPERTY_KEYS.equals(s_propertyKeys)) {
          arguments.add(s_propertyKeys);
        }
        if ("get-label".equals(s)
            && s_edgeLabelsNormalized != null
            && !BenchmarkMicro.DEFAULT_EDGE_LABELS.equals(s_edgeLabelsNormalized)) {
          arguments.add(s_edgeLabelsNormalized);
        }
        if ("get-k-label".equals(s)
            && s_edgeLabelsNormalized != null
            && !BenchmarkMicro.DEFAULT_EDGE_LABELS.equals(s_edgeLabelsNormalized)) {
          arguments.add(s_edgeLabelsNormalized);
        }
      }
    }

    if (usesOpCount) {
      if (s_opCount != null) {
        if (!s_opCount.equals("" + BenchmarkMicro.DEFAULT_OP_COUNT)) {
          arguments.add("--op-count");
          arguments.add(s_opCount);
        }
      }
      if (s_warmupOpCount != null) {
        if (!s_warmupOpCount.equals(s_opCount) && !noWarmup && warmupEnabled) {
          arguments.add("--warmup-op-count");
          arguments.add(s_warmupOpCount);
        }
      }
    }

    if (workloads.containsKey("get-k")) {
      if (s_kHops != null) {
        if (!s_kHops.equals("" + BenchmarkMicro.DEFAULT_K_HOPS)) {
          arguments.add("--k-hops");
          arguments.add(s_kHops);
        }
      }
    }

    if (s_edgeCondProp != null
        && !BenchmarkMicro.DEFAULT_EDGE_CONDITIONAL_PROPERTY_KEY.equals(s_edgeCondProp)) {
      if (workloads.containsKey("get")
          || workloads.containsKey("get--micro")
          || workloads.containsKey("get--traversals")
          || workloads.containsKey("get-k")
          || workloads.containsKey("get-label")
          || workloads.containsKey("get-k-label")) {
        arguments.add("--edge-cond-prop");
        arguments.add(s_edgeCondProp);
      }
    }

    if (workloads.containsKey("ingest") || workloads.containsKey("incr-ingest")) {
      if (ingestAsUndirected) {
        arguments.add("--ingest-as-undirected");
      }
      if (s_ingestWarmupFile != null) {
        if (!s_ingestWarmupFile.equals(s_ingestFile)) {
          arguments.add("--warmup-ingest");
          arguments.add(s_ingestWarmupFile);
        }
      }
    }

    if (workloads.containsKey("generate")) {
      if (s_generateModel == null || "barabasi".equals(s_generateModel)) {
        if (s_generateBarabasiN != null) {
          if (!s_generateBarabasiN.equals("" + BenchmarkMicro.DEFAULT_BARABASI_N)) {
            arguments.add("--barabasi-n");
            arguments.add(s_generateBarabasiN);
          }
        }
        if (s_generateBarabasiM != null) {
          if (!s_generateBarabasiM.equals("" + BenchmarkMicro.DEFAULT_BARABASI_M)) {
            arguments.add("--barabasi-m");
            arguments.add(s_generateBarabasiM);
          }
        }
      }
    }
  }
Пример #28
0
 @Override
 public void init(ServletConfig config) throws ServletException {
   _app = WebUtils.getApp(config);
 }
  private Archive<?> handleArchive(
      EnterpriseArchive applicationArchive,
      Collection<Archive<?>> auxiliaryArchives,
      WebArchive protocol,
      Processor processor,
      TestDeployment testDeployment) {
    Map<ArchivePath, Node> applicationArchiveWars =
        applicationArchive.getContent(Filters.include(".*\\.war"));
    if (applicationArchiveWars.size() == 1) {
      ArchivePath warPath = applicationArchiveWars.keySet().iterator().next();
      try {
        handleArchive(
            applicationArchive.getAsType(WebArchive.class, warPath),
            new ArrayList<
                Archive<
                    ?>>(), // reuse the War handling, but Auxiliary Archives should be added to the
                           // EAR, not the WAR
            protocol,
            processor);
      } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException(
            "Can not manipulate war's that are not of type " + WebArchive.class, e);
      }
    } else if (applicationArchiveWars.size() > 1) {
      Archive<?> archiveToTest = testDeployment.getArchiveForEnrichment();
      if (archiveToTest == null) {
        throw new UnsupportedOperationException(
            "Multiple WebArchives found in "
                + applicationArchive.getName()
                + ". Can not determine which to enrich");
      } else if (!archiveToTest.getName().endsWith(".war")) {
        // TODO: Removed throwing an exception when EJB modules are supported as well
        throw new UnsupportedOperationException("Archive to test is not a WebArchive!");
      } else {
        handleArchive(
            archiveToTest.as(WebArchive.class),
            new ArrayList<
                Archive<
                    ?>>(), // reuse the War handling, but Auxiliary Archives should be added to the
                           // EAR, not the WAR
            protocol,
            processor);
      }
    } else {
      // SHRINKWRAP-187, to eager on not allowing overrides, delete it first
      protocol.delete(WEB_XML_PATH);
      applicationArchive.addAsModule(
          protocol.setWebXML(new StringAsset(WebUtils.createNewDescriptor().exportAsString())));

      if (applicationArchive.contains(APPLICATION_XML_PATH)) {
        ApplicationDescriptor applicationXml =
            Descriptors.importAs(ApplicationDescriptor.class)
                .from(applicationArchive.get(APPLICATION_XML_PATH).getAsset().openStream());

        applicationXml.webModule(
            protocol.getName(), ServletUtil.calculateContextRoot(protocol.getName()));

        // SHRINKWRAP-187, to eager on not allowing overrides, delete it first
        applicationArchive.delete(APPLICATION_XML_PATH);
        applicationArchive.setApplicationXML(new StringAsset(applicationXml.exportAsString()));
      }

      processor.process(protocol);
    }
    applicationArchive.addAsLibraries(auxiliaryArchives.toArray(new Archive<?>[0]));
    return applicationArchive;
  }
Пример #30
0
  /**
   * menu action
   *
   * @throws Exception cyl
   * @param request
   * @param tableCategoryId desgin menu list
   * @paqram includeAction if true, will load webactions also
   * @return elements are Table or WebAction and menu list
   */
  public List getChildrenOfTableCategorybymenu(
      HttpServletRequest request, int tableCategoryId, boolean includeAction) throws Exception {
    TableManager manager = TableManager.getInstance();

    WebAction action;
    ArrayList cats = new ArrayList();
    List children = new ArrayList();
    Connection conn = null;
    HashMap webActionEnv = null;
    Table table;
    List al =
        QueryEngine.getInstance()
            .doQueryList(
                "select e.id,e.name from ad_table g,AD_ACCORDION e where g.AD_ACCORDION_id=e.id and g.ad_tablecategory_id="
                    + tableCategoryId
                    + " group by e.id,e.name,e.orderno order by e.orderno asc");
    UserWebImpl userWeb =
        ((UserWebImpl)
            WebUtils.getSessionContextManager(request.getSession())
                .getActor(nds.util.WebKeys.USER));
    TableCategory tc = manager.getTableCategory(tableCategoryId);
    if (tc != null) children = tc.children();

    // ArrayList prow= new ArrayList();
    if (al.size() > 0) {
      for (int i = 0; i < al.size(); i++) {
        List als = (List) al.get(i);
        int ACCORDION = Tools.getInt(als.get(0), -1);
        logger.debug("ACCORDION~~~~~~~~~~" + String.valueOf(ACCORDION));
        ArrayList catschild = new ArrayList();
        String ACCORDION_name = (String) als.get(1);
        try {
          if (includeAction) {
            conn = QueryEngine.getInstance().getConnection();
            webActionEnv = new HashMap();
            webActionEnv.put("connection", conn);
            webActionEnv.put("httpservletrequest", request);
            webActionEnv.put("userweb", userWeb);
          }
          for (int j = 0; j < children.size(); j++) {
            if (children.get(j) instanceof Table) {
              table = (Table) children.get(j);
              // logger.debug("getAccordid~~~~~~~~~~"+String.valueOf(table.getAccordid()));
              if (!table.isMenuObject()) {
                continue;
              } else if (ACCORDION != table.getAccordid()) {
                // logger.debug(String.valueOf(ACCORDION)+"!="+String.valueOf(table.getAccordid()));
                continue;
              }
              try {
                WebUtils.checkTableQueryPermission(table.getName(), request);
              } catch (NDSSecurityException e) {
                continue;
              }
              // table is ok for current user to list
              logger.debug(String.valueOf(ACCORDION) + "&&" + String.valueOf(table.getAccordid()));
              catschild.add(table);
            } else if (children.get(j) instanceof WebAction) {
              if (includeAction) {
                action = (WebAction) children.get(j);
                if (action.canDisplay(webActionEnv) && (action.getAcordionId() == ACCORDION)) {
                  logger.debug("add action" + String.valueOf(ACCORDION));
                  //				        			System.out.print("add action"+String.valueOf(ACCORDION));
                  //				        			System.out.print("action name"+String.valueOf(action.getName()));
                  //				        			System.out.print("ACCORDION name"+String.valueOf(ACCORDION));
                  //				        			System.out.print("action
                  // name"+String.valueOf(action.getAcordionId()));
                  catschild.add(action);
                }
              }
            } else {
              throw new NDSRuntimeException(
                  "Unsupported element in TableCategory children:" + children.get(j).getClass());
            }
          }
        } catch (Throwable t) {
          logger.error("Fail to load subsystem tree", t);
        } finally {
          try {
            if (conn != null) conn.close();
          } catch (Throwable e) {
          }
        }
        if (catschild.size() > 0) {
          // show this category
          ArrayList row = new ArrayList();
          row.add(ACCORDION_name);
          row.add(catschild);
          cats.add(row);
        }
      }
      return cats;
    } else {
      ArrayList catschild1 = new ArrayList();
      try {
        if (includeAction) {
          conn = QueryEngine.getInstance().getConnection();
          webActionEnv = new HashMap();
          webActionEnv.put("connection", conn);
          webActionEnv.put("httpservletrequest", request);
          webActionEnv.put("userweb", userWeb);
        }
        for (int j = 0; j < children.size(); j++) {
          if (children.get(j) instanceof Table) {
            table = (Table) children.get(j);
            if (!table.isMenuObject()) {
              continue;
            }
            try {
              WebUtils.checkTableQueryPermission(table.getName(), request);
            } catch (NDSSecurityException e) {
              continue;
            }
            // table is ok for current user to list
            catschild1.add(table);
          } else if (children.get(j) instanceof WebAction) {
            if (includeAction) {
              action = (WebAction) children.get(j);
              if (action.canDisplay(webActionEnv)) catschild1.add(action);
            }
          } else {
            throw new NDSRuntimeException(
                "Unsupported element in TableCategory children:" + children.get(j).getClass());
          }
        }
      } catch (Throwable t) {
        logger.error("Fail to load subsystem tree", t);
      } finally {
        try {
          if (conn != null) conn.close();
        } catch (Throwable e) {
        }
      }
      if (catschild1.size() > 0) {
        // show this category
        ArrayList row = new ArrayList();
        row.add(tc.getName());
        row.add(catschild1);
        cats.add(row);
      }
    }
    return cats;
  }