I wanted to play around with the new technology stack available with the Hana Cloud Platform. This is a simple example of how we can use the platform to add additional features to some of our cloud products. Although here I work with Business ByDesign, I believe the same can be done for C4C as well.
In this document I want to describe my attempts to enhance the functionality of Business ByDesign UI using a web application that will allow me to display data from a custom business object and change the person responsible via drag and drop. Essentially all I am doing is consuming a custom web service I have created.
My UI5 application will request my Servlet to consume a custom web service for my own business object. The business objects purpose is to simulate a Task by having a unique id, a name and a responsible business partner, this work center I called JohnTask2.
The JohnTask2, called because I have a similar business object in the same system where I was testing something else, is a simple BO with an association to Business Partner. This allows me to have a person responsible for each task. I will give you the code to create the Bo below but you will need to create your own web service for this object, include a query and an update.
To consume the standard Business Partner web service, make sure you are using the correct user.
Here is my BO Definition and the event-AfterModify that will display a formatted name after we select a Business Partner from the ovs.
import AP.Common.GDT as apCommonGDT; businessobject JohnTest2 { // Root node must not be specified, it is created implicitly // // Add elements here. // // To declare an element as alternative key, use the [AlternativeKey] annotation. // Please note: // - An alternative key of type UUID exists implicitly for each node, enabling the node // to be used as an association target. // - The QueryByElements query is created automatically for each node. // - Code completion is available with CTRL + SPACE. [AlternativeKey]element id:ID; [Label("Task Name")]element taskName:LANGUAGEINDEPENDENT_EXTENDED_Name; [Label ("Responcible")]element custom:BusinessPartnerID; [Label ("Responcible Name")]element ResponceName1:LANGUAGEINDEPENDENT_EXTENDED_Name; }
import ABSL; import AP.FO.BusinessPartner.Global; if(!this.custom.IsInitial()){ var BusinessR=BusinessPartner.Retrieve(this.custom); this.ResponceName1=BusinessR.CurrentCommon.BusinessPartnerFormattedName; }
Image may be NSFW.
Clik here to view.
Prerequisites:
You must have your Business Object and web services set up in PDI.
You must have WSDL.
You must download the Axis 2 library’s.
Step 1-Create Project
Create a Dynamic Web Project.
Select the Hana Runtime and Modify your configuration to have SAPUI5 and Javascript.
Select next and finish.
Image may be NSFW.
Clik here to view.Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.
Step 2-Create UI5 views
Create a new folder in the WebContent folder called bydhcp. Of course you can name this folder what you wish in another sceanrio but my code below refers to this name.
Right click on bydhcp and create a SAPUI5 view called CustomTask.
Do the same again and call it BusinessPartner.
Image may be NSFW.
Clik here to view.
After you will have something like below
Image may be NSFW.
Clik here to view.
Create an index.html file in the WebContent folder and add the code below to each file
Add in this code to your CustomTask controller
sap.ui.controller("bydhcp.CustomTask", { // This sets the model data for the table getJohnQueryTask : function() { var xmlHttp = new XMLHttpRequest(); var xmlDOM; xmlHttp.open("GET", "/ByDIntegration/QueryJohnTask", false); xmlHttp.send(); xmlDOM = xmlHttp.responseText; var objectModel = JSON.parse(xmlDOM); return objectModel; }, checkDragEnter : function() { console.log("Check Drag enter"); // Reset the element where a dragEnter is true var parent = this.parentElement; var rowsForReset = parent.getElementsByClassName("sapUiTableTr"); for (var k = 0; k < rowsForReset.length; k++) { rowsForReset[k].setAttribute("dragEnter", "false"); } // Set value for new dragenter this.setAttribute("dragEnter", "true"); var childern = this.children; var childDiv = childern[2].getElementsByClassName("sapUiTvAlignLeft"); var innerDiv = childDiv[0]; var dropElement = innerDiv.getAttribute("title"); this.setAttribute("lastDragged", dropElement); }, checkDragOver : function() { //Set dragOver true this.setAttribute("dragOver", "true"); }, onAfterRendering : function() { // var inRow = false; console.log("on Render"); var myView = this.getView(); var myTable = myView.getDomRef(); var myRows = myTable.getElementsByClassName("sapUiTableTr"); // Loop ,make rows draggable and set events for (var i = 0; i < myRows.length - 1; i++) { myRows[i].setAttribute("dragEnter", "false"); myRows[i].ondragenter = this.checkDragEnter; myRows[i].ondragleave = this.checkDragLeaver; myRows[i].setAttribute("dragOver", "false"); myRows[i].ondragover = this.checkDragOver; } }, });
Here is an example of my CustomTask.view
sap.ui.jsview("bydhcp.CustomTask", { getControllerName : function() { return "bydhcp.CustomTask"; }, createContent : function(oController) { // Define my table var oTable = new sap.ui.table.Table("table"); oTable.setWidth("600px"); oTable.setTitle("John Task Table"); var oColumnUUID = new sap.ui.table.Column("uuid"); oColumnUUID.setTemplate(new sap.ui.commons.TextView().bindProperty("text", "uuid")); oColumnUUID.setLabel("UUID"); // Create and bind the rows var oColumnId = new sap.ui.table.Column("id"); oColumnId.setLabel("ID"); oColumnId.setTemplate(new sap.ui.commons.TextView().bindProperty("text", "id")); var oColumnTaskName = new sap.ui.table.Column("taskame"); oColumnTaskName.setLabel("Task Name"); oColumnTaskName.setTemplate(new sap.ui.commons.TextView().bindProperty( "text", "taskname")); var oColumnRe = new sap.ui.table.Column("re"); oColumnRe.setLabel("resp"); oColumnRe.setTemplate(new sap.ui.commons.TextView().bindProperty("text", "Resp")); oTable.addColumn(oColumnUUID); oTable.addColumn(oColumnId); oTable.addColumn(oColumnTaskName); oTable.addColumn(oColumnRe); oTable.onclick(oController); // Create Data // Bind the data to the response from the servlet GlobaloModel.setData({ modelData : oController.getJohnQueryTask() }); oTable.setModel(GlobaloModel); oTable.bindRows("/modelData"); return oTable; } });
Add this code to BusinessPartner.view
sap.ui.jsview("bydhcp.BusinessPartner", { getControllerName : function() { return "bydhcp.BusinessPartner"; }, createContent : function(oController) { var oTable = new sap.ui.table.Table("table1"); oTable.setWidth("400px"); oTable.setTitle("Business Partner Table"); var oRowUUID = new sap.ui.table.Column("id1"); oRowUUID.setTemplate(new sap.ui.commons.TextView().bindProperty("text", "id")); oRowUUID.setLabel("Business Partner Id"); oTable.addColumn(oRowUUID); var oRowBP = new sap.ui.table.Column("bpName"); oRowBP.setTemplate(new sap.ui.commons.TextView().bindProperty("text", "Name")); oRowBP.setLabel("Business Partner Name"); oTable.addColumn(oRowBP); // Create a model and bind the table rows to this model var oModel = new sap.ui.model.json.JSONModel(); oModel.setData({ modelData : oController.getQueryBP() }); oTable.setModel(oModel); oTable.bindRows("/modelData"); return oTable; } });
Add this code to BusinessPartner.controller
sap.ui.controller("bydhcp.BusinessPartner", { getQueryBP : function() { var xmlHttp = new XMLHttpRequest(); var xmlDOM; xmlHttp.open("GET", "/ByDIntegration/QueryBusinessPartner", false); xmlHttp.send(); xmlDOM = xmlHttp.responseText; var objectModel = JSON.parse(xmlDOM); return objectModel; }, onAfterRendering : function() { }, //Update event -Set up request parameters in a Get style updateByD : function(jtid, bpid) { var url = "/ByDIntegration/UpdateJohnTask?id="; url = url.concat(jtid + "&bpid="); url = url.concat(bpid); // url.toString() var xmlHttp = new XMLHttpRequest(); var xmlDOM; xmlHttp.open("GET", url.toString(), false); xmlHttp.send(); //Dont need this but you can return it if you like xmlDOM = xmlHttp.responseText; var newTableModel = view.oController.getJohnQueryTask(); GlobaloModel.setData({ modelData : newTableModel }); }, checkInDrag : function() { this.setAttribute("Drag", "true"); }, onAfterRendering : function() { console.log("on Render"); var myView = this.getView(); var myTable = myView.getDomRef(); var myRows = myTable.getElementsByClassName("sapUiTableTr"); // Loop and make draggable for (var i = 0; i < myRows.length - 1; i++) { myRows[i].draggable = true; myRows[i].ondrag = this.checkInDrag; myRows[i].ondragend = this.checkDrop; // Giving the row an attribute to see if it is in a drag myRows[i].setAttribute("Drag", "false"); } }, checkDrop : function() { console.log("Dropping is complete"); var table = view1.getDomRef(); var tableRow = table.getElementsByClassName("sapUiTableTr"); for (var i = 0; i < tableRow.length; i++) { if (tableRow[i].getAttribute("drag") == "true") { // Grab table from view var table = view.getDomRef(); var viewTableRows = table .getElementsByClassName("sapUiTableTr"); for (var c = 0; c < viewTableRows.length; c++) { var viewRow = viewTableRows[c]; if (viewRow.getAttribute("dragEnter") == "true") { // Get BP ID var dragRow = tableRow[i]; var dragCell = dragRow .getElementsByClassName("sapUiTableTdFirst"); var draCellElAr = dragCell[0] .getElementsByClassName("sapUiTableCell"); var draCellEl = draCellElAr[0]; var dragCellValue = draCellEl.children[0]; var bpId = dragCellValue.getAttribute("title"); // viewRow.getAtt has the id console.log("WEB SERVICE: +" + bpId + " dragged into " + viewRow.getAttribute("lastDragged")); //Call update event view1.oController.updateByD(viewRow .getAttribute("lastDragged"), bpId); } } } } this.setAttribute("Drag", "false"); }, });
Create an index.html and add this code
<!DOCTYPE HTML><html><head><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta http-equiv='Content-Type' content='text/html;charset=UTF-8' /><script src="resources/sap-ui-core.js" id="sap-ui-bootstrap" data-sap-ui-libs="sap.ui.commons, sap.ui.ux3, sap.ui.table" data-sap-ui-theme="sap_bluecrystal"></script><!-- add sap.ui.table,sap.ui.ux3 and/or other libraries to 'data-sap-ui-libs' if required --><script> //Global model var GlobaloModel = new sap.ui.model.json.JSONModel(); //Set content sap.ui.localResources("bydhcp"); var view = sap.ui.view({ id : "idCustomTask1", viewName : "bydhcp.CustomTask", type : sap.ui.core.mvc.ViewType.JS }); view.placeAt("content"); var view1 = sap.ui.view({ id : "idBusinessPartner1", viewName : "bydhcp.BusinessPartner", type : sap.ui.core.mvc.ViewType.JS }); view1.placeAt("content1");</script></head><body class="sapUiBody" role="application"> <table> <tr> <td> <div id="content"> </td> </div> <td><div id="content1"></div></td> </tr> </table></body></html>
Step 3-Axis set up
Create a new folder in your WebContent folder called resource and add your WSDL for the JohnTask2 webservice and the standard webservice to query BusinessPartners.
Image may be NSFW.
Clik here to view.
Download the Axis2 librarys
Set up Axis2 runtime by selecting Windows -> Preferences -> Web Services ->Axis 2
Image may be NSFW.
Clik here to view.
Right click on your project root and create a new webservice clientImage may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.
You only need to Assemble the client here (notice the drag bar on the left)
Select “Web service runtime Apache Axis” and "you choose Web service runtime" then choose Apache Axis2.
Press ok and Next
Press Finish
Image may be NSFW.
Clik here to view.
In the ServiceStub constructors you need to add the below code. Make sure to add the ByD
user name and password of the user who is able to consume the webservices.
this(configurationContext,targetEndpoint,false); HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator(); auth.setPassword(""); auth.setUsername(""); this._getServiceClient().getOptions().setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE,auth);
Step 4 - Servlet set up
Create a new package and servlet called QueryJohnTask
Add in the following code to consume the web service.
package com.sap.integrate; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.axis2.databinding.types.Token; import com.sap._0000159922_one_off.ypxftrpry_.ServiceStub; import com.sap._0000159922_one_off.ypxftrpry_.StandardFaultMessage; import com.sap._0000159922_one_off.ypxftrpry_.ServiceStub.ID; import com.sap._0000159922_one_off.ypxftrpry_.ServiceStub.InclusionExclusionCode; import com.sap._0000159922_one_off.ypxftrpry_.ServiceStub.Indicator; import com.sap._0000159922_one_off.ypxftrpry_.ServiceStub.IntervalBoundaryTypeCode; import com.sap._0000159922_one_off.ypxftrpry_.ServiceStub.JohnTest2Johntest2Viewnamejohntask2QuerySimpleByConfirmation; import com.sap._0000159922_one_off.ypxftrpry_.ServiceStub.JohnTest2Johntest2Viewnamejohntask2QuerySimpleByConfirmation_sync; import com.sap._0000159922_one_off.ypxftrpry_.ServiceStub.JohnTest2Johntest2Viewnamejohntask2QuerySimpleByRequest; import com.sap._0000159922_one_off.ypxftrpry_.ServiceStub.JohnTest2Johntest2Viewnamejohntask2QuerySimpleByRequestMessage_sync; import com.sap._0000159922_one_off.ypxftrpry_.ServiceStub.JohnTest2Johntest2Viewnamejohntask2QuerySimpleByRequestSelectionByid; import com.sap._0000159922_one_off.ypxftrpry_.ServiceStub.JohnTest2Johntest2Viewnamejohntask2QuerySimpleByRequest_sync; import com.sap._0000159922_one_off.ypxftrpry_.ServiceStub.LANGUAGEINDEPENDENT_EXTENDED_Name; import com.sap._0000159922_one_off.ypxftrpry_.ServiceStub.NumberValue; import com.sap._0000159922_one_off.ypxftrpry_.ServiceStub.QueryProcessingConditions; /** * Servlet implementation class QueryJohnTask */ public class QueryJohnTask extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public QueryJohnTask() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub ServiceStub stub =new ServiceStub(); JohnTest2Johntest2Viewnamejohntask2QuerySimpleByRequest_sync simpleRequest=new JohnTest2Johntest2Viewnamejohntask2QuerySimpleByRequest_sync(); JohnTest2Johntest2Viewnamejohntask2QuerySimpleByRequestMessage_sync queryParam= new JohnTest2Johntest2Viewnamejohntask2QuerySimpleByRequestMessage_sync(); QueryProcessingConditions processConditions=new QueryProcessingConditions(); JohnTest2Johntest2Viewnamejohntask2QuerySimpleByRequest querySelectionParam=new JohnTest2Johntest2Viewnamejohntask2QuerySimpleByRequest(); JohnTest2Johntest2Viewnamejohntask2QuerySimpleByRequestSelectionByid[] selectionID=new JohnTest2Johntest2Viewnamejohntask2QuerySimpleByRequestSelectionByid[1]; selectionID[0]=new JohnTest2Johntest2Viewnamejohntask2QuerySimpleByRequestSelectionByid(); //Set ID ID lowerParam=new ID(); Token idTok=new Token(); idTok.setValue("*"); lowerParam.setID(idTok); //Interval boundary IntervalBoundaryTypeCode intevalBound=new IntervalBoundaryTypeCode(); Token inTok=new Token(); inTok.setValue("1"); intevalBound.setIntervalBoundaryTypeCode(inTok); //Create Inclusion param InclusionExclusionCode inExBound=new InclusionExclusionCode(); Token tok=new Token(); tok.setValue("I"); inExBound.setInclusionExclusionCode(tok); //Set selection param selectionID[0].setInclusionExclusionCode(inExBound); selectionID[0].setIntervalBoundaryTypeCode(intevalBound); selectionID[0].setLowerBoundaryid(lowerParam); //Set Maxindicator Indicator hitsInd=new Indicator(); hitsInd.setIndicator(false); processConditions.setQueryHitsUnlimitedIndicator(hitsInd); //max hits NumberValue indicator=new NumberValue(); indicator.setNumberValue(100); processConditions.setQueryHitsMaximumNumberValue(indicator); //Set query params queryParam.setProcessingConditions(processConditions); //Set Selection by Id params querySelectionParam.setSelectionByid(selectionID); JohnTest2Johntest2Viewnamejohntask2QuerySimpleByRequestMessage_sync requestParam=new JohnTest2Johntest2Viewnamejohntask2QuerySimpleByRequestMessage_sync(); requestParam.setJohnTest2SimpleSelectionBy(querySelectionParam); requestParam.setProcessingConditions(processConditions); simpleRequest.setJohnTest2Johntest2Viewnamejohntask2QuerySimpleByRequest_sync(requestParam); try { JohnTest2Johntest2Viewnamejohntask2QuerySimpleByConfirmation_sync respon=new JohnTest2Johntest2Viewnamejohntask2QuerySimpleByConfirmation_sync(); respon=stub.johntask2Query(simpleRequest); JohnTest2Johntest2Viewnamejohntask2QuerySimpleByConfirmation[] content=respon.getJohnTest2Johntest2Viewnamejohntask2QuerySimpleByConfirmation_sync().getJohnTest2(); StringBuilder sb1=new StringBuilder(); String comma=""; sb1.append("["); for(JohnTest2Johntest2Viewnamejohntask2QuerySimpleByConfirmation line:content){ line.getSAP_UUID().getXMLStreamReader(); sb1.append(comma); comma=","; LANGUAGEINDEPENDENT_EXTENDED_Name respName = line.getResponceName1(); if(respName==null){ line.getSAP_UUID(); respName=new LANGUAGEINDEPENDENT_EXTENDED_Name(); respName.setLANGUAGEINDEPENDENT_EXTENDED_Name(" "); } sb1.append(jsonConvertor.Convert("id",line.getId().toString(),"taskname",line.getTaskName().toString().replace("<SAP_UUID>", ""),"uuid",line.getSAP_UUID().toString(),"Resp",respName.toString())); } sb1.append("]"); response.getWriter().print(sb1.toString()); } catch (StandardFaultMessage e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub } }
Create a new class called JsonConvertor.
I use this to format my response so that my Javascript can create an object directly from it.
package com.sap.integrate; public class JsonConvertor { public JsonConvertor() { // TODO Auto-generated constructor stub } //output will be "id":"hi", public static String Convert(String... param){ StringBuffer sb=new StringBuffer(); boolean colonInd=true; String comma=""; sb.append("{"); comma=","; for(String p : param){ sb.append("\""); sb.append(p); sb.append("\""); //Only want colon every two inputs on the first if(colonInd==true){ sb.append(":"); colonInd=false; }else{ sb.append(comma); colonInd=true; } } int len=sb.length(); sb.replace(sb.lastIndexOf(","), len, ""); //sb.replace(sb.lastIndexOf(","), sb.lastIndexOf(","), ""); sb.append("}"); return sb.toString(); } }
Create a Servlet called QueryBusinessPartner and insert this code.
package com.sap.integrate; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.axis2.databinding.types.Token; import com.sap.xi.a1s.global.ServiceStub; import com.sap.xi.a1s.global.ServiceStub.BusinessPartnerByIdentificationQueryMessage_sync; import com.sap.xi.a1s.global.ServiceStub.BusinessPartnerByIdentificationQuery_sync; import com.sap.xi.a1s.global.ServiceStub.BusinessPartnerByIdentificationResponse_sync; import com.sap.xi.a1s.global.ServiceStub.BusinessPartnerReponseBusinessPartnerPerson; import com.sap.xi.a1s.global.ServiceStub.BusinessPartnerResponseBusinessPartner; import com.sap.xi.a1s.global.ServiceStub.BusinessPartnerResponseMessage_sync; import com.sap.xi.a1s.global.ServiceStub.BusinessPartnerSelectionByIdentification; import com.sap.xi.a1s.global.ServiceStub.InclusionExclusionCode; import com.sap.xi.a1s.global.ServiceStub.IntervalBoundaryTypeCode; import com.sap.xi.a1s.global.ServiceStub.LANGUAGEINDEPENDENT_MEDIUM_Name; import com.sap.xi.a1s.global.ServiceStub.SearchText; import com.sap.xi.a1s.global.ServiceStub.SelectionByIdentifier; import com.sap.xi.a1s.global.StandardFaultMessage; /** * Servlet implementation class QueryBusinessPartner */ public class QueryBusinessPartner extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public QueryBusinessPartner() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse * response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { BusinessPartnerByIdentificationQuery_sync message = new BusinessPartnerByIdentificationQuery_sync(); BusinessPartnerByIdentificationQueryMessage_sync queryMessage = new BusinessPartnerByIdentificationQueryMessage_sync(); BusinessPartnerSelectionByIdentification selectionByIdParam = new BusinessPartnerSelectionByIdentification(); ServiceStub stub = new ServiceStub(); SelectionByIdentifier[] internalIdParam = new SelectionByIdentifier[1]; // Set selection param internalIdParam[0] = new SelectionByIdentifier(); // Set Inclusion code InclusionExclusionCode inclusionCode = new InclusionExclusionCode(); Token inToken = new Token(); inToken.setValue("I"); inclusionCode.setInclusionExclusionCode(inToken); internalIdParam[0].setInclusionExclusionCode(inclusionCode); // Set type code IntervalBoundaryTypeCode typeCode = new IntervalBoundaryTypeCode(); Token typeToken = new Token(); typeToken.setValue("1"); typeCode.setIntervalBoundaryTypeCode(typeToken); // Set lowerbound SearchText lowerBound = new SearchText(); lowerBound.setSearchText("*"); internalIdParam[0].setLowerBoundaryIdentifier(lowerBound); // Set Interval boundary internalIdParam[0].setIntervalBoundaryTypeCode(typeCode); selectionByIdParam.setSelectionByInternalID(internalIdParam); queryMessage .setBusinessPartnerSelectionByIdentification(selectionByIdParam); message.setBusinessPartnerByIdentificationQuery_sync(queryMessage); // Create the response StringBuilder line1 = new StringBuilder(); line1.append("["); String comma = ""; try { BusinessPartnerByIdentificationResponse_sync find = stub .findByIdentification(message); BusinessPartnerResponseMessage_sync resp = find .getBusinessPartnerByIdentificationResponse_sync(); BusinessPartnerResponseBusinessPartner[] result = resp .getBusinessPartner(); for (BusinessPartnerResponseBusinessPartner line : result) { line1.append(comma); comma = ","; LANGUAGEINDEPENDENT_MEDIUM_Name famName = new LANGUAGEINDEPENDENT_MEDIUM_Name(); LANGUAGEINDEPENDENT_MEDIUM_Name givenNamem = new LANGUAGEINDEPENDENT_MEDIUM_Name(); if (line.getPerson() != null) { if (line.getPerson().getFamilyName() == null) { famName = new LANGUAGEINDEPENDENT_MEDIUM_Name(); famName.setLANGUAGEINDEPENDENT_MEDIUM_Name(""); line.getPerson().setFamilyName(famName); } if (line.getPerson().getGivenName() == null) { givenNamem.setLANGUAGEINDEPENDENT_MEDIUM_Name(""); line.getPerson().setGivenName(givenNamem); } } else { // Create Person BusinessPartnerReponseBusinessPartnerPerson person = new BusinessPartnerReponseBusinessPartnerPerson(); line.setPerson(person); famName.setLANGUAGEINDEPENDENT_MEDIUM_Name(""); givenNamem.setLANGUAGEINDEPENDENT_MEDIUM_Name(""); line.getPerson().setFamilyName(famName); line.getPerson().setGivenName(givenNamem); } line1.append(JsonConvertor.Convert("id", line.getInternalID() .getBusinessPartnerInternalID().toString(), "Name", line.getPerson().getGivenName().toString() + " " + line.getPerson().getFamilyName().toString())); } line1.append("]"); // Set response response.getWriter().print(line1.toString()); } catch (StandardFaultMessage e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse * response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub } }
Now is a good time to test our views. Create your server in the eclipse view.If you are deploying to your localhost make sure you have your own proxy arguments added to the VM arguments of the server. Sometimes depending on the wsdl you use your service stub may throw back an exception. In my case it was the date format from the time stamp of the message. You can correct this by altering the regex or commenting out the throwable.
If you have a successful test add in the last Servlet called UpdateJohnTask and add this code
package com.sap.integrate; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.axis2.databinding.types.Token; import com.sap._0000159922_one_off.ypxftrpry_.ServiceStub; import com.sap._0000159922_one_off.ypxftrpry_.ServiceStub.BusinessDocumentBasicMessageHeader; import com.sap._0000159922_one_off.ypxftrpry_.ServiceStub.BusinessPartnerID; import com.sap._0000159922_one_off.ypxftrpry_.ServiceStub.ID; import com.sap._0000159922_one_off.ypxftrpry_.ServiceStub.JohnTest2Johntest2ViewnameUpdateConfirmation_sync; import com.sap._0000159922_one_off.ypxftrpry_.ServiceStub.JohnTest2Johntest2ViewnameUpdateRequest; import com.sap._0000159922_one_off.ypxftrpry_.ServiceStub.JohnTest2Johntest2ViewnameUpdateRequestMessage_sync; import com.sap._0000159922_one_off.ypxftrpry_.ServiceStub.JohnTest2Johntest2ViewnameUpdateRequest_sync; import com.sap._0000159922_one_off.ypxftrpry_.StandardFaultMessage; /** * Servlet implementation class UpdateJohnTask */ public class UpdateJohnTask extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public UpdateJohnTask() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse * response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub // TODO Auto-generated method stub ServiceStub stub = new ServiceStub(); String id = request.getParameter("id").toString(); String bpid = request.getParameter("bpid").toString(); JohnTest2Johntest2ViewnameUpdateRequest_sync johnTest2Johntest2ViewnameUpdateRequest_sync6 = new JohnTest2Johntest2ViewnameUpdateRequest_sync(); JohnTest2Johntest2ViewnameUpdateRequestMessage_sync requetParam = new JohnTest2Johntest2ViewnameUpdateRequestMessage_sync(); JohnTest2Johntest2ViewnameUpdateRequest JTparam = new JohnTest2Johntest2ViewnameUpdateRequest(); // Set id ID param = new ID(); Token tokenParam = new Token(); tokenParam.setValue(id); param.setID(tokenParam); JTparam.setId(param); // Set Business Partner id BusinessPartnerID custParm = new BusinessPartnerID(); Token Cusparam = new Token(); Cusparam.setValue(bpid); custParm.setBusinessPartnerID(Cusparam); JTparam.setCustom(custParm); // Set the header requetParam.setJohnTest2(JTparam); BusinessDocumentBasicMessageHeader header = new BusinessDocumentBasicMessageHeader(); requetParam.setBasicMessageHeader(header); johnTest2Johntest2ViewnameUpdateRequest_sync6 .setJohnTest2Johntest2ViewnameUpdateRequest_sync(requetParam); try { // Execute JohnTest2Johntest2ViewnameUpdateConfirmation_sync t = stub .update(johnTest2Johntest2ViewnameUpdateRequest_sync6); } catch (StandardFaultMessage e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse * response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub } }
Now you should be able to drag rows from the Business Partner Table into the John Task Table. The Table gets automatically updated and the JohnTask2 instances get updated ByD .Of course you can add more instances by creating them in ByD