Sample scripting code
The following sample scripting API code shows the usage of starting Java™ API extension points from scripting approach.
Script that is used in this case is the Pre-processing Script of
the catalog.
var logger = getLogger("default");
item.setCtgItemAttrib("Default Hierarchy Primary Spec/Name", "Item attribute value set from script");
logger.loggerInfo(item.getCtgItemAttrib("Default Hierarchy Primary Spec/Name"));
logger.loggerInfo("Java API extension point being invoked to update the same item attribute…");
runJavaApiExtensionPoint("japi:///uploaded_java_classes:packaged_class_sample.com.ibm.pim.PrePostProcessingFunctionImpl.class");
logger.loggerInfo(item.getEntryAttrib("Default Hierarchy Primary Spec/Name"));.
Java API extension point
implementation class:
public class PrePostProcessingFunctionImpl implements PrePostProcessingFunction
{
Context ctx = null;
public PrePostProcessingFunctionImpl() throws Exception {
ctx = PIMContextFactory.getCurrentContext();
}
public void prePostProcessing
(com.ibm.pim.extensionpoints.ItemPrePostProcessingFunctionArguments arg0)
{
Item item = arg0.getItem();
item.setAttributeValue("Default Hierarchy Primary Spec/Name", "Item attribute value set from Java API extension point");
}
public void prePostProcessing (com.ibm.pim.extensionpoints.CategoryPrePostProcessingFunctionArguments arg0)
{
}
public void prePostProcessing
(com.ibm.pim.extensionpoints.CollaborationItemPrePostProcessingFunctionArguments arg0)
{
}
public void prePostProcessing (com.ibm.pim.extensionpoints.CollaborationCategoryPrePostProcessingFunctionArguments arg0)
{
}
}
When the item is saved, the combination of script and Java API extension point produces the following
output (as seen in the logs). The value of the attribute reflects
the value set from the Java API
extension point:
- Item attribute value set from script
- Java API extension point that is started to update the same item attribute…
- Item attribute value set from Java API extension point