use of com.liferay.portal.kernel.json.JSONObject in project liferay-ide by liferay.
the class TasksEntryLocalServiceImpl method sendNotificationEvent.
protected void sendNotificationEvent(TasksEntry tasksEntry, int oldStatus, long oldAssigneeUserId, ServiceContext serviceContext) throws PortalException, SystemException {
HashSet<Long> receiverUserIds = new HashSet<Long>(3);
receiverUserIds.add(oldAssigneeUserId);
receiverUserIds.add(tasksEntry.getUserId());
receiverUserIds.add(tasksEntry.getAssigneeUserId());
receiverUserIds.remove(serviceContext.getUserId());
JSONObject notificationEventJSONObject = JSONFactoryUtil.createJSONObject();
notificationEventJSONObject.put("classPK", tasksEntry.getTasksEntryId());
notificationEventJSONObject.put("userId", serviceContext.getUserId());
for (long receiverUserId : receiverUserIds) {
if ((receiverUserId == 0) || !UserNotificationManagerUtil.isDeliver(receiverUserId, PortletKeys.TASKS, 0, TasksEntryConstants.STATUS_ALL, UserNotificationDeliveryConstants.TYPE_WEBSITE)) {
continue;
}
String title = StringPool.BLANK;
if (oldStatus == TasksEntryConstants.STATUS_ALL) {
title = "x-assigned-you-a-task";
} else if (tasksEntry.getAssigneeUserId() != oldAssigneeUserId) {
if (receiverUserId == oldAssigneeUserId) {
title = "x-reassigned-your-task";
} else {
title = "x-assigned-you-a-task";
}
} else if (tasksEntry.getStatus() != oldStatus) {
if ((tasksEntry.getStatus() != TasksEntryConstants.STATUS_OPEN) && (tasksEntry.getStatus() != TasksEntryConstants.STATUS_REOPENED) && (tasksEntry.getStatus() != TasksEntryConstants.STATUS_RESOLVED)) {
return;
}
String statusLabel = TasksEntryConstants.getStatusLabel(tasksEntry.getStatus());
title = "x-" + statusLabel + "-the-task";
} else {
title = "x-modified-the-task";
}
notificationEventJSONObject.put("title", title);
NotificationEvent notificationEvent = NotificationEventFactoryUtil.createNotificationEvent(System.currentTimeMillis(), PortletKeys.TASKS, notificationEventJSONObject);
notificationEvent.setDeliveryRequired(0);
UserNotificationEventLocalServiceUtil.addUserNotificationEvent(receiverUserId, notificationEvent);
}
}
use of com.liferay.portal.kernel.json.JSONObject in project liferay-ide by liferay.
the class EditDiscussionAction method processAction.
@Override
public void processAction(ActionMapping actionMapping, ActionForm actionForm, PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
try {
String redirect = PortalUtil.escapeRedirect(ParamUtil.getString(actionRequest, "redirect"));
if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
MBMessage message = updateMessage(actionRequest);
boolean ajax = ParamUtil.getBoolean(actionRequest, "ajax");
if (ajax) {
String randomNamespace = ParamUtil.getString(actionRequest, "randomNamespace");
JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
jsonObject.put("messageId", message.getMessageId());
jsonObject.put("randomNamespace", randomNamespace);
writeJSON(actionRequest, actionResponse, jsonObject);
return;
}
} else if (cmd.equals(Constants.DELETE)) {
deleteMessage(actionRequest);
} else if (cmd.equals(Constants.SUBSCRIBE_TO_COMMENTS)) {
subscribeToComments(actionRequest, true);
} else if (cmd.equals(Constants.UNSUBSCRIBE_FROM_COMMENTS)) {
subscribeToComments(actionRequest, false);
}
sendRedirect(actionRequest, actionResponse, redirect);
} catch (Exception e) {
if (e instanceof MessageBodyException || e instanceof NoSuchMessageException || e instanceof PrincipalException || e instanceof RequiredMessageException) {
JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
jsonObject.putException(e);
writeJSON(actionRequest, actionResponse, jsonObject);
} else {
throw e;
}
}
}
use of com.liferay.portal.kernel.json.JSONObject in project liferay-ide by liferay.
the class LiferayActivityService method doCreateActivity.
public void doCreateActivity(UserId userId, GroupId groupId, String appId, Set<String> fields, Activity activity, SecurityToken securityToken) throws Exception {
long userIdLong = GetterUtil.getLong(userId.getUserId(securityToken));
String activityAppId = activity.getAppId();
JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();
SerializerUtil.copyProperties(activity, extraDataJSONObject, _ACTIVITY_FIELDS);
SocialActivityLocalServiceUtil.addActivity(userIdLong, 0L, Activity.class.getName(), activity.getPostedTime(), activityAppId.hashCode(), extraDataJSONObject.toString(), 0L);
}
use of com.liferay.portal.kernel.json.JSONObject in project liferay-ide by liferay.
the class LiferayActivityService method getTemplateParams.
protected JSONArray getTemplateParams(Map<String, String> map) {
if (map == null) {
return null;
}
JSONArray templateParamsJSONArray = JSONFactoryUtil.createJSONArray();
for (Entry<String, String> entry : map.entrySet()) {
JSONObject templateParamJSONObject = JSONFactoryUtil.createJSONObject();
String name = entry.getKey();
String value = entry.getValue();
templateParamJSONObject.put(name, value);
templateParamsJSONArray.put(templateParamJSONObject);
}
return templateParamsJSONArray;
}
use of com.liferay.portal.kernel.json.JSONObject in project liferay-ide by liferay.
the class LiferayActivityService method getMediaItems.
protected List<MediaItem> getMediaItems(JSONArray mediaItemsJSONArray) {
if (mediaItemsJSONArray == null) {
return null;
}
List<MediaItem> mediaItems = new ArrayList<MediaItem>();
for (int i = 0; i < mediaItemsJSONArray.length(); i++) {
JSONObject mediaItemsJsonObject = mediaItemsJSONArray.getJSONObject(i);
MediaItem mediaItem = new MediaItemImpl(mediaItemsJsonObject.getString("mimeType"), Type.valueOf(mediaItemsJsonObject.getString("type")), mediaItemsJsonObject.getString("url"));
mediaItems.add(mediaItem);
}
return mediaItems;
}
Aggregations