Author: apevec Date: 2005-08-29 07:26:15 +0200 (Mon, 29 Aug 2005) New Revision: 730 Added: contrib/ccm-ldn-content-check/ contrib/ccm-ldn-content-check/trunk/ contrib/ccm-ldn-content-check/trunk/application.xml contrib/ccm-ldn-content-check/trunk/pdl/ contrib/ccm-ldn-content-check/trunk/pdl/com/ contrib/ccm-ldn-content-check/trunk/pdl/com/arsdigita/ contrib/ccm-ldn-content-check/trunk/pdl/com/arsdigita/london/ contrib/ccm-ldn-content-check/trunk/pdl/com/arsdigita/london/cms/ contrib/ccm-ldn-content-check/trunk/pdl/com/arsdigita/london/cms/check/ contrib/ccm-ldn-content-check/trunk/pdl/com/arsdigita/london/cms/check/ContentCheck.pdl contrib/ccm-ldn-content-check/trunk/sql/ contrib/ccm-ldn-content-check/trunk/sql/ccm-ldn-content-check/ contrib/ccm-ldn-content-check/trunk/sql/ccm-ldn-content-check/default/ contrib/ccm-ldn-content-check/trunk/sql/ccm-ldn-content-check/default/table-cms_content_checks.sql contrib/ccm-ldn-content-check/trunk/sql/ccm-ldn-content-check/oracle-se-create.sql contrib/ccm-ldn-content-check/trunk/sql/ccm-ldn-content-check/oracle-se-drop.sql contrib/ccm-ldn-content-check/trunk/sql/ccm-ldn-content-check/postgres-create.sql contrib/ccm-ldn-content-check/trunk/sql/ccm-ldn-content-check/postgres-drop.sql contrib/ccm-ldn-content-check/trunk/src/ contrib/ccm-ldn-content-check/trunk/src/ccm-ldn-content-check.config contrib/ccm-ldn-content-check/trunk/src/ccm-ldn-content-check.load contrib/ccm-ldn-content-check/trunk/src/com/ contrib/ccm-ldn-content-check/trunk/src/com/arsdigita/ contrib/ccm-ldn-content-check/trunk/src/com/arsdigita/london/ contrib/ccm-ldn-content-check/trunk/src/com/arsdigita/london/cms/ contrib/ccm-ldn-content-check/trunk/src/com/arsdigita/london/cms/check/ contrib/ccm-ldn-content-check/trunk/src/com/arsdigita/london/cms/check/Config.java contrib/ccm-ldn-content-check/trunk/src/com/arsdigita/london/cms/check/Config_parameter.properties contrib/ccm-ldn-content-check/trunk/src/com/arsdigita/london/cms/check/ContentCheckAlert.java contrib/ccm-ldn-content-check/trunk/src/com/arsdigita/london/cms/check/Initializer.java contrib/ccm-ldn-content-check/trunk/src/com/arsdigita/london/cms/check/Loader.java Log: Content Check Alerts - packaged as a small ccm app b/c of dep. on ccm-ldn-dublin Added: contrib/ccm-ldn-content-check/trunk/application.xml =================================================================== --- contrib/ccm-ldn-content-check/trunk/application.xml 2005-08-29 05:20:48 UTC (rev 729) +++ contrib/ccm-ldn-content-check/trunk/application.xml 2005-08-29 05:26:15 UTC (rev 730) @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> + +<ccm:application name="ccm-ldn-content-check" + prettyName="Content Check Alerts" + version="1.0.0" + release="1" + xmlns:ccm="http://ccm.redhat.com/ccm-project"> + + <ccm:dependencies> + <ccm:requires name="ccm-ldn-dublin" version="1.4.3"/> + </ccm:dependencies> + + <ccm:contacts> + <ccm:contact uri="http://www.redhat.com/software/rhea" type="website"/> + <ccm:contact uri="mailto:rh...@re..." type="support"/> + </ccm:contacts> + + <ccm:description> + Content Check Alerts checks periodically for outdated content items + and send email alerts to Content Owners. + </ccm:description> + +</ccm:application> Added: contrib/ccm-ldn-content-check/trunk/pdl/com/arsdigita/london/cms/check/ContentCheck.pdl =================================================================== --- contrib/ccm-ldn-content-check/trunk/pdl/com/arsdigita/london/cms/check/ContentCheck.pdl 2005-08-29 05:20:48 UTC (rev 729) +++ contrib/ccm-ldn-content-check/trunk/pdl/com/arsdigita/london/cms/check/ContentCheck.pdl 2005-08-29 05:26:15 UTC (rev 730) @@ -0,0 +1,41 @@ +model com.arsdigita.london.cms.check; + +query getOutdatedContent { + BigDecimal itemID; + String objectType; + String creatorContact; + + do { + select ci.item_id, ct.object_type, dc.creator_contact + from acs_object_lifecycle_map lcm, lifecycles lc, + ldn_dublin_core_item_map dcm, ldn_dublin_core_items dc, + content_types ct, + cms_items ci left outer join cms_content_checks cc + on ( ci.item_id = cc.item_id ) + where ci.type_id IN :contentTypes + and ci.version = 'live' + and ci.type_id = ct.type_id + and ci.item_id = lcm.item_id and lcm.cycle_id = lc.cycle_id + and ci.item_id = dcm.item_id and dcm.dublin_id = dc.dublin_id + and dc.creator_contact is not null + and nvl(cc.last_alert, lc.start_date_time) < sysdate - :intervalDays + } map { + itemID = ci.item_id; + objectType = ct.object_type; + creatorContact = dc.creator_contact; + } +} + +data operation updateContentCheck { + do { + begin + insert into cms_content_checks(item_id) + select item_id from cms_items + where item_id = :itemID + and not exists (select 1 from cms_content_checks + where item_id = :itemID); + update cms_content_checks cc set cc.last_alert = sysdate + where cc.item_id = :itemID; + end; + } +} Added: contrib/ccm-ldn-content-check/trunk/sql/ccm-ldn-content-check/default/table-cms_content_checks.sql =================================================================== --- contrib/ccm-ldn-content-check/trunk/sql/ccm-ldn-content-check/default/table-cms_content_checks.sql 2005-08-29 05:20:48 UTC (rev 729) +++ contrib/ccm-ldn-content-check/trunk/sql/ccm-ldn-content-check/default/table-cms_content_checks.sql 2005-08-29 05:26:15 UTC (rev 730) @@ -0,0 +1,26 @@ +-- +-- Copyright (C) 2005 Red Hat Inc. All Rights Reserved. +-- +-- This library is free software; you can redistribute it and/or +-- modify it under the terms of the GNU Lesser General Public License +-- as published by the Free Software Foundation; either version 2.1 of +-- the License, or (at your option) any later version. +-- +-- This library is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +-- Lesser General Public License for more details. +-- +-- You should have received a copy of the GNU Lesser General Public +-- License along with this library; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-- +-- $Id$ + +create table cms_content_checks( + item_id integer + constraint cms_cont_chk_pk primary key + constraint cms_cont_chk_fk references cms_items + on delete cascade, + last_alert date +); Added: contrib/ccm-ldn-content-check/trunk/sql/ccm-ldn-content-check/oracle-se-create.sql =================================================================== --- contrib/ccm-ldn-content-check/trunk/sql/ccm-ldn-content-check/oracle-se-create.sql 2005-08-29 05:20:48 UTC (rev 729) +++ contrib/ccm-ldn-content-check/trunk/sql/ccm-ldn-content-check/oracle-se-create.sql 2005-08-29 05:26:15 UTC (rev 730) @@ -0,0 +1,21 @@ +-- +-- Copyright (C) 2005 Red Hat Inc. All Rights Reserved. +-- +-- This library is free software; you can redistribute it and/or +-- modify it under the terms of the GNU Lesser General Public License +-- as published by the Free Software Foundation; either version 2.1 of +-- the License, or (at your option) any later version. +-- +-- This library is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +-- Lesser General Public License for more details. +-- +-- You should have received a copy of the GNU Lesser General Public +-- License along with this library; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-- +-- $Id$ + +@@ default/table-cms_content_checks.sql + Added: contrib/ccm-ldn-content-check/trunk/sql/ccm-ldn-content-check/oracle-se-drop.sql =================================================================== --- contrib/ccm-ldn-content-check/trunk/sql/ccm-ldn-content-check/oracle-se-drop.sql 2005-08-29 05:20:48 UTC (rev 729) +++ contrib/ccm-ldn-content-check/trunk/sql/ccm-ldn-content-check/oracle-se-drop.sql 2005-08-29 05:26:15 UTC (rev 730) @@ -0,0 +1,21 @@ +-- +-- Copyright (C) 2005 Red Hat Inc. All Rights Reserved. +-- +-- This library is free software; you can redistribute it and/or +-- modify it under the terms of the GNU Lesser General Public License +-- as published by the Free Software Foundation; either version 2.1 of +-- the License, or (at your option) any later version. +-- +-- This library is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +-- Lesser General Public License for more details. +-- +-- You should have received a copy of the GNU Lesser General Public +-- License along with this library; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-- +-- $Id$ + +drop table cms_content_checks; + Added: contrib/ccm-ldn-content-check/trunk/sql/ccm-ldn-content-check/postgres-create.sql =================================================================== --- contrib/ccm-ldn-content-check/trunk/sql/ccm-ldn-content-check/postgres-create.sql 2005-08-29 05:20:48 UTC (rev 729) +++ contrib/ccm-ldn-content-check/trunk/sql/ccm-ldn-content-check/postgres-create.sql 2005-08-29 05:26:15 UTC (rev 730) @@ -0,0 +1,21 @@ +-- +-- Copyright (C) 2005 Red Hat Inc. All Rights Reserved. +-- +-- This library is free software; you can redistribute it and/or +-- modify it under the terms of the GNU Lesser General Public License +-- as published by the Free Software Foundation; either version 2.1 of +-- the License, or (at your option) any later version. +-- +-- This library is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +-- Lesser General Public License for more details. +-- +-- You should have received a copy of the GNU Lesser General Public +-- License along with this library; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-- +-- $Id$ + +\i default/table-cms_content_checks.sql + Added: contrib/ccm-ldn-content-check/trunk/sql/ccm-ldn-content-check/postgres-drop.sql =================================================================== --- contrib/ccm-ldn-content-check/trunk/sql/ccm-ldn-content-check/postgres-drop.sql 2005-08-29 05:20:48 UTC (rev 729) +++ contrib/ccm-ldn-content-check/trunk/sql/ccm-ldn-content-check/postgres-drop.sql 2005-08-29 05:26:15 UTC (rev 730) @@ -0,0 +1,21 @@ +-- +-- Copyright (C) 2005 Red Hat Inc. All Rights Reserved. +-- +-- This library is free software; you can redistribute it and/or +-- modify it under the terms of the GNU Lesser General Public License +-- as published by the Free Software Foundation; either version 2.1 of +-- the License, or (at your option) any later version. +-- +-- This library is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +-- Lesser General Public License for more details. +-- +-- You should have received a copy of the GNU Lesser General Public +-- License along with this library; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-- +-- $Id$ + +drop table cms_content_checks; + Added: contrib/ccm-ldn-content-check/trunk/src/ccm-ldn-content-check.config =================================================================== --- contrib/ccm-ldn-content-check/trunk/src/ccm-ldn-content-check.config 2005-08-29 05:20:48 UTC (rev 729) +++ contrib/ccm-ldn-content-check/trunk/src/ccm-ldn-content-check.config 2005-08-29 05:26:15 UTC (rev 730) @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="utf-8"?> +<registry> + <config class="com.arsdigita.london.cms.check.Config" + storage="ccm-ldn-content-check/content-check.properties"/> +</registry> Added: contrib/ccm-ldn-content-check/trunk/src/ccm-ldn-content-check.load =================================================================== --- contrib/ccm-ldn-content-check/trunk/src/ccm-ldn-content-check.load 2005-08-29 05:20:48 UTC (rev 729) +++ contrib/ccm-ldn-content-check/trunk/src/ccm-ldn-content-check.load 2005-08-29 05:26:15 UTC (rev 730) @@ -0,0 +1,15 @@ +<load> + <requires> + <table name="cms_items"/> + <initializer class="com.arsdigita.cms.Initializer"/> + <initializer class="com.arsdigita.london.cms.dublin.Initializer"/> + </requires> + <provides> + <table name="cms_content_checks"/> + <initializer class="com.arsdigita.london.cms.check.Initializer"/> + </provides> + <scripts> + <schema directory="ccm-ldn-content-check"/> + <data class="com.arsdigita.london.cms.check.Loader"/> + </scripts> +</load> Added: contrib/ccm-ldn-content-check/trunk/src/com/arsdigita/london/cms/check/Config.java =================================================================== --- contrib/ccm-ldn-content-check/trunk/src/com/arsdigita/london/cms/check/Config.java 2005-08-29 05:20:48 UTC (rev 729) +++ contrib/ccm-ldn-content-check/trunk/src/com/arsdigita/london/cms/check/Config.java 2005-08-29 05:26:15 UTC (rev 730) @@ -0,0 +1,47 @@ +package com.arsdigita.london.cms.check; + +import com.arsdigita.runtime.AbstractConfig; +import com.arsdigita.util.parameter.IntegerParameter; +import com.arsdigita.util.parameter.Parameter; +import com.arsdigita.util.parameter.StringArrayParameter; + +public class Config extends AbstractConfig { + + private final Parameter m_contentCheckTypes; + + private final Parameter m_contentCheckInterval; + + private final Parameter m_contentCheckLimit; + + public Config() { + super(); + m_contentCheckTypes = new StringArrayParameter( + "com.arsdigita.cms.check_types", Parameter.OPTIONAL, + new String[] { "com.arsdigita.cms.contenttypes.Article", + "com.arsdigita.cms.contenttypes.MultiPartArticle" }); + m_contentCheckInterval = new IntegerParameter( + "com.arsdigita.cms.check_interval", Parameter.REQUIRED, + new Integer(17 * 7) // in days, 17 weeks is default + ); + m_contentCheckLimit = new IntegerParameter( + "com.arsdigita.cms.check_limit", Parameter.REQUIRED, + new Integer(0)); + register(m_contentCheckTypes); + register(m_contentCheckInterval); + register(m_contentCheckLimit); + + } + + public final String[] getContentCheckTypes() { + return (String[]) get(m_contentCheckTypes); + } + + public final Integer getContentCheckInterval() { + return (Integer) get(m_contentCheckInterval); + } + + public final Integer getContentCheckLimit() { + return (Integer) get(m_contentCheckLimit); + } + +} Added: contrib/ccm-ldn-content-check/trunk/src/com/arsdigita/london/cms/check/Config_parameter.properties =================================================================== --- contrib/ccm-ldn-content-check/trunk/src/com/arsdigita/london/cms/check/Config_parameter.properties 2005-08-29 05:20:48 UTC (rev 729) +++ contrib/ccm-ldn-content-check/trunk/src/com/arsdigita/london/cms/check/Config_parameter.properties 2005-08-29 05:26:15 UTC (rev 730) @@ -0,0 +1,15 @@ +com.arsdigita.cms.check_types.title=Content Check Alerts: list of Content Types +com.arsdigita.cms.check_types.purpose=Content Types for which Content Check Alerts are sent (fully-qualified names of associated data object types) +com.arsdigita.cms.check_types.example=com.arsdigita.cms.contenttypes.Article,com.arsdigita.cms.contenttypes.MultiPartArticle +com.arsdigita.cms.check_types.format=[string,string,...] + +com.arsdigita.cms.check_interval.title=Content Check Alerts: outdate period +com.arsdigita.cms.check_interval.purpose=Interval in days after publishing, when Content Check Alert is issued. Default is 17 weeks. 0 to disable Content Check. +com.arsdigita.cms.check_interval.example=119 +com.arsdigita.cms.check_interval.format=[integer] + +com.arsdigita.cms.check_limit.title=Content Check Alerts: maximum number per day +com.arsdigita.cms.check_limit.purpose=Alerts are sent out daily, up to this limit. 0 for no limit. +com.arsdigita.cms.check_limit.example=0 +com.arsdigita.cms.check_limit.format=[integer] + Added: contrib/ccm-ldn-content-check/trunk/src/com/arsdigita/london/cms/check/ContentCheckAlert.java =================================================================== --- contrib/ccm-ldn-content-check/trunk/src/com/arsdigita/london/cms/check/ContentCheckAlert.java 2005-08-29 05:20:48 UTC (rev 729) +++ contrib/ccm-ldn-content-check/trunk/src/com/arsdigita/london/cms/check/ContentCheckAlert.java 2005-08-29 05:26:15 UTC (rev 730) @@ -0,0 +1,192 @@ +/* + * Copyright (C) 2005 Red Hat Inc. All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.london.cms.check; + +import java.math.BigDecimal; +import java.net.URLEncoder; +import java.util.Collection; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.TimerTask; + +import org.apache.log4j.Logger; + +import com.arsdigita.cms.ContentItem; +import com.arsdigita.cms.ContentSection; +import com.arsdigita.cms.ContentType; +import com.arsdigita.cms.util.GlobalizationUtil; +import com.arsdigita.cms.workflow.CMSTask; +import com.arsdigita.domain.DataObjectNotFoundException; +import com.arsdigita.kernel.Kernel; +import com.arsdigita.kernel.Party; +import com.arsdigita.mail.Mail; +import com.arsdigita.messaging.Message; +import com.arsdigita.messaging.MessagingException; +import com.arsdigita.notification.Notification; +import com.arsdigita.persistence.DataOperation; +import com.arsdigita.persistence.DataQuery; +import com.arsdigita.persistence.Session; +import com.arsdigita.persistence.SessionManager; +import com.arsdigita.persistence.TransactionContext; +import com.arsdigita.util.StringUtils; +import com.arsdigita.util.servlet.HttpHost; +import com.arsdigita.web.URL; +import com.arsdigita.web.Web; +import com.arsdigita.web.WebConfig; + +/** + * A TimerTask which will send alerts when items become outdated. + * Configured by registry parameters: + * com.arsdigita.cms.check_types, com.arsdigita.cms.check_interval and com.arsdigita.cms.check_limit. + */ +public class ContentCheckAlert extends TimerTask { + + private static final Logger s_log = Logger.getLogger(ContentCheckAlert.class); + + private String[] checkTypes; + private Collection checkTypeIDs = null; + private Integer interval; + private Integer limit; + private String serverURL; + + public ContentCheckAlert(String[] checkTypes, Integer interval, Integer limit) { + super(); + this.checkTypes = checkTypes; + this.interval = interval; + this.limit = limit; + this.serverURL = URL.root().getURL(); + } + + public void run() { + Thread.currentThread().setName("content-check"); + s_log.warn("Content Check start"); + TransactionContext txn = null; + DataQuery outdated = null; + try { + txn = SessionManager.getSession().getTransactionContext(); + txn.beginTxn(); + if (checkTypeIDs == null) { + checkTypeIDs = new LinkedList(); + for (int i=0,n=checkTypes.length; i<n; i++) { + try { + ContentType ct = ContentType.findByAssociatedObjectType(checkTypes[i]); + checkTypeIDs.add(ct.getID()); + } catch (DataObjectNotFoundException donfe) { + s_log.error("Content Check: Content Type "+checkTypes[i]+ " not found."); + } + } + } + if ( !checkTypeIDs.isEmpty() ) { + outdated = SessionManager.getSession().retrieveQuery("com.arsdigita.london.cms.check.getOutdatedContent"); + checkContent(outdated); + } + txn.commitTxn(); + } catch (Exception e) { + s_log.warn("error: ", e); + try { + if (txn != null) { + if (outdated != null) { + outdated.close(); + } + txn.abortTxn(); + } + } catch (Exception ee) { + s_log.warn("double fault: ",ee); + } + } + } + + private void checkContent(DataQuery outdated) { + outdated.setParameter("intervalDays", interval); + outdated.setParameter("contentTypes", checkTypeIDs); + outdated.addOrder("creatorContact"); + int totalItems = 0; + if (outdated.next()) { + String sender = CMSTask.getAlertsSender().getPrimaryEmail().getEmailAddress(); + String prevContact = (String) outdated.get("creatorContact"); + int msgCountDown = limit.intValue(); + // max number of alerts per day, initial limit 0 means no limit + if (msgCountDown == 0) { + msgCountDown--; + } + int i = 0; + StringBuffer itemURLs = new StringBuffer(); + Collection itemIDs = new LinkedList(); + do { + totalItems++; + BigDecimal itemID = (BigDecimal) outdated.get("itemID"); + String objectType = (String) outdated.get("objectType"); + String contact = (String) outdated.get("creatorContact"); + if ( !contact.equals(prevContact) ) { + if (sendAlert(sender, prevContact, itemURLs, i)) { + saveLastAlerts(itemIDs); + msgCountDown--; + } + // reset list of items + i = 0; + itemURLs = new StringBuffer(); + itemIDs.clear(); + prevContact = contact; + } + itemIDs.add(itemID); + itemURLs.append(++i).append(". ").append(serverURL) + .append("/redirect?oid=") + .append(URLEncoder.encode("["+objectType+":{id="+itemID+"}]")) + .append("&context=").append(ContentItem.DRAFT) // .LIVE + .append(StringUtils.NEW_LINE).append(StringUtils.NEW_LINE); + } while (msgCountDown != 0 && outdated.next()); + if (msgCountDown != 0) { + outdated.close(); + if (sendAlert(sender, prevContact, itemURLs, i)) { + saveLastAlerts(itemIDs); + } + } else { + s_log.warn(limit+" limit reached"); + } + } + s_log.warn("check performed for "+totalItems+" item(s)"); + } + + private boolean sendAlert(String from, String to, StringBuffer itemURLs, int n) { + Object[] args = new Object[2]; + args[0] = new Integer(n); + args[1] = itemURLs.toString(); + String subject = (String) GlobalizationUtil.globalize("cms.ui.content_check_alert.subject").localize(); + String body = (String) GlobalizationUtil.globalize("cms.ui.content_check_alert.body", args).localize(); + try { + Mail.send(to, from, subject, body); + if (s_log.isDebugEnabled()) { + s_log.debug("Mail to:"+to+" from:"+from+" subject:"+subject+" body:"+body); + } + return true; + } catch (Exception e) { + s_log.error("email error: ",e); + return false; + } + } + + private void saveLastAlerts(Collection itemIDs) { + DataOperation op = SessionManager.getSession().retrieveDataOperation("com.arsdigita.london.cms.check.updateContentCheck"); + for (Iterator iter=itemIDs.iterator(); iter.hasNext(); ) { + op.setParameter("itemID", iter.next()); + op.execute(); + } + } + +} Added: contrib/ccm-ldn-content-check/trunk/src/com/arsdigita/london/cms/check/Initializer.java =================================================================== --- contrib/ccm-ldn-content-check/trunk/src/com/arsdigita/london/cms/check/Initializer.java 2005-08-29 05:20:48 UTC (rev 729) +++ contrib/ccm-ldn-content-check/trunk/src/com/arsdigita/london/cms/check/Initializer.java 2005-08-29 05:26:15 UTC (rev 730) @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2005 Red Hat Inc. All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package com.arsdigita.london.cms.check; + +import java.util.Calendar; +import java.util.Timer; + +import org.apache.log4j.Logger; + +import com.arsdigita.db.DbHelper; +import com.arsdigita.persistence.pdl.ManifestSource; +import com.arsdigita.persistence.pdl.NameFilter; +import com.arsdigita.runtime.CompoundInitializer; +import com.arsdigita.runtime.DataInitEvent; +import com.arsdigita.runtime.PDLInitializer; +import com.arsdigita.runtime.RuntimeConfig; + +/** + * The CMS Content Check initializer. + * + * @version $Id$ + */ +public class Initializer extends CompoundInitializer { + public final static String versionId = + "$Id$"; + + private static final Logger s_log = Logger.getLogger + (Initializer.class); + + private static final Config s_config = new Config(); + + static { + s_config.load(); + } + + private Timer contentCheckTimer = null; + + public Initializer() { + final String url = RuntimeConfig.getConfig().getJDBCURL(); + final int database = DbHelper.getDatabaseFromURL(url); + + add(new PDLInitializer + (new ManifestSource + ("ccm-ldn-content-check.pdl.mf", + new NameFilter(DbHelper.getDatabaseSuffix(database), "pdl")))); + } + + public void init(DataInitEvent ev) { + super.init(ev); + contentCheckTimer =startContentCheck(); + } + + public static Config getConfig() { + return s_config; + } + + public Timer startContentCheck() { + String[] checkTypes = s_config.getContentCheckTypes(); + Integer interval = s_config.getContentCheckInterval(); + Integer limit = s_config.getContentCheckLimit(); + Timer contentCheckTimer = null; + if (interval.intValue() > 0 && checkTypes != null && checkTypes.length > 0) { + contentCheckTimer = new Timer(true); + ContentCheckAlert task = new ContentCheckAlert(checkTypes, interval, limit); + Calendar nextDay5am = Calendar.getInstance(); + nextDay5am.add(Calendar.DATE, 1); + nextDay5am.set(Calendar.HOUR_OF_DAY, 5); + // daily cron job at 5am + contentCheckTimer.scheduleAtFixedRate(task, nextDay5am.getTime(), 60L * 60 * 1000 * 24 ); + s_log.info("Content Check runs daily at 05:00"); + } else { + s_log.info("Content Check is DISABLED"); + } + return contentCheckTimer; + } + +} Added: contrib/ccm-ldn-content-check/trunk/src/com/arsdigita/london/cms/check/Loader.java =================================================================== --- contrib/ccm-ldn-content-check/trunk/src/com/arsdigita/london/cms/check/Loader.java 2005-08-29 05:20:48 UTC (rev 729) +++ contrib/ccm-ldn-content-check/trunk/src/com/arsdigita/london/cms/check/Loader.java 2005-08-29 05:26:15 UTC (rev 730) @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2005 Red Hat Inc. All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package com.arsdigita.london.cms.check; + +import com.arsdigita.runtime.ScriptContext; +import com.arsdigita.loader.PackageLoader; + +import org.apache.log4j.Logger; + +/** + * Empty Loader. + * + * @version $Id$ + */ +public class Loader extends PackageLoader { + public final static String versionId = + "$Id$"; + + private static final Logger s_log = Logger.getLogger(Loader.class); + + public void run(final ScriptContext ctx) { + // empty + } +} |