-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#349 Add notification feature for event information
- Loading branch information
1 parent
d949683
commit 1eb8766
Showing
8 changed files
with
349 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
...ava/org/support/project/knowledge/logic/notification/AbstractParticipateNotification.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package org.support.project.knowledge.logic.notification; | ||
|
||
import org.support.project.common.config.Resources; | ||
import org.support.project.common.util.StringUtils; | ||
import org.support.project.knowledge.entity.KnowledgesEntity; | ||
import org.support.project.knowledge.entity.MailLocaleTemplatesEntity; | ||
import org.support.project.knowledge.logic.EventsLogic; | ||
import org.support.project.knowledge.logic.MailLogic; | ||
import org.support.project.knowledge.logic.NotificationLogic; | ||
import org.support.project.knowledge.logic.NotifyLogic; | ||
import org.support.project.knowledge.vo.notification.Participate; | ||
import org.support.project.web.bean.LoginedUser; | ||
import org.support.project.web.dao.NotificationsDao; | ||
import org.support.project.web.dao.UserNotificationsDao; | ||
import org.support.project.web.dao.UsersDao; | ||
import org.support.project.web.entity.NotificationsEntity; | ||
import org.support.project.web.entity.UserNotificationsEntity; | ||
import org.support.project.web.entity.UsersEntity; | ||
|
||
import net.arnx.jsonic.JSON; | ||
|
||
public abstract class AbstractParticipateNotification extends AbstractNotification implements ParticipateNotification { | ||
|
||
|
||
protected void insertNotification(KnowledgesEntity knowledge, Integer participant, Integer status, String template) { | ||
NotificationsEntity notification = new NotificationsEntity(); | ||
notification.setTitle(template); | ||
|
||
Participate info = new Participate(); | ||
info.setKnowledgeId(knowledge.getKnowledgeId()); | ||
info.setKnowledgeTitle(knowledge.getTitle()); | ||
info.setUpdateUser(knowledge.getUpdateUserName()); | ||
|
||
info.setParticipant(participant); | ||
info.setStatus(status); | ||
|
||
notification.setContent(JSON.encode(info)); | ||
notification = NotificationsDao.get().insert(notification); | ||
|
||
if (template.equals(MailLogic.NOTIFY_ADD_PARTICIPATE)) { | ||
// 参加登録があったことを、開催者へ通知 | ||
UserNotificationsEntity userNotification = new UserNotificationsEntity(notification.getNo(), knowledge.getInsertUser()); | ||
userNotification.setStatus(NotificationLogic.STATUS_UNREAD); | ||
UserNotificationsDao.get().insert(userNotification); | ||
} else { | ||
// 参加登録したことを、参加者へ通知 | ||
UserNotificationsEntity userNotification = new UserNotificationsEntity(notification.getNo(), participant); | ||
userNotification.setStatus(NotificationLogic.STATUS_UNREAD); | ||
UserNotificationsDao.get().insert(userNotification); | ||
} | ||
} | ||
|
||
|
||
@Override | ||
public void convNotification(NotificationsEntity notificationsEntity, LoginedUser loginedUser, TARGET target) { | ||
Participate info = JSON.decode(notificationsEntity.getContent(), Participate.class); | ||
String templateString = notificationsEntity.getTitle(); | ||
MailLocaleTemplatesEntity template = MailLogic.get().load(loginedUser.getLocale(), notificationsEntity.getTitle()); | ||
|
||
String title = template.getTitle(); | ||
title = title.replace("{KnowledgeId}", String.valueOf(info.getKnowledgeId())); | ||
title = title.replace("{KnowledgeTitle}", StringUtils.abbreviate(info.getKnowledgeTitle(), 80)); | ||
notificationsEntity.setTitle(title); | ||
|
||
if (target == TARGET.detail) { | ||
String contents = template.getContent(); | ||
contents = contents.replace("{KnowledgeId}", String.valueOf(info.getKnowledgeId())); | ||
contents = contents.replace("{KnowledgeTitle}", info.getKnowledgeTitle()); | ||
contents = contents.replace("{URL}", NotifyLogic.get().makeURL(info.getKnowledgeId())); | ||
UsersEntity participant = UsersDao.get().selectOnKey(info.getParticipant()); | ||
if (participant != null) { | ||
Resources resources = Resources.getInstance(loginedUser.getLocale()); | ||
StringBuilder builder = new StringBuilder(); | ||
int status = info.getStatus(); | ||
if (MailLogic.NOTIFY_ADD_PARTICIPATE.equals(templateString)) { | ||
// 参加登録があったことを、開催者へ通知 | ||
builder.append(participant.getUserName()); | ||
if (status == EventsLogic.STATUS_PARTICIPATION) { | ||
builder.append("[").append(resources.getResource("knowledge.view.label.status.participation")).append("]"); | ||
} else { | ||
builder.append("[").append(resources.getResource("knowledge.view.label.status.wait.cansel")).append("]"); | ||
} | ||
contents = contents.replace("{Participant}", builder.toString()); | ||
} else { | ||
// 参加登録したことを、参加者へ通知 | ||
if (status == EventsLogic.STATUS_PARTICIPATION) { | ||
builder.append(resources.getResource("knowledge.view.label.status.participation")); | ||
} else { | ||
builder.append(resources.getResource("knowledge.view.label.status.wait.cansel")); | ||
} | ||
contents = contents.replace("{Status}", builder.toString()); | ||
} | ||
} | ||
notificationsEntity.setContent(contents); | ||
} | ||
} | ||
|
||
|
||
} |
96 changes: 96 additions & 0 deletions
96
...g/support/project/knowledge/logic/notification/ParticipateForParticipantNotification.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package org.support.project.knowledge.logic.notification; | ||
|
||
import org.support.project.common.config.Resources; | ||
import org.support.project.common.log.Log; | ||
import org.support.project.common.log.LogFactory; | ||
import org.support.project.common.util.StringUtils; | ||
import org.support.project.di.Container; | ||
import org.support.project.di.DI; | ||
import org.support.project.di.Instance; | ||
import org.support.project.knowledge.config.AppConfig; | ||
import org.support.project.knowledge.dao.KnowledgesDao; | ||
import org.support.project.knowledge.entity.KnowledgesEntity; | ||
import org.support.project.knowledge.entity.MailLocaleTemplatesEntity; | ||
import org.support.project.knowledge.logic.EventsLogic; | ||
import org.support.project.knowledge.logic.MailLogic; | ||
import org.support.project.knowledge.logic.NotifyLogic; | ||
import org.support.project.web.dao.MailConfigsDao; | ||
import org.support.project.web.dao.MailsDao; | ||
import org.support.project.web.dao.UsersDao; | ||
import org.support.project.web.entity.MailConfigsEntity; | ||
import org.support.project.web.entity.MailsEntity; | ||
import org.support.project.web.entity.UsersEntity; | ||
|
||
/** | ||
* 参加登録したことを、参加者へ通知 | ||
* @author koda | ||
*/ | ||
@DI(instance = Instance.Singleton) | ||
public class ParticipateForParticipantNotification extends AbstractParticipateNotification{ | ||
/** ログ */ | ||
private static final Log LOG = LogFactory.getLog(ParticipateForParticipantNotification.class); | ||
/** インスタンス取得 */ | ||
public static ParticipateForParticipantNotification get() { | ||
return Container.getComp(ParticipateForParticipantNotification.class); | ||
} | ||
|
||
@Override | ||
public void notify(Long knowledgeId, Integer userId, Integer status) { | ||
KnowledgesEntity knowledge = KnowledgesDao.get().selectOnKey(knowledgeId); | ||
if (knowledge == null) { | ||
LOG.info("knowledge [" + knowledgeId + "] is not exists."); | ||
return; | ||
} | ||
// 参加者 | ||
UsersEntity participant = UsersDao.get().selectOnKey(userId); | ||
if (participant == null) { | ||
LOG.warn("sponsor or participant is not exist."); | ||
return; | ||
} | ||
|
||
// 通知情報生成 | ||
insertNotification(knowledge, userId, status, MailLogic.NOTIFY_REGISTRATION_EVENT); | ||
|
||
MailConfigsDao mailConfigsDao = MailConfigsDao.get(); | ||
MailConfigsEntity mailConfigsEntity = mailConfigsDao.selectOnKey(AppConfig.get().getSystemName()); | ||
if (mailConfigsEntity == null) { | ||
// メールの設定が登録されていなければ、送信処理は終了 | ||
LOG.info("mail config is not exists."); | ||
return; | ||
} | ||
if (!StringUtils.isEmailAddress(participant.getMailAddress())) { | ||
// 送信先のメールアドレスが不正なので、送信処理は終了 | ||
LOG.warn("mail targget [" + participant.getMailAddress() + "] is wrong."); | ||
return; | ||
} | ||
|
||
MailsEntity mailsEntity = new MailsEntity(); | ||
String mailId = idGen("Notify"); | ||
mailsEntity.setMailId(mailId); | ||
mailsEntity.setStatus(MailLogic.MAIL_STATUS_UNSENT); | ||
mailsEntity.setToAddress(participant.getMailAddress()); | ||
mailsEntity.setToName(participant.getUserName()); | ||
|
||
MailLocaleTemplatesEntity template = MailLogic.get().load(participant.getLocale(), MailLogic.NOTIFY_REGISTRATION_EVENT); | ||
String title = template.getTitle(); | ||
title = title.replace("{KnowledgeId}", knowledge.getKnowledgeId().toString()); | ||
title = title.replace("{KnowledgeTitle}", StringUtils.abbreviate(knowledge.getTitle(), 80)); | ||
mailsEntity.setTitle(title); | ||
String contents = template.getContent(); | ||
contents = contents.replace("{KnowledgeId}", knowledge.getKnowledgeId().toString()); | ||
contents = contents.replace("{KnowledgeTitle}", knowledge.getTitle()); | ||
StringBuilder builder = new StringBuilder(); | ||
Resources resources = Resources.getInstance(participant.getLocale()); | ||
if (status == EventsLogic.STATUS_PARTICIPATION) { | ||
builder.append(resources.getResource("knowledge.view.label.status.participation")); | ||
} else { | ||
builder.append(resources.getResource("knowledge.view.label.status.wait.cansel")); | ||
} | ||
contents = contents.replace("{Status}", builder.toString()); | ||
contents = contents.replace("{URL}", NotifyLogic.get().makeURL(knowledge.getKnowledgeId())); | ||
|
||
mailsEntity.setContent(contents); | ||
MailsDao.get().insert(mailsEntity); | ||
} | ||
|
||
} |
Oops, something went wrong.