Github user ilgrosso commented on a diff in the pull request:

    https://github.com/apache/syncope/pull/5#discussion_r30799389
  
    --- Diff: 
core/src/main/java/org/apache/syncope/core/rest/controller/AbstractJobController.java
 ---
    @@ -0,0 +1,154 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *   http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +package org.apache.syncope.core.rest.controller;
    +
    +import static 
org.apache.syncope.core.rest.controller.AbstractController.LOG;
    +
    +import java.util.ArrayList;
    +import java.util.List;
    +import org.apache.syncope.common.AbstractBaseBean;
    +import org.apache.syncope.common.to.AbstractExecTO;
    +import org.apache.syncope.common.types.JobAction;
    +import org.apache.syncope.common.types.JobStatusType;
    +import org.quartz.JobExecutionContext;
    +import org.quartz.JobKey;
    +import org.quartz.Scheduler;
    +import org.quartz.SchedulerException;
    +import org.quartz.Trigger;
    +import org.quartz.impl.matchers.GroupMatcher;
    +import org.springframework.beans.factory.annotation.Autowired;
    +import org.springframework.scheduling.quartz.SchedulerFactoryBean;
    +
    +abstract class AbstractJobController<T extends AbstractBaseBean> extends 
AbstractTransactionalController<T> {
    +
    +    @Autowired
    +    protected SchedulerFactoryBean scheduler;
    +
    +    protected abstract Long getIdFromJobName(JobKey jobKey);
    +
    +    public <E extends AbstractExecTO> List<E> list(final JobStatusType 
type, final Class<E> reference) {
    +        List<E> jobExecTOs = new ArrayList<E>();
    +
    +        switch (type) {
    +            case ALL:
    +                try {
    +                    for (String groupName : 
scheduler.getScheduler().getJobGroupNames()) {
    +                        for (JobKey jobKey : 
scheduler.getScheduler().getJobKeys(GroupMatcher.jobGroupEquals(groupName))) {
    +
    +                            Long jobId = getIdFromJobName(jobKey);
    +                            if (jobId != null) {
    +                                List<? extends Trigger> jobTriggers = 
scheduler.getScheduler().getTriggersOfJob(jobKey);
    +                                if (jobTriggers.size() > 0) {
    +                                    for (Trigger t : jobTriggers) {
    +                                        E jobExecTO = 
reference.newInstance();
    +                                        jobExecTO.setId(jobId);
    +                                        jobExecTO.
    +                                                
setStatus(scheduler.getScheduler().getTriggerState(t.getKey()).name());
    +                                        
jobExecTO.setStartDate(t.getStartTime());
    +                                        jobExecTOs.add(jobExecTO);
    +                                    }
    +                                } else {
    +                                    E jobExecTO = reference.newInstance();
    +                                    jobExecTO.setId(jobId);
    +                                    jobExecTO.setStatus("Not Scheduled");
    +                                    jobExecTOs.add(jobExecTO);
    +                                }
    +                            }
    +                        }
    +                    }
    +                } catch (SchedulerException ex) {
    +                    LOG.debug("Problems during retrieving all scheduled 
jobs {}", ex);
    +                } catch (InstantiationException ex) {
    +                    LOG.debug("Problems during instantiating {}  {}", 
reference, ex);
    +                } catch (IllegalAccessException ex) {
    +                    LOG.debug("Problems during accessing {}  {}", 
reference, ex);
    +                }
    +                break;
    +            case RUNNING:
    +                try {
    +                    for (JobExecutionContext jec : 
scheduler.getScheduler().getCurrentlyExecutingJobs()) {
    +                        Long jobId = 
getIdFromJobName(jec.getJobDetail().getKey());
    +                        if (jobId != null) {
    +                            E jobExecTO = reference.newInstance();
    +                            jobExecTO.setId(jobId);
    +                            jobExecTO.setStatus("Running");
    +                            jobExecTO.setStartDate(jec.getFireTime());
    +                            jobExecTOs.add(jobExecTO);
    +                        }
    +                    }
    +                } catch (SchedulerException ex) {
    +                    LOG.debug("Problems during retrieving all currently 
executing jobs {}", ex);
    +                } catch (InstantiationException ex) {
    +                    LOG.debug("Problems during instantiating {}  {}", 
reference, ex);
    +                } catch (IllegalAccessException ex) {
    +                    LOG.debug("Problems during accessing {}  {}", 
reference, ex);
    +                }
    +                break;
    +            case SCHEDULED:
    +                try {
    +                    for (String groupName : 
scheduler.getScheduler().getJobGroupNames()) {
    +                        for (JobKey jobKey : 
scheduler.getScheduler().getJobKeys(GroupMatcher.jobGroupEquals(groupName))) {
    +                            Long jobId = getIdFromJobName(jobKey);
    +                            if (jobId != null) {
    +                                List<? extends Trigger> jobTriggers = 
scheduler.getScheduler().getTriggersOfJob(jobKey);
    +                                for (Trigger t : jobTriggers) {
    +                                    E jobExecTO = reference.newInstance();
    +                                    jobExecTO.setId(jobId);
    +                                    
jobExecTO.setStatus(scheduler.getScheduler().getTriggerState(t.getKey()).name());
    +                                    
jobExecTO.setStartDate(t.getStartTime());
    --- End diff --
    
    Why not setting status here?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to