use of nl.knaw.huygens.timbuctoo.model.Change in project timbuctoo by HuygensING.
the class ChangeDatePropertyParserTest method parseReturnsAFormattedYearMonthAndDateIfTheInputIsValid.
@Test
public void parseReturnsAFormattedYearMonthAndDateIfTheInputIsValid() throws JsonProcessingException {
long timeStampOnJan20th2016 = 1453290593000L;
Change change = new Change(timeStampOnJan20th2016, "user", "vre");
String changeString = new ObjectMapper().writeValueAsString(change);
String result = instance.parse(changeString);
assertThat(result, is(equalTo("20160120")));
}
use of nl.knaw.huygens.timbuctoo.model.Change in project timbuctoo by HuygensING.
the class TinkerPopToEntityMapper method mapEntity.
public ReadEntity mapEntity(GraphTraversal<Vertex, Vertex> entityT, boolean withRelations) {
final List<TimProperty<?>> properties = Lists.newArrayList();
TinkerPopPropertyConverter dbPropertyConverter = new TinkerPopPropertyConverter(collection);
String entityTypeName = collection.getEntityTypeName();
GraphTraversal[] propertyGetters = collection.getReadableProperties().entrySet().stream().map(prop -> prop.getValue().traversalRaw().sideEffect(x -> x.get().onSuccess(value -> {
try {
properties.add(dbPropertyConverter.from(prop.getKey(), value));
} catch (UnknownPropertyException e) {
LOG.error("Unknown property", e);
} catch (IOException e) {
LOG.error(databaseInvariant, "Property '" + prop.getKey() + "' is not encoded correctly", e.getCause());
}
}).onFailure(e -> {
if (e.getCause() instanceof IOException) {
LOG.error(databaseInvariant, "Property '" + prop.getKey() + "' is not encoded correctly", e.getCause());
} else {
LOG.error("Something went wrong while reading the property '" + prop.getKey() + "'.", e.getCause());
}
}))).toArray(GraphTraversal[]::new);
entityT.asAdmin().clone().union(propertyGetters).forEachRemaining(x -> {
// Force side effects to happen
});
ReadEntityImpl entity = new ReadEntityImpl();
entity.setProperties(properties);
Vertex entityVertex = entityT.asAdmin().clone().next();
// TODO make use conversion for the types
entity.setRev(getProp(entityVertex, "rev", Integer.class).orElse(-1));
entity.setDeleted(getProp(entityVertex, "deleted", Boolean.class).orElse(false));
entity.setPid(getProp(entityVertex, "pid", String.class).orElse(null));
URI rdfUri = getProp(entityVertex, RDF_URI_PROP, String.class).map(x -> {
try {
return new URI(x);
} catch (URISyntaxException e) {
return null;
}
}).orElse(null);
entity.setRdfUri(rdfUri);
Property<String[]> rdfAlternativesProp = entityVertex.property(RDF_SYNONYM_PROP);
if (rdfAlternativesProp.isPresent()) {
try {
entity.setRdfAlternatives(Lists.newArrayList(rdfAlternativesProp.value()));
} catch (Exception e) {
LOG.error(databaseInvariant, "Error while reading rdfAlternatives", e);
}
}
Optional<String> typesOptional = getProp(entityVertex, "types", String.class);
if (typesOptional.isPresent()) {
try {
List<String> types = new ObjectMapper().readValue(typesOptional.get(), new TypeReference<List<String>>() {
});
entity.setTypes(types);
} catch (Exception e) {
LOG.error(databaseInvariant, "Error while generating variation refs", e);
entity.setTypes(Lists.newArrayList(entityTypeName));
}
} else {
entity.setTypes(Lists.newArrayList(entityTypeName));
}
Optional<String> modifiedStringOptional = getProp(entityVertex, "modified", String.class);
if (modifiedStringOptional.isPresent()) {
try {
entity.setModified(new ObjectMapper().readValue(modifiedStringOptional.get(), Change.class));
} catch (IOException e) {
LOG.error(databaseInvariant, "Change cannot be converted", e);
entity.setModified(new Change());
}
} else {
entity.setModified(new Change());
}
Optional<String> createdStringOptional = getProp(entityVertex, "created", String.class);
if (createdStringOptional.isPresent()) {
try {
entity.setCreated(new ObjectMapper().readValue(createdStringOptional.get(), Change.class));
} catch (IOException e) {
LOG.error(databaseInvariant, "Change cannot be converted", e);
entity.setCreated(new Change());
}
} else {
entity.setCreated(new Change());
}
entity.setDisplayName(DisplayNameHelper.getDisplayname(traversalSource, entityVertex, collection).orElse(""));
entity.setId(getIdOrDefault(entityVertex));
if (withRelations) {
entity.setRelations(getRelations(entityVertex, traversalSource, collection));
}
customEntityProperties.execute(entity, entityVertex);
return entity;
}
use of nl.knaw.huygens.timbuctoo.model.Change in project timbuctoo by HuygensING.
the class FileLogOutput method newEdge.
@Override
public void newEdge(Edge edge) {
String modifiedString = edge.value("modified");
try {
Change modified = objectMapper.readValue(modifiedString, Change.class);
writeAndFlush(String.format("%d - Edge with tim_id '%s' between Vertex with tim_id '%s' and Vertex with tim_id '%s' created.%n", modified.getTimeStamp(), edge.value("tim_id"), edge.outVertex().value("tim_id"), edge.inVertex().value("tim_id")));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of nl.knaw.huygens.timbuctoo.model.Change in project timbuctoo by HuygensING.
the class FileLogOutput method updateEdge.
@Override
public void updateEdge(Edge edge) {
String modifiedString = edge.value("modified");
try {
Change modified = objectMapper.readValue(modifiedString, Change.class);
writeAndFlush(String.format("%d - Edge with tim_id '%s' between Vertex with tim_id '%s' and Vertex with tim_id '%s' updated.%n", modified.getTimeStamp(), edge.value("tim_id"), edge.outVertex().value("tim_id"), edge.inVertex().value("tim_id")));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of nl.knaw.huygens.timbuctoo.model.Change in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method deleteEntitySetsModified.
@Test
public void deleteEntitySetsModified() throws Exception {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testthings").get();
UUID id = UUID.randomUUID();
String idString = id.toString();
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withTimId(idString).withProperty("isLatest", true).withVre("test").withType("thing").withProperty("rev", 1).withIncomingRelation("VERSION_OF", "orig")).withVertex("orig", v -> v.withTimId(idString).withVre("test").withType("thing").withProperty("isLatest", false).withProperty("rev", 1)).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
long timeStamp = Instant.now().toEpochMilli();
String userId = "userId";
instance.deleteEntity(collection, id, new Change(timeStamp, userId, null));
assertThat(graphManager.getGraph().traversal().V().has("tim_id", idString).has("deleted", true).next().value("modified"), sameJSONAs(String.format("{\"timeStamp\": %s,\"userId\": \"%s\"}", timeStamp, userId)));
}
Aggregations