To insert an object, you need get the template document first and then add the necessary values into the document and insert it.Back
Please follow the steps below:
Template Document for Asset:
- After executing the build, create a new Java project and copy the Services-test-client.jar and XBeans-packaged.jar files into a lib folder in the project
- Go to properties of the project and add all the jar files to the project
- Create new java class, naming it WebSeviceSample and make it main by checking the public static void main(String[] args) in the method stubs to create
- Create a new java class AssetUpload to run the service
- Go to the WebServiceSample file and create a new object assetUpload for the AssetUpload class
- Setup the authentication details in the AssetUpload class in a try catch block
- We need to create two classes after setting up the authentication, one is the serivceStub and the other is the document (same as the one used in SoapUI) which we are sending to the stub
- Setup up SerivceStub for template (for asset)
- Pass the ENDPOINT which is the UCONN server
https://uconnapp.assetworks.com:8443/fmax/ws for test
https://uconnapp.assetworks.com/fmax/ws for prod - Pass the authentication through the serviceStub using Options
- Now, we need to setup the template document for the asset using TemplateAeAAssetEDocument
- Create a TemplateAeAAssetEDocument document using the factory class and create a new instance (We are using this because there are certain things the TemplateAeAAssetEDocument constructor cannot do)
- Add the document with a addNewTemplateAeAAsset() to the document
- Store the result of the retrieved document and return the result
- Create the catch block such that it prints the exception
- Call the templateAsset() function we built to create a template Asset document
- Print the document by using assetUpload.templateAsset().toString() and verify if indeed it returns an Asset Document
Inserting the document with the data:
- We are now going to insert some data to the retrieved document and send it
- But instead of having the template document as AeAAssetEDocument, have it as AeAAssetEType
- Create a new function saveAsset() by copying the templateAsset() function but with boolean return type
- Create a document of type InsertAeAAssetEDocument instead of TemplateAeAAssetEDocument in the save function
- Add the document with the result obtained from the template function as we did it earlier using SOAPUI
- Now, fill in the mandatory fields required for the document (To know the mandatory fields of a document, go to the AiM system and go to a document and the red boxes show the mandatory fields)
- Add the attributes to the result of the template function in the WebServiceSample driver class
- Create a attributes object to get the attributes (attributes tag)of the result
- For example, to insert the region code, use the addNewRegionCode() and set the value
- Likewise, set the values for all the mandatory fields of the document
- Call the save function and it should insert the document successfully
Go back to Development with web services – Training