Get createstep from MvcAuthoringKit annotation
parent
270316e37a
commit
49c1467777
|
|
@ -75,13 +75,13 @@ import javax.xml.bind.annotation.XmlRootElement;
|
||||||
order = 2
|
order = 2
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
//@MvcAuthoringKit(
|
@MvcAuthoringKit(
|
||||||
// createStep = MvcArticleCreateStep.class,
|
createStep = MvcArticleCreateStep.class,
|
||||||
// authoringSteps = {
|
authoringSteps = {
|
||||||
// MvcArticlePropertiesStep.class,
|
MvcArticlePropertiesStep.class,
|
||||||
// MvcArticleTextBodyStep.class
|
MvcArticleTextBodyStep.class
|
||||||
// }
|
}
|
||||||
//)
|
)
|
||||||
@XmlRootElement(name = "article", namespace = CMS_XML_NS)
|
@XmlRootElement(name = "article", namespace = CMS_XML_NS)
|
||||||
public class Article extends ContentItem implements Serializable {
|
public class Article extends ContentItem implements Serializable {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -149,6 +149,14 @@ public class DocumentFolderModel {
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getPathWithTrailingSlash() {
|
||||||
|
if (path.isEmpty()) {
|
||||||
|
return "";
|
||||||
|
} else {
|
||||||
|
return String.format("%s/", path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void setPath(final String path) {
|
protected void setPath(final String path) {
|
||||||
this.path = path;
|
this.path = path;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,51 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2021 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.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}
|
|
||||||
* defining 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();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -108,11 +108,13 @@ public class DocumentController {
|
||||||
@Inject
|
@Inject
|
||||||
private ContentItemRepository itemRepo;
|
private ContentItemRepository itemRepo;
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * All available {@link MvcAuthoringStep}s.
|
* All available {@link MvcAuthoringStep}s.
|
||||||
// */
|
*/
|
||||||
// @Inject
|
@Inject
|
||||||
// private Instance<MvcAuthoringStep> authoringSteps;
|
@Any
|
||||||
|
private Instance<MvcAuthoringStep> authoringSteps;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All available {@link MvcDocumentCreateStep}s.
|
* All available {@link MvcDocumentCreateStep}s.
|
||||||
*/
|
*/
|
||||||
|
|
@ -225,6 +227,21 @@ public class DocumentController {
|
||||||
return showCreateStep(sectionIdentifier, "", documentType);
|
return showCreateStep(sectionIdentifier, "", documentType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Path("/@create")
|
||||||
|
@AuthorizationRequired
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
public String showCreateStepPost(
|
||||||
|
@PathParam("sectionIdentifier") final String sectionIdentifier,
|
||||||
|
@FormParam("documentType") final String documentType
|
||||||
|
) {
|
||||||
|
return String.format(
|
||||||
|
"redirect:/%s/documents/@create/%s",
|
||||||
|
sectionIdentifier,
|
||||||
|
documentType
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows the create step of the document type.
|
* Shows the create step of the document type.
|
||||||
*
|
*
|
||||||
|
|
@ -257,6 +274,24 @@ public class DocumentController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Path("/{folderPath:(.+)?}/@create/{documentType}")
|
||||||
|
@AuthorizationRequired
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public String showCreateStepPost(
|
||||||
|
@PathParam("sectionIdentifier") final String sectionIdentifier,
|
||||||
|
@PathParam("folderPath") final String folderPath,
|
||||||
|
@FormParam("documentType") final String documentType
|
||||||
|
) {
|
||||||
|
return String.format(
|
||||||
|
"redirect:/%s/documents/%s/@create/%s",
|
||||||
|
sectionIdentifier,
|
||||||
|
folderPath,
|
||||||
|
documentType
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("/@create/{documentType}")
|
@Path("/@create/{documentType}")
|
||||||
@AuthorizationRequired
|
@AuthorizationRequired
|
||||||
|
|
@ -268,7 +303,7 @@ public class DocumentController {
|
||||||
) {
|
) {
|
||||||
return createDocument(
|
return createDocument(
|
||||||
sectionIdentifier,
|
sectionIdentifier,
|
||||||
"",
|
"",
|
||||||
documentType,
|
documentType,
|
||||||
//formParameters
|
//formParameters
|
||||||
request
|
request
|
||||||
|
|
@ -798,31 +833,6 @@ public class DocumentController {
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* An annotation literal used to retrieve the create step for a specific
|
|
||||||
* content type.
|
|
||||||
*/
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An annotation literal for retrieving the authoring step with a specific
|
* An annotation literal for retrieving the authoring step with a specific
|
||||||
* path fragment.
|
* path fragment.
|
||||||
|
|
@ -958,8 +968,23 @@ public class DocumentController {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
final Instance<MvcDocumentCreateStep<?>> instance = createSteps
|
final Optional<MvcAuthoringKit> authoringKitResult = Optional
|
||||||
.select(new CreateDocumentOfTypeLiteral(documentClass));
|
.ofNullable(
|
||||||
|
documentClass.getDeclaredAnnotation(MvcAuthoringKit.class)
|
||||||
|
);
|
||||||
|
if (!authoringKitResult.isPresent()) {
|
||||||
|
return new CreateStepResult(
|
||||||
|
showCreateStepNotAvailable(section, folderPath, documentType)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
final MvcAuthoringKit authoringKit = authoringKitResult.get();
|
||||||
|
final Class<? extends MvcDocumentCreateStep<?>> createStepClass
|
||||||
|
= authoringKit.createStep();
|
||||||
|
|
||||||
|
// final Instance<MvcDocumentCreateStep<?>> instance = createSteps
|
||||||
|
// .select(new CreateDocumentOfTypeLiteral(documentClass));
|
||||||
|
final Instance<? extends MvcDocumentCreateStep<?>> instance
|
||||||
|
= createSteps.select(createStepClass);
|
||||||
if (instance.isUnsatisfied() || instance.isAmbiguous()) {
|
if (instance.isUnsatisfied() || instance.isAmbiguous()) {
|
||||||
return new CreateStepResult(
|
return new CreateStepResult(
|
||||||
showCreateStepNotAvailable(section, folderPath, documentType)
|
showCreateStepNotAvailable(section, folderPath, documentType)
|
||||||
|
|
|
||||||
|
|
@ -26,9 +26,7 @@ import org.librecms.contentsection.ContentItemManager;
|
||||||
import org.librecms.contentsection.ContentItemRepository;
|
import org.librecms.contentsection.ContentItemRepository;
|
||||||
import org.librecms.contenttypes.Article;
|
import org.librecms.contenttypes.Article;
|
||||||
import org.librecms.ui.contentsections.documents.AbstractMvcDocumentCreateStep;
|
import org.librecms.ui.contentsections.documents.AbstractMvcDocumentCreateStep;
|
||||||
import org.librecms.ui.contentsections.documents.CreatesDocumentOfType;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
@ -47,7 +45,6 @@ import javax.transaction.Transactional;
|
||||||
*/
|
*/
|
||||||
@RequestScoped
|
@RequestScoped
|
||||||
@Named("CmsArticleCreateStep")
|
@Named("CmsArticleCreateStep")
|
||||||
@CreatesDocumentOfType(Article.class)
|
|
||||||
public class MvcArticleCreateStep
|
public class MvcArticleCreateStep
|
||||||
extends AbstractMvcDocumentCreateStep<Article> {
|
extends AbstractMvcDocumentCreateStep<Article> {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -201,7 +201,7 @@
|
||||||
id="new-document-dialog"
|
id="new-document-dialog"
|
||||||
tabindex="-1">
|
tabindex="-1">
|
||||||
<div class="modal-dialog">
|
<div class="modal-dialog">
|
||||||
<form action="#{mvc.basePath}/#{ContentSectionModel.sectionName}/documents/#{DocumentFolderModel.path}/@create"
|
<form action="#{mvc.basePath}/#{ContentSectionModel.sectionName}/documents/#{DocumentFolderModel.pathWithTrailingSlash}@create"
|
||||||
class="modal-content"
|
class="modal-content"
|
||||||
method="post">
|
method="post">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue