use of com.liferay.portlet.asset.model.AssetLink 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;
}
Aggregations