/* ======================================================================================= "This sample program is provided AS IS and may be used, executed, copied and modified without royalty payment by customer (a) for its own instruction and study, (b) in order to develop applications designed to run with an IBM WebSphere product, either for customer's own internal use or for redistribution by customer, as part of such an application, in customer's own products." Product 5655-FLW, (C) COPYRIGHT International Business Machines Corp., 2006, 2010 All Rights Reserved * Licensed Materials - Property of IBM ======================================================================================= */ package bpc.samples.command; import java.util.Iterator; import java.util.List; import java.util.logging.Logger; import bpc.samples.CustomException; import bpc.samples.ServiceFactory; import bpc.samples.bean.CustomTaskInstanceBean; import bpc.samples.handler.CustomTaskMessageHandler; import com.ibm.bpc.clientcore.ClientException; import com.ibm.bpc.clientcore.Command; import com.ibm.bpc.clientcore.MessageWrapper; import com.ibm.task.api.ClientObjectWrapper; import com.ibm.task.api.HumanTaskManagerService; /** * SaveTaskCommand will complete task instances provided in the execute method * through the HumanTaskManagerService.save(..) method. Please refer to the * Human Task Manager API for more details. * *

Any output message must be provided by the containing object referenced in the * context attribute of the command tag, e.g a handler.

* *

Any error during the execution will be wrapped in a CustomException. Add more * error handling here if wanted.

*/ public class SaveTaskCommand implements Command { static Logger logger = Logger.getLogger( "CustomClient" ) ; CustomTaskMessageHandler messageHandler = null; /**

Executes the command on the selected objects.

*

Usually the selected items are provided by an ItemProvider

* @see com.ibm.bpc.clientcore.Command#execute(java.util.List) */ public String execute(List selectedObjects) throws ClientException { try { HumanTaskManagerService htm = ServiceFactory.getInstance().getHumanTaskManagerService() ; for( Iterator iter = selectedObjects.iterator(); iter.hasNext(); ) { Object obj = iter.next(); if( obj instanceof CustomTaskInstanceBean ) { CustomTaskInstanceBean bean = (CustomTaskInstanceBean) obj ; MessageWrapper outputMessage = messageHandler.getOutputMessage(); try { if (outputMessage != null && outputMessage.getMessage() != null) { htm.setOutputMessage(bean.getID(), new ClientObjectWrapper(outputMessage.getMessage())); } else { throw new CustomException("No output message."); } } catch( Exception e) { throw new CustomException(e.getMessage()) ; } } } } catch( Exception e ) { if(e instanceof CustomException) throw (CustomException)e;//do not handle custom exceptions // The command has encountered an error while accessing the HTM service. // Therefore return the outcome "error". // logger.info( "SaveTaskCommand - general xcpt: " + e ) ; return "error" ; } // Returns the outcome for the command. In this case the command indicates it has no special outcome // return null; } /* (non-Javadoc) * @see com.ibm.bpc.clientcore.Command#isMultiSelectEnabled() */ public boolean isMultiSelectEnabled() { return false; } /* (non-Javadoc) * @see com.ibm.bpc.clientcore.Command#isApplicable(java.util.List) */ public boolean[] isApplicable(List itemsOnList) { return null; } /* (non-Javadoc) * @see com.ibm.bpc.clientcore.Command#setContext(java.lang.Object) */ public void setContext(Object context) { logger.info("setContext: " + context); if(context!= null && context instanceof CustomTaskMessageHandler) { messageHandler = (CustomTaskMessageHandler)context; } } }