Search in sources :

Example 1 with NotificationModeType

use of com.willshex.blogwt.shared.api.datatype.NotificationModeType in project blogwt by billy1380.

the class MetaNotificationsPage method modes.

SafeHtml modes(List<NotificationModeType> modes) {
    SafeHtmlBuilder b = new SafeHtmlBuilder();
    boolean first = true;
    for (NotificationModeType t : Arrays.stream(NotificationModeType.values()).sorted((l, r) -> l.toString().compareTo(r.toString())).collect(Collectors.toList())) {
        if (!first) {
            b.appendEscaped(" ");
        } else {
            first = false;
        }
        b.appendEscaped(t.toString() + "(");
        if (modes == null || !modes.contains(t)) {
            b.append(PagesPageTemplates.INSTANCE.no());
        } else {
            b.append(PagesPageTemplates.INSTANCE.yes());
        }
        b.appendEscaped(")");
    }
    return b.toSafeHtml();
}
Also used : Arrays(java.util.Arrays) MetaNotificationController(com.willshex.blogwt.client.controller.MetaNotificationController) NotificationModeType(com.willshex.blogwt.shared.api.datatype.NotificationModeType) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) LoadingPanel(com.willshex.blogwt.client.part.LoadingPanel) UiHandler(com.google.gwt.uibinder.client.UiHandler) PagerHelper(com.willshex.blogwt.shared.helper.PagerHelper) GWT(com.google.gwt.core.client.GWT) PageType(com.willshex.blogwt.shared.page.PageType) UiBinder(com.google.gwt.uibinder.client.UiBinder) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) PagesPageTemplates(com.willshex.blogwt.client.page.admin.PagesPage.PagesPageTemplates) Page(com.willshex.blogwt.client.page.Page) Button(com.google.gwt.user.client.ui.Button) UiHelper(com.willshex.blogwt.client.helper.UiHelper) Collectors(java.util.stream.Collectors) MetaNotification(com.willshex.blogwt.shared.api.datatype.MetaNotification) List(java.util.List) Widget(com.google.gwt.user.client.ui.Widget) TextColumn(com.google.gwt.user.cellview.client.TextColumn) Column(com.google.gwt.user.cellview.client.Column) NoneFoundPanel(com.willshex.blogwt.client.part.NoneFoundPanel) UiField(com.google.gwt.uibinder.client.UiField) SimplePager(com.willshex.blogwt.client.part.SimplePager) CellTable(com.google.gwt.user.cellview.client.CellTable) PageTypeHelper(com.willshex.blogwt.client.helper.PageTypeHelper) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) BootstrapGwtCellTable(com.willshex.blogwt.client.part.BootstrapGwtCellTable) NotificationModeType(com.willshex.blogwt.shared.api.datatype.NotificationModeType) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder)

Example 2 with NotificationModeType

use of com.willshex.blogwt.shared.api.datatype.NotificationModeType in project blogwt by billy1380.

the class MetaNotificationDetailPage method showMetaNotification.

private void showMetaNotification(MetaNotification metaNotification) {
    txtCode.setText(metaNotification.code);
    txtName.setText(metaNotification.name);
    txtContent.setText(metaNotification.content);
    txtGroup.setText(metaNotification.group);
    if (metaNotification.modes != null) {
        for (NotificationModeType mode : metaNotification.modes) {
            switch(mode) {
                case NotificationModeTypeEmail:
                    cboModeEmail.setValue(Boolean.TRUE, true);
                    break;
                case NotificationModeTypePush:
                    cboModePush.setValue(Boolean.TRUE, true);
                    break;
                case NotificationModeTypeSms:
                    cboModeSms.setValue(Boolean.TRUE, true);
                    break;
            }
        }
    }
    if (metaNotification.defaults != null) {
        for (NotificationModeType mode : metaNotification.defaults) {
            switch(mode) {
                case NotificationModeTypeEmail:
                    cboDefaultEmail.setValue(Boolean.TRUE, true);
                    break;
                case NotificationModeTypePush:
                    cboDefaultPush.setValue(Boolean.TRUE, true);
                    break;
                case NotificationModeTypeSms:
                    cboDefaultSms.setValue(Boolean.TRUE, true);
                    break;
            }
        }
    }
}
Also used : NotificationModeType(com.willshex.blogwt.shared.api.datatype.NotificationModeType)

Example 3 with NotificationModeType

use of com.willshex.blogwt.shared.api.datatype.NotificationModeType in project blogwt by billy1380.

the class NotificationHelper method sendNotification.

