Search in sources :

Example 26 with JSONObject

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);
    }
}
Also used : JSONObject(com.liferay.portal.kernel.json.JSONObject) NotificationEvent(com.liferay.portal.kernel.notifications.NotificationEvent) HashSet(java.util.HashSet)

Example 27 with JSONObject

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;
        }
    }
}
Also used : RequiredMessageException(com.liferay.portlet.messageboards.RequiredMessageException) MessageBodyException(com.liferay.portlet.messageboards.MessageBodyException) NoSuchMessageException(com.liferay.portlet.messageboards.NoSuchMessageException) MBMessage(com.liferay.portlet.messageboards.model.MBMessage) JSONObject(com.liferay.portal.kernel.json.JSONObject) PrincipalException(com.liferay.portal.security.auth.PrincipalException) NoSuchMessageException(com.liferay.portlet.messageboards.NoSuchMessageException) PrincipalException(com.liferay.portal.security.auth.PrincipalException) MessageBodyException(com.liferay.portlet.messageboards.MessageBodyException) RequiredMessageException(com.liferay.portlet.messageboards.RequiredMessageException)

Example 28 with JSONObject

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);
}
Also used : JSONObject(com.liferay.portal.kernel.json.JSONObject) SocialActivity(com.liferay.portlet.social.model.SocialActivity) Activity(org.apache.shindig.social.opensocial.model.Activity)

Example 29 with JSONObject

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;
}
Also used : JSONObject(com.liferay.portal.kernel.json.JSONObject) JSONArray(com.liferay.portal.kernel.json.JSONArray)

Example 30 with JSONObject

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;
}
Also used : MediaItemImpl(org.apache.shindig.social.core.model.MediaItemImpl) JSONObject(com.liferay.portal.kernel.json.JSONObject) MediaItem(org.apache.shindig.social.opensocial.model.MediaItem) ArrayList(java.util.ArrayList)

Aggregations

JSONObject (com.liferay.portal.kernel.json.JSONObject)54 JSONArray (com.liferay.portal.kernel.json.JSONArray)13 IOException (java.io.IOException)10 TException (org.apache.thrift.TException)9 PrintWriter (java.io.PrintWriter)7 FileEntry (com.liferay.portal.kernel.repository.model.FileEntry)5 ServiceContext (com.liferay.portal.service.ServiceContext)5 ThemeDisplay (com.liferay.portal.theme.ThemeDisplay)5 PortalException (com.liferay.portal.kernel.exception.PortalException)4 JSONException (com.liferay.portal.kernel.json.JSONException)4 Folder (com.liferay.portal.kernel.repository.model.Folder)4 Date (java.util.Date)4 CveSearchService (org.eclipse.sw360.datahandler.thrift.cvesearch.CveSearchService)4 VulnerabilityUpdateStatus (org.eclipse.sw360.datahandler.thrift.cvesearch.VulnerabilityUpdateStatus)4 User (org.eclipse.sw360.datahandler.thrift.users.User)4 JSONFactoryUtil.createJSONObject (com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONObject)3 Role (com.liferay.portal.kernel.model.Role)3 User (com.liferay.portal.kernel.model.User)3 UploadPortletRequest (com.liferay.portal.kernel.upload.UploadPortletRequest)3 User (com.liferay.portal.model.User)3