[SYNCOPE-1298] Now TaskService#listJobs also reports custom Quartz jobs
authorFrancesco Chicchiriccò <ilgrosso@apache.org>
Tue, 10 Apr 2018 14:02:14 +0000 (16:02 +0200)
committerFrancesco Chicchiriccò <ilgrosso@apache.org>
Tue, 10 Apr 2018 14:10:08 +0000 (16:10 +0200)
client/console/src/main/java/org/apache/syncope/client/console/pages/BasePage.java
client/console/src/main/java/org/apache/syncope/client/console/panels/AnyObjectDirectoryPanel.java
client/console/src/main/java/org/apache/syncope/client/console/panels/GroupDirectoryPanel.java
client/console/src/main/java/org/apache/syncope/client/console/panels/UserDirectoryPanel.java
client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/ActionLinksTogglePanel.java
client/console/src/main/java/org/apache/syncope/client/console/widgets/JobWidget.java
common/lib/src/main/java/org/apache/syncope/common/lib/types/JobType.java
core/logic/src/main/java/org/apache/syncope/core/logic/AbstractJobLogic.java
core/logic/src/main/java/org/apache/syncope/core/logic/NotificationLogic.java
core/logic/src/main/java/org/apache/syncope/core/logic/ReportLogic.java
core/logic/src/main/java/org/apache/syncope/core/logic/TaskLogic.java

index 93f385d..17d6717 100644 (file)
@@ -171,8 +171,9 @@ public class BasePage extends WebPage implements IAjaxIndicatorAware {
         body.add(liContainer);
         link = BookmarkablePageLinkBuilder.build("topology", Topology.class);
         MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.RENDER,
-                StringUtils.join(
-                        new String[] { StandardEntitlement.CONNECTOR_LIST, StandardEntitlement.CONNECTOR_LIST }, ","));
+                String.format("%s,%s",
+                        StandardEntitlement.CONNECTOR_LIST,
+                        StandardEntitlement.RESOURCE_LIST));
         liContainer.add(link);
 
         liContainer = new WebMarkupContainer(getLIContainerId("reports"));
@@ -222,8 +223,9 @@ public class BasePage extends WebPage implements IAjaxIndicatorAware {
         confULContainer.add(liContainer);
         link = BookmarkablePageLinkBuilder.build("security", Security.class);
         MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.RENDER,
-                StringUtils.join(
-                        new String[] { StandardEntitlement.ROLE_LIST, StandardEntitlement.APPLICATION_LIST }, ","));
+                String.format("%s,%s",
+                        StandardEntitlement.ROLE_LIST,
+                        StandardEntitlement.APPLICATION_LIST));
         liContainer.add(link);
 
         liContainer = new WebMarkupContainer(getLIContainerId("policies"));
index 3db9615..7a642dc 100644 (file)
@@ -109,8 +109,8 @@ public class AnyObjectDirectoryPanel extends AnyDirectoryPanel<AnyObjectTO, AnyO
                                 new AnyWrapper<>(new AnyObjectRestClient().read(model.getObject().getKey())),
                                 target));
             }
-        }, ActionType.EDIT, StringUtils.join(
-                new String[] { AnyEntitlement.READ.getFor(type), AnyEntitlement.UPDATE.getFor(type) }, ",")).
+        }, ActionType.EDIT,
+                String.format("%s,%s", AnyEntitlement.READ.getFor(type), AnyEntitlement.UPDATE.getFor(type))).
                 setRealm(realm);
 
         panel.add(new ActionLink<AnyObjectTO>() {
@@ -154,7 +154,9 @@ public class AnyObjectDirectoryPanel extends AnyDirectoryPanel<AnyObjectTO, AnyO
 
                     altDefaultModal.show(true);
                 }
-            }, ActionType.MANAGE_RESOURCES, AnyEntitlement.UPDATE.getFor(type)).setRealm(realm);
+            }, ActionType.MANAGE_RESOURCES,
+                    String.format("%s,%s", AnyEntitlement.READ.getFor(type), AnyEntitlement.UPDATE.getFor(type))).
+                    setRealm(realm);
 
             panel.add(
                     new ActionLink<AnyObjectTO>() {
index 6168829..6bef561 100644 (file)
@@ -214,8 +214,8 @@ public class GroupDirectoryPanel extends AnyDirectoryPanel<GroupTO, GroupRestCli
                         new AjaxWizard.EditItemActionEvent<>(new GroupWrapper(
                                 restClient.read(model.getObject().getKey())), target));
             }
