-
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.
- Loading branch information
1 parent
034bdcb
commit f50074a
Showing
10 changed files
with
295 additions
and
8 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
38 changes: 38 additions & 0 deletions
38
src/main/java/org/support/project/knowledge/control/protect/NotificationControl.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,38 @@ | ||
package org.support.project.knowledge.control.protect; | ||
|
||
import java.util.List; | ||
|
||
import org.support.project.knowledge.control.Control; | ||
import org.support.project.knowledge.logic.NotificationLogic; | ||
import org.support.project.web.boundary.Boundary; | ||
import org.support.project.web.control.service.Get; | ||
import org.support.project.web.entity.NotificationsEntity; | ||
import org.support.project.web.exception.InvalidParamException; | ||
|
||
public class NotificationControl extends Control { | ||
|
||
@Get | ||
public Boundary list() throws InvalidParamException { | ||
int offset = getPathInteger(0); | ||
List<NotificationsEntity> notifications = NotificationLogic.get().getNotification(getLoginUserId(), offset); | ||
|
||
for (NotificationsEntity notificationsEntity : notifications) { | ||
NotificationLogic.get().convNotification(notificationsEntity, getLoginedUser(), NotificationLogic.TARGET.list); | ||
} | ||
|
||
setAttribute("notifications", notifications); | ||
|
||
int previous = offset - 1; | ||
if (previous < 0) { | ||
previous = 0; | ||
} | ||
setAttribute("offset", offset); | ||
setAttribute("previous", previous); | ||
setAttribute("next", offset + 1); | ||
|
||
return forward("list.jsp"); | ||
} | ||
|
||
|
||
|
||
} |
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
101 changes: 101 additions & 0 deletions
101
src/main/java/org/support/project/knowledge/logic/NotificationLogic.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,101 @@ | ||
package org.support.project.knowledge.logic; | ||
|
||
import org.support.project.common.util.StringUtils; | ||
import org.support.project.di.Container; | ||
import org.support.project.knowledge.entity.KnowledgesEntity; | ||
import org.support.project.knowledge.entity.MailLocaleTemplatesEntity; | ||
import org.support.project.knowledge.vo.notification.KnowledgeUpdate; | ||
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.entity.NotificationsEntity; | ||
import org.support.project.web.entity.UserNotificationsEntity; | ||
import org.support.project.web.entity.UsersEntity; | ||
|
||
import net.arnx.jsonic.JSON; | ||
|
||
public class NotificationLogic extends org.support.project.web.logic.NotificationLogic { | ||
public static enum TARGET { | ||
list, detail | ||
} | ||
|
||
/** | ||
* Get instance | ||
* @return instance | ||
*/ | ||
public static NotificationLogic get() { | ||
return Container.getComp(NotificationLogic.class); | ||
} | ||
|
||
/** | ||
* ユーザに通知をセット | ||
* @param notification | ||
* @param usersEntity | ||
*/ | ||
public void insertUserNotification(NotificationsEntity notification, UsersEntity usersEntity) { | ||
UserNotificationsEntity userNotification = new UserNotificationsEntity(notification.getNo(), usersEntity.getUserId()); | ||
userNotification.setStatus(NotificationLogic.STATUS_UNREAD); | ||
UserNotificationsDao.get().insert(userNotification); | ||
} | ||
|
||
/** | ||
* Knowledgeの登録/更新時の通知情報を作成 | ||
* @param knowledge | ||
* @return | ||
*/ | ||
public NotificationsEntity insertNotificationOnKnowledgeUpdate(KnowledgesEntity knowledge) { | ||
// 通知情報を作成 | ||
NotificationsEntity notification = new NotificationsEntity(); | ||
if (knowledge.getNotifyStatus() == null || knowledge.getNotifyStatus().intValue() == 0) { | ||
notification.setTitle(MailLogic.NOTIFY_INSERT_KNOWLEDGE); | ||
} else { | ||
notification.setTitle(MailLogic.NOTIFY_UPDATE_KNOWLEDGE); | ||
} | ||
KnowledgeUpdate update = new KnowledgeUpdate(); | ||
update.setKnowledgeId(knowledge.getKnowledgeId()); | ||
update.setKnowledgeTitle(knowledge.getTitle()); | ||
update.setUpdateUser(knowledge.getUpdateUserName()); | ||
notification.setContent(JSON.encode(update)); | ||
notification = NotificationsDao.get().insert(notification); | ||
return notification; | ||
} | ||
|
||
|
||
/** | ||
* ユーザへの通知を意味のある形へ変換 | ||
* @param notificationsEntity | ||
* @param loginedUser | ||
*/ | ||
public void convNotification(NotificationsEntity notificationsEntity, LoginedUser loginedUser, TARGET target) { | ||
String category = notificationsEntity.getTitle(); | ||
if (MailLogic.NOTIFY_INSERT_KNOWLEDGE.equals(category) || MailLogic.NOTIFY_UPDATE_KNOWLEDGE.equals(category)) { | ||
KnowledgeUpdate update = JSON.decode(notificationsEntity.getContent(), KnowledgeUpdate.class); | ||
MailLocaleTemplatesEntity template = MailLogic.get().load(loginedUser.getLocale(), MailLogic.NOTIFY_INSERT_KNOWLEDGE); | ||
|
||
String title = template.getTitle(); | ||
title = title.replace("{KnowledgeId}", String.valueOf(update.getKnowledgeId())); | ||
title = title.replace("{KnowledgeTitle}", StringUtils.abbreviate(update.getKnowledgeTitle(), 80)); | ||
notificationsEntity.setTitle(title); | ||
|
||
if (target == TARGET.detail) { | ||
String contents = template.getContent(); | ||
contents = contents.replace("{KnowledgeId}", String.valueOf(update.getKnowledgeId())); | ||
contents = contents.replace("{KnowledgeTitle}", update.getKnowledgeTitle()); | ||
contents = contents.replace("{User}", update.getUpdateUser()); | ||
contents = contents.replace("{URL}", NotifyLogic.get().makeURL(update.getKnowledgeId())); | ||
KnowledgesEntity entity = KnowledgeLogic.get().select(update.getKnowledgeId(), loginedUser); | ||
if (entity != null) { | ||
contents = contents.replace("{Contents}", entity.getContent()); | ||
} else { | ||
contents = contents.replace("{Contents}", ""); | ||
} | ||
notificationsEntity.setContent(contents); | ||
} | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
|
||
} |
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
43 changes: 43 additions & 0 deletions
43
src/main/java/org/support/project/knowledge/vo/notification/KnowledgeUpdate.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,43 @@ | ||
package org.support.project.knowledge.vo.notification; | ||
|
||
public class KnowledgeUpdate { | ||
private long KnowledgeId; | ||
private String KnowledgeTitle; | ||
private String updateUser; | ||
/** | ||
* @return the knowledgeId | ||
*/ | ||
public long getKnowledgeId() { | ||
return KnowledgeId; | ||
} | ||
/** | ||
* @param knowledgeId the knowledgeId to set | ||
*/ | ||
public void setKnowledgeId(long knowledgeId) { | ||
KnowledgeId = knowledgeId; | ||
} | ||
/** | ||
* @return the knowledgeTitle | ||
*/ | ||
public String getKnowledgeTitle() { | ||
return KnowledgeTitle; | ||
} | ||
/** | ||
* @param knowledgeTitle the knowledgeTitle to set | ||
*/ | ||
public void setKnowledgeTitle(String knowledgeTitle) { | ||
KnowledgeTitle = knowledgeTitle; | ||
} | ||
/** | ||
* @return the updateUser | ||
*/ | ||
public String getUpdateUser() { | ||
return updateUser; | ||
} | ||
/** | ||
* @param updateUser the updateUser to set | ||
*/ | ||
public void setUpdateUser(String updateUser) { | ||
this.updateUser = updateUser; | ||
} | ||
} |
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
Oops, something went wrong.