use of nl.knaw.huygens.timbuctoo.core.dto.rdf.CreateProperty in project timbuctoo by HuygensING.
the class PropertyFactoryTest method fromRdfPredicateWillNotCreateTheSameClientNameTwice.
@Test
public void fromRdfPredicateWillNotCreateTheSameClientNameTwice() {
ValueTypeInUse valueType1 = ImmutableValueTypeInUse.builder().typeUri("http://example.org/type1").addEntitiesConnected("entity1", "entity2").build();
List<PredicateInUse> predicates = Lists.newArrayList(ImmutablePredicateInUse.builder().predicateUri("http://example.org/localName").addValueTypes(valueType1).build(), ImmutablePredicateInUse.builder().predicateUri("http://example.com/localName").addValueTypes(valueType1).build());
List<CreateProperty> properties = instance.fromPredicates(predicates);
assertThat(properties, containsInAnyOrder(allOf(hasProperty("clientName", equalTo("localName")), hasProperty("rdfUri", equalTo("http://example.org/localName"))), allOf(hasProperty("clientName", equalTo("http://example.com/localName")), hasProperty("rdfUri", equalTo("http://example.com/localName")))));
}
use of nl.knaw.huygens.timbuctoo.core.dto.rdf.CreateProperty in project timbuctoo by HuygensING.
the class RdfImportSessionTest method closeCreatesPropertyDescriptionsForEachPredicate.
@Test
public void closeCreatesPropertyDescriptionsForEachPredicate() {
List<PredicateInUse> predicates = Lists.newArrayList();
given(dataStoreOperations.getPredicatesFor(any(Collection.class))).willReturn(predicates);
PropertyFactory propertyFactory = mock(PropertyFactory.class);
ArrayList<CreateProperty> createProperties = Lists.newArrayList();
given(propertyFactory.fromPredicates(predicates)).willReturn(createProperties);
RdfImportSession instance = rdfImportSessionWithPropertyFactory(VRE_NAME, dataStoreOperations, propertyFactory);
instance.commit();
instance.close();
verify(propertyFactory).fromPredicates(predicates);
verify(dataStoreOperations).addPropertiesToCollection(any(Collection.class), eq(createProperties));
}
use of nl.knaw.huygens.timbuctoo.core.dto.rdf.CreateProperty in project timbuctoo by HuygensING.
the class PropertyFactory method convertToProperty.
private CreateProperty convertToProperty(PredicateInUse pred) {
Stack<ValueTypeInUse> valueTypes = pred.getValueTypes().stream().sorted(comparingInt(o -> o.getEntitiesConnected().size())).collect(toCollection(Stack::new));
ValueTypeInUse type = valueTypes.pop();
valueTypes.forEach(vt -> vt.getEntitiesConnected().forEach(e -> importErrorReporter.entityHasWrongTypeForProperty(e, pred.getPredicateUri(), type.getTypeUri(), vt.getTypeUri())));
return ImmutableCreateProperty.builder().clientName(getPredicateName(pred)).rdfUri(pred.getPredicateUri()).typeUri(type.getTypeUri()).propertyType(getPropertyType(pred.getPredicateUri(), type)).build();
}
use of nl.knaw.huygens.timbuctoo.core.dto.rdf.CreateProperty in project timbuctoo by HuygensING.
the class PropertyFactory method fromPredicates.
public List<CreateProperty> fromPredicates(List<PredicateInUse> predicates) {
List<CreateProperty> result = predicates.stream().map(pred -> convertToProperty(pred)).collect(toList());
Set<String> encounteredLocalnames = new HashSet<>();
for (int i = 0; i < result.size(); i++) {
CreateProperty createProperty = result.get(i);
if (encounteredLocalnames.contains(createProperty.getClientName())) {
createProperty = ImmutableCreateProperty.copyOf(createProperty).withClientName(createProperty.getRdfUri());
result.set(i, createProperty);
}
encounteredLocalnames.add(createProperty.getClientName());
}
return result;
}
Aggregations