Advertisement

Responsive Advertisement

Java Code to get & set Service audit property

Raw Java Code to get IS Flow service audit property

Hi Folks ,

Here is a sample code to get the audit property of the flow services. This service is in raw format , you need to modify it according to your requirements.


import com.wm.data.*;
import com.wm.util.Values;
import com.wm.app.b2b.server.Service;
import com.wm.app.b2b.server.ServiceException;
import com.wm.app.b2b.server.ns.Namespace;
import com.wm.lang.ns.NSName;
import com.wm.lang.ns.NSNode;
import com.wm.lang.ns.NSService;
import com.wm.lang.ns.AuditSettings;

public final class getCurrentServiceAuditProperty_SVC

{

/**
* The primary method for the Java service
*
* @param pipeline
*            The IData pipeline
* @throws ServiceException
*/
public static final void getCurrentServiceAuditProperty(IData pipeline) throws ServiceException {
IDataCursor pipelineCursor = pipeline.getCursor();
String serviceName = IDataUtil.getString( pipelineCursor, "serviceName" );
pipelineCursor.destroy();

String enableAudit="";
String includePipeline="";
String logOn="";

String startExec="";
String stopExec="";


int enableAuditOptionInt;


NSName localNSName=NSName.create(serviceName);
NSService localNSService=Namespace.getService(localNSName);

enableAuditOptionInt=localNSService.getAuditOption();
if(enableAuditOptionInt==0)
{
enableAudit="Never";
}
if(enableAuditOptionInt==1)
{
enableAudit="Always";
}
if(enableAuditOptionInt==2)
{
enableAudit="When Top-level service only ";
}

AuditSettings asExisting=new AuditSettings();
asExisting=localNSService.getAuditSettings();

IData asExistingDoc=IDataFactory.create();
asExistingDoc=asExisting.getAsData();

IDataCursor asExistingDocCur=asExistingDoc.getCursor();
includePipeline=IDataUtil.getString(asExistingDocCur, "document_data");

startExec=IDataUtil.getString(asExistingDocCur, "startExecution");
stopExec=IDataUtil.getString(asExistingDocCur, "stopExecution");


if(includePipeline.equalsIgnoreCase("0"))
{
includePipeline="Never";
}
if(includePipeline.equalsIgnoreCase("1"))
{
includePipeline="On errors only";
}
if(includePipeline.equalsIgnoreCase("2"))
{
includePipeline="Always";
}

if(startExec.equalsIgnoreCase("false") && stopExec.equalsIgnoreCase("false"))
{
logOn="Error only";
}
if(startExec.equalsIgnoreCase("false") && stopExec.equalsIgnoreCase("true"))
{
logOn="Error and success";
}
if(startExec.equalsIgnoreCase("true") && stopExec.equalsIgnoreCase("true"))
{
logOn="Error , success and start";
}

// pipeline
IDataCursor pipelineCursor_1 = pipeline.getCursor();
IDataUtil.put( pipelineCursor_1, "enableAudit", enableAudit);
IDataUtil.put( pipelineCursor_1, "includePipeline", includePipeline);
IDataUtil.put( pipelineCursor_1, "logOn", logOn);
pipelineCursor_1.destroy();

}


Here is a sample code to set the audit property of the flow services. This service is in raw format , you need to modify it according to your requirements.

import com.wm.data.*;
import com.wm.util.Values;
import com.wm.app.b2b.server.Service;
import com.wm.app.b2b.server.ServiceException;
import com.wm.app.b2b.server.ns.Namespace;
import com.wm.lang.ns.NSName;
import com.wm.lang.ns.NSNode;
import com.wm.lang.ns.NSService;
import com.wm.lang.ns.AuditSettings;

public final class setServiceAuditProperty_SVC

{

/**
* The primary method for the Java service
*
* @param pipeline
*            The IData pipeline
* @throws ServiceException
*/
public static final void setServiceAuditProperty(IData pipeline) throws ServiceException {
// pipeline
IDataCursor pipelineCursor = pipeline.getCursor();
String serviceName = IDataUtil.getString( pipelineCursor, "serviceName" );
String enableAudit = IDataUtil.getString( pipelineCursor, "enableAudit" );
String logOn = IDataUtil.getString( pipelineCursor, "logOn" );
String includePipeline = IDataUtil.getString( pipelineCursor, "includePipeline" );
//String packageName="";
String status="success";

pipelineCursor.destroy();

try
{

int enableAuditOptionInt = Integer.parseInt(enableAudit);
int includePipelineInt=Integer.parseInt(includePipeline);

  NSName localNSName=NSName.create(serviceName);
  NSService localNSService=Namespace.getService(localNSName);
 
  localNSService.setAuditOption(enableAuditOptionInt); // Setting Enable Auditing Property
 
 
  AuditSettings asNew=new AuditSettings();
 
  asNew.enableDocumentAudit(includePipelineInt); //Setting Include Pipeline Property
 
  if(logOn.equalsIgnoreCase("0"))
  {
  asNew.enableErrorAudit(true);  //Setting LogOn Property = Error only
  }
  if(logOn.equalsIgnoreCase("1"))
  {
  asNew.enableCompleteAudit(true); //Setting LogOn Property = Error and Success
  asNew.enableErrorAudit(true);
  }
  if(logOn.equalsIgnoreCase("2"))
  {
  asNew.enableStartAudit(true); //Setting LogOn Property = Error success and start
  asNew.enableCompleteAudit(true);
  asNew.enableErrorAudit(true);
 
  }
 
  localNSService.setAuditSettings(asNew); //setting new Audit Settings for the Service
}
catch(Exception e)
{
status="failed";
}
 

// pipeline
IDataCursor pipelineCursor_1 = pipeline.getCursor();
IDataUtil.put( pipelineCursor_1, "status", status);
pipelineCursor_1.destroy();


}

Enjoy Reading , If you have any Question related to webMethods please comment below , I will try to answer the questions.Please Subscribe for latest update on the blogs

Post a Comment

5 Comments

  1. Hi Rakesh,

    In line no 5 of the above code you are using "NSService localNSService=Namespace.current().getService(localNSName);".What this "Namespace" suggest?Is it methods from "import com.wm.lang.ns.Namespace",if so then here it does not contain any method as current.I am getting error here.

    ReplyDelete
  2. It's working now.Needs to import "com.wm.app.b2b.server.ns.Namespace;" instead of ""import com.wm.lang.ns.Namespace""

    ReplyDelete
    Replies
    1. Yes Baharul , you need to import the com.wm.app.b2b.server.ns.Namespace; class . Thanks for the update.

      Delete
  3. Hello Rakesh,
    Thanl you for your tutorial, it's realy helpfull.
    Please, could you make for use a tutorial about Traiding Network, how to put document and how to read document in/from TN.
    Thank you for your help.
    Rachid

    ReplyDelete
  4. Hello Rachid ,

    Thanks for your comments . 2018 is going to be an exciting year and new updates and posts will be published regarding B2B Integration i.e. Trading Networks , EDI , Flatfiles , AseXMls , ebXMls etc.

    Please tune in and subscribe to the blog for more updates

    ReplyDelete