Search in sources :

Example 21 with JSONObject

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

the class PortletUtils method importStatusToJSON.

public static JSONObject importStatusToJSON(VulnerabilityUpdateStatus updateStatus) {
    JSONObject responseData = JSONFactoryUtil.createJSONObject();
    if (!updateStatus.isSetStatusToVulnerabilityIds() || !updateStatus.isSetRequestStatus()) {
        responseData.put(PortalConstants.REQUEST_STATUS, PortalConstants.RESPONSE__IMPORT_GENERAL_FAILURE);
        return responseData;
    }
    if (updateStatus.getRequestStatus().equals(RequestStatus.FAILURE) && nullToEmptyList(updateStatus.getStatusToVulnerabilityIds().get(UpdateType.FAILED)).size() == 0) {
        responseData.put(PortalConstants.REQUEST_STATUS, PortalConstants.RESPONSE__IMPORT_GENERAL_FAILURE);
        return responseData;
    }
    responseData.put(PortalConstants.REQUEST_STATUS, updateStatus.getRequestStatus().toString());
    JSONArray jsonFailedIds = JSONFactoryUtil.createJSONArray();
    JSONArray jsonNewIds = JSONFactoryUtil.createJSONArray();
    JSONArray jsonUpdatedIds = JSONFactoryUtil.createJSONArray();
    updateStatus.getStatusToVulnerabilityIds().get(UpdateType.FAILED).forEach(jsonFailedIds::put);
    updateStatus.getStatusToVulnerabilityIds().get(UpdateType.NEW).forEach(jsonNewIds::put);
    updateStatus.getStatusToVulnerabilityIds().get(UpdateType.UPDATED).forEach(jsonUpdatedIds::put);
    responseData.put(PortalConstants.UPDATE_VULNERABILITIES__FAILED_IDS, jsonFailedIds);
    responseData.put(PortalConstants.UPDATE_VULNERABILITIES__NEW_IDS, jsonNewIds);
    responseData.put(PortalConstants.UPDATE_VULNERABILITIES__UPDATED_IDS, jsonUpdatedIds);
    return responseData;
}
Also used : JSONObject(com.liferay.portal.kernel.json.JSONObject) JSONArray(com.liferay.portal.kernel.json.JSONArray)

Example 22 with JSONObject

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

the class KBArticleLocalServiceImpl method updateStatus.

@Override
public KBArticle updateStatus(long userId, long resourcePrimKey, int status, ServiceContext serviceContext) throws PortalException, SystemException {
    // KB article
    User user = userPersistence.findByPrimaryKey(userId);
    boolean main = false;
    Date now = new Date();
    if (status == WorkflowConstants.STATUS_APPROVED) {
        main = true;
    }
    KBArticle kbArticle = getLatestKBArticle(resourcePrimKey, WorkflowConstants.STATUS_ANY);
    kbArticle.setModifiedDate(serviceContext.getModifiedDate(now));
    kbArticle.setMain(main);
    kbArticle.setStatus(status);
    kbArticle.setStatusByUserId(user.getUserId());
    kbArticle.setStatusByUserName(user.getFullName());
    kbArticle.setStatusDate(serviceContext.getModifiedDate(now));
    kbArticlePersistence.update(kbArticle);
    if (status != WorkflowConstants.STATUS_APPROVED) {
        return kbArticle;
    }
    if (!kbArticle.isFirstVersion()) {
        KBArticle oldKBArticle = kbArticlePersistence.findByR_V(resourcePrimKey, kbArticle.getVersion() - 1);
        oldKBArticle.setMain(false);
        kbArticlePersistence.update(oldKBArticle);
    }
    // Asset
    AssetEntry assetEntry = assetEntryLocalService.getEntry(KBArticle.class.getName(), kbArticle.getKbArticleId());
    List<AssetLink> assetLinks = assetLinkLocalService.getDirectLinks(assetEntry.getEntryId(), AssetLinkConstants.TYPE_RELATED);
    long[] assetLinkEntryIds = StringUtil.split(ListUtil.toString(assetLinks, AssetLink.ENTRY_ID2_ACCESSOR), 0L);
    updateKBArticleAsset(userId, kbArticle, assetEntry.getCategoryIds(), assetEntry.getTagNames(), assetLinkEntryIds);
    SystemEventHierarchyEntryThreadLocal.push(KBArticle.class);
    try {
        assetEntryLocalService.deleteEntry(KBArticle.class.getName(), kbArticle.getKbArticleId());
    } finally {
        SystemEventHierarchyEntryThreadLocal.pop(KBArticle.class);
    }
    assetEntryLocalService.updateVisible(KBArticle.class.getName(), kbArticle.getResourcePrimKey(), true);
    // Social
    JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();
    extraDataJSONObject.put("title", kbArticle.getTitle());
    if (!kbArticle.isFirstVersion()) {
        socialActivityLocalService.addActivity(userId, kbArticle.getGroupId(), KBArticle.class.getName(), resourcePrimKey, AdminActivityKeys.UPDATE_KB_ARTICLE, extraDataJSONObject.toString(), 0);
    } else {
        socialActivityLocalService.addActivity(userId, kbArticle.getGroupId(), KBArticle.class.getName(), resourcePrimKey, AdminActivityKeys.ADD_KB_ARTICLE, extraDataJSONObject.toString(), 0);
    }
    // Indexer
    Indexer indexer = IndexerRegistryUtil.getIndexer(KBArticle.class);
    indexer.reindex(kbArticle);
    // Subscriptions
    notifySubscribers(kbArticle, serviceContext);
    return kbArticle;
}
Also used : AssetEntry(com.liferay.portlet.asset.model.AssetEntry) User(com.liferay.portal.model.User) Indexer(com.liferay.portal.kernel.search.Indexer) KBArticle(com.liferay.knowledgebase.model.KBArticle) JSONObject(com.liferay.portal.kernel.json.JSONObject) Date(java.util.Date) AssetLink(com.liferay.portlet.asset.model.AssetLink)

Example 23 with JSONObject

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

the class KBCommentLocalServiceImpl method updateKBComment.

@Override
public KBComment updateKBComment(long kbCommentId, long classNameId, long classPK, String content, int userRating, int status, ServiceContext serviceContext) throws PortalException, SystemException {
    // KB comment
    validate(content);
    KBComment kbComment = kbCommentPersistence.findByPrimaryKey(kbCommentId);
    kbComment.setModifiedDate(serviceContext.getModifiedDate(null));
    kbComment.setClassNameId(classNameId);
    kbComment.setClassPK(classPK);
    kbComment.setContent(content);
    kbComment.setUserRating(userRating);
    kbComment.setStatus(status);
    kbCommentPersistence.update(kbComment);
    // Social
    JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();
    putTitle(extraDataJSONObject, kbComment);
    socialActivityLocalService.addActivity(kbComment.getUserId(), kbComment.getGroupId(), KBComment.class.getName(), kbCommentId, AdminActivityKeys.UPDATE_KB_COMMENT, extraDataJSONObject.toString(), 0);
    return kbComment;
}
Also used : KBComment(com.liferay.knowledgebase.model.KBComment) JSONObject(com.liferay.portal.kernel.json.JSONObject)

Example 24 with JSONObject

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

the class KBArticleLocalServiceImpl method moveKBArticle.

