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;
}
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;
}
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;
}
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);
}
}
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);
}
Aggregations