Search in sources :

Example 1 with Event

use of net.nemerosa.ontrack.model.events.Event 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 2 with Event

use of net.nemerosa.ontrack.model.events.Event in project ontrack by nemerosa.

the class EventPostServiceImpl method post.

@Override
public void post(Event event) {
    Event e = event;
    if (e.getSignature() == null) {
        e = e.withSignature(securityService.getCurrentSignature());
    }
    eventRepository.post(e);
    // Notification to the listeners
    eventListenerService.onEvent(event);
}
Also used : Event(net.nemerosa.ontrack.model.events.Event)

Example 3 with Event

use of net.nemerosa.ontrack.model.events.Event in project ontrack by nemerosa.

the class ConfigurationServiceTest method event_on_delete_configuration.

@Test
public void event_on_delete_configuration() {
    TestConfiguration config = config("test");
    Event event = Event.of(EventFactory.DELETE_CONFIGURATION).with("configuration", "test").get();
    when(configurationRepository.find(TestConfiguration.class, "test")).thenReturn(Optional.of(config));
    when(eventFactory.deleteConfiguration(config.withPassword("xxxxx"))).thenReturn(event);
    when(encryptionService.decrypt(PLAIN_PASSWORD)).thenReturn("xxxxx");
    configurationService.deleteConfiguration("test");
    verify(eventPostService).post(event);
}
Also used : TestConfiguration(net.nemerosa.ontrack.extension.api.support.TestConfiguration) Event(net.nemerosa.ontrack.model.events.Event) Test(org.junit.Test)

Example 4 with Event

use of net.nemerosa.ontrack.model.events.Event in project ontrack by nemerosa.

the class ConfigurationServiceTest method event_on_update_configuration.

@Test
public void event_on_update_configuration() {
    TestConfiguration config = config("test");
    Event event = Event.of(EventFactory.UPDATE_CONFIGURATION).with("configuration", "test").get();
    when(eventFactory.updateConfiguration(config)).thenReturn(event);
    when(configurationRepository.find(TestConfiguration.class, "test")).thenReturn(Optional.of(config));
    configurationService.updateConfiguration("test", config);
    verify(eventPostService).post(event);
}
Also used : TestConfiguration(net.nemerosa.ontrack.extension.api.support.TestConfiguration) Event(net.nemerosa.ontrack.model.events.Event) Test(org.junit.Test)

Example 5 with Event

use of net.nemerosa.ontrack.model.events.Event in project ontrack by nemerosa.

the class ConfigurationServiceTest method event_on_new_configuration.

@Test
public void event_on_new_configuration() {
    TestConfiguration config = config("test");
    Event event = Event.of(EventFactory.NEW_CONFIGURATION).with("configuration", "test").get();
    when(eventFactory.newConfiguration(config)).thenReturn(event);
    configurationService.newConfiguration(config);
    verify(eventPostService).post(event);
}
Also used : TestConfiguration(net.nemerosa.ontrack.extension.api.support.TestConfiguration) Event(net.nemerosa.ontrack.model.events.Event) Test(org.junit.Test)

Aggregations

Event (net.nemerosa.ontrack.model.events.Event)5 TestConfiguration (net.nemerosa.ontrack.extension.api.support.TestConfiguration)3 Test (org.junit.Test)3 ProjectEntity (net.nemerosa.ontrack.model.structure.ProjectEntity)1 ProjectEntityType (net.nemerosa.ontrack.model.structure.ProjectEntityType)1 Signature (net.nemerosa.ontrack.model.structure.Signature)1 NameValue (net.nemerosa.ontrack.model.support.NameValue)1