-        }, ActionType.EDIT, StringUtils.join(
-                new String[] { StandardEntitlement.GROUP_READ, StandardEntitlement.GROUP_UPDATE }, ",")).
+        }, ActionType.EDIT,
+                String.format("%s,%s", StandardEntitlement.GROUP_READ, StandardEntitlement.GROUP_UPDATE)).
                 setRealm(realm);
 
         panel.add(new ActionLink<GroupTO>() {
@@ -263,7 +263,9 @@ public class GroupDirectoryPanel extends AnyDirectoryPanel<GroupTO, GroupRestCli
             public boolean isIndicatorEnabled() {
                 return false;
             }
-        }, ActionType.MEMBERS, StandardEntitlement.GROUP_UPDATE).setRealm(realm);
+        }, ActionType.MEMBERS,
+                String.format("%s,%s", StandardEntitlement.GROUP_READ, StandardEntitlement.GROUP_UPDATE)).
+                setRealm(realm);
 
         panel.add(new ActionLink<GroupTO>() {
 
@@ -283,7 +285,8 @@ public class GroupDirectoryPanel extends AnyDirectoryPanel<GroupTO, GroupRestCli
                 ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
             }
         }, ActionType.PROVISION_MEMBERS,
-                String.format("%s,%s", StandardEntitlement.TASK_CREATE, StandardEntitlement.TASK_EXECUTE));
+                String.format("%s,%s", StandardEntitlement.TASK_CREATE, StandardEntitlement.TASK_EXECUTE)).
+                setRealm(realm);
 
         panel.add(
                 new ActionLink<GroupTO>() {
@@ -304,7 +307,8 @@ public class GroupDirectoryPanel extends AnyDirectoryPanel<GroupTO, GroupRestCli
                 ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
             }
         }, ActionType.DEPROVISION_MEMBERS,
-                String.format("%s,%s", StandardEntitlement.TASK_CREATE, StandardEntitlement.TASK_EXECUTE));
+                String.format("%s,%s", StandardEntitlement.TASK_CREATE, StandardEntitlement.TASK_EXECUTE)).
+                setRealm(realm);
 
         panel.add(new ActionLink<GroupTO>() {
 
@@ -328,7 +332,9 @@ public class GroupDirectoryPanel extends AnyDirectoryPanel<GroupTO, GroupRestCli
 
                 altDefaultModal.show(true);
             }
-        }, ActionType.MANAGE_RESOURCES, StandardEntitlement.GROUP_READ).setRealm(realm);
+        }, ActionType.MANAGE_RESOURCES,
+                String.format("%s,%s", StandardEntitlement.GROUP_READ, StandardEntitlement.GROUP_UPDATE)).
+                setRealm(realm);
 
         panel.add(new ActionLink<GroupTO>() {
 
index 66f214b..5452853 100644 (file)
@@ -141,8 +141,8 @@ public class UserDirectoryPanel extends AnyDirectoryPanel<UserTO, UserRestClient
                                 new UserWrapper(new UserRestClient().read(model.getObject().getKey())),
                                 target));
             }
