From 7acb09ccf49a60ceb87e7fc02e681bdecaf779f7 Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Tue, 19 Nov 2019 13:29:03 +0100 Subject: [PATCH] Forms for WorkingPapers --- .../cms/contenttypes/ui/ReviewController.java | 14 -- .../ui/WorkingPaperController.java | 50 +++++++ .../ui/WorkingPaperPropertiesStep.java | 128 +++++++++++++++++ .../ui/WorkingPaperPropertyForm.java | 135 ++++++++++++++++++ 4 files changed, 313 insertions(+), 14 deletions(-) delete mode 100644 sci-publications/src/main/java/com/arsdigita/cms/contenttypes/ui/ReviewController.java create mode 100644 sci-publications/src/main/java/com/arsdigita/cms/contenttypes/ui/WorkingPaperController.java create mode 100644 sci-publications/src/main/java/com/arsdigita/cms/contenttypes/ui/WorkingPaperPropertiesStep.java create mode 100644 sci-publications/src/main/java/com/arsdigita/cms/contenttypes/ui/WorkingPaperPropertyForm.java diff --git a/sci-publications/src/main/java/com/arsdigita/cms/contenttypes/ui/ReviewController.java b/sci-publications/src/main/java/com/arsdigita/cms/contenttypes/ui/ReviewController.java deleted file mode 100644 index e612ced..0000000 --- a/sci-publications/src/main/java/com/arsdigita/cms/contenttypes/ui/ReviewController.java +++ /dev/null @@ -1,14 +0,0 @@ -/* - * 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 com.arsdigita.cms.contenttypes.ui; - -/** - * - * @author Jens Pelzetter - */ -public class ReviewController { - -} diff --git a/sci-publications/src/main/java/com/arsdigita/cms/contenttypes/ui/WorkingPaperController.java b/sci-publications/src/main/java/com/arsdigita/cms/contenttypes/ui/WorkingPaperController.java new file mode 100644 index 0000000..1ca8cfd --- /dev/null +++ b/sci-publications/src/main/java/com/arsdigita/cms/contenttypes/ui/WorkingPaperController.java @@ -0,0 +1,50 @@ +/* + * 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 com.arsdigita.cms.contenttypes.ui; + +import org.scientificcms.publications.PublicationRepository; +import org.scientificcms.publications.WorkingPaper; + +import java.util.Map; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.transaction.Transactional; + +/** + * + * @author Jens Pelzetter + */ +@RequestScoped +public class WorkingPaperController { + + public static final String PEER_REVIEWED = "reviewed"; + + @Inject + private PublicationRepository publicationRepository; + + @Transactional(Transactional.TxType.REQUIRED) + public void saveWorkingPaper( + final long workingPaperId, final Map data + ) { + final WorkingPaper workingPaper = publicationRepository + .findByIdAndType(workingPaperId, WorkingPaper.class) + .orElseThrow( + () -> new IllegalArgumentException( + String.format( + "No WorkingPaper with Id %d found.", workingPaperId + ) + ) + ); + + if (data.containsKey(PEER_REVIEWED)) { + workingPaper.setPeerReviewed((Boolean) data.get(PEER_REVIEWED)); + } + + publicationRepository.save(workingPaper); + } + +} diff --git a/sci-publications/src/main/java/com/arsdigita/cms/contenttypes/ui/WorkingPaperPropertiesStep.java b/sci-publications/src/main/java/com/arsdigita/cms/contenttypes/ui/WorkingPaperPropertiesStep.java new file mode 100644 index 0000000..16dae17 --- /dev/null +++ b/sci-publications/src/main/java/com/arsdigita/cms/contenttypes/ui/WorkingPaperPropertiesStep.java @@ -0,0 +1,128 @@ +/* + * 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 com.arsdigita.cms.contenttypes.ui; + +import com.arsdigita.bebop.Component; +import com.arsdigita.bebop.Label; +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.parameters.StringParameter; +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.ui.authoring.AuthoringKitWizard; +import com.arsdigita.cms.ui.authoring.BasicPageForm; +import com.arsdigita.cms.ui.authoring.SimpleEditStep; +import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess; +import com.arsdigita.domain.DomainService; +import com.arsdigita.globalization.GlobalizedMessage; +import com.arsdigita.toolbox.ui.DomainObjectPropertySheet; + +import org.scientificcms.publications.SciPublicationsConstants; + +/** + * + * @author Jens Pelzetter + */ +public class WorkingPaperPropertiesStep extends UnPublishedPropertiesStep { + + private final StringParameter selectedLangParam; + + public WorkingPaperPropertiesStep( + final ItemSelectionModel itemModel, + final AuthoringKitWizard parent, + final StringParameter selectedLangParam) { + super(itemModel, parent, selectedLangParam); + this.selectedLangParam = selectedLangParam; + } + + public static Component getWorkingPaperPropertySheet( + final ItemSelectionModel itemModel, + final StringParameter selectedLangParam + ) { + final DomainObjectPropertySheet sheet + = (DomainObjectPropertySheet) getUnPublishedPropertySheet( + itemModel, selectedLangParam + ); + + sheet.add( + new GlobalizedMessage( + "publications.ui.workingpaper.reviewed", + SciPublicationsConstants.BUNDLE + ), + WorkingPaperController.PEER_REVIEWED, + new ReviewedFormatter() + ); + + return sheet; + } + + @Override + protected void addBasicProperties( + final ItemSelectionModel itemModel, + final AuthoringKitWizard parent + ) { + final SimpleEditStep basicProperties = new SimpleEditStep( + itemModel, + parent, + selectedLangParam, + EDIT_SHEET_NAME + ); + + BasicPageForm editBasicSheet = new WorkingPaperPropertyForm( + itemModel, this, selectedLangParam + ); + + basicProperties.add( + EDIT_SHEET_NAME, + new GlobalizedMessage( + "publications.ui.workingpaper.edit_basic_sheet", + SciPublicationsConstants.BUNDLE + ), + new WorkflowLockedComponentAccess(editBasicSheet, itemModel), + editBasicSheet.getSaveCancelSection().getCancelButton()); + + basicProperties.setDisplayComponent( + getWorkingPaperPropertySheet(itemModel, selectedLangParam) + ); + + getSegmentedPanel().addSegment( + new Label( + new GlobalizedMessage( + "publications.ui.publication.basic_properties", + SciPublicationsConstants.BUNDLE + ) + ), + basicProperties); + } + + private static class ReviewedFormatter + extends DomainService + implements DomainObjectPropertySheet.AttributeFormatter { + + public ReviewedFormatter() { + super(); + } + + @Override + public String format( + final Object obj, final String attribute, final PageState state + ) { + if ((get(obj, attribute) != null) + && (get(obj, attribute) instanceof Boolean) + && ((Boolean) get(obj, attribute) == true)) { + return (String) new GlobalizedMessage( + "publications.ui.workingpaper.reviewed.yes", + SciPublicationsConstants.BUNDLE + ).localize(); + } else { + return (String) new GlobalizedMessage( + "publications.ui.workingpaper.reviewed.no", + SciPublicationsConstants.BUNDLE + ).localize(); + } + } + + } + +} diff --git a/sci-publications/src/main/java/com/arsdigita/cms/contenttypes/ui/WorkingPaperPropertyForm.java b/sci-publications/src/main/java/com/arsdigita/cms/contenttypes/ui/WorkingPaperPropertyForm.java new file mode 100644 index 0000000..022cc7a --- /dev/null +++ b/sci-publications/src/main/java/com/arsdigita/cms/contenttypes/ui/WorkingPaperPropertyForm.java @@ -0,0 +1,135 @@ +/* + * 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 com.arsdigita.cms.contenttypes.ui; + +import com.arsdigita.bebop.FormProcessException; +import com.arsdigita.bebop.Label; +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.event.FormInitListener; +import com.arsdigita.bebop.event.FormProcessListener; +import com.arsdigita.bebop.event.FormSectionEvent; +import com.arsdigita.bebop.event.FormSubmissionListener; +import com.arsdigita.bebop.form.CheckboxGroup; +import com.arsdigita.bebop.form.Option; +import com.arsdigita.bebop.parameters.StringParameter; +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.globalization.GlobalizedMessage; + +import org.libreccm.cdi.utils.CdiUtil; +import org.scientificcms.publications.SciPublicationsConstants; +import org.scientificcms.publications.WorkingPaper; +import org.scientificcms.publications.contenttypes.WorkingPaperItem; + +import java.util.HashMap; +import java.util.Map; + +/** + * + * @author Jens Pelzetter + */ +public class WorkingPaperPropertyForm + extends UnPublishedPropertyForm + implements FormInitListener, + FormProcessListener, + FormSubmissionListener { + + public static final String ID = "WorkingPaperEdit"; + + private final WorkingPaperPropertiesStep step; + + private CheckboxGroup reviewed; + + public WorkingPaperPropertyForm( + final ItemSelectionModel itemModel, + final StringParameter selectedLangParam + ) { + this(itemModel, null, selectedLangParam); + } + + public WorkingPaperPropertyForm( + ItemSelectionModel itemModel, + WorkingPaperPropertiesStep step, + final StringParameter selectedLangParam + ) { + super(itemModel, step, selectedLangParam); + this.step = step; + addSubmissionListener(this); + } + + @Override + protected void addWidgets() { + + super.addWidgets(); + + reviewed = new CheckboxGroup("reviewedGroup"); + reviewed.addOption( + new Option( + WorkingPaperController.PEER_REVIEWED, + new Label( + new GlobalizedMessage( + "publications.ui.workingpaper.reviewed", + SciPublicationsConstants.BUNDLE + ) + ) + ) + ); + reviewed.setLabel( + new GlobalizedMessage( + "publications.ui.workingpaper.reviewed", + SciPublicationsConstants.BUNDLE + ) + ); + add(reviewed); + } + + @Override + public void init(final FormSectionEvent event) throws FormProcessException { + super.init(event); + + final WorkingPaperItem paperItem = (WorkingPaperItem) super + .initBasicWidgets(event); + final WorkingPaper paper = paperItem.getPublication(); + + if ((paper.getPeerReviewed() != null) && (paper.getPeerReviewed())) { + reviewed.setValue( + event.getPageState(), + new String[]{WorkingPaperController.PEER_REVIEWED} + ); + } else { + reviewed.setValue(event.getPageState(), null); + } + } + + @Override + public void process(final FormSectionEvent event) + throws FormProcessException { + super.process(event); + final PageState state = event.getPageState(); + + final WorkingPaperItem paperItem = (WorkingPaperItem) super + .processBasicWidgets(event); + + if ((paperItem != null) + && getSaveCancelSection().getSaveButton().isSelected(state)) { + + final Map data = new HashMap<>(); + if (reviewed.getValue(event.getPageState()) == null) { + data.put(WorkingPaperController.PEER_REVIEWED, false); + } else { + data.put(WorkingPaperController.PEER_REVIEWED, true); + } + + final WorkingPaperController controller = CdiUtil + .createCdiUtil() + .findBean(WorkingPaperController.class); + + controller.saveWorkingPaper( + paperItem.getPublication().getPublicationId(), data + ); + } + } + +}