Example usage for com.liferay.portal.kernel.json JSONFactoryUtil looseSerialize

List of usage examples for com.liferay.portal.kernel.json JSONFactoryUtil looseSerialize

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.json JSONFactoryUtil looseSerialize.

Prototype

public static String looseSerialize(Object object) 

Source Link

Usage

From source file:com.delfilab.gargall.service.impl.GargallServiceImpl.java

License:Open Source License

protected GargallDLFileEntry getGargallDLFileEntry(DLFileEntry dlFileEntry) throws Exception {

    List<String> tagNames = new ArrayList<String>();
    for (AssetTag theTag : AssetTagServiceUtil.getTags(DLFileEntry.class.getName(), dlFileEntry.getClassPK())) {
        tagNames.add(theTag.getName());/*from   ww w.j a  va 2 s.c  om*/
    }
    String jsonTags = JSONFactoryUtil.looseSerialize(tagNames);

    GargallDLFileEntry gargallDLFileEntry = new GargallDLFileEntry();
    gargallDLFileEntry.addDynamicElement("uuid", dlFileEntry.getUuid());
    gargallDLFileEntry.addDynamicElement("description", dlFileEntry.getDescription());
    gargallDLFileEntry.addDynamicElement("title", dlFileEntry.getTitle());
    gargallDLFileEntry.addDynamicElement("size", String.valueOf(dlFileEntry.getSize()));
    gargallDLFileEntry.addDynamicElement("modifiedDate", _format.format(dlFileEntry.getModifiedDate()));
    gargallDLFileEntry.addDynamicElement("fileEntryId", String.valueOf(dlFileEntry.getFileEntryId()));
    gargallDLFileEntry.addDynamicElement("folderId", String.valueOf(dlFileEntry.getFolderId()));
    gargallDLFileEntry.addDynamicElement("tags", jsonTags);

    populateGargallDLFileEntry(gargallDLFileEntry);

    return gargallDLFileEntry;
}

From source file:com.liferay.alloy.mvc.AlloyDataRequestHandler.java

License:Open Source License

protected static String executeDynamicQuery(BaseAlloyControllerImpl baseAlloyControllerImpl,
        ActionRequest actionRequest) throws Exception {

    if (baseAlloyControllerImpl.permissioned) {
        AlloyPermission.check(baseAlloyControllerImpl.themeDisplay, baseAlloyControllerImpl.controllerPath,
                "index");
    }//from   w w  w .  j  a  v  a 2 s  . c o  m

    AlloyServiceInvoker alloyServiceInvoker = baseAlloyControllerImpl.alloyServiceInvoker;

    List<Object> properties = JSONFactoryUtil.looseDeserialize(ParamUtil.getString(actionRequest, "properties"),
            ArrayList.class);
    int start = ParamUtil.getInteger(actionRequest, "start", QueryUtil.ALL_POS);
    int end = ParamUtil.getInteger(actionRequest, "end", QueryUtil.ALL_POS);

    List<BaseModel<?>> baseModels = alloyServiceInvoker.executeDynamicQuery(properties.toArray(), start, end);

    return JSONFactoryUtil.looseSerialize(baseModels);
}

From source file:com.liferay.alloy.mvc.AlloyDataRequestHandler.java

License:Open Source License

