Search in sources :

Example 1 with AbstractBase

use of com.twinsoft.convertigo.beans.scheduler.AbstractBase in project convertigo by convertigo.

the class CreateScheduledElements method getServiceResult.

protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
    SchedulerManager schedulerManager = Engine.theApp.schedulerManager;
    SchedulerXML schedulerXML = schedulerManager.getSchedulerXML();
    boolean edit = (request.getParameter("edit") != null);
    boolean del = (request.getParameter("del") != null);
    Type type = null;
    try {
        type = Type.valueOf(request.getParameter("type"));
    } catch (Exception e) {
        throw new ServiceException("invalide \"type\" parameter");
    }
    Element rootElement = document.getDocumentElement();
    AbstractBase ab = null;
    Exception eProb = null;
    try {
        if (edit || del) {
            String exname = ServiceUtils.getRequiredParameter(request, "exname");
            if (ScheduledJob.class.isAssignableFrom(type.c)) {
                ab = schedulerXML.getScheduledJob(exname);
            } else if (AbstractSchedule.class.isAssignableFrom(type.c)) {
                ab = schedulerXML.getSchedule(exname);
            } else if (AbstractJob.class.isAssignableFrom(type.c)) {
                ab = schedulerXML.getJob(exname);
            }
            if (del) {
                schedulerXML.delAbstractBase(ab);
                ab = null;
            }
        } else {
            ab = type.c.getConstructor().newInstance();
        }
        if (ab != null) {
            String exName = ab.getName();
            String name = ServiceUtils.getRequiredParameter(request, "name");
            ab.setName(name);
            ab.setDescription(ServiceUtils.getRequiredParameter(request, "description"));
            ab.setEnable("true".equals(ServiceUtils.getRequiredParameter(request, "enabled")));
            if (ScheduledJob.class.isAssignableFrom(type.c)) {
                ScheduledJob sj = (ScheduledJob) ab;
                sj.setJob(schedulerXML.getJob(ServiceUtils.getRequiredParameter(request, "jobName")));
                sj.setSchedule(schedulerXML.getSchedule(ServiceUtils.getRequiredParameter(request, "scheduleName")));
            } else if (AbstractSchedule.class.isAssignableFrom(type.c)) {
                AbstractSchedule as = (AbstractSchedule) ab;
                if (ScheduleCron.class.isAssignableFrom(type.c)) {
                    ScheduleCron sc = (ScheduleCron) as;
                    sc.setCron(ServiceUtils.getRequiredParameter(request, "cron"));
                }
            } else if (AbstractJob.class.isAssignableFrom(type.c)) {
                AbstractJob aj = (AbstractJob) ab;
                if (JobGroupJob.class.isAssignableFrom(type.c)) {
                    JobGroupJob jgj = (JobGroupJob) aj;
                    jgj.setParallelJob(Integer.parseInt(ServiceUtils.getRequiredParameter(request, "parallelJob")));
                    jgj.delAllJobs();
                    for (String jobname : request.getParameterValues("jobsname")) {
                        AbstractJob jobToAdd = schedulerXML.getJob(jobname);
                        if (jobToAdd != null) {
                            jgj.addJob(jobToAdd);
                        }
                    }
                } else if (AbstractConvertigoJob.class.isAssignableFrom(type.c)) {
                    AbstractConvertigoJob acj = (AbstractConvertigoJob) aj;
                    acj.setContextName(ServiceUtils.getRequiredParameter(request, "context"));
                    acj.setProjectName(ServiceUtils.getRequiredParameter(request, "project"));
                    acj.setWriteOutput("true".equals(ServiceUtils.getRequiredParameter(request, "writeOutput")));
                    if (TransactionConvertigoJob.class.isAssignableFrom(type.c)) {
                        TransactionConvertigoJob tcj = (TransactionConvertigoJob) acj;
                        tcj.setConnectorName(ServiceUtils.getParameter(request, "connector", ""));
                        tcj.setTransactionName(ServiceUtils.getParameter(request, "transaction", ""));
                    } else if (SequenceConvertigoJob.class.isAssignableFrom(type.c)) {
                        SequenceConvertigoJob scj = (SequenceConvertigoJob) acj;
                        scj.setSequenceName(ServiceUtils.getParameter(request, "sequence", ""));
                    }
                    Map<String, String[]> parameters = new HashMap<String, String[]>();
                    Matcher prefix = prefixPattern.matcher("");
                    for (String pname : Collections.list(GenericUtils.<Enumeration<String>>cast(request.getParameterNames()))) {
                        prefix.reset(pname);
                        if (prefix.find()) {
                            String para_name = prefix.group(1);
                            String[] values = request.getParameterValues(pname);
                            // for (String value : values) {
                            // parameters.put(para_name, value);
                            parameters.put(para_name, values);
                        // }
                        }
                        if (pname.equals("parameters")) {
                            String value = request.getParameter(pname);
                            if (!value.equals("0")) {
                                parameters.put("__testcase", new String[] { value });
                            }
                        }
                    }
                    acj.setParameters(parameters);
                }
            }
            List<String> problems = schedulerXML.checkProblems(ab);
            if (exName.equals(name) && edit) {
                problems.remove(SchedulerXML.prob_alreadyExist);
            }
            if (problems.size() > 0) {
                for (String problem : problems) {
                    rootElement.appendChild(document.createElement("problem")).appendChild(document.createTextNode(problem));
                }
                throw (eProb = new Exception("problem!"));
            } else {
                if (!edit) {
                    schedulerXML.addAbstractBase(ab);
                }
            }
        }
        schedulerManager.save();
        schedulerManager.refreshJobs();
    } catch (Exception e) {
        schedulerManager.load();
        if (e != eProb) {
            throw e;
        }
    }
}
Also used : SchedulerXML(com.twinsoft.convertigo.beans.scheduler.SchedulerXML) Enumeration(java.util.Enumeration) Matcher(java.util.regex.Matcher) Element(org.w3c.dom.Element) ScheduledJob(com.twinsoft.convertigo.beans.scheduler.ScheduledJob) AbstractBase(com.twinsoft.convertigo.beans.scheduler.AbstractBase) SequenceConvertigoJob(com.twinsoft.convertigo.beans.scheduler.SequenceConvertigoJob) AbstractSchedule(com.twinsoft.convertigo.beans.scheduler.AbstractSchedule) ScheduleCron(com.twinsoft.convertigo.beans.scheduler.ScheduleCron) ServiceException(com.twinsoft.convertigo.engine.admin.services.ServiceException) SchedulerManager(com.twinsoft.convertigo.engine.scheduler.SchedulerManager) AbstractJob(com.twinsoft.convertigo.beans.scheduler.AbstractJob) ServiceException(com.twinsoft.convertigo.engine.admin.services.ServiceException) JobGroupJob(com.twinsoft.convertigo.beans.scheduler.JobGroupJob) AbstractConvertigoJob(com.twinsoft.convertigo.beans.scheduler.AbstractConvertigoJob) TransactionConvertigoJob(com.twinsoft.convertigo.beans.scheduler.TransactionConvertigoJob) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

AbstractBase (com.twinsoft.convertigo.beans.scheduler.AbstractBase)1 AbstractConvertigoJob (com.twinsoft.convertigo.beans.scheduler.AbstractConvertigoJob)1 AbstractJob (com.twinsoft.convertigo.beans.scheduler.AbstractJob)1 AbstractSchedule (com.twinsoft.convertigo.beans.scheduler.AbstractSchedule)1 JobGroupJob (com.twinsoft.convertigo.beans.scheduler.JobGroupJob)1 ScheduleCron (com.twinsoft.convertigo.beans.scheduler.ScheduleCron)1 ScheduledJob (com.twinsoft.convertigo.beans.scheduler.ScheduledJob)1 SchedulerXML (com.twinsoft.convertigo.beans.scheduler.SchedulerXML)1 SequenceConvertigoJob (com.twinsoft.convertigo.beans.scheduler.SequenceConvertigoJob)1 TransactionConvertigoJob (com.twinsoft.convertigo.beans.scheduler.TransactionConvertigoJob)1 ServiceException (com.twinsoft.convertigo.engine.admin.services.ServiceException)1 SchedulerManager (com.twinsoft.convertigo.engine.scheduler.SchedulerManager)1 Enumeration (java.util.Enumeration)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Matcher (java.util.regex.Matcher)1 Element (org.w3c.dom.Element)1