Preparation for Authoring Steps integration
parent
49c1467777
commit
c2aa9ba307
|
|
@ -39,8 +39,10 @@ import org.librecms.ui.contentsections.ItemPermissionChecker;
|
||||||
|
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
@ -264,7 +266,8 @@ public class DocumentController {
|
||||||
) {
|
) {
|
||||||
final CreateStepResult result = findCreateStep(
|
final CreateStepResult result = findCreateStep(
|
||||||
sectionIdentifier,
|
sectionIdentifier,
|
||||||
folderPath, documentType
|
folderPath,
|
||||||
|
documentType
|
||||||
);
|
);
|
||||||
|
|
||||||
if (result.isCreateStepAvailable()) {
|
if (result.isCreateStepAvailable()) {
|
||||||
|
|
@ -334,130 +337,169 @@ public class DocumentController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Redirects to the first authoring step for the document identified by the
|
* Redirects to the first authoring step for the document identified by the
|
||||||
// * provided path.
|
* provided path.
|
||||||
// *
|
*
|
||||||
// * @param sectionIdentifier The identifier of the current content section.
|
* @param sectionIdentifier The identifier of the current content section.
|
||||||
// * @param documentPath The path of the document.
|
* @param documentPath The path of the document.
|
||||||
// *
|
*
|
||||||
// * @return A redirect to the first authoring step of the document, or the
|
* @return A redirect to the first authoring step of the document, or the
|
||||||
// * {@link DocumentNotFound} pseudo authoring step.
|
* {@link DocumentNotFound} pseudo authoring step.
|
||||||
// */
|
*/
|
||||||
// @Path("/{documentPath:(.+)?}")
|
@GET
|
||||||
// @AuthorizationRequired
|
@Path("/{documentPath:(.+)?}")
|
||||||
// @Transactional(Transactional.TxType.REQUIRED)
|
@AuthorizationRequired
|
||||||
// public String editDocument(
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
// @PathParam("sectionIdentifier") final String sectionIdentifier,
|
public String showEditDocument(
|
||||||
// @PathParam("documentPath") final String documentPath
|
@PathParam("sectionIdentifier") final String sectionIdentifier,
|
||||||
// ) {
|
@PathParam("documentPath") final String documentPath
|
||||||
// final Optional<ContentSection> sectionResult = sectionsUi
|
) {
|
||||||
// .findContentSection(sectionIdentifier);
|
final Optional<ContentSection> sectionResult = sectionsUi
|
||||||
// if (!sectionResult.isPresent()) {
|
.findContentSection(sectionIdentifier);
|
||||||
// sectionsUi.showContentSectionNotFound(sectionIdentifier);
|
if (!sectionResult.isPresent()) {
|
||||||
// }
|
sectionsUi.showContentSectionNotFound(sectionIdentifier);
|
||||||
// final ContentSection section = sectionResult.get();
|
}
|
||||||
//
|
final ContentSection section = sectionResult.get();
|
||||||
// final Optional<ContentItem> itemResult = itemRepo
|
|
||||||
// .findByPath(section, documentPath);
|
final Optional<ContentItem> itemResult = itemRepo
|
||||||
// if (!itemResult.isPresent()) {
|
.findByPath(section, documentPath);
|
||||||
// models.put("section", section.getLabel());
|
if (!itemResult.isPresent()) {
|
||||||
// models.put("documentPath", documentPath);
|
models.put("section", section.getLabel());
|
||||||
// documentUi.showDocumentNotFound(section, documentPath);
|
models.put("documentPath", documentPath);
|
||||||
// }
|
documentUi.showDocumentNotFound(section, documentPath);
|
||||||
// final ContentItem item = itemResult.get();
|
}
|
||||||
// if (!itemPermissionChecker.canEditItem(item)) {
|
final ContentItem item = itemResult.get();
|
||||||
// return documentUi.showAccessDenied(
|
if (!itemPermissionChecker.canEditItem(item)) {
|
||||||
// section,
|
return documentUi.showAccessDenied(
|
||||||
// item,
|
section,
|
||||||
// defaultStepsMessageBundle.getMessage("edit_denied")
|
item,
|
||||||
// );
|
defaultStepsMessageBundle.getMessage("edit_denied")
|
||||||
// }
|
);
|
||||||
//
|
}
|
||||||
// return String.format(
|
|
||||||
// "redirect:/%s/documents/%s/@authoringsteps/%s",
|
return String.format(
|
||||||
// sectionIdentifier,
|
"redirect:/%s/documents/%s/@authoringsteps/%s",
|
||||||
// documentPath,
|
sectionIdentifier,
|
||||||
// findPathFragmentForFirstStep(item)
|
documentPath,
|
||||||
// );
|
findFirstAuthoringStep(item)
|
||||||
// }
|
);
|
||||||
// /**
|
}
|
||||||
// * Redirect requests for an authoring step to the subresource of the
|
|
||||||
// * authoring step.
|
/**
|
||||||
// *
|
* Redirect requests for an authoring step to the subresource of the
|
||||||
// * @param sectionIdentifier The identifier of the current content
|
* authoring step.
|
||||||
// * section.
|
*
|
||||||
// * @param documentPath The path of the document to edit.
|
* @param sectionIdentifier The identifier of the current content
|
||||||
// * @param authoringStepIdentifier The identifier/path fragment of the
|
* section.
|
||||||
// * authoring step.
|
* @param documentPath The path of the document to edit.
|
||||||
// *
|
* @param authoringStepIdentifier The identifier/path fragment of the
|
||||||
// * @return The authoring step subresource.
|
* authoring step.
|
||||||
// */
|
* @param request
|
||||||
// @Path("/{documentPath:(.+)?}/@authoringsteps/{authoringStep}")
|
*
|
||||||
// @AuthorizationRequired
|
* @return The authoring step subresource.
|
||||||
// @Transactional(Transactional.TxType.REQUIRED)
|
*/
|
||||||
// public MvcAuthoringStep editDocument(
|
@GET
|
||||||
// @PathParam("sectionIdentifier") final String sectionIdentifier,
|
@Path("/{documentPath:(.+)?}/@authoringsteps/{authoringStep}")
|
||||||
// @PathParam("documentPath") final String documentPath,
|
@AuthorizationRequired
|
||||||
// @PathParam("authoringStep") final String authoringStepIdentifier
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
// ) {
|
public String showEditDocument(
|
||||||
// final Optional<ContentSection> sectionResult = sectionsUi
|
@PathParam("sectionIdentifier") final String sectionIdentifier,
|
||||||
// .findContentSection(sectionIdentifier);
|
@PathParam("documentPath") final String documentPath,
|
||||||
// if (!sectionResult.isPresent()) {
|
@PathParam("authoringStep") final String authoringStepIdentifier,
|
||||||
// models.put("sectionIdentifier", sectionIdentifier);
|
@Context final HttpServletRequest request
|
||||||
// return new ContentSectionNotFound();
|
) {
|
||||||
// }
|
final Optional<ContentSection> sectionResult = sectionsUi
|
||||||
// final ContentSection section = sectionResult.get();
|
.findContentSection(sectionIdentifier);
|
||||||
//
|
if (!sectionResult.isPresent()) {
|
||||||
// final Optional<ContentItem> itemResult = itemRepo
|
models.put("sectionIdentifier", sectionIdentifier);
|
||||||
// .findByPath(section, documentPath);
|
return sectionsUi.showContentSectionNotFound(sectionIdentifier);
|
||||||
// if (!itemResult.isPresent()) {
|
}
|
||||||
// models.put("section", section.getLabel());
|
final ContentSection section = sectionResult.get();
|
||||||
// models.put("documentPath", documentPath);
|
|
||||||
// return new DocumentNotFound();
|
final Optional<ContentItem> itemResult = itemRepo
|
||||||
// }
|
.findByPath(section, documentPath);
|
||||||
// final ContentItem item = itemResult.get();
|
if (!itemResult.isPresent()) {
|
||||||
// if (!itemPermissionChecker.canEditItem(item)) {
|
models.put("section", section.getLabel());
|
||||||
// models.put("section", section.getLabel());
|
models.put("documentPath", documentPath);
|
||||||
// models.put("documentPath", itemManager.getItemFolder(item));
|
return documentUi.showDocumentNotFound(section, documentPath);
|
||||||
// models.put(
|
}
|
||||||
// "step", defaultStepsMessageBundle.getMessage("edit_step")
|
final ContentItem item = itemResult.get();
|
||||||
// );
|
if (!itemPermissionChecker.canEditItem(item)) {
|
||||||
// return new EditDenied();
|
models.put("section", section.getLabel());
|
||||||
// }
|
models.put("documentPath", itemManager.getItemFolder(item));
|
||||||
//
|
models.put(
|
||||||
// final Instance<MvcAuthoringStep> instance = authoringSteps
|
"step", defaultStepsMessageBundle.getMessage("edit_step")
|
||||||
// .select(
|
);
|
||||||
// new AuthoringStepPathFragmentLiteral(
|
return documentUi.showAccessDenied(
|
||||||
// authoringStepIdentifier
|
section, documentPath, documentPath
|
||||||
// )
|
);
|
||||||
// );
|
}
|
||||||
// if (instance.isUnsatisfied() || instance.isAmbiguous()) {
|
|
||||||
// models.put("section", section.getLabel());
|
final Instance<MvcAuthoringStep> instance = authoringSteps
|
||||||
// models.put("documentPath", documentPath);
|
.select(
|
||||||
// models.put("authoringStep", authoringStepIdentifier);
|
new AuthoringStepPathFragmentLiteral(
|
||||||
// return new AuthoringStepNotAvailable();
|
authoringStepIdentifier
|
||||||
// }
|
)
|
||||||
// final MvcAuthoringStep authoringStep = instance.get();
|
);
|
||||||
//
|
if (instance.isUnsatisfied() || instance.isAmbiguous()) {
|
||||||
// if (!authoringStep.supportedDocumentType().isAssignableFrom(item
|
models.put("section", section.getLabel());
|
||||||
// .getClass())) {
|
models.put("documentPath", documentPath);
|
||||||
// models.put("section", section.getLabel());
|
models.put("authoringStep", authoringStepIdentifier);
|
||||||
// models.put("documentPath", documentPath);
|
return showAuthoringStepNotAvailable(authoringStepIdentifier);
|
||||||
// models.put("documentType", item.getClass().getName());
|
}
|
||||||
// models.put("authoringStep", authoringStepIdentifier);
|
final MvcAuthoringStep authoringStep = instance.get();
|
||||||
// return new UnsupportedDocumentType();
|
|
||||||
// }
|
if (!authoringStep.supportedDocumentType().isAssignableFrom(item
|
||||||
//
|
.getClass())) {
|
||||||
// models.put("authoringStep", authoringStepIdentifier);
|
models.put("section", section.getLabel());
|
||||||
//
|
models.put("documentPath", documentPath);
|
||||||
// selectedDocumentModel.setContentItem(item);
|
models.put("documentType", item.getClass().getName());
|
||||||
//
|
models.put("authoringStep", authoringStepIdentifier);
|
||||||
// authoringStep.setContentSection(section);
|
return showUnsupportedDocumentType(
|
||||||
// authoringStep.setContentItem(item);
|
authoringStepIdentifier,
|
||||||
//
|
item.getClass().getName()
|
||||||
// return authoringStep;
|
);
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
models.put("authoringStep", authoringStepIdentifier);
|
||||||
|
|
||||||
|
selectedDocumentModel.setContentItem(item);
|
||||||
|
|
||||||
|
authoringStep.setContentSection(section);
|
||||||
|
authoringStep.setContentItem(item);
|
||||||
|
|
||||||
|
return authoringStep.showStep();
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Path("/{documentPath:(.+)?}/@authoringsteps/{authoringStep}")
|
||||||
|
@AuthorizationRequired
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
public String doEditAction(
|
||||||
|
@PathParam("sectionIdentifier") final String sectionIdentifier,
|
||||||
|
@PathParam("documentPath") final String documentPath,
|
||||||
|
@PathParam("authoringStep") final String authoringStepIdentifier,
|
||||||
|
@Context final HttpServletRequest request
|
||||||
|
) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Path(
|
||||||
|
"/{documentPath:(.+)?}/@authoringsteps/{authoringStep}/{parameterPath:(.+)?}")
|
||||||
|
@AuthorizationRequired
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
public String doEditAction(
|
||||||
|
@PathParam("sectionIdentifier") final String sectionIdentifier,
|
||||||
|
@PathParam("documentPath") final String documentPath,
|
||||||
|
@PathParam("authoringStep") final String authoringStepIdentifier,
|
||||||
|
@PathParam("parameterPath") final String parameterPath,
|
||||||
|
@Context final HttpServletRequest request
|
||||||
|
) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show the document history page.
|
* Show the document history page.
|
||||||
*
|
*
|
||||||
|
|
@ -730,46 +772,48 @@ public class DocumentController {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Helper method for reading the authoring steps for the current content
|
|
||||||
// * item.
|
|
||||||
// *
|
|
||||||
// * @param item The content item.
|
|
||||||
// *
|
|
||||||
// * @return A list of authoring steps for the provided item.
|
|
||||||
// */
|
|
||||||
// private List<MvcAuthoringStep> readAuthoringSteps(
|
|
||||||
// final ContentItem item
|
|
||||||
// ) {
|
|
||||||
// final MvcAuthoringKit authoringKit = item
|
|
||||||
// .getClass()
|
|
||||||
// .getAnnotation(MvcAuthoringKit.class);
|
|
||||||
//
|
|
||||||
// final Class<? extends MvcAuthoringStep>[] stepClasses = authoringKit
|
|
||||||
// .authoringSteps();
|
|
||||||
//
|
|
||||||
// return Arrays
|
|
||||||
// .stream(stepClasses)
|
|
||||||
// .map(authoringSteps::select)
|
|
||||||
// .filter(instance -> instance.isResolvable())
|
|
||||||
// .map(Instance::get)
|
|
||||||
// .collect(Collectors.toList());
|
|
||||||
// }
|
|
||||||
/**
|
/**
|
||||||
* // * Helper method for finding the path fragment for the first authoring
|
* Helper method for reading the authoring steps for the current content
|
||||||
* step // * for a content item. // * // * @param item The content item. //
|
* item.
|
||||||
* * // * @return The path fragment of the first authoring step of the item.
|
*
|
||||||
* //
|
* @param item The content item.
|
||||||
|
*
|
||||||
|
* @return A list of authoring steps for the provided item.
|
||||||
*/
|
*/
|
||||||
// private String findPathFragmentForFirstStep(final ContentItem item) {
|
private List<MvcAuthoringStep> readAuthoringSteps(
|
||||||
// final List<MvcAuthoringStep> steps = readAuthoringSteps(item);
|
final ContentItem item
|
||||||
//
|
) {
|
||||||
// final MvcAuthoringStep firstStep = steps.get(0);
|
final MvcAuthoringKit authoringKit = item
|
||||||
// final AuthoringStepPathFragment pathFragment = firstStep
|
.getClass()
|
||||||
// .getClass()
|
.getAnnotation(MvcAuthoringKit.class);
|
||||||
// .getAnnotation(AuthoringStepPathFragment.class);
|
|
||||||
// return pathFragment.value();
|
final Class<? extends MvcAuthoringStep>[] stepClasses = authoringKit
|
||||||
// }
|
.authoringSteps();
|
||||||
|
|
||||||
|
return Arrays
|
||||||
|
.stream(stepClasses)
|
||||||
|
.map(authoringSteps::select)
|
||||||
|
.filter(instance -> instance.isResolvable())
|
||||||
|
.map(Instance::get)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method for finding the path fragment for the first authoring step
|
||||||
|
* for a content item.
|
||||||
|
*
|
||||||
|
* @param item The content item.
|
||||||
|
*
|
||||||
|
* @return The path fragment of the first authoring step of the item.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private String findFirstAuthoringStep(final ContentItem item) {
|
||||||
|
final List<MvcAuthoringStep> steps = readAuthoringSteps(item);
|
||||||
|
|
||||||
|
final MvcAuthoringStep firstStep = steps.get(0);
|
||||||
|
return firstStep.getClass().getName();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method for building an entry in the list of lifecycles for the
|
* Helper method for building an entry in the list of lifecycles for the
|
||||||
* view.
|
* view.
|
||||||
|
|
@ -903,6 +947,19 @@ public class DocumentController {
|
||||||
return "org/librecms/ui/contentsection/documents/create-step-not-available.xhtml";
|
return "org/librecms/ui/contentsection/documents/create-step-not-available.xhtml";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String showAuthoringStepNotAvailable(final String stepIdentifier) {
|
||||||
|
models.put("stepIdentifier", stepIdentifier);
|
||||||
|
return "org/librecms/ui/contentsection/documents/authoringstep-not-available.xhtml";
|
||||||
|
}
|
||||||
|
|
||||||
|
private String showUnsupportedDocumentType(
|
||||||
|
final String stepIdentifier, final String documentType
|
||||||
|
) {
|
||||||
|
models.put("stepIdentifier", stepIdentifier);
|
||||||
|
models.put("documentType", documentType);
|
||||||
|
return "org/librecms/ui/contentsection/documents/unsupportedDocumentType.xhtml";
|
||||||
|
}
|
||||||
|
|
||||||
private CreateStepResult findCreateStep(
|
private CreateStepResult findCreateStep(
|
||||||
final String sectionIdentifier,
|
final String sectionIdentifier,
|
||||||
final String folderPath,
|
final String folderPath,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue