diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/BasicPageForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/BasicPageForm.java
index c63aeb99b..fc85d4d26 100755
--- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/BasicPageForm.java
+++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/BasicPageForm.java
@@ -43,6 +43,7 @@ import com.arsdigita.util.Assert;
import org.arsdigita.cms.CMSConfig;
import org.libreccm.cdi.utils.CdiUtil;
import org.librecms.CmsConstants;
+import org.librecms.contentsection.ContentItemInitializer;
import org.librecms.contentsection.ContentItemManager;
import org.librecms.contentsection.ContentType;
@@ -240,16 +241,18 @@ public abstract class BasicPageForm extends BasicItemForm {
* @param name
* @param section
* @param folder
+ * @param initializer
*
* @return the new content item (or a proper subclass thereof)
*
* @throws com.arsdigita.bebop.FormProcessException
*/
- public ContentItem createContentPage(final PageState state,
- final String name,
- final ContentSection section,
- final Folder folder)
- throws FormProcessException {
+ public ContentItem createContentPage(
+ final PageState state,
+ final String name,
+ final ContentSection section,
+ final Folder folder,
+ final ContentItemInitializer initializer) throws FormProcessException {
final ItemSelectionModel selectionModel = getItemSelectionModel();
final ContentType contentType = selectionModel.getContentType();
@@ -265,7 +268,11 @@ public abstract class BasicPageForm extends BasicItemForm {
final Class extends ContentItem> clazz
= (Class extends ContentItem>) Class
.forName(contentType.getContentItemClass());
- item = itemManager.createContentItem(name, section, folder, clazz);
+ item = itemManager.createContentItem(name,
+ section,
+ folder,
+ clazz,
+ initializer);
} catch (ClassNotFoundException ex) {
throw new FormProcessException(
"Couldn't create contentpage",
@@ -276,7 +283,6 @@ public abstract class BasicPageForm extends BasicItemForm {
}
// Create new item
-
// Make sure the item will be remembered across requests
selectionModel.setSelectedKey(state, item.getObjectId());
diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/PageCreateForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/PageCreateForm.java
index b6d5606b1..7ecbf31ee 100755
--- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/PageCreateForm.java
+++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/PageCreateForm.java
@@ -23,7 +23,6 @@ import com.arsdigita.bebop.FormData;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.PageState;
-import com.arsdigita.bebop.Text;
import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.bebop.event.FormSubmissionListener;
import com.arsdigita.bebop.event.PrintEvent;
@@ -35,13 +34,13 @@ import org.librecms.contentsection.Folder;
import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.globalization.GlobalizedMessage;
-import com.arsdigita.kernel.KernelConfig;
import com.arsdigita.util.Assert;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.l10n.GlobalizationHelper;
import org.librecms.CmsConstants;
import org.librecms.contentsection.ContentItem;
+import org.librecms.contentsection.ContentItemInitializer;
import org.librecms.contenttypes.ContentTypeInfo;
import org.librecms.contenttypes.ContentTypesManager;
@@ -120,7 +119,8 @@ public class PageCreateForm
/* content type */
add(new Label(new GlobalizedMessage("cms.ui.authoring.content_type",
CmsConstants.CMS_BUNDLE)));
- final Label typeOutput = new Label(new ContentTypePrintListener(typeInfo));
+ final Label typeOutput = new Label(
+ new ContentTypePrintListener(typeInfo));
add(typeOutput);
/* language selection */
add(new Label(new GlobalizedMessage("cms.ui.language.field",
@@ -205,7 +205,7 @@ public class PageCreateForm
* @throws FormProcessException
*/
@Override
- public void process(final FormSectionEvent event)
+ public final void process(final FormSectionEvent event)
throws FormProcessException {
final FormData data = event.getFormData();
@@ -218,7 +218,9 @@ public class PageCreateForm
final ContentItem item = createContentPage(state,
(String) data.get(NAME),
section,
- folder);
+ folder,
+ getItemInitializer(data,
+ state));
final Locale locale = new Locale((String) data.get(LANGUAGE));
item.getName().addValue(locale, (String) data.get(NAME));
item.getTitle().addValue(locale, (String) data.get(TITLE));
@@ -228,6 +230,12 @@ public class PageCreateForm
creationSelector.editItem(state, item);
}
+ protected ContentItemInitializer> getItemInitializer(
+ final FormData data, final PageState state) {
+
+ return item -> {};
+ }
+
private class ContentTypePrintListener implements PrintListener {
private final ContentTypeInfo typeInfo;
@@ -247,7 +255,7 @@ public class PageCreateForm
globalizationHelper.getNegotiatedLocale());
final String typeLabel = bundle.getString(typeInfo.getLabelKey());
-
+
final Label target = (Label) event.getTarget();
target.setLabel(typeLabel);
}
diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/ContentItemInitializer.java b/ccm-cms/src/main/java/org/librecms/contentsection/ContentItemInitializer.java
new file mode 100644
index 000000000..4d70cc4d9
--- /dev/null
+++ b/ccm-cms/src/main/java/org/librecms/contentsection/ContentItemInitializer.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2017 LibreCCM Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301 USA
+ */
+package org.librecms.contentsection;
+
+/**
+ *
+ *
+ * @author Jens Pelzetter
+ * @param
+ */
+public interface ContentItemInitializer {
+
+ /**
+ * Initialise the provided item.
+ *
+ * @param item The item to initialise.
+ */
+ void initializeValues(T item);
+
+}
diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/ContentItemManager.java b/ccm-cms/src/main/java/org/librecms/contentsection/ContentItemManager.java
index fdecf8ab4..0f99f9517 100644
--- a/ccm-cms/src/main/java/org/librecms/contentsection/ContentItemManager.java
+++ b/ccm-cms/src/main/java/org/librecms/contentsection/ContentItemManager.java
@@ -123,7 +123,7 @@ public class ContentItemManager {
/**
* Creates a new content item in the provided content section and folder
- * with the workflow.
+ * with the default workflow for the content type of the item.
*
* The folder must be a subfolder of the
* {@link ContentSection#rootDocumentsFolder} of the provided content
@@ -146,6 +146,43 @@ public class ContentItemManager {
final Folder folder,
final Class type) {
+ return createContentItem(name,
+ section,
+ folder,
+ type,
+ item -> {
+ });
+
+ }
+
+ /**
+ * Creates a new content item in the provided content section and folder
+ * with the default workflow for the content type of the item.
+ *
+ * The folder must be a subfolder of the
+ * {@link ContentSection#rootDocumentsFolder} of the provided content
+ * section. Otherwise an {@link IllegalArgumentException} is thrown.
+ *
+ * @param The type of the content item.
+ * @param name The name (URL stub) of the new content item.
+ * @param section The content section in which the item is generated.
+ * @param folder The folder in which in the item is stored.
+ * @param type The type of the new content item.
+ * @param initalizer A {@link ContentItemInitializer} for setting mandatory
+ * values
+ *
+ * @return The new content item.
+ */
+ @AuthorizationRequired
+ @Transactional(Transactional.TxType.REQUIRED)
+ public T createContentItem(
+ final String name,
+ final ContentSection section,
+ @RequiresPrivilege(ItemPrivileges.CREATE_NEW)
+ final Folder folder,
+ final Class type,
+ final ContentItemInitializer initalizer) {
+
final Optional contentType = typeRepo
.findByContentSectionAndClass(section, type);
@@ -160,10 +197,11 @@ public class ContentItemManager {
section,
folder,
contentType.get().getDefaultWorkflow(),
- type);
+ type,
+ initalizer);
}
- /**
+ /**
* Creates a new content item in the provided content section and folder
* with specific workflow.
*
@@ -196,6 +234,52 @@ public class ContentItemManager {
final WorkflowTemplate workflowTemplate,
final Class type) {
+ return createContentItem(name,
+ section,
+ folder,
+ workflowTemplate,
+ type,
+ item -> {
+ });
+
+ }
+
+ /**
+ * Creates a new content item in the provided content section and folder
+ * with specific workflow.
+ *
+ * The folder must be a subfolder of the
+ * {@link ContentSection#rootDocumentsFolder} of the provided content
+ * section. Otherwise an {@link IllegalArgumentException} is thrown.
+ *
+ * Likewise the provided {@link WorkflowTemplate} must be defined in the
+ * provided content section. Otherwise an {@link IllegalArgumentException}
+ * is thrown.
+ *
+ * @param The type of the content item.
+ * @param name The name (URL stub) of the new content item.
+ * @param section The content section in which the item is
+ * generated.
+ * @param folder The folder in which in the item is stored.
+ * @param workflowTemplate The template for the workflow to apply to the new
+ * item.
+ * @param type The type of the new content item.
+ * @param initializer Initialiser implementation for setting mandatory
+ * properties of the new item.
+ *
+ * @return The new content item.
+ */
+ @AuthorizationRequired
+ @Transactional(Transactional.TxType.REQUIRED)
+ public T createContentItem(
+ final String name,
+ final ContentSection section,
+ @RequiresPrivilege(ItemPrivileges.CREATE_NEW)
+ final Folder folder,
+ final WorkflowTemplate workflowTemplate,
+ final Class type,
+ final ContentItemInitializer initializer) {
+
final Optional contentType = typeRepo
.findByContentSectionAndClass(section, type);
@@ -242,6 +326,10 @@ public class ContentItemManager {
item.setWorkflow(workflow);
}
+ if (initializer != null) {
+ initializer.initializeValues(item);
+ }
+
contentItemRepo.save(item);
categoryManager.addObjectToCategory(
diff --git a/ccm-cms/src/main/java/org/librecms/contenttypes/News.java b/ccm-cms/src/main/java/org/librecms/contenttypes/News.java
index 8dddfd3f4..94e748c25 100644
--- a/ccm-cms/src/main/java/org/librecms/contenttypes/News.java
+++ b/ccm-cms/src/main/java/org/librecms/contenttypes/News.java
@@ -18,7 +18,8 @@
*/
package org.librecms.contenttypes;
-import com.arsdigita.cms.ui.authoring.PageCreateForm;
+import com.arsdigita.cms.ui.contenttypes.NewsCreateForm;
+
import org.hibernate.envers.Audited;
import org.hibernate.validator.constraints.NotEmpty;
import org.libreccm.l10n.LocalizedString;
@@ -37,6 +38,7 @@ import javax.persistence.JoinTable;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
+import javax.validation.constraints.NotNull;
import static org.librecms.CmsConstants.*;
@@ -49,7 +51,7 @@ import static org.librecms.CmsConstants.*;
@Table(name = "NEWS", schema = DB_SCHEMA)
@ContentTypeDescription(labelBundle = "org.librecms.contenttypes.News",
descriptionBundle = "org.librecms.contenttypes.News")
-@AuthoringKit(createComponent = PageCreateForm.class,
+@AuthoringKit(createComponent = NewsCreateForm.class,
steps = {})
public class News extends ContentItem implements Serializable {
@@ -72,7 +74,7 @@ public class News extends ContentItem implements Serializable {
* Release date of the news
*/
@Column(name = "NEWS_DATE", nullable = false)
- @NotEmpty
+ @NotNull
@Temporal(TemporalType.DATE)
private Date releaseDate;
diff --git a/ccm-cms/src/main/resources/org/librecms/CmsResources.properties b/ccm-cms/src/main/resources/org/librecms/CmsResources.properties
index d6aea8ed4..1aacc9a4b 100644
--- a/ccm-cms/src/main/resources/org/librecms/CmsResources.properties
+++ b/ccm-cms/src/main/resources/org/librecms/CmsResources.properties
@@ -279,3 +279,4 @@ cms.ui.language.field=Sprache
cms.ui.authoring.workflow=Select a workflow
cms.ui.create=Create
cms.contenttypes.ui.summary=Summary
+cms.contenttypes.ui.newsitem.date\ =Release date
diff --git a/ccm-cms/src/main/resources/org/librecms/CmsResources_de.properties b/ccm-cms/src/main/resources/org/librecms/CmsResources_de.properties
index 487f1da76..fec8f7c7b 100644
--- a/ccm-cms/src/main/resources/org/librecms/CmsResources_de.properties
+++ b/ccm-cms/src/main/resources/org/librecms/CmsResources_de.properties
@@ -277,3 +277,4 @@ cms.ui.language.field=Sprache
cms.ui.authoring.workflow=Arbeitsablauf ausw\u00e4hlen
cms.ui.create=Anlegen
cms.contenttypes.ui.summary=Zusammenfassung
+cms.contenttypes.ui.newsitem.date\ =Erscheinungsdatum
diff --git a/ccm-cms/src/main/resources/org/librecms/CmsResources_fr.properties b/ccm-cms/src/main/resources/org/librecms/CmsResources_fr.properties
index 798c94e3b..0af3b51f4 100644
--- a/ccm-cms/src/main/resources/org/librecms/CmsResources_fr.properties
+++ b/ccm-cms/src/main/resources/org/librecms/CmsResources_fr.properties
@@ -236,3 +236,4 @@ cms.ui.language.field=Sprache
cms.ui.authoring.workflow=Select a workflow
cms.ui.create=Create
cms.contenttypes.ui.summary=Summary
+cms.contenttypes.ui.newsitem.date\ =Release date