CCM NG/ccm-cms: More work for the authoring steps

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4795 8810af33-2d31-482b-a856-94f89814c4df
pull/2/head
jensp 2017-06-21 18:20:41 +00:00
parent 3a538ff8fd
commit da7f83cee2
8 changed files with 299 additions and 41 deletions

View File

@ -43,16 +43,10 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.security.PermissionChecker;
import org.libreccm.workflow.AssignableTask;
import org.libreccm.workflow.AssignableTaskManager;
import org.libreccm.workflow.Workflow;
import org.libreccm.workflow.WorkflowManager;
import org.libreccm.workflow.WorkflowTemplate;
import org.libreccm.workflow.WorkflowTemplateRepository;
import org.librecms.CmsConstants;
import org.librecms.contentsection.privileges.ItemPrivileges;
import java.util.ArrayList;
import java.util.List;
import java.util.TooManyListenersException;
@ -206,6 +200,10 @@ public class ApplyWorkflowFormSection
return result;
}
public Long getSelectedWorkflowTemplateId(final PageState state) {
return (Long) radioGroup.getValue(state);
}
/**
* Apply the proper initial workflow to the item. If the user has
* SecurityConstants.APPLY_ALTERNATE_WORKFLOWS permission on the parent

View File

@ -42,6 +42,7 @@ import com.arsdigita.util.Assert;
import org.arsdigita.cms.CMSConfig;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.workflow.WorkflowTemplate;
import org.librecms.CmsConstants;
import org.librecms.contentsection.ContentItemInitializer;
import org.librecms.contentsection.ContentItemManager;
@ -247,32 +248,105 @@ public abstract class BasicPageForm extends BasicItemForm {
*
* @throws com.arsdigita.bebop.FormProcessException
*/
public ContentItem createContentPage(
public <T extends ContentItem> T createContentPage(
final PageState state,
final String name,
final ContentSection section,
final Folder folder,
final ContentItemInitializer initializer) throws FormProcessException {
final ContentItemInitializer<T> initializer) throws FormProcessException {
// final ItemSelectionModel selectionModel = getItemSelectionModel();
// final ContentType contentType = selectionModel.getContentType();
//
// final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
// final ContentItemManager itemManager = cdiUtil
// .findBean(ContentItemManager.class);
//
// // Create new item
// final ContentItem item;
// try {
// @SuppressWarnings("unchecked")
// final Class<? extends ContentItem> clazz
// = (Class<? extends ContentItem>) Class
// .forName(contentType.getContentItemClass());
// item = itemManager.createContentItem(name,
// section,
// folder,
// clazz,
// initializer);
// } catch (ClassNotFoundException ex) {
// throw new FormProcessException(
// "Couldn't create contentpage",
// new GlobalizedMessage(
// "cms.ui.authoring.couldnt_create_contentpage",
// CmsConstants.CMS_BUNDLE),
// ex);
// }
//
// // Create new item
// // Make sure the item will be remembered across requests
// selectionModel.setSelectedKey(state, item.getObjectId());
//
// return item;
return createContentItemPage(state,
name,
section,
folder,
null,
initializer);
}
public <T extends ContentItem> T createContentItemPage(
final PageState state,
final String name,
final ContentSection section,
final Folder folder,
final WorkflowTemplate workflowTemplate,
final ContentItemInitializer<T> initializer) throws FormProcessException {
final ItemSelectionModel selectionModel = getItemSelectionModel();
final ContentType contentType = selectionModel.getContentType();
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final ContentItemManager itemManager = cdiUtil
.findBean(ContentItemManager.class);
// Create new item
final ContentItem item;
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
// final ContentItemManager itemManager = cdiUtil
// .findBean(ContentItemManager.class);
final BasicPageFormController controller = cdiUtil
.findBean(BasicPageFormController.class);
final T item;
try {
@SuppressWarnings("unchecked")
final Class<? extends ContentItem> clazz
= (Class<? extends ContentItem>) Class
.forName(contentType.getContentItemClass());
item = itemManager.createContentItem(name,
section,
folder,
clazz,
initializer);
final Class<T> clazz = (Class<T>) Class
.forName(contentType.getContentItemClass());
// @SuppressWarnings("unchecked")
// final Class<? extends ContentItem> clazz
// = (Class<? extends ContentItem>) Class
// .forName(contentType.getContentItemClass());
//
if (workflowTemplate == null) {
// item = itemManager.createContentItem(name,
// section,
// folder,
// clazz,
// initializer);
item = controller.createContentItem(name, section, folder, clazz,
initializer);
} else {
// item = itemManager.createContentItem(name,
// section,
// folder,
// workflowTemplate,
// clazz,
// initializer);
item = controller.createContentItem(name,
section,
folder,
workflowTemplate,
clazz,
initializer);
}
} catch (ClassNotFoundException ex) {
throw new FormProcessException(
"Couldn't create contentpage",
@ -282,7 +356,6 @@ public abstract class BasicPageForm extends BasicItemForm {
ex);
}
// Create new item
// Make sure the item will be remembered across requests
selectionModel.setSelectedKey(state, item.getObjectId());

View File

@ -0,0 +1,117 @@
/*
* 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 com.arsdigita.cms.ui.authoring;
import org.libreccm.workflow.WorkflowTemplate;
import org.libreccm.workflow.WorkflowTemplateRepository;
import org.librecms.contentsection.ContentItem;
import org.librecms.contentsection.ContentItemInitializer;
import org.librecms.contentsection.ContentItemManager;
import org.librecms.contentsection.ContentItemRepository;
import org.librecms.contentsection.ContentSection;
import org.librecms.contentsection.ContentSectionRepository;
import org.librecms.contentsection.Folder;
import org.librecms.contentsection.FolderRepository;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.transaction.Transactional;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
class BasicPageFormController {
@Inject
private ContentSectionRepository sectionRepo;
@Inject
private ContentItemRepository itemRepo;
@Inject
private ContentItemManager itemManager;
@Inject
private FolderRepository folderRepo;
@Inject
private WorkflowTemplateRepository workflowTemplateRepo;
@Transactional(Transactional.TxType.REQUIRED)
protected <T extends ContentItem> T createContentItem(
final String name,
final ContentSection section,
final Folder folder,
final Class<T> clazz,
final ContentItemInitializer<T> initializer) {
return createContentItem(name, section, folder, null, clazz, initializer);
}
@Transactional(Transactional.TxType.REQUIRED)
protected <T extends ContentItem> T createContentItem(
final String name,
final ContentSection section,
final Folder folder,
final WorkflowTemplate workflowTemplate,
final Class<T> clazz,
final ContentItemInitializer<T> initializer) {
final ContentSection contentSection = sectionRepo
.findById(section.getObjectId())
.orElseThrow(() -> new IllegalArgumentException(String
.format("No ContentSection with ID %d in the database.",
section.getObjectId())));
final Folder itemFolder = folderRepo
.findById(folder.getObjectId())
.orElseThrow(() -> new IllegalArgumentException(String
.format("No Folder with ID %d in the database.",
folder.getObjectId())));
final T item;
if (workflowTemplate == null) {
item = itemManager.createContentItem(name,
contentSection,
itemFolder,
clazz,
initializer);
} else {
final WorkflowTemplate itemWorkflowTemplate = workflowTemplateRepo
.findById(workflowTemplate.getWorkflowId())
.orElseThrow(() -> new IllegalArgumentException(String
.format("No WorkflowTemplate with ID %d in the database.",
workflowTemplate.getWorkflowId())));
item = itemManager.createContentItem(name,
contentSection,
itemFolder,
itemWorkflowTemplate,
clazz,
initializer);
}
return item;
}
}

View File

@ -38,6 +38,8 @@ import com.arsdigita.util.Assert;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.l10n.GlobalizationHelper;
import org.libreccm.workflow.WorkflowTemplate;
import org.libreccm.workflow.WorkflowTemplateRepository;
import org.librecms.CmsConstants;
import org.librecms.contentsection.ContentItem;
import org.librecms.contentsection.ContentItemInitializer;
@ -215,25 +217,48 @@ public class PageCreateForm
Assert.exists(section, ContentSection.class);
final ContentItem item = createContentPage(state,
(String) data.get(NAME),
section,
folder,
getItemInitializer(data,
state));
final Long selectedWorkflowTemplateId = workflowSection
.getSelectedWorkflowTemplateId(state);
final ContentItem item;
if (selectedWorkflowTemplateId == null) {
item = createContentPage(state,
(String) data.get(NAME),
section,
folder,
getItemInitializer(data, state));
} else {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final WorkflowTemplateRepository workflowTemplateRepo = cdiUtil
.findBean(WorkflowTemplateRepository.class);
final WorkflowTemplate workflowTemplate = workflowTemplateRepo
.findById(selectedWorkflowTemplateId)
.orElseThrow(() -> new IllegalArgumentException(String.format(
"No WorkflowTemplate with ID %d in the database.",
selectedWorkflowTemplateId)));
item = createContentItemPage(state,
(String) data.get(NAME),
section,
folder,
workflowTemplate,
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));
workflowSection.applyWorkflow(state, item);
// workflowSection.applyWorkflow(state, item);
creationSelector.editItem(state, item);
}
protected ContentItemInitializer<?> getItemInitializer(
final FormData data, final PageState state) {
return item -> {};
return item -> {
};
}
private class ContentTypePrintListener implements PrintListener {

View File

@ -72,7 +72,6 @@ import javax.transaction.Transactional;
import org.libreccm.security.PermissionChecker;
import org.librecms.contentsection.privileges.TypePrivileges;
/**
* Manager class providing several methods to manipulate {@link ContentItem}s.
*
@ -200,7 +199,7 @@ public class ContentItemManager {
initalizer);
}
/**
/**
* Creates a new content item in the provided content section and folder
* with specific workflow.
*
@ -320,15 +319,15 @@ public class ContentItemManager {
item.setContentType(contentType.get());
if (workflowTemplate != null) {
final Workflow workflow = workflowManager.createWorkflow(
workflowTemplate, item);
final Workflow workflow = workflowManager
.createWorkflow(workflowTemplate, item);
item.setWorkflow(workflow);
}
if (initializer != null) {
initializer.initializeValues(item);
}
contentItemRepo.save(item);
categoryManager.addObjectToCategory(
@ -337,6 +336,10 @@ public class ContentItemManager {
CATEGORIZATION_TYPE_FOLDER);
contentItemRepo.save(item);
if (item.getWorkflow() != null) {
workflowManager.start(item.getWorkflow());
}
return item;
}
@ -878,8 +881,8 @@ public class ContentItemManager {
liveItem.setLifecycle(lifecycle);
liveItem.setWorkflow(draftItem.getWorkflow());
final BeanInfo beanInfo;
final BeanInfo beanInfo;
try {
beanInfo = Introspector.getBeanInfo(item.getClass());
} catch (IntrospectionException ex) {
@ -1012,12 +1015,12 @@ public class ContentItemManager {
throw new RuntimeException(ex);
}
});
draftItem.getCategories().forEach(categorization -> categoryManager
.addObjectToCategory(liveItem,
categorization.getCategory(),
categorization.getType()));
for (int i = 0; i < draftItem.getAttachments().size(); i++) {
final AttachmentList sourceList = draftItem.getAttachments().get(i);

View File

@ -296,3 +296,17 @@ cms.contenttypes.shared.body_text.title=Body text
cms.contenttypes.shared.body_text.description=Edit body text
cms.contenttypes.shared.assign_categories.title=Categories
cms.contenttypes.shared.assign_categories.description=Edit category assignments
cms.ui.item.summary=Summary
cms.ui.item.authoring=Authoring
cms.ui.item.languages=Languages
cms.ui.item.workflow=Workflow
cms.ui.item.lifecycles=Lifecycle
cms.ui.item.history=History
cms.ui.item.templates=Templates
cms.ui.authoring.steps=Authorings steps
cms.contenttypes.ui.lead=Description
cms.contenttypes.ui.description_hint=A short summary of this item. You limit hte text to two to three sentences. By default the description is displayed along with the title in every item list.
cms.ui.workflow.task.assigned=Your assigned tasks
cms.ui.workflow.task.assigned.none=You have no assigned tasks
cms.ui.workflow.restart_stopped_workflow=Start workflow
cms.ui.content_item=Document

View File

@ -293,3 +293,17 @@ cms.contenttypes.shared.body_text.title=Haupttext
cms.contenttypes.shared.body_text.description=Haupttext bearbeiten
cms.contenttypes.shared.assign_categories.title=Kategorien
cms.contenttypes.shared.assign_categories.description=Kategorienzuweisungen bearbeiten
cms.ui.item.summary=Zusammenfassung
cms.ui.item.authoring=Verfassen
cms.ui.item.languages=Sprachen
cms.ui.item.workflow=Arbeitsablauf
cms.ui.item.lifecycles=Ver\u00f6ffentlichungszyklus
cms.ui.item.history=Historie
cms.ui.item.templates=Vorlagen
cms.ui.authoring.steps=Bearbeitungsschritte
cms.contenttypes.ui.lead=Beschreibung
cms.contenttypes.ui.description_hint=Eine kurze Zusammenfassung des Dokumentes. Verwenden Sie wenn m\u00f6glich nicht mehr als zwei bis drei S\u00e4tze. Die Beschreibung wird zusammen mit dem Titel in Dokumentlisten angezeigt.
cms.ui.workflow.task.assigned=Ihre zugeordneten Aufgaben
cms.ui.workflow.task.assigned.none=Sie haben keine zugeordneten Aufgaben
cms.ui.workflow.restart_stopped_workflow=Arbeitsablauf starten
cms.ui.content_item=Dokument

View File

@ -252,3 +252,17 @@ cms.contenttypes.shared.body_text.title=Body text
cms.contenttypes.shared.body_text.description=Edit body text
cms.contenttypes.shared.assign_categories.title=Categories
cms.contenttypes.shared.assign_categories.description=Edit category assignments
cms.ui.item.summary=Summary
cms.ui.item.authoring=Authoring
cms.ui.item.languages=Languages
cms.ui.item.workflow=Workflow
cms.ui.item.lifecycles=Lifecycle
cms.ui.item.history=History
cms.ui.item.templates=Templates
cms.ui.authoring.steps=Authoring steps
cms.contenttypes.ui.lead=Description
cms.contenttypes.ui.description_hint=A short summary of this item. You limit hte text to two to three sentences. By default the description is displayed along with the title in every item list.
cms.ui.workflow.task.assigned=Your assigned tasks
cms.ui.workflow.task.assigned.none=You have no assigned tasks
cms.ui.workflow.restart_stopped_workflow=Start workflow
cms.ui.content_item=Document