Hi Jun,
Please find the following:
SubstMgr.java
public class SubstMgr extends AbstractSessionBean implements SubstMgrLocal {
/**
* Default constructor.
*/
public SubstMgr() {
// TODO Auto-generated constructor stub
}
public StoreSubstTemplateToDbResDTO storeSubstTemplateToDb(String userID, String templateID, String templateName, String templateStatus){
// time tracing
long start = new Date().getTime();
StoreSubstTemplateToDbResDTO res = new StoreSubstTemplateToDbResDTO();
userID = StringUtils.upperCase(userID);
SubstitutionTemplateDAO substTempl = em.find(SubstitutionTemplateDAO.class, templateID);
if(substTempl == null){
substTempl = new SubstitutionTemplateDAO();
substTempl.setTemplateID(templateID);
}
substTempl.setUserID(userID);
substTempl.setTemplateName(templateName);
substTempl.setTemplateStatus(templateStatus);
em.persist(substTempl);
// time tracing
long end = new Date().getTime();
res.setDuration(end - start);
return res;
}
}
SubstMgrLocal.java
@Local
public interface SubstMgrLocal {
public StoreSubstTemplateToDbResDTO storeSubstTemplateToDb(String userID, String templateID, String templateName, String templateStatus);
}
AbstractSessionBean.java
public abstract class AbstractSessionBean implements AbstractSessionBeanLocal{
protected final static Location LOC = Location.getLocation(AbstractSessionBean.class);
//Entity Manager
@PersistenceContext(unitName="JDP_SubstMgP_D~substmgr~ejb", type=PersistenceContextType.TRANSACTION)
protected EntityManager em;
}
AbstractSessionBeanLocal.java
public interface AbstractSessionBeanLocal {
}
SubstTemplateProcessor.java
public class SubstitutionTemplateProcessor extends IfxDefaultDataProcessor {
@Override
public Object runFunctionImport(EdmFunctionImport function, Map<String, Object> parameters, Object keyInstance,
IfxOdataQueryOption oDataQueryOption) throws EdmException, IfxOdataProcessorException, ODataNotImplementedException{
if(function.getName().equalsIgnoreCase(AppConstant.funcGetSubstitutionTemplate)){
//read out template information from Portal DB
} else if(function.getName().equalsIgnoreCase(AppConstant.funcSetSubstitutionforPES)){
//set the substitute for user in PES landscape, then update template information in DB
return setPesSubstitute(parameters.get("Username").toString(), parameters.get("SubstituteID").toString(), parameters.get("SubstBegin").toString(), parameters.get("SubstEnd").toString());
}
return null;
}
@EJB
SubstMgrLocal bean;
private StoreSubstTemplateToDbResDTO storeSubstTemplateToDb(){
bean.storeSubstTemplateToDb("testUser", "0001", "Template0001", "N");
return null;
}
private SubstitutionTemplate setPesSubstitute(String username, String substituteID, String substBegin, String substEnd) throws IfxOdataProcessorException{
SubstitutionTemplate result = new SubstitutionTemplate();
DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
Date subst_beginDate = new Date();
Date subst_endDate = new Date();
try{
subst_beginDate = df.parse(substBegin);
subst_endDate = df.parse(substEnd);
}catch (Exception e) {
e.printStackTrace();
}
DatasourceConn datasourceConn = DatasourceConn.getInstance();
JCO.Client connClient = null;
connClient = datasourceConn.backendEnvironmentConnection();
IRepository mRepository;
mRepository = new JCO.Repository("nwd", connClient);
JCO.Function function = mRepository.getFunctionTemplate("SAP_WAPI_SUBSTITUTE_MAINTAIN").getFunction();
JCO.ParameterList input = function.getImportParameterList();
JCO.Structure substitutedObject = function.getImportParameterList().getStructure("SUBSTITUTED_OBJECT");
JCO.Structure substitute = function.getImportParameterList().getStructure("SUBSTITUTE");
substitutedObject.setValue("US", "OTYPE");
substitutedObject.setValue(username, "OBJID");
substitute.setValue("US", "OTYPE");
substitute.setValue(substituteID, "OBJID");
input.setValue(substitutedObject, "SUBSTITUTED_OBJECT");
input.setValue(substitute, "SUBSTITUTE");
input.setValue(subst_beginDate, "SUBST_BEGIN");
input.setValue(subst_endDate, "SUBST_END");
connClient.execute(function);
result.setReturnCode(function.getExportParameterList().getString("RETURN_CODE"));
connClient.disconnect();
storeSubstTemplateToDb();
return result;
}
private String getPesSubstitute (String username) throws IfxOdataProcessorException{
String substitute = "";
Object substituteObj = new Object();
DatasourceConn datasourceConn = DatasourceConn.getInstance();
JCO.Client connClient = null;
connClient = datasourceConn.backendEnvironmentConnection();
IRepository mRepository;
mRepository = new JCO.Repository("nwd", connClient);
JCO.Function function = mRepository.getFunctionTemplate("SAP_WAPI_SUBSTITUTES_GET").getFunction();
JCO.ParameterList input = function.getImportParameterList();
JCO.Structure substitutedObject = function.getImportParameterList().getStructure("SUBSTITUTED_OBJECT");
substitutedObject.setValue("US", "OTYPE");
substitutedObject.setValue(username, "OBJID");
input.setValue(substitutedObject, "SUBSTITUTED_OBJECT");
connClient.execute(function);
JCO.Table substitutesTable = function.getTableParameterList().getTable("SUBSTITUTES");
substitute = substitutesTable.getField("OBJID").getString();
connClient.disconnect();
return substitute;
}
}
Thanks & Regards,
Goh