/** * Copyright © 2013 enioka. All rights reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package pyl; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; import java.util.HashMap; import java.util.Map; import com.enioka.jqm.api.JobManager; public class EngineApiInjectThread implements Runnable { // This will be injected by the JQM engine - it could be named anything JobManager jm; @Override public void run() { // Using JQM variables System.out.println("run method of runnable payload with API"); System.out.println("JobDefID: " + jm.jobApplicationId()); System.out.println("Application: " + jm.application()); System.out.println("JobName: " + jm.applicationName()); System.out.println("Default JDBC: " + jm.defaultConnect()); System.out.println("Keyword1: " + jm.keyword1()); System.out.println("Keyword2: " + jm.keyword2()); System.out.println("Keyword3: " + jm.keyword3()); System.out.println("Module: " + jm.module()); System.out.println("Session ID: " + jm.sessionID()); System.out.println("Restart enabled: " + jm.canBeRestarted()); System.out.println("JI ID: " + jm.jobInstanceID()); System.out.println("Parent JI ID: " + jm.parentID()); System.out.println("Nb of parameters: " + jm.parameters().size()); // Sending info to the user jm.sendProgress(10); jm.sendMsg("houba hop"); // Working with a temp directory File workDir = jm.getWorkDir(); System.out.println("Work dir is " + workDir.getAbsolutePath()); // Creating a file made available to the end user (PDF, XLS, ...) PrintWriter writer; File dest = new File(workDir, "marsu.txt"); try { writer = new PrintWriter(dest, "UTF-8"); } catch (FileNotFoundException e) { e.printStackTrace(); return; } catch (UnsupportedEncodingException e) { e.printStackTrace(); return; } writer.println("The first line"); writer.println("The second line"); writer.close(); try { jm.addDeliverable(dest.getAbsolutePath(), "TEST"); } catch (IOException e) { e.printStackTrace(); return; } // Using parameters & enqueue (both sync and async) if (jm.parameters().size() == 0) { jm.sendProgress(33); Map<String, String> prms = new HashMap<String, String>(); prms.put("rr", "2nd run"); System.out.println("creating a new async job instance request"); int i = jm.enqueue(jm.applicationName(), null, null, null, jm.application(), jm.module(), null, null, null, prms); System.out.println("New request is number " + i); jm.sendProgress(66); prms.put("rrr", "3rd run"); System.out.println("creating a new sync job instance request"); jm.enqueueSync(jm.applicationName(), null, null, null, jm.application(), jm.module(), null, null, null, prms); System.out.println("New request is number " + i + " and should be done now"); } // Done jm.sendProgress(100); } }