@Test
  public void testFetchByPrimaryKeyExisting() throws Exception {
    AnnouncementsDelivery newAnnouncementsDelivery = addAnnouncementsDelivery();

    AnnouncementsDelivery existingAnnouncementsDelivery =
        _persistence.fetchByPrimaryKey(newAnnouncementsDelivery.getPrimaryKey());

    Assert.assertEquals(existingAnnouncementsDelivery, newAnnouncementsDelivery);
  }
  @Test
  public void testCreate() throws Exception {
    long pk = ServiceTestUtil.nextLong();

    AnnouncementsDelivery announcementsDelivery = _persistence.create(pk);

    Assert.assertNotNull(announcementsDelivery);

    Assert.assertEquals(announcementsDelivery.getPrimaryKey(), pk);
  }
  @Test
  public void testRemove() throws Exception {
    AnnouncementsDelivery newAnnouncementsDelivery = addAnnouncementsDelivery();

    _persistence.remove(newAnnouncementsDelivery);

    AnnouncementsDelivery existingAnnouncementsDelivery =
        _persistence.fetchByPrimaryKey(newAnnouncementsDelivery.getPrimaryKey());

    Assert.assertNull(existingAnnouncementsDelivery);
  }
  @Test
  public void testDynamicQueryByPrimaryKeyExisting() throws Exception {
    AnnouncementsDelivery newAnnouncementsDelivery = addAnnouncementsDelivery();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(
            AnnouncementsDelivery.class, AnnouncementsDelivery.class.getClassLoader());

    dynamicQuery.add(
        RestrictionsFactoryUtil.eq("deliveryId", newAnnouncementsDelivery.getDeliveryId()));

    List<AnnouncementsDelivery> result = _persistence.findWithDynamicQuery(dynamicQuery);

    Assert.assertEquals(1, result.size());

    AnnouncementsDelivery existingAnnouncementsDelivery = result.get(0);

    Assert.assertEquals(existingAnnouncementsDelivery, newAnnouncementsDelivery);
  }
  @Test
  public void testResetOriginalValues() throws Exception {
    if (!PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
      return;
    }

    AnnouncementsDelivery newAnnouncementsDelivery = addAnnouncementsDelivery();

    _persistence.clearCache();

    AnnouncementsDeliveryModelImpl existingAnnouncementsDeliveryModelImpl =
        (AnnouncementsDeliveryModelImpl)
            _persistence.findByPrimaryKey(newAnnouncementsDelivery.getPrimaryKey());

    Assert.assertEquals(
        existingAnnouncementsDeliveryModelImpl.getUserId(),
        existingAnnouncementsDeliveryModelImpl.getOriginalUserId());
    Assert.assertTrue(
        Validator.equals(
            existingAnnouncementsDeliveryModelImpl.getType(),
            existingAnnouncementsDeliveryModelImpl.getOriginalType()));
  }
  @Test
  public void testDynamicQueryByProjectionExisting() throws Exception {
    AnnouncementsDelivery newAnnouncementsDelivery = addAnnouncementsDelivery();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(
            AnnouncementsDelivery.class, AnnouncementsDelivery.class.getClassLoader());

    dynamicQuery.setProjection(ProjectionFactoryUtil.property("deliveryId"));

    Object newDeliveryId = newAnnouncementsDelivery.getDeliveryId();

    dynamicQuery.add(RestrictionsFactoryUtil.in("deliveryId", new Object[] {newDeliveryId}));

    List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);

    Assert.assertEquals(1, result.size());

    Object existingDeliveryId = result.get(0);

    Assert.assertEquals(existingDeliveryId, newDeliveryId);
  }
  protected AnnouncementsDelivery addAnnouncementsDelivery() throws Exception {
    long pk = ServiceTestUtil.nextLong();

    AnnouncementsDelivery announcementsDelivery = _persistence.create(pk);

    announcementsDelivery.setCompanyId(ServiceTestUtil.nextLong());

    announcementsDelivery.setUserId(ServiceTestUtil.nextLong());

    announcementsDelivery.setType(ServiceTestUtil.randomString());

    announcementsDelivery.setEmail(ServiceTestUtil.randomBoolean());

    announcementsDelivery.setSms(ServiceTestUtil.randomBoolean());

    announcementsDelivery.setWebsite(ServiceTestUtil.randomBoolean());

    _persistence.update(announcementsDelivery, false);

    return announcementsDelivery;
  }
  @Test
  public void testUpdateExisting() throws Exception {
    long pk = ServiceTestUtil.nextLong();

    AnnouncementsDelivery newAnnouncementsDelivery = _persistence.create(pk);

    newAnnouncementsDelivery.setCompanyId(ServiceTestUtil.nextLong());

    newAnnouncementsDelivery.setUserId(ServiceTestUtil.nextLong());

    newAnnouncementsDelivery.setType(ServiceTestUtil.randomString());

    newAnnouncementsDelivery.setEmail(ServiceTestUtil.randomBoolean());

    newAnnouncementsDelivery.setSms(ServiceTestUtil.randomBoolean());

    newAnnouncementsDelivery.setWebsite(ServiceTestUtil.randomBoolean());

    _persistence.update(newAnnouncementsDelivery, false);

    AnnouncementsDelivery existingAnnouncementsDelivery =
        _persistence.findByPrimaryKey(newAnnouncementsDelivery.getPrimaryKey());

    Assert.assertEquals(
        existingAnnouncementsDelivery.getDeliveryId(), newAnnouncementsDelivery.getDeliveryId());
    Assert.assertEquals(
        existingAnnouncementsDelivery.getCompanyId(), newAnnouncementsDelivery.getCompanyId());
    Assert.assertEquals(
        existingAnnouncementsDelivery.getUserId(), newAnnouncementsDelivery.getUserId());
    Assert.assertEquals(
        existingAnnouncementsDelivery.getType(), newAnnouncementsDelivery.getType());
    Assert.assertEquals(
        existingAnnouncementsDelivery.getEmail(), newAnnouncementsDelivery.getEmail());
    Assert.assertEquals(existingAnnouncementsDelivery.getSms(), newAnnouncementsDelivery.getSms());
    Assert.assertEquals(
        existingAnnouncementsDelivery.getWebsite(), newAnnouncementsDelivery.getWebsite());
  }
