Removed creation of new content sections via the initializer (Ticket #2029)
git-svn-id: https://svn.libreccm.org/ccm/trunk@2530 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
8aa2a7ea21
commit
3d25fc7630
File diff suppressed because it is too large
Load Diff
|
|
@ -1,8 +1,3 @@
|
||||||
com.arsdigita.cms.contentsection.new_section_name.title=Name of a new content section to be created during next ccm startup.
|
|
||||||
com.arsdigita.cms.contentsection.new_section_name.purpose=Name of a new content section to be created during next ccm startup. Will be ignored if it already exists.
|
|
||||||
com.arsdigita.cms.contentsection.new_section_name.example=content
|
|
||||||
com.arsdigita.cms.contentsection.new_section_name.format=[string]
|
|
||||||
|
|
||||||
com.arsdigita.cms.contentsection.xxx.title=
|
com.arsdigita.cms.contentsection.xxx.title=
|
||||||
com.arsdigita.cms.contentsection.xxx.purpose=
|
com.arsdigita.cms.contentsection.xxx.purpose=
|
||||||
com.arsdigita.cms.contentsection.xxx.example=/default/item.jsp
|
com.arsdigita.cms.contentsection.xxx.example=/default/item.jsp
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,6 @@
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
package com.arsdigita.cms.contentsection;
|
package com.arsdigita.cms.contentsection;
|
||||||
|
|
||||||
import com.arsdigita.cms.ContentSection;
|
import com.arsdigita.cms.ContentSection;
|
||||||
|
|
@ -41,19 +39,15 @@ import java.util.Timer;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the content section sub-package of the CMS package (module).
|
* Initializes the content section sub-package of the CMS package (module).
|
||||||
*
|
*
|
||||||
* XXX Reformulate according to the code development!
|
* XXX Reformulate according to the code development! This initializer performs: - check whether to
|
||||||
* This initializer performs:
|
* create an additional content sections during restart - initializes alert preferences for each
|
||||||
* - check whether to create an additional content sections during restart
|
* content section - initializes overdue alerts for each content section
|
||||||
* - initializes alert preferences for each content section
|
|
||||||
* - initializes overdue alerts for each content section
|
|
||||||
*
|
*
|
||||||
* In the (hopefully) near future:
|
* In the (hopefully) near future: Content section specific tasks of cms.Initializer will be moved
|
||||||
* Content section specific tasks of cms.Initializer will be moved into this
|
* into this Initializer.
|
||||||
* Initializer.
|
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @author Daniel Berrange (berrange@redhat.com)
|
* @author Daniel Berrange (berrange@redhat.com)
|
||||||
|
|
@ -63,22 +57,26 @@ import org.apache.log4j.Logger;
|
||||||
*/
|
*/
|
||||||
public class Initializer extends CompoundInitializer {
|
public class Initializer extends CompoundInitializer {
|
||||||
|
|
||||||
|
/**
|
||||||
/** Creates a s_logging category with name = to the full name of class */
|
* Creates a s_logging category with name = to the full name of class
|
||||||
|
*/
|
||||||
private static Logger s_log = Logger.getLogger(Initializer.class);
|
private static Logger s_log = Logger.getLogger(Initializer.class);
|
||||||
|
|
||||||
/** Configuration object ContentSectionConfig containing parameters
|
/**
|
||||||
which may be changed each system startup. */
|
* Configuration object ContentSectionConfig containing parameters which may be changed each
|
||||||
|
* system startup.
|
||||||
|
*/
|
||||||
private static final ContentSectionConfig s_conf = ContentSectionConfig
|
private static final ContentSectionConfig s_conf = ContentSectionConfig
|
||||||
.getInstance();
|
.getInstance();
|
||||||
|
|
||||||
/** The Timer used to send Unfinished notifications */
|
/**
|
||||||
|
* The Timer used to send Unfinished notifications
|
||||||
|
*/
|
||||||
private static Vector s_unfinishedTimers = new Vector();
|
private static Vector s_unfinishedTimers = new Vector();
|
||||||
|
|
||||||
|
|
||||||
public Initializer() {
|
public Initializer() {
|
||||||
//final String url = RuntimeConfig.getConfig().getJDBCURL();
|
//final String url = RuntimeConfig.getConfig().getJDBCURL();
|
||||||
//final int database = DbHelper.getDatabaseFromURL(url);
|
//final int database = DbHelper.getDatabaseFromURL(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Currently nothing to do here. May change during the ongoing migration process
|
// Currently nothing to do here. May change during the ongoing migration process
|
||||||
|
|
@ -89,10 +87,9 @@ public class Initializer extends CompoundInitializer {
|
||||||
// */
|
// */
|
||||||
// public void init(DataInitEvent evt) {
|
// public void init(DataInitEvent evt) {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes domain-coupling machinery, usually consisting of
|
* Initializes domain-coupling machinery, usually consisting of registering object instantiators
|
||||||
* registering object instantiators and observers.
|
* and observers.
|
||||||
*
|
*
|
||||||
* Here additionally checks whether to create a new content section.
|
* Here additionally checks whether to create a new content section.
|
||||||
*/
|
*/
|
||||||
|
|
@ -105,32 +102,27 @@ public class Initializer extends CompoundInitializer {
|
||||||
super.init(evt);
|
super.init(evt);
|
||||||
|
|
||||||
/* Register object instantiator for ContentSection */
|
/* Register object instantiator for ContentSection */
|
||||||
evt.getFactory().registerInstantiator
|
evt.getFactory().registerInstantiator(
|
||||||
(ContentSection.BASE_DATA_OBJECT_TYPE,
|
ContentSection.BASE_DATA_OBJECT_TYPE,
|
||||||
new ACSObjectInstantiator() {
|
new ACSObjectInstantiator() {
|
||||||
@Override
|
@Override
|
||||||
public DomainObject doNewInstance(DataObject dobj) {
|
public DomainObject doNewInstance(DataObject dobj) {
|
||||||
return new ContentSection(dobj);
|
return new ContentSection(dobj);
|
||||||
}
|
}
|
||||||
} );
|
|
||||||
|
|
||||||
// whether we have to create an additional (new) content section
|
});
|
||||||
// specified in config file.
|
|
||||||
checkForNewContentSection();
|
|
||||||
|
|
||||||
s_log.debug("contentsection.Initializer.init(DomainInitEvent) completed");
|
s_log.debug("contentsection.Initializer.init(DomainInitEvent) completed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of the {@link Initializer#init(ContextInitEvent)}
|
* Implementation of the {@link Initializer#init(ContextInitEvent)} method.
|
||||||
* method.
|
|
||||||
*
|
*
|
||||||
* Steps through all installed content sections and for each section
|
* Steps through all installed content sections and for each section - initializes the alert
|
||||||
* - initializes the alert preferences
|
* preferences - initializes the scheduler background thread to fire all alert events.
|
||||||
* - initializes the scheduler background thread to fire all alert events.
|
|
||||||
*
|
*
|
||||||
* A delay value of 0 inhibits start of processing.
|
* A delay value of 0 inhibits start of processing.
|
||||||
|
*
|
||||||
* @param evt The context init event.
|
* @param evt The context init event.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -145,23 +137,23 @@ public class Initializer extends CompoundInitializer {
|
||||||
// TODO: Store alerts prefs as well as timer configuration for each
|
// TODO: Store alerts prefs as well as timer configuration for each
|
||||||
// content section and make it configurable in the UI.
|
// content section and make it configurable in the UI.
|
||||||
// For now we step through all sections and configure them the same way.
|
// For now we step through all sections and configure them the same way.
|
||||||
ContentSectionCollection sections=ContentSection.getAllSections();
|
ContentSectionCollection sections = ContentSection.getAllSections();
|
||||||
while( sections.next() ) {
|
while (sections.next()) {
|
||||||
ContentSection section = sections.getContentSection();
|
ContentSection section = sections.getContentSection();
|
||||||
|
|
||||||
// Initialize workflow tasks and associated events from configuration
|
// Initialize workflow tasks and associated events from configuration
|
||||||
// file filling a hashmap.
|
// file filling a hashmap.
|
||||||
initializeTaskAlerts(section, s_conf.getTaskAlerts() );
|
initializeTaskAlerts(section, s_conf.getTaskAlerts());
|
||||||
|
|
||||||
// create a standard java util timer object
|
// create a standard java util timer object
|
||||||
Timer unfinishedTimer = startNotifierTask(
|
Timer unfinishedTimer = startNotifierTask(
|
||||||
section,
|
section,
|
||||||
s_conf.getSendOverdueAlerts(),
|
s_conf.getSendOverdueAlerts(),
|
||||||
s_conf.getTaskDuration(),
|
s_conf.getTaskDuration(),
|
||||||
s_conf.getAlertInterval(),
|
s_conf.getAlertInterval(),
|
||||||
s_conf.getMaxAlerts()
|
s_conf.getMaxAlerts()
|
||||||
);
|
);
|
||||||
if ( unfinishedTimer != null) {
|
if (unfinishedTimer != null) {
|
||||||
s_unfinishedTimers.addElement(unfinishedTimer);
|
s_unfinishedTimers.addElement(unfinishedTimer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -171,8 +163,7 @@ public class Initializer extends CompoundInitializer {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of the {@link Initializer#init(ContextCloseEvent)}
|
* Implementation of the {@link Initializer#init(ContextCloseEvent)} method.
|
||||||
* method.
|
|
||||||
*
|
*
|
||||||
* Stops various background threads started during startup process.
|
* Stops various background threads started during startup process.
|
||||||
*/
|
*/
|
||||||
|
|
@ -182,76 +173,36 @@ public class Initializer extends CompoundInitializer {
|
||||||
|
|
||||||
Timer unfinishedTimer = null;
|
Timer unfinishedTimer = null;
|
||||||
if (s_unfinishedTimers.size() > 0) {
|
if (s_unfinishedTimers.size() > 0) {
|
||||||
for (Enumeration el=s_unfinishedTimers.elements();
|
for (Enumeration el = s_unfinishedTimers.elements();
|
||||||
el.hasMoreElements(); ) {
|
el.hasMoreElements();) {
|
||||||
unfinishedTimer = (Timer) el.nextElement();
|
unfinishedTimer = (Timer) el.nextElement();
|
||||||
if(unfinishedTimer != null) {
|
if (unfinishedTimer != null) {
|
||||||
unfinishedTimer.cancel();
|
unfinishedTimer.cancel();
|
||||||
}
|
}
|
||||||
unfinishedTimer = null;
|
unfinishedTimer = null;
|
||||||
// s_unfinishedTimer = null;
|
// s_unfinishedTimer = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
s_log.debug("content section ContextCloseEvent completed");
|
s_log.debug("content section ContextCloseEvent completed");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkForNewContentSection() {
|
|
||||||
|
|
||||||
// Check here weather a new content section has to be created.
|
|
||||||
String newSectionName = s_conf.getNewContentSectionName();
|
|
||||||
if (newSectionName != null && !newSectionName.isEmpty() ) {
|
|
||||||
ContentSectionCollection sections=ContentSection.getAllSections();
|
|
||||||
sections.addEqualsFilter( Application.PRIMARY_URL,
|
|
||||||
"/" + newSectionName + "/" );
|
|
||||||
ContentSection section;
|
|
||||||
if( sections.next() ) {
|
|
||||||
// Section with the configured name already exists
|
|
||||||
s_log.warn( "Content section " + newSectionName +
|
|
||||||
" already exists, skipping creation task.\n" +
|
|
||||||
"You may delete the entry from configuration file.");
|
|
||||||
section = sections.getContentSection();
|
|
||||||
sections.close();
|
|
||||||
} else {
|
|
||||||
s_log.info( "Content section " + newSectionName + " in " +
|
|
||||||
" doesn't exist, creating it." );
|
|
||||||
TransactionContext txn = SessionManager.getSession()
|
|
||||||
.getTransactionContext();
|
|
||||||
txn.beginTxn();
|
|
||||||
ContentSectionSetup.setupContentSectionAppInstance
|
|
||||||
(newSectionName,
|
|
||||||
s_conf.getDefaultRoles(),
|
|
||||||
s_conf.getDefaultWorkflows(),
|
|
||||||
s_conf.isPubliclyViewable(),
|
|
||||||
s_conf.getItemResolverClass(),
|
|
||||||
s_conf.getTemplateResolverClass(),
|
|
||||||
s_conf.getContentSectionsContentTypes(),
|
|
||||||
s_conf.getUseSectionCategories(),
|
|
||||||
s_conf.getCategoryFileList()
|
|
||||||
);
|
|
||||||
txn.commitTxn();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Steps through a string array of tasks and associated alert events
|
* Steps through a string array of tasks and associated alert events creating section specific
|
||||||
* creating section specific CMStasks from configuration file.
|
* CMStasks from configuration file.
|
||||||
*
|
*
|
||||||
* Note: Tasks are created on a per section base, but we have currently no
|
* Note: Tasks are created on a per section base, but we have currently no way to store
|
||||||
* way to store different values for each section. So all sections are
|
* different values for each section. So all sections are configured equal.
|
||||||
* configured equal.
|
|
||||||
*
|
*
|
||||||
* @param section A section object
|
* @param section A section object
|
||||||
* @param taskAlerts An array of tasks and associated events
|
* @param taskAlerts An array of tasks and associated events
|
||||||
*/
|
*/
|
||||||
public void initializeTaskAlerts(ContentSection section,
|
public void initializeTaskAlerts(ContentSection section,
|
||||||
String[] taskAlerts) {
|
String[] taskAlerts) {
|
||||||
|
|
||||||
if (taskAlerts != null) {
|
if (taskAlerts != null) {
|
||||||
for (int i=0,n=taskAlerts.length; i<n; i++) {
|
for (int i = 0, n = taskAlerts.length; i < n; i++) {
|
||||||
StringTokenizer tok = new StringTokenizer(taskAlerts[i],":");
|
StringTokenizer tok = new StringTokenizer(taskAlerts[i], ":");
|
||||||
try {
|
try {
|
||||||
String taskName = tok.nextToken();
|
String taskName = tok.nextToken();
|
||||||
while (tok.hasMoreTokens()) {
|
while (tok.hasMoreTokens()) {
|
||||||
|
|
@ -266,39 +217,38 @@ public class Initializer extends CompoundInitializer {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param section content section for which notifier should be started
|
* @param section content section for which notifier should be started
|
||||||
* @param sendOverdue
|
* @param sendOverdue
|
||||||
* @param duration
|
* @param duration
|
||||||
* @param alertInterval
|
* @param alertInterval
|
||||||
* @param max
|
* @param max
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private Timer startNotifierTask( ContentSection section,
|
private Timer startNotifierTask(ContentSection section,
|
||||||
Boolean sendOverdue,
|
Boolean sendOverdue,
|
||||||
Integer duration,
|
Integer duration,
|
||||||
Integer alertInterval,
|
Integer alertInterval,
|
||||||
Integer max
|
Integer max
|
||||||
) {
|
) {
|
||||||
Timer unfinished = null;
|
Timer unfinished = null;
|
||||||
if (sendOverdue.booleanValue()) {
|
if (sendOverdue.booleanValue()) {
|
||||||
if (duration == null || alertInterval == null || max == null) {
|
if (duration == null || alertInterval == null || max == null) {
|
||||||
s_log.info("Not sending overdue task alerts, " +
|
s_log.info("Not sending overdue task alerts, "
|
||||||
"required initialization parameters were not specified");
|
+ "required initialization parameters were not specified");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// start the Timer as a daemon, so it doesn't keep the JVM from exiting
|
// start the Timer as a daemon, so it doesn't keep the JVM from exiting
|
||||||
unfinished = new Timer(true);
|
unfinished = new Timer(true);
|
||||||
UnfinishedTaskNotifier notifier = new UnfinishedTaskNotifier(
|
UnfinishedTaskNotifier notifier = new UnfinishedTaskNotifier(
|
||||||
section,
|
section,
|
||||||
duration.intValue(),
|
duration.intValue(),
|
||||||
alertInterval.intValue(),
|
alertInterval.intValue(),
|
||||||
max.intValue() );
|
max.intValue());
|
||||||
// schedule the Task to start in 5 minutes, at 1 hour intervals
|
// schedule the Task to start in 5 minutes, at 1 hour intervals
|
||||||
unfinished.schedule(notifier, 5L * 60 * 1000, 60L * 60 * 1000);
|
unfinished.schedule(notifier, 5L * 60 * 1000, 60L * 60 * 1000);
|
||||||
s_log.info("Sending overdue alerts for tasks greater than " +
|
s_log.info("Sending overdue alerts for tasks greater than " + duration + " hours old");
|
||||||
duration + " hours old");
|
|
||||||
} else {
|
} else {
|
||||||
s_log.info("Not sending overdue task alerts");
|
s_log.info("Not sending overdue task alerts");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue