use of net.nemerosa.ontrack.model.structure.ProjectEntity 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.ProjectEntity 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.ProjectEntity in project ontrack by nemerosa.
the class PropertyJdbcRepository method searchByProperty.
@Override
public Collection<ProjectEntity> searchByProperty(String typeName, BiFunction<ProjectEntityType, ID, ProjectEntity> entityLoader, Predicate<TProperty> predicate) {
return getNamedParameterJdbcTemplate().execute("SELECT * FROM PROPERTIES WHERE TYPE = :type ORDER BY ID DESC", params("type", typeName), (PreparedStatement ps) -> {
Collection<ProjectEntity> entities = new ArrayList<>();
ResultSet rs = ps.executeQuery();
while (rs.next()) {
TProperty t = toProperty(rs);
if (predicate.test(t)) {
entities.add(entityLoader.apply(t.getEntityType(), t.getEntityId()));
}
}
return entities;
});
}
use of net.nemerosa.ontrack.model.structure.ProjectEntity 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)));
}
use of net.nemerosa.ontrack.model.structure.ProjectEntity in project ontrack by nemerosa.
the class DecorationServiceImplTest method base_exception_decoration_generates_default_error_decoration.
@Test
public void base_exception_decoration_generates_default_error_decoration() {
ProjectEntity projectEntity = mock(ProjectEntity.class);
DecorationExtension decorator = mock(DecorationExtension.class);
when(decorator.getDecorations(any(ProjectEntity.class))).thenThrow(new TestBaseException());
ExtensionManager extensionManager = mock(ExtensionManager.class);
when(extensionManager.getExtensions(DecorationExtension.class)).thenReturn(Collections.singletonList(decorator));
SecurityService securityService = mock(SecurityService.class);
DecorationServiceImpl service = new DecorationServiceImpl(extensionManager, securityService);
@SuppressWarnings("unchecked") List<? extends Decoration> decorations = service.getDecorations(projectEntity, decorator);
assertNotNull(decorations);
assertEquals(1, decorations.size());
Decoration decoration = decorations.get(0);
assertEquals("Known exception", decoration.getError());
assertNull(decoration.getData());
}
Aggregations