Search in sources :

Example 1 with Signature

use of net.nemerosa.ontrack.model.structure.Signature in project ontrack by nemerosa.

the class EventJdbcRepository method toEvent.

private Event toEvent(ResultSet rs, BiFunction<ProjectEntityType, ID, ProjectEntity> entityLoader, Function<String, EventType> eventTypeLoader) throws SQLException {
    // Event type name
    String eventTypeName = rs.getString("event_type");
    // Signature
    Signature signature = readSignature(rs, "event_time", "event_user");
    // Entities
    Map<ProjectEntityType, ProjectEntity> entities = new LinkedHashMap<>();
    for (ProjectEntityType type : ProjectEntityType.values()) {
        int entityId = rs.getInt(type.name());
        if (!rs.wasNull()) {
            ProjectEntity entity = entityLoader.apply(type, ID.of(entityId));
            entities.put(type, entity);
        }
    }
    // Reference (if any)
    ProjectEntityType refEntity = getEnum(ProjectEntityType.class, rs, "ref");
    // Values
    Map<String, NameValue> values = loadValues(rs);
    // OK
    return new Event(eventTypeLoader.apply(eventTypeName), signature, entities, refEntity, values);
}
Also used : NameValue(net.nemerosa.ontrack.model.support.NameValue) ProjectEntityType(net.nemerosa.ontrack.model.structure.ProjectEntityType) ProjectEntity(net.nemerosa.ontrack.model.structure.ProjectEntity) Signature(net.nemerosa.ontrack.model.structure.Signature) Event(net.nemerosa.ontrack.model.events.Event)

Example 2 with Signature

use of net.nemerosa.ontrack.model.structure.Signature in project ontrack by nemerosa.

the class TimeTest method end_to_end.

@Test
public void end_to_end() throws JsonProcessingException {
    // Server time
    LocalDateTime time = Time.now();
    System.out.format("Server time: %s%n", time);
    // For storage
    String stored = Time.forStorage(time);
    System.out.format("Stored time: %s%n", stored);
    // From storage
    LocalDateTime retrieved = Time.fromStorage(stored);
    System.out.format("Retrieved time: %s%n", retrieved);
    // Out for JSON
    Signature signature = Signature.of(time, "user");
    JsonNode jsonNode = ObjectMapperFactory.create().valueToTree(signature);
    String json = ObjectMapperFactory.create().writeValueAsString(jsonNode);
    System.out.format("JSON output: %s%n", json);
    // Extracts the date from the JSON
    String jsonTime = jsonNode.path("time").asText();
    System.out.format("JSON time: %s%n", jsonTime);
    // Converts to a LocalDateTime
    LocalDateTime parsed = LocalDateTime.parse(jsonTime, DateTimeFormatter.ISO_DATE_TIME);
    System.out.format("Parsed time: %s%n", parsed);
    // Checks equality
    assertEquals("The initial date & the parsed date must be equal", time, parsed);
}
Also used : LocalDateTime(java.time.LocalDateTime) Signature(net.nemerosa.ontrack.model.structure.Signature) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.Test)

Aggregations

Signature (net.nemerosa.ontrack.model.structure.Signature)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 LocalDateTime (java.time.LocalDateTime)1 Event (net.nemerosa.ontrack.model.events.Event)1 ProjectEntity (net.nemerosa.ontrack.model.structure.ProjectEntity)1 ProjectEntityType (net.nemerosa.ontrack.model.structure.ProjectEntityType)1 NameValue (net.nemerosa.ontrack.model.support.NameValue)1 Test (org.junit.Test)1