private void verifyResult(final ResourceSnapshot snapshot, DynamicResourceHandler handler, boolean b) throws UnknownResourceException { DataSet dataSet = handler.get(snapshot); Individual<?, ?> resource=dataSet.individualOfId(ManagedIndividualId.createId(RID, DynamicResourceHandler.ID)); assertThat(resource.hasProperty(DynamicResourceUpdater.REFRESHED_ON),equalTo(b)); }
private void verifyResult(final ResourceSnapshot snapshot, DynamicResourceHandler handler, boolean resolveToUri, boolean resolveRoundtrip, String roundtrip) throws UnknownResourceException { DataSet dataSet = handler.get(snapshot); Individual<?, ?> resource=dataSet.individualOfId(ManagedIndividualId.createId(RID, DynamicResourceHandler.ID)); assertThat("Could "+(resolveToUri?"not":"")+" resolve uri",resource.hasProperty(DynamicResourceResolver.SNAPSHOT_ENDPOINT),equalTo(resolveToUri)); if(resolveToUri) { assertThat("Invalid uri resolution",resource.property(DynamicResourceResolver.SNAPSHOT_ENDPOINT).hasLiteralValue(Literals.newLiteral(ENDPOINT)),equalTo(resolveRoundtrip)); } assertThat("Could "+(resolveRoundtrip?"not":"")+" resolve roundtrip",resource.hasProperty(DynamicResourceResolver.SNAPSHOT_RESOLUTION),equalTo(resolveRoundtrip)); if(resolveRoundtrip) { assertThat("Invalid roundtrip resolution",resource.property(DynamicResourceResolver.SNAPSHOT_RESOLUTION).hasLiteralValue(Literals.of(roundtrip)),equalTo(resolveRoundtrip)); } }
/** * Update the resource representation adding a temporal timestamp of when * the resource was last updated. */ @Override public void run() { ApplicationContext ctx = ApplicationContext.getInstance(); Date date = new Date(); LOGGER.debug("Starting update process on {}...",date); try(WriteSession session = ctx.createSession()) { ResourceSnapshot snapshot = session.find(ResourceSnapshot.class,this.name,DynamicResourceHandler.class); DataSet dataSet = this.handler.get(snapshot); Individual<?,?> individual = dataSet. individualOfId( ManagedIndividualId. createId(this.name, DynamicResourceHandler.ID)); individual. addValue( REFRESHED_ON, Literals.of(date).dateTime()); this.handler.update(this.name, dataSet); session.modify(snapshot); session.saveChanges(); } catch (Exception e) { LOGGER.error("Could not update resource",e); } finally { LOGGER.debug("Finalized update process"); } }
DynamicResourceHandler.class); DataSet dataSet = this.handler.get(snapshot); Individual<?,?> individual = dataSet.
application.shutdown(); DataSet dataSet = application.dynamicResourceHandler().get(snapshot); LOGGER.info("Updated resource:\n{}",dataSet);