掲示板

Asset Builder

7年前 に raja ponna によって更新されました。

Asset Builder

New Member 投稿: 6 参加年月日: 16/11/09 最新の投稿
Hi everyone, I'm trying to pull data for tags and categories in one of the sites i'm building. I've gone through so many forums but couldn't find relevant information on how to retrieve data. Can somebody please help me in resolving this issue.

Issue: I have few documents, pictures and videos uploaded. Based on the files the category must pull data of what sort it is.
Eg: Document.
Tags must pull the top words from that document
Eg: interviews, social history.
when clicked on any of those tags it must display all the files that contains interviews as its tag.
I'm using these tags, and categories in the Asset Builder.

I want to pull the data similar to those categories and tags
Attached image is the current one i'm trying to do.

Thanks In Advance.

添付ファイル:

thumbnail
7年前 に Andrew Jardine によって更新されました。

RE: Asset Builder

Liferay Legend 投稿: 2416 参加年月日: 10/12/22 最新の投稿
Hi Raja,

I'm not sure that I entirely understand your question, but I hate to leave a post unanswered. Nothing more frustrating than asking for help and getting dead silence -- so I'll give it a shot.

Here is what I understand.

1. You have multiple files that you have uploaded -- to the Documents and Media perhaps? (please confirm)
2. Assuming that you have placed them in the Documents and Media, you upload all of them using the "Basic Document" type.
3. Once a document is added, you used the category to try to provide a (structured) document classification.
4. You are also using tags as a means to provide unstructured classification.

Now you are trying to use the Asset PUBLISHER (I think you called in a builder, but I presume that was a typo) to try to provide a list of specific document types -- but the problem is when you are configuring the Asset Publisher you have to list the categories to include, and since the list might change, that won't work for you.

Have I understood so far?
7年前 に raja ponna によって更新されました。

RE: Asset Builder

New Member 投稿: 6 参加年月日: 16/11/09 最新の投稿
Hi Andrew,
Thanks for the reply.

Yes ! that is what i'm trying to do (points 1-4).

Here is the link as in how it should appear (URL). Please go through this URL once.This is what i want my page to be like .

So far i could create a template with categories and tags but couldn't provide functionality to it in pulling the data.(please find the attached picture)

This is the current code with which i'm trying:

<label>Categories</label>
<liferay-ui:asset-categories-summary

JournalArticleLocalServiceUtil.getLatestArticle(classPK)

JournalArticle wc = JournalArticleLocalServiceUtil.getArticle(assetEntry.getClassPK());
classPK="<%= assetEntry.getClassPK () %>"
JournalArticleLocalServiceUtil.getLatestArticle(classPK);
portletURL='<%= selectionStyle.equals("manual") ? null : renderResponse.createRenderURL() %>'
/>

<label>Tags</label>
<liferay-ui:asset-tags-summary
className="<%= categories.getClass().getName() %>"
classPK="<%= categories.getPrimaryKey() %>"
/>



Hope this finds you the clear picture. Apologizes for my confused.

Thanks In Advance.

添付ファイル:

thumbnail
7年前 に Andrew Jardine によって更新されました。

RE: Asset Builder

Liferay Legend 投稿: 2416 参加年月日: 10/12/22 最新の投稿
Your code doesn't look like template code. Are you using the asset publisher portlet? or are you building a custom portlet?
7年前 に raja ponna によって更新されました。

RE: Asset Builder

New Member 投稿: 6 参加年月日: 16/11/09 最新の投稿
I'm using Application Display Template to write the code and Asset Publisher to use everything together(basic web content, other structures)
thumbnail
7年前 に Andrew Jardine によって更新されました。

RE: Asset Builder

Liferay Legend 投稿: 2416 参加年月日: 10/12/22 最新の投稿
I see -- I guess the confusing part is the syntax that you showed. If you want to use the taglibs, then you need to use Freemarker as your templating language. I would have expected to see a declaration of the tag lib and then a different syntax for it's use. For example, something like this --

&lt;#assign aui=PortalJspTagLibs["/WEB-INF/tld/liferay-aui.tld"]&gt;

&lt;@aui.input name=“keywords” label=“Search:” /&gt;


.. but using the liferay-ui instead. So maybe we can start from the top. Is your issue at you are getting template errors when you try to use those taglibs? Or are the screenshots you are providing the actual screens your template is producing?
7年前 に raja ponna によって更新されました。

RE: Asset Builder

New Member 投稿: 6 参加年月日: 16/11/09 最新の投稿
The screenshot I've provided is the actual output of my template. I want those categories and tags to pull the data which it isn't doing.
thumbnail
7年前 に Andrew Jardine によって更新されました。

RE: Asset Builder

