Basic structure for EE MVC based create and authoring steps

pull/10/head
Jens Pelzetter 2021-03-13 17:37:07 +01:00
parent 5b854d78a1
commit b5178788c2
24 changed files with 1942 additions and 73 deletions

View File

@ -69,6 +69,8 @@ import org.libreccm.security.PermissionChecker;
import org.libreccm.security.PermissionManager;
import org.librecms.contentsection.privileges.TypePrivileges;
import java.lang.reflect.Constructor;
/**
* Manager class providing several methods to manipulate {@link ContentItem}s.
*
@ -307,8 +309,12 @@ public class ContentItemManager {
final T item;
try {
item = type.newInstance();
} catch (InstantiationException | IllegalAccessException ex) {
final Constructor<T> constructor = type.getConstructor();
item = constructor.newInstance();
} catch (NoSuchMethodException
| InstantiationException
| InvocationTargetException
| IllegalAccessException ex) {
LOGGER.error("Failed to create new content item of type \"{}\" "
+ "in content section \"{}\".",
type.getName(),
@ -317,8 +323,7 @@ public class ContentItemManager {
}
item.setDisplayName(name);
item.getName().addValue(locale,
name);
item.getName().addValue(locale, name);
item.setVersion(ContentItemVersion.DRAFT);
item.setContentType(contentType.get());

View File

@ -39,9 +39,9 @@ import org.librecms.CmsConstants;
import static org.librecms.CmsConstants.*;
import org.librecms.contentsection.ContentItem;
import org.librecms.ui.contentsections.documents.MvcArticleCreateStep;
import org.librecms.ui.contentsections.documents.MvcArticlePropertiesStep;
import org.librecms.ui.contentsections.documents.MvcArticleTextBodyStep;
import org.librecms.ui.contenttypes.MvcArticleCreateStep;
import org.librecms.ui.contenttypes.MvcArticlePropertiesStep;
import org.librecms.ui.contenttypes.MvcArticleTextBodyStep;
import org.librecms.ui.contentsections.documents.MvcAuthoringKit;
import javax.xml.bind.annotation.XmlRootElement;

View File

@ -11,7 +11,6 @@ import org.libreccm.l10n.GlobalizationHelper;
import org.libreccm.security.AuthorizationRequired;
import org.libreccm.workflow.CircularTaskDependencyException;
import org.libreccm.workflow.Task;
import org.libreccm.workflow.TaskDependency;
import org.libreccm.workflow.TaskManager;
import org.libreccm.workflow.TaskRepository;
import org.libreccm.workflow.Workflow;
@ -20,7 +19,6 @@ import org.libreccm.workflow.WorkflowRepository;
import org.librecms.contentsection.ContentSection;
import org.librecms.contentsection.ContentSectionManager;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Optional;

View File

@ -24,7 +24,7 @@ import javax.mvc.Models;
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
class ContentSectionsUi {
public class ContentSectionsUi {
@Inject
private ContentSectionRepository sectionRepo;

View File

@ -0,0 +1,110 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.librecms.ui.contentsections.documents;
import org.librecms.contentsection.ContentItem;
import org.librecms.contentsection.ContentSection;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
/**
* A pseudo implemention of the {@link MvcAuthoringStep} interface used by the
* {@link DocumentController} to show an error message when the authoring step
* does not exist.
*
* Most of methods in this implementation are throwing an
* {@link UnsupportedOperationException}.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class AuthoringStepNotAvailable implements MvcAuthoringStep {
@Override
public Class<? extends ContentItem> supportedDocumenType() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String getLabel() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String getDescription() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String getBundle() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void setContentSection(ContentSection section) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public ContentSection getContentSection() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void setContentItem(ContentItem document) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public ContentItem getContentItem() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String showStep() {
return "org/librecms/ui/contentsection/authoringstep-not-available.xhtml";
}
@GET
@Path("/documentPath:(.+)?")
public String showForAllGets() {
return showStep();
}
@POST
@Path("/")
public String showForPost() {
return showStep();
}
@POST
@Path("/documentPath:(.+)?")
public String showForAllPosts() {
return showStep();
}
@Override
public String getContentSectionLabel() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String getContentSectionTitle() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String getContentItemPath() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String getContentItemTitle() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}

View File

@ -0,0 +1,34 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.librecms.ui.contentsections.documents;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;
/**
*
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@Qualifier
@Retention(RetentionPolicy.RUNTIME)
@Target(
{
ElementType.METHOD,
ElementType.FIELD,
ElementType.PARAMETER,
ElementType.TYPE
}
)
public @interface AuthoringStepPathFragment {
String value();
}

View File

@ -0,0 +1,19 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.librecms.ui.contentsections.documents;
import org.librecms.contentsection.ContentItem;
/**
* Interface to be implemented by all authoring steps.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public interface AuthoringStepResource {
void setDocument(final ContentItem item) ;
}

View File

@ -0,0 +1,142 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.librecms.ui.contentsections.documents;
import org.librecms.contentsection.ContentItem;
import org.librecms.contentsection.ContentSection;
import org.librecms.contentsection.Folder;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
/**
* A pseudo implemention of the {@link MvcDocumentCreateStep} interface used by
* the {@link DocumentController} to show an error message when the requested
* content section does not exist.
*
* Most of methods in this implementation are throwing an
* {@link UnsupportedOperationException}.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class ContentSectionNotFound
implements MvcDocumentCreateStep<ContentItem>, MvcAuthoringStep {
@Override
public Class<ContentItem> getDocumentType() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String getDescription() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String getBundle() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void setContentSection(ContentSection section) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public ContentSection getContentSection() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void setFolder(Folder folder) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public Folder getFolder() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public Class<? extends ContentItem> supportedDocumenType() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String getLabel() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void setContentItem(ContentItem document) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public ContentItem getContentItem() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String showStep() {
return "org/librecms/ui/contentsection/contentsection-not-found.xhtml";
}
@GET
@Path("/documentPath:(.+)?")
public String showForAllGets() {
return showStep();
}
@POST
@Path("/")
public String showForPost() {
return showStep();
}
@POST
@Path("/documentPath:(.+)?")
public String showForAllPosts() {
return showStep();
}
@Override
public String showCreateForm() {
return showStep();
}
@Override
public String createContentItem() {
return showStep();
}
@Override
public String getContentSectionLabel() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String getContentSectionTitle() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String getFolderPath() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String getContentItemPath() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String getContentItemTitle() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}

View File

@ -0,0 +1,85 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.librecms.ui.contentsections.documents;
import org.librecms.contentsection.ContentItem;
import org.librecms.contentsection.ContentSection;
import org.librecms.contentsection.Folder;
/**
* A pseudo implemention of the {@link MvcDocumentCreateStep} interface used by
* the {@link DocumentController} to show an error message when the requested
* document type/content type is not available for the current content section.
*
* Most of methods in this implementation are throwing an
* {@link UnsupportedOperationException}.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class ContentTypeNotAvailable
implements MvcDocumentCreateStep<ContentItem> {
@Override
public Class<ContentItem> getDocumentType() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String getDescription() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String getBundle() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void setContentSection(ContentSection section) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public ContentSection getContentSection() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void setFolder(Folder folder) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public Folder getFolder() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String showCreateForm() {
return "org/librecms/ui/contentsection/documents/document-type-not-available.xhtml";
}
@Override
public String createContentItem() {
return "org/librecms/ui/contentsection/documents/document-type-not-notavailable.xhtml";
}
@Override
public String getContentSectionLabel() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String getContentSectionTitle() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String getFolderPath() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}

View File

@ -0,0 +1,85 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.librecms.ui.contentsections.documents;
import org.librecms.contentsection.ContentItem;
import org.librecms.contentsection.ContentSection;
import org.librecms.contentsection.Folder;
/**
* A pseudo implemention of the {@link MvcDocumentCreateStep} interface used by
* the {@link DocumentController} to show an error message when not create step
* for the requested document type/content type is available.
*
* Most of methods in this implementation are throwing an
* {@link UnsupportedOperationException}.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class CreateStepNotAvailable
implements MvcDocumentCreateStep<ContentItem> {
@Override
public Class<ContentItem> getDocumentType() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String getDescription() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String getBundle() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void setContentSection(ContentSection section) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public ContentSection getContentSection() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void setFolder(Folder folder) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public Folder getFolder() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String showCreateForm() {
return "org/librecms/ui/contentsection/documents/create-step-not-available.xhtml";
}
@Override
public String createContentItem() {
return "org/librecms/ui/contentsection/documents/create-step-not-notavailable.xhtml";
}
@Override
public String getContentSectionLabel() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String getContentSectionTitle() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String getFolderPath() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}

View File

@ -0,0 +1,38 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.librecms.ui.contentsections.documents;
import org.librecms.contentsection.ContentItem;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;
/**
* Qualifier annotation for implementation of {@link MvcDocumentCreateStep}
* providing the type of the created document/content item. Used to select
* the requested create step from all available implementations.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@Qualifier
@Retention(RetentionPolicy.RUNTIME)
@Target(
{
ElementType.METHOD,
ElementType.FIELD,
ElementType.PARAMETER,
ElementType.TYPE
}
)
public @interface CreatesDocumentOfType {
Class<? extends ContentItem> value();
}

View File

@ -0,0 +1,241 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.librecms.ui.contentsections.documents;
import org.librecms.contentsection.ContentItem;
import org.librecms.contentsection.ContentItemRepository;
import org.librecms.contentsection.ContentSection;
import org.librecms.contentsection.Folder;
import org.librecms.contentsection.FolderRepository;
import org.librecms.contentsection.FolderType;
import org.librecms.ui.contentsections.ContentSectionsUi;
import java.util.Optional;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.inject.Instance;
import javax.enterprise.util.AnnotationLiteral;
import javax.inject.Inject;
import javax.mvc.Controller;
import javax.mvc.Models;
import javax.transaction.Transactional;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
@Path("/{sectionIdentifier}/documents")
@Controller
public class DocumentController {
@Inject
private ContentSectionsUi sectionsUi;
@Inject
private FolderRepository folderRepo;
@Inject
private ContentItemRepository itemRepo;
@Inject
private Instance<MvcAuthoringStep> authoringSteps;
@Inject
private Instance<MvcDocumentCreateStep<?>> createSteps;
@Inject
private Models models;
@GET
@Path("/")
@Transactional(Transactional.TxType.REQUIRED)
public String redirectToDocumentFolders(
@PathParam("sectionIdentifider") final String sectionIdentifier
) {
return String.format(
"redirect:/%s/documentfolders/",
sectionIdentifier
);
}
@Path("/@create/{documentType}")
@Transactional(Transactional.TxType.REQUIRED)
public MvcDocumentCreateStep<? extends ContentItem> createDocument(
@PathParam("sectionIdentifider") final String sectionIdentifier,
@PathParam("documentType") final String documentType
) {
return createDocument(sectionIdentifier, "", documentType);
}
@Path("/{folderPath:(.+)?}/@create/{documentType}")
@Transactional(Transactional.TxType.REQUIRED)
@SuppressWarnings("unchecked")
public MvcDocumentCreateStep<? extends ContentItem> createDocument(
@PathParam("sectionIdentifider") final String sectionIdentifier,
@PathParam("folderPath") final String folderPath,
@PathParam("documentType") final String documentType
) {
final Optional<ContentSection> sectionResult = sectionsUi
.findContentSection(sectionIdentifier);
if (!sectionResult.isPresent()) {
models.put("sectionIdentifier", sectionIdentifier);
return new ContentSectionNotFound();
}
final ContentSection section = sectionResult.get();
final Folder folder;
if (folderPath.isEmpty()) {
folder = section.getRootDocumentsFolder();
} else {
final Optional<Folder> folderResult = folderRepo
.findByPath(
section, folderPath, FolderType.DOCUMENTS_FOLDER
);
if (!folderResult.isPresent()) {
models.put("section", section.getLabel());
models.put("folderPath", folderPath);
return new FolderNotFound();
}
folder = folderResult.get();
}
final Class<? extends ContentItem> documentClass;
try {
documentClass = (Class<? extends ContentItem>) Class.forName(
documentType
);
} catch (ClassNotFoundException ex) {
models.put("documentType", documentType);
return new DocumentTypeClassNotFound();
}
final boolean hasRequestedType = section
.getContentTypes()
.stream()
.anyMatch(
type -> type.getContentItemClass().equals(documentType)
);
if (!hasRequestedType) {
models.put("documentType", documentType);
models.put("section", section.getLabel());
return new ContentTypeNotAvailable();
}
final Instance<MvcDocumentCreateStep<?>> instance = createSteps
.select(new CreateDocumentOfTypeLiteral(documentClass));
if (instance.isUnsatisfied() || instance.isAmbiguous()) {
models.put("section", section.getLabel());
models.put("folderPath", folderPath);
models.put("documentType", documentType);
return new CreateStepNotAvailable();
}
final MvcDocumentCreateStep<? extends ContentItem> createStep = instance
.get();
createStep.setContentSection(section);
createStep.setFolder(folder);
return createStep;
}
@Path("/{documentPath:(.+)?}/@authoringsteps/{authoringStep}")
@Transactional(Transactional.TxType.REQUIRED)
public MvcAuthoringStep editDocument(
@PathParam("sectionIdentifider") final String sectionIdentifier,
@PathParam("documentPath") final String documentPath,
@PathParam("authoringStep") final String authoringStepIdentifier
) {
final Optional<ContentSection> sectionResult = sectionsUi
.findContentSection(sectionIdentifier);
if (!sectionResult.isPresent()) {
models.put("sectionIdentifier", sectionIdentifier);
return new ContentSectionNotFound();
}
final ContentSection section = sectionResult.get();
final Optional<ContentItem> itemResult = itemRepo
.findByPath(section, documentPath);
if (!itemResult.isPresent()) {
models.put("section", section.getLabel());
models.put("documentPath", documentPath);
return new DocumentNotFound();
}
final ContentItem item = itemResult.get();
final Instance<MvcAuthoringStep> instance = authoringSteps
.select(
new AuthoringStepPathFragmentLiteral(
authoringStepIdentifier
)
);
if (instance.isUnsatisfied() || instance.isAmbiguous()) {
models.put("section", section.getLabel());
models.put("documentPath", documentPath);
models.put("authoringStep", authoringStepIdentifier);
return new AuthoringStepNotAvailable();
}
final MvcAuthoringStep authoringStep = instance.get();
if (!authoringStep.supportedDocumenType().isAssignableFrom(item
.getClass())) {
models.put("section", section.getLabel());
models.put("documentPath", documentPath);
models.put("documentType", item.getClass().getName());
models.put("authoringStep", authoringStepIdentifier);
return new UnsupportedDocumentType();
}
authoringStep.setContentSection(section);
authoringStep.setContentItem(item);
return authoringStep;
}
private static class CreateDocumentOfTypeLiteral
extends AnnotationLiteral<CreatesDocumentOfType>
implements CreatesDocumentOfType {
private static final long serialVersionUID = 1L;
private final Class<? extends ContentItem> value;
public CreateDocumentOfTypeLiteral(
final Class<? extends ContentItem> value
) {
this.value = value;
}
@Override
public Class<? extends ContentItem> value() {
return value;
}
}
private static class AuthoringStepPathFragmentLiteral
extends AnnotationLiteral<AuthoringStepPathFragment>
implements AuthoringStepPathFragment {
private static final long serialVersionUID = 1L;
private final String value;
public AuthoringStepPathFragmentLiteral(final String value) {
this.value = value;
}
@Override
public String value() {
return value;
}
}
}

View File

@ -0,0 +1,111 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.librecms.ui.contentsections.documents;
import org.librecms.contentsection.ContentItem;
import org.librecms.contentsection.ContentSection;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
/**
* A pseudo implemention of the {@link MvcAuthoringStep} interface used by
* the {@link DocumentController} to show an error message when the requested
* document/content item does not exist.
*
* Most of methods in this implementation are throwing an
* {@link UnsupportedOperationException}.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class DocumentNotFound implements MvcAuthoringStep {
@Override
public Class<? extends ContentItem> supportedDocumenType() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String getLabel() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String getDescription() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String getBundle() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void setContentSection(ContentSection section) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public ContentSection getContentSection() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void setContentItem(ContentItem document) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public ContentItem getContentItem() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String showStep() {
return "org/librecms/ui/contentsection/document-not-found.xhtml";
}
@GET
@Path("/documentPath:(.+)?")
public String showForAllGets() {
return showStep();
}
@POST
@Path("/")
public String showForPost() {
return showStep();
}
@POST
@Path("/documentPath:(.+)?")
public String showForAllPosts() {
return showStep();
}
@Override
public String getContentSectionLabel() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String getContentSectionTitle() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String getContentItemPath() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String getContentItemTitle() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}

View File

@ -0,0 +1,85 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.librecms.ui.contentsections.documents;
import org.librecms.contentsection.ContentItem;
import org.librecms.contentsection.ContentSection;
import org.librecms.contentsection.Folder;
/**
* A pseudo implemention of the {@link MvcDocumentCreateStep} interface used by
* the {@link DocumentController} to show an error message when the requested
* document type does not exist.
*
* Most of methods in this implementation are throwing an
* {@link UnsupportedOperationException}.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
class DocumentTypeClassNotFound
implements MvcDocumentCreateStep<ContentItem> {
@Override
public Class<ContentItem> getDocumentType() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String getDescription() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String getBundle() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void setContentSection(ContentSection section) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public ContentSection getContentSection() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void setFolder(Folder folder) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public Folder getFolder() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String showCreateForm() {
return "org/librecms/ui/contentsection/documents/document-type-not-found.xhtml";
}
@Override
public String createContentItem() {
return "org/librecms/ui/contentsection/documents/document-type-not-found.xhtml";
}
@Override
public String getContentSectionLabel() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String getContentSectionTitle() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String getFolderPath() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}

View File

@ -0,0 +1,85 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.librecms.ui.contentsections.documents;
import org.librecms.contentsection.ContentItem;
import org.librecms.contentsection.ContentSection;
import org.librecms.contentsection.Folder;
/**
* A pseudo implemention of the {@link MvcDocumentCreateStep} interface used by
* the {@link DocumentController} to show an error message when the requested
* folder does not exist.
*
* Most of methods in this implementation are throwing an
* {@link UnsupportedOperationException}.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class FolderNotFound
implements MvcDocumentCreateStep<ContentItem> {
@Override
public Class<ContentItem> getDocumentType() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String getDescription() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String getBundle() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void setContentSection(ContentSection section) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public ContentSection getContentSection() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void setFolder(Folder folder) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public Folder getFolder() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String showCreateForm() {
return "org/librecms/ui/contentsection/documents/folder-not-found.xhtml";
}
@Override
public String createContentItem() {
return "org/librecms/ui/contentsection/documents/folder-not-found.xhtml";
}
@Override
public String getContentSectionLabel() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String getContentSectionTitle() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String getFolderPath() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}

View File

@ -7,26 +7,26 @@ package org.librecms.ui.contentsections.documents;
import org.libreccm.l10n.GlobalizationHelper;
import org.librecms.contentsection.ContentItem;
import org.librecms.contentsection.ContentSection;
import java.util.Set;
import javax.inject.Named;
import javax.transaction.Transactional;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
/**
* Describes an authoring step for a document (content item).
* An authoring step for a document (content item). Implementing classes are
* used as subresources by {@link DocumentController#editDocument(java.lang.String, java.lang.String, java.lang.String)
* }. An implementation must be a named CDI bean (annotated with {@link Named},
* annotated with the {@link AuthoringStepPathFragment} qualifier annotation.
*
* An implementation may contain multiple subresource paths for for displaying
* forms and apply changes from these forms.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public interface MvcAuthoringStep {
/**
* Returns the step identifier.
*
* Each authoring step is accessible over the URL {@code /contentsections/documents/{path:+.*}/@authoringsteps/{step}.
* The method provides the identifier for hte step.
*
* @return The path fragment for the authoring step used in URLs.
*/
String getPathFragment();
/**
* Authoring steps only support a specific type, and all subtypes.
*
@ -56,8 +56,79 @@ public interface MvcAuthoringStep {
* Gets the name of the resource bundle providing the localized label and
* description.
*
* @return The resource bundle providing the localized label and description.
* @return The resource bundle providing the localized label and
* description.
*/
String getBundle();
/**
* The current content section.
*
* @return The current content section.
*/
ContentSection getContentSection();
/**
* Convinient method for getting the label of the current content section.
*
* @return The label of the current content section.
*/
String getContentSectionLabel();
/**
* Convinient method for getting the title of the current content section.
*
* @return The title of the current content section for the current locale.
*/
String getContentSectionTitle();
/**
* The current content section is provided by the
* {@link DocumentController}.
*
* @param section The current content section.
*/
void setContentSection(final ContentSection section);
/**
* The selected document/content item.
*
* @return The selected document/content item.
*/
ContentItem getContentItem();
/**
* Gets the path of the selected content item.
*
* @return The path of the selected content item.
*/
String getContentItemPath();
/**
* Gets the title of the selected content item.
*
* @return The title of the selected content item.
*/
String getContentItemTitle();
/**
* The current document/content item is provided by the
* {@link DocumentController}.
*
* @param document The document/content item to edit.
*/
void setContentItem(ContentItem document);
/**
* Endpoint displaying the authoring step. This should not show the form,
* only an overview. The actual form(s) are provided by endpoints added by
* the implementation.
*
* @return The template of the edit step.
*/
@GET
@Path("/")
@Transactional(Transactional.TxType.REQUIRED)
String showStep();
}

View File

@ -7,23 +7,30 @@ package org.librecms.ui.contentsections.documents;
import org.libreccm.l10n.GlobalizationHelper;
import org.librecms.contentsection.ContentItem;
import org.librecms.contentsection.ContentSection;
import org.librecms.contentsection.Folder;
import java.util.ResourceBundle;
import javax.inject.Named;
import javax.transaction.Transactional;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
/**
* Describes the create for a document (content item).
* A create step for a document/content item. Implementing classes are used as
* subresources by {@link DocumentController#createDocument(java.lang.String, java.lang.String)
* }. An implmenting class must be a named CDI bean (annotated with
* {@link Named}), annotated with the {@link CreatesDocumentOfType} qualifier
* annotation. The implementing bean must also contain properties annotated with
* {@link FormParam} for all fields of the create form.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
* @param <T> The document type created by the create step.
*/
public interface MvcDocumentCreateStep {
/**
* Get the class implementing the sub resource implemeting the logic for the
* step. This must be a CDI bean.
*
* @return The sub resource class implementing the create step.
*/
Class<?> getSubResourceClass();
public interface MvcDocumentCreateStep<T extends ContentItem> {
/**
* The document type generated by the create step described by an instance
@ -31,7 +38,7 @@ public interface MvcDocumentCreateStep {
*
* @return Document type generated.
*/
Class<? extends ContentItem> getDocumentType();
Class<T> getDocumentType();
/**
* Localized description of the create step. The current locale as returned
@ -51,4 +58,76 @@ public interface MvcDocumentCreateStep {
*/
String getBundle();
/**
* The current content section.
*
* @return The current content section.
*/
ContentSection getContentSection();
/**
* Convinient method for getting the label of the current content section.
*
* @return The label of the current content section.
*/
String getContentSectionLabel();
/**
* Convinient method for getting the title of the current content section.
*
* @return The title of the current content section for the current locale.
*/
String getContentSectionTitle();
/**
* The current content section is provided by the
* {@link DocumentController}.
*
* @param section The current content section.
*/
void setContentSection(final ContentSection section);
/**
* The parent folder of the new item.
*
* @return The parent folder of the new item.
*/
Folder getFolder();
/**
* Gets the path the the parent folder of the new item.
*
* @return The path of the parent folder of the new item.
*/
String getFolderPath();
/**
* The parent folder of the new item is provided by the
* {@link DocumentController}.
*
* @param folder The parent folder of the new doucment.
*/
void setFolder(final Folder folder);
/**
* Endpoint displaying the create form.
*
* @return The template of the create step.
*/
@GET
@Path("/")
@Transactional(Transactional.TxType.REQUIRED)
String showCreateForm();
/**
* Creates the new document using the values provided in the form
* parameters.
*
* @return A redirect to the new content item.
*/
@POST
@Path("/")
@Transactional(Transactional.TxType.REQUIRED)
String createContentItem();
}

View File

@ -0,0 +1,110 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.librecms.ui.contentsections.documents;
import org.librecms.contentsection.ContentItem;
import org.librecms.contentsection.ContentSection;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
/**
* A pseudo implemention of the {@link MvcAuthoringStep} interface used by the
* {@link DocumentController} to show an error message when the authoring step
* does not support the requested document.
*
* Most of methods in this implementation are throwing an
* {@link UnsupportedOperationException}.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class UnsupportedDocumentType implements MvcAuthoringStep {
@Override
public Class<? extends ContentItem> supportedDocumenType() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String getLabel() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String getDescription() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String getBundle() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void setContentSection(ContentSection section) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public ContentSection getContentSection() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void setContentItem(ContentItem document) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public ContentItem getContentItem() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String showStep() {
return "org/librecms/ui/contentsection/unsupported-documenttype.xhtml";
}
@GET
@Path("/documentPath:(.+)?")
public String showForAllGets() {
return showStep();
}
@POST
@Path("/")
public String showForPost() {
return showStep();
}
@POST
@Path("/documentPath:(.+)?")
public String showForAllPosts() {
return showStep();
}
@Override
public String getContentSectionLabel() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String getContentSectionTitle() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String getContentItemPath() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String getContentItemTitle() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}

View File

@ -0,0 +1,23 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.librecms.ui.contenttypes;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public final class ArticleStepsConstants {
private ArticleStepsConstants() {
}
public static final String BUNDLE
= "org.libreccms.ui.contenttypes.ArticleBundle";
}

View File

@ -3,38 +3,166 @@
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.librecms.ui.contentsections.documents;
package org.librecms.ui.contenttypes;
import org.librecms.contentsection.ContentItem;
import org.libreccm.l10n.GlobalizationHelper;
import org.libreccm.workflow.Workflow;
import org.librecms.contentsection.ContentItemManager;
import org.librecms.contentsection.ContentItemRepository;
import org.librecms.contentsection.ContentSection;
import org.librecms.contentsection.Folder;
import org.librecms.contentsection.FolderManager;
import org.librecms.contenttypes.Article;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
import org.librecms.ui.contentsections.documents.MvcDocumentCreateStep;
import java.util.Locale;
import java.util.Optional;
import javax.inject.Inject;
import javax.mvc.Models;
import javax.ws.rs.FormParam;
/**
* Describes the create step for {@link Article}.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class MvcArticleCreateStep implements MvcDocumentCreateStep {
@RequestScoped
@Named
public class MvcArticleCreateStep implements MvcDocumentCreateStep<Article> {
@Inject
private ContentItemManager itemManager;
@Inject
private ContentItemRepository itemRepo;
@Inject
private FolderManager folderManager;
@Inject
private GlobalizationHelper globalizationHelper;
@Inject
private Models models;
private ContentSection section;
private Folder folder;
@FormParam("name")
private String name;
@FormParam("title")
private String title;
@FormParam("summary")
private String summary;
@FormParam("locale")
private String initialLocale;
@FormParam("selectedWorkflow")
private String selectedWorkflow;
@Override
public Class<?> getSubResourceClass() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public Class<? extends ContentItem> getDocumentType() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
public Class<Article> getDocumentType() {
return Article.class;
}
@Override
public String getDescription() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
return globalizationHelper
.getLocalizedTextsUtil(getBundle())
.getText("createstep.description");
}
@Override
public String getBundle() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
return ArticleStepsConstants.BUNDLE;
}
@Override
public ContentSection getContentSection() {
return section;
}
@Override
public String getContentSectionLabel() {
return section.getLabel();
}
@Override
public String getContentSectionTitle() {
return globalizationHelper
.getValueFromLocalizedString(section.getTitle());
}
@Override
public void setContentSection(final ContentSection section) {
this.section = section;
}
@Override
public Folder getFolder() {
return folder;
}
@Override
public String getFolderPath() {
return folderManager.getFolderPath(folder);
}
@Override
public void setFolder(final Folder folder) {
this.folder = folder;
}
@Override
public String showCreateForm() {
return "org/librecms/ui/contenttypes/article/create-article.xhtml";
}
@Override
public String createContentItem() {
final Optional<Workflow> workflowResult = section
.getWorkflowTemplates()
.stream()
.filter(template -> template.getUuid().equals(selectedWorkflow))
.findAny();
if (!workflowResult.isPresent()) {
models.put("section", section.getLabel());
models.put("selectedWorkflow", selectedWorkflow);
return "org/librecms/ui/contentsection/documents/workflow-not-available.xhtml";
}
final Locale locale = new Locale(initialLocale);
final Article article = itemManager.createContentItem(
name,
section,
folder,
workflowResult.get(),
Article.class,
locale
);
article.getTitle().addValue(locale, title);
article.getDescription().addValue(locale, summary);
itemRepo.save(article);
return String.format(
"redirect:/%s/documents/%s/%s/@edit/basicproperties",
section.getLabel(),
folderManager.getFolderPath(folder),
name
);
}
}

View File

@ -3,14 +3,35 @@
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.librecms.ui.contentsections.documents;
package org.librecms.ui.contenttypes;
import org.libreccm.core.UnexpectedErrorException;
import org.libreccm.l10n.GlobalizationHelper;
import org.librecms.contentsection.ContentItem;
import org.librecms.contentsection.ContentItemL10NManager;
import org.librecms.contentsection.ContentItemManager;
import org.librecms.contentsection.ContentItemRepository;
import org.librecms.contentsection.ContentSection;
import org.librecms.contentsection.FolderManager;
import org.librecms.contenttypes.Article;
import org.librecms.ui.contentsections.documents.AuthoringStepPathFragment;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.mvc.Controller;
import javax.ws.rs.Path;
import org.librecms.ui.contentsections.documents.MvcAuthoringStep;
import java.util.Locale;
import java.util.Map;
import java.util.stream.Collectors;
import javax.transaction.Transactional;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.PathParam;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
@ -18,31 +39,262 @@ import javax.ws.rs.Path;
@RequestScoped
@Controller
@Path("/")
@AuthoringStepPathFragment(MvcArticlePropertiesStep.PATH_FRAGMENT)
public class MvcArticlePropertiesStep implements MvcAuthoringStep {
@Override
public String getPathFragment() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
static final String PATH_FRAGMENT = "basicproperties";
@Inject
private ContentItemRepository itemRepo;
@Inject
private ContentItemManager itemManager;
@Inject
private FolderManager folderManager;
@Inject
private GlobalizationHelper globalizationHelper;
private ContentSection section;
private Article document;
@Override
public Class<? extends ContentItem> supportedDocumenType() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
return Article.class;
}
@Override
public String getLabel() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
return globalizationHelper
.getLocalizedTextsUtil(getBundle())
.getText("authoringsteps.basicproperties.label");
}
@Override
public String getDescription() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
return globalizationHelper
.getLocalizedTextsUtil(getBundle())
.getText("authoringsteps.basicproperties.description");
}
@Override
public String getBundle() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
return ArticleStepsConstants.BUNDLE;
}
@Override
public ContentSection getContentSection() {
return section;
}
@Override
public String getContentSectionLabel() {
return section.getLabel();
}
@Override
public String getContentSectionTitle() {
return globalizationHelper
.getValueFromLocalizedString(section.getTitle());
}
@Override
public void setContentSection(final ContentSection section) {
this.section = section;
}
@Override
public ContentItem getContentItem() {
return document;
}
@Override
public String getContentItemPath() {
return itemManager.getItemPath(document);
}
@Override
public String getContentItemTitle() {
return globalizationHelper
.getValueFromLocalizedString(document.getTitle());
}
@Override
public void setContentItem(final ContentItem document) {
if (!(document instanceof Article)) {
throw new UnexpectedErrorException("Not an article.");
}
this.document = (Article) document;
}
@Override
public String showStep() {
return "org/librecms/ui/contenttypes/article/article-basic-properties.xhtml";
}
public String getName() {
return document.getDisplayName();
}
@POST
@Path("/name/{locale}")
@Transactional(Transactional.TxType.REQUIRED)
public String updateName(@FormParam("name") final String name) {
document.setDisplayName(name);
itemRepo.save(document);
return String.format(
"redirect:/@documents/%s/%s/%s/@edit/%s",
section.getLabel(),
folderManager.getFolderPath(
itemManager.getItemFolder(document).get()
),
name,
PATH_FRAGMENT
);
}
public Map<String, String> getTitleValues() {
return document
.getTitle()
.getValues()
.entrySet()
.stream()
.collect(
Collectors.toMap(
entry -> entry.getKey().toString(),
entry -> entry.getValue()
)
);
}
@POST
@Path("/title/@add")
@Transactional(Transactional.TxType.REQUIRED)
public String addTitle(
@FormParam("locale") final String localeParam,
@FormParam("value") final String value
) {
final Locale locale = new Locale(localeParam);
document.getTitle().addValue(locale, value);
itemRepo.save(document);
return String.format(
"redirect:/@documents/%s/%s/@edit/%s",
section.getLabel(),
getContentItemPath(),
PATH_FRAGMENT
);
}
@POST
@Path("/title/@edit/{locale}")
@Transactional(Transactional.TxType.REQUIRED)
public String editTitle(
@PathParam("locale") final String localeParam,
@FormParam("value") final String value
) {
final Locale locale = new Locale(localeParam);
document.getTitle().addValue(locale, value);
itemRepo.save(document);
return String.format(
"redirect:/@documents/%s/%s/@edit/%s",
section.getLabel(),
getContentItemPath(),
PATH_FRAGMENT
);
}
@POST
@Path("/title/@remove/{locale}")
@Transactional(Transactional.TxType.REQUIRED)
public String removeTitle(
@PathParam("locale") final String localeParam
) {
final Locale locale = new Locale(localeParam);
document.getTitle().removeValue(locale);
itemRepo.save(document);
return String.format(
"redirect:/@documents/%s/%s/@edit/%s",
section.getLabel(),
getContentItemPath(),
PATH_FRAGMENT
);
}
public Map<String, String> getDescriptionValues() {
return document
.getDescription()
.getValues()
.entrySet()
.stream()
.collect(
Collectors.toMap(
entry -> entry.getKey().toString(),
entry -> entry.getValue()
)
);
}
@POST
@Path("/title/@add")
@Transactional(Transactional.TxType.REQUIRED)
public String addDescription(
@FormParam("locale") final String localeParam,
@FormParam("value") final String value
) {
final Locale locale = new Locale(localeParam);
document.getDescription().addValue(locale, value);
itemRepo.save(document);
return String.format(
"redirect:/@documents/%s/%s/@edit/%s",
section.getLabel(),
getContentItemPath(),
PATH_FRAGMENT
);
}
@POST
@Path("/title/@edit/{locale}")
@Transactional(Transactional.TxType.REQUIRED)
public String editDescription(
@PathParam("locale") final String localeParam,
@FormParam("value") final String value
) {
final Locale locale = new Locale(localeParam);
document.getDescription().addValue(locale, value);
itemRepo.save(document);
return String.format(
"redirect:/@documents/%s/%s/@edit/%s",
section.getLabel(),
getContentItemPath(),
PATH_FRAGMENT
);
}
@POST
@Path("/title/@remove/{locale}")
@Transactional(Transactional.TxType.REQUIRED)
public String removeDescription(
@PathParam("locale") final String localeParam
) {
final Locale locale = new Locale(localeParam);
document.getDescription().removeValue(locale);
itemRepo.save(document);
return String.format(
"redirect:/@documents/%s/%s/@edit/%s",
section.getLabel(),
getContentItemPath(),
PATH_FRAGMENT
);
}
}

View File

@ -3,14 +3,35 @@
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.librecms.ui.contentsections.documents;
package org.librecms.ui.contenttypes;
import org.libreccm.core.UnexpectedErrorException;
import org.libreccm.l10n.GlobalizationHelper;
import org.librecms.contentsection.ContentItem;
import org.librecms.contentsection.ContentItemManager;
import org.librecms.contentsection.ContentItemRepository;
import org.librecms.contentsection.ContentSection;
import org.librecms.contentsection.FolderManager;
import org.librecms.contenttypes.Article;
import org.librecms.ui.contentsections.documents.AuthoringStepPathFragment;
import javax.enterprise.context.RequestScoped;
import javax.mvc.Controller;
import javax.ws.rs.Path;
import org.librecms.ui.contentsections.documents.MvcAuthoringStep;
import java.util.Locale;
import java.util.Map;
import java.util.stream.Collectors;
import javax.inject.Inject;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.PathParam;
import static org.librecms.ui.contenttypes.MvcArticlePropertiesStep.PATH_FRAGMENT;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
@ -18,31 +39,166 @@ import javax.ws.rs.Path;
@RequestScoped
@Controller
@Path("/")
@AuthoringStepPathFragment(MvcArticleTextBodyStep.PATH_FRAGMENT)
public class MvcArticleTextBodyStep implements MvcAuthoringStep {
@Override
public String getPathFragment() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
static final String PATH_FRAGMENT = "basicproperties";
@Inject
private ContentItemRepository itemRepo;
@Inject
private ContentItemManager itemManager;
@Inject
private FolderManager folderManager;
@Inject
private GlobalizationHelper globalizationHelper;
private ContentSection section;
private Article document;
@Override
public Class<? extends ContentItem> supportedDocumenType() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
return Article.class;
}
@Override
public String getLabel() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
return globalizationHelper
.getLocalizedTextsUtil(getBundle())
.getText("authoringsteps.text.label");
}
@Override
public String getDescription() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
return globalizationHelper
.getLocalizedTextsUtil(getBundle())
.getText("authoringsteps.text.description");
}
@Override
public String getBundle() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
return ArticleStepsConstants.BUNDLE;
}
@Override
public ContentSection getContentSection() {
return section;
}
@Override
public String getContentSectionLabel() {
return section.getLabel();
}
@Override
public String getContentSectionTitle() {
return globalizationHelper
.getValueFromLocalizedString(section.getTitle());
}
@Override
public void setContentSection(final ContentSection section) {
this.section = section;
}
@Override
public ContentItem getContentItem() {
return document;
}
@Override
public String getContentItemPath() {
return itemManager.getItemPath(document);
}
@Override
public String getContentItemTitle() {
return globalizationHelper
.getValueFromLocalizedString(document.getTitle());
}
@Override
public void setContentItem(final ContentItem document) {
if (!(document instanceof Article)) {
throw new UnexpectedErrorException("Not an article.");
}
this.document = (Article) document;
}
@Override
public String showStep() {
return "org/librecms/ui/contenttypes/article/article-text.xhtml";
}
public Map<String, String> getTextValues() {
return document
.getText()
.getValues()
.entrySet()
.stream()
.collect(
Collectors.toMap(
entry -> entry.getKey().toString(),
entry -> entry.getValue()
)
);
}
@POST
@Path("/@add")
public String addTextValue(
@FormParam("locale") final String localeParam,
@FormParam("value") final String value
) {
final Locale locale = new Locale(localeParam);
document.getText().addValue(locale, value);
itemRepo.save(document);
return String.format(
"redirect:/@documents/%s/%s/@edit/%s",
section.getLabel(),
getContentItemPath(),
PATH_FRAGMENT
);
}
@POST
@Path("/@edit/{locale}")
public String editTextValue(
@PathParam("locale") final String localeParam,
@FormParam("value") final String value
) {
final Locale locale = new Locale(localeParam);
document.getText().addValue(locale, value);
itemRepo.save(document);
return String.format(
"redirect:/@documents/%s/%s/@edit/%s",
section.getLabel(),
getContentItemPath(),
PATH_FRAGMENT
);
}
@POST
@Path("/@remove/{locale}")
public String remvoeTextValue(
@PathParam("locale") final String localeParam
) {
final Locale locale = new Locale(localeParam);
document.getText().removeValue(locale);
itemRepo.save(document);
return String.format(
"redirect:/@documents/%s/%s/@edit/%s",
section.getLabel(),
getContentItemPath(),
PATH_FRAGMENT
);
}
}

View File

@ -0,0 +1,6 @@
createstep.label=Article
createstep.description=Creates an article with a summary and a main text.
authoringsteps.basicproperties.label=Basic Properties
authoringsteps.basicproperties.description=Edit the basic properties.
authoringsteps.text.description=Edit the text of an article.
authoringsteps.text.label=Body Text

View File

@ -0,0 +1,6 @@
createstep.label=Artikel
createstep.description=Erstellt einen Artikel mit einer Zusammenfassung und einem Hauptteil.
authoringsteps.basicproperties.label=Basiseigenschaften
authoringsteps.basicproperties.description=Bearbeiten der Basiseigenschaften.
authoringsteps.text.description=Bearbeiten des Artikel-Textes.
authoringsteps.text.label=Haupttext