public Iterable<Statement> serialize( final EntityState entityState, final boolean includeNonQueryable ) { Graph graph = new GraphImpl(); serialize( entityState, includeNonQueryable, graph ); return graph; }
private void removeEntityStates( Iterable<EntityState> entityStates, RepositoryConnection connection ) throws RepositoryException { List<URI> removedStates = new ArrayList<>(); for( EntityState entityState : entityStates ) { if( entityState.status().equals( EntityStatus.REMOVED ) ) { removedStates.add( stateSerializer.createEntityURI( getValueFactory(), entityState.entityReference() ) ); } else if( entityState.status().equals( EntityStatus.UPDATED ) ) { removedStates.add( stateSerializer.createEntityURI( getValueFactory(), entityState.entityReference() ) ); } } if( !removedStates.isEmpty() ) { Resource[] resources = removedStates.toArray( new Resource[ removedStates.size() ] ); connection.remove( null, null, null, resources ); } }
private void indexEntityState( final EntityState entityState, final RepositoryConnection connection ) throws RepositoryException { if( entityState.entityDescriptor().queryable() ) { EntityReference reference = entityState.entityReference(); final URI entityURI = stateSerializer.createEntityURI( getValueFactory(), reference); Graph graph = new GraphImpl(); stateSerializer.serialize( entityState, false, graph ); connection.add( graph, entityURI ); } }
public void serialize( final EntityState entityState, final boolean includeNonQueryable, final Graph graph ) { ValueFactory values = graph.getValueFactory(); EntityReference reference = entityState.entityReference(); URI entityUri = createEntityURI( values, reference ); graph.add( entityUri, Rdfs.TYPE, values.createURI( Classes.toURI( entityState.entityDescriptor().types().findFirst().orElse( null ) ) ) ); serializeProperties( entityState, graph, entityUri, entityState.entityDescriptor(), includeNonQueryable ); serializeAssociations( entityState, graph, entityUri, entityState.entityDescriptor().state().associations(), includeNonQueryable ); serializeManyAssociations( entityState, graph, entityUri, entityState.entityDescriptor().state().manyAssociations(), includeNonQueryable ); }
.qualifiedName() .name() ); serializeValueComposite( collection, pred, (ValueComposite) propertyValue, type, graph, serializeProperty( persistentProperty, propertyValue, collection, graph,
private void serializeProperties( EntityState entityState, Graph graph, Resource subject, EntityDescriptor entityType, boolean includeNonQueryable ) { // Properties entityType.state().properties().forEach( persistentProperty -> { Object property = entityState.propertyValueOf( persistentProperty.qualifiedName() ); if( property != null ) { serializeProperty( persistentProperty, property, subject, graph, includeNonQueryable ); } } ); }
private void indexEntityState( final EntityState entityState, final RepositoryConnection connection ) throws RepositoryException { if( entityState.entityDescriptor().queryable() ) { EntityReference reference = entityState.entityReference(); final URI entityURI = stateSerializer.createEntityURI( getValueFactory(), reference); Graph graph = new GraphImpl(); stateSerializer.serialize( entityState, false, graph ); connection.add( graph, entityURI ); } }
@Override public void write( Writer writer ) throws IOException { try { Iterable<Statement> statements = entitySerializer.serialize( entity ); new RdfXmlSerializer().serialize( statements, writer ); } catch( RDFHandlerException e ) { throw new IOException( e ); } } };
private void removeEntityStates( Iterable<EntityState> entityStates, RepositoryConnection connection ) throws RepositoryException { List<URI> removedStates = new ArrayList<>(); for( EntityState entityState : entityStates ) { if( entityState.status().equals( EntityStatus.REMOVED ) ) { removedStates.add( stateSerializer.createEntityURI( getValueFactory(), entityState.entityReference() ) ); } else if( entityState.status().equals( EntityStatus.UPDATED ) ) { removedStates.add( stateSerializer.createEntityURI( getValueFactory(), entityState.entityReference() ) ); } } if( !removedStates.isEmpty() ) { Resource[] resources = removedStates.toArray( new Resource[ removedStates.size() ] ); connection.remove( null, null, null, resources ); } }
stateSerializer.serialize( entityState, false, graph );
@Test public void testEntitySerializer() throws RDFHandlerException { EntityReference entityReference = EntityReference.parseEntityReference( "test2" ); Usecase usecase = UsecaseBuilder.newUsecase( "Test" ); Instant currentTime = SystemTime.now(); EntityStoreUnitOfWork unitOfWork = entityStore.newUnitOfWork( module, usecase, currentTime ); EntityState entityState = unitOfWork.entityStateOf( module, entityReference ); Iterable<Statement> graph = serializer.serialize( entityState ); String[] prefixes = new String[]{ "rdf", "dc", " vc" }; String[] namespaces = new String[]{ Rdfs.RDF, DcRdf.NAMESPACE, "http://www.w3.org/2001/vcard-rdf/3.0#" }; new RdfXmlSerializer().serialize( graph, new PrintWriter( System.out ), prefixes, namespaces ); }