dpillot 2005/12/14 17:08:39 CET
Modified files:
core/src/java/org/jahia/services/scheduler
SchedulerService.java
SchedulerServiceImpl.java
Log:
added convenient method to grab jobdetail list on a server
Revision Changes Path
1.8 +17 -9
jahia/core/src/java/org/jahia/services/scheduler/SchedulerService.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/java/org/jahia/services/scheduler/SchedulerService.java.diff?r1=1.7&r2=1.8&f=h
1.12 +101 -27
jahia/core/src/java/org/jahia/services/scheduler/SchedulerServiceImpl.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/java/org/jahia/services/scheduler/SchedulerServiceImpl.java.diff?r1=1.11&r2=1.12&f=h
Index: SchedulerService.java
===================================================================
RCS file:
/home/cvs/repository/jahia/core/src/java/org/jahia/services/scheduler/SchedulerService.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- SchedulerService.java 9 Nov 2005 14:12:09 -0000 1.7
+++ SchedulerService.java 14 Dec 2005 16:08:39 -0000 1.8
@@ -1,38 +1,46 @@
package org.jahia.services.scheduler;
+import org.jahia.exceptions.JahiaException;
import org.jahia.services.JahiaService;
+import org.jahia.services.usermanager.JahiaUser;
import org.quartz.JobDetail;
import org.quartz.Trigger;
-import org.jahia.exceptions.JahiaException;
import java.util.List;
public abstract class SchedulerService extends JahiaService {
public abstract void scheduleJobNow(JobDetail jobDetail)
- throws JahiaException;
+ throws JahiaException;
public abstract void scheduleJob(JobDetail jobDetail, Trigger trigger)
- throws JahiaException;
+ throws JahiaException;
public abstract void scheduleRamJob(JobDetail jobDetail, Trigger trigger)
- throws JahiaException;
+ throws JahiaException;
/**
* Delete the given Job and associated trigger
+ *
* @param jobName
* @param groupName
* @throws JahiaException
*/
public abstract void deleteJob(String jobName, String groupName)
- throws JahiaException;
+ throws JahiaException;
public abstract JobDetail getJobDetail(String jobName, String groupName)
- throws JahiaException;
+ throws JahiaException;
+
+ public abstract List getJobsDetails(JahiaUser user, String groupname)
+ throws JahiaException;
- public abstract String[] getJobNames(String jobGroupName) throws
JahiaException;
+ public abstract String[] getJobNames(String jobGroupName)
+ throws JahiaException;
- public abstract List getCurrentlyExecutingJobs() throws JahiaException;
+ public abstract List getCurrentlyExecutingJobs()
+ throws JahiaException;
- public abstract void triggerJobWithVolatileTrigger(String jobName,
String jobGroupName) throws JahiaException;
+ public abstract void triggerJobWithVolatileTrigger(String jobName,
String jobGroupName)
+ throws JahiaException;
}
Index: SchedulerServiceImpl.java
===================================================================
RCS file:
/home/cvs/repository/jahia/core/src/java/org/jahia/services/scheduler/SchedulerServiceImpl.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- SchedulerServiceImpl.java 9 Nov 2005 14:12:09 -0000 1.11
+++ SchedulerServiceImpl.java 14 Dec 2005 16:08:39 -0000 1.12
@@ -2,11 +2,21 @@
import org.jahia.exceptions.JahiaException;
import org.jahia.exceptions.JahiaInitializationException;
+import org.jahia.registries.ServicesRegistry;
+import org.jahia.services.sites.JahiaSite;
+import org.jahia.services.usermanager.JahiaUser;
import org.quartz.*;
import java.io.File;
-import java.util.List;
+import java.util.Enumeration;
import java.util.Iterator;
+import java.util.List;
+import java.util.Vector;
+
+/**
+ * @version $Id: SchedulerServiceImpl.java,v 1.12 2005/12/14 16:08:39
dpillot Exp $
+ */
+
public class SchedulerServiceImpl extends SchedulerService {
@@ -20,7 +30,7 @@
private boolean schedulerRunning = false;
- protected SchedulerServiceImpl () {
+ protected SchedulerServiceImpl() {
}
/**
@@ -29,9 +39,9 @@
*
* @return The unique service instance.
*/
- public synchronized static SchedulerServiceImpl getInstance () {
+ public synchronized static SchedulerServiceImpl getInstance() {
if (singletonInstance == null) {
- singletonInstance = new SchedulerServiceImpl ();
+ singletonInstance = new SchedulerServiceImpl();
}
return singletonInstance;
}
@@ -39,12 +49,13 @@
/**
* Initializes the servlet dispatching service with parameters loaded
* from the Jahia configuration file.
+ *
* @throws JahiaInitializationException thrown in the case of an error
- * during this initialization, that will be treated as a critical error
- * in Jahia and probably stop execution of Jahia once and for all.
+ * during this initialization, that
will be treated as a critical error
+ * in Jahia and probably stop
execution of Jahia once and for all.
*/
public void start()
- throws JahiaInitializationException {
+ throws JahiaInitializationException {
try {
scheduler = getScheduler(new
File(settingsBean.getSchedulerConfigFile()), settingsBean.isProcessingServer());
@@ -54,12 +65,12 @@
} catch (SchedulerException se) {
if (se.getUnderlyingException() != null) {
throw new JahiaInitializationException(
- "Error while initializing scheduler service",
- se.getUnderlyingException());
+ "Error while initializing scheduler service",
+ se.getUnderlyingException());
} else {
throw new JahiaInitializationException(
- "Error while initializing scheduler service",
- se);
+ "Error while initializing scheduler service",
+ se);
}
}
@@ -81,8 +92,8 @@
return scheduler;
}
- public synchronized void stop ()
- throws JahiaException {
+ public synchronized void stop()
+ throws JahiaException {
try {
logger.debug("Shutting down scheduler...");
scheduler.shutdown();
@@ -96,12 +107,12 @@
}
public void scheduleJobNow(JobDetail jobDetail) throws JahiaException {
- SimpleTrigger trigger = new
SimpleTrigger(jobDetail.getName()+"_Trigger",Scheduler.DEFAULT_GROUP);
+ SimpleTrigger trigger = new SimpleTrigger(jobDetail.getName() +
"_Trigger", Scheduler.DEFAULT_GROUP);
scheduleJob(jobDetail, trigger);
}
public void scheduleJob(JobDetail jobDetail, Trigger trigger)
- throws JahiaException {
+ throws JahiaException {
if (!schedulerRunning) {
return;
}
@@ -113,7 +124,7 @@
}
public void scheduleRamJob(JobDetail jobDetail, Trigger trigger)
- throws JahiaException {
+ throws JahiaException {
if (!schedulerRunning) {
return;
}
@@ -125,12 +136,12 @@
}
public JobDetail getJobDetail(String jobName, String groupName)
- throws JahiaException {
+ throws JahiaException {
if (!schedulerRunning) {
return null;
}
try {
- return scheduler.getJobDetail(jobName,groupName);
+ return scheduler.getJobDetail(jobName, groupName);
} catch (SchedulerException se) {
throw getJahiaException(se);
}
@@ -140,28 +151,29 @@
if (se.getUnderlyingException() != null) {
se.getUnderlyingException().printStackTrace();
return new JahiaException("Error while shutting down scheduler
service",
- "Error while shutting down scheduler
service",
- JahiaException.SERVICE_ERROR,
- JahiaException.ERROR_SEVERITY,
- se.getUnderlyingException());
+ "Error while shutting down scheduler service",
+ JahiaException.SERVICE_ERROR,
+ JahiaException.ERROR_SEVERITY,
+ se.getUnderlyingException());
} else {
return new JahiaException("Error while shutting down scheduler
service",
- "Error while shutting down scheduler
service",
- JahiaException.SERVICE_ERROR,
- JahiaException.ERROR_SEVERITY,
- se);
+ "Error while shutting down scheduler service",
+ JahiaException.SERVICE_ERROR,
+ JahiaException.ERROR_SEVERITY,
+ se);
}
}
/**
* Delete the given Job and associated trigger
+ *
* @param jobName
* @param groupName
* @throws JahiaException
*/
public void deleteJob(String jobName, String groupName)
- throws JahiaException {
+ throws JahiaException {
if (!schedulerRunning) {
return;
}
@@ -195,4 +207,66 @@
throw getJahiaException(e);
}
}
+
+ /**
+ * A convenient method to Get a list of scheduled and queued
jobdetails.<br>
+ *
+ *
+ * @param user the current jahia user
+ * @param groupname (could be empty or null)
+ * @return a list of jobdetails available for this user
+ * @throws JahiaException
+ */
+ public List getJobsDetails(JahiaUser user, String groupname) throws
JahiaException {
+ if (user == null) throw new IllegalArgumentException("user cannot be
null");
+ String gn = Scheduler.DEFAULT_GROUP;
+ if (groupname != null && !groupname.equalsIgnoreCase("")) gn =
groupname;
+
+ String[] process = getJobNames(gn);
+
+ List all = new Vector();
+ if (process.length == 0) return all;
+ for (int n = 0; n < process.length; n++) {
+ JobDetail jd = getJobDetail(process[n], gn);
+ all.add(jd);
+ }
+ //return the all list since the user is root
+ if (user.isRoot() || all.isEmpty()) return all;
+
+ List list = new Vector();
+ boolean isAdminSomewhere = false;
+
+ // get 1st all sitekey of sites where the user is admin member
+ Enumeration sites =
ServicesRegistry.getInstance().getJahiaSitesService().getSites();
+ List adminsites = new Vector();
+ while (sites.hasMoreElements()) {
+ JahiaSite site = (JahiaSite) sites.nextElement();
+ int siteid = site.getID();
+ if (user.isAdminMember(siteid))
adminsites.add(site.getSiteKey());
+ }
+
+ // second we grab the jobdetails with the same sitekeys
+ for (Iterator it = all.iterator(); it.hasNext();) {
+ JobDetail jd = (JobDetail) it.next();
+ JobDataMap data = jd.getJobDataMap();
+ if (data.get("sitekey") != null &&
adminsites.contains(data.get("sitekey"))) {
+ list.add(jd);
+ isAdminSomewhere = true;
+ }
+ }
+ if (isAdminSomewhere) return list;
+
+ // for all standard users
+ // grab only own process
+ list = new Vector();
+ for (Iterator it = all.iterator(); it.hasNext();) {
+ JobDetail jd = (JobDetail) it.next();
+ JobDataMap data = jd.getJobDataMap();
+ if (data.get("userkey") != null && ((String)
data.get("userkey")).equalsIgnoreCase(user.getUserKey())) {
+ list.add(jd);
+ }
+ }
+ return list;
+
+ }
}