Hitachi Vantara Pentaho Community Forums
Results 1 to 8 of 8

Thread: Read JobXML via Javascript

  1. #1
    Join Date
    Oct 2011
    Posts
    15

    Default Read JobXML via Javascript

    Hi,

    i am wondering how to get the xml-definition of an existing job out of an database repository via Java-Script.

    At the moment i have the following script

    var log = Packages.org.pentaho.di.core.logging.LogWriter.getInstance();
    var jobMeta = new Packages.org.pentaho.di.job.JobMeta(log, "/Job1.kjb", null);
    var jobXML = jobMeta.getXML();

    which returns me the XML-defintion of Job1 located at c:\job1.kjb and puts it into the field "jobXML".

    The problem is that I store my repository in database and want to read the XML-definition from a job stored in this repository (that I am currently connectd to), say "/Job1".

    Can anyone help me to specify the corresponding call to PDI API - if it's possible?

    Thanks

    Thomas

  2. #2
    Join Date
    Sep 2009
    Posts
    810

    Default

    Hey Thomas,

    Check out Roland's krex project
    http://code.google.com/p/krex/

    Cheers
    Slawo

  3. #3
    Join Date
    Oct 2011
    Posts
    15

    Default

    Hi Slawo,

    I know the krex project. The Problem is, that i dont want to export anything to filesystem. I want to get XML specifications of jobs and transformations out of my database-repository and transform these information whithin PDI.

    Roland uses "export repostitory to xml-file" and works on the filesystem.

    Cheers

    Thomas

  4. #4
    Join Date
    Nov 1999
    Posts
    9,729

    Default

    You can use the autodoc step in 4.2 to read the JobMeta object.

  5. #5
    Join Date
    Sep 2009
    Posts
    810

    Default

    Hi Thomas,

    sorry about that, I kind of assumed that it was all the same to you to export the job in question to the file system first.

    Code:
    var name = 'Job 1';
    var directory = '/home/joe'
    
    var repo = _step_.getTrans().getRepository();
    var transJob = repo.loadJob(name, repo.findDirectory(directory), null, null);
    
    var xml = transJob.getXML();
    Cheers
    Slawo

  6. #6
    Join Date
    Oct 2011
    Posts
    15

    Default

    Hello Slawo,

    i am sorry, but your statement does not work. When I insert it into a Java-Script step and preview results, i allways get:

    Code:
    2011/10/20 16:23:04 - ## TEST DATA ##.0 - Finished processing (I=0, O=0, R=0, W=10, U=0, E=0)
    2011/10/20 16:23:04 - Modified Java Script Value.0 - ERROR (version 3.2.5-zeb-4 from 2011-03-31 09.35.52) : Unexpected error : 
    2011/10/20 16:23:04 - Modified Java Script Value.0 - ERROR (version 3.2.5-zeb-4 from 2011-03-31 09.35.52) : org.pentaho.di.core.exception.KettleValueException: 
    2011/10/20 16:23:04 - Modified Java Script Value.0 - ERROR (version 3.2.5-zeb-4 from 2011-03-31 09.35.52) : Javascript error: 
    2011/10/20 16:23:04 - Modified Java Script Value.0 - ERROR (version 3.2.5-zeb-4 from 2011-03-31 09.35.52) : TypeError: Cannot call method "loadJob" of null (script#5)
    2011/10/20 16:23:04 - Modified Java Script Value.0 - ERROR (version 3.2.5-zeb-4 from 2011-03-31 09.35.52) : 
    2011/10/20 16:23:04 - Modified Java Script Value.0 - ERROR (version 3.2.5-zeb-4 from 2011-03-31 09.35.52) :     at org.pentaho.di.trans.steps.scriptvalues_mod.ScriptValuesMod.addValues(ScriptValuesMod.java:436)
    2011/10/20 16:23:04 - Modified Java Script Value.0 - ERROR (version 3.2.5-zeb-4 from 2011-03-31 09.35.52) :     at org.pentaho.di.trans.steps.scriptvalues_mod.ScriptValuesMod.processRow(ScriptValuesMod.java:667)
    2011/10/20 16:23:04 - Modified Java Script Value.0 - ERROR (version 3.2.5-zeb-4 from 2011-03-31 09.35.52) :     at org.pentaho.di.trans.step.BaseStep.runStepThread(BaseStep.java:2890)
    2011/10/20 16:23:04 - Modified Java Script Value.0 - ERROR (version 3.2.5-zeb-4 from 2011-03-31 09.35.52) :     at org.pentaho.di.trans.steps.scriptvalues_mod.ScriptValuesMod.run(ScriptValuesMod.java:731)
    2011/10/20 16:23:04 - Modified Java Script Value.0 - ERROR (version 3.2.5-zeb-4 from 2011-03-31 09.35.52) : Caused by: org.mozilla.javascript.EcmaError: TypeError: Cannot call method "loadJob" of null (script#5)
    2011/10/20 16:23:04 - Modified Java Script Value.0 - ERROR (version 3.2.5-zeb-4 from 2011-03-31 09.35.52) :     at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3557)
    2011/10/20 16:23:04 - Modified Java Script Value.0 - ERROR (version 3.2.5-zeb-4 from 2011-03-31 09.35.52) :     at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3535)
    2011/10/20 16:23:04 - Modified Java Script Value.0 - ERROR (version 3.2.5-zeb-4 from 2011-03-31 09.35.52) :     at org.mozilla.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3563)
    2011/10/20 16:23:04 - Modified Java Script Value.0 - ERROR (version 3.2.5-zeb-4 from 2011-03-31 09.35.52) :     at org.mozilla.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3582)
    2011/10/20 16:23:04 - Modified Java Script Value.0 - ERROR (version 3.2.5-zeb-4 from 2011-03-31 09.35.52) :     at org.mozilla.javascript.ScriptRuntime.undefCallError(ScriptRuntime.java:3601)
    2011/10/20 16:23:04 - Modified Java Script Value.0 - ERROR (version 3.2.5-zeb-4 from 2011-03-31 09.35.52) :     at org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:2160)
    2011/10/20 16:23:04 - Modified Java Script Value.0 - ERROR (version 3.2.5-zeb-4 from 2011-03-31 09.35.52) :     at org.mozilla.javascript.gen.c2._c0(script:5)
    2011/10/20 16:23:04 - Modified Java Script Value.0 - ERROR (version 3.2.5-zeb-4 from 2011-03-31 09.35.52) :     at org.mozilla.javascript.gen.c2.call(script)
    2011/10/20 16:23:04 - Modified Java Script Value.0 - ERROR (version 3.2.5-zeb-4 from 2011-03-31 09.35.52) :     at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:401)
    2011/10/20 16:23:04 - Modified Java Script Value.0 - ERROR (version 3.2.5-zeb-4 from 2011-03-31 09.35.52) :     at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3003)
    2011/10/20 16:23:04 - Modified Java Script Value.0 - ERROR (version 3.2.5-zeb-4 from 2011-03-31 09.35.52) :     at org.mozilla.javascript.gen.c2.call(script)
    2011/10/20 16:23:04 - Modified Java Script Value.0 - ERROR (version 3.2.5-zeb-4 from 2011-03-31 09.35.52) :     at org.mozilla.javascript.gen.c2.exec(script)
    2011/10/20 16:23:04 - Modified Java Script Value.0 - ERROR (version 3.2.5-zeb-4 from 2011-03-31 09.35.52) :     at org.pentaho.di.trans.steps.scriptvalues_mod.ScriptValuesMod.addValues(ScriptValuesMod.java:355)
    2011/10/20 16:23:04 - Modified Java Script Value.0 - ERROR (version 3.2.5-zeb-4 from 2011-03-31 09.35.52) :     ... 3 more
    Can you tell me, whats wrong?

    Thanks and greetings

    Thomas

  7. #7
    Join Date
    Sep 2009
    Posts
    810

    Default

    hi there,
    two things come to mind:

    1 - Make sure Spoon is connected to a repository when you run this
    2 - It works for me on 4.2, have not tried it on 3.2.5

    The error says that there is no repository object to call "loadJob" on, so make sure the transformation is run from a repo.

    Cheers
    Slawo

  8. #8
    Join Date
    Oct 2011
    Posts
    15

    Default

    Hi Slawo,

    thanks for the fast reply. Now i have integrated your snipplet into a simple transformation and call this trafo out of a job. Then it works! Just pressing "Test script" within the Java Script step results in the error mentioned before.

    Great!

    Thanks

    Thomas

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.