ensureControlPermission(subject, group);
validateOperationNameAndParameters(group.getResourceType(), operationName, parameters);
JobDataMap jobDataMap = new JobDataMap();
jobDataMap.put(OperationJob.DATAMAP_STRING_OPERATION_NAME, operationName);
putDisplayName(jobDataMap, group.getResourceType().getId(), operationName);
if (parameters != null) {
if (parameters.getId() == 0) {
entityManager.persist(parameters);
}
jobDataMap.putAsString(OperationJob.DATAMAP_INT_PARAMETERS_ID, parameters.getId());
}
jobDataMap.putAsString(OperationJob.DATAMAP_INT_SUBJECT_ID, subject.getId());
jobDataMap.putAsString(GroupOperationJob.DATAMAP_INT_GROUP_ID, group.getId());
jobDataMap.putAsString(GroupOperationJob.DATAMAP_BOOL_HALT_ON_FAILURE, haltOnFailure);
if ((executionOrderResourceIds != null) && (executionOrderResourceIds.length > 0)) {
StringBuilder orderString = new StringBuilder();
orderString.append(executionOrderResourceIds[0]);
for (int i = 1; i < executionOrderResourceIds.length; i++) {
orderString.append(',');
orderString.append(executionOrderResourceIds[i]);
}
jobDataMap.put(GroupOperationJob.DATAMAP_INT_ARRAY_EXECUTION_ORDER, orderString.toString());
}
JobDetail jobDetail = new JobDetail();
jobDetail.setName(createUniqueJobName(group, operationName));
jobDetail.setGroup(createJobGroupName(group));
jobDetail.setDescription(notes);
jobDetail.setVolatility(false); // we want it persisted
jobDetail.setDurability(false);
jobDetail.setRequestsRecovery(false);
jobDetail.setJobClass(GroupOperationJob.class);
jobDetail.setJobDataMap(jobDataMap);
trigger.setName(jobDetail.getName());
trigger.setGroup(jobDetail.getGroup());
trigger.setJobName(jobDetail.getName());
trigger.setJobGroup(jobDetail.getGroup());
// we need to create our own schedule tracking entity
GroupOperationScheduleEntity schedule;
schedule = new GroupOperationScheduleEntity(jobDetail.getName(), jobDetail.getGroup(), trigger.getStartTime(),
group);
entityManager.persist(schedule);
// Add the id of the entity bean, so we can easily map the Quartz job to the associated entity bean.
jobDataMap.put(OperationJob.DATAMAP_INT_ENTITY_ID, String.valueOf(schedule.getId()));
// now actually schedule it
Date next = scheduler.scheduleJob(jobDetail, trigger);
GroupOperationSchedule newSchedule = getGroupOperationSchedule(subject, jobDetail);