示例#9
0
  protected void notifyUsers(
      List<User> users, AnnouncementsEntry entry, Locale locale, String toAddress, String toName)
      throws PortalException {

    if (_log.isDebugEnabled()) {
      _log.debug("Notifying " + users.size() + " users");
    }

    boolean notifyUsers = false;

    SubscriptionSender subscriptionSender = new SubscriptionSender();

    for (User user : users) {
      AnnouncementsDelivery announcementsDelivery =
          announcementsDeliveryLocalService.getUserDelivery(user.getUserId(), entry.getType());

      if (announcementsDelivery.isEmail()) {
        subscriptionSender.addRuntimeSubscribers(user.getEmailAddress(), user.getFullName());

        notifyUsers = true;
      }

      if (announcementsDelivery.isSms()) {
        String smsSn = user.getContact().getSmsSn();

        subscriptionSender.addRuntimeSubscribers(smsSn, user.getFullName());

        notifyUsers = true;
      }
    }

    if (!notifyUsers) {
      return;
    }

    String body = ContentUtil.get(PropsValues.ANNOUNCEMENTS_EMAIL_BODY);
    String fromAddress =
        PrefsPropsUtil.getStringFromNames(
            entry.getCompanyId(),
            PropsKeys.ANNOUNCEMENTS_EMAIL_FROM_ADDRESS,
            PropsKeys.ADMIN_EMAIL_FROM_ADDRESS);
    String fromName =
        PrefsPropsUtil.getStringFromNames(
            entry.getCompanyId(),
            PropsKeys.ANNOUNCEMENTS_EMAIL_FROM_NAME,
            PropsKeys.ADMIN_EMAIL_FROM_NAME);
    String subject = ContentUtil.get(PropsValues.ANNOUNCEMENTS_EMAIL_SUBJECT);

    subscriptionSender.setBody(body);
    subscriptionSender.setCompanyId(entry.getCompanyId());
    subscriptionSender.setContextAttribute("[$ENTRY_CONTENT$]", entry.getContent(), false);
    subscriptionSender.setContextAttributes(
        "[$ENTRY_ID$]",
        entry.getEntryId(),
        "[$ENTRY_TITLE$]",
        entry.getTitle(),
        "[$ENTRY_TYPE$]",
        LanguageUtil.get(locale, entry.getType()),
        "[$ENTRY_URL$]",
        entry.getUrl(),
        "[$PORTLET_NAME$]",
        LanguageUtil.get(locale, (entry.isAlert() ? "alert" : "announcement")));
    subscriptionSender.setFrom(fromAddress, fromName);
    subscriptionSender.setHtmlFormat(true);
    subscriptionSender.setMailId("announcements_entry", entry.getEntryId());
    subscriptionSender.setPortletId(PortletKeys.ANNOUNCEMENTS);
    subscriptionSender.setScopeGroupId(entry.getGroupId());
    subscriptionSender.setSubject(subject);

    subscriptionSender.addRuntimeSubscribers(toAddress, toName);

    subscriptionSender.flushNotificationsAsync();
  }