diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/BaseAdminPane.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/BaseAdminPane.java new file mode 100755 index 000000000..b232d9c4d --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/BaseAdminPane.java @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2003-2004 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.cms.ui; + +import com.arsdigita.bebop.Component; +import com.arsdigita.bebop.SingleSelectionModel; +import com.arsdigita.bebop.list.ListModelBuilder; +import com.arsdigita.bebop.tree.TreeModelBuilder; +import com.arsdigita.globalization.GlobalizedMessage; +import com.arsdigita.toolbox.ui.SelectionPanel; +import org.apache.log4j.Logger; +import org.librecms.CmsConstants; + +/** + * A base component for use in CMS admin panes. + * + * @author Justin Ross <jross@redhat.com> + */ +public abstract class BaseAdminPane extends SelectionPanel { + + /** Internal logger instance to faciliate debugging. Enable logging output + * by editing /WEB-INF/conf/log4j.properties int the runtime environment + * and set com.arsdigita.cms.ui.BaseAdminPane=DEBUG + * by uncommenting or adding the line. */ + private static final Logger s_log = Logger.getLogger(BaseAdminPane.class); + + protected BaseAdminPane() { + super(); + } + + protected BaseAdminPane(final Component title, + final Component selector) { + super(title, selector); + } + + protected BaseAdminPane(final GlobalizedMessage title, + final Component selector) { + super(title, selector); + } + + protected BaseAdminPane(final Component title, + final Component selector, + final SingleSelectionModel model) { + super(title, selector, model); + } + + protected BaseAdminPane(final GlobalizedMessage title, + final Component selector, + final SingleSelectionModel model) { + super(title, selector, model); + } + + protected BaseAdminPane(final Component title, + final ListModelBuilder builder) { + super(title, builder); + } + + protected BaseAdminPane(final GlobalizedMessage title, + final ListModelBuilder builder) { + super(title, builder); + } + + protected BaseAdminPane(final Component title, + final TreeModelBuilder builder) { + super(title, builder); + } + + protected BaseAdminPane(final GlobalizedMessage title, + final TreeModelBuilder builder) { + super(title, builder); + } + + protected static GlobalizedMessage gz(final String key) { + return new GlobalizedMessage(key, CmsConstants.CMS_BUNDLE); + } + + protected static String lz(final String key) { + return (String) gz(key).localize(); + } +} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/lifecycle/LifecycleAdminPane.java.off b/ccm-cms/src/main/java/com/arsdigita/cms/ui/lifecycle/LifecycleAdminPane.java.off index a375e8f39..55ab2b208 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/lifecycle/LifecycleAdminPane.java.off +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/lifecycle/LifecycleAdminPane.java.off @@ -24,9 +24,8 @@ import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.SingleSelectionModel; import com.arsdigita.bebop.event.FormSectionEvent; import com.arsdigita.cms.CMS; -import com.arsdigita.cms.ContentSection; -import com.arsdigita.cms.SecurityManager; -import com.arsdigita.cms.lifecycle.LifecycleDefinition; +import org.librecms.contentsection.ContentSection; +import org.librecms.lifecycle.LifecycleDefinition; import com.arsdigita.cms.ui.BaseAdminPane; import com.arsdigita.cms.ui.BaseDeleteForm; import com.arsdigita.cms.ui.FormSecurityListener; diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/lifecycle/LifecycleDefinitionRequestLocal.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/lifecycle/LifecycleDefinitionRequestLocal.java new file mode 100755 index 000000000..7285f968e --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/lifecycle/LifecycleDefinitionRequestLocal.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2003-2004 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.cms.ui.lifecycle; + +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.RequestLocal; +import org.librecms.lifecycle.LifecycleDefinition; +import org.apache.log4j.Logger; + +public abstract class LifecycleDefinitionRequestLocal extends RequestLocal { + + private static final Logger s_log = Logger.getLogger + (LifecycleDefinitionRequestLocal.class); + + public final LifecycleDefinition getLifecycleDefinition + (final PageState state) { + return (LifecycleDefinition) get(state); + } +} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/lifecycle/LifecycleListModelBuilder.java.off b/ccm-cms/src/main/java/com/arsdigita/cms/ui/lifecycle/LifecycleListModelBuilder.java.off new file mode 100755 index 000000000..17a2ecdcf --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/lifecycle/LifecycleListModelBuilder.java.off @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2003-2004 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.cms.ui.lifecycle; + +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.list.ListModel; +import com.arsdigita.bebop.list.ListModelBuilder; +import com.arsdigita.cms.CMS; +import org.librecms.contentsection.ContentSection; +import com.arsdigita.util.LockableImpl; +import com.arsdigita.util.UncheckedWrapperException; +import java.util.List; + +import java.util.NoSuchElementException; +import org.librecms.lifecycle.LifecycleDefinition; + +/** + * Loads all the current lifecycles from the database so that they may be + * displayed in a list. + * + * @author Jens Pelzetter + * @author Michael Pih + * @author Jack Chung + */ +public final class LifecycleListModelBuilder extends LockableImpl + implements ListModelBuilder { + + @Override + public final ListModel makeModel(final com.arsdigita.bebop.List list, + final PageState state) { + return new Model(state); + } + + private class Model implements ListModel { + + private List m_cycles; + + public Model(final PageState state) { + m_cycles = getCollection(state); + } + + private List getCollection(final PageState state) { + final ContentSection section = CMS.getContext().getContentSection(); + + final List cycles = section.get + getLifecycleDefinitions(); + + cycles.addOrder("upper(label)"); + + return cycles; + } + + public boolean next() throws NoSuchElementException { + return m_cycles.next(); + } + + public Object getElement() { + return m_cycles.getLifecycleDefinition().getLabel(); + } + + public String getKey() { + return m_cycles.getLifecycleDefinition().getID().toString(); + } + } +} diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/ContentSection.java b/ccm-cms/src/main/java/org/librecms/contentsection/ContentSection.java index 40d4c4485..d72e4b33e 100644 --- a/ccm-cms/src/main/java/org/librecms/contentsection/ContentSection.java +++ b/ccm-cms/src/main/java/org/librecms/contentsection/ContentSection.java @@ -18,7 +18,6 @@ */ package org.librecms.contentsection; - import org.libreccm.categorization.Category; import org.libreccm.security.Role; import org.libreccm.web.CcmApplication; @@ -42,6 +41,8 @@ import java.util.ArrayList; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; import javax.persistence.OneToMany; +import org.libreccm.workflow.WorkflowTemplate; +import org.librecms.lifecycle.LifecycleDefinition; import static org.librecms.CmsConstants.*; @@ -53,14 +54,14 @@ import static org.librecms.CmsConstants.*; @Table(name = "CONTENT_SECTIONS", schema = DB_SCHEMA) @NamedQueries({ @NamedQuery( - name = "ContentSection.findByLabel", - query = "SELECT s FROM ContentSection s WHERE s.label = :label"), + name = "ContentSection.findByLabel", + query = "SELECT s FROM ContentSection s WHERE s.label = :label"), @NamedQuery( - name = "ContentSection.findPermissions", - query = "SELECT p FROM Permission p " - + "WHERE (p.object = :section " - + " OR p.object = :rootDocumentsFolder) " - + "AND p.grantee = :role") + name = "ContentSection.findPermissions", + query = "SELECT p FROM Permission p " + + "WHERE (p.object = :section " + + " OR p.object = :rootDocumentsFolder) " + + "AND p.grantee = :role") }) //@ApplicationType( // name = CONTENT_SECTION_APP_TYPE, @@ -118,10 +119,34 @@ public class ContentSection extends CcmApplication implements Serializable { @Column(name = "DEFAULT_LOCALE") private Locale defaultLocale; - + @OneToMany(mappedBy = "contentSection") private List contentTypes; + @OneToMany + @JoinTable( + name = "CONTENT_SECTION_LIFECYCLE_DEFINITIONS", + joinColumns = { + @JoinColumn(name = "CONTENT_SECTION_ID") + }, + inverseJoinColumns = { + @JoinColumn(name = "LIFECYCLE_DEFINITION_ID") + } + ) + private List lifecycleDefinitions; + + @OneToMany + @JoinTable( + name = "CONTENT_SECTION_WORKFLOW_TEMPLATES", + joinColumns = { + @JoinColumn(name = "CONTENT_SECTION_ID") + }, + inverseJoinColumns = { + @JoinColumn(name = "WORKFLOW_TEMPLATE_ID") + } + ) + private List workflowTemplates; + public ContentSection() { roles = new ArrayList<>(); } @@ -222,19 +247,53 @@ public class ContentSection extends CcmApplication implements Serializable { public List getContentTypes() { return Collections.unmodifiableList(contentTypes); } - + protected void setContentTypes(final List contentTypes) { this.contentTypes = contentTypes; } - + protected void addContentType(final ContentType contentType) { contentTypes.add(contentType); } - + protected void removeContentType(final ContentType contentType) { contentTypes.remove(contentType); } - + + public List getLifecycleDefinitions() { + return Collections.unmodifiableList(lifecycleDefinitions); + } + + protected void setLifecycleDefinitions( + final List lifecycleDefinitions) { + this.lifecycleDefinitions = lifecycleDefinitions; + } + + protected void addLifecycleDefinition(final LifecycleDefinition definition) { + lifecycleDefinitions.add(definition); + } + + protected void removeLifecycleDefinition( + final LifecycleDefinition definition) { + lifecycleDefinitions.remove(definition); + } + + public List getWorkflowTemplates() { + return Collections.unmodifiableList(workflowTemplates); + } + + protected void setWorkflowTemplates(final List workflowTemplates) { + this.workflowTemplates = workflowTemplates; + } + + protected void addWorkflowTemplate(final WorkflowTemplate template) { + workflowTemplates.add(template); + } + + protected void removeWorkflowTemplate(final WorkflowTemplate template) { + workflowTemplates.remove(template); + } + @Override public int hashCode() { int hash = super.hashCode(); @@ -301,23 +360,23 @@ public class ContentSection extends CcmApplication implements Serializable { @Override public String toString(final String data) { return super.toString(String.format( - ", label = \"%s\", " - + "rootDocumentsFolder = \"%s\", " - + "rootAssetsFolder = \"%s\", " - + "pageResolverClass = \"%s\", " - + "itemResolverClass = \"%s\", " - + "templateResolverClass = \"%s\", " - + "xmlGeneratorClass = \"%s\", " - + "defaultLocale = \"%s\"%s", - label, - Objects.toString(rootDocumentsFolder), - Objects.toString(rootAssetsFolder), - pageResolverClass, - itemResolverClass, - templateResolverClass, - xmlGeneratorClass, - Objects.toString(defaultLocale), - data)); + ", label = \"%s\", " + + "rootDocumentsFolder = \"%s\", " + + "rootAssetsFolder = \"%s\", " + + "pageResolverClass = \"%s\", " + + "itemResolverClass = \"%s\", " + + "templateResolverClass = \"%s\", " + + "xmlGeneratorClass = \"%s\", " + + "defaultLocale = \"%s\"%s", + label, + Objects.toString(rootDocumentsFolder), + Objects.toString(rootAssetsFolder), + pageResolverClass, + itemResolverClass, + templateResolverClass, + xmlGeneratorClass, + Objects.toString(defaultLocale), + data)); } } diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/ContentSectionManager.java b/ccm-cms/src/main/java/org/librecms/contentsection/ContentSectionManager.java index 040a81b0d..86b72dae0 100644 --- a/ccm-cms/src/main/java/org/librecms/contentsection/ContentSectionManager.java +++ b/ccm-cms/src/main/java/org/librecms/contentsection/ContentSectionManager.java @@ -41,6 +41,7 @@ import javax.inject.Inject; import javax.persistence.EntityManager; import javax.persistence.TypedQuery; import javax.transaction.Transactional; +import org.librecms.lifecycle.LifecycleDefinition; import static org.librecms.CmsConstants.*; import static org.librecms.contentsection.ContentSection.*; @@ -275,6 +276,43 @@ public class ContentSectionManager { throw new UnsupportedOperationException(); } + @AuthorizationRequired + @RequiresPrivilege(CoreConstants.ADMIN_PRIVILEGE) + @Transactional(Transactional.TxType.REQUIRED) + public void addLifecycleDefinitionToContentSection( + final LifecycleDefinition definition, + final ContentSection section) { + throw new UnsupportedOperationException(); + } + + @AuthorizationRequired + @RequiresPrivilege(CoreConstants.ADMIN_PRIVILEGE) + @Transactional(Transactional.TxType.REQUIRED) + public void removeLifecycleDefinitionFromContentSection( + final LifecycleDefinition definition, + final ContentSection contentSection) { + throw new UnsupportedOperationException(); + } + + @AuthorizationRequired + @RequiresPrivilege(CoreConstants.ADMIN_PRIVILEGE) + @Transactional(Transactional.TxType.REQUIRED) + public void addWorkflowTemplateToContentSection( + final LifecycleDefinition definition, + final ContentSection section) { + throw new UnsupportedOperationException(); + } + + @AuthorizationRequired + @RequiresPrivilege(CoreConstants.ADMIN_PRIVILEGE) + @Transactional(Transactional.TxType.REQUIRED) + + public void removeWorkflowTemplateFromContentSection( + final LifecycleDefinition definition, + final ContentSection contentSection) { + throw new UnsupportedOperationException(); + } + public ItemResolver getItemResolver(final ContentSection section) { try { final Class itemResolverClazz = (Class) Class.