Sunday, May 12, 2013

Getting list size in fatwire.

A cleaner way to get the size of a list in fatwire is as below.


<ics:listget listname="sortedlist" fieldname="#numRows" output="numRowsOut"/>
<ics:getvar name="numRowsOut"/>



Wednesday, April 24, 2013

Flex Filters


What is Flex Filter?

Flex filter is a post processor for an asset.  The filter is invoked whenever the asset is saved/edited.

Some common usages of flex filter are
  • Image Processing: For instance, you may have a image of a particular resolution. You can write a flex filter, which creates images of different resolutions
  • Document: For instance, you may have an article asset, and a flex filter for it, which creates corresponding txt files or PDF files.

You can get more details on the flex filter Webcenter Sites 11g Developer guide.  The idea of this writeup is to help you guys to to implement a very simple flex filter.

For the purpose of this, we are assuming that 
  • 3 fields(firstname, lastname, username) are already created for your site
  • We have a sample asset definition with 2 fields (firstName, lastName), We will be writing a simple flex filter to have 3 field named username. The filter is append "_Username" to the value of firstName field. For instance if firstname is "John", then when you save the asset, the filter will add a value of "John_Username" to username attribute.


Implementing a flex filter 4 step process
  1. Create custom flex filter class
  2. Register flex filter
  3. Create flex filter asset
  4. Assign the flex filter asset to any other asset



Create Customer Flex Filter
  1. Create a custom class that implements AbstractFlexFilter
public class DemoFilter extends AbstractFlexFilter {
}

b.      Implement the below 2 mandatory methods
public void filterAsset(IFilterEnvironment env, String identifier, FTValList fList, IFilterableAssetInstance instance) throws AssetException;

This is the main method which will have your logic. For our example, this method, will get the value of the inputfieldname(firstname in our case),  and set the username field with the updated value.


public FTValList getLegalArguments(IFilterEnvironment arg0, String arg1) throws AssetException;

This method is invoked to populate the combobox after selecting the filter or clicking getArguments


package com.demo;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import COM.FutureTense.Interfaces.FTValList;

import com.openmarket.basic.interfaces.AssetException;
import com.openmarket.gator.flexfilters.AbstractFlexFilter;
import com.openmarket.gator.interfaces.IFilterEnvironment;
import com.openmarket.gator.interfaces.IFilterableAssetInstance;
import com.openmarket.basic.interfaces.IListBasic;

