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;
}
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;
}
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;
}
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;
}
Aggregations