Export with Scheduler Task
When you need to generate reports
periodically or
on a designated date-time or
with big data
You can create tasks to generate reports automatically as scheduled.
scheduler.createTask()
String taskID = scheduler.createTask(serverInfo, configMap, exportMap);
createTask.jsp
<%@ page language="java"
contentType="text/html; charset=UTF-8"
import="oz.scheduler.*,
oz.framework.api.*,
oz.util.SortProperties,
oz.framework.cp.OZCPException,
org.apache.log4j.*,
java.util.*,
java.io.*"
%><%
request.setCharacterEncoding("UTF-8");
String dt = request.getParameter("dt");
String serverUrl = "http://localhost/oz/server";
String serverID = "admin";
String serverPW = "password";
String schedulerIp = "127.0.0.1";
int schedulerPort = 9521;
String ozrName = "order";
String odiName = "order";
String exportFormat = "pdf";
String exportFileName = "order";
int ozrParamCnt = 0;
int odiParamCnt = 0;
String exYear = dt.substring(0,4);
String exMonth = dt.substring(5,7);
String exDay = dt.substring(7,9);
String exHour = dt.substring(10,12);
String exMin = dt.substring(12,14);
String reportPath = "demo/" + ozrName + ".ozr";
Scheduler scheduler = new Scheduler(schedulerIp, schedulerPort);
Publisher publisher = new Publisher(schedulerIp, schedulerPort);
Service service = new Service(serverUrl, serverID, serverPW, false, false);
ServerInfo serverInfo = new ServerInfo();
SortProperties configMap = new SortProperties();
SortProperties exportMap = new SortProperties();
%><%
try {
if (!service.ping()) {
out.println("ERROR: Cannot connect to OZ Server [" + serverUrl + "]");
if (true) return ;
}
if (!scheduler.ping()) {
out.println("ERROR: Cannot connect to OZ Scheduler [" + schedulerIp + ":" + schedulerPort + "]");
if (true) return ;
}
// OZ Server connection
serverInfo.setURL(serverUrl);
serverInfo.setID(serverID);
serverInfo.setPWD(serverPW);
serverInfo.setIsDaemon(false);
// Task parameters
configMap.setProperty("launch_type", "once"); // Task schedule option: 'immediately', 'once', 'periodically'
configMap.setProperty("cfg.type", "new"); // Task type option: 'new', 'edit'
configMap.setProperty("task_type", "viewerTag"); // Use Viewer parameters for task run option
// Export parameters
exportMap.setProperty("connection.servlet", serverUrl); // OZ Server connection
exportMap.setProperty("connection.reportname", reportPath); // OZR file name (full path)
exportMap.setProperty("viewer.mode", "export");
exportMap.setProperty("export.mode", "silent");
exportMap.setProperty("export.confirmsave", "false");
exportMap.setProperty("export.format", exportFormat);
exportMap.setProperty(exportFormat + ".filename", exportFileName + "." + exportFormat);
/* Form Parameters
exportMap.setProperty("connection.pcount", pcount);
export.setProperty("connection.args1", "param1=value");
*/
/* ODI Parameters
exportMap.setProperty("odi.odinames", odiName);
exportMap.setProperty("odi." + odiName + ".pcount", pcount);
exportMap.setProperty("odi.odiName.args1", "param1=value");
*/
// schedule
configMap.setProperty("execution_year", exYear);
configMap.setProperty("execution_month", exMonth);
configMap.setProperty("execution_day", exDay);
configMap.setProperty("execution_hour", exHour);
configMap.setProperty("execution_min", exMin);
// request Scheduler to create a task
String taskID = scheduler.createTask(serverInfo, configMap, exportMap);
out.println("taskID=" + taskID);
}
catch (Exception e) {
out.println("Exception: " + e.getMessage());
return;
}
%>
scheduler.getTaskResult()
TaskResult[] taskList = scheduler.getTaskResult(serverInfo, from, to, taskID);
Member variables:
String taskID
String taskName
String taskGroupName
String completedTime
Boolean isSuccessfulCode : 400001(Succeeded), etc.
Boolean isSuccessful : Failed, Succeeded, Export
String formFileName
String Parameter
String schedulingType : immediately, once, periodically
String formCategoryName
String exportFileList
int pageCount
String errorMsg
getTaskResult.jsp
<%@ page language="java"
contentType="text/html; charset=UTF-8"
import="oz.scheduler.*,
oz.framework.api.*,
oz.util.SortProperties,
oz.framework.cp.OZCPException,
org.apache.log4j.*,
java.util.*,
java.io.*"
%><%
request.setCharacterEncoding("UTF-8");
String taskID = request.getParameter("taskID");
String serverUrl = "http://localhost/oz/server";
String serverID = "admin";
String serverPW = "password";
String schedulerIp = "127.0.0.1";
int schedulerPort = 9521;
String exportFormat = "pdf";
String exportPath = "C:\\Program Files\\Apache Software Foundation\\Tomcat 9.0\\webapps\\exported\\demo\\";
%>
<%
Scheduler scheduler = new Scheduler(schedulerIp, schedulerPort);
Publisher publisher = new Publisher(schedulerIp, schedulerPort);
Service service = new Service(serverUrl, serverID, serverPW, false, false);
ServerInfo serverInfo = new ServerInfo();
if (taskID == "") { out.println("taskID is required"); return; }
try {
if (!service.ping()) {
out.println("ERROR: Cannot connect to OZ Server [" + serverUrl + "]");
if (true) return ;
}
if (!scheduler.ping()) {
out.println("ERROR: Cannot connect to OZ Scheduler [" + schedulerIp + ":" + schedulerPort + "]");
if (true) return ;
}
// OZ Server connection
serverInfo.setURL(serverUrl);
serverInfo.setID(serverID);
serverInfo.setPWD(serverPW);
serverInfo.setIsDaemon(false);
// Rresult of task
TaskResult[] taskList = scheduler.getTaskResult(serverInfo, "", "", taskID);
if (taskList.length == 0) {
out.println("Task not found.");
return;
}
// a single task can have multiple documents
for (int i = 0; i < taskList.length; i++) {
TaskResult result = taskList[i];
if ("Succeeded".equals(result.isSuccessful)) {
out.println("getTaskResult: " + result.isSuccessfulCode +", "+ result.isSuccessful +", "+ result.taskID);
}
else {
out.println("errorMsg : " + new String(taskList[i].errorMsg.getBytes("8859_1"),"UTF-8"));
}
}
}
catch (Exception e) {
out.println("Exception: " + e.getMessage());
return;
}
%>
Last updated
Was this helpful?