@Override public void consume(final Individual<?, ?> subject, final URI predicate, final Literal<?> object) { if(subject==this.from) { this.to.addValue(predicate,object); } }
@Override public void visitIndividual(Individual<?, ?> value) { individuals.add(value.id()); }
@SuppressWarnings("unchecked") // TODO: fully generify when Vistor is generic <T extends Serializable> Individual<T,?> findOrCreate(Individual<T,?> individual) { individual.accept(this); return (Individual<T,?>)this.found; }
@Override public void consume(final Individual<?, ?> subject, final URI predicate, final Individual<?, ?> object) { if(subject==this.from) { Value value=object; if(value==this.from) { value=this.to; } this.to.addValue(predicate,value); } else if(subject!=this.to && object==this.from) { subject.removeValue(predicate, object); subject.addValue(predicate,this.to); } } }
@Override public void visitIndividual(Individual<?,?> value) { Individual<?, ?> cValue = target.dataSet().individualOfId(value.id()); if(cValue!=null) { target.removeValue(propertyId, cValue); } } };
private void mergeIndividuals(Individual<?, ?> source, Individual<?, ?> target) { for(Property property:source.properties()) { for(Value value:property) { target.addValue(property.predicate(), value); } } }
/** * {@inheritDoc} */ @Override public IndividualPropertyHelper withIndividual(URI id) { if(id!=null) { Individual<?,?> srcIndividual=null; if(id.isAbsolute()) { srcIndividual=this.individual.dataSet().individual(id, ExternalIndividual.class); } else { srcIndividual=this.individual.dataSet().individual(id, NewIndividual.class); } this.individual.addValue(this.propertyId,srcIndividual); } return new IndividualPropertyHelperImpl(new IndividualHelperImpl(this.individual),this); }
private Property getProperty() { return this.individual.property(propertyId); }
private void configureHasMemberValidationConstraints(ValidatorBuilder builder, Individual<?, ?> individual, DataSet metadata, URI predicate) { // NOSONAR ValidationConstraint<Property> constraint=null; Property property = individual.property(predicate); if(property!=null) { constraint=ValidationConstraintFactory.readOnlyProperty(property); } else { constraint=ValidationConstraintFactory.readOnlyProperty(individual.id(),predicate); } builder.withPropertyConstraint(constraint); }
public static void merge(Individual<?,?> source, Individual<?,?> target) { ValueReplicator replicator=new ValueReplicator(target.dataSet()); for(Property property:source.properties()) { for(Value value:property) { target.addValue(property.predicate(),replicator.replicate(value)); } } }
private void contains(DataSet dataSet, DataSet original) { for(Individual<?,?> individual:dataSet) { Individual<?, ?> originalInd = original.individualOfId(individual.id()); assertThat(originalInd,notNullValue()); for(Property property:individual) { assertThat(originalInd.hasProperty(property.predicate()),equalTo(true)); final Property originalProp = originalInd.property(property.predicate()); for(Value value:property) { value.accept( new ValueVisitor() { @Override public void visitLiteral(Literal<?> value) { assertThat(originalProp.hasLiteralValue(value),equalTo(true)); } @Override public void visitIndividual(Individual<?, ?> value) { assertThat(originalProp.hasIdentifiedIndividual(value.id()),equalTo(true)); } }); } } } }
@Override public void remove(final Individual<?, ?> src) { if(this!=src.dataSet()) { return; } for(Individual<?,?> individual:this) { for(Property property:individual) { for(Value value:property) { value.accept(new IndividualRemover(property,src,individual)); } } } this.individuals.remove(src.id()); }
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)); } }
@Override public void visitLiteral(Literal<?> value) { target.removeValue(propertyId, value); } @Override
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)); }
/** * {@inheritDoc} */ @Override public IndividualPropertyHelper withIndividual(Name<?> id) { if(id!=null) { @SuppressWarnings("rawtypes") Individual<?,?> srcIndividual = this.individual.dataSet().individual((Name)id, LocalIndividual.class); this.individual.addValue(this.propertyId,srcIndividual); } return new IndividualPropertyHelperImpl(new IndividualHelperImpl(this.individual),this); }
/** * {@inheritDoc} */ @Override public Set<URI> types() { Property property = this.individual.property(RDF.TYPE.as(URI.class)); if(property==null) { return Collections.emptySet(); } TypeCollector collector = new TypeCollector(); for(Value value:property) { value.accept(collector); } return collector.collectedTypes(); }
@Override protected void configureValidationConstraints(ValidatorBuilder builder, Individual<?,?> individual, DataSet metadata) { builder.withPropertyConstraint(ValidationConstraintFactory.mandatoryPropertyValues(individual.property(RDF.TYPE.as(URI.class)))); Multimap<URI,AttachedTemplate> attachmentMap=LinkedHashMultimap.create(); for(AttachedTemplate attachedTemplate:template().attachedTemplates()) { URI propertyId = attachedTemplate.predicate().or(HAS_ATTACHMENT); attachmentMap.put(propertyId, attachedTemplate); } for(Entry<URI, Collection<AttachedTemplate>> entry:attachmentMap.asMap().entrySet()) { URI propertyId=entry.getKey(); Property property = individual.property(propertyId); if(property!=null) { configurePropertyValidationConstraints(builder,individual,metadata,property,entry.getValue()); } else { builder.withPropertyConstraint(ValidationConstraintFactory.readOnlyProperty(individual.id(),propertyId)); } } }
private void addIndividual(Individual<?, ?> value) { Individual<?,?> target=null; if(dataSet().hasIndividual(value.id())) { if(dataSet().equals(value.dataSet())) { target=value; } else { target=dataSet().individualOfId(value.id()); } } else { target=addIndividualToDataset(value); } if(target!=value) { mergeIndividuals(value,target); } this.values.add(target); }
private void cleanIndividual(Individual<?,?> individual) { for(Property property:individual) { URI propertyId = property.predicate(); for(Value value:property) { individual.removeValue(propertyId,value); } } }