String taskClass = request.getParameter("taskClass");
if (taskClass == null || "".equals(taskClass)) {
handleException("Task Class cannot be null or empty");
}
TaskDescription taskDescription = new TaskDescription();
taskDescription.setName(name.trim());
taskDescription.setGroup(group.trim());
taskDescription.setTaskClass(taskClass.trim());
String trigger = request.getParameter("taskTrigger");
if (trigger != null && !"".equals(trigger)) {
if ("simple".equals(trigger)) {
String interval = request.getParameter("triggerInterval");
if (interval != null && !"".equals(interval)) {
try {
taskDescription.setInterval(Long.parseLong(interval.trim()) * 1000);
} catch (NumberFormatException e) {
handleException("Invalid value for interval (Expected type is long) : " +
interval);
}
}
String count = request.getParameter("triggerCount");
if (count != null && !"".equals(count)) {
try {
taskDescription.setCount(Integer.parseInt(count.trim()));
} catch (NumberFormatException e) {
handleException("Invalid value for Count (Expected type is int) : " +
count);
}
}
} else if ("cron".equals(trigger)) {
String cron = request.getParameter("triggerCron");
if (cron != null && !"".equals(cron)) {
taskDescription.setCron(cron.trim());
} else {
handleException("Cron expression cannot be empty for cron trigger");
}
}
} else {
handleException("No Trigger has been selected");
}
String pinnedServers = request.getParameter("pinnedServers");
if (pinnedServers != null || !"".equals(pinnedServers)) {
StringTokenizer st = new StringTokenizer(pinnedServers, " ,");
List<String> pinnedServersList = new ArrayList<String>();
while (st.hasMoreTokens()) {
String token = st.nextToken();
if (token.length() != 0) {
pinnedServersList.add(token);
}
}
taskDescription.setPinnedServers(pinnedServersList);
}
String propertyCount = request.getParameter("propertyCount");
if (propertyCount != null && !"".equals(propertyCount)) {
try {
int propCount = Integer.parseInt(propertyCount.trim());
if (log.isDebugEnabled()) {
log.debug("Number of properties : " + propCount);
}
for (int i = 0; i < propCount; i++) {
String id = "property_name_hidden" + String.valueOf(i);
String propName = request.getParameter(id);
if (propName != null && !"".equals(propName)) {
String propertyType = request.getParameter("propertyTypeSelection" +
String.valueOf(i));
if ("literal".equals(propertyType)) {
String value = request.getParameter("textField" + String.valueOf(i));
if (log.isDebugEnabled()) {
log.debug("[ Property Name : " + name + " ]" +
"[ Property Value : " + value + " ]");
}
if (value != null && !"".equals(value)) {
OMElement propElem = FACTORY.createOMElement("property",
TASK_OM_NAMESPACE);
OMNamespace nullNS = FACTORY.createOMNamespace("", "");
propElem.addAttribute("name", propName.trim(), nullNS);
propElem.addAttribute("value", value.trim(), nullNS);
taskDescription.addProperty(propElem);
}
} else if ("xml".equals(propertyType)) {
String value = request.getParameter("textArea" + String.valueOf(i));
if (log.isDebugEnabled()) {
log.debug("[ Property Name : " + name + " ][ Property Value : " +
value + " ]");
}
if (value != null && !"".equals(value)) {
OMElement propElem = FACTORY.createOMElement("property",
TASK_OM_NAMESPACE);
OMNamespace nullNS = FACTORY.createOMNamespace("", "");
propElem.addAttribute("name", propName.trim(), nullNS);
try {
propElem.addChild(createOMElement(value.trim()));
} catch (Throwable e) {
handleException("Invalid XML has been provided " +
"for property : " + propName);
}
taskDescription.addProperty(propElem);
}
}
}
}
} catch (NumberFormatException ignored) {