Search in sources :

Example 1 with SystemMessage

use of org.guvnor.messageconsole.events.SystemMessage in project kie-wb-common by kiegroup.

the class ProjectMessagesListener method fireNotification.

void fireNotification(final AbstractNotification notification) {
    final ClientSession session = clientSessionManager.getCurrentSession();
    final Path path = session.getCanvasHandler().getDiagram().getMetadata().getPath();
    final SystemMessage systemMessage = new SystemMessage();
    final ArrayList<SystemMessage> messagesList = new ArrayList<>();
    switch(notification.getType()) {
        case ERROR:
            systemMessage.setLevel(Level.ERROR);
            break;
        case WARNING:
            systemMessage.setLevel(Level.WARNING);
            break;
        case INFO:
            systemMessage.setLevel(Level.INFO);
            break;
    }
    systemMessage.setText(notification.getMessage());
    systemMessage.setPath(path);
    messagesList.add(systemMessage);
    PublishMessagesEvent messages = new PublishMessagesEvent();
    messages.setMessagesToPublish(messagesList);
    publishMessagesEvent.fire(messages);
}
Also used : Path(org.uberfire.backend.vfs.Path) SystemMessage(org.guvnor.messageconsole.events.SystemMessage) PublishMessagesEvent(org.guvnor.messageconsole.events.PublishMessagesEvent) ClientSession(org.kie.workbench.common.stunner.core.client.session.ClientSession) ArrayList(java.util.ArrayList)

Example 2 with SystemMessage

use of org.guvnor.messageconsole.events.SystemMessage in project kie-wb-common by kiegroup.

the class ProjectMessagesListenerTest method testFireNotificationInfo.

@Test
public void testFireNotificationInfo() {
    NotificationContext context = new NotificationContext.Builder().build("test", "test", "test");
    Command<?, CanvasViolation> source = mock(Command.class);
    CommandNotification commandNotification = CommandNotification.Builder.build(context, source, Notification.Type.INFO, "message");
    projectMessagesListener.fireNotification(commandNotification);
    ArgumentCaptor<PublishMessagesEvent> eventCaptor = ArgumentCaptor.forClass(PublishMessagesEvent.class);
    verify(publishMessagesEvent, times(1)).fire(eventCaptor.capture());
    final List<SystemMessage> messagesToPublish = eventCaptor.getValue().getMessagesToPublish();
    assertEquals(messagesToPublish.size(), 1);
    SystemMessage message = messagesToPublish.get(0);
    assertEquals(message.getText(), "message");
    assertEquals(message.getLevel(), Level.INFO);
}
Also used : NotificationContext(org.kie.workbench.common.stunner.client.widgets.notification.NotificationContext) SystemMessage(org.guvnor.messageconsole.events.SystemMessage) CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) PublishMessagesEvent(org.guvnor.messageconsole.events.PublishMessagesEvent) CommandNotification(org.kie.workbench.common.stunner.client.widgets.notification.CommandNotification) Test(org.junit.Test)

Example 3 with SystemMessage

use of org.guvnor.messageconsole.events.SystemMessage in project kie-wb-common by kiegroup.

the class ProjectMessagesListenerTest method testFireNotificationWarning.

@Test
public void testFireNotificationWarning() {
    NotificationContext context = new NotificationContext.Builder().build("test", "test", "test");
    Command<?, CanvasViolation> source = mock(Command.class);
    CommandNotification commandNotification = CommandNotification.Builder.build(context, source, Notification.Type.WARNING, "message");
    projectMessagesListener.fireNotification(commandNotification);
    ArgumentCaptor<PublishMessagesEvent> eventCaptor = ArgumentCaptor.forClass(PublishMessagesEvent.class);
    verify(publishMessagesEvent, times(1)).fire(eventCaptor.capture());
    final List<SystemMessage> messagesToPublish = eventCaptor.getValue().getMessagesToPublish();
    assertEquals(messagesToPublish.size(), 1);
    SystemMessage message = messagesToPublish.get(0);
    assertEquals(message.getText(), "message");
    assertEquals(message.getLevel(), Level.WARNING);
}
Also used : NotificationContext(org.kie.workbench.common.stunner.client.widgets.notification.NotificationContext) SystemMessage(org.guvnor.messageconsole.events.SystemMessage) CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) PublishMessagesEvent(org.guvnor.messageconsole.events.PublishMessagesEvent) CommandNotification(org.kie.workbench.common.stunner.client.widgets.notification.CommandNotification) Test(org.junit.Test)

