Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lps 205014 dxp master #5802

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ public class NotificationTemplateContextFactory {
public static NotificationTemplateContext getInstance(
CalendarBooking calendarBooking,
NotificationTemplateType notificationTemplateType,
NotificationType notificationType, long scopeGroupId, User user)
NotificationType notificationType,
ServiceContext serviceContext,
User user)
throws Exception {

CalendarBooking parentCalendarBooking =
Expand Down Expand Up @@ -101,13 +103,13 @@ public static NotificationTemplateContext getInstance(
"icsFile",
() -> {
if (Objects.equals(
notificationTemplateContext.
getNotificationTemplateType(),
NotificationTemplateType.INVITE)) {
notificationTemplateContext.
getNotificationTemplateType(),
NotificationTemplateType.INVITE)) {

CalendarBookingLocalService
calendarBookingLocalService =
_calendarBookingLocalServiceSnapshot.get();
_calendarBookingLocalServiceSnapshot.get();

String calendarBookingString =
calendarBookingLocalService.exportCalendarBooking(
Expand All @@ -123,17 +125,7 @@ public static NotificationTemplateContext getInstance(
).put(
"location", calendarBooking.getLocation()
).put(
"portalURL",
() -> {
GroupLocalService groupLocalService =
_groupLocalServiceSnapshot.get();

Group group = groupLocalService.getGroup(
user.getCompanyId(), GroupConstants.GUEST);

return _getPortalURL(
group.getCompanyId(), group.getGroupId());
}
"portalURL", _getPortalURL(serviceContext, user)
).put(
"portletName",
LanguageUtil.get(
Expand Down Expand Up @@ -164,43 +156,18 @@ public static NotificationTemplateContext getInstance(
).put(
"url",
_getCalendarBookingURL(
calendarBooking.getCalendarBookingId(), scopeGroupId, user)
calendarBooking.getCalendarBookingId(), serviceContext, user)
).build();

notificationTemplateContext.setAttributes(attributes);

return notificationTemplateContext;
}

public static NotificationTemplateContext getInstance(
NotificationType notificationType,
NotificationTemplateType notificationTemplateType,
CalendarBooking calendarBooking, User user,
ServiceContext serviceContext)
throws Exception {

long scopeGroupId = 0L;

if (serviceContext != null) {
scopeGroupId = serviceContext.getScopeGroupId();
}

NotificationTemplateContext notificationTemplateContext = getInstance(
calendarBooking, notificationTemplateType, notificationType,
scopeGroupId, user);

if ((serviceContext != null) &&
Validator.isNotNull(
serviceContext.getAttribute("instanceStartTime"))) {

long instanceStartTime = (long)serviceContext.getAttribute(
"instanceStartTime");

Format userDateTimeFormat = _getUserDateTimeFormat(
calendarBooking, user);

String userTimezoneDisplayName = _getUserTimezoneDisplayName(user);

String instanceStartTimeFormatted =
userDateTimeFormat.format(instanceStartTime) +
StringPool.SPACE + userTimezoneDisplayName;
Expand All @@ -218,41 +185,39 @@ public static NotificationTemplateContext getInstance(
* CalendarBooking)}
*/
private static String _getCalendarBookingURL(
long calendarBookingId, long scopeGroupId, User user)
long calendarBookingId, ServiceContext serviceContext, User user)
throws Exception {

GroupLocalService groupLocalService = _groupLocalServiceSnapshot.get();
String layoutURL = "";

Group group = null;
if (serviceContext != null) {
layoutURL = serviceContext.getLayoutURL();
} else {
GroupLocalService groupLocalService = _groupLocalServiceSnapshot.get();

if (scopeGroupId != 0) {
group = groupLocalService.getGroup(scopeGroupId);
}
else {
group = groupLocalService.getGroup(
Group group = groupLocalService.getGroup(
user.getCompanyId(), GroupConstants.GUEST);
}

LayoutLocalService layoutLocalService =
_layoutLocalServiceSnapshot.get();
LayoutLocalService layoutLocalService =
_layoutLocalServiceSnapshot.get();

Layout layout = layoutLocalService.fetchLayout(
group.getDefaultPublicPlid());
Layout layout = layoutLocalService.fetchLayout(
group.getDefaultPublicPlid());

if (layout == null) {
group = groupLocalService.getGroup(
user.getCompanyId(), GroupConstants.GUEST);
if (layout == null) {
group = groupLocalService.getGroup(
user.getCompanyId(), GroupConstants.GUEST);

layout = layoutLocalService.fetchLayout(
group.getDefaultPublicPlid());
}
layout = layoutLocalService.fetchLayout(
group.getDefaultPublicPlid());
}

String portalURL = _getPortalURL(
group.getCompanyId(), group.getGroupId());
layoutURL = PortalUtil.getLayoutActualURL(layout);
}

String layoutActualURL = PortalUtil.getLayoutActualURL(layout);
String portalURL = _getPortalURL(serviceContext, user);

String url = portalURL + layoutActualURL;
String url = portalURL + layoutURL;

String namespace = PortalUtil.getPortletNamespace(
CalendarPortletKeys.CALENDAR);
Expand All @@ -271,15 +236,25 @@ private static String _getCalendarBookingURL(
return url;
}

private static String _getPortalURL(long companyId, long groupId)
private static String _getPortalURL(ServiceContext serviceContext, User user)
throws PortalException {

if (serviceContext != null) {
return serviceContext.getPortalURL();
}

GroupLocalService groupLocalService =
_groupLocalServiceSnapshot.get();

Group group = groupLocalService.getGroup(
user.getCompanyId(), GroupConstants.GUEST);

CompanyLocalService companyLocalService =
_companyLocalServiceSnapshot.get();

Company company = companyLocalService.getCompany(companyId);
Company company = companyLocalService.getCompany(group.getCompanyId());

return company.getPortalURL(groupId);
return company.getPortalURL(group.getGroupId());
}

private static Format _getUserDateTimeFormat(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2225,8 +2225,8 @@ private void _notifyCalendarBookingRecipients(

NotificationTemplateContext notificationTemplateContext =
NotificationTemplateContextFactory.getInstance(
notificationType, notificationTemplateType, calendarBooking,
recipientUser, serviceContext);
calendarBooking, notificationTemplateType, notificationType,
serviceContext, recipientUser);

notificationSender.sendNotification(
senderUser.getEmailAddress(), resourceName,
Expand All @@ -2247,8 +2247,8 @@ private void _notifyCalendarBookingRecipients(

NotificationTemplateContext notificationTemplateContext =
NotificationTemplateContextFactory.getInstance(
notificationType, notificationTemplateType,
calendarBooking, user, serviceContext);
calendarBooking, notificationTemplateType,
notificationType, serviceContext, user);

notificationSender.sendNotification(
senderUser.getEmailAddress(), senderUser.getFullName(),
Expand Down Expand Up @@ -2303,7 +2303,7 @@ else if (_isInCheckInterval(
NotificationTemplateContext notificationTemplateContext =
NotificationTemplateContextFactory.getInstance(
calendarBooking, NotificationTemplateType.REMINDER,
notificationType, 0L, user);
notificationType, null, user);

notificationSender.sendNotification(
user.getEmailAddress(), user.getFullName(),
Expand Down