
The following example shows you how to create a Guided Procedures (GP) template and provider to wrap a Knowledge Management (KM) Document business model defined in an SAP system. In essence, you create a template corresponding to the particular business object resource, create and register a provider and then instantiate a single aspect of the business object (BO) data to use it in GP.
You should have in mind that implementation depends mainly on the business object resource you want to expose.
Before you start, you need to:
Modeling the Template Structure
In our example, we have to instantiate the business object utility manager, the global service factory of the KM platform and the indexing service.
KMDocumentTemplateHandler
| Initializing Services |
|---|
importcom.sap.caf.eu.gp.bo.api.IGPBusinessObjectUtilityManager; importcom.sap.caf.eu.gp.bo.api.GPBusinessObjectFactory; importcom.sapportals.wcm.service.IServiceFactory; importcom.sapportals.wcm.service.IServiceTypesConst; importcom.sapportals.wcm.service.ServiceFactory; importcom.sapportals.wcm.service.indexmanagement.IIndexService; importcom.sap.caf.eu.gp.exception.api.GPInvocationException; importcom.sapportals.wcm.WcmException; privateIGPBusinessObjectUtilityManager managerUtility; privateIIndexService indexService; privatevoid initialize() throws WcmException, GPInvocationException{// instantiate the utility manager managerUtility= GPBusinessObjectFactory.getUtilityManager(); // Retrieve the global service Factory of the KM Platform IServiceFactoryserviceFactory = ServiceFactory.getInstance(); // Retrieve the Index Service indexService= (IIndexService) serviceFactory.getService(IServiceTypesConst.INDEX_SERVICE); ... } |
In the particular example, we need to add some document properties: name, description, date of creation, target URL and so on.
| Creating a Type Definition (Structure and Attributes) |
|---|
importcom.sap.caf.eu.gp.structure.api.IGPAttributeInfo; importcom.sap.caf.eu.gp.structure.api.IGPLabel; importcom.sap.caf.eu.gp.structure.api.IGPStructure; importcom.sap.caf.eu.gp.structure.api.IGPStructureInfo; importcom.sap.caf.eu.gp.structure.api.GPStructureFactory; privateIGPLabel completeDocumentLabel; privateIGPStructureInfo documentStructureInfo; privatestatic final String NAME_STRUCTURE_NAME = "Name"; privatestatic final String NAME_STRUCTURE_CREATED = "Created"; privatestatic final String NAME_STRUCTURE = "Documents"; privatestatic final String NAMESPACE = "com.sap.bc.er.bo.provider.km.KMDocumentTemplate"; privatestatic IGPLabel NAME_LABEL_STRUCTURE; privatestatic IGPLabel NAME_LABEL_STRUCTURE_DESCRIPTION; ... // create a label and structure for the document object completeDocumentLabel= GPStructureFactory.createLabel(NAME_STRUCTURE, NAMESPACE); documentStructureInfo= GPStructureFactory.getStructureInfo(completeDocumentLabel); documentStructureInfo.setMultiplicity(IGPStructureInfo.MULITIPLICITY_0_N); // add an attribute for structure name and set its multiplicity IGPAttributeInfostructureName = documentStructureInfo.addAttribute( NAME_STRUCTURE_NAME, NAMESPACE, IGPAttributeInfo.BASE_STRING); structureName.setMultiplicity(IGPAttributeInfo.MULITIPLICITY_1_1); // add an attribute for creation date and set its multiplicity IGPAttributeInfostructureCreated = documentStructureInfo.addAttribute( NAME_STRUCTURE_CREATED, NAMESPACE, IGPAttributeInfo.BASE_DATE); structureCreated.setMultiplicity(IGPAttributeInfo.MULITIPLICITY_1_1); // by analogy, add attributes for: description, created by, modified by, date // modified, target URL // create labels for all attributes specified above NAME_LABEL_STRUCTURE= GPStructureFactory.createLabel( NAME_STRUCTURE, NAMESPACE); NAME_LABEL_STRUCTURE_DESCRIPTION= GPStructureFactory.createLabel( NAME_STRUCTURE_DESCRIPTION, NAMESPACE); ... |
Constructing a Restriction Locator and Template
In the particular case, we create a locator that represents the whole structure of the business object. You may also create a locator that is a subset of the structure.
| Creating An Attribute Locator |
|---|
importjava.util.Collection; importjava.util.Iterator; importcom.sap.caf.eu.gp.bo.utility.api.IGPBusinessObjectAttributeLocator; privateIGPBusinessObjectAttributeLocator createTemplateLocator() throws GPInvocationException {IGPBusinessObjectAttributeLocator locator = managerUtility.createLocator(completeDocumentLabel); Collection attributes = documentStructureInfo.getAttributes(); // for each attribute in the structure, add a locator for (Iterator iter = attributes.iterator(); iter.hasNext();) {IGPAttributeInfo attr = (IGPAttributeInfo) iter.next(); locator.addLocator( attr.getLabel() ); } return locator; } |
IGPBusinessObjectTemplateDetail
IGPBusinessObjectTemplateOverview
| Creating A Template Detail and Overview |
|---|
importcom.sap.caf.eu.gp.bo.template.api.IGPBusinessObjectTemplateDetail; importcom.sap.caf.eu.gp.bo.template.api.IGPBusinessObjectTemplateOverview; privatestatic final String NAME_TEMPLATE = "KM_Documents"; privatestatic final String TITLE_TEMPLATE = "Documents"; privatestatic final String DESCRIPTION_TEMPLATE = "documents"; // create detailed template providing the document structure and locator IGPBusinessObjectTemplateDetail templateDetail = managerUtility.createTemplateDetail(NAME_TEMPLATE, TITLE_TEMPLATE, DESCRIPTION_TEMPLATE, documentStructureInfo, locator, true); // create a template overview IGPBusinessObjectTemplateOverview templateOverview = managerUtility.createTemplateOverview(NAME_TEMPLATE, TITLE_TEMPLATE, DESCRIPTION_TEMPLATE, true); |
IGPBusinessObjectTemplateDetailIGPBusinessObjectTemplateOverview
Depending on the locator you define, you may create more than one template based on the same business object model.
IGPPlainTemplateReaderIGPPatternTemplateReaderKMDocumentTemplateReader
In this implementation you can specify how to retrieve:
Implementing and Registering a BO Provider
KMDocumentBOProvider
In the implementation you may include, for example:
| Implementing A Business Object Provider |
|---|
importcom.sap.caf.eu.gp.bo.aspect.api.IGPBusinessObjectAspect; importcom.sap.security.api.IUser; importcom.sap.caf.eu.gp.bo.utility.api.IGPBusinessObjectEndpoint; // create an object aspect by specifying SAP system and locator restriction publicIGPBusinessObjectAspect readObjectAspect( IUser user, IGPBusinessObjectEndpoint endpoint, String name, String id, IGPBusinessObjectAttributeLocator locator) throws GPEngineException, GPInvocationException {KMDocumentTemplateHandler documentTemplateHandler = KMDocumentTemplateHandler.getInstance(); return documentTemplateHandler.createObjectAspect(user,name,id,locator) } // create a template detail by specifying SAP system endpoint publicIGPBusinessObjectTemplateDetail readTemplateDetail( IUser user, IGPBusinessObjectEndpoint endpoint, String name) throws GPEngineException, GPInvocationException {KMDocumentTemplateHandler documentTemplateHandler = KMDocumentTemplateHandler.getInstance(); return documentTemplateHandler.readTemplateDetail(); } // create aspect enumeration, template overview, and so on... |
createObjectAspect()
| Registering A Business Object Provider |
|---|
// instantiate the BO Provider KMDocumentBOProvider documentBOProvider =newKMDocumentBOProvider(); // instantiate the business object registry IGPBusinessObjectProviderRegistryboProviderRegistry = GPBusinessObjectFactory.getProviderRegistry(); // add the new provider boProviderRegistry.addProvider(documentBOProvider); |
Creating and Instantiating a BO Aspect and Enumeration
KMDocumentTemplateHandler
The method should copy the attributes of the resource to the structure of the template instance (aspect).
| Creating A Business Object Aspect |
|---|
importcom.sap.caf.eu.gp.bo.aspect.api.IGPBusinessObjectAspect; importcom.sapportals.wcm.repository.IResource; importcom.sapportals.wcm.repository.IResourceContext; importcom.sapportals.wcm.repository.ResourceContext; importcom.sapportals.wcm.repository.ResourceException; importcom.sapportals.wcm.repository.ResourceFactory; importcom.sap.caf.eu.gp.exception.api.GPEngineException; importcom.sap.security.api.IUser; publicIGPBusinessObjectAspect createObjectAspect(IUser user, String name, String id, IGPBusinessObjectAttributeLocator locator) throws GPEngineException, GPInvocationException { try {// retrieve the resource RID rid = RID.getRID(id); IResourceContext resourceContext = new ResourceContext(user); IResource resource = ResourceFactory.getInstance().getResource(rid, resourceContext); // build the GP structure IGPStructure document = GPStructureFactory.getStructure(documentStructureInfo); // set the attribute values EnumerationlocatorEnum = locator.createLocatorEnumeration(); while (locatorEnum.hasMoreElements()) {IGPBusinessObjectAttributeLocator attrLocator = (IGPBusinessObjectAttributeLocator) locatorEnum.nextElement(); if ( attrLocator.getLabel().equals( NAME_LABEL_STRUCTURE_NAME )) {document.setAttributeValue( NAME_STRUCTURE_NAME, NAMESPACE, resource.getName()); } else if ( attrLocator.getLabel().equals( NAME_LABEL_STRUCTURE_DESCRIPTION )) {document.setAttributeValue( NAME_STRUCTURE_DESCRIPTION, NAMESPACE, resource.getDescription()); } else if ( attrLocator.getLabel().equals( NAME_LABEL_STRUCTURE_CREATED )) {document.setAttributeValue( NAME_STRUCTURE_CREATED, NAMESPACE, resource.getCreationDate()); } // by analogy, set all other attribute values ... } return managerUtility.createAspect(id, document); } catch (ResourceException e) {throw new GPEngineException(LOCATION, e); } } |
KMDocumentBOProvider
IGPBusinessObjectAspectboAspect = documentBOProvider.readObjectAspect(user, endpoint, name, id, locator); |
KMDocumentTemplateHandler
| Creating An Object Aspect Enumeration | |
|---|---|
importjava.util.Enumeration; importjava.util.Vector; importcom.sapportals.wcm.service.indexmanagement.retrieval.search.IFederatedSearch; importcom.sapportals.wcm.service.indexmanagement.IWcmIndexConst; importcom.sapportals.wcm.WcmException; importcom.sapportals.portal.security.usermanagement.UserManagementException; publicEnumeration createObjectAspectEnumeration( IUseruser, Stringname, IGPStructurerestriction, IGPBusinessObjectAttributeLocatorlocator) throwsGPEngineException, GPInvocationException { try {Vector objectAspects = new Vector(); IFederatedSearch fedSearch = (IFederatedSearch) indexService.getObjectInstance( IWcmIndexConst.FEDERATED_SEARCH_INSTANCE ); ... // build the query based on the BO restriction structure // retrieve results from the search // for each resource found, build the GP structure and set attributes // add the new development object to the vector objectAspects.add(managerUtility.createAspect( resource.getRID().toString(), document)); return objectAspects.elements(); } catch (WcmException e) {throw new GPEngineException( LOCATION, e ); } catch (UserManagementException e) {throw new GPEngineException( LOCATION, e ); }
|
Once you have implemented a provider and constructed a template, you can use it in GP. You need to create a callable object and add to it a parameter that is a reference to the data retrieved from the business object model.
For this purpose, you must explicitly create the structure type definition of the new parameter. It should be equivalent to the type definition of the template (described above) based on the restriction of the locator.
For more information on how to add parameters to a callable object, refer to Creating Callable Objects .
Consequently, for each instantiation of the callable object, you should create an aspect of the business object and fill in the actual values into this structure.