FileUtils.forceDelete(new File(jobMap.remove(jobPrecedence.remove(0))));
if (spec.getJob().getId() == null)
spec.getJob().setId(UUID.randomUUID().toString());
else if (this.jobMap.containsKey(spec.getJob().getId()))
throw new JobRepositoryException("JobId '" + spec.getJob().getId() + "' already in use -- must pick unique JobId");
File file = this.generateFilePath(spec.getJob().getId());
os = new FileOutputStream(file);
xstream.toXML(spec, os);
jobMap.put(spec.getJob().getId(), file.getAbsolutePath());
jobPrecedence.add(spec.getJob().getId());
return spec.getJob().getId();
}catch (Exception e) {
throw new JobRepositoryException("Failed to add job spec to repo : " + e.getMessage(), e);
}finally {
try {
os.close();
}catch (Exception e) {}
}