public class DemoFilter extends AbstractFlexFilter {

private String Filter_Attributes[] = {  
   "Input Attribute" 
  , "Output Attribute" 
  };

private Map<String, String> filterParameters = null;

public DemoFilter(FTValList ftvallist) {
super(ftvallist);
filterParameters = new HashMap<String, String>();
System.out.println("DemoFilter Constructor: " + ftvallist);

//If any parameter is required to be passed during filter registration, we can fetch the parameters from filter table
if ( ftvallist != null) {
System.out.println(ftvallist);
Set<String> entries = ftvallist.keySet();
for ( String key : entries ) {
filterParameters.put(key, ftvallist.getValString(key));
  }

}

@Override
public void filterAsset(IFilterEnvironment env, String identifier,
FTValList fList, IFilterableAssetInstance instance)
throws AssetException {
String value = null;
System.out.println(instance.getAssetID() + ":" + instance.getAssetID());        
        // Put some interesting information in the log. 
System.out.println(identifier+" SampleFlexFilter filterAsset :" 
+" FilterType="+env.getFilterType()
+", AttributeType="+env.getAttributeType()
+", AssetTypeName="+instance.getAssetTypeName()
+", GroupTypeName="+instance.getGroupTypeName()
);
 
//Get the attribute details... When filter asset is created, we specify the name of the inputfield & output field... In this case inputfield is set as "firstname" and output field is set as "username" 
String inputattr = getAttrID(env, fList, Filter_Attributes[0]);
System.out.println(4 + ":" + inputattr + " : " + Filter_Attributes[0]);
IListBasic ilistbasic = instance.getAttribute(inputattr);
if ( inputattr != null && ilistbasic != null && ilistbasic.hasData() ) {
try {
value = ilistbasic.getValue("value");
}
catch ( NoSuchFieldException e) {
System.out.println("SampleFlexFilter : NoSuchFieldException");
}
}
if (value == null) {
throw new AssetException("Value cannot be blank");
}
// Create the derived attribute using the attribute name and the string values 
// that were initialized above.

System.out.println("filterParameters: " + this.filterParameters);

        instance.addDerivedDataValue(identifier
        , env.getAttributeIdentifier(fList.getValString(Filter_Attributes[1]))
        , value + "_user");   

}

@Override
public FTValList getLegalArguments(IFilterEnvironment arg0, String arg1)
throws AssetException {
FTValList ftvallist = new FTValList();
ftvallist.setValString(Filter_Attributes[0], Filter_Attributes[0]);
ftvallist.setValString(Filter_Attributes[1], Filter_Attributes[1]);
return ftvallist;
}



}



Register flex filter

Once you have your flex filter implementation is in place, the next step is to create the jar and put it in /cs/web-inf/lib folder and then register the filter in your sites. To register the filter, you may use sites explorer and add a new row to the filter table as shown below.








Once you complete this step, make sure to restart your wc sites.

Create flex filter asset
On successful registration of the flex filter asset, you create a flex filter asset using WC Sites admin console for your site. For this create a new filter, and chose the filter you created from the dropdown and click on getArguments.

As you can see, this retrieves the arguments that is required for this filter. As you may have noted that "getArguments" invokes getLegalArguments method from the flex filter class that you created.

There are 2 parameters which are required for this filter. Input Attribute (which is firstname) and Output attribute(which is username). Both firstname & lastname are attributes that should have been created in your site.




Assign the flex filter asset to any other asset

Assign the filter to a asset definition. In this example, I have created a asset defnation named "Sample Asset". This is 2 attributes (Firstname & lastname), apart from this I have assigned the filter that I have created.




Test your filter
Create a new sample asset using contributor interface. Give all the required values

Name: Demo Content
firstName: John
LastName: Corner

Save the attribute.

Open the asset in read only mode, You should be able to see username field with value "John_Username".





The code for this example is also being attached with this tutorial. Please feel free to add your comments for any questions.

The jar that may be required with this project would be 
  1. gator.jar
  2. cs.jar
  3. xcelarate.jar
  4. basic.jar
  5. framework.jar
  6. cs-cache-1.2.2.jar







Wednesday, April 3, 2013

OSB SOA Direct

This sample illustrates the implementation of asynchronous communication between two BPEL processes, with an OSB in between. Though this communication can be done using SOAP messaging, but for the purpose of this sample, I will be using new SOA-Direct transport which is available in 11g. It should be noted that the SOA-Direct transport is used in cases where, it is required to propagate transaction contexts between OSB and SOA Suite.

Please download the attached PDF for the step by step tutorial.

How do I render attribute from a page on a template

The other day I was trying to use the below code to get page attributes on template

<asset:get name="theCurrentPage" field="customField" output="assetname"/>
<ics:getvar name="assetname"/>

Unfortunately, it did not work,

Then the other way to do the same stuff which I was trying to achieve was this

<assetset:setasset name="pAsset" type='<%=ics.GetVar("c")%>' id='<%=ics.GetVar("cid")%>'/>

<assetset:getattributevalues name="pAsset" typename="PageAttribute" listvarname="pageAList" attribute="pagebody" />
<ics:listget fieldname="value" listname="pageAList" output="theCurrentAssetCopy"/>

which worked.

So whats the difference in the above 2 approaches.

The approach one is used/works only for system generated fields like name. The 2nd approach works for custom defined fields too.