Search in sources :

Example 1 with RepositoryModelNameComparator

use of com.liferay.portlet.documentlibrary.util.comparator.RepositoryModelNameComparator 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);
}
Also used : Gadget(com.liferay.opensocial.model.Gadget) JSONArray(com.liferay.portal.kernel.json.JSONArray) Folder(com.liferay.portal.kernel.repository.model.Folder) IOException(java.io.IOException) PortletException(javax.portlet.PortletException) RepositoryModelNameComparator(com.liferay.portlet.documentlibrary.util.comparator.RepositoryModelNameComparator) JSONObject(com.liferay.portal.kernel.json.JSONObject) PermissionChecker(com.liferay.portal.security.permission.PermissionChecker) FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) ThemeDisplay(com.liferay.portal.theme.ThemeDisplay)

Aggregations

Gadget (com.liferay.opensocial.model.Gadget)1 JSONArray (com.liferay.portal.kernel.json.JSONArray)1 JSONObject (com.liferay.portal.kernel.json.JSONObject)1 FileEntry (com.liferay.portal.kernel.repository.model.FileEntry)1 Folder (com.liferay.portal.kernel.repository.model.Folder)1 PermissionChecker (com.liferay.portal.security.permission.PermissionChecker)1 ThemeDisplay (com.liferay.portal.theme.ThemeDisplay)1 RepositoryModelNameComparator (com.liferay.portlet.documentlibrary.util.comparator.RepositoryModelNameComparator)1 IOException (java.io.IOException)1 PortletException (javax.portlet.PortletException)1