Search in sources :

Example 1 with JSONArray

use of com.liferay.portal.kernel.json.JSONArray in project liferay-ide by liferay.

the class AssetEntriesFacet method initFacetClause.

protected void initFacetClause() {
    SearchContext searchContext = getSearchContext();
    FacetConfiguration facetConfiguration = getFacetConfiguration();
    JSONObject dataJSONObject = facetConfiguration.getData();
    String[] entryClassNames = null;
    if (dataJSONObject.has("values")) {
        JSONArray valuesJSONArray = dataJSONObject.getJSONArray("values");
        entryClassNames = new String[valuesJSONArray.length()];
        for (int i = 0; i < valuesJSONArray.length(); i++) {
            entryClassNames[i] = valuesJSONArray.getString(i);
        }
    }
    if (ArrayUtil.isEmpty(entryClassNames)) {
        entryClassNames = searchContext.getEntryClassNames();
    }
    if (!isStatic()) {
        String[] entryClassNameParam = StringUtil.split(GetterUtil.getString(searchContext.getAttribute(getFieldName())));
        if (ArrayUtil.isNotEmpty(entryClassNameParam)) {
            entryClassNames = entryClassNameParam;
        }
    }
    if (ArrayUtil.isEmpty(entryClassNames)) {
        entryClassNames = SearchEngineUtil.getEntryClassNames();
        if (!dataJSONObject.has("values")) {
            JSONArray entriesJSONArray = JSONFactoryUtil.createJSONArray();
            for (String entryClassName : entryClassNames) {
                entriesJSONArray.put(entryClassName);
            }
            dataJSONObject.put("values", entriesJSONArray);
        }
    }
    searchContext.setEntryClassNames(entryClassNames);
}
Also used : FacetConfiguration(com.liferay.portal.kernel.search.facet.config.FacetConfiguration) JSONObject(com.liferay.portal.kernel.json.JSONObject) JSONArray(com.liferay.portal.kernel.json.JSONArray) SearchContext(com.liferay.portal.kernel.search.SearchContext)

Example 2 with JSONArray

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

Example 3 with JSONArray

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

Example 4 with JSONArray

use of com.liferay.portal.kernel.json.JSONArray 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)

Example 5 with JSONArray

use of com.liferay.portal.kernel.json.JSONArray in project sw360portal by sw360.

the class ProjectImportPortlet method updateImportables.

private void updateImportables(JSONObject responseData, LoginState loginState, RemoteCredentials remoteCredentials, String projectName) throws JsonProcessingException {
    if (!nullToEmpty(remoteCredentials.getServerUrl()).isEmpty()) {
        List<Project> importables = loadImportables(remoteCredentials, projectName);
        JSONArray serializedProjects = JSONFactoryUtil.createJSONArray();
        for (Project p : importables) {
            JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
            if (p.isSetExternalIds() && !isNullOrEmpty(p.getExternalIds().get(getIdName())))
                jsonObject.put("externalId", p.getExternalIds().get(getIdName()));
            jsonObject.put("name", p.getName());
            serializedProjects.put(jsonObject.toString());
        }
        responseData.put(ProjectImportConstants.RESPONSE__NEW_IMPORTABLES, serializedProjects);
    }
    responseData.put(ProjectImportConstants.RESPONSE__DB_URL, remoteCredentials.getServerUrl());
    loginState.login(remoteCredentials.getServerUrl());
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) JSONObject(com.liferay.portal.kernel.json.JSONObject) JSONArray(com.liferay.portal.kernel.json.JSONArray)

Aggregations

JSONArray (com.liferay.portal.kernel.json.JSONArray)13 JSONObject (com.liferay.portal.kernel.json.JSONObject)13 JSONException (com.liferay.portal.kernel.json.JSONException)4 IOException (java.io.IOException)4 PortalException (com.liferay.portal.kernel.exception.PortalException)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 BufferedReader (java.io.BufferedReader)3 File (java.io.File)3 FileReader (java.io.FileReader)3 Gadget (com.liferay.opensocial.model.Gadget)1 JSONFactoryUtil.createJSONArray (com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONArray)1 JSONFactoryUtil.createJSONObject (com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONObject)1 Organization (com.liferay.portal.kernel.model.Organization)1 UserGroup (com.liferay.portal.kernel.model.UserGroup)1 FileEntry (com.liferay.portal.kernel.repository.model.FileEntry)1 Folder (com.liferay.portal.kernel.repository.model.Folder)1 SearchContext (com.liferay.portal.kernel.search.SearchContext)1 FacetConfiguration (com.liferay.portal.kernel.search.facet.config.FacetConfiguration)1