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