Java Code Examples for org.quartz.TriggerKey#getName()

The following examples show how to use org.quartz.TriggerKey#getName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JobExecution.java    From quartz-glass with Apache License 2.0 6 votes vote down vote up
/**
 * Fill common attributes with properties from context.
 */
public void fillWithContext(JobExecutionContext context) {
    startDate = context.getFireTime();

    jobClass = Jobs.jobCass(context.getJobDetail()).getName();

    JobKey key = context.getJobDetail().getKey();
    jobKey = Keys.desc(key);
    jobGroup = key.getGroup();
    jobName = key.getName();
    TriggerKey key2 = context.getTrigger().getKey();
    triggerKey = Keys.desc(key2);
    triggerGroup = key2.getGroup();
    triggerName = key2.getName();
    dataMap = JobDataMapUtils.toProperties(context.getMergedJobDataMap());
}
 
Example 2
Source File: SmartQuartzUtil.java    From smart-admin with MIT License 4 votes vote down vote up
public static Integer getTaskIdByTriggerKey(TriggerKey triggerKey) {
    String name = triggerKey.getName();
    return Integer.valueOf(StringUtils.replace(name, QuartzConst.TRIGGER_KEY_PREFIX, ""));
}
 
Example 3
Source File: EmailProgressController.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
    * Gets learners or monitors of the lesson and organisation containing it.
    *
    * @throws SchedulerException
    */
   @RequestMapping("/getEmailProgressDates")
   @ResponseBody
   public String getEmailProgressDates(HttpServletRequest request, HttpServletResponse response)
    throws IOException, SchedulerException {
Long lessonId = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID);
if (!securityService.isLessonMonitor(lessonId, getCurrentUser().getUserID(), "get class members", false)) {
    response.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not a monitor in the lesson");
    return null;
}

HttpSession ss = SessionManager.getSession();
UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER);

ObjectNode responseJSON = JsonNodeFactory.instance.objectNode();
ArrayNode datesJSON = JsonNodeFactory.instance.arrayNode();

// find all the current dates set up to send the emails
String triggerPrefix = getTriggerPrefix(lessonId);
SortedSet<Date> currentDatesSet = new TreeSet<>();
Set<TriggerKey> triggerKeys = scheduler
	.getTriggerKeys(GroupMatcher.triggerGroupEquals(Scheduler.DEFAULT_GROUP));
for (TriggerKey triggerKey : triggerKeys) {
    String triggerName = triggerKey.getName();
    if (triggerName.startsWith(triggerPrefix)) {
	Trigger trigger = scheduler.getTrigger(triggerKey);
	JobDetail jobDetail = scheduler.getJobDetail(trigger.getJobKey());
	JobDataMap jobDataMap = jobDetail.getJobDataMap();

	// get only the trigger for the current lesson

	Object jobLessonId = jobDataMap.get(AttributeNames.PARAM_LESSON_ID);
	if (lessonId.equals(jobLessonId)) {

	    Date triggerDate = trigger.getNextFireTime();
	    currentDatesSet.add(triggerDate);
	}
    }
}

for (Date date : currentDatesSet) {
    datesJSON.add(createDateJSON(request.getLocale(), user, date, null));
}
responseJSON.set("dates", datesJSON);

response.setContentType("application/json;charset=utf-8");
return responseJSON.toString();
   }
 
