From 8dad9039633c5f718745b70d4c99e2db280f09b3 Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Mon, 11 Apr 2022 19:16:12 +0200 Subject: [PATCH] First part of MVC based UI for SciProject --- .../sciproject/ui/ProjectCreateStep.java | 188 ++++++++++++++++++ .../ui/SciProjectStepsConstants.java | 34 ++++ 2 files changed, 222 insertions(+) create mode 100644 sci-types-project/src/main/java/org/scientificcms/contenttypes/sciproject/ui/ProjectCreateStep.java create mode 100644 sci-types-project/src/main/java/org/scientificcms/contenttypes/sciproject/ui/SciProjectStepsConstants.java diff --git a/sci-types-project/src/main/java/org/scientificcms/contenttypes/sciproject/ui/ProjectCreateStep.java b/sci-types-project/src/main/java/org/scientificcms/contenttypes/sciproject/ui/ProjectCreateStep.java new file mode 100644 index 0000000..1139abb --- /dev/null +++ b/sci-types-project/src/main/java/org/scientificcms/contenttypes/sciproject/ui/ProjectCreateStep.java @@ -0,0 +1,188 @@ +* Copyright (C) 2022 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.scientificcms.contenttypes.sciproject.ui; + +import org.libreccm.l10n.GlobalizationHelper; +import org.libreccm.l10n.LocalizedString; +import org.libreccm.security.AuthorizationRequired; +import org.libreccm.workflow.Workflow; +import org.librecms.contentsection.ContentItemManager; +import org.librecms.contentsection.ContentItemRepository; +import org.librecms.ui.contentsections.documents.AbstractMvcDocumentCreateStep; + +import org.scientificcms.contenttypes.sciproject.SciProject; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.inject.Named; +import javax.transaction.Transactional; + +/** + * Create step for a {@link SciProject} + * @author Jens Pelzetter + */ + @RequestScoped + @Named("SciProjectCreateStep") + public class ProjectCreateStep + extends AbstractMvcDocumentCreateStep { + + private static final String FORM_PARAM_NAME = "name"; + + private static final String FORM_PARAM_TITLE = "title"; + + private static final String FORM_PARAM_STARTDATE = "startDate"; + + private static final String FORM_PARAM_ENDDATE = "startDate"; + + private static final String FORM_PARAM_SUMMARY = "summary"; + + private static final String FORM_PARAM_INITIAL_LOCALE = "locale"; + + private static final String FORM_PARAM_SELECTED_WORKFLOW = "workflow"; + + /** + * Provides functions for working with content items. + */ + @Inject + private ContentItemManager itemManager; + + /** + * Used to save the event. + */ + @Inject + private ContentItemRepository itemRepo; + + /** + * Provides functions for working with {@link LocalizedString}s. + */ + @Inject + private GlobalizationHelper globalizationHelper; + + /** + * Name of the project. + */ + private String name; + + /** + * Title of the project. + */ + private String title; + + /** + * The start date of the project. + */ + private String startDate; + + /** + * The end date of the project + */ + private String endDate; + + /** + * The short description of the project. + */ + private String shortDescription; + + /** + * The initial locale of the project. + */ + private String initialLocale; + + /** + * The workflow to use for the new project. + */ + private String selectedWorkflow; + + @Override + public String getDocumentType() { + return SciProject.class.getName(); + } + + @Override + public String getDescription() { + return globalizationHelper + .getLocalizedTextsUtil(getBundle()) + .getText("createstep.description"); + } + + @Override + public String getBundle() { + return SciProjectStepsConstants.BUNDLE; + } + + public String getName() { + return name; + } + + public String getTitle() { + return getTitle(); + } + + public String getStartDate() { + return startDate; + } + + public String getEndDate() { + return endDate; + } + + public String getShortDescription() { + return shortDescription; + } + + public String getInitialLocale() { + return initialLocale; + } + + @Transactional(Transactional.TxType.REQUIRED) + public String getSelectedWorkflow() { + if (selectedWorkflow == null || selectedWorkflow.isEmpty()) { + return getContentSection() + .getContentTypes() + .stream() + .filter( + type -> type.getContentItemClass().equals( + Event.class.getName() + ) + ) + .findAny() + .map(type -> type.getDefaultWorkflow()) + .map( + workflow -> globalizationHelper.getValueFromLocalizedString( + workflow.getName() + ) + ) + .orElse(""); + } else { + return selectedWorkflow; + } + } + + @Override + public String showCreateStep() { + return "org/scientificcms/contenttypes/sciproject/ui/create-sciproject.xhtml"; + } + + @AuthorizationRequired + @Transactional(Transactional.TxType.REQUIRED) + @Override + public String createItem(final Map formParams) { + // ToDo + } + } + diff --git a/sci-types-project/src/main/java/org/scientificcms/contenttypes/sciproject/ui/SciProjectStepsConstants.java b/sci-types-project/src/main/java/org/scientificcms/contenttypes/sciproject/ui/SciProjectStepsConstants.java new file mode 100644 index 0000000..42cab7e --- /dev/null +++ b/sci-types-project/src/main/java/org/scientificcms/contenttypes/sciproject/ui/SciProjectStepsConstants.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2022 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.scientificcms.contenttypes.sciproject.ui; + + /** + * Constants for the authoring steps for editing an {@link Event}. + * + * @author Jens Pelzetter + */ +public final class SciProjectStepsConstants { + + private SciProjectStepsConstants() { + // Nothing + } + + public static final String BUNDLE + = "org.scientificcms.contentypes.sciproject.ui.SciProjectBundle"; +} \ No newline at end of file