if (null != idlistFilter) {
params.put("idlist", idlistFilter);
}
//2. send request via ServerService
final WebserviceResponse response;
try {
response = serverService.makeRundeckRequest(RUNDECK_API_JOBS_EXPORT_PATH, params, null, null,
expectedContentType, null);
} catch (MalformedURLException e) {
throw new CentralDispatcherServerRequestException("Failed to make request", e);
}
checkErrorResponse(response);
//if xml, do local validation and listing
if (null == fformat || fformat == JobDefinitionFileFormat.xml) {
validateJobsResponse(response);
////////////////////
//parse result list of queued items, return the collection of QueuedItems
///////////////////
final Document resultDoc = response.getResultDoc();
final Node node = resultDoc.selectSingleNode("/joblist");
final ArrayList<IStoredJob> list = new ArrayList<IStoredJob>();
if (null == node) {
return list;
}
final List items = node.selectNodes("job");
if (null != items && items.size() > 0) {
for (final Object o : items) {
final Node node1 = (Node) o;
final Node uuid = node1.selectSingleNode("uuid");
final Node id1 = node1.selectSingleNode("id");
final String id = null!=uuid?uuid.getStringValue():id1.getStringValue();
final String name = node1.selectSingleNode("name").getStringValue();
final String url = createJobURL(id);
final Node gnode = node1.selectSingleNode("group");
final String group = null != gnode ? gnode.getStringValue() : null;
final String description = node1.selectSingleNode("description").getStringValue();
list.add(StoredJobImpl.create(id, name, url, group, description, projectFilter));
}
}
if (null != output) {
//write output doc to the outputstream
final OutputFormat format = OutputFormat.createPrettyPrint();
try {
final XMLWriter writer = new XMLWriter(output, format);
writer.write(resultDoc);
writer.flush();
} catch (IOException e) {
throw new CentralDispatcherServerRequestException(e);
}
}
return list;
} else if (fformat == JobDefinitionFileFormat.yaml) {
//do rough yaml parse
final Collection<Map> mapCollection;
//write to temp file
File temp;
InputStream tempIn;
try {
temp= File.createTempFile("listStoredJobs", ".yaml");
temp.deleteOnExit();
OutputStream os = new FileOutputStream(temp);
try{
Streams.copyStream(response.getResultStream(), os);
}finally {
os.close();
}
tempIn = new FileInputStream(temp);
try {