Package org.apache.stanbol.factstore.model

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


    }
  }
 
    @Override
    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);
           
View Full Code Here


       
        return fact;
    }

  private Fact getFact(int factId, FactSchema factSchema, Connection con) throws Exception {
      Fact fact = null;
     
      String factSchemaB64 = Base64.encodeBase64URLSafeString(factSchema.getFactSchemaURN().getBytes());
      logger.info("Loading fact {} from fact table {}", factId, factSchemaB64);
     
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            StringBuilder selectBuilder = new StringBuilder("SELECT ");
            boolean firstRole = true;
            for (String role : factSchema.getRoles()) {
                if (!firstRole) {
                    selectBuilder.append(",");
                }
                selectBuilder.append(role);
                firstRole = false;
            }
            selectBuilder.append(" FROM " + factSchemaB64 + " WHERE id=?");
           
            // TODO Load the context, too
           
            ps = con.prepareStatement(selectBuilder.toString());
            ps.setInt(1, factId);
            rs = ps.executeQuery();

            if (rs.next()) {
                fact = new Fact();
                fact.setFactSchemaURN(factSchema.getFactSchemaURN());
                for (int col=1; col<=rs.getMetaData().getColumnCount(); col++) {
                    String role = factSchema.fixSpellingOfRole(rs.getMetaData().getColumnName(col));
                    fact.addRole(role, rs.getString(col));
                }
            }
        } catch (SQLException e) {
            throw new Exception("Error while selecting fact", e);
        } finally {
View Full Code Here

        }

        int factId = -1;
        if (jsonLd.getResourceSubjects().size() < 2) {
            // post a single fact
            Fact fact = Fact.factFromJsonLd(jsonLd);
            if (fact != null) {
                logger.info("Request for posting new fact for {}", fact.getFactSchemaURN());
                try {
                    factId = this.factStore.addFact(fact);
                } catch (Exception e) {
                    logger.error("Error adding new fact", e);
                    ResponseBuilder rb = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage())
                            .type(MediaType.TEXT_PLAIN);
                    CorsHelper.addCORSOrigin(servletContext, rb, requestHeaders);
                    return rb.build();
                }
            } else {
                ResponseBuilder rb = Response.status(Status.BAD_REQUEST)
                        .entity("Could not extract fact from JSON-LD input.").type(MediaType.TEXT_PLAIN);
                CorsHelper.addCORSOrigin(servletContext, rb, requestHeaders);
                return rb.build();
            }
           
            String schemaEncoded = null;
            try {
                schemaEncoded = URLEncoder.encode(fact.getFactSchemaURN(), "UTF-8");
            } catch (UnsupportedEncodingException e) {
                logger.error("Could not encode fact schema URI", e);
            }
           
            ResponseBuilder rb = Response
View Full Code Here

            return validationResponse;
        }

        logger.info("Request for getting fact {} of schema {}", factId, factSchemaURN);
       
        Fact fact = null;
        try {
            fact = this.factStore.getFact(factId, factSchemaURN);
        } catch (Exception e) {
            logger.error("Error while loading fact {}", factId, e);
            ResponseBuilder rb = Response
                    .status(Status.INTERNAL_SERVER_ERROR)
                    .entity(
                        "Error while loading fact " + factId + " of fact schema " + factSchemaURN
                                + " from database").type(MediaType.TEXT_PLAIN);
            CorsHelper.addCORSOrigin(servletContext, rb, requestHeaders);
            return rb.build();
        }
        if (fact == null) {
            logger.debug("Fact {} for fact schema {} not found", factId, factSchemaURN);
            ResponseBuilder rb = Response.status(Status.NOT_FOUND).entity(
                "Could not find fact with ID " + factId + " for fact schema " + factSchemaURN);
            CorsHelper.addCORSOrigin(servletContext, rb, requestHeaders);
            return rb.build();
        }
        else {
            JsonLd factAsJsonLd = fact.factToJsonLd();
            ResponseBuilder rb = Response.status(Status.OK).entity(factAsJsonLd.toString())
                    .type(MediaType.APPLICATION_JSON);
            CorsHelper.addCORSOrigin(servletContext, rb, requestHeaders);
            return rb.build();
        }
View Full Code Here

            return validationResponse;
        }

        logger.info("Request for getting fact {} of schema {}", factId, factSchemaURN);
       
        Fact fact = null;
        try {
            fact = this.factStore.getFact(factId, factSchemaURN);
        } catch (Exception e) {
            logger.error("Error while loading fact {}", factId, e);
            ResponseBuilder rb = Response
                    .status(Status.INTERNAL_SERVER_ERROR)
                    .entity(
                        "Error while loading fact " + factId + " of fact schema " + factSchemaURN
                                + " from database").type(MediaType.TEXT_PLAIN);
            CorsHelper.addCORSOrigin(servletContext, rb, requestHeaders);
            return rb.build();
        }
        if (fact == null) {
            logger.debug("Fact {} for fact schema {} not found", factId, factSchemaURN);
            ResponseBuilder rb = Response.status(Status.NOT_FOUND).entity(
                "Could not find fact with ID " + factId + " for fact schema " + factSchemaURN);
            CorsHelper.addCORSOrigin(servletContext, rb, requestHeaders);
            return rb.build();
        }
        else {
            JsonLd factAsJsonLd = fact.factToJsonLd();
           
            StringBuilder sb = new StringBuilder();
            sb.append("<html><body>");
            sb.append("<pre>");
            sb.append(factAsJsonLd.toString(2));
View Full Code Here

TOP

Related Classes of org.apache.stanbol.factstore.model.Fact

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.