/** * @see org.opencms.module.I_CmsModuleAction#initialize(CmsObject cmsObject, * CmsConfigurationManager cmsConfigurationManager, CmsModule cmsModule) */ public void initialize( CmsObject cmsObject, CmsConfigurationManager cmsConfigurationManager, CmsModule cmsModule) { boolean isTransmitMaiJobThere = false; boolean isDeletionJobThere = false; TreeMap map = new TreeMap(); CmsContextInfo context = new CmsContextInfo(cmsObject.getRequestContext()); CmsScheduleManager scheduleManager = OpenCms.getScheduleManager(); List jobs = scheduleManager.getJobs(); Iterator jobsIter = jobs.iterator(); while (jobsIter.hasNext()) { CmsScheduledJobInfo jobInfo = ((CmsScheduledJobInfo) jobsIter.next()); log.debug("The name of the ScheduledClass is : " + jobInfo.getClassName()); log.debug("The name of the ScheduledJob is : " + jobInfo.getJobName()); if (jobInfo.getClassName().equals(CLASSNAME_TRANSMIT_MAIL)) { isTransmitMaiJobThere = true; } if (jobInfo.getClassName().equals(CLASSNAME_DELETION_JOB)) { isDeletionJobThere = true; } } // check if the necessary jobs are there or not if (!isDeletionJobThere) { try { // create a new schedule job at the opencms system to delete greeting cards from archive // after a specified time CmsScheduledJobInfo scheduleDeletionJob = new CmsScheduledJobInfo( null, JOBNAME_DELETION_JOB, CLASSNAME_DELETION_JOB, context, CRONEXPRESSION_DELETION_JOB, false, true, map); // add the new job to the schedule manager scheduleManager.scheduleJob(cmsObject, scheduleDeletionJob); } catch (CmsRoleViolationException ex) { log.error("Exception scheduling job", ex); } catch (CmsSchedulerException ex) { log.error("Exception scheduling job", ex); } } if (!isTransmitMaiJobThere) { try { // create a new schedule job at the opencms system to transmit mails at the specified // timestamp CmsScheduledJobInfo newScheduleJob = new CmsScheduledJobInfo( null, JOBNAME_TRANSMIT_MAIL, CLASSNAME_TRANSMIT_MAIL, context, CRONEXPRESSION_TRANSMIT_MAIL, false, true, map); // add the new job to the schedule manager scheduleManager.scheduleJob(cmsObject, newScheduleJob); } catch (CmsRoleViolationException ex) { log.error("Exception scheduling job", ex); } catch (CmsSchedulerException ex) { log.error("Exception scheduling job", ex); } } }
/** * Creates a clone of this scheduled job. * * <p>The clone will not be active in the scheduler until it is scheduled with <code> * {@link CmsScheduleManager#scheduleJob(org.opencms.file.CmsObject, CmsScheduledJobInfo)}</code>. * The job id returned by <code>{@link #getId()}</code> will be the same. The <code> * {@link #isActive()}</code> flag will be set to false. The clones job instance class will be the * same if the <code>{@link #isReuseInstance()}</code> flag is set. * * <p> * * @see java.lang.Object#clone() */ @Override public Object clone() { CmsScheduledJobInfo result = new CmsScheduledJobInfo(); result.m_id = m_id; result.m_active = false; result.m_frozen = false; result.m_className = m_className; if (isReuseInstance()) { result.m_jobInstance = m_jobInstance; } result.m_reuseInstance = m_reuseInstance; result.m_context = (CmsContextInfo) m_context.clone(); result.m_cronExpression = m_cronExpression; result.m_jobName = m_jobName; result.m_parameters = new TreeMap<String, String>(m_parameters); result.m_trigger = null; return result; }