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);
}
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);
}
Aggregations