Package com.data2semantics.yasgui.server.db

Examples of com.data2semantics.yasgui.server.db.DbHelper


      //parse json from request
      JSONObject jsonObj = null;
      jsonObj = getJsonObject(request);
   
     
      DbHelper dbHelper = new DbHelper(new File(getServletContext().getRealPath("/")), request);
     
      //is user logged in?
      int userId = dbHelper.getUserId();
      if (userId < 0) {
        response.sendError(HttpServletResponse.SC_FORBIDDEN, "You should be logged in before submitting completions");
        return;
      }
     
     
      FetchType type = getTypeFromJson(jsonObj);
      String endpoint = getEndpointFromJson(jsonObj);
      JSONArray completions = jsonObj.getJSONArray(AutocompleteKeys.REQUEST_COMPLETIONS);
     
      //does endpoint already exist as a public endpoint?? If so, ignore..
      try {
        dbHelper.getEndpointId(endpoint, EndpointPrivateFlag.PUBLIC);
        //hmm, no exception thrown. there is a public version of this endpoint!!!
        response.sendError(HttpServletResponse.SC_CONFLICT, "Endpoint " + endpoint + " is stored as -public- endpoint already. Using this endpoint url as a private endpoint is not allowed");
        return;
      } catch (EndpointIdException e) {
        //this is fine ;)
      }
     
      //try to get endpoint id for this specific user
      int endpointId;
      try {
        endpointId = dbHelper.getEndpointId(endpoint, EndpointPrivateFlag.OWN);
      } catch (EndpointIdException e) {
        //endpoint does not exist yet for this user. create a private one!
        endpointId = dbHelper.generateIdForEndpoint(endpoint, AccessibilityStatus.INACCESSIBLE)
      }
      //clear previous fetches for this endpoint!
      dbHelper.clearPreviousAutocompletionFetches(endpointId, FetchMethod.QUERY_RESULTS, type);
     
      dbHelper.storeCompletionFetchesFromLocalhost(endpointId, type, FetchMethod.QUERY_RESULTS, completions);
      //done!
      response.setStatus(HttpServletResponse.SC_NO_CONTENT);
     
     
    } catch (JSONException e) {
View Full Code Here


 
  /**
   * Save the unique identifier in our DB. Store all user detail info as well if applicable
   */
  public void saveIdentifierForUniqueId(File configDir, UserDetails userDetails) throws ClassNotFoundException, FileNotFoundException, SQLException, IOException, org.json.JSONException, ParseException {
    DbHelper db = new DbHelper(configDir);
    db.storeUserInfo(userDetails);
  }
View Full Code Here

    UserDetails userDetails = new UserDetails();
    userDetails.setOpenId(HttpCookies.getCookieValue(request, openIdCookieName));
    userDetails.setUniqueId(HttpCookies.getCookieValue(request, uniqueIdCookieName));
    if (userDetails.getOpenId() != null && userDetails.getUniqueId() != null) {
      //get more info
      DbHelper db = new DbHelper(configDir, request);
      userDetails = db.getUserDetails(userDetails);
    }
   
   
    return userDetails;
  }
View Full Code Here

  public static void store(DbHelper dbHelper, String query, String endpoint, boolean debug) throws SQLException {
    QueryCompletionExtractor extractor = new QueryCompletionExtractor(dbHelper, query, endpoint, debug);
    extractor.analyzeAndStore();
  }
  public static void main (String[] args) throws ClassNotFoundException, FileNotFoundException, JSONException, SQLException, IOException, ParseException {
    DbHelper dbHelper = new DbHelper(new File("src/main/webapp/"));
    String query = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" +
        "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" +
        "\n" +
        "SELECT DISTINCT * WHERE {\n" +
        "  ?bla rdf:type rdfs:Class\n" +
View Full Code Here

    return endpoints;
  }

  @Override
  public void addBookmark(Bookmark bookmark) throws IllegalArgumentException, FetchException, OpenIdException {
    DbHelper db = null;
    try {
      db = new DbHelper(new File(getServletContext().getRealPath("/")), getThreadLocalRequest());
      db.addBookmarks(bookmark);
    } catch (SQLException e) {
      e.printStackTrace();
      throw new FetchException(e.getMessage(), e);
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
      throw new FetchException(e.getMessage(), e);
    } catch (FileNotFoundException e) {
      e.printStackTrace();
      throw new FetchException(e.getMessage(), e);
    } catch (JSONException e) {
      e.printStackTrace();
      throw new FetchException(e.getMessage(), e);
    } catch (IOException e) {
      e.printStackTrace();
      throw new FetchException(e.getMessage(), e);
    } catch (ParseException e) {
      e.printStackTrace();
      throw new FetchException(e.getMessage(), e);
    } finally {
      if (db != null)
        db.close();
    }
  }
View Full Code Here

public class AutocompletionsInfoResponseCreator {
 
  private DbHelper dbHelper;

  private AutocompletionsInfoResponseCreator(HttpServletRequest request, HttpServletResponse response, File webappDir) throws ClassNotFoundException, FileNotFoundException, JSONException, SQLException, IOException, ParseException {
    this.dbHelper = new DbHelper(webappDir, request);
   
  }
View Full Code Here

        db.close();
    }
  }

  public Bookmark[] getBookmarks() throws IllegalArgumentException, FetchException, OpenIdException {
    DbHelper db = null;
    Bookmark[] bookmarks = null;
    try {
      db = new DbHelper(new File(getServletContext().getRealPath("/")), getThreadLocalRequest());
      bookmarks = db.getBookmarks();
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
      throw new FetchException(e.getMessage(), e);
    } catch (FileNotFoundException e) {
      e.printStackTrace();
      throw new FetchException(e.getMessage(), e);
    } catch (JSONException e) {
      e.printStackTrace();
      throw new FetchException(e.getMessage(), e);
    } catch (SQLException e) {
      e.printStackTrace();
      throw new FetchException(e.getMessage(), e);
    } catch (IOException e) {
      e.printStackTrace();
      throw new FetchException(e.getMessage(), e);
    } catch (ParseException e) {
      e.printStackTrace();
      throw new FetchException(e.getMessage(), e);
    } finally {
      if (db != null)
        db.close();
    }
    return bookmarks;
  }
View Full Code Here

    return bookmarks;
  }

  @Override
  public void updateBookmarks(Bookmark[] bookmarks) throws IllegalArgumentException, FetchException, OpenIdException {
    DbHelper db = null;

    try {
      db = new DbHelper(new File(getServletContext().getRealPath("/")), getThreadLocalRequest());
      db.updateBookmarks(bookmarks);
    } catch (SQLException e) {
      e.printStackTrace();
      throw new FetchException(e.getMessage(), e);
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
      throw new FetchException(e.getMessage(), e);
    } catch (FileNotFoundException e) {
      e.printStackTrace();
      throw new FetchException(e.getMessage(), e);
    } catch (JSONException e) {
      e.printStackTrace();
      throw new FetchException(e.getMessage(), e);
    } catch (IOException e) {
      e.printStackTrace();
      throw new FetchException(e.getMessage(), e);
    } catch (ParseException e) {
      e.printStackTrace();
      throw new FetchException(e.getMessage(), e);
    } finally {
      if (db != null)
        db.close();
    }
  }
View Full Code Here

    }
  }

  @Override
  public void deleteBookmarks(int[] bookmarkIds) throws IllegalArgumentException, FetchException, OpenIdException {
    DbHelper db = null;
    try {
      db = new DbHelper(new File(getServletContext().getRealPath("/")), getThreadLocalRequest());
      db.clearBookmarks(bookmarkIds);
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
      throw new FetchException(e.getMessage(), e);
    } catch (FileNotFoundException e) {
      e.printStackTrace();
      throw new FetchException(e.getMessage(), e);
    } catch (JSONException e) {
      e.printStackTrace();
      throw new FetchException(e.getMessage(), e);
    } catch (SQLException e) {
      e.printStackTrace();
      throw new FetchException(e.getMessage(), e);
    } catch (IOException e) {
      e.printStackTrace();
      throw new FetchException(e.getMessage(), e);
    } catch (ParseException e) {
      e.printStackTrace();
      throw new FetchException(e.getMessage(), e);
    } finally {
      if (db != null)
        db.close();
    }
  }
View Full Code Here

  }

  @Override
  public void logLazyQuery(String query, String endpoint) throws IllegalArgumentException, EndpointIdException {
    try {
      QueryCompletionExtractor.store(new DbHelper(new File(getServletContext().getRealPath("/")), getThreadLocalRequest()), query, endpoint);
    } catch (EndpointIdException e) {
      throw e;
    } catch (Exception e) {
      throw new IllegalArgumentException(e.getMessage());
    }
View Full Code Here

TOP

Related Classes of com.data2semantics.yasgui.server.db.DbHelper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.