OneData 10.7 | Managing Master Data with webMethods OneData | Developing for webMethods OneData | OneData Hooks | How are hooks used in OneData? | Hook Types | iHooks Sample Code | Java RMI
 
Java RMI
iHook Required Section
This is required at the beginning of any Java iHook execute() method.
HookOutput hookOutput = new
HookOutput();hookOutput.setInvocationNumber(hookInput.getInvocationNumber());
hookOutput.setOriginalRowset(hookInput.getOriginalRowset());
Hello World in iHooks
import com.datafoundations.onedata.hook.OnedataHook;
import com.datafoundations.onedata.hook.HookOutput;
import com.datafoundations.onedata.hook.HookInput;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
 
public class HelloWorldHook extends UnicastRemoteObject
implements OnedataHook{
public HelloWorldHook() throws RemoteException {
  super(); }
 
public void init() throws RemoteException { }
public void commit() throws RemoteException { }
public void rollback() throws RemoteException { }
public void close() throws RemoteException { }
public HookOutput execute(HookInput hookInput) throws RemoteException {
 HookOutput hookOutput = new HookOutput();
 hookOutput.setInvocationNumber(hookInput.getInvocationNumber());
 hookOutput.setOriginalRowset(hookInput.getOriginalRowset());
 hookOutput.setMessage("Hello World!");
 return hookOutput; }
public void setSavepoint(String string) { }
public void releaseSavepoint(String string) { }
public void rollback(String string) { }}
Creating a Showable Rowset from an Existing Object
if (hookInput.getInvocationNumber() == 0) { ActionRowset objActionRow =
hookInput.getOriginalRowset();
 if (objActionRow != null) {
  List list_Rows = objActionRow.getRows();
  ShowableRowset objShowable = new ShowableRowset();
  objShowable.setRows(hookInput.getOriginalRowset().getRows());
  objShowable.setObjectName(hookInput.getOriginalRowset()
 .getObjectName());
 objShowable.setObjectType(hookInput.getOriginalRowset()
 .getObjectType());
 objShowable.setSelectionType(1);
 objShowable.setSelectionTypeDesc("Single");
 hookOutput.setShowRowset(objShowable);
 Question question = new Question();
 test_Question.setText ("Select a row to associate and click on
'Associate' or click on 'Create New' to create a new row'");
 Answer answer1 = new Answer();
 answer1.setId(1);
 answer1.setText("Associate");
 answer1.setOrder(1);
 Answer answer2 = new Answer();
 answer2.setId(2);
 answer2.setText("Create New");
 answer2.setOrder(2);
 List answers = new ArrayList();
 answers.add(answer1);
 answers.add(answer2 );
 auestion.setAnswers(answers);
 hookOutput.setQuestion(question);
 }
}
Creating a Showable Rowset for a Custom Object
 List rowList = new ArrayList();
 Row objRow1 = new Row();
 List list_col1 = new ArrayList();
 Column objCOL1 = new Column();
 objCOL1.setName("ACC_CD");
 objCOL1.setValue("100");
 list_col1.add(objCOL1);
 Column objCOL2 = new Column();
 objCOL2.setName("ACC_NM");
 objCOL2.setValue("AC100");
 list_col1.add(objCOL2);
 
 objRow1.setColumns(list_col1);
 rowList.add(objRow1);
 objRow1 = new Row();
 list_col1 = new ArrayList();
 objCOL1 = new Column();
 objCOL1.setName("ACC_CD");
 objCOL1.setValue("200");
 list_col1.add(objCOL1);
 
 objCOL2 = new Column(); 
 objCOL2.setName("ACC_NM");
 objCOL2.setValue("AC200");
 list_col1.add(objCOL2);
 objRow1.setColumns(list_col1);
 rowList.add(objRow1);
  
 ShowableRowset objShowable = new ShowableRowset();
 objShowable.setRows(rowList);
 objShowable.setObjectName("TEST");
 objShowable.setObjectType(4);
 objShowable.setSelectionType(1);
 objShowable.setSelectionTypeDesc("Single");
 hookOutput.setShowRowset(objShowable);
Conceptual Object DML
The following code inserts a record to Brand object in Product->Brand->Vendor hierarchy. The insertion is done with conceptual object context.
if(hookInput.getInvocationNumber() == 0){  
 Question question = new Question();
 question.setText("Enter Data");
 Answer answer1 = new Answer();
 answer1.setId(1);
 answer1.setText("Submit");
 answer1.setOrder(0);
 List answerList = new ArrayList();
 answerList.add(answer1);
 question.setAnswers(answerList);
 hookOutput.setQuestion(question);
 Forms forms = new Forms();
 Form form1 = new Form();
 form1.setCardinality(1);
 form1.setObjectName("Brand ");
 forms.addForm(form1); 
 hookOutput.setForms(forms);
 }
 
else{
 Forms forms = hookInput.getForms();
 List list_forms = forms.getForms();
 Iterator iter = list_forms.iterator();
 Actions objActions = new Actions();
 int order = 0;
   
while(iter.hasNext()){
 Form form1 = (Form)iter.next();
 ActionRowset objActionRowset = new ActionRowset();
 objActionRowset.setActionType(
 objActionRowset.ACTION_TYPE_INSERT);
 objActionRowset.setRows(form1.getRowset().getRows());
 objActionRowset.setObjectName(form1.getObjectName());
 objActionRowset.setObjectType(2);
 objActionRowset.setConceptualObjectName("Product_Catalog");
 objActionRowset.setOrder(1);
 objActions.addAction(objActionRowset);
  }
 hookOutput.setActions(objActions);
 hookOutput.setMessage("Data inserted successfully.");
 }
Form
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.datafoundations.onedata.hook.ActionRowset;
import com.datafoundations.onedata.hook.Actions;
import com.datafoundations.onedata.hook.Answer;
import com.datafoundations.onedata.hook.Form;
import com.datafoundations.onedata.hook.Forms;
import com.datafoundations.onedata.hook.HookInput;
import com.datafoundations.onedata.hook.HookOutput;
import com.datafoundations.onedata.hook.OnedataHook;
import com.datafoundations.onedata.hook.Question;
 
public class SampleFormHook extends UnicastRemoteObject
implements OnedataHook {
public SampleFormHook() throws RemoteException { super(); }
 
public void init() throws RemoteException { }
public void commit() throws RemoteException { }
public void rollback() throws RemoteException { }
public void close() throws RemoteException { }
public HookOutput execute(HookInput hookInput)
throws RemoteException {
 HookOutput hookOutput = new HookOutput();
 hookOutput.setInvocationNumber(hookInput.getInvocationNumber());
 hookOutput.setOriginalRowset(hookInput.getOriginalRowset());
if(hookInput.getInvocationNumber() == 0){
 Question question = new Question();
 question.setText("Enter Data");
 Answer answer1 = new Answer();
 answer1.setId(1);
 answer1.setText("Submit");
 answer1.setOrder(0);
 List answerList = new ArrayList();
 answerList.add(answer1);
 question.setAnswers(answerList);
 hookOutput.setQuestion(question);
 Forms forms = new Forms();
 Form form1 = new Form();
 form1.setCardinality(1);
 Form1.setObjectName("Data Object");
 forms.addForm(form1);
 hookOutput.setForms(forms);
}
else{
 Forms forms = hookInput.getForms();
 List formList = forms.getForms();
 Actions actions = new Actions();
 
 for (Iterator it = formList.iterator();
  it.hasNext();) {
  Form form = (Form) it.next();
  ActionRowset insertRowSet = new ActionRowset();
  insertRowSet.setObjectName(form.getObjectName());
  insertRowSet.setActionType(ActionRowset.ACTION_TYPE_INSERT);
  insertRowSet.setActionTypeDesc("INSERT");
  insertRowSet.setObjectType(form.getObjectType());
  insertRowSet.setRows(form.getRowset().getRows());
  actions.addAction(insertRowSet);
 }
 hookOutput.setActions(actions);
 hookOutput.setMessage("Data inserted successfully.");
 }
 return hookOutput;
}
public void setSavepoint(String string) { }
public void releaseSavepoint(String string) { }
public void rollback(String string) {
}}