protected static String executeSearch(BaseAlloyControllerImpl baseAlloyControllerImpl,
        ActionRequest actionRequest) throws Exception {

    if (baseAlloyControllerImpl.permissioned) {
        AlloyPermission.check(baseAlloyControllerImpl.themeDisplay, baseAlloyControllerImpl.controllerPath,
                "index");
    }/*from w  w  w.  j  a v  a 2  s. com*/

    Map<String, Serializable> attributes = null;

    String attributesString = ParamUtil.getString(actionRequest, "attributes");

    if (Validator.isNotNull(attributesString)) {
        attributes = JSONFactoryUtil.looseDeserialize(attributesString, HashMap.class);
    }

    String keywords = ParamUtil.getString(actionRequest, "keywords");

    Sort[] sorts = null;

    String sortsString = ParamUtil.getString(actionRequest, "sorts");

    if (Validator.isNotNull(sortsString)) {
        Map<String, Boolean> sortsMap = JSONFactoryUtil.looseDeserialize(sortsString, LinkedHashMap.class);

        sorts = new Sort[sortsMap.size()];

        int i = 0;

        for (Map.Entry<String, Boolean> entry : sortsMap.entrySet()) {
            sorts[i++] = new Sort(entry.getKey(), entry.getValue());
        }
    }

    AlloySearchResult alloySearchResult = baseAlloyControllerImpl.search(
            PortalUtil.getHttpServletRequest(actionRequest), actionRequest, attributes, keywords, sorts);

    List<BaseModel<?>> baseModels = alloySearchResult.getBaseModels();

    return JSONFactoryUtil.looseSerialize(baseModels);
}

From source file:com.liferay.newsletter.portlet.NewsletterPortlet.java

License:Open Source License

protected void toJSON(ResourceResponse resourceResponse, Object object) throws Exception {

    JSONArray jsonArray = JSONFactoryUtil.createJSONArray(JSONFactoryUtil.looseSerialize(object));

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    jsonObject.put("results", jsonArray);

    resourceResponse.setContentType(ContentTypes.TEXT_JAVASCRIPT);

    OutputStream os = resourceResponse.getPortletOutputStream();

    try {//from www  .  j  a v  a2s .  c  o  m
        os.write(jsonObject.toString().getBytes());
    } finally {
        os.close();
    }
}

From source file:com.liferay.portlet.asset.service.impl.AssetCategoryServiceImpl.java

License:Open Source License

public JSONObject getJSONVocabularyCategories(long groupId, String name, long vocabularyId, int start, int end,
        OrderByComparator obc) throws PortalException, SystemException {

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    int page = end / (end - start);

    jsonObject.put("page", page);

    List<AssetCategory> categories;
    int total = 0;

    if (Validator.isNotNull(name)) {
        name = (CustomSQLUtil.keywords(name))[0];

        categories = getVocabularyCategories(groupId, name, vocabularyId, start, end, obc);
        total = getVocabularyCategoriesCount(groupId, name, vocabularyId);
    } else {/*  w  w w. j a  va  2 s  .  c o m*/
        categories = getVocabularyCategories(vocabularyId, start, end, obc);
        total = getVocabularyCategoriesCount(groupId, vocabularyId);
    }

    String categoriesJSON = JSONFactoryUtil.looseSerialize(categories);

    JSONArray categoriesJSONArray = JSONFactoryUtil.createJSONArray(categoriesJSON);

    jsonObject.put("categories", categoriesJSONArray);

    jsonObject.put("total", total);

    return jsonObject;
}

From source file:com.liferay.portlet.asset.service.impl.AssetTagServiceImpl.java

License:Open Source License

public JSONObject getJSONGroupTags(long groupId, String name, int start, int end)
        throws PortalException, SystemException {

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    int page = end / (end - start);

    jsonObject.put("page", page);

    List<AssetTag> tags = new ArrayList<AssetTag>();
    int total = 0;

    if (Validator.isNotNull(name)) {
        name = (CustomSQLUtil.keywords(name))[0];

        tags = getTags(groupId, name, new String[0], start, end);
        total = getTagsCount(groupId, name, new String[0]);
    } else {//from  www  .ja  v a2 s. c  o m
        tags = getGroupTags(groupId, start, end, null);
        total = getGroupTagsCount(groupId);
    }

    String tagsJSON = JSONFactoryUtil.looseSerialize(tags);

    JSONArray tagsJSONArray = JSONFactoryUtil.createJSONArray(tagsJSON);

    jsonObject.put("tags", tagsJSONArray);

    jsonObject.put("total", total);

    return jsonObject;
}

From source file:com.liferay.portlet.asset.service.impl.AssetVocabularyServiceImpl.java

