Using the DAS Java API is very easy. Below we will describe the steps needed to create a simple job application.
Step 1: Write the Source Code
Copy the code listed below into the a text file named SimpleJob.java.
import java.io.*;
import java.lang.*;
import ecrion.das.*;
import java.net.*;
import java.util.*;
public class SampleJob
{
public static void main(String[] args)
{
try
{
// create parameters
JobParameters rp = new JobParameters();
// create a new engine
Engine eng = new Engine();
//Make sure that this path is valid!!!
String jobPath = "C:\\Users\\Public\\Documents\\Ecrion\\Data Aggregation Server 2011\\Samples\\Job Samples\\SampleCSV.dax";
rp.Diagram = new LocalDiagram(jobPath);
//Make sure that this path is valid!!
String csvPath = "C:\\Users\Public\\Documents\\Ecrion\\Data Aggregation Server 2011\\Samples\\Database Samples\\US Presidents.csv");
//override CSV file path
rp.Diagram.Properties = new Vector();
rp.Diagram.Properties.add(new JobProperty("11", "src", csvPath));
// create an output stream
OutputStream outputStream = new FileOutputStream("C:\\Temp\\CSVSample.xml");
// render
eng.Aggregate(outputStream, rp);
// remember to close the streams
inputStream.close();
outputStream.close();
}
catch(Exception e)
{
System.out.println(e.getMessage());
};
}
}
Step 2: Compile the Code File
First locate our .jar file named Ecrion.DAS.Java.jar. It should be in C:\Program Files\Ecrion\Data Aggregation Server 2011\Client\Java or C:\Program Files (x86)\Ecrion\Data Aggregation Server 2011\Client\Java under a default installation. We'll assume that this is the case and provide the console commands under this assumption. If you have the .jar under a different path you can adapt the commands to use that location. Also make sure that you have the Java Development Kit installed. To check, search for a directory under C:\Program Files\Java that starts with the string "jdk".
Open a console, navigate using the cd command to the location where you saved your SimpleJob.java file and type the following:
> javac -cp ".;C:\Program Files\Ecrion\Data Aggregation Server 2011\Client\Java\Ecrion.DAS.Java.jar" SimpleJob.java
Step 3: Run the Program
Running the program is done using the java command.
> java -cp ".;C:\Program Files\Ecrion\Data Aggregation Server 2011\Client\Java\Ecrion.DAS.Java.jar" SimpleJob
The last command should have no output. If you have the proper write permissions on your C:\ drive, a file named jobOut.xml should appear at that location.
This concludes our "Simple Job" example. More examples can be found in your Samples folder. Read on below if you want a step by step explanation of the code.
Understanding the Code
First is creating our Engine object:
// create a new engine
Engine eng = new Engine();
Next, we'll need to create a Diagram. In our example, we will use a LocalDiagram constructed from a hard-coded string.
//Make sure that this path is valid!!!
String jobPath = "C:\\Users\\Public\\Documents\\Ecrion\\Data Aggregation Server 2011\\Samples\\Job Samples\\SampleCSV.dax";
rp.Diagram = new LocalDiagram(jobPath);
Set some job parameters. Job Parameters are used to overwrite some key resources in your job, like connection-strings, Web service URLs, etc. The
purpose is to use the same job with various data sources, or to hide some critical aspects of your jobs (like username and password from XML job).
In this sample we will overwrite the CSV file path from job <das:csv-url> element with the id 11.
Now we'll create an output stream (we'll use a FileOutputStream in this example) and call the Aggregate() method on our Engine object.
// create an output stream
OutputStream outputStream = new FileOutputStream("C:\\Temp\\CSVSample.xml");
// render
eng.Aggregate(outputStream, rp);
Also, remember to close the streams after rendering:
// remember to close the streams
inputStream.close();
outputStream.close();