Custom Java Components - Accessing Workspace Directory

Support/help with CloverETL (4.9) and CloverDX (5.0 or newer) implementation problems

pfield
Posts: 20
Joined: Thu Mar 19, 2020 3:46 pm

Custom Java Components - Accessing Workspace Directory

Postby pfield » Tue Jan 19, 2021 6:32 pm

Hi,

I have a Custom Java Component that collects a file from my project workspace for processing based on an input port field value. Everything works fine, however, in order to access the file I need to provide the full file path from my C Drive despite the file sitting in a project directory. This is inconvenient as if I ever move the component to a different project I would need to rekey in the project location.

Here is a snippet of my current code

Code: Select all

String WorkingFolder = "C:/Users/<My User>/clover_workspace/<clover project>";
      String Dir = getProperties().getStringProperty("Directory");
      
      DataRecord inRecord = inRecords[0];
      DataRecord outRecord = outRecords[0];
      
      while ((inRecord = readRecordFromPort(0)) != null) {
         
         String fileUrl = WorkingFolder+Dir+inRecord.getField(0).getValue().toString();
...



Is there a more elegant way to achieve this? I tried using the project Graph Parameter via graph.getGraphParameters() but it returns "." as opposed to the full file path.


Thanks,
Paul

pfield
Posts: 20
Joined: Thu Mar 19, 2020 3:46 pm

Re: Custom Java Components - Accessing Workspace Directory

Postby pfield » Wed Jan 20, 2021 12:04 pm

Hi,

After some more exploration of the graph parameters I found SANDBOX_ROOT which gives me the path I was looking for.

Code: Select all

String WorkingFolder = getGraph().getGraphParameters().getGraphParameter("SANDBOX_ROOT").getValue();


Paul

jandikovae
Posts: 63
Joined: Fri Nov 04, 2016 8:51 am

Re: Custom Java Components - Accessing Workspace Directory

Postby jandikovae » Mon Jan 25, 2021 9:34 am

Hi Paul,

Yes, the SANDBOX_ROOT parameter is exactly what I would suggest in your case. You can find the list of parameters on the following page:
https://doc.cloverdx.com/latest/server/graph-parameters.html
Please don't get confused by the fact that this documentation page points to the Server related topic. These parameters can be all used by the Designer as well.

Have a nice day, Eva
---
Eva Jandikova
CloverCARE Support
CloverDX

Visit us online at http://www.cloverdx.com


cron