Search in sources :

Example 1 with ProjectEntityType

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

the class EventJdbcRepository method post.

@Override
public void post(Event event) {
    StringBuilder sql = new StringBuilder("INSERT INTO EVENTS(EVENT_VALUES, EVENT_TIME, EVENT_USER, EVENT_TYPE, REF");
    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("eventValues", writeJson(event.getValues()));
    params.addValue("eventTime", dateTimeForDB(event.getSignature().getTime()));
    params.addValue("eventUser", event.getSignature().getUser().getName());
    params.addValue("eventType", event.getEventType().getId());
    params.addValue("ref", event.getRef() != null ? event.getRef().name() : null);
    for (ProjectEntityType type : event.getEntities().keySet()) {
        sql.append(", ").append(type.name());
    }
    sql.append(") VALUES (:eventValues, :eventTime, :eventUser, :eventType, :ref");
    for (Map.Entry<ProjectEntityType, ProjectEntity> entry : event.getEntities().entrySet()) {
        ProjectEntityType type = entry.getKey();
        ProjectEntity entity = entry.getValue();
        String typeEntry = type.name().toLowerCase();
        sql.append(", :").append(typeEntry);
        params.addValue(typeEntry, entity.id());
    }
    sql.append(")");
    getNamedParameterJdbcTemplate().update(sql.toString(), params);
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) ProjectEntityType(net.nemerosa.ontrack.model.structure.ProjectEntityType) ProjectEntity(net.nemerosa.ontrack.model.structure.ProjectEntity)

Example 2 with ProjectEntityType

use of net.nemerosa.ontrack.model.structure.ProjectEntityType 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 3 with ProjectEntityType

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

the class PropertyJdbcRepository method toProperty.

private TProperty toProperty(ResultSet rs) throws SQLException {
    int id = rs.getInt("id");
    String searchKey = rs.getString("searchKey");
    String typeName = rs.getString("type");
    // Detects the entity
    ProjectEntityType entityType = null;
    ID entityId = null;
    for (ProjectEntityType candidate : ProjectEntityType.values()) {
        Integer candidateId = rs.getInt(candidate.name());
        if (!rs.wasNull()) {
            entityType = candidate;
            entityId = ID.of(candidateId);
        }
    }
    // Sanity check
    if (entityType == null || !ID.isDefined(entityId)) {
        throw new IllegalStateException(String.format("Could not find any entity for property %s with key %s (id = %d)", typeName, searchKey, id));
    }
    // OK
    return new TProperty(typeName, entityType, entityId, searchKey, readJson(rs, "json"));
}
Also used : ProjectEntityType(net.nemerosa.ontrack.model.structure.ProjectEntityType) ID(net.nemerosa.ontrack.model.structure.ID)

Example 4 with ProjectEntityType

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

the class ProjectEntityExtensionController method getInformation.

/**
 * Gets the list of information extensions for an entity
 */
@RequestMapping(value = "information/{entityType}/{id}", method = RequestMethod.GET)
public Resources<EntityInformation> getInformation(@PathVariable ProjectEntityType entityType, @PathVariable ID id) {
    // Gets the entity
    ProjectEntity entity = getEntity(entityType, id);
    // List of informations to return
    List<EntityInformation> informations = extensionManager.getExtensions(EntityInformationExtension.class).stream().map(x -> x.getInformation(entity)).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
    // OK
    return Resources.of(informations, uri(MvcUriComponentsBuilder.on(getClass()).getInformation(entityType, id)));
}
Also used : EntityInformationExtension(net.nemerosa.ontrack.extension.api.EntityInformationExtension) PathVariable(org.springframework.web.bind.annotation.PathVariable) EntityInformation(net.nemerosa.ontrack.extension.api.model.EntityInformation) StructureService(net.nemerosa.ontrack.model.structure.StructureService) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Action(net.nemerosa.ontrack.model.support.Action) RestController(org.springframework.web.bind.annotation.RestController) Collectors(java.util.stream.Collectors) ProjectEntityType(net.nemerosa.ontrack.model.structure.ProjectEntityType) ProjectEntityActionExtension(net.nemerosa.ontrack.extension.api.ProjectEntityActionExtension) List(java.util.List) Resources(net.nemerosa.ontrack.ui.resource.Resources) MvcUriComponentsBuilder(org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder) EntityInformationExtension(net.nemerosa.ontrack.extension.api.EntityInformationExtension) ProjectEntity(net.nemerosa.ontrack.model.structure.ProjectEntity) Optional(java.util.Optional) ExtensionManager(net.nemerosa.ontrack.extension.api.ExtensionManager) ID(net.nemerosa.ontrack.model.structure.ID) Optional(java.util.Optional) ProjectEntity(net.nemerosa.ontrack.model.structure.ProjectEntity) EntityInformation(net.nemerosa.ontrack.extension.api.model.EntityInformation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ProjectEntityType (net.nemerosa.ontrack.model.structure.ProjectEntityType)4 ProjectEntity (net.nemerosa.ontrack.model.structure.ProjectEntity)3 ID (net.nemerosa.ontrack.model.structure.ID)2 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 EntityInformationExtension (net.nemerosa.ontrack.extension.api.EntityInformationExtension)1 ExtensionManager (net.nemerosa.ontrack.extension.api.ExtensionManager)1 ProjectEntityActionExtension (net.nemerosa.ontrack.extension.api.ProjectEntityActionExtension)1 EntityInformation (net.nemerosa.ontrack.extension.api.model.EntityInformation)1 Event (net.nemerosa.ontrack.model.events.Event)1 Signature (net.nemerosa.ontrack.model.structure.Signature)1 StructureService (net.nemerosa.ontrack.model.structure.StructureService)1 Action (net.nemerosa.ontrack.model.support.Action)1 NameValue (net.nemerosa.ontrack.model.support.NameValue)1 Resources (net.nemerosa.ontrack.ui.resource.Resources)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)1 PathVariable (org.springframework.web.bind.annotation.PathVariable)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1