on 03-25-2013 3:40 PM
Hi,
We have CPS version M33.69-61130.
Few of our Windows batch job definitions have directory paths as parameters(Custom defined).
Now, i am using the following code to change the substring of the directory, but to no avail.
//Changing the Job definition prefixes
{
for (java.util.Iterator it = jcsImportRuleSet.getObjects().iterator(); it.hasNext(); )
{
Object o = (Object) it.next();
if (o instanceof JobDefinition)
{
JobDefinition jd = (JobDefinition) o;
//Changing the Src path parameters
JobDefinitionParameter jp2 = jd.getJobDefinitionParameterByName("Src_Path");
if (jp2 != null && jp2.getDefaultExpression() != null && jp2.getDefaultExpression().indexOf("x_qa_sap") >= 0)
{
jp2.setDefaultExpression(jp2.getDefaultExpression().replaceFirst("x_qa_sap","x_dev_sap"));
}
}
}
}
I parameter Src_Path will have the following Default Expression.
\\somedrive\x_qa_sap\ABC\XYZ\Out\ZDI_016\
After import, i always get a NULL string for the parameter.
I tried the following considering the escape char '\'
replaceFirst("\\x_qa_sap\\","\\x_dev_sap\\")
replaceFirst("(.*)\\x_qa_sap\\(.*)","\\x_dev_sap\\")
I'm wondering whether getdefaultExpression() itself is returning a NULL value.
Please let me know what am i doing wrong.
Thanks
Nanda
I have a really different problem now, when i use the following snippet alone, as an import action
{
for (java.util.Iterator it = jcsImportRuleSet.getObjects().iterator(); it.hasNext(); )
{
Object o = (Object) it.next();
if (o instanceof JobDefinition)
{
JobDefinition jd = (JobDefinition) o;
//Changing the Src path parameters
JobDefinitionParameter jp2 = jd.getJobDefinitionParameterByName("Src_Path");
JobDefinitionParameter jp3 = jd.getJobDefinitionParameterByName("Arc_Path");
jp2.setDefaultExpression(jp2.getDefaultExpression().replaceAll("x_qa_sap","x_dev_sap"));
jp3.setDefaultExpression(jp3.getDefaultExpression().replaceAll("x_qa_sap","x_dev_sap"));
}
}
}
The string gets replaced and it works completely fine, but when i use it along with a different code(mentioned below) , i get an error.
Caused by: java.lang.NullPointerException: while trying to invoke the method java.lang.String.replaceAll(java.lang.String, java.lang.String) of an object returned from com.redwood.scheduler.api.model.JobDefinitionParameter.getDefaultExpression()
The code i am trying to use is
//Changing the Job definition prefixes
{
for (java.util.Iterator it = jcsImportRuleSet.getObjects().iterator(); it.hasNext(); )
{
Object o = (Object) it.next();
if (o instanceof JobDefinition)
{
JobDefinition jd = (JobDefinition) o;
//Changing the SAP Job Name prefixes
// JobDefinitionParameter jp1 = jd.getJobDefinitionParameterByName("JOBNAME");
//Changing the Src path & Arc path parameters
JobDefinitionParameter jp2 = jd.getJobDefinitionParameterByName("Src_Path");
JobDefinitionParameter jp3 = jd.getJobDefinitionParameterByName("Arc_Path");
if (jd.getName().contains("ZDI"))
{
jp2.setDefaultExpression(jp2.getDefaultExpression().replaceAll("x_qa_sap","x_dev_sap"));
jp3.setDefaultExpression(jp3.getDefaultExpression().replaceAll("x_qa_sap","x_dev_sap"));
}
}
}
}
this is just bizarre for me! Can some one please help me understand what is wrong with the above code and why i am getting an Null pointer exception only while using the replaceAll() method?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Nanda,
It looks like one of your job definitions does not contain a default value.
Most of the time it is better to use the 'safe' approach like this;
JobDefinitionParameter jp = jd.getJobDefinitionParameterByName("Src_Path");
if (jp != null) // maybe your job definition does not have this parameter
{
if (jp.getDefaultExpression() != null) // if the current value is empty, there is nothing to replace
{
...
}
}
Regards Gerben
User | Count |
---|---|
83 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.