@Override
public void moveKBArticle(long userId, long resourcePrimKey, long parentResourceClassNameId, long parentResourcePrimKey, double priority) throws PortalException, SystemException {
    // KB article
    validate(priority);
    updatePermissionFields(resourcePrimKey, parentResourceClassNameId, parentResourcePrimKey);
    long kbFolderClassNameId = classNameLocalService.getClassNameId(KBFolderConstants.getClassName());
    long kbFolderId = KBFolderConstants.DEFAULT_PARENT_FOLDER_ID;
    if (parentResourceClassNameId == kbFolderClassNameId) {
        kbFolderId = parentResourcePrimKey;
    } else {
        KBArticle latestKBArticle = getLatestKBArticle(parentResourcePrimKey, WorkflowConstants.STATUS_ANY);
        kbFolderId = latestKBArticle.getKbFolderId();
    }
    List<KBArticle> kbArticles = getKBArticleVersions(resourcePrimKey, WorkflowConstants.STATUS_ANY, QueryUtil.ALL_POS, QueryUtil.ALL_POS, new KBArticleVersionComparator());
    for (KBArticle curKBArticle : kbArticles) {
        curKBArticle.setParentResourceClassNameId(parentResourceClassNameId);
        curKBArticle.setParentResourcePrimKey(parentResourcePrimKey);
        curKBArticle.setKbFolderId(kbFolderId);
        curKBArticle.setPriority(priority);
        kbArticlePersistence.update(curKBArticle);
    }
    KBArticle kbArticle = getLatestKBArticle(resourcePrimKey, WorkflowConstants.STATUS_ANY);
    if (kbArticle.getKbFolderId() != kbFolderId) {
        List<KBArticle> descendantKBArticles = getAllDescendantKBArticles(resourcePrimKey, WorkflowConstants.STATUS_ANY, null);
        for (KBArticle curKBArticle : descendantKBArticles) {
            List<KBArticle> kbArticleVersions = getKBArticleVersions(curKBArticle.getResourcePrimKey(), WorkflowConstants.STATUS_ANY, QueryUtil.ALL_POS, QueryUtil.ALL_POS, new KBArticleVersionComparator());
            for (KBArticle kbArticleVersion : kbArticleVersions) {
                kbArticleVersion.setKbFolderId(kbFolderId);
                kbArticlePersistence.update(kbArticleVersion);
            }
        }
    }
    // Social
    KBArticle latestKBArticle = getLatestKBArticle(resourcePrimKey, WorkflowConstants.STATUS_ANY);
    JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();
    extraDataJSONObject.put("title", latestKBArticle.getTitle());
    if (latestKBArticle.isApproved() || !latestKBArticle.isFirstVersion()) {
        socialActivityLocalService.addActivity(userId, latestKBArticle.getGroupId(), KBArticle.class.getName(), resourcePrimKey, AdminActivityKeys.MOVE_KB_ARTICLE, extraDataJSONObject.toString(), 0);
    }
}
Also used : KBArticle(com.liferay.knowledgebase.model.KBArticle) KBArticleVersionComparator(com.liferay.knowledgebase.util.comparator.KBArticleVersionComparator) JSONObject(com.liferay.portal.kernel.json.JSONObject)

Example 25 with JSONObject

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

the class BaseKBPortlet method deleteTempAttachment.

public void deleteTempAttachment(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
    long resourcePrimKey = ParamUtil.getLong(actionRequest, "resourcePrimKey");
    String fileName = ParamUtil.getString(actionRequest, "fileName");
    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
    try {
        KBArticleServiceUtil.deleteTempAttachment(themeDisplay.getScopeGroupId(), resourcePrimKey, fileName, KnowledgeBaseConstants.TEMP_FOLDER_NAME);
        jsonObject.put("deleted", Boolean.TRUE);
    } catch (Exception e) {
        String errorMessage = themeDisplay.translate("an-unexpected-error-occurred-while-deleting-the-file");
        jsonObject.put("deleted", Boolean.FALSE);
        jsonObject.put("errorMessage", errorMessage);
    }
    writeJSON(actionRequest, actionResponse, jsonObject);
}
Also used : JSONObject(com.liferay.portal.kernel.json.JSONObject) ThemeDisplay(com.liferay.portal.theme.ThemeDisplay) AssetCategoryException(com.liferay.portlet.asset.AssetCategoryException) KBCommentContentException(com.liferay.knowledgebase.KBCommentContentException) FileNameException(com.liferay.portlet.documentlibrary.FileNameException) NoSuchArticleException(com.liferay.knowledgebase.NoSuchArticleException) KBArticlePriorityException(com.liferay.knowledgebase.KBArticlePriorityException) KBArticleTitleException(com.liferay.knowledgebase.KBArticleTitleException) PrincipalException(com.liferay.portal.security.auth.PrincipalException) PortalException(com.liferay.portal.kernel.exception.PortalException) SystemException(com.liferay.portal.kernel.exception.SystemException) NoSuchFileException(com.liferay.portlet.documentlibrary.NoSuchFileException) FileSizeException(com.liferay.portlet.documentlibrary.FileSizeException) KBArticleContentException(com.liferay.knowledgebase.KBArticleContentException) DuplicateFileException(com.liferay.portlet.documentlibrary.DuplicateFileException) IOException(java.io.IOException) UploadException(com.liferay.portal.kernel.upload.UploadException) NoSuchCommentException(com.liferay.knowledgebase.NoSuchCommentException) AssetTagException(com.liferay.portlet.asset.AssetTagException) PortletException(javax.portlet.PortletException)

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