Search in sources :

Example 1 with NameValue

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);
    }
}
Also used : NameValue(net.nemerosa.ontrack.model.support.NameValue)

Example 2 with NameValue

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;
}
Also used : NameValue(net.nemerosa.ontrack.model.support.NameValue) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 3 with NameValue

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);
}
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 4 with NameValue

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;
}
Also used : NameValue(net.nemerosa.ontrack.model.support.NameValue) HashMap(java.util.HashMap) PropertyTypeNotFoundException(net.nemerosa.ontrack.model.exceptions.PropertyTypeNotFoundException)

Aggregations

NameValue (net.nemerosa.ontrack.model.support.NameValue)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 HashMap (java.util.HashMap)1 Event (net.nemerosa.ontrack.model.events.Event)1 PropertyTypeNotFoundException (net.nemerosa.ontrack.model.exceptions.PropertyTypeNotFoundException)1 ProjectEntity (net.nemerosa.ontrack.model.structure.ProjectEntity)1 ProjectEntityType (net.nemerosa.ontrack.model.structure.ProjectEntityType)1 Signature (net.nemerosa.ontrack.model.structure.Signature)1