public static List<Notification> sendNotification(String code, User user, final Map<String, ?> values) {
    List<Notification> notifications = new ArrayList<>();
    final MetaNotification meta = MetaNotificationServiceProvider.provide().getCodeMetaNotification(code);
    if (meta == null) {
        if (LOG.isLoggable(Level.WARNING)) {
            LOG.warning("No meta notification found for code [" + code + "]");
        }
    } else {
        NotificationSetting setting = NotificationSettingServiceProvider.provide().getMetaUserNotificationSetting(meta, user);
        if (setting == null) {
            setting = NotificationSettingServiceProvider.provide().addNotificationSetting(new NotificationSetting().meta(meta).selected(meta.defaults).user(user));
        }
        String content;
        final Notification template = new Notification().content(content = InflatorHelper.inflate(values, meta.content)).meta(meta).target(user);
        Notification notification;
        String title = "Message from " + PropertyHelper.value(PropertyServiceProvider.provide().getNamedProperty(PropertyHelper.TITLE));
        if (setting.selected == null || setting.selected.size() == 0) {
            if (LOG.isLoggable(Level.INFO)) {
                LOG.info("No notification modes found for [" + code + "] and user [" + user + "] adding template [" + template + "]");
            }
            notifications.add(NotificationServiceProvider.provide().addNotification(template));
        } else {
            for (NotificationModeType mode : setting.selected) {
                notification = JsonableHelper.copy(template, new Notification()).mode(mode);
                switch(mode) {
                    case NotificationModeTypeEmail:
                        EmailHelper.sendEmail(user.email, UserHelper.name(user), title, content, false);
                        break;
                    case NotificationModeTypePush:
                        List<PushToken> tokens = PushTokenServiceProvider.provide().getUserPushTokens(user);
                        Jsonable data = new Jsonable() {

                            @Override
                            public JsonObject toJson() {
                                JsonObject object = super.toJson();
                                object.addProperty("code", meta.code);
                                if (values != null) {
                                    Object value;
                                    DataType slim;
                                    for (String key : values.keySet()) {
                                        value = values.get(key);
                                        if (value instanceof DataType) {
                                            slim = PersistenceHelper.slim(DataType.class, (DataType) value, null);
                                            object.add(key, slim.toJson());
                                        }
                                    }
                                }
                                return object;
                            }
                        };
                        for (PushToken pushToken : tokens) {
                            PushHelper.push(pushToken, meta.name, content, data);
                        }
                        if (LOG.isLoggable(Level.FINE) && tokens.size() == 0) {
                            LOG.fine("Could not push because no tokens found [" + meta.name + "], [" + content + "] payload approximation [" + PushHelper.buildPayload(new PushToken().platform("android").user(user).value("approx-test-token"), new AndroidMessage().title(meta.name).body(content), data) + "]");
                        }
                        break;
                    case NotificationModeTypeSms:
                        break;
                }
                notifications.add(NotificationServiceProvider.provide().addNotification(notification));
            }
        }
    }
    return notifications;
}
Also used : AndroidMessage(com.willshex.blogwt.server.helper.push.AndroidMessage) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) MetaNotification(com.willshex.blogwt.shared.api.datatype.MetaNotification) Jsonable(com.willshex.gson.shared.Jsonable) Notification(com.willshex.blogwt.shared.api.datatype.Notification) MetaNotification(com.willshex.blogwt.shared.api.datatype.MetaNotification) NotificationSetting(com.willshex.blogwt.shared.api.datatype.NotificationSetting) DataType(com.willshex.blogwt.shared.api.datatype.DataType) JsonObject(com.google.gson.JsonObject) NotificationModeType(com.willshex.blogwt.shared.api.datatype.NotificationModeType) PushToken(com.willshex.blogwt.shared.api.datatype.PushToken)

Aggregations

NotificationModeType (com.willshex.blogwt.shared.api.datatype.NotificationModeType)3 MetaNotification (com.willshex.blogwt.shared.api.datatype.MetaNotification)2 JsonObject (com.google.gson.JsonObject)1 GWT (com.google.gwt.core.client.GWT)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)1 SafeHtmlBuilder (com.google.gwt.safehtml.shared.SafeHtmlBuilder)1 UiBinder (com.google.gwt.uibinder.client.UiBinder)1 UiField (com.google.gwt.uibinder.client.UiField)1 UiHandler (com.google.gwt.uibinder.client.UiHandler)1 CellTable (com.google.gwt.user.cellview.client.CellTable)1 Column (com.google.gwt.user.cellview.client.Column)1 TextColumn (com.google.gwt.user.cellview.client.TextColumn)1 Button (com.google.gwt.user.client.ui.Button)1 Widget (com.google.gwt.user.client.ui.Widget)1 MetaNotificationController (com.willshex.blogwt.client.controller.MetaNotificationController)1 PageTypeHelper (com.willshex.blogwt.client.helper.PageTypeHelper)1 UiHelper (com.willshex.blogwt.client.helper.UiHelper)1 Page (com.willshex.blogwt.client.page.Page)1 PagesPageTemplates (com.willshex.blogwt.client.page.admin.PagesPage.PagesPageTemplates)1