Liferay Legend 投稿: 2416 参加年月日: 10/12/22 最新の投稿
Alright -- can you provide your full template code to me? That way I can try/modify it on my side rather than asking a million questions.
7年前 に raja ponna によって更新されました。

RE: Asset Builder

New Member 投稿: 6 参加年月日: 16/11/09 最新の投稿
i'm using Velocity to display each document's information. The application display template velocity code needs to pull any category, or tags that were assigned to it. How do you pull that information with velocity.


<style>

.news{
display: inline-flex !important;

}

.news-image{
height: 130px!important;
height: 130px!important;
width: 200px!important;
padding: 5px;
border: 2px;


}

.news-details h3{
color: #790d22! important;
font: 500 normal 1.375em "Roboto",Arial,Verdana,sans-serif;
}

.the-icons .span3 a {

background-color: #790d22;
padding: 0px 5px 3px 5px;
position: relative;
top: 1px;
display: inline-block;
font-style: normal;
font-weight: 400;
line-height: 1;
}
.the-icons .span3 a:hover {
background-color: #083963;

}
.the-icons .span3 a [class^="glyphicon glyphicon-plus"], .the-icons .span3 a [class*="glyphicon glyphicon-plus"] {
color: #fff !important;
font-size: 28px;
text-align: center;
width: 20px;
height: 10px;
}

</style>
#if (!$entries.isEmpty())
<div class="event">
#foreach ($entry in $entries)

#set($renderer = $entry.getAssetRenderer() )
#set($className = $renderer.getClassName() )
#if( $className == "com.liferay.portlet.journal.model.JournalArticle" )
#set( $journalArticle = $renderer.getArticle() )
#set( $document = $saxReaderUtil.read($journalArticle.getContent()) )
#set( $rootElement = $document.getRootElement() )

## FETCH Title
#set( $xPathSelector = $saxReaderUtil.createXPath("dynamic-element[@name='newstitle']") )
#set( $title = $xPathSelector.selectSingleNode($rootElement).getStringValue())

## FETCH image
#set( $xPathSelector = $saxReaderUtil.createXPath("dynamic-element[@name='featureimage']") )
#set( $img = $xPathSelector.selectSingleNode($rootElement).getStringValue())

## FETCH FullDescription
#set( $xPathSelector = $saxReaderUtil.createXPath("dynamic-element[@name='newsfulldescription']") )
#set( $fulldesc = $xPathSelector.selectSingleNode($rootElement).getStringValue() )

## FETCH ShortDescription
#set( $xPathSelector = $saxReaderUtil.createXPath("dynamic-element[@name='newsshortdescription']") )
#set( $shortdesc = $xPathSelector.selectSingleNode($rootElement).getStringValue() )


## FETCH Group
#set( $xPathSelector = $saxReaderUtil.createXPath("dynamic-element[@name='group']") )
#set( $Group = $xPathSelector.selectSingleNode($rootElement).getStringValue())

#set( $link = $assetPublisherHelper.getAssetViewURL($renderRequest, $renderResponse, $entry) )

#if ("$assetLinkBehavior" != "showFullContent")
#set( $link = $renderer.getURLViewInContext($renderRequest, $renderResponse, $link) )
#end


#set( $newsDate = $entry.getPublishDate())

#set($format = $dateUtil.getISOFormat("yyyyMMdd"))


#set ( $curdate = $format.parse($dateUtil.getCurrentDate("yyyyMMdd", $locale)) )
<div class="event-feed">
#set($datevar = $dateUtil.getDate( $newsDate , "dd", $locale))

#set($monthvar = $dateUtil.getDate($newsDate , "MMMM", $locale))

#set($dayvar = $dateUtil.getDate($newsDate , "EEEE", $locale))

#set($fulldatevar = $dateUtil.getDate($newsDate , "yyyy-MM-dd", $locale))
#set($yearvar = $dateUtil.getDate($newsDate , "yyyy", $locale))


<section class="news">
<div class="news-image">
<a href="$link" target="_self">
<img alt="$img" src="$img">
</a>
</div>

<div class="news-details"
<span class="asset-entry"></span>
<a href="$link" target="">
<h3>$title</h3>
</a>
<label>Categories</label>
<liferay-ui:asset-categories-summary

JournalArticleLocalServiceUtil.getLatestArticle(classPK)

JournalArticle wc = JournalArticleLocalServiceUtil.getArticle(assetEntry.getClassPK());
classPK="<%= assetEntry.getClassPK () %>"
JournalArticleLocalServiceUtil.getLatestArticle(classPK);
portletURL='<%= selectionStyle.equals("manual") ? null : renderResponse.createRenderURL() %>'
/>

<label>Tags</label>
<liferay-ui:asset-tags-summary
className="<%= categories.getClass().getName() %>"
classPK="<%= categories.getPrimaryKey() %>"
/>
<div class="the-icons">
<span class="span3">
<a href="$link" target="_self"> <i class="glyphicon glyphicon-plus"></i></a></span></div>
</div>
<hr class="hr">
</section>
</div>

#end
#end
</div>
#end
thumbnail
7年前 に Andrew Jardine によって更新されました。

RE: Asset Builder

Liferay Legend 投稿: 2416 参加年月日: 10/12/22 最新の投稿
Hey Raja,

I'm not sure if I have what you are looking for but let's start with this. I looked at your code -- incidentally, you should format your code using the <> button in the toolbar please -- and it looks like you are only rendering JournalArticles. If that is the case, then you should configure your asset publisher so that you only select assets of type WebContent -- and if there is a particular structure, then you should further refine on those as well. In my example, I created a News Article structure with one field -- a body. The title field is there already as a reserved word -- so no need to duplicate it. I then created a News Article Template. My template is not an ADT, it is a WCM template with content like this --

<div class="row-fluid">
    <div span="12">
        ${.vars['reserved-article-title'].getData()}
    </div>
</div>
<div class="row-fluid">
    <div span="12">
        ${body.getData()}
    </div>
</div>


You'll see why I did this in a minute. The next thing I did was I made a couple of sample News Article content items. I then created a new page, and added the asset publisher to it. I configured my AP to only show web content of type News Article. I then went to the display settings and created a new ADT template call News Listing.

Now, for my solution, I don't use the SaxReader. I try to avoid parsing XML by hand whenever I can. instead what I have done is looked up my WCM template that I created (above) using the serviceLocator and then used a method on the JournalArticle service API to render the HTML. You also want the tags and categories associated to the asset so I updated the ADT to use the AssetTags and AssetCategories services to pull in those values. Those values I had set when I created my sample content using the "Categories" section on the right of the content editor.

The tags and categories list are in the ADT, but there is nothing stopping you for instead putting them in the WCM.

Here is the code --

&lt;#assign liferay_ui = taglibLiferayHash["/WEB-INF/tld/liferay-ui.tld"] /&gt;

&lt;#-- services we need for the template --&gt;
&lt;#assign JournalArticleLocalService = serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleLocalService")/&gt;
&lt;#assign DDMTemplateLocalService = serviceLocator.findService("com.liferay.portlet.dynamicdatamapping.service.DDMTemplateLocalService")/&gt;
&lt;#assign AssetTagLocalService = serviceLocator.findService("com.liferay.portlet.asset.service.AssetTagLocalService")/&gt;
&lt;#assign AssetCategoryLocalService = serviceLocator.findService("com.liferay.portlet.asset.service.AssetCategoryLocalService")/&gt;


&lt;#-- 
I am using a loop here to find the template name because I normally
have the template name set as a configuration property that I read so 
that if the template name changes in future I don't have to change the 
references everywhere -- just the configuration. But if you want to just
pull the one template name you can, you just need a different method
--&gt;
&lt;#assign templateName = "News Article"/&gt;
&lt;#assign ddmTemplateList = DDMTemplateLocalService.getDDMTemplates(-1, -1)/&gt;

&lt;#if ddmTemplateList?has_content&gt;
    &lt;#list ddmTemplateList as ddmTemplate&gt;
        &lt;#if ddmTemplate.getName(themeDisplay.getLocale()) == templateName&gt;
           &lt;#assign ddmCardTemplate = ddmTemplate /&gt;
        <!--#if-->
    <!--#list-->
<!--#if-->

&lt;#-- 
Now we loop over the items to render their content. Rather than using the 
SAXReader to parse the XML, I tend to go for a method that is available
in the journal api that you can pass the article and template key and it 
will return to you the html result of rendering the code in the template
--&gt;
&lt;#if entries?has_content&gt;

    <ul>
    	&lt;#list entries as curEntry&gt;
    	    &lt;#assign assetRenderer = curEntry.getAssetRenderer() /&gt;
    	    
    	    &lt;#-- 
    	    rather than do this, if you just want to render journal articles you can configure
    	    the asset publisher to only pull items on this content type. You can also further
    	    refine it to the structure so that you can say -- just give me journal articles
    	    with a structure type of "News Article". That way you don't have a pile of 
    	    items in your list that you are just going to ignore 
    	    --&gt;
    	    &lt;#if assetRenderer?? &amp;&amp; assetRenderer.getClassName() == "com.liferay.portlet.journal.model.JournalArticle"&gt;
    	       
    	        &lt;#-- get the article object --&gt;
    	        &lt;#assign journalArticle = assetRenderer.getArticle() /&gt;
    	        
    	        &lt;#assign viewURL = assetPublisherHelper.getAssetViewURL(renderRequest, renderResponse, curEntry) /&gt;
                &lt;#if assetLinkBehavior != "showFullContent"&gt;
                    &lt;#assign viewURL = assetRenderer.getURLViewInContext(renderRequest, renderResponse, viewURL) /&gt;
                <!--#if-->
    	        
    	        
    	        <a href="${viewURL}">
        	        <li>
        	            
        	            ${JournalArticleLocalService.getArticleContent(assetRenderer.getArticle(), ddmCardTemplate.getTemplateKey(), "", themeDisplay.getLanguageId(), themeDisplay)}
        	            
        	            &lt;#-- // tags --&gt;
                        &lt;#assign tagsList = AssetTagLocalService.getAssetEntryAssetTags(curEntry.getEntryId()) /&gt;
                        &lt;#if tagsList?? &amp;&amp; tagsList?has_content&gt;
                            <ul class="inline">
                                &lt;#list tagsList as tag&gt;
                                    <li>${tag.getName()}</li>
                                <!--#list-->
                            </ul>
                        <!--#if-->
                        
                        &lt;#-- // categories --&gt;
                        &lt;#assign categoryList = AssetCategoryLocalService.getAssetEntryAssetCategories(curEntry.getEntryId()) /&gt;
                        &lt;#if categoryList?? &amp;&amp; categoryList?has_content&gt;
                            <ul class="inline">
                                &lt;#list categoryList as category&gt;
                                    <li>${category.getName()}</li>
                                <!--#list-->
                            </ul>
                        <!--#if-->
        	        </li>
    	        </a>
    	    <!--#if-->

    	<!--#list-->
	</ul>
<!--#if-->


Note that I have elected to use Freemarker here because I thought you wanted to use the tag libraries. But from the code you sent over I don't see it -- at any rate, FTL is much easier to work with because it actually throws errors to you when things go wrong -- as opposed to the "blank screen" solution that Velocity likes to use.

Hopefully this helps. If you have any additional questions, just fire'em back.
thumbnail
7年前 に Andrew Jordan によって更新されました。

RE: Asset Builder

Junior Member 投稿: 39 参加年月日: 15/11/02 最新の投稿
Hi Andrew,

I work with Raja and have been mulling over your code while he is away. I had a couple of questions I hope you can assist with.

First of all, thank you so much for your assistance!

1) How do we obtain the URL for the tag/category that when clicked will display the list of assets that also share that tag/category?
2) You mentioned --
The tags and categories list are in the ADT, but there is nothing stopping you for instead putting them in the WCM
. How could we achieve this considering we may want certain elements to fall in different places within the WCM's html structure.

Thanks again for your assistance. I look forward to your response.

Andrew Jordan
thumbnail
7年前 に Andrew Jardine によって更新されました。

RE: Asset Builder

Liferay Legend 投稿: 2416 参加年月日: 10/12/22 最新の投稿
Hi Andrew,

Let me see if I can help --

1) How do we obtain the URL for the tag/category that when clicked will display the list of assets that also share that tag/category?


Have a look at your publisher configuration. You'll see that there is a tab called "Communication". In this tab you will find a table (I attached an image for your reference) that contains a list of rows, each identifying a public render parameter. Public render parameters (PRPs) are awesome because they allow you to pass parameters to a "page" and have portlets respond accordingly. Just to make it clear let me give you an example.

Let's say I have 3 portlets.

Client Account Summary
Client Receipts
Client Orders

I of course want to use these portlets for all my clients, but also generically. So if I put the Client Orders portlet on a page, I want the portlet to use this logic.

1. If no clientId is found in the request, display a complete list of all orders across all clients
2. If a clientId is found in the request, display just the orders for the client with the matching id.

I apply this same logic to all three of my portlets. Form another page, I create a portlet request that targets the "Client Account Summary" portlet to example. The page with all three is rendered of course. The parameter is "targeted" to the Client Account Summary, but because it is a PRP it is stored in a shared space that all portlets can see so the result is that by sending the parameter to ONE portlet, I can have all three affected.

So if you pass to the asset publisher a parameter "categoryId" with the id of the corresponding category then it will see it automagically. It's been a while since I had to do something like that but if I remember correctly you need to create a render request targeting the asset publisher (portletId = 101) and make sure to include a categoryId parameter with the value you want to apply. Same goes for Tag.

How could we achieve this considering we may want certain elements to fall in different places within the WCM's html structure. 


I think what I meant here is that in the AssetPublisher ADT the tags and categories are easy to reach. But if you want to control the display of the item using the WCM template (not the ADT template) then you can use the service locator in the WCM template to get the asset tags and asset categories for a journal article. It just means you will have to use the serviceLocator.find() to get a reference to the AssetCategoryLocalService and the AssetTagLocalService to fetch the data.

HTH