Example 4 with SystemMessage

use of org.guvnor.messageconsole.events.SystemMessage in project kie-wb-common by kiegroup.

the class DataModelerServiceImpl method processErrors.

private void processErrors(KieModule module, ModelDriverResult result) {
    PublishBatchMessagesEvent publishEvent = new PublishBatchMessagesEvent();
    publishEvent.setCleanExisting(true);
    publishEvent.setUserId(identity != null ? identity.getIdentifier() : null);
    publishEvent.setMessageType("DataModeler");
    SystemMessage systemMessage;
    for (DriverError error : result.getErrors()) {
        systemMessage = new SystemMessage();
        systemMessage.setMessageType("DataModeler");
        systemMessage.setLevel(Level.ERROR);
        systemMessage.setId(error.getId());
        systemMessage.setText(error.getMessage());
        systemMessage.setColumn(error.getColumn());
        systemMessage.setLine(error.getLine());
        systemMessage.setPath(error.getFile());
        publishEvent.getMessagesToPublish().add(systemMessage);
    }
    publishBatchMessagesEvent.fire(publishEvent);
}
Also used : SystemMessage(org.guvnor.messageconsole.events.SystemMessage) PublishBatchMessagesEvent(org.guvnor.messageconsole.events.PublishBatchMessagesEvent) DriverError(org.kie.workbench.common.services.datamodeller.driver.model.DriverError)

Example 5 with SystemMessage

use of org.guvnor.messageconsole.events.SystemMessage in project kie-wb-common by kiegroup.

the class DataModelerScreenPresenter method publishSystemMessages.

private void publishSystemMessages(String messageType, boolean cleanExisting, List<DataModelerError> errors) {
    PublishBatchMessagesEvent publishMessage = new PublishBatchMessagesEvent();
    publishMessage.setCleanExisting(cleanExisting);
    publishMessage.setMessageType(messageType);
    publishMessage.setUserId((sessionInfo != null && sessionInfo.getIdentity() != null) ? sessionInfo.getIdentity().getIdentifier() : null);
    publishMessage.setPlace(PublishBaseEvent.Place.TOP);
    SystemMessage systemMessage;
    for (DataModelerError error : errors) {
        systemMessage = new SystemMessage();
        systemMessage.setMessageType(messageType);
        systemMessage.setId(error.getId());
        systemMessage.setText(error.getMessage());
        systemMessage.setPath(error.getFile());
        systemMessage.setLevel(error.getLevel());
        systemMessage.setLine(error.getLine());
        systemMessage.setColumn(error.getColumn());
        publishMessage.getMessagesToPublish().add(systemMessage);
    }
    publishBatchMessagesEvent.fire(publishMessage);
}
Also used : SystemMessage(org.guvnor.messageconsole.events.SystemMessage) DataModelerError(org.kie.workbench.common.screens.datamodeller.model.DataModelerError) PublishBatchMessagesEvent(org.guvnor.messageconsole.events.PublishBatchMessagesEvent)

Aggregations

SystemMessage (org.guvnor.messageconsole.events.SystemMessage)6 PublishMessagesEvent (org.guvnor.messageconsole.events.PublishMessagesEvent)4 Test (org.junit.Test)3 CommandNotification (org.kie.workbench.common.stunner.client.widgets.notification.CommandNotification)3 NotificationContext (org.kie.workbench.common.stunner.client.widgets.notification.NotificationContext)3 CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)3 PublishBatchMessagesEvent (org.guvnor.messageconsole.events.PublishBatchMessagesEvent)2 ArrayList (java.util.ArrayList)1 DataModelerError (org.kie.workbench.common.screens.datamodeller.model.DataModelerError)1 DriverError (org.kie.workbench.common.services.datamodeller.driver.model.DriverError)1 ClientSession (org.kie.workbench.common.stunner.core.client.session.ClientSession)1 Path (org.uberfire.backend.vfs.Path)1