How to get articleId dynamically? - liferay-6

I am using Asset Publisher and need to dynamically get the articleId of the latest journal article published.
I am using in abstracts.jsp hook:
version=JournalArticleLocalServiceUtil.getLatestVersion(assetRenderer.getGroupId(), "14405");
journalArticle = JournalArticleLocalServiceUtil.getArticle(assetRenderer.getGroupId() , "14405",version);
I have hardcoded the articleId here.
How do I avoid this??
Kindly help.
Thanks.

Use a dynamic query to get the latest Article from JournalArticleLocalServiceUtil maybe you can use ProjectionFactoryUtil.max("createDate"); to get the latest Date
DynamicQueryFactoryUtil.forClass(JournalArticle.class)
.add(ProjectionFactoryUtil.max("createDate"))
.add(PropertyFactoryUtil.forName("groupId").eq(new Long(groupId)));
List results =JournalArticleLocalServiceUtil.dynamicQuery(query);`

Related

Magento 2 with Full Page Cache: How to get product ID from a product page?

I am trying to find a solution to what seems to be a FPC-linked issue.
In my code I am using the following method in order to get the current product ID from a Product page.
$this->catalogSession->getData('last_viewed_product_id')
This worked just fine until I tried it on a website with Full Page Cache: in this case, it returns an empty value (maybe because the session data cannot be accessed from cache).
Does anyone know an alternative method to get the product ID from the current context?
I have tried this alternative synthax:
$_SESSION['catalog']['last_viewed_product_id'];
While not the best solution and definitely not best practice, you can use objectmanager:
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->get('Magento\Framework\Registry')->registry('current_product');
$id = $product->getId();
This will get you the id but, as stated above, it's not suggested and you should create a block and inject the registry there and call it in your code.
You can see this post https://meetanshi.com/blog/get-current-product-id-in-magento-2/

How to retrieve build attachment from VSTS release summary tab

I need to retrieve a build attachment attached using (##vso[task.addattachment]value) from release summary page (ms.vss-releaseManagement-web.release-details-summary-tab). Please point me to any references to achieve this.
Thanks in advance.
Yes, you need to do followings things to get this:
1.Get the related build id of the release via getConfiguration():
var c = VSS.getConfiguration();
c.onReleaseChanged(function (release) {
release.artifacts.forEach(function (art) {
var buildid = art.definitionReference.version.id;
});
});
2.Use the build ID you get in previous step to get the detailed build information via getBuild(). And then you can get the planid from the build information.
3.Use the planid to get the uploaded file via getPlanAttachments().

UCM service for searching in all revisions

I would like to search for a text in an attribute of UCM content using RIDC. If I use GET_SEARCH_RESULTS service, I will be getting only the latest revision the of result document. But I want to get all the revisions, which will fall in to the given search criteria. is there any way for the same?
Sample code is here..
String whereClause = "UPPER(XCOMMENTS) LIKE '%VALUE%'";
dataBinder.putLocal("IdcService", "GET_DATARESULTSET");
dataBinder.putLocal("dataSource", "Documents");
dataBinder.putLocal("whereClause", whereClause);
dataBinder.putLocal("resultName", "YourResult");
ServiceResponse response =
idcClient.sendRequest(userContext, dataBinder);
System.out.println(response.toString());
DataBinder serverBinder = response.getResponseAsBinder();
DataResultSet resultSet = serverBinder.getResultSet("YourResult");
Do you want to search for against full-text or metadata?
If metadata, you should be able to use service GET_DATARESULTSET and dataSource RevisionIDs.
If full-text, you might need to roll your own.

Posting/retrieving photo-comments using Graph API

When I use the Graph API to fetch a comment containing an image, the returned JSON contains no reference to it, e.g.
{
  "id": "10151452996201039_9302037",
  "from": {
    "name": "Anton Raxacoricofallapatorius Dyudin",
    "id": "1534947411"
  },
  "message": "",
  "can_remove": true,
  "created_time": "2013-06-20T06:47:41+0000",
  "like_count": 0,
  "user_likes": false
}
I am likewise lost as to what POST field can be used to embed a picture when commenting.
How can I achieve either of the above?
Add fields=attachment to your query.
https://developers.facebook.com/docs/graph-api/reference/comment
It actually works when you use fields=attachment
https://graph.facebook.com/POSTID_COMMENTID?fields=attachment&access_token=ACCESS_TOKEN
If you want a more extensive query that return everythings and I mean everything including user id's, profile image (large version), comment related info as well and attachement info use this.
&fields=id,status_type,created_time,from{name,id,picture.width(400).height(400)},message,picture.width(400).height(400),link,icon,comments{comments{attachment,from{picture.width(400).height(400),name},id,message,created_time},from{picture.width(400).height(400),name},id,message,attachment,created_time}

how to show metadata associate with a custom document

I would like to view the custom metadata that I associated with the my custom document, that I created with the document library, anyone know how to due with velocity variable?
Thanks in advance
Sabrina
You can get some meta-data articles properties with
$reserved-article-id.data
$reserved-article-title.data
full list you can find here
Also you can check this post, it has example how to get journal's categories at velocity template.
UPD. For getting document metadata you can use smth like this:
#set($dlFileUtil = $serviceLocator.findService("com.liferay.portlet.documentlibrary.service.DLFileE‌​ntryLocalService"))
#set ($groupId = $getterUtil.getLong($groupId))
#set($fileEntry = $dlFileEntryUtil.getFileEntryByUuidAndGroupId($uuid,$longGroupId))
#set($metadataUtil=$serviceLocator.findService("com.liferay.portlet.documentlibrary.service.DLFileE‌​ntryMetadataLocalService"))
You can use getFileEntryMetadata(ddmStructureId, fileVersionId) from $metadataUtil
More detailed code you can check this.
BR,
Paul Butenko