License:Open Source License

public JSONObject getJSONGroupVocabularies(long groupId, String name, int start, int end, OrderByComparator obc)
        throws PortalException, SystemException {

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    int page = end / (end - start);

    jsonObject.put("page", page);

    List<AssetVocabulary> vocabularies;
    int total = 0;

    if (Validator.isNotNull(name)) {
        name = (CustomSQLUtil.keywords(name))[0];

        vocabularies = getGroupVocabularies(groupId, name, start, end, obc);
        total = getGroupVocabulariesCount(groupId, name);
    } else {//from  w  ww  .j a  v a2  s . co  m
        vocabularies = getGroupVocabularies(groupId, start, end, obc);
        total = getGroupVocabulariesCount(groupId);
    }

    String vocabulariesJSON = JSONFactoryUtil.looseSerialize(vocabularies);

    JSONArray vocabulariesJSONArray = JSONFactoryUtil.createJSONArray(vocabulariesJSON);

    jsonObject.put("vocabularies", vocabulariesJSONArray);

    jsonObject.put("total", total);

    return jsonObject;
}

From source file:com.liferay.portlet.social.service.impl.SocialActivitySettingServiceImpl.java

License:Open Source License

public JSONArray getJSONActivityDefinitions(long groupId, String className)
        throws PortalException, SystemException {

    checkPermission(groupId);//  w  w  w  .j av  a  2s.  c  om

    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

    List<SocialActivityDefinition> activityDefinitions = socialActivitySettingLocalService
            .getActivityDefinitions(groupId, className);

    Collections.sort(activityDefinitions,
            new SocialActivityDefinitionNameComparator(LocaleThreadLocal.getThemeDisplayLocale()));

    for (SocialActivityDefinition activityDefinition : activityDefinitions) {

        JSONObject activityDefinitionJSONObject = JSONFactoryUtil
                .createJSONObject(JSONFactoryUtil.looseSerialize(activityDefinition));

        JSONArray activityCounterDefinitionsJSONArray = JSONFactoryUtil.createJSONArray();

        for (SocialActivityCounterDefinition activityCounterDefinition : activityDefinition
                .getActivityCounterDefinitions()) {

            JSONObject activityCounterDefinitionJSONObject = JSONFactoryUtil
                    .createJSONObject(JSONFactoryUtil.looseSerialize(activityCounterDefinition));

            activityCounterDefinitionsJSONArray.put(activityCounterDefinitionJSONObject);
        }

        activityDefinitionJSONObject.put("counters", activityCounterDefinitionsJSONArray);

        jsonArray.put(activityDefinitionJSONObject);
    }

    return jsonArray;
}

From source file:com.liferay.screens.service.impl.ScreensAssetEntryServiceImpl.java

License:Open Source License

protected JSONObject getBlogsEntryJSONObject(AssetEntry assetEntry) throws PortalException {

    BlogsEntry blogsEntry = _blogsEntryService.getEntry(assetEntry.getClassPK());

    JSONObject blogsEntryJSONObject = JSONFactoryUtil.createJSONObject();

    blogsEntryJSONObject.put("blogsEntry",
            JSONFactoryUtil.createJSONObject(JSONFactoryUtil.looseSerialize(blogsEntry)));

    return blogsEntryJSONObject;
}

From source file:com.liferay.screens.service.impl.ScreensAssetEntryServiceImpl.java

License:Open Source License

protected JSONObject getFileEntryJSONObject(AssetEntry assetEntry) throws PortalException {

    FileEntry fileEntry = dlAppService.getFileEntry(assetEntry.getClassPK());

    JSONObject fileEntryJSONObject = JSONFactoryUtil.createJSONObject();

    fileEntryJSONObject.put("fileEntry",
            JSONFactoryUtil.createJSONObject(JSONFactoryUtil.looseSerialize(fileEntry)));
    fileEntryJSONObject.put("url", getFileEntryPreviewURL(fileEntry));

    return fileEntryJSONObject;
}