Search in sources :

Example 1 with ApplicationUninstalledJson

use of com.enonic.xp.impl.server.rest.model.ApplicationUninstalledJson in project xp by enonic.

the class SseEntryPoint method handleEvent.

private void handleEvent(final Event event, final String eventSubType) {
    final SseContextHolder ctx = contextHolder;
    if (ctx == null) {
        LOG.debug("Skipping {} {}. Please to subscribe to send SSE events.", EVENT_TYPE, eventSubType);
        return;
    }
    if (event.getValue(APPLICATION_KEY_PARAM).isPresent()) {
        final OutboundSseEvent.Builder eventBuilder = ctx.sse.newEventBuilder().name(eventSubType).id(UUID.randomUUID().toString()).mediaType(MediaType.APPLICATION_JSON_TYPE);
        if (UNINSTALLED.equals(eventSubType)) {
            eventBuilder.data(ApplicationUninstalledJson.class, new ApplicationUninstalledJson(event.getValue(APPLICATION_KEY_PARAM).get().toString()));
        } else {
            final ApplicationKey applicationKey = ApplicationKey.from(event.getValue(APPLICATION_KEY_PARAM).get().toString());
            final Application application = applicationService.getInstalledApplication(applicationKey);
            if (application == null) {
                LOG.warn("Application \"{}\" not found", applicationKey);
                return;
            }
            final boolean localApplication = applicationService.isLocalApplication(application.getKey());
            eventBuilder.data(ApplicationInfoJson.class, new ApplicationInfoJson(application, localApplication));
        }
        ctx.broadcaster.broadcast(eventBuilder.build());
    }
}
Also used : ApplicationInfoJson(com.enonic.xp.impl.server.rest.model.ApplicationInfoJson) OutboundSseEvent(javax.ws.rs.sse.OutboundSseEvent) ApplicationKey(com.enonic.xp.app.ApplicationKey) ApplicationUninstalledJson(com.enonic.xp.impl.server.rest.model.ApplicationUninstalledJson) Application(com.enonic.xp.app.Application)

Aggregations

Application (com.enonic.xp.app.Application)1 ApplicationKey (com.enonic.xp.app.ApplicationKey)1 ApplicationInfoJson (com.enonic.xp.impl.server.rest.model.ApplicationInfoJson)1 ApplicationUninstalledJson (com.enonic.xp.impl.server.rest.model.ApplicationUninstalledJson)1 OutboundSseEvent (javax.ws.rs.sse.OutboundSseEvent)1