Created
October 20, 2023 21:41
-
-
Save prince-neres/5b7521c78bbbf86f41d95992c2680ee6 to your computer and use it in GitHub Desktop.
Relacionando arquivo de documentos e mídia com conteúdo web no liferay
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void relateFileToContent(long fileId, String externalReferenceCode) throws PortalException { | |
long groupId = _b3MigratorSystemConfiguration.clientsGroupId(); | |
AssetEntry journalArticleEntry = getJournalArticleEntry(externalReferenceCode, groupId); | |
AssetEntry fileEntry = getFileEntry(fileId, groupId); | |
if (Validator.isNotNull(journalArticleEntry) && Validator.isNotNull(fileEntry)) { | |
relateEntries(journalArticleEntry, fileEntry); | |
relateEntries(fileEntry, journalArticleEntry); | |
String successMessage = String.format( | |
"Relacionamento entre conteúdo %s e documento %s relizado com sucesso", | |
journalArticleEntry.getTitle(), fileEntry.getTitle()); | |
logInfo(successMessage); | |
} else { | |
String warnMessage = String.format( | |
"Não foi possível relacionar conteúdo %s com documento %s ", | |
journalArticleEntry.getTitle(), fileEntry.getTitle()); | |
logWarn(warnMessage); | |
} | |
} | |
private AssetEntry getFileEntry(long fileId, long groupId) throws PortalException { | |
FileEntry file = _dlAppLocalServiceUtil.getFileEntry(fileId); | |
return _assetEntryLocalService.fetchEntry(groupId, file.getUuid()); | |
} | |
private AssetEntry getJournalArticleEntry(String externalReferenceCode,long groupId) throws PortalException { | |
JournalArticle journalArticleEntry = _journalArticleLocalService.getLatestArticleByExternalReferenceCode(groupId, externalReferenceCode); | |
return _assetEntryLocalService.fetchEntry(groupId, journalArticleEntry.getArticleResourceUuid()); | |
} | |
private void relateEntries( | |
AssetEntry entry1, AssetEntry entry2) { | |
ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext(); | |
long assetLinkId = _counterLocalService.increment(AssetLink.class.getName()); | |
AssetLink assetLink = _assetLinkLocalService.createAssetLink(assetLinkId); | |
assetLink.setEntryId1(entry1.getEntryId()); | |
assetLink.setEntryId2(entry2.getEntryId()); | |
assetLink.setCompanyId(serviceContext.getCompanyId()); | |
assetLink.setUserId(serviceContext.getUserId()); | |
_assetLinkLocalService.updateAssetLink(assetLink); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment