Translate

Showing posts with label flex. Show all posts
Showing posts with label flex. Show all posts

Sunday, December 8, 2013

Example 5: Searching Assets

Searching assets is very basic functionality required in various online sites whether be a content search, tagged-content search or even media asset search. Content (Assets) can be any assets like product assets, article assets, etc.

Following instructions are for searching FLEX assets using searchstate tags.

GENERAL STEPS TO FOLLOW:
  1. For using searchstate tag, add the searchstate taglib at starting of your JSP/XML. 
  2. Create an empty searchstate object (using searchstate:create tag), which can contain 2 operations: "and" & "or".
  3. Add constraint to the searchstate i.e. adding a condition for restricting search based on single attribute or another searchstate (also called as nested constraint). For adding constraint, use anyone of the following tag as required: searchstate:addlikeconstraint, searchstate:addnestedconstraint, searchstate:addrangeconstraint, searchstate:addsimpleconstraint, searchstate:addsimplestandardconstraint, searchstate:addstandardconstraint, etc. according to you requirement. 
  4. Set the searchstate (Using assetset:setsearchedassets tag)
  5. Get the required attribute values (Using assetset:getmultiplevalues or assetset:getattributevalues)
  6. Then list through the result (Using ics:listloop and ics:listget tag)
CASE 1: A simple case: Finding attributes of a flex asset to search against value of one attribute

<searchstate:create name="ss" />
<searchstate:addsimplelikeconstraint name="ss" attribute="cat2" value="Watt%"/>
<assetset:setsearchedassets name="as" constraint="ss" assettypes="Products"/>
<assetset:getattributevalues name="as" attribute="productdesc" listvarname="resultlist"/>
<ics:listloop listname="resultlist">
<ics:listget listname="resultlist" fieldname="value"/><br/>
</ics:listloop>


Apart from using searchstate tags, there are other tags which can be used for searching assets (flex or basic or table data) which are described briefly below:
  1. ics:sql - It executes inline SQL statement. You can write a SQL query and search against tablename which should be registered SYTEMINFO table.
  2. ics:callsql - It retrieves and executes a SQL query stored in the SYSTEMSQL table
  3. ics:sqlexp - This tag is used only to build where clause based on given set of parameters. It does not execute any statement. It passes a column name and an expression that contains the column name to be used as the left side in the where clause.
  4. ics:selectto - It executes a simple query from a table, which is equivalent to run a simple SQL query like select * from tablename
  5. asset:search - It locates a list of asset primary table rows based on the asset type and a set of search criteria. Criteria can be defined which can narrow your search. Not recommended for searching FLEX assets.
  6. asset:list - This tag queries the database and retrieve a list of assets that meets the specified criteria. It creates a list of assets of one type. Specific criteria could be against field/value of certain tablename, passing argument in field name/value pairs, etc. to restrict the list.
Detailed explanation is provided in Tag Reference/Developer guide.

INFO:
  • The above case is very simple case provided by tag reference itself.
  • Check the examples and details of every searchstate tag in TagReference and Developer Guide
  • Following is the list which shows which searchstate tags to use for what case:
    • searchstate:addsimplestandardconstraint - Adds an attribute name/single value constraint to an existing searchstate object.
    • searchstate:addlikeconstraint - Adds a list of attribute like name/value constraints into a new or existing searchstate object.
    • searchstate:addnestedconstraint - Nests a searchstate as a constraint within another searchstate.
    • searchstate:addrangeconstraint - Adds a range constraint to a searchstate on a specific attribute.
    • searchstate:addsimplelikeconstraint - Adds an attribute like name/value constraint into a new or existing searchstate object.
    • searchstate:addstandardconstraint - Adds a list of attribute name/value constraints into a new or existing searchstate object.

----------------------------------------------------
SUGGESTIONS/COMMENTS ARE INVITED
----------------------------------------------------


Saturday, November 16, 2013

Example 4: Rendering Blobs

This post illustrates how to render blobs (BINARY LARGE OBJECTS)

GENERAL STEPS TO FOLLOW:
  1. Load the flex asset (using assetset tags) 
  2. Get the value of imagefile attribute in list (using assetset:getattributevalues tag) 
  3. Retrieve information using blobservice tags 
CASE 1: If we are using normal upload functionality for images while creating asset and if you know asset type(c) and asset id (cid). This is used to render image asset as shown below:

<ics:if condition='<%=ics.GetVar("c")!=null && ics.GetVar("cid")!=null%>'><ics:then>
<!-- Use assetset tags to load FLEX ASSETS. CheckOut tagReference for further details. -->
<assetset:setasset name='Media' type='<%=ics.GetVar("c") %>' id='<%=ics.GetVar("cid")%>' />
<assetset:getattributevalues name='Media' immediateonly='true' typename='FlexAssetAttributeType' attribute='ImageFile' listvarname='mediaImageList' />
                 
<!-- 
BLOB attributes are to be rendered differently and uses BlobServer servlet.
Don't forget to include tld in your template/CSElement for BlobService -> taglib prefix="blobservice" uri="futuretense_cs/blobservice.tld"
 -->                  
<ics:if condition='<%=ics.GetList("mediaImageList")!=null && ics.GetList("mediaImageList").hasData()%>'>
<ics:then>        
      <ics:listloop listname='mediaImageList'>
<ics:listget listname='mediaImageList' fieldname='value' output='media_image' />
      
 <blobservice:gettablename varname="uTabname"/>
 <blobservice:getidcolumn varname="idColumn"/>
 <blobservice:geturlcolumn varname="uColumn"/>
 
 <render:getbloburl 
 blobtable='<%=ics.GetVar("uTabname")%>' 
 blobcol='<%=ics.GetVar("uColumn")%>'
 blobheader="image/jpeg"
 blobkey='<%=ics.GetVar("idColumn")%>'
 blobwhere='<%=ics.GetVar("media_image")%>' 
 outstr="imageURL"/> 
    </ics:listloop>
   
<img  src='<%=ics.GetVar("imageURL")%>' >
  
      </ics:then></ics:if>   
          
</ics:then></ics:if>

INFO:
  • Media is just a name used in Assetset tag
  • This code in template should be created once and called from various template/cselement as required by passing c and cid to render blobs.
  •  FlexAssetAttributeType is attribute type (For eg: It would be something like Media_A if you have created flex family using Media_* where *=CD, C, PD, P, A and F)
  • Always do a null check and use log messages to capture errors.

CASE 2: This case may be trickier. If you have stored your images under some folder say "image" in Shared directory, then you can obtain url value of blob, we can use blobservice.readdata as followed and render the image:

<ics:if condition='<%=ics.GetVar("c")!=null && ics.GetVar("cid")!=null%>'><ics:then>
<!-- Use assetset tags to load FLEX ASSETS. CheckOut tagReference for further details. -->
<assetset:setasset name='Media' type='<%=ics.GetVar("c") %>' id='<%=ics.GetVar("cid")%>' />
<assetset:getattributevalues name='Media' immediateonly='true' typename='FlexAssetAttributeType' attribute='ImageFile' listvarname='mediaList' />
<%if (ics.GetList("mediaList") != null && ics.GetList("mediaList").hasData()) { %>
<ics:listget listname='mediaList' fieldname='value' output='mediaFile' />
<%} %>
<%if (ics.GetVar("mediaFile") != null ) { %>
<blobservice:readdata id='<%=ics.GetVar("mediaFile") %>' listvarname="mediaInfo"/>
<%} %>
<% if (ics.GetList("mediaInfo") != null && ics.GetList("mediaInfo").hasData()) 
{
ics.SetVar("mediaURL", "/media/" + ics.GetList("mediaInfo").getValue("urldata").replace("\\", "/"));
}
%>

<img src='<%= ics.GetVar("mediaURL") %>' >

INFO:
  • Create one folder "media" in Shared directory and place all your images.
  • Add this property in server.xml if you are using apache tomcat which is located in conf directory:     <Context path="/media" docBase="<installed location of fatwire>/Shared/ccurl" reloadable="true" debug="1" crossContext="true"/>
----------------------------------------------------
SUGGESTIONS/COMMENTS ARE INVITED
----------------------------------------------------

Saturday, July 6, 2013

Example 2: Rendering Flex Asset

This example illustrates how to render FLEX ASSET in different situations. Although there are many examples available in developer guide, here I am providing general steps and some scenarios.

GENERAL STEPS TO FOLLOW:
  1. Use assetset:setasset tag to load the flex asset (obviously we should know asset type(c) and asset id(cid)).
  2. Use assetset:getmultiplevalues or assetset:getattributevalues to retrieve information after the flex asset is loaded.
  3. Fetch attributes (looping through list using ics:listloop tag) In the following cases it is assumed that we know asset id and asset type. (Searchstates to retrieve flex assets would be discussed in different tutorial)
CASE 1: Retrieving flex attributes using assetset:getmultiplevalues tag (for eg: retrieving price and article name of an article asset.)

<assetset:setasset name="myassetset" type='<%=ics.GetVar("c")%>' id='<%=ics.GetVar("cid")%>' />
<assetset:getmultiplevalues name="myassetset" prefix="ArticleList" immediateonly="false"> <assetset:sortlistentry attributetypename="Article_A" attributename="Price" direction="ascending"/>
<assetset:sortlistentry attributetypename="Article_A" attributename="ArticleName"/>
<assetset:getmultiplevalues/>

<!-- Display results -->
Article Price List: <br/>
<ics:listloop listname="ArticleList:Price">
     <ics:listget listname="ArticleList:Price" fieldname="value" /><br/>
</ics:listloop>
Article Name List:<br/>
<ics:listloop listname="ArticleList:ArticleName">
     <ics:listget listname="ArticleList:ArticleName" fieldname="value" /><br/>
</ics:listloop>


INFO:
  • Using assetset:setasset tag is basic step to do for loading the flex asset.
  • Use assetset:getmultiplevalues to retrieve all the attributes at once, its like fetching all the results in one go. But there are limitations on this tag that it can not be used to retrieve attribute of type - "text", you have to use assetset:getattributevalues tag described below in case 2.
  • immediateonly - using this can be useful in some scenarios like if you want the value of attribute of the parent asset. For eg: Suppose I have hierarchy like Cricket is my parent asset(which contains "parentname" as one attribute) and ODI is child asset(which contains some attributes.). If I want the value of the attribute - "parentname", i don't need to load the parent asset i.e. Cricket in our case, to get the "parentname" attribute value as it is inherited in child assets too. So to get the parent attributes we set immediateonly="false" in assetset:getattributevalues tag.
  • direction - ascending or descending - Sorts assets. This scenarios is helpful when you have list of flex assets and then looping through that list and then trying to fetch the attributes which you require and want to sort them by a particular attribute.
  • This tag is used when you want all the attributes of flex assets in one go except the attribute of type - "text"CASE 2: Retrieving flex attributes using assetset:getattributevalues
CASE 2: Retrieving flex attributes using assetset:getattributevalues tag (for eg: retrieving price and article name of an article asset.)

<assetset:setasset name="myassetset" type='<%=ics.GetVar("c")%>' id='<%=ics.GetVar("cid")%>' />
<assetset:getattributevalues ordering="descending" name="myassetset" typename="Article_A" attribute="Price" immediateonly="true" listvarname="pricelist"/>
<assetset:getattributevalues name="myassetset" typename="Article_A" attribute="ArticleName" listvarname="articlenamelist"/>

<!-- Display results -->
Article Price List: <br/>
<ics:listloop listname="pricelist">
     <ics:listget listname="pricelist" fieldname="value" /><br/>
</ics:listloop>
Article Name List:<br/>
<ics:listloop listname="articlenamelist">
     <ics:listget listname="articlenamelist" fieldname="value" /><br/>
</ics:listloop>


INFO:
  • This tag generates one or more database queries, in order to retrieve the value of the attributes specified
  • Similar to case 1, we can get parent attributes too and can have ordering too.
----------------------------------------------------
SUGGESTIONS/COMMENTS ARE INVITED
----------------------------------------------------