[Amavisadmin-svn] SF.net SVN: amavisadmin: [32] amavisadmin/trunk/src/java/de/sreindl/ amavisadmin
Status: Beta
Brought to you by:
streindl
From: <str...@us...> - 2007-01-18 21:53:30
|
Revision: 32 http://amavisadmin.svn.sourceforge.net/amavisadmin/?rev=32&view=rev Author: streindl Date: 2007-01-18 13:53:25 -0800 (Thu, 18 Jan 2007) Log Message: ----------- Fix for #1636519 Added Paths: ----------- amavisadmin/trunk/src/java/de/sreindl/amavisadmin/jobs/AdminNotifierJob.java amavisadmin/trunk/src/java/de/sreindl/amavisadmin/templates/AdminNotifier.vm Added: amavisadmin/trunk/src/java/de/sreindl/amavisadmin/jobs/AdminNotifierJob.java =================================================================== --- amavisadmin/trunk/src/java/de/sreindl/amavisadmin/jobs/AdminNotifierJob.java (rev 0) +++ amavisadmin/trunk/src/java/de/sreindl/amavisadmin/jobs/AdminNotifierJob.java 2007-01-18 21:53:25 UTC (rev 32) @@ -0,0 +1,125 @@ +/* + * Copyright (C) 2007 Stephen Reindl. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package de.sreindl.amavisadmin.jobs; + +import de.sreindl.amavisadmin.bo.ConfigurationBO; +import de.sreindl.amavisadmin.bo.UserBO; +import de.sreindl.amavisadmin.bo.configuration.ConfigurationDataEntry; +import de.sreindl.amavisadmin.db.MailQueueEntry; +import de.sreindl.amavisadmin.db.MailQueueEntryDAO; +import de.sreindl.amavisadmin.db.MailQueueReceipient; +import de.sreindl.amavisadmin.db.MailQueueReceipientDAO; +import de.sreindl.amavisadmin.db.MsgReceipientDAO; +import de.sreindl.amavisadmin.db.User; +import de.sreindl.amavisadmin.db.UserDAO; +import de.sreindl.amavisadmin.db.util.HibernateSessionFactory; +import java.io.StringWriter; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.velocity.Template; +import org.apache.velocity.VelocityContext; +import org.apache.velocity.app.Velocity; +import org.hibernate.Query; +import org.hibernate.Session; +import org.quartz.JobExecutionContext; + +/** + * This job is responsible for informing administrators + * + * @author sreindl + */ +public class AdminNotifierJob extends BaseJob { + + private static Log log = LogFactory.getLog(AdminNotifierJob.class); + + /** Creates a new instance of ReminderJob */ + public AdminNotifierJob() { + } + + /** + * ececutor that the job itself has to execute. + */ + public void excuteJob(JobExecutionContext context) throws Exception { + log.info("Starting new admin notifier job"); + Session session = HibernateSessionFactory.getSession(); + User user; + Query qry = session.createQuery("select count(*) from MsgRecipient where rs = :wait_ind"); + qry.setCharacter("wait_ind", MsgReceipientDAO.RS_REL_PENDING); + + BigInteger count = (BigInteger)qry.uniqueResult(); + if (count != null && count.intValue() > 0) { + sendAdminNotifier(count.intValue()); + } + log.info("Finishing new mail notifier job"); + } + + /** + * Return true if a surrounding transaction layer has to be created. + */ + public boolean isTransactionalJob() { + return true; + } + + public ArrayList<ConfigurationDataEntry> getConfigurationDataTable() { + ArrayList<ConfigurationDataEntry> entries = + new ArrayList<ConfigurationDataEntry>(); + return entries; + } + + /** + * Send the mail to the admins + */ + private void sendAdminNotifier(int requestCount) throws Exception { + VelocityContext context = new VelocityContext(); + UserDAO dao = new UserDAO(); + List adminUsers = dao.findByAdmin(Boolean.TRUE); + + if (adminUsers.size() == 0) { + log.warn ("Warning: No admin users defined"); + return; + } + context.put("appTitle", ConfigurationBO.getConfValue(ConfigurationBO.APP_TITLE)); + context.put("signature", ConfigurationBO.getConfValue(ConfigurationBO.APP_TITLE)); + context.put("baselink", ConfigurationBO.getConfValue(ConfigurationBO.CONF_BASE_URL) + "/"); + context.put("requestCount", Integer.valueOf(requestCount)); + Template lostPwd = Velocity.getTemplate("/de/sreindl/amavisadmin/templates/AdminNotifier.vm"); + StringWriter w = new StringWriter(); + lostPwd.merge(context, w); + MailQueueEntry mqe = new MailQueueEntry(); + mqe.setEncoding("text/plain"); + mqe.setStatus(MailQueueEntryDAO.STATUS_NEW); + mqe.setFrom(ConfigurationBO.getConfValue(ConfigurationBO.MAIL_SENDER)); + mqe.setMailText(w.toString()); + mqe.setSubject((String)context.get("subject")); + Iterator i = adminUsers.iterator(); + mqe.setReceipients(new HashSet()); + HibernateSessionFactory.getSession().save(mqe); + while (i.hasNext()) { + User user = (User)i.next(); + MailQueueReceipient mqr = new MailQueueReceipient(); + mqr.setReceipient(UserBO.formatMailAddress(user)); + mqr.setType(MailQueueReceipientDAO.TYPE_TO); + mqe.getReceipients().add(mqr); + mqr.setMailQueueEntry(mqe); + HibernateSessionFactory.getSession().save(mqr); + } + } +} Property changes on: amavisadmin/trunk/src/java/de/sreindl/amavisadmin/jobs/AdminNotifierJob.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native Added: amavisadmin/trunk/src/java/de/sreindl/amavisadmin/templates/AdminNotifier.vm =================================================================== --- amavisadmin/trunk/src/java/de/sreindl/amavisadmin/templates/AdminNotifier.vm (rev 0) +++ amavisadmin/trunk/src/java/de/sreindl/amavisadmin/templates/AdminNotifier.vm 2007-01-18 21:53:25 UTC (rev 32) @@ -0,0 +1,26 @@ +#* + * Copyright (C) 2007 Stephen Reindl. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *# +## Template used to inform administrators about pending release mails +#parse("/de/sreindl/amavisadmin/templates/HeaderTemplate.vm") +#set( $subject = "$appTitle: There mails waiting for your approval" ) +Hello Administrator(s), + +You have $requestCount mails that need to be approved/rejected for being +released. + +Please login at $baselink . + +#parse("/de/sreindl/amavisadmin/templates/FooterTemplate.vm") Property changes on: amavisadmin/trunk/src/java/de/sreindl/amavisadmin/templates/AdminNotifier.vm ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |