Ejemplo n.º 1
0
  @Override
  public void process(NotificationContext ctx, String... userIds) {
    NotificationInfo notification = ctx.getNotificationInfo();
    String pluginId = notification.getKey().getId();
    UserSettingService userService =
        (UserSettingService)
            ExoContainerContext.getCurrentContainer()
                .getComponentInstanceOfType(UserSettingService.class);

    for (String userId : userIds) {
      UserSetting userSetting = userService.get(userId);
      // check channel active for user
      if (!userSetting.isChannelActive(getChannel().getId())) {
        continue;
      }

      if (userSetting.isActive(getChannel().getId(), pluginId)) {
        process(ctx.setNotificationInfo(notification.clone(true).setTo(userId)), userId);
      }
    }
  }
  @Override
  public Map<PluginKey, List<NotificationInfo>> getByUser(
      NotificationContext context, UserSetting setting) {
    boolean created = NotificationSessionManager.createSystemProvider();
    SessionProvider sProvider = NotificationSessionManager.getSessionProvider();

    Map<PluginKey, List<NotificationInfo>> notificationData =
        new LinkedHashMap<PluginKey, List<NotificationInfo>>();
    try {
      boolean isWeekly = context.value(NotificationJob.JOB_WEEKLY);
      if (isWeekly) {
        for (String pluginId : setting.getWeeklyPlugins()) {
          putMap(
              notificationData,
              PluginKey.key(pluginId),
              getWeeklyNotifs(sProvider, pluginId, setting.getUserId()));
        }
      }
      //
      boolean isDaily = context.value(NotificationJob.JOB_DAILY);
      if (isDaily) {
        for (String pluginId : setting.getDailyPlugins()) {
          putMap(
              notificationData,
              PluginKey.key(pluginId),
              getDailyNotifs(sProvider, context, pluginId, setting.getUserId()));
        }
      }
    } catch (Exception e) {
      LOG.error("Failed to get the NotificationMessage by user: " + setting.getUserId(), e);
    } finally {
      NotificationSessionManager.closeSessionProvider(created);
    }

    return notificationData;
  }
Ejemplo n.º 3
0
 private UserSetting createUserSetting(
     String userId, List<String> instantly, List<String> daily, List<String> weekly) {
   UserSetting model = new UserSetting();
   model.setUserId(userId);
   model.setChannelActive(UserSetting.EMAIL_CHANNEL);
   model.setDailyPlugins(daily);
   model.setChannelPlugins(UserSetting.EMAIL_CHANNEL, instantly);
   model.setWeeklyPlugins(weekly);
   return model;
 }
Ejemplo n.º 4
0
  public void testDisabledUser() throws Exception {
    User u =
        CommonsUtils.getService(OrganizationService.class)
            .getUserHandler()
            .createUserInstance("binh");
    u.setEmail("email@test");
    u.setFirstName("first");
    u.setLastName("last");
    u.setPassword("pwdADDSomeSaltToBeCompliantWithSomeIS00");
    CommonsUtils.getService(OrganizationService.class).getUserHandler().createUser(u, true);

    userSettingService.save(createUserSetting("binh", null, null, null));
    UserSetting userSetting = userSettingService.get("binh");
    assertTrue(userSetting.isChannelActive(MailChannel.ID));
    assertTrue(userSetting.isEnabled());

    // disable user "root"
    CommonsUtils.getService(OrganizationService.class)
        .getUserHandler()
        .setEnabled("binh", false, true);
    userSetting = userSettingService.get("binh");
    assertTrue(userSetting.isChannelActive(MailChannel.ID));
    assertFalse(userSetting.isEnabled());

    // enable user "root" but not change the active channel status
    CommonsUtils.getService(OrganizationService.class)
        .getUserHandler()
        .setEnabled("binh", true, true);
    userSetting = userSettingService.get("binh");
    assertTrue(userSetting.isChannelActive(MailChannel.ID));
    assertTrue(userSetting.isEnabled());

    CommonsUtils.getService(OrganizationService.class).getUserHandler().removeUser("binh", false);
    assertNull(
        CommonsUtils.getService(OrganizationService.class).getUserHandler().findUserByName("binh"));
  }