Show TOC Start of Content Area

This graphic is explained in the accompanying text UserDetailsCallableObject  Locate the document in its SAP Library structure

 

UserDetailsCallableObject.java

package com.examples.bckgco;

 

import java.util.Locale;

 

import com.sap.caf.eu.gp.co.api.GPCallableObjectFactory;

import com.sap.caf.eu.gp.co.api.GPStandardResourceAccessor;

import com.sap.caf.eu.gp.co.api.IGPBackgroundCallableObject;

import com.sap.caf.eu.gp.co.api.IGPCOResultStateInfo;

import com.sap.caf.eu.gp.co.api.IGPExceptionInfo;

import com.sap.caf.eu.gp.co.api.IGPExecutionContext;

import com.sap.caf.eu.gp.co.api.IGPTechnicalDescription;

import com.sap.caf.eu.gp.exception.api.GPEngineException;

import com.sap.caf.eu.gp.exception.api.GPInvocationException;

import com.sap.caf.eu.gp.exception.api.GPTechnicalCallableObjectException;

import com.sap.caf.eu.gp.structure.api.IGPAttributeInfo;

import com.sap.caf.eu.gp.structure.api.IGPStructure;

import com.sap.caf.eu.gp.structure.api.IGPStructureInfo;

import com.sap.security.api.IUser;

import com.sap.security.api.UMException;

import com.sap.security.api.UMFactory;

import com.sap.tc.logging.Category;

import com.sap.tc.logging.Location;

import com.sap.tc.logging.Severity;

 

public class UserDetailsCallableObject implements IGPBackgroundCallableObject {

  

   public static Location logger =

        Location.getLocation(UserDetailsCallableObject.class);

 

//initialize the resource accessor class with the resource bundle as a parameter

GPStandardResourceAccessor resourceAccessor =

        new UserDetailsResourceAccessor("com.examples.bckgco.UserDetails");

 

 

public IGPTechnicalDescription getDescription(Locale originalLocale) {

      try {

 

       //create technical description instance

       IGPTechnicalDescription technicalDescription =

         GPCallableObjectFactory.createTechnicalDescription(

            "CO_NAME",

            "CO_DESCRIPTION",

            resourceAccessor,

            originalLocale);

 

       //get root structure for input parameters

       IGPStructureInfo input = technicalDescription.getInputStructureInfo();

 

       //define attributes for input parameters

       IGPAttributeInfo userId =

         input.addAttribute("UserID", IGPAttributeInfo.BASE_STRING);

       userId.setMultiplicity(IGPAttributeInfo.MULITIPLICITY_1_1);

 

       //get root structure for output parameters

       IGPStructureInfo output =

         technicalDescription.getOutputStructureInfo();

 

       //add a sub-structure for the output

       IGPStructureInfo user = output.addStructure("User");

 

       //define attributes in output sub-structure

       user.addAttribute("firstName", IGPAttributeInfo.BASE_STRING);

       user.addAttribute("lastName", IGPAttributeInfo.BASE_STRING);

       user.addAttribute("phone", IGPAttributeInfo.BASE_STRING);

       user.addAttribute("fax", IGPAttributeInfo.BASE_STRING);

 

       //add a result state for successful execution

       IGPCOResultStateInfo success =

         technicalDescription.addResultState("Success");

       success.setDescriptionKey("Success_desc");

       IGPExceptionInfo exception = technicalDescription.addProcessException("EXCEPTION_NO_USER_FOUND");

       return technicalDescription;

 

     } catch (GPInvocationException e) {

       logger.logT(

         Severity.ERROR,

         Category.APPLICATIONS,

         "Incorrect technical name");

       logger.traceThrowableT(

         Severity.ERROR,

         "Exception while creating technical description: ",

         e);

       return null;

     }

   }

 

public void execute(IGPExecutionContext executionContext)

      throws GPTechnicalCallableObjectException {

         String userId = null;

 

     try {

 

       //retrieve the runtime representation of the input structure  

       IGPStructure input = executionContext.getInputStructure();

 

       //retrieve the value of the input parameter

       userId = (String) input.getAttributeAsString("UserID");

 

       //retrieve the runtime representation of the output structure

      IGPStructure output = executionContext.getOutputStructure();

      IGPStructure user = output.addStructure("User");

 

       try {

 

         //find user in user management

         IUser umeUser =

            UMFactory.getUserFactory().getUserByLogonID(userId);

 

         //set values to output parameters

         user.setAttributeValue("firstName", umeUser.getFirstName());

         user.setAttributeValue("lastName", umeUser.getLastName());

         user.setAttributeValue("phone", umeUser.getTelephone());

         user.setAttributeValue("fax", umeUser.getFax());

 

         //set result state

         executionContext.setResultState("Success");

 

       } catch (UMException e) {

         //set process exception if user is not found

        executionContext.setProcessException("EXCEPTION_NO_USER_FOUND");

 

       }

 

       //complete object execution

       executionContext.processingComplete();

 

     } catch (GPInvocationException e) {

       throw new GPTechnicalCallableObjectException(

            logger,

            resourceAccessor,

            "ERROR_PARAMETERS",

            e);

     } catch (GPEngineException e) {

       throw new GPTechnicalCallableObjectException(

            logger,

            resourceAccessor,

            "INTERNAL_ERROR",

         e);

     }

   }

}

 

End of Content Area