From: <pb...@fe...> - 2012-12-30 09:46:20
|
Author: pboy Date: 2012-12-30 09:46:08 +0000 (Sun, 30 Dec 2012) New Revision: 2446 Modified: contrib/camden/ccm-lbc-contentcheck/src/com/arsdigita/london/cms/check/Config.java contrib/camden/ccm-lbc-contentcheck/src/com/arsdigita/london/cms/check/ContentCheckAlert.java contrib/camden/ccm-lbc-contentcheck/src/com/arsdigita/london/cms/check/Initializer.java Log: First part of update to version 2.0. Does not compile yet. Modified: contrib/camden/ccm-lbc-contentcheck/src/com/arsdigita/london/cms/check/Config.java =================================================================== --- contrib/camden/ccm-lbc-contentcheck/src/com/arsdigita/london/cms/check/Config.java 2012-12-30 09:44:23 UTC (rev 2445) +++ contrib/camden/ccm-lbc-contentcheck/src/com/arsdigita/london/cms/check/Config.java 2012-12-30 09:46:08 UTC (rev 2446) @@ -1,3 +1,22 @@ +/* + * 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.AbstractConfig; @@ -4,45 +23,85 @@ import com.arsdigita.util.parameter.IntegerParameter; import com.arsdigita.util.parameter.Parameter; import com.arsdigita.util.parameter.StringArrayParameter; - import com.arsdigita.util.parameter.StringParameter; +import org.apache.log4j.Logger; + +/** + * A record containing server-session scoped configuration properties. + * + * Accessors of this class may return null. Developers should take care to trap + * null return values in their code. + * + * @version $Id: Config.java 2070 2012-12-28 08:47:41Z pboy $ + */ public class Config extends AbstractConfig { - private final Parameter m_contentCheckTypes; + /** Private Logger instance for debugging purpose. */ + private static final Logger s_log = Logger.getLogger(Config.class); - private final Parameter m_contentCheckInterval; + /** Private Object to hold one's own instance to return to users. */ + private static Config s_config; - private final Parameter m_contentCheckLimit; + /** + * Returns the singleton configuration config record. + * + * Use always this method to rtrieve a configuration object, never + * instantiate using the constructor (singelton pattern)! + * + * @return The <code>Config</code> record; it cannot be null + */ + public static synchronized Config getInstance() { + if (s_config == null) { + s_config = new Config(); + s_config.load(); + } + return s_config; + } - private final Parameter m_contentCheckFrom; + // /////////////////////////////////////////////////////////////////////// + // Config Parameter Section + // /////////////////////////////////////////////////////////////////////// + + private final Parameter m_contentCheckTypes = new StringArrayParameter( + "com.arsdigita.cms.check_types", Parameter.OPTIONAL, + new String[] { + "com.arsdigita.cms.contenttypes.Article", + "com.arsdigita.cms.contenttypes.MultiPartArticle" } + ); - private final Parameter m_contentCheckBcc; + private final Parameter m_contentCheckInterval = new IntegerParameter( + "com.arsdigita.cms.check_interval", Parameter.REQUIRED, + new Integer(17 * 7) // in days, 17 weeks is default + ); - private final Parameter m_contentCheckHour; - - 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( + private final Parameter m_contentCheckLimit = new IntegerParameter( "com.arsdigita.cms.check_limit", Parameter.REQUIRED, new Integer(0)); - m_contentCheckFrom = new StringParameter( - "com.arsdigita.cms.check_sender", Parameter.OPTIONAL,null - ); - m_contentCheckBcc = new StringParameter( - "com.arsdigita.cms.check_bcc", Parameter.OPTIONAL,null - ); - m_contentCheckHour = new IntegerParameter( + + private final Parameter m_contentCheckFrom = new StringParameter( + "com.arsdigita.cms.check_sender", Parameter.OPTIONAL, null ); + + private final Parameter m_contentCheckBcc = new StringParameter( + "com.arsdigita.cms.check_bcc", Parameter.OPTIONAL, null ); + + private final Parameter m_contentCheckHour = new IntegerParameter( "com.arsdigita.cms.check_hour", Parameter.REQUIRED, new Integer(5)); + + // /////////////////////////////////////////////////////////////////////// + // Config Parameter Section END + // /////////////////////////////////////////////////////////////////////// + + /** + * Constructor, but do NOT instantiate this class directly. + * + * Just registers the configuration parameters. + */ + public Config() { + // Remove testwise. does nothing at all (empty). + // super(); + register(m_contentCheckTypes); register(m_contentCheckInterval); register(m_contentCheckLimit); @@ -50,8 +109,15 @@ register(m_contentCheckBcc); register(m_contentCheckHour); + loadInfo(); + } + + // /////////////////////////////////////////////////////////////////////// + // Retrieve Parameter Section + // /////////////////////////////////////////////////////////////////////// + public final String[] getContentCheckTypes() { return (String[]) get(m_contentCheckTypes); } Modified: contrib/camden/ccm-lbc-contentcheck/src/com/arsdigita/london/cms/check/ContentCheckAlert.java =================================================================== --- contrib/camden/ccm-lbc-contentcheck/src/com/arsdigita/london/cms/check/ContentCheckAlert.java 2012-12-30 09:44:23 UTC (rev 2445) +++ contrib/camden/ccm-lbc-contentcheck/src/com/arsdigita/london/cms/check/ContentCheckAlert.java 2012-12-30 09:46:08 UTC (rev 2446) @@ -18,46 +18,39 @@ */ package com.arsdigita.london.cms.check; -import java.math.BigDecimal; -import java.net.URLEncoder; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.Map; -import java.util.Random; -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; +import java.math.BigDecimal; +import java.net.URLEncoder; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.Map; +import java.util.Random; +import java.util.TimerTask; +import org.apache.log4j.Logger; /** * 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. - * and optional arsdigita.cms.check_sender arsdigita.cms.check_bcc + * com.arsdigita.cms.check_types, + * com.arsdigita.cms.check_interval + * and + * com.arsdigita.cms.check_limit. + * + * and optional + * arsdigita.cms.check_sender + * arsdigita.cms.check_bcc */ public class ContentCheckAlert extends TimerTask { @@ -72,7 +65,19 @@ private String checkBcc; private String serverURL; - public ContentCheckAlert(String[] checkTypes, Integer interval, Integer limit, String checkFrom, String checkBcc) { + /** + * + * @param checkTypes + * @param interval + * @param limit + * @param checkFrom + * @param checkBcc + */ + public ContentCheckAlert(String[] checkTypes, + Integer interval, + Integer limit, + String checkFrom, + String checkBcc) { super(); this.checkTypes = checkTypes; this.interval = interval; @@ -82,7 +87,11 @@ this.serverURL = URL.root().getURL(); } + /** + * + */ public void run() { + Thread.currentThread().setName("content-check"); s_log.warn("Content Check start"); TransactionContext txn = null; @@ -102,7 +111,8 @@ } } if ( !checkTypeIDs.isEmpty() ) { - outdated = SessionManager.getSession().retrieveQuery("com.arsdigita.london.cms.check.getOutdatedContent"); + outdated = SessionManager.getSession() + .retrieveQuery("com.arsdigita.london.cms.check.getOutdatedContent"); checkContent(outdated); } txn.commitTxn(); @@ -123,6 +133,10 @@ } } + /** + * + * @param outdated + */ private void checkContent(DataQuery outdated) { //Set query parameters @@ -151,7 +165,8 @@ final String objectType = (String) outdated.get("objectType"); final String contact = (String) outdated.get("creatorContact"); final String itemHash = (String) outdated.get("alertMsgHash"); - s_log.debug("Retrieved outdated item (itemID,objectType,contact,itemHash): " + itemID+ objectType+ contact+ itemHash); + s_log.debug("Retrieved outdated item (itemID,objectType,contact,itemHash): " + + itemID + objectType + contact + itemHash); LinkedList alertItems = (LinkedList) creatorItemsMap.get(contact); if(alertItems == null) { @@ -191,6 +206,13 @@ s_log.warn("check performed for "+totalItems+" item(s)"); } + /** + * + * @param from + * @param to + * @param alertItems + * @return + */ private boolean sendAlert(String from, String to, LinkedList alertItems) { Object[] args = new Object[2]; args[0] = new Integer(alertItems.size()); @@ -203,7 +225,8 @@ ItemAlert itemAlert = (ItemAlert) it.next(); itemURLs.append(count++).append(". ").append(serverURL) .append("contentcheck/review_index.jsp?object=") - .append(URLEncoder.encode("["+itemAlert.getObjectType()+":{id="+itemAlert.getItemId()+"}]")) + .append(URLEncoder.encode("["+itemAlert.getObjectType() + +":{id="+itemAlert.getItemId()+"}]")) .append("&hash=") .append(itemAlert.getItemAlertHash()) .append("&oid=") @@ -214,14 +237,19 @@ } 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(); + 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 { - if(checkBcc != null) Mail.send(checkBcc, to, "Bcc: " + subject, body); + if(checkBcc != null) { + Mail.send(checkBcc, to, "Bcc: " + subject, body); + } Mail.send(to, from, subject, body); if (s_log.isDebugEnabled()) { - s_log.debug("Mail to:"+to+" from:"+from+" subject:"+subject+" body:"+body+" bcc:"+checkBcc); + s_log.debug("Mail to:"+to+" from:"+from+" subject:"+subject + +" body:"+body+" bcc:"+checkBcc); } return true; } catch (Exception e) { @@ -230,8 +258,14 @@ } } + /** + * + * @param alertItems + */ private void saveLastAlerts(LinkedList alertItems) { - DataOperation op = SessionManager.getSession().retrieveDataOperation("com.arsdigita.london.cms.check.updateContentCheck"); + DataOperation op = SessionManager.getSession() + .retrieveDataOperation( + "com.arsdigita.london.cms.check.updateContentCheck"); for (Iterator iter=alertItems.iterator(); iter.hasNext(); ) { ItemAlert itemAlert = (ItemAlert) iter.next(); op.setParameter("itemID", itemAlert.getItemId()); @@ -241,6 +275,9 @@ } } + /** + * + */ private static class ItemAlert { private final BigDecimal itemId; @@ -253,7 +290,8 @@ if(itemAlertHash == null || itemAlertHash.equals("null")) { //Create randam 10 char hash string - this.itemAlertHash = Long.toString(Math.abs(random.nextLong()), 79).substring(0,10); + this.itemAlertHash = Long.toString(Math + .abs(random.nextLong()),79).substring(0,10); s_log.debug("Created item alert hash " + this.itemAlertHash); } else { Modified: contrib/camden/ccm-lbc-contentcheck/src/com/arsdigita/london/cms/check/Initializer.java =================================================================== --- contrib/camden/ccm-lbc-contentcheck/src/com/arsdigita/london/cms/check/Initializer.java 2012-12-30 09:44:23 UTC (rev 2445) +++ contrib/camden/ccm-lbc-contentcheck/src/com/arsdigita/london/cms/check/Initializer.java 2012-12-30 09:46:08 UTC (rev 2446) @@ -18,18 +18,16 @@ 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.ContextInitEvent; import com.arsdigita.runtime.PDLInitializer; import com.arsdigita.runtime.RuntimeConfig; +import java.util.Calendar; +import java.util.Timer; +import org.apache.log4j.Logger; /** * The CMS Content Check initializer. @@ -37,18 +35,12 @@ * @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(); + private static final Config s_config = Config.getInstance(); - static { - s_config.load(); - } - private Timer contentCheckTimer = null; public Initializer() { @@ -57,19 +49,20 @@ add(new PDLInitializer (new ManifestSource - ("ccm-ldn-content-check.pdl.mf", + ("ccm-lbc-contentcheck.pdl.mf", new NameFilter(DbHelper.getDatabaseSuffix(database), "pdl")))); } - public void init(DataInitEvent ev) { + @Override + public void init(ContextInitEvent ev) { super.init(ev); contentCheckTimer =startContentCheck(); } - +/* Unused public static Config getConfig() { return s_config; } - +*/ public Timer startContentCheck() { String[] checkTypes = s_config.getContentCheckTypes(); Integer interval = s_config.getContentCheckInterval(); @@ -85,8 +78,12 @@ Calendar nextDay = Calendar.getInstance(); nextDay.add(Calendar.DATE, 1); - if(checkHour >= 0 && checkHour < 24) nextDay.set(Calendar.HOUR_OF_DAY, checkHour); - else nextDay.set(Calendar.HOUR_OF_DAY, 5); + if(checkHour >= 0 && checkHour < 24) { + nextDay.set(Calendar.HOUR_OF_DAY, checkHour); + } + else { + nextDay.set(Calendar.HOUR_OF_DAY, 5); + } // daily cron job //TODO uncomment |