Element ee = (Element) nl.item(i);
canBeRestarted = ("true".equals(ee.getElementsByTagName("canBeRestarted").item(0).getTextContent())) ? true : false;
javaClassName = ee.getElementsByTagName("javaClassName").item(0).getTextContent();
JobDef jd;
TypedQuery<JobDef> q = em.createQuery("SELECT j FROM JobDef j WHERE j.applicationName = :n", JobDef.class);
q.setParameter("n", ee.getElementsByTagName("name").item(0).getTextContent());
if (q.getResultList().size() == 1)
{
jd = q.getResultList().get(0);
jd.getParameters().clear();
}
else
{
jd = new JobDef();
}
// Queue
if (jd.getQueue() == null && ee.getElementsByTagName("queue").getLength() != 0)
{
// Specified inside the XML. Does the queue already exist?
String qname = ee.getElementsByTagName("queue").item(0).getTextContent();
try
{
queue = em.createQuery("SELECT q FROM Queue q WHERE q.name = :name", Queue.class)
.setParameter("name", qname).getSingleResult();
// The queue exists
}
catch (NoResultException noe)
{
// The queue must be created.
if (createdQueues.containsKey(qname))
{
queue = createdQueues.get(qname);
}
else
{
queue = new Queue();
queue.setDescription("Created from a jobdef import. Description should be set later");
queue.setName(qname);
em.persist(queue);
createdQueues.put(qname, queue);
}
}
}
else
{
// Not specified => default queue
queue = em.createQuery("SELECT q FROM Queue q WHERE q.defaultQueue = true", Queue.class).getSingleResult();
}
// Easy attributes
description = ee.getElementsByTagName("description").item(0).getTextContent();
applicationName = ee.getElementsByTagName("name").item(0).getTextContent();
application = ee.getElementsByTagName("application").item(0).getTextContent();
module = ee.getElementsByTagName("module").item(0).getTextContent();
// Keyword used to be called "other". We allow both for ascending compatibility. ("other" is deprecated - don't use)
if (ee.getElementsByTagName("other1").getLength() > 0 && ee.getElementsByTagName("other2").getLength() > 0
&& ee.getElementsByTagName("other3").getLength() > 0)
{
keyword1 = ee.getElementsByTagName("other1").item(0).getTextContent();
keyword2 = ee.getElementsByTagName("other2").item(0).getTextContent();
keyword3 = ee.getElementsByTagName("other3").item(0).getTextContent();
}
else if (ee.getElementsByTagName("keyword1").getLength() > 0 && ee.getElementsByTagName("keyword2").getLength() > 0
&& ee.getElementsByTagName("keyword3").getLength() > 0)
{
keyword1 = ee.getElementsByTagName("keyword1").item(0).getTextContent();
keyword2 = ee.getElementsByTagName("keyword2").item(0).getTextContent();
keyword3 = ee.getElementsByTagName("keyword3").item(0).getTextContent();
}
highlander = ("true".equals(ee.getElementsByTagName("highlander").item(0).getTextContent())) ? true : false;
jarPath = e.getElementsByTagName("path").item(0).getTextContent();
NodeList l = ee.getElementsByTagName("parameter");
for (int j = 0; j < l.getLength(); j++)
{
Element t = (Element) l.item(j);
JobDefParameter jdp = new JobDefParameter();
jdp.setKey(t.getElementsByTagName("key").item(0).getTextContent());
jdp.setValue(t.getElementsByTagName("value").item(0).getTextContent());
jd.getParameters().add(jdp);
}
jd.setCanBeRestarted(canBeRestarted);
jd.setJavaClassName(javaClassName);
jd.setQueue(queue);
jd.setApplicationName(applicationName);
jd.setApplication(application);
jd.setModule(module);
jd.setKeyword1(keyword1);
jd.setKeyword2(keyword2);
jd.setKeyword3(keyword3);
jd.setHighlander(highlander);
jd.setJarPath(jarPath);
jd.setDescription(description);
em.persist(jd);
jqmlogger.info("Imported application " + applicationName);
}
}