use of nl.knaw.huygens.timbuctoo.model.Change in project timbuctoo by HuygensING.
the class LogEntryFactoryTest method changeWithTimestamp.
private Change changeWithTimestamp(long timestamp) {
Change change = new Change();
change.setTimeStamp(timestamp);
return change;
}
use of nl.knaw.huygens.timbuctoo.model.Change in project timbuctoo by HuygensING.
the class EntityToJsonMapper method mapEntity.
public ObjectNode mapEntity(Collection collection, ReadEntity entity, boolean withRelations, ExtraEntityMappingOptions extraEntityMappingOptions, ExtraRelationMappingOptions relationMappingOptions) {
final ObjectNode mappedEntity = JsonNodeFactory.instance.objectNode();
String id = entity.getId().toString();
mappedEntity.set("@type", jsn(collection.getEntityTypeName()));
mappedEntity.set("_id", jsn(id));
mappedEntity.set("^rev", jsn(entity.getRev()));
mappedEntity.set("^deleted", jsn(entity.getDeleted()));
mappedEntity.set("^pid", jsn(entity.getPid()));
if (entity.getRdfUri() != null) {
mappedEntity.set("^rdfUri", jsn(entity.getRdfUri().toString()));
}
mappedEntity.set("^rdfAlternatives", jsnA(entity.getRdfAlternatives().stream().map(JsonBuilder::jsn)));
JsonNode variationRefs = jsnA(entity.getTypes().stream().map(type -> {
ObjectNode variationRef = jsnO();
variationRef.set("id", jsn(id));
variationRef.set("type", jsn(type));
return variationRef;
}));
mappedEntity.set("@variationRefs", variationRefs);
Change modified = entity.getModified();
mappedEntity.set("^modified", mapChange(modified));
Change created = entity.getCreated();
mappedEntity.set("^created", mapChange(created));
// translate TimProperties to Json
JsonPropertyConverter jsonPropertyConverter = new JsonPropertyConverter(collection);
entity.getProperties().forEach(prop -> {
try {
Tuple<String, JsonNode> convertedProperty = prop.convert(jsonPropertyConverter);
mappedEntity.set(convertedProperty.getLeft(), convertedProperty.getRight());
} catch (IOException e) {
LOG.error(databaseInvariant, propConversionErrorMessage(id, prop));
LOG.error("Exception message: {}", e.getMessage());
LOG.debug("Stack trace", e);
}
});
if (!Strings.isNullOrEmpty(entity.getDisplayName())) {
mappedEntity.set("@displayName", jsn(entity.getDisplayName()));
}
extraEntityMappingOptions.execute(entity, mappedEntity);
if (withRelations) {
mappedEntity.set("@relationCount", jsn(entity.getRelations().size()));
mappedEntity.set("@relations", mapRelations(entity.getRelations(), relationMappingOptions));
}
return mappedEntity;
}
use of nl.knaw.huygens.timbuctoo.model.Change in project timbuctoo by HuygensING.
the class FileLogOutput method newVertex.
@Override
public void newVertex(Vertex vertex) {
String modifiedString = vertex.value("modified");
try {
Change modified = objectMapper.readValue(modifiedString, Change.class);
writeAndFlush(String.format("%d - Vertex with tim_id '%s' created.%n", modified.getTimeStamp(), vertex.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 updateVertex.
@Override
public void updateVertex(Vertex vertex) {
String modifiedString = vertex.value("modified");
try {
Change modified = objectMapper.readValue(modifiedString, Change.class);
writeAndFlush(String.format("%d - Vertex with tim_id '%s' updated.%n", modified.getTimeStamp(), vertex.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 ChangeRangeFacetDescriptionTest method serializedChangeWithDate.
/**
* Serializes a Change with a json object mapper.
*
* @param dateString a date in the format yyyyMMdd
* @return the serialized Change
*/
private String serializedChangeWithDate(String dateString) {
try {
LocalDate localDate = LocalDate.parse(dateString, DateTimeFormatter.BASIC_ISO_DATE);
Instant instant = localDate.atStartOfDay(ZoneId.systemDefault()).toInstant();
Change change = new Change(instant.toEpochMilli(), "notImportant", "notImportant");
return new ObjectMapper().writeValueAsString(change);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations