Search in sources :

Example 46 with Change

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;
}
Also used : Change(nl.knaw.huygens.timbuctoo.model.Change)

Example 47 with 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;
}
Also used : JsonBuilder(nl.knaw.huygens.timbuctoo.util.JsonBuilder) UserValidator(nl.knaw.huygens.timbuctoo.v5.security.UserValidator) JsonBuilder.jsnO(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsnO) JsonBuilder(nl.knaw.huygens.timbuctoo.util.JsonBuilder) LoggerFactory(org.slf4j.LoggerFactory) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) Tuple(nl.knaw.huygens.timbuctoo.util.Tuple) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) UrlGenerator(nl.knaw.huygens.timbuctoo.crud.UrlGenerator) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Strings(com.google.common.base.Strings) JsonBuilder.jsnA(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsnA) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonBuilder.jsn(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsn) Logmarkers.databaseInvariant(nl.knaw.huygens.timbuctoo.logging.Logmarkers.databaseInvariant) RelationRef(nl.knaw.huygens.timbuctoo.core.dto.RelationRef) Logger(org.slf4j.Logger) TimProperty(nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) UUID(java.util.UUID) ReadEntity(nl.knaw.huygens.timbuctoo.core.dto.ReadEntity) List(java.util.List) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory) Change(nl.knaw.huygens.timbuctoo.model.Change) Tuple.tuple(nl.knaw.huygens.timbuctoo.util.Tuple.tuple) UserValidationException(nl.knaw.huygens.timbuctoo.v5.security.exceptions.UserValidationException) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) Change(nl.knaw.huygens.timbuctoo.model.Change) IOException(java.io.IOException)

Example 48 with Change

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);
    }
}
Also used : Change(nl.knaw.huygens.timbuctoo.model.Change) IOException(java.io.IOException)

Example 49 with Change

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);
    }
}
Also used : Change(nl.knaw.huygens.timbuctoo.model.Change) IOException(java.io.IOException)

Example 50 with Change

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);
    }
}
Also used : Instant(java.time.Instant) Change(nl.knaw.huygens.timbuctoo.model.Change) LocalDate(java.time.LocalDate) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

Change (nl.knaw.huygens.timbuctoo.model.Change)52 Collection (nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection)40 Test (org.junit.Test)40 UUID (java.util.UUID)39 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)34 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)33 IOException (java.io.IOException)33 TimProperty (nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty)31 UpdateEntity (nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity)30 Instant (java.time.Instant)29 List (java.util.List)29 ReadEntity (nl.knaw.huygens.timbuctoo.core.dto.ReadEntity)29 Vres (nl.knaw.huygens.timbuctoo.model.vre.Vres)29 Lists (com.google.common.collect.Lists)28 URI (java.net.URI)28 Optional (java.util.Optional)28 Collectors.toList (java.util.stream.Collectors.toList)28 CreateCollection (nl.knaw.huygens.timbuctoo.core.dto.CreateCollection)28 CreateEntity (nl.knaw.huygens.timbuctoo.core.dto.CreateEntity)28 ArrayList (java.util.ArrayList)27