in study-builder/fdahpStudyDesigner/src/main/java/com/fdahpstudydesigner/controller/StudyController.java [3858:4087]
public ModelAndView saveOrUpdateStudyNotification(
HttpServletRequest request, NotificationBO notificationBO) {
logger.entry("begin saveOrUpdateStudyNotification");
ModelAndView mav = new ModelAndView("redirect:/adminStudies/studyList.do");
ModelMap map = new ModelMap();
String notificationId = null;
Map<String, String> propMap = FdahpStudyDesignerUtil.getAppProperties();
String customStudyId = "";
try {
HttpSession session = request.getSession();
Integer sessionStudyCount =
StringUtils.isNumeric(request.getParameter("_S"))
? Integer.parseInt(request.getParameter("_S"))
: 0;
SessionObject sessionObject =
(SessionObject) session.getAttribute(FdahpStudyDesignerConstants.SESSION_OBJECT);
if ((sessionObject != null)
&& (sessionObject.getStudySession() != null)
&& sessionObject.getStudySession().contains(sessionStudyCount)) {
String notificationType = "Study level";
String currentDateTime =
FdahpStudyDesignerUtil.isEmpty(request.getParameter("currentDateTime"))
? ""
: request.getParameter("currentDateTime");
String buttonType =
FdahpStudyDesignerUtil.isEmpty(request.getParameter("buttonType"))
? ""
: request.getParameter("buttonType");
String actionPage =
(String)
request
.getSession()
.getAttribute(sessionStudyCount + FdahpStudyDesignerConstants.ACTION_PAGE);
String appId1 = (String) request.getAttribute("appId");
customStudyId =
(String)
request
.getSession()
.getAttribute(sessionStudyCount + FdahpStudyDesignerConstants.CUSTOM_STUDY_ID);
if (StringUtils.isEmpty(actionPage)) {
actionPage =
FdahpStudyDesignerUtil.isEmpty(
request.getParameter(FdahpStudyDesignerConstants.ACTION_PAGE))
? ""
: request.getParameter(FdahpStudyDesignerConstants.ACTION_PAGE);
}
if (notificationBO != null) {
if (!"".equals(buttonType)) {
if ("save".equalsIgnoreCase(buttonType)) {
notificationBO.setNotificationDone(false);
notificationBO.setNotificationAction(false);
} else if ("done".equalsIgnoreCase(buttonType)
|| FdahpStudyDesignerConstants.RESEND.equalsIgnoreCase(buttonType)) {
notificationBO.setNotificationDone(true);
notificationBO.setNotificationAction(true);
}
}
if (FdahpStudyDesignerConstants.NOTIFICATION_NOTIMMEDIATE.equals(currentDateTime)) {
notificationBO.setScheduleDate(
FdahpStudyDesignerUtil.isNotEmpty(notificationBO.getScheduleDate())
? String.valueOf(
FdahpStudyDesignerUtil.getFormattedDate(
notificationBO.getScheduleDate(),
FdahpStudyDesignerConstants.UI_SDF_DATE,
FdahpStudyDesignerConstants.DB_SDF_DATE))
: "");
notificationBO.setScheduleTime(
FdahpStudyDesignerUtil.isNotEmpty(notificationBO.getScheduleTime())
? String.valueOf(
FdahpStudyDesignerUtil.getFormattedDate(
notificationBO.getScheduleTime(),
FdahpStudyDesignerConstants.SDF_TIME,
FdahpStudyDesignerConstants.DB_SDF_TIME))
: "");
notificationBO.setScheduleTimestamp(
(FdahpStudyDesignerUtil.isNotEmpty(notificationBO.getScheduleDate())
&& FdahpStudyDesignerUtil.isNotEmpty(notificationBO.getScheduleTime()))
? FdahpStudyDesignerUtil.getTimeStamp(
notificationBO.getScheduleDate(), notificationBO.getScheduleTime())
: null);
notificationBO.setNotificationScheduleType(
FdahpStudyDesignerConstants.NOTIFICATION_NOTIMMEDIATE);
} else if (FdahpStudyDesignerConstants.NOTIFICATION_IMMEDIATE.equals(currentDateTime)) {
notificationBO.setScheduleDate(FdahpStudyDesignerUtil.getCurrentDate());
notificationBO.setScheduleTime(FdahpStudyDesignerUtil.getCurrentTime());
notificationBO.setScheduleTimestamp(
FdahpStudyDesignerUtil.getTimeStamp(
notificationBO.getScheduleDate(), notificationBO.getScheduleTime()));
notificationBO.setNotificationScheduleType(
FdahpStudyDesignerConstants.NOTIFICATION_IMMEDIATE);
} else {
notificationBO.setScheduleDate("");
notificationBO.setScheduleTime("");
notificationBO.setScheduleTimestamp(null);
notificationBO.setNotificationScheduleType("0");
}
String studyId =
(String)
request
.getSession()
.getAttribute(sessionStudyCount + FdahpStudyDesignerConstants.STUDY_ID);
if (StringUtils.isEmpty(studyId)) {
studyId =
FdahpStudyDesignerUtil.isEmpty(
request.getParameter(FdahpStudyDesignerConstants.STUDY_ID))
? ""
: request.getParameter(FdahpStudyDesignerConstants.STUDY_ID);
}
if (StringUtils.isNotEmpty(studyId)) {
StudyBo studyBo = studyService.getStudyById(studyId, null);
if (studyBo != null) {
notificationBO.setCustomStudyId(studyBo.getCustomStudyId());
notificationBO.setStudyId(studyId);
}
}
if (StringUtils.isEmpty(notificationBO.getNotificationId())) {
notificationBO.setCreatedBy(sessionObject.getUserId());
notificationBO.setCreatedOn(FdahpStudyDesignerUtil.getCurrentDateTime());
} else {
notificationBO.setModifiedBy(sessionObject.getUserId());
notificationBO.setModifiedOn(FdahpStudyDesignerUtil.getCurrentDateTime());
}
notificationId =
notificationService.saveOrUpdateOrResendNotification(
notificationBO, notificationType, buttonType, sessionObject, customStudyId);
}
if (StringUtils.isNotEmpty(notificationId)) {
if (StringUtils.isEmpty(notificationBO.getNotificationId())) {
if ("save".equalsIgnoreCase(buttonType)) {
request
.getSession()
.setAttribute(
sessionStudyCount + FdahpStudyDesignerConstants.SUC_MSG,
propMap.get(FdahpStudyDesignerConstants.SAVE_STUDY_SUCCESS_MESSAGE));
} else {
request
.getSession()
.setAttribute(
sessionStudyCount + FdahpStudyDesignerConstants.SUC_MSG,
propMap.get("save.notification.success.message"));
}
} else {
if ("save".equalsIgnoreCase(buttonType)) {
request
.getSession()
.setAttribute(
sessionStudyCount + FdahpStudyDesignerConstants.SUC_MSG,
propMap.get(FdahpStudyDesignerConstants.SAVE_STUDY_SUCCESS_MESSAGE));
} else if (FdahpStudyDesignerConstants.RESEND.equalsIgnoreCase(buttonType)) {
request
.getSession()
.setAttribute(
sessionStudyCount + FdahpStudyDesignerConstants.SUC_MSG,
propMap.get("resend.notification.success.message"));
} else {
request
.getSession()
.setAttribute(
sessionStudyCount + FdahpStudyDesignerConstants.SUC_MSG,
propMap.get("update.notification.success.message"));
}
}
} else {
if ("save".equalsIgnoreCase(buttonType) && (notificationBO.getNotificationId() == null)) {
request
.getSession()
.setAttribute(
sessionStudyCount + FdahpStudyDesignerConstants.ERR_MSG,
propMap.get("save.notification.error.message"));
} else if (FdahpStudyDesignerConstants.RESEND.equalsIgnoreCase(buttonType)) {
request
.getSession()
.setAttribute(
sessionStudyCount + FdahpStudyDesignerConstants.ERR_MSG,
propMap.get("resend.notification.error.message"));
} else {
request
.getSession()
.setAttribute(
sessionStudyCount + FdahpStudyDesignerConstants.ERR_MSG,
propMap.get("update.notification.error.message"));
}
}
map.addAttribute("_S", sessionStudyCount);
if ("save".equalsIgnoreCase(buttonType)
&& !FdahpStudyDesignerConstants.ADDORCOPY.equals(actionPage)) {
request
.getSession()
.setAttribute(
sessionStudyCount + FdahpStudyDesignerConstants.NOTIFICATIONID,
notificationId + "");
request
.getSession()
.setAttribute(
sessionStudyCount + FdahpStudyDesignerConstants.CHKREFRESHFLAG, "Y" + "");
request
.getSession()
.setAttribute(
sessionStudyCount + FdahpStudyDesignerConstants.ACTION_TYPE, "edit" + "");
mav = new ModelAndView("redirect:getStudyNotification.do", map);
} else if ("save".equalsIgnoreCase(buttonType)
&& FdahpStudyDesignerConstants.ADDORCOPY.equals(actionPage)) {
request
.getSession()
.setAttribute(
sessionStudyCount + FdahpStudyDesignerConstants.NOTIFICATIONID,
notificationId + "");
request
.getSession()
.setAttribute(
sessionStudyCount + FdahpStudyDesignerConstants.CHKREFRESHFLAG, "Y" + "");
request
.getSession()
.setAttribute(
sessionStudyCount + FdahpStudyDesignerConstants.ACTION_TYPE,
FdahpStudyDesignerConstants.ADDORCOPY + "");
mav = new ModelAndView("redirect:getStudyNotification.do", map);
} else {
mav = new ModelAndView("redirect:/adminStudies/viewStudyNotificationList.do", map);
}
}
} catch (Exception e) {
logger.error("StudyController - saveOrUpdateStudyNotification - ERROR", e);
}
logger.exit("saveOrUpdateStudyNotification - Ends");
return mav;
}