Search in sources :

Example 1 with GraphImpl

use of org.openrdf.model.impl.GraphImpl in project qi4j-sdk by Qi4j.

the class SolrEntityIndexerMixin method indexEntityState.

private SolrInputDocument indexEntityState(final EntityState entityState, final SolrServer server) throws IOException, SolrServerException, JSONException {
    Graph graph = new GraphImpl();
    stateSerializer.serialize(entityState, false, graph);
    SolrInputDocument input = new SolrInputDocument();
    input.addField("id", entityState.identity().identity());
    input.addField("type", first(entityState.entityDescriptor().types()).getName());
    input.addField("lastModified", new Date(entityState.lastModified()));
    for (Statement statement : graph) {
        SchemaField field = indexedFields.get(statement.getPredicate().getLocalName());
        if (field != null) {
            if (statement.getObject() instanceof Literal) {
                String value = statement.getObject().stringValue();
                if (field.getType().getTypeName().equals("json")) {
                    if (value.charAt(0) == '[') {
                        JSONArray array = new JSONArray(value);
                        indexJson(input, array);
                    } else if (value.charAt(0) == '{') {
                        JSONObject object = new JSONObject(value);
                        indexJson(input, object);
                    }
                } else {
                    input.addField(field.getName(), value);
                }
            } else if (statement.getObject() instanceof URI && !"type".equals(field.getName())) {
                String value = statement.getObject().stringValue();
                value = value.substring(value.lastIndexOf(':') + 1, value.length());
                String name = field.getName();
                input.addField(name, value);
            } else if (statement.getObject() instanceof BNode) {
                Iterator<Statement> seq = graph.match((Resource) statement.getObject(), new URIImpl("http://www.w3.org/1999/02/22-rdf-syntax-ns#li"), null, (Resource) null);
                while (seq.hasNext()) {
                    Statement seqStatement = seq.next();
                    String value = seqStatement.getObject().stringValue();
                    value = value.substring(value.lastIndexOf(':') + 1, value.length());
                    input.addField(field.getName(), value);
                }
            }
        }
    }
    return input;
}
Also used : BNode(org.openrdf.model.BNode) Statement(org.openrdf.model.Statement) JSONArray(org.json.JSONArray) URIImpl(org.openrdf.model.impl.URIImpl) URI(org.openrdf.model.URI) Date(java.util.Date) SchemaField(org.apache.solr.schema.SchemaField) SolrInputDocument(org.apache.solr.common.SolrInputDocument) Graph(org.openrdf.model.Graph) JSONObject(org.json.JSONObject) GraphImpl(org.openrdf.model.impl.GraphImpl) Literal(org.openrdf.model.Literal)

Example 2 with GraphImpl

use of org.openrdf.model.impl.GraphImpl in project qi4j-sdk by Qi4j.

the class EntityStateSerializer method serialize.

public Iterable<Statement> serialize(final EntityState entityState, final boolean includeNonQueryable) {
    Graph graph = new GraphImpl();
    serialize(entityState, includeNonQueryable, graph);
    return graph;
}
Also used : Graph(org.openrdf.model.Graph) GraphImpl(org.openrdf.model.impl.GraphImpl)

Example 3 with GraphImpl

use of org.openrdf.model.impl.GraphImpl in project qi4j-sdk by Qi4j.

the class EntityTypeSerializer method serialize.

public Iterable<Statement> serialize(final EntityDescriptor entityDescriptor) {
    Graph graph = new GraphImpl();
    ValueFactory values = graph.getValueFactory();
    URI entityTypeUri = values.createURI(Classes.toURI(first(entityDescriptor.types())));
    graph.add(entityTypeUri, Rdfs.TYPE, Rdfs.CLASS);
    graph.add(entityTypeUri, Rdfs.TYPE, OWL.CLASS);
    graph.add(entityTypeUri, Qi4jEntityType.TYPE, values.createLiteral(first(entityDescriptor.types()).toString()));
    graph.add(entityTypeUri, Qi4jEntityType.QUERYABLE, values.createLiteral(entityDescriptor.queryable()));
    serializeMixinTypes(entityDescriptor, graph, entityTypeUri);
    serializePropertyTypes(entityDescriptor, graph, entityTypeUri);
    serializeAssociationTypes(entityDescriptor, graph, entityTypeUri);
    serializeManyAssociationTypes(entityDescriptor, graph, entityTypeUri);
    return graph;
}
Also used : Graph(org.openrdf.model.Graph) GraphImpl(org.openrdf.model.impl.GraphImpl) ValueFactory(org.openrdf.model.ValueFactory) URI(org.openrdf.model.URI)

Example 4 with GraphImpl

use of org.openrdf.model.impl.GraphImpl in project qi4j-sdk by Qi4j.

the class ApplicationSerializer method serialize.

public Graph serialize(Application app) {
    Graph graph = new GraphImpl();
    SerializerContext context = new SerializerContext(graph);
    ApplicationVisitor applicationVisitor = new ApplicationVisitor(context);
    ((Application) app).descriptor().accept(applicationVisitor);
    return graph;
}
Also used : Graph(org.openrdf.model.Graph) GraphImpl(org.openrdf.model.impl.GraphImpl) SerializerContext(org.qi4j.library.rdf.serializer.SerializerContext)

Aggregations

Graph (org.openrdf.model.Graph)4 GraphImpl (org.openrdf.model.impl.GraphImpl)4 URI (org.openrdf.model.URI)2 Date (java.util.Date)1 SolrInputDocument (org.apache.solr.common.SolrInputDocument)1 SchemaField (org.apache.solr.schema.SchemaField)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1 BNode (org.openrdf.model.BNode)1 Literal (org.openrdf.model.Literal)1 Statement (org.openrdf.model.Statement)1 ValueFactory (org.openrdf.model.ValueFactory)1 URIImpl (org.openrdf.model.impl.URIImpl)1 SerializerContext (org.qi4j.library.rdf.serializer.SerializerContext)1