-        }, ActionType.EDIT, StringUtils.join(
-                new String[] { StandardEntitlement.USER_READ, StandardEntitlement.USER_UPDATE }, ",")).
+        }, ActionType.EDIT,
+                String.format("%s,%s", StandardEntitlement.USER_READ, StandardEntitlement.USER_UPDATE)).
                 setRealm(realm);
 
         panel.add(new ActionLink<UserTO>() {
@@ -281,7 +281,9 @@ public class UserDirectoryPanel extends AnyDirectoryPanel<UserTO, UserRestClient
 
                     altDefaultModal.show(true);
                 }
-            }, ActionType.MANAGE_RESOURCES, StandardEntitlement.USER_UPDATE).setRealm(realm);
+            }, ActionType.MANAGE_RESOURCES,
+                    String.format("%s,%s", StandardEntitlement.USER_READ, StandardEntitlement.USER_UPDATE)).
+                    setRealm(realm);
 
             panel.add(new ActionLink<UserTO>() {
 
index 4d63c3e..71e5ef4 100644 (file)
@@ -71,8 +71,7 @@ public class ActionLinksTogglePanel<T extends Serializable> extends TogglePanel<
         container.add(getEmptyFragment());
     }
 
-    public void updateHeader(
-            final AjaxRequestTarget target, final Serializable modelObject) {
+    public void updateHeader(final AjaxRequestTarget target, final Serializable modelObject) {
         final String header;
         if (modelObject == null) {
             header = new ResourceModel("actions", StringUtils.EMPTY).getObject();
@@ -125,6 +124,7 @@ public class ActionLinksTogglePanel<T extends Serializable> extends TogglePanel<
         } else {
             header = new ResourceModel("actions", StringUtils.EMPTY).getObject();
         }
+
         setHeader(target, StringUtils.abbreviate(header, HEADER_FIRST_ABBREVIATION));
     }
 
index 897ae2e..efd27b5 100644 (file)
@@ -393,7 +393,7 @@ public class JobWidget extends BaseWidget {
                             break;
 
                         case REPORT:
-                            ReportTO reportTO = new ReportRestClient().read(jobTO.getRefKey());
+                            ReportTO reportTO = reportRestClient.read(jobTO.getRefKey());
 
                             ReportWizardBuilder rwb = new ReportWizardBuilder(reportTO, pageRef);
                             rwb.setEventSink(AvailableJobsPanel.this);
@@ -411,11 +411,11 @@ public class JobWidget extends BaseWidget {
                         case TASK:
                             ProvisioningTaskTO schedTaskTO;
                             try {
-                                schedTaskTO = new TaskRestClient().readTask(TaskType.PULL, jobTO.getRefKey());
+                                schedTaskTO = taskRestClient.readTask(TaskType.PULL, jobTO.getRefKey());
                             } catch (Exception e) {
                                 LOG.debug("Failed to read {} as {}, attempting {}",
                                         jobTO.getRefKey(), TaskType.PULL, TaskType.PUSH, e);
-                                schedTaskTO = new TaskRestClient().readTask(TaskType.PUSH, jobTO.getRefKey());
+                                schedTaskTO = taskRestClient.readTask(TaskType.PUSH, jobTO.getRefKey());
                             }
 
                             SchedTaskWizardBuilder<ProvisioningTaskTO> swb =
@@ -459,7 +459,7 @@ public class JobWidget extends BaseWidget {
 
                             case REPORT:
 
-                                final ReportTO reportTO = new ReportRestClient().read(jobTO.getRefKey());
+                                final ReportTO reportTO = reportRestClient.read(jobTO.getRefKey());
 
                                 target.add(AvailableJobsPanel.this.reportModal.setContent(
                                         new ReportletDirectoryPanel(reportModal, jobTO.getRefKey(), pageRef)));
@@ -506,11 +506,11 @@ public class JobWidget extends BaseWidget {
                                     break;
 
                                 case REPORT:
-                                    new ReportRestClient().actionJob(jobTO.getRefKey(), JobAction.DELETE);
+                                    reportRestClient.actionJob(jobTO.getRefKey(), JobAction.DELETE);
                                     break;
 
                                 case TASK:
-                                    new TaskRestClient().actionJob(jobTO.getRefKey(), JobAction.DELETE);
+                                    taskRestClient.actionJob(jobTO.getRefKey(), JobAction.DELETE);
                                     break;
 
                                 default:
index b480848..bc2657a 100644 (file)
@@ -24,6 +24,7 @@ import javax.xml.bind.annotation.XmlEnum;
 public enum JobType {
     NOTIFICATION,
     REPORT,
-    TASK;
+    TASK,
+    CUSTOM;
 
 }
index 844d353..38bb876 100644 (file)
@@ -27,7 +27,12 @@ import org.apache.syncope.common.lib.types.JobAction;
 import org.apache.syncope.common.lib.types.JobType;
 import org.apache.syncope.core.provisioning.api.job.JobManager;
 import org.apache.syncope.core.provisioning.java.job.AbstractInterruptableJob;
+import org.apache.syncope.core.provisioning.java.job.SystemLoadReporterJob;
+import org.apache.syncope.core.provisioning.java.job.TaskJob;
+import org.apache.syncope.core.provisioning.java.job.notification.NotificationJob;
+import org.apache.syncope.core.provisioning.java.job.report.ReportJob;
 import org.apache.syncope.core.spring.ApplicationContextProvider;
+import org.quartz.JobDetail;
 import org.quartz.JobKey;
 import org.quartz.Scheduler;
 import org.quartz.SchedulerException;
@@ -47,38 +52,53 @@ abstract class AbstractJobLogic<T extends AbstractBaseBean> extends AbstractTran
 
     protected abstract Triple<JobType, String, String> getReference(final JobKey jobKey);
 
-    protected JobTO getJobTO(final JobKey jobKey) throws SchedulerException {
+    protected JobTO getJobTO(final JobKey jobKey, final boolean includeCustom) throws SchedulerException {
         JobTO jobTO = null;
 
-        Triple<JobType, String, String> reference = getReference(jobKey);
-        if (reference != null) {
-            jobTO = new JobTO();
-
-            jobTO.setType(reference.getLeft());
-            jobTO.setRefKey(reference.getMiddle());
-            jobTO.setRefDesc(reference.getRight());
-
-            List<? extends Trigger> jobTriggers = scheduler.getScheduler().getTriggersOfJob(jobKey);
-            if (jobTriggers.isEmpty()) {
-                jobTO.setScheduled(false);
-            } else {
-                jobTO.setScheduled(true);
-                jobTO.setStart(jobTriggers.get(0).getStartTime());
+        if (scheduler.getScheduler().checkExists(jobKey)) {
+            Triple<JobType, String, String> reference = getReference(jobKey);
+            if (reference != null) {
+                jobTO = new JobTO();
+                jobTO.setType(reference.getLeft());
+                jobTO.setRefKey(reference.getMiddle());
+                jobTO.setRefDesc(reference.getRight());
+            } else if (includeCustom) {
+                JobDetail jobDetail = scheduler.getScheduler().getJobDetail(jobKey);
+                if (!TaskJob.class.isAssignableFrom(jobDetail.getJobClass())
+                        && !ReportJob.class.isAssignableFrom(jobDetail.getJobClass())
+                        && !SystemLoadReporterJob.class.isAssignableFrom(jobDetail.getJobClass())
+                        && !NotificationJob.class.isAssignableFrom(jobDetail.getJobClass())) {
+
+                    jobTO = new JobTO();
+                    jobTO.setType(JobType.CUSTOM);
+                    jobTO.setRefKey(jobKey.getName());
+                    jobTO.setRefDesc(jobDetail.getJobClass().getName());
+                }
             }
 
-            jobTO.setRunning(jobManager.isRunning(jobKey));
+            if (jobTO != null) {
+                List<? extends Trigger> jobTriggers = scheduler.getScheduler().getTriggersOfJob(jobKey);
+                if (jobTriggers.isEmpty()) {
+                    jobTO.setScheduled(false);
+                } else {
+                    jobTO.setScheduled(true);
+                    jobTO.setStart(jobTriggers.get(0).getStartTime());
+                }
+
+                jobTO.setRunning(jobManager.isRunning(jobKey));
 
-            jobTO.setStatus("UNKNOWN");
-            if (jobTO.isRunning()) {
-                try {
-                    Object job = ApplicationContextProvider.getBeanFactory().getBean(jobKey.getName());
-                    if (job instanceof AbstractInterruptableJob
-                            && ((AbstractInterruptableJob) job).getDelegate() != null) {
+                jobTO.setStatus("UNKNOWN");
+                if (jobTO.isRunning()) {
+                    try {
+                        Object job = ApplicationContextProvider.getBeanFactory().getBean(jobKey.getName());
+                        if (job instanceof AbstractInterruptableJob
+                                && ((AbstractInterruptableJob) job).getDelegate() != null) {
 
-                        jobTO.setStatus(((AbstractInterruptableJob) job).getDelegate().currentStatus());
+                            jobTO.setStatus(((AbstractInterruptableJob) job).getDelegate().currentStatus());
+                        }
+                    } catch (NoSuchBeanDefinitionException e) {
+                        LOG.warn("Could not find job {} implementation", jobKey, e);
                     }
-                } catch (NoSuchBeanDefinitionException e) {
-                    LOG.warn("Could not find job {} implementation", jobKey, e);
                 }
             }
         }
@@ -86,13 +106,13 @@ abstract class AbstractJobLogic<T extends AbstractBaseBean> extends AbstractTran
         return jobTO;
     }
 
-    protected List<JobTO> doListJobs() {
+    protected List<JobTO> doListJobs(final boolean includeCustom) {
         List<JobTO> jobTOs = new ArrayList<>();
         try {
             for (JobKey jobKey : scheduler.getScheduler().
                     getJobKeys(GroupMatcher.jobGroupEquals(Scheduler.DEFAULT_GROUP))) {
 
-                JobTO jobTO = getJobTO(jobKey);
+                JobTO jobTO = getJobTO(jobKey, includeCustom);
                 if (jobTO != null) {
                     jobTOs.add(jobTO);
                 }
index d9a662f..7b9aa90 100644 (file)
@@ -110,7 +110,7 @@ public class NotificationLogic extends AbstractJobLogic<NotificationTO> {
 
     @PreAuthorize("hasRole('" + StandardEntitlement.NOTIFICATION_LIST + "')")
     public JobTO getJob() {
-        List<JobTO> jobs = super.doListJobs();
+        List<JobTO> jobs = super.doListJobs(false);
         return jobs.isEmpty() ? null : jobs.get(0);
     }
 
index 780e8ac..523b75a 100644 (file)
@@ -369,7 +369,7 @@ public class ReportLogic extends AbstractExecutableLogic<ReportTO> {
     @PreAuthorize("hasRole('" + StandardEntitlement.REPORT_LIST + "')")
     @Override
     public List<JobTO> listJobs() {
-        return super.doListJobs();
+        return super.doListJobs(false);
     }
 
     @PreAuthorize("hasRole('" + StandardEntitlement.REPORT_READ + "')")
@@ -382,7 +382,7 @@ public class ReportLogic extends AbstractExecutableLogic<ReportTO> {
 
         JobTO jobTO = null;
         try {
-            jobTO = getJobTO(JobNamer.getJobKey(report));
+            jobTO = getJobTO(JobNamer.getJobKey(report), false);
         } catch (SchedulerException e) {
             LOG.error("Problems while retrieving scheduled job {}", JobNamer.getJobKey(report), e);
 
index bdd2fe2..2da812e 100644 (file)
@@ -386,7 +386,7 @@ public class TaskLogic extends AbstractExecutableLogic<TaskTO> {
     @PreAuthorize("hasRole('" + StandardEntitlement.TASK_LIST + "')")
     @Override
     public List<JobTO> listJobs() {
-        return super.doListJobs();
+        return super.doListJobs(true);
     }
 
     @PreAuthorize("hasRole('" + StandardEntitlement.TASK_READ + "')")
@@ -399,7 +399,7 @@ public class TaskLogic extends AbstractExecutableLogic<TaskTO> {
 
         JobTO jobTO = null;
         try {
-            jobTO = getJobTO(JobNamer.getJobKey(task));
+            jobTO = getJobTO(JobNamer.getJobKey(task), false);
         } catch (SchedulerException e) {
             LOG.error("Problems while retrieving scheduled job {}", JobNamer.getJobKey(task), e);