use of net.nemerosa.ontrack.model.support.NameValue in project ontrack by nemerosa.
the class Event method expandExpression.
private String expandExpression(String expression, EventRenderer eventRenderer) {
if (StringUtils.startsWith(expression, ":")) {
String valueKey = expression.substring(1);
NameValue value = values.get(valueKey);
if (value == null) {
throw new EventMissingValueException(eventType.getTemplate(), valueKey);
}
return eventRenderer.render(valueKey, value, this);
} else if ("REF".equals(expression)) {
if (ref == null) {
throw new EventMissingRefEntityException(eventType.getTemplate());
} else {
ProjectEntity entity = entities.get(ref);
if (entity == null) {
throw new EventMissingEntityException(eventType.getTemplate(), ref);
}
return eventRenderer.render(entity, this);
}
} else {
// Project entity type
ProjectEntityType projectEntityType = ProjectEntityType.valueOf(expression);
// Gets the corresponding entity
ProjectEntity projectEntity = entities.get(projectEntityType);
if (projectEntity == null) {
throw new EventMissingEntityException(eventType.getTemplate(), projectEntityType);
}
// Rendering
return eventRenderer.render(projectEntity, this);
}
}
use of net.nemerosa.ontrack.model.support.NameValue in project ontrack by nemerosa.
the class EventJdbcRepository method loadValues.
private Map<String, NameValue> loadValues(ResultSet rs) throws SQLException {
Map<String, NameValue> map = new LinkedHashMap<>();
JsonNode node = readJson(rs, "event_values");
Iterator<Map.Entry<String, JsonNode>> i = node.fields();
while (i.hasNext()) {
Map.Entry<String, JsonNode> child = i.next();
String key = child.getKey();
JsonNode nameValue = child.getValue();
map.put(key, new NameValue(nameValue.path("name").asText(), nameValue.path("value").asText()));
}
return map;
}
use of net.nemerosa.ontrack.model.support.NameValue 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.support.NameValue in project ontrack by nemerosa.
the class EventController method computeData.
protected Map<String, ?> computeData(Event event) {
// Result
Map<String, ? super Object> result = new HashMap<>();
// Any property in values?
NameValue property = event.getValues().get("property");
if (property != null) {
String propertyName = property.getName();
// Gets the property type by name
try {
PropertyType<?> propertyType = propertyService.getPropertyTypeByName(propertyName);
result.put("property", PropertyTypeDescriptor.of(propertyType));
} catch (PropertyTypeNotFoundException ignored) {
// Logs and ignores
logger.warn("[event] Could not find property type for {}", propertyName);
}
}
// OK
return result;
}
Aggregations