Example 4
Source File: EmailNotificationsController.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
    * Renders a page listing all scheduled emails.
    */
   @RequestMapping("/showScheduledEmails")
   public String showScheduledEmails(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException, SchedulerException {

TreeSet<EmailScheduleMessageJobDTO> scheduleList = new TreeSet<>();
Long lessonId = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID, true);
boolean isLessonNotifications = (lessonId != null);
Integer organisationId = WebUtil.readIntParam(request, AttributeNames.PARAM_ORGANISATION_ID, true);
if (isLessonNotifications) {
    if (!securityService.isLessonMonitor(lessonId, getCurrentUser().getUserID(),
	    "show scheduled lesson email notifications", false)) {
	response.sendError(HttpServletResponse.SC_FORBIDDEN, "The user is not a monitor in the lesson");
	return null;
    }
} else {
    if (!securityService.isGroupMonitor(organisationId, getCurrentUser().getUserID(),
	    "show scheduled course email notifications", false)) {
	response.sendError(HttpServletResponse.SC_FORBIDDEN, "The user is not a monitor in the organisation");
	return null;
    }
}

Set<TriggerKey> triggerKeys = scheduler
	.getTriggerKeys(GroupMatcher.triggerGroupEquals(Scheduler.DEFAULT_GROUP));
for (TriggerKey triggerKey : triggerKeys) {
    String triggerName = triggerKey.getName();
    if (triggerName.startsWith(EmailNotificationsController.TRIGGER_PREFIX_NAME)) {
	Trigger trigger = scheduler.getTrigger(triggerKey);
	JobDetail jobDetail = scheduler.getJobDetail(trigger.getJobKey());
	JobDataMap jobDataMap = jobDetail.getJobDataMap();

	// filter triggers
	if (isLessonNotifications) {
	    Object jobLessonId = jobDataMap.get(AttributeNames.PARAM_LESSON_ID);
	    if ((jobLessonId == null) || (!lessonId.equals(jobLessonId))) {
		continue;
	    }
	} else {
	    Object jobOrganisationId = jobDataMap.get(AttributeNames.PARAM_ORGANISATION_ID);
	    if ((jobOrganisationId == null) || (!organisationId.equals(jobOrganisationId))) {
		continue;
	    }
	}

	Date triggerDate = trigger.getNextFireTime();
	String emailBody = WebUtil.convertNewlines((String) jobDataMap.get("emailBody"));
	int searchType = (Integer) jobDataMap.get("searchType");
	EmailScheduleMessageJobDTO emailScheduleJobDTO = new EmailScheduleMessageJobDTO();
	emailScheduleJobDTO.setTriggerName(triggerName);
	emailScheduleJobDTO.setTriggerDate(triggerDate);
	emailScheduleJobDTO.setEmailBody(emailBody);
	emailScheduleJobDTO.setSearchType(searchType);
	scheduleList.add(emailScheduleJobDTO);
    }
}

request.setAttribute("scheduleList", scheduleList);
request.setAttribute(AttributeNames.PARAM_LESSON_ID, lessonId);
request.setAttribute(AttributeNames.PARAM_ORGANISATION_ID, organisationId);

return "emailnotifications/scheduledEmailList";
   }
 
Example 5
Source File: EmailNotificationsController.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
    * Delete a scheduled emails.
    *
    * @throws JSONException
    */
   @RequestMapping(path = "/deleteNotification", method = RequestMethod.POST)
   @ResponseBody
   public String deleteNotification(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException, SchedulerException {

String inputTriggerName = WebUtil.readStrParam(request, "triggerName");
Long lessonId = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID, true);
Integer userId = getCurrentUser().getUserID();
boolean isLessonNotifications = (lessonId != null);
Integer organisationId = WebUtil.readIntParam(request, AttributeNames.PARAM_ORGANISATION_ID, true);

ObjectNode jsonObject = JsonNodeFactory.instance.objectNode();
String error = null;

try {
    // if this method throws an Exception, there will be no deleteNotification=true in the JSON reply
    if (isLessonNotifications) {
	if (!securityService.isLessonMonitor(lessonId, userId, "show scheduled lesson email notifications",
		false)) {
	    error = "Unable to delete notification: the user is not a monitor in the lesson";
	}
    } else {
	if (!securityService.isGroupMonitor(organisationId, userId,
		"show scheduled course course email notifications", false)) {
	    error = "Unable to delete notification: the user is not a monitor in the organisation";
	}
    }

    if (error == null) {
	Set<TriggerKey> triggerKeys = scheduler
		.getTriggerKeys(GroupMatcher.triggerGroupEquals(Scheduler.DEFAULT_GROUP));
	for (TriggerKey triggerKey : triggerKeys) {
	    String triggerName = triggerKey.getName();
	    if (triggerName.equals(inputTriggerName)) {
		Trigger trigger = scheduler.getTrigger(triggerKey);

		JobKey jobKey = trigger.getJobKey();

		JobDetail jobDetail = scheduler.getJobDetail(trigger.getJobKey());
		JobDataMap jobDataMap = jobDetail.getJobDataMap();
		logEventService.logEvent(LogEvent.TYPE_NOTIFICATION, userId, null, lessonId, null,
			"Deleting unsent scheduled notification " + jobKey + " "
				+ jobDataMap.getString("emailBody"));

		scheduler.deleteJob(jobKey);

	    }
	}

    }

} catch (Exception e) {
    String[] msg = new String[1];
    msg[0] = e.getMessage();
    error = monitoringService.getMessageService().getMessage("error.system.error", msg);
}

jsonObject.put("deleteNotification", error == null ? "true" : error);
response.setContentType("application/json;charset=utf-8");
return jsonObject.toString();

   }