Calling a Media Object Business Service
The published business service class exposes a public method as a web service operation. The business service method that the Media Object published business service class calls acts as a controller to the business logic that can perform operations on the media objects.
The rules for calling a business service also apply to calling a Media Object business service. See Calling a Business Service for more information.
You may need to call multiple business services from a published business service method to perform the following tasks:
Call a normal internal business service, such as a call to the AddAddressBook business service, which does not perform a Media Object operation.
Call the Media Object internal business service for adding the Media Object attachments.
For example, you could change the existing RI_AddressBook business service (JPR01000) so that it performs the add Media Object operation after creating an Address Book record. The following sample code shows this example:
protected RI_ConfirmAddAddressBook addAddressBookMO(IContext context,
IConnection connection,
RI_AddAddressBook vo) throws BusinessServiceException {
//perform all work within try block, finally will clean up any connections.
try {
//Call start published method, passing context of null
//will return context object so BSFN or DB operation can be called later.
//Context will be used to indicate default transaction boundary, as well as access
//to formatting and logging operations.
context = startPublishedMethod(context, "addAddressBookMO", vo);
//Create new PublishedBusinessService messages object for holding errors and warnings that occur during processing.
E1MessageList messages = new E1MessageList();
//TODO: Create a new internal value object.
RI_InternalAddAddressBook internalVO =
new RI_InternalAddAddressBook();
messages.addMessages(vo.mapFromPublished(context, internalVO));
//Call BSSV passing context, connection and internal VO
E1MessageList bssvMessages =
RI_AddressBookProcessor.addAddressBook(context, connection,
internalVO);
//Add messages returned from BSSV to message list for Published Business Service.
messages.addMessages(bssvMessages);
//PublishedBusinessService will send either warnings in the Confirm Value Object or throw a BusinessServiceException.
//If messages contains errors, throw the exception
if (messages.hasErrors()) {
//Get the string representation of all the messages.
String error = messages.getMessagesAsString();
//Throw new BusinessServiceException
throw new BusinessServiceException(error, context);
}
//MO Code to call Internal BSSV - Start
ABGT_Internal inputVO = new ABGT_Internal();
messages.addMessages(vo.mapFromPublished(context, inputVO));
inputVO.setMnAddressNumber(internalVO.getMnAddressBookNumber());
E1MessageList moMessages =
RI_AddressBookMediaObjectProcessor.addAddressBookMO(context,
connection,
inputVO);
messages.addMessages(moMessages);
//MO Code to call Internal BSSV End
if (messages.hasErrors()) {
//Get the string representation of all the messages.
String error = messages.getMessagesAsString();
//Throw new BusinessServiceException
throw new BusinessServiceException(error, context);
}
//Exception was not thrown, so create the confirm VO from internal VO
RI_ConfirmAddAddressBook confirmVO =
new RI_ConfirmAddAddressBook(internalVO);
confirmVO.setE1MessageList(messages);
finishPublishedMethod(context, "addAddressBookMO");
//return outVO, filled with return values and messages
return confirmVO;
} finally {
//Call close to clean up all remaining connections and resources.
close(context, "addAddressBookMO");
}
}
See Calling Media Object Operations in this guide for details on how to call the Media Object operations within the internal business service.