Examples of FactSchema


Examples of org.apache.stanbol.factstore.model.FactSchema

    return exists;
  }

  @Override
  public FactSchema getFactSchema(String factSchemaURN) {
    FactSchema factSchema = null;

    Connection con = null;
    try {
      con = DriverManager.getConnection(DB_URL);
      factSchema = loadFactSchema(factSchemaURN, con);
View Full Code Here

Examples of org.apache.stanbol.factstore.model.FactSchema

    return factSchema;
  }

  private FactSchema loadFactSchema(String factSchemaURN, Connection con)
      throws Exception {
    FactSchema factSchema = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    try {
      String selectFactSchema = "SELECT factschemata.name AS schemaURN, factroles.name AS role, factroles.type AS type FROM factroles JOIN factschemata ON ( factschemata.id = factroles.factschema_id ) WHERE factschemata.name = ?";
      ps = con.prepareStatement(selectFactSchema);
      ps.setString(1, factSchemaURN);
      rs = ps.executeQuery();

      boolean first = true;
      while (rs.next()) {
        if (first) {
          factSchema = new FactSchema();
          factSchema.setFactSchemaURN(rs.getString("schemaURN"));
          first = false;
        }
        String typeFromDB = rs.getString("type");
        String[] types = typeFromDB.split(",");
        if (types.length > 0) {
          for (String type : types) {
            factSchema.addRole(rs.getString("role"), type);
          }
        } else {
          factSchema.addRole(rs.getString("role"), typeFromDB);
        }
      }
    } catch (SQLException e) {
      throw new Exception("Error while selecting fact schema meta data",
          e);
View Full Code Here

Examples of org.apache.stanbol.factstore.model.FactSchema

    public Fact getFact(int factId, String factSchemaURN) throws Exception {
        Fact fact = null;
        Connection con = null;
        try {
            con = DriverManager.getConnection(DB_URL);
            FactSchema factSchema = this.loadFactSchema(factSchemaURN, con);
           
            if (factSchema != null) {
                fact = this.getFact(factId, factSchema, con);
            }
           
View Full Code Here

Examples of org.apache.stanbol.factstore.model.FactSchema

    return factId;
  }

    private int addFact(Fact fact, Connection con) throws Exception {
        int factId = -1;
        FactSchema factSchema = this.loadFactSchema(fact.getFactSchemaURN(), con);
        if (factSchema != null) {
            StringBuilder insertContext = new StringBuilder("INSERT INTO factcontexts (created, updated, validFrom, validTo, contextURN) VALUES (?, ?, ?, ?, ?)");
           
            // Create the fact
            String factSchemaB64 = Base64.encodeBase64URLSafeString(fact.getFactSchemaURN().getBytes());

            StringBuilder insertFact = new StringBuilder("INSERT INTO ").append(factSchemaB64).append(" (context_id");
            StringBuilder valueSB = new StringBuilder(" VALUES (?");
           
            Map<String,Integer> roleIndexMap = new HashMap<String,Integer>();
            int roleIndex = 1;
            for (String role : factSchema.getRoles()) {
                if (fact.getRoles().contains(role)) {
                    insertFact.append(',');
                    valueSB.append(',');

                    insertFact.append(role);
View Full Code Here

Examples of org.apache.stanbol.factstore.model.FactSchema

      PreparedStatement ps = null;
      ResultSet rs = null;
      try {
        con = DriverManager.getConnection(DB_URL);

        FactSchema schema = validateQuery(query, con);

        // from here on we have valid data

        String factSchemaB64 = Base64.encodeBase64URLSafeString(query.getFromSchemaURN().getBytes());

        StringBuilder querySql = new StringBuilder("SELECT ");

        boolean firstRole = true;
        for (String role : query.getRoles()) {
          if (!firstRole) {
            querySql.append(",");
          }
          querySql.append(role);
          firstRole = false;
        }

        querySql.append(" FROM ").append(factSchemaB64);

        List<String> queryParams = new ArrayList<String>();
        querySql.append(" WHERE ");
        for (WhereClause wc : query.getWhereClauses()) {
          querySql.append('(');
          querySql.append(wc.getComparedRole());
          switch (wc.getCompareOperator()) {
          case EQ:
            querySql.append(" = ").append('?');
            queryParams.add(wc.getSearchedValue());
            break;
          }
        }
        querySql.append(')');

        // TODO load context, too
       
        logger.info("performing query {}", querySql);

        ps = con.prepareStatement(querySql.toString());
        for (int i = 0; i < queryParams.size(); i++) {
          ps.setString(i + 1, queryParams.get(i));
        }

        rs = ps.executeQuery();
        if (rs != null) {
          List<String> header = new ArrayList<String>();
          for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
            header.add(schema.fixSpellingOfRole(rs.getMetaData().getColumnName(i)));
          }

          frs = new FactResultSet();
          frs.setHeader(header);
View Full Code Here

Examples of org.apache.stanbol.factstore.model.FactSchema

    return frs;
  }

  private FactSchema validateQuery(Query query, Connection con) throws Exception {
    FactSchema schema = this.loadFactSchema(query.getFromSchemaURN(), con);

    if (schema == null) {
      throw new Exception("Fact schema " + query.getFromSchemaURN() + " does not exist.");
    }

    StringBuilder unknownRoles = new StringBuilder();
    for (String role : query.getRoles()) {
      if (!schema.hasRole(role)) {
        if (!unknownRoles.toString().isEmpty()) {
          unknownRoles.append(',');
        }
        unknownRoles.append("role");
      }
View Full Code Here

Examples of org.apache.stanbol.factstore.model.FactSchema

            return validationResponse;
        }

        logger.info("Request for getting existing fact schema {}", factSchemaURN);

        FactSchema factSchema = this.factStore.getFactSchema(factSchemaURN);
        if (factSchema == null) {
            ResponseBuilder rb = Response.status(Status.NOT_FOUND)
                    .entity("Could not find fact schema " + factSchemaURN).type(MediaType.TEXT_PLAIN);
            CorsHelper.addCORSOrigin(servletContext, rb, requestHeaders);
            return rb.build();
        }

        ResponseBuilder rb = Response.ok(factSchema.toJsonLdProfile().toString(), MediaType.APPLICATION_JSON);
        CorsHelper.addCORSOrigin(servletContext, rb, requestHeaders);
        return rb.build();
    }
View Full Code Here

Examples of org.apache.stanbol.factstore.model.FactSchema

            return validationResponse;
        }

        logger.info("Request for getting existing fact schema {}", factSchemaURN);

        FactSchema factSchema = this.factStore.getFactSchema(factSchemaURN);
        if (factSchema == null) {
            ResponseBuilder rb = Response.status(Status.NOT_FOUND).entity("Could not find fact schema " + factSchemaURN)
                    .type(MediaType.TEXT_PLAIN);
            CorsHelper.addCORSOrigin(servletContext, rb, requestHeaders);
            return rb.build();
        }

        Map<String, Object> model = new HashMap<String,Object>();
        model.put("it", this);
        model.put("factSchemaURN", factSchemaURN);
        model.put("factschema", factSchema.toJsonLdProfile().toString(2));
       
        ResponseBuilder rb = Response.ok(new Viewable("factschema", model), MediaType.TEXT_HTML);
        CorsHelper.addCORSOrigin(servletContext, rb, requestHeaders);
        return rb.build();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.