use of com.liferay.portal.kernel.json.JSONObject in project liferay-ide by liferay.
the class LiferayActivityService method getMediaItems.
protected JSONArray getMediaItems(List<MediaItem> mediaItems) {
if (mediaItems == null) {
return null;
}
JSONArray mediaItemsJSONArray = JSONFactoryUtil.createJSONArray();
for (MediaItem mediaItem : mediaItems) {
JSONObject mediaItemsJsonObject = JSONFactoryUtil.createJSONObject();
mediaItemsJsonObject.put("mimeType", mediaItem.getMimeType());
mediaItemsJsonObject.put("type", String.valueOf(mediaItem.getType()));
mediaItemsJsonObject.put("url", mediaItem.getUrl());
mediaItemsJSONArray.put(mediaItemsJsonObject);
}
return mediaItemsJSONArray;
}
use of com.liferay.portal.kernel.json.JSONObject in project liferay-ide by liferay.
the class LiferayActivityService method getTemplateParams.
protected Map<String, String> getTemplateParams(JSONArray templateParamsJSONArray) {
if (templateParamsJSONArray == null) {
return null;
}
Map<String, String> templateParams = new HashMap<String, String>();
for (int i = 0; i < templateParamsJSONArray.length(); i++) {
JSONObject templateParamJSONObject = templateParamsJSONArray.getJSONObject(i);
JSONArray namesJSONArray = templateParamJSONObject.names();
for (int j = 0; j < namesJSONArray.length(); j++) {
String name = namesJSONArray.getString(j);
String value = templateParamJSONObject.getString(name);
templateParams.put(name, value);
}
}
return templateParams;
}
use of com.liferay.portal.kernel.json.JSONObject in project liferay-ide by liferay.
the class EditorPortlet method serveAddFolder.
protected void serveAddFolder(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws Exception {
long parentFolderId = ParamUtil.getLong(resourceRequest, "parentFolderId");
Folder parentFolder = DLAppServiceUtil.getFolder(parentFolderId);
String folderName = ParamUtil.getString(resourceRequest, "folderName");
ServiceContext serviceContext = ServiceContextFactory.getInstance(resourceRequest);
serviceContext.setAddGroupPermissions(true);
serviceContext.setAddGuestPermissions(true);
serviceContext.setScopeGroupId(parentFolder.getGroupId());
Folder folder = DLAppServiceUtil.addFolder(parentFolder.getRepositoryId(), parentFolderId, folderName, StringPool.BLANK, serviceContext);
JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
jsonObject.put("folderId", folder.getFolderId());
writeJSON(resourceRequest, resourceResponse, jsonObject);
}
use of com.liferay.portal.kernel.json.JSONObject in project liferay-ide by liferay.
the class EditorPortlet method serveUpdateFolderName.
protected void serveUpdateFolderName(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws Exception {
long folderId = ParamUtil.getLong(resourceRequest, "folderId");
Folder folder = DLAppServiceUtil.getFolder(folderId);
String folderName = ParamUtil.getString(resourceRequest, "folderName");
ServiceContext serviceContext = ServiceContextFactory.getInstance(resourceRequest);
DLAppServiceUtil.updateFolder(folderId, folderName, folder.getDescription(), serviceContext);
JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
writeJSON(resourceRequest, resourceResponse, jsonObject);
}
use of com.liferay.portal.kernel.json.JSONObject in project liferay-ide by liferay.
the class EditorPortlet method serveGetFolderChildren.
protected void serveGetFolderChildren(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws Exception {
ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);
long repositoryId = ParamUtil.getLong(resourceRequest, "repositoryId");
long folderId = ParamUtil.getLong(resourceRequest, "folderId");
List<Folder> folders = DLAppServiceUtil.getFolders(repositoryId, folderId);
folders = ListUtil.sort(folders, new RepositoryModelNameComparator(true));
JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
for (Folder folder : folders) {
JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
jsonObject.put("entryId", folder.getFolderId());
jsonObject.put("label", folder.getName());
jsonObject.put("leaf", false);
jsonObject.put("type", "editor");
jsonArray.put(jsonObject);
}
boolean getFileEntries = ParamUtil.getBoolean(resourceRequest, "getFileEntries");
if (getFileEntries) {
PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();
List<FileEntry> fileEntries = DLAppServiceUtil.getFileEntries(repositoryId, folderId);
fileEntries = ListUtil.sort(fileEntries, new RepositoryModelNameComparator(true));
for (FileEntry fileEntry : fileEntries) {
JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
jsonObject.put("entryId", fileEntry.getFileEntryId());
String portalURL = PortalUtil.getPortalURL(themeDisplay);
String fileEntryURL = ShindigUtil.getFileEntryURL(portalURL, fileEntry.getFileEntryId());
jsonObject.put("fileEntryURL", fileEntryURL);
long gadgetId = 0;
try {
Gadget gadget = GadgetLocalServiceUtil.getGadget(themeDisplay.getCompanyId(), fileEntryURL);
gadgetId = gadget.getGadgetId();
} catch (Exception e) {
}
jsonObject.put("gadgetId", gadgetId);
jsonObject.put("label", fileEntry.getTitle());
jsonObject.put("leaf", true);
JSONObject jsonPermissions = JSONFactoryUtil.createJSONObject();
if (gadgetId > 0) {
boolean unpublishPermission = GadgetPermission.contains(permissionChecker, themeDisplay.getScopeGroupId(), gadgetId, ActionKeys.DELETE);
jsonPermissions.put("unpublishPermission", unpublishPermission);
}
jsonObject.put("permissions", jsonPermissions);
jsonObject.put("type", "editor");
jsonArray.put(jsonObject);
}
}
writeJSON(resourceRequest, resourceResponse, jsonArray);
}
Aggregations