Current status of portation of the UI for SciPublications. WARNING:

Does not compile yet!
pull/1/head
Jens Pelzetter 2019-09-14 19:50:20 +02:00
parent cf5d3fb5e3
commit 0cf1647e06
10 changed files with 1532 additions and 16 deletions

View File

@ -0,0 +1,281 @@
/*
* 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.FormData;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.Text;
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.cms.ui.assets.AssetSearchWidget;
import com.arsdigita.cms.ui.assets.ItemSearchWidget;
import com.arsdigita.cms.ui.authoring.BasicItemForm;
import com.arsdigita.cms.ui.authoring.SimpleEditStep;
import com.arsdigita.globalization.GlobalizedMessage;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.libreccm.cdi.utils.CdiUtil;
import org.librecms.assets.Person;
import org.scientificcms.publications.Publication;
import org.scientificcms.publications.SciPublicationsConfig;
import org.scientificcms.publications.SciPublicationsConstants;
import org.scientificcms.publications.contenttypes.PublicationItem;
import java.util.Objects;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class PublicationAuthorAddForm
extends BasicItemForm
implements FormProcessListener, FormInitListener, FormSubmissionListener {
private static final Logger LOGGER = LogManager.getLogger(
PublicationAuthorAddForm.class
);
private final static String AUTHOR_SEARCH = "authors";
private final static SciPublicationsConfig CONFIG = SciPublicationsConfig
.getConfig();
private PublicationPropertiesStep step;
private AssetSearchWidget authorSearchWidget;
private final ItemSelectionModel itemModel;
private final SimpleEditStep editStep;
private Text selectedAuthorLabel;
private CheckboxGroup isEditor;
public PublicationAuthorAddForm(
final ItemSelectionModel itemModel,
final SimpleEditStep editStep,
final StringParameter selectedLanguageParam
) {
super("AuthorsEntryForm", itemModel, selectedLanguageParam);
this.itemModel = itemModel;
this.editStep = editStep;
addSubmissionListener(this);
}
@Override
protected void addWidgets() {
authorSearchWidget = new AssetSearchWidget(
AUTHOR_SEARCH, Person.class
);
authorSearchWidget.setLabel(
new GlobalizedMessage(
"publications.ui.authors.selectAuthor",
SciPublicationsConstants.BUNDLE
)
);
add(authorSearchWidget);
selectedAuthorLabel = new Text();
add(selectedAuthorLabel);
isEditor = new CheckboxGroup("isEditorGroup");
isEditor.addOption(
new Option(
SciPublicationsController.AUTHORSHIP_IS_EDITOR,
new Label(
new GlobalizedMessage(
"publications.ui.authors.author.is_editor",
SciPublicationsConstants.BUNDLE
)
)
)
);
add(isEditor);
}
@Override
public void init(final FormSectionEvent event) throws FormProcessException {
final FormData formData = event.getFormData();
final PageState state = event.getPageState();
final Person author;
final Boolean editor;
author = ((PublicationAuthorsPropertyStep) editStep).getSelectedAuthor();
editor = ((PublicationAuthorsPropertyStep) editStep)
.isSelectedAuthorEditor();
if (author == null) {
LOGGER.warn("No author selected.");
authorSearchWidget.setVisible(state, true);
selectedAuthorLabel.setVisible(state, false);
} else {
LOGGER.warn(
String.format(
"Author is here: %s", Objects.toString(author)
)
);
formData.put(AUTHOR_SEARCH, author);
if ((editor != null) && editor) {
isEditor.setValue(
state,
new String[]{
SciPublicationsController.AUTHORSHIP_IS_EDITOR
}
);
} else {
isEditor.setValue(state, null);
}
authorSearchWidget.setVisible(state, false);
selectedAuthorLabel.setText(
String.format("%s, %s",
author.getPersonName().getSurname(),
author.getPersonName().getGivenName()
)
);
selectedAuthorLabel.setVisible(state, true);
}
setVisible(state, true);
}
@Override
public void process(final FormSectionEvent event)
throws FormProcessException {
final FormData formData = event.getFormData();
final PageState state = event.getPageState();
final PublicationItem<?> item = (PublicationItem) itemModel
.getSelectedItem(state);
final Publication publication = item.getPublication();
if (getSaveCancelSection().getSaveButton().isSelected(state)) {
final Person author = ((PublicationAuthorsPropertyStep) editStep)
.getSelectedAuthor();
final Boolean editor;
if (isEditor.getValue(state) == null) {
editor = Boolean.FALSE;
} else {
editor = Boolean.TRUE;
}
final SciPublicationsController controller = CdiUtil
.createCdiUtil()
.findBean(SciPublicationsController.class);
if (author == null) {
final Person authorToAdd = (Person) formData.get(
AUTHOR_SEARCH
);
controller.addAuthor(
publication.getPublicationId(),
authorToAdd.getObjectId(),
editor
);
} else {
controller.updateAuthorship(publication.getPublicationId(),
author.getObjectId(),
editor);
((PublicationAuthorsPropertyStep) editStep)
.setSelectedAuthor(null);
((PublicationAuthorsPropertyStep) editStep)
.setSelectedAuthorEditor(null);
}
}
init(event);
}
@Override
public void submitted(final FormSectionEvent fse) throws
FormProcessException {
if (getSaveCancelSection().getCancelButton()
.isSelected(fse.getPageState())) {
((PublicationAuthorsPropertyStep) editStep)
.setSelectedAuthor(null);
((PublicationAuthorsPropertyStep) editStep)
.setSelectedAuthorEditor(null);
init(fse);
}
}
@Override
public void validate(final FormSectionEvent event)
throws FormProcessException {
final PageState state = event.getPageState();
final FormData formData = event.getFormData();
boolean editing = false; //Are we editing the association
if ((((PublicationAuthorsPropertyStep) editStep)
.getSelectedAuthor() == null)
&& (formData.get(AUTHOR_SEARCH) == null)) {
formData.addError(
new GlobalizedMessage(
"publications.ui.authors.selectAuthor.no_author_selected",
SciPublicationsConstants.BUNDLE
)
);
return;
}
final PublicationItem<?> item
= (PublicationItem<?>) getItemSelectionModel()
.getSelectedObject(state);
final Person author;
if (formData.get(AUTHOR_SEARCH) == null) {
author = ((PublicationAuthorsPropertyStep) editStep)
.getSelectedAuthor();
editing = true;
} else {
author = (Person) formData.get(AUTHOR_SEARCH);
}
if (!editing) {
final SciPublicationsController controller = CdiUtil
.createCdiUtil()
.findBean(SciPublicationsController.class);
final boolean hasAuthor = controller.hasAuthor(
item.getPublication().getPublicationId(),
author.getObjectId()
);
if (hasAuthor) {
formData.addError(
new GlobalizedMessage(
"publications.ui.authors.selectAuthor.already_added",
SciPublicationsConstants.BUNDLE
)
);
}
}
}
}

View File

@ -0,0 +1,81 @@
/*
* 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.parameters.StringParameter;
import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.ui.authoring.AuthoringKitWizard;
import com.arsdigita.cms.ui.authoring.BasicItemForm;
import com.arsdigita.cms.ui.authoring.SimpleEditStep;
import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess;
import com.arsdigita.globalization.GlobalizedMessage;
import org.librecms.assets.Person;
import org.scientificcms.publications.SciPublicationsConstants;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class PublicationAuthorsPropertyStep extends SimpleEditStep {
public static final String ADD_AUTHOR_SHEET_NAME = "addAuthor";
private Person selectedAuthor;
private Boolean selectedAuthorEditor;
public PublicationAuthorsPropertyStep(
final ItemSelectionModel itemModel,
final AuthoringKitWizard parent,
final StringParameter selectedLanguageParam
) {
this(itemModel, parent, selectedLanguageParam, null);
}
public PublicationAuthorsPropertyStep(
final ItemSelectionModel itemModel,
final AuthoringKitWizard authoringKitWizard,
final StringParameter selectedLanguageParameter,
final String prefix
) {
super(itemModel, authoringKitWizard, selectedLanguageParameter, prefix);
final BasicItemForm addAuthorSheet = new PublicationAuthorAddForm(
itemModel, this, selectedLanguageParameter
);
add(ADD_AUTHOR_SHEET_NAME,
new GlobalizedMessage(
"publications.ui.authors.add_author",
SciPublicationsConstants.BUNDLE
),
new WorkflowLockedComponentAccess(addAuthorSheet, itemModel),
addAuthorSheet.getSaveCancelSection().getCancelButton());
final PublicationAuthorsTable authorsTable = new PublicationAuthorsTable(
itemModel, this);
setDisplayComponent(authorsTable);
}
protected Person getSelectedAuthor() {
return selectedAuthor;
}
protected Boolean isSelectedAuthorEditor() {
return selectedAuthorEditor;
}
protected void setSelectedAuthor(final Person selectedAuthor) {
this.selectedAuthor = selectedAuthor;
}
protected void setSelectedAuthorEditor(final Boolean selectedAuthorEditor) {
this.selectedAuthorEditor = selectedAuthorEditor;
}
}

View File

@ -0,0 +1,259 @@
/*
* 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.SegmentedPanel;
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.arsdigita.cms.CMSConfig;
import org.librecms.CmsConstants;
import org.librecms.contentsection.ContentItem;
import org.scientificcms.publications.SciPublicationsConfig;
import org.scientificcms.publications.SciPublicationsConstants;
import java.text.DateFormat;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class PublicationPropertiesStep extends SimpleEditStep {
public static final String EDIT_SHEET_NAME = "edit";
private final SegmentedPanel segmentedPanel;
private final StringParameter selectedLangParameter;
public PublicationPropertiesStep(
final ItemSelectionModel itemModel,
final AuthoringKitWizard parent,
final StringParameter selectedLangParameter
) {
super(itemModel, parent, selectedLangParameter);
segmentedPanel = new SegmentedPanel();
setDefaultEditKey(EDIT_SHEET_NAME);
addBasicProperties(itemModel, parent);
addSteps(itemModel, parent);
this.selectedLangParameter = selectedLangParameter;
setDisplayComponent(segmentedPanel);
}
public static Component getPublicationPropertySheet(
final ItemSelectionModel itemModel,
final StringParameter selectedLanguageParam
) {
final DomainObjectPropertySheet sheet = new DomainObjectPropertySheet(
itemModel,
false,
selectedLanguageParam
);
sheet.add(
new GlobalizedMessage(
"publications.ui.publication.name",
SciPublicationsConstants.BUNDLE
),
SciPublicationsController.NAME
);
sheet.add(
new GlobalizedMessage(
"publications.ui.publication.title",
SciPublicationsConstants.BUNDLE),
SciPublicationsController.TITLE
);
sheet.add(
new GlobalizedMessage(
"publications.ui.publication.year_of_publication",
SciPublicationsConstants.BUNDLE
),
SciPublicationsController.YEAR_OF_PUBLICATION
);
sheet.add(
new GlobalizedMessage(
"publications.ui.publication.short_desc",
SciPublicationsConstants.BUNDLE
),
SciPublicationsController.SHORT_DESCRIPTION
);
sheet.add(
new GlobalizedMessage(
"publications.ui.publication.abstract",
SciPublicationsConstants.BUNDLE
),
SciPublicationsController.ABSTRACT
);
//new PreFormattedTextFormatter());
sheet.add(
new GlobalizedMessage(
"publications.ui.publication.misc",
SciPublicationsConstants.BUNDLE
),
SciPublicationsController.MISC
);
final SciPublicationsConfig config = SciPublicationsConfig.getConfig();
if (config.isFirstPublishedPropertyEnabled()) {
sheet.add(
new GlobalizedMessage(
"publications.ui.publication.first_published",
SciPublicationsConstants.BUNDLE),
SciPublicationsController.YEAR_FIRST_PUBLISHED
);
}
if (config.isLanguagePropertyEnabled()) {
sheet.add(
new GlobalizedMessage(
"publications.ui.publication.language_of_publication",
SciPublicationsConstants.BUNDLE
),
SciPublicationsController.LANGUAGE_OF_PUBLICATION
);
}
if (!CMSConfig.getConfig().isHideLaunchDate()) {
sheet.add(new GlobalizedMessage("cms.contenttypes.ui.launch_date",
CmsConstants.CMS_BUNDLE),
SciPublicationsController.LAUNCH_DATE,
new DomainObjectPropertySheet.AttributeFormatter() {
@Override
public String format(final Object item,
final String attribute,
final PageState state) {
final ContentItem page = (ContentItem) item;
if (page.getLaunchDate() != null) {
return DateFormat
.getDateInstance(DateFormat.LONG)
.format(page.getLaunchDate());
} else {
return (String) new GlobalizedMessage(
"cms.ui.unknown",
CmsConstants.CMS_BUNDLE)
.localize();
}
}
});
}
return sheet;
}
protected SegmentedPanel getSegmentedPanel() {
return segmentedPanel;
}
protected void addBasicProperties(final ItemSelectionModel itemModel,
final AuthoringKitWizard parent) {
SimpleEditStep basicProperties = new SimpleEditStep(
itemModel,
parent,
selectedLangParameter,
EDIT_SHEET_NAME
);
final BasicPageForm editBasicSheet = new PublicationPropertyForm(
itemModel,
this,
selectedLangParameter
);
basicProperties.add(
EDIT_SHEET_NAME,
new GlobalizedMessage(
"publications.ui.publication.edit_basic_sheet",
SciPublicationsConstants.BUNDLE
),
new WorkflowLockedComponentAccess(editBasicSheet, itemModel),
editBasicSheet.getSaveCancelSection().getCancelButton());
basicProperties.setDisplayComponent(
getPublicationPropertySheet(itemModel, selectedLangParameter)
);
segmentedPanel.addSegment(
new Label(new GlobalizedMessage(
"publications.ui.publication.basic_properties",
SciPublicationsConstants.BUNDLE)
),
basicProperties);
}
protected void addSteps(ItemSelectionModel itemModel,
AuthoringKitWizard parent) {
addStep(
new PublicationAuthorsPropertyStep(
itemModel, parent, selectedLangParameter),
new GlobalizedMessage(
"publications.ui.publication.authors",
SciPublicationsConstants.BUNDLE
)
);
if (isSeriesStepEnabled()) {
addStep(
new PublicationSeriesPropertyStep(
itemModel, parent, selectedLangParameter),
new GlobalizedMessage(
"publications.ui.publication.series",
SciPublicationsConstants.BUNDLE
)
);
}
}
protected void addStep(final SimpleEditStep step,
final GlobalizedMessage label
) {
segmentedPanel.addSegment(new Label(label), step);
}
protected boolean isSeriesStepEnabled() {
return true;
}
protected static class PreFormattedTextFormatter
extends DomainService
implements DomainObjectPropertySheet.AttributeFormatter {
public PreFormattedTextFormatter() {
super();
}
@Override
public String format(final Object obj,
final String attribute,
final PageState state) {
final String str = (String) get(obj, attribute);
if ((str == null) || str.trim().isEmpty()) {
return (String) new GlobalizedMessage(
"cms.ui.unknown", CmsConstants.CMS_BUNDLE
).localize();
} else {
return String.format("<pre>%s</pre>", str);
}
}
}
}

View File

@ -0,0 +1,338 @@
/*
* 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.FormData;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.Text;
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.event.PrintEvent;
import com.arsdigita.bebop.event.PrintListener;
import com.arsdigita.bebop.form.Option;
import com.arsdigita.bebop.form.SingleSelect;
import com.arsdigita.bebop.form.TextArea;
import com.arsdigita.bebop.form.TextField;
import com.arsdigita.bebop.parameters.IntegerParameter;
import com.arsdigita.bebop.parameters.ParameterModel;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.ui.CMSDHTMLEditor;
import com.arsdigita.cms.ui.authoring.BasicPageForm;
import com.arsdigita.cms.ui.authoring.SelectedLanguageUtil;
import com.arsdigita.globalization.GlobalizedMessage;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.l10n.GlobalizationHelper;
import org.scientificcms.publications.Publication;
import org.scientificcms.publications.SciPublicationsConfig;
import org.scientificcms.publications.SciPublicationsConstants;
import org.scientificcms.publications.contenttypes.PublicationItem;
import java.text.Collator;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class PublicationPropertyForm
extends BasicPageForm
implements FormProcessListener, FormInitListener, FormSubmissionListener {
private static final Logger LOGGER = LogManager.getLogger(
PublicationPropertyForm.class
);
public static final String ID = "Publication_edit";
private final static SciPublicationsConfig CONFIG = SciPublicationsConfig
.getConfig();
private PublicationPropertiesStep step;
private final StringParameter selectedLanguageParam;
public PublicationPropertyForm(final ItemSelectionModel itemModel,
final StringParameter selectedLangParam) {
this(itemModel, null, selectedLangParam);
}
public PublicationPropertyForm(final ItemSelectionModel itemModel,
final PublicationPropertiesStep step,
final StringParameter selectedLangParam) {
super(ID, itemModel, selectedLangParam);
this.step = step;
this.selectedLanguageParam = selectedLangParam;
addSubmissionListener(this);
}
@Override
protected void addWidgets() {
super.addWidgets();
final ParameterModel yearOfPublicationParam = new IntegerParameter(
"yearOfPublication"
);
final TextField yearOfPublication
= new TextField(yearOfPublicationParam);
yearOfPublication.setMaxLength(4);
yearOfPublication.setLabel(
new GlobalizedMessage(
"publications.ui.publication.year_of_publication",
SciPublicationsConstants.BUNDLE
)
);
add(yearOfPublication);
final ParameterModel firstPublishedParam = new IntegerParameter(
SciPublicationsController.YEAR_FIRST_PUBLISHED);
final TextField firstPublished = new TextField(firstPublishedParam);
firstPublished.setLabel(
new GlobalizedMessage(
"publications.ui.publication.first_published",
SciPublicationsConstants.BUNDLE
)
);
add(firstPublished);
final ParameterModel langParam = new StringParameter(
SciPublicationsController.LANGUAGE_OF_PUBLICATION
);
final SingleSelect lang = new SingleSelect(langParam);
final Locale[] locales = Locale.getAvailableLocales();
lang.addOption(new Option("", new Text("")));
Arrays.sort(locales, new Comparator<Locale>() {
@Override
public int compare(final Locale locale1,
final Locale locale2) {
final GlobalizationHelper globalizationHelper = CdiUtil
.createCdiUtil()
.findBean(GlobalizationHelper.class);
final Locale negLocale = globalizationHelper
.getNegotiatedLocale();
final Collator collator = Collator
.getInstance(negLocale);
return collator.compare(locale1
.getDisplayName(negLocale),
locale2
.getDisplayName(negLocale));
}
});
for (Locale locale : locales) {
final Locale currentLocale = locale;
final Label optionLabel = new Label(new PrintListener() {
@Override
public void prepare(final PrintEvent event) {
final Label target = (Label) event.getTarget();
final GlobalizationHelper globalizationHelper = CdiUtil
.createCdiUtil()
.findBean(GlobalizationHelper.class);
target.setLabel(
currentLocale.getDisplayName(
globalizationHelper.getNegotiatedLocale()
)
);
}
});
lang.addOption(new Option(locale.toString(), optionLabel));
}
lang.setLabel(
new GlobalizedMessage(
"publications.ui.publication.language",
SciPublicationsConstants.BUNDLE
)
);
add(lang);
final ParameterModel abstractParam = new StringParameter(
SciPublicationsController.ABSTRACT
);
final TextArea abstractArea;
if (CONFIG.isAbstractHtmlEnabled()) {
abstractArea = new CMSDHTMLEditor(abstractParam);
} else {
abstractArea = new TextArea(abstractParam);
}
abstractArea.setCols(60);
abstractArea.setRows(18);
abstractArea.setLabel(
new GlobalizedMessage(
"publications.ui.publication.abstract",
SciPublicationsConstants.BUNDLE
)
);
add(abstractArea);
final ParameterModel shortDescParam = new StringParameter(
SciPublicationsController.SHORT_DESCRIPTION
);
final TextArea shortDesc;
if (CONFIG.isShortDescriptionHtmlEnabled()) {
shortDesc = new CMSDHTMLEditor(shortDescParam);
} else {
shortDesc = new TextArea(shortDescParam);
}
shortDesc.setLabel(
new GlobalizedMessage(
"publications.ui.publication.short_description",
SciPublicationsConstants.BUNDLE
)
);
shortDesc.setCols(60);
shortDesc.setRows(10);
add(shortDesc);
final ParameterModel miscParam = new StringParameter(
SciPublicationsController.MISC
);
final TextArea misc;
if (CONFIG.isMiscHtmlEnabled()) {
misc = new CMSDHTMLEditor(miscParam);
} else {
misc = new TextArea(miscParam);
}
misc.setLabel(
new GlobalizedMessage(
"publications.ui.publication.misc",
SciPublicationsConstants.BUNDLE
)
);
misc.setCols(60);
misc.setRows(18);
add(misc);
}
@Override
public void init(final FormSectionEvent event) throws FormProcessException {
final FormData data = event.getFormData();
final PublicationItem<?> item = (PublicationItem<?>) super
.initBasicWidgets(event);
final PageState state = event.getPageState();
final Locale selectedLanguage = SelectedLanguageUtil
.selectedLocale(state, selectedLanguageParam);
data.put(SciPublicationsController.YEAR_OF_PUBLICATION,
item.getPublication().getYearOfPublication());
data.put(SciPublicationsController.YEAR_FIRST_PUBLISHED,
item.getPublication().getYearFirstPublished());
data.put(SciPublicationsController.LANGUAGE_OF_PUBLICATION,
item.getPublication().getLanguageOfPublication());
data.put(
SciPublicationsController.ABSTRACT,
item.getPublication().getPublicationAbstract().getValue(
selectedLanguage
)
);
data.put(
SciPublicationsController.SHORT_DESCRIPTION,
item.getPublication().getShortDescription().getValue(
selectedLanguage
)
);
data.put(
SciPublicationsController.MISC,
item.getPublication().getMisc().getValue(selectedLanguage)
);
}
@Override
public void process(FormSectionEvent event) throws FormProcessException {
final FormData formData = event.getFormData();
final PageState state = event.getPageState();
final PublicationItem<?> item = (PublicationItem) super
.processBasicWidgets(event);
if ((item != null)
&& getSaveCancelSection().getSaveButton().isSelected(state)) {
final Map<String, Object> data = new HashMap<>();
data.put(
SciPublicationsController.YEAR_OF_PUBLICATION,
formData.get(SciPublicationsController.YEAR_OF_PUBLICATION)
);
data.put(
SciPublicationsController.YEAR_FIRST_PUBLISHED,
formData.get(SciPublicationsController.YEAR_FIRST_PUBLISHED
)
);
data.put(
SciPublicationsController.LANGUAGE_OF_PUBLICATION,
new Locale(
(String) formData.get(
SciPublicationsController.LANGUAGE_OF_PUBLICATION
)
)
);
data.put(
SciPublicationsController.ABSTRACT,
formData.get(SciPublicationsController.ABSTRACT)
);
data.put(
SciPublicationsController.SHORT_DESCRIPTION,
formData.get(SciPublicationsController.SHORT_DESCRIPTION)
);
data.put(
SciPublicationsController.MISC,
formData.get(SciPublicationsController.MISC)
);
final Locale selectedLocale = SelectedLanguageUtil.selectedLocale(
state, selectedLanguageParam
);
final SciPublicationsController controller = CdiUtil
.createCdiUtil()
.findBean(SciPublicationsController.class);
controller.savePublication(item.getPublication().getPublicationId(),
selectedLocale,
data);
}
}
@Override
public void submitted(final FormSectionEvent event)
throws FormProcessException {
if ((step != null) && getSaveCancelSection().getCancelButton().
isSelected(event.getPageState())) {
step.cancelStreamlinedCreation(event.getPageState());
}
}
@Override
protected GlobalizedMessage getTitleLabel() {
return new GlobalizedMessage(
"publications.ui.publication.title",
SciPublicationsConstants.BUNDLE
);
}
}

View File

@ -0,0 +1,58 @@
/*
* 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.parameters.StringParameter;
import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.ui.authoring.AuthoringKitWizard;
import com.arsdigita.cms.ui.authoring.BasicItemForm;
import com.arsdigita.cms.ui.authoring.SimpleEditStep;
import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess;
import com.arsdigita.globalization.GlobalizedMessage;
import org.scientificcms.publications.SciPublicationsConstants;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class PublicationSeriesPropertyStep extends SimpleEditStep {
private static final String ADD_SERIES_SHEET_NAME = "addSeries";
public PublicationSeriesPropertyStep(
final ItemSelectionModel itemModel,
final AuthoringKitWizard parent,
final StringParameter selectedLanguageParameter) {
this(itemModel, parent, selectedLanguageParameter, null);
}
public PublicationSeriesPropertyStep(
final ItemSelectionModel itemModel,
final AuthoringKitWizard parent,
final StringParameter selectedLanguageParameter,
final String prefix
) {
super(itemModel, parent, selectedLanguageParameter, prefix);
final BasicItemForm addSeriesSheet = new PublicationSeriesAddForm(
itemModel, selectedLanguageParameter
);
add(ADD_SERIES_SHEET_NAME,
new GlobalizedMessage(
"publications.ui.series.add_series",
SciPublicationsConstants.BUNDLE
),
new WorkflowLockedComponentAccess(addSeriesSheet, itemModel),
addSeriesSheet.getSaveCancelSection().getCancelButton());
final PublicationSeriesTable seriesTable = new PublicationSeriesTable(
itemModel
);
setDisplayComponent(seriesTable);
}
}

View File

@ -0,0 +1,381 @@
/*
* 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.librecms.assets.Person;
import org.librecms.assets.PersonRepository;
import org.scientificcms.publications.Authorship;
import org.scientificcms.publications.Publication;
import org.scientificcms.publications.PublicationManager;
import org.scientificcms.publications.PublicationRepository;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.transaction.Transactional;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
class SciPublicationsController implements Serializable {
private static final long serialVersionUID = 1L;
public static final String NAME = "name";
public static final String TITLE = "title";
public static final String YEAR_OF_PUBLICATION = "yearOfPublication";
public static final String SHORT_DESCRIPTION = "shortDescription";
public static final String ABSTRACT = "abstract";
public static final String MISC = "misc";
public static final String YEAR_FIRST_PUBLISHED = "yearFirstPublished";
public static final String LANGUAGE_OF_PUBLICATION = "languageOfPublication";
public static final String LAUNCH_DATE = "launchDate";
public static final String AUTHORSHIP_ID = "authorshipId";
public static final String AUTHOR_NAME = "authorName";
public static final String AUTHORSHIP_IS_EDITOR = "isEditor";
public static final String AUTHORSHIP_ORDER = "order";
@Inject
private PersonRepository personRepository;
@Inject
private PublicationManager publicationManager;
@Inject
private PublicationRepository publicationRepository;
@Transactional(Transactional.TxType.REQUIRED)
public void savePublication(final long publicationId,
final Locale selectedLocale,
final Map<String, Object> data) {
final Publication publication = publicationRepository
.findById(publicationId)
.orElseThrow(
() -> new IllegalArgumentException(
String.format(
"No Publication with ID %d found.", publicationId
)
)
);
final Integer yearOfPublication = (Integer) data.get(
YEAR_OF_PUBLICATION
);
final Integer yearFirstPublished = (Integer) data.get(
YEAR_FIRST_PUBLISHED
);
final Locale languageOfPublication = (Locale) data.get(
LANGUAGE_OF_PUBLICATION
);
final String publicationAbstract = (String) data.get(ABSTRACT);
final String shortDescription = (String) data.get(SHORT_DESCRIPTION);
final String misc = (String) data.get(MISC);
publication.setYearOfPublication(yearOfPublication);
publication.setYearFirstPublished(yearFirstPublished);
publication.setLanguageOfPublication(languageOfPublication);
publication.getShortDescription().addValue(selectedLocale,
shortDescription);
publication.getPublicationAbstract().addValue(selectedLocale,
publicationAbstract);
publication.getMisc().addValue(selectedLocale, misc);
publicationRepository.save(publication);
}
@Transactional(Transactional.TxType.REQUIRED)
public List<Map<String, Object>> getAuthors(final long publicationId) {
final Publication publication = publicationRepository
.findById(publicationId)
.orElseThrow(
() -> new IllegalArgumentException(
String.format(
"No Publication with ID %d found.", publicationId
)
)
);
return publication
.getAuthorships()
.stream()
.map(this::buildAuthorshipEntry)
.collect(Collectors.toList());
}
private Map<String, Object> buildAuthorshipEntry(
final Authorship authorship
) {
Objects.requireNonNull(authorship);
final Map<String, Object> result = new HashMap<>();
result.put(AUTHORSHIP_ID, authorship.getAuthorshipId());
result.put(
AUTHOR_NAME,
String.format(
"%s, %s",
authorship.getAuthor().getPersonName().getSurname(),
authorship.getAuthor().getPersonName().getGivenName()
)
);
result.put(AUTHORSHIP_IS_EDITOR, authorship.isEditor());
result.put(AUTHORSHIP_ORDER, authorship.getAuthorOrder());
return result;
}
@Transactional(Transactional.TxType.REQUIRED)
public Optional<Authorship> findAuthorship(
final long publicationId, final Object key
) {
final Publication publication = publicationRepository
.findById(publicationId)
.orElseThrow(
() -> new IllegalArgumentException(
String.format(
"No Publication with ID %d found.", publicationId
)
)
);
final long authorshipId = (long) key;
return publication
.getAuthorships()
.stream()
.filter(authorship -> authorship.getAuthorshipId() == authorshipId)
.findAny();
}
@Transactional(Transactional.TxType.REQUIRED)
public void addAuthor(
final long publicationId, final long authorId, final boolean isEditor
) {
final Publication publication = publicationRepository
.findById(publicationId)
.orElseThrow(
() -> new IllegalArgumentException(
String.format(
"No Publication with ID %d found.", publicationId
)
)
);
final Person author = personRepository
.findById(authorId)
.orElseThrow(
() -> new IllegalArgumentException(
String.format("No Person with ID %d found.",
authorId)
)
);
publicationManager.addAuthor(author, publication, isEditor);
}
@Transactional(Transactional.TxType.REQUIRED)
public void updateAuthorship(
final long publicationId, final long authorId, final boolean isEditor
) {
final Publication publication = publicationRepository
.findById(publicationId)
.orElseThrow(
() -> new IllegalArgumentException(
String.format(
"No Publication with ID %d found.", publicationId
)
)
);
final Person author = personRepository
.findById(authorId)
.orElseThrow(
() -> new IllegalArgumentException(
String.format("No Person with ID %d found.",
authorId)
)
);
final Optional<Authorship> authorship = publication
.getAuthorships()
.stream()
.filter(current -> filterAuthorship(current, publication, author))
.findAny();
if (authorship.isPresent()) {
authorship.get().setEditor(isEditor);
publicationRepository.save(publication);
}
}
@Transactional(Transactional.TxType.REQUIRED)
public void removeAuthor(
final long publicationId, final long authorshipId
) {
final Publication publication = publicationRepository
.findById(publicationId)
.orElseThrow(
() -> new IllegalArgumentException(
String.format(
"No Publication with ID %d found.", publicationId
)
)
);
final Optional<Authorship> authorship = publication
.getAuthorships()
.stream()
.filter(current -> current.getAuthorshipId() == authorshipId)
.findAny();
if (authorship.isPresent()) {
publicationManager.removeAuthor(
authorship.get().getAuthor(),
publication
);
}
}
@Transactional(Transactional.TxType.REQUIRED)
public boolean hasAuthor(final long publicationId, final long authorId) {
final Publication publication = publicationRepository
.findById(publicationId)
.orElseThrow(
() -> new IllegalArgumentException(
String.format(
"No Publication with ID %d found.", publicationId
)
)
);
final Person author = personRepository
.findById(authorId)
.orElseThrow(
() -> new IllegalArgumentException(
String.format("No Person with ID %d found.",
authorId)
)
);
return publication
.getAuthorships()
.stream()
.anyMatch(
current -> filterAuthorship(current, publication, author)
);
}
@Transactional(Transactional.TxType.REQUIRED)
public void swapWithPrevAuthorship(
final long publicationId, final long authorshipId
) {
final Publication publication = publicationRepository
.findById(publicationId)
.orElseThrow(
() -> new IllegalArgumentException(
String.format(
"No Publication with ID %d found.", publicationId
)
)
);
final List<Authorship> authorships = publication.getAuthorships();
Authorship authorship = null;
int index = -1;
for (int i = 0; i < authorships.size(); i++) {
if (authorships.get(i).getAuthorshipId() == authorshipId) {
authorship = authorships.get(i);
index = i;
break;
}
}
if (index > 0 && authorship != null) {
final long order = authorship.getAuthorOrder();
final Authorship prevAuthorship = authorships.get(index - 1);
final long prevOrder = prevAuthorship.getAuthorOrder();
authorship.setAuthorOrder(prevOrder);
prevAuthorship.setAuthorOrder(order);
publicationRepository.save(publication);
}
}
@Transactional(Transactional.TxType.REQUIRED)
public void swapWithNextAuthorship(
final long publicationId, final long authorshipId
) {
final Publication publication = publicationRepository
.findById(publicationId)
.orElseThrow(
() -> new IllegalArgumentException(
String.format(
"No Publication with ID %d found.", publicationId
)
)
);
final List<Authorship> authorships = publication.getAuthorships();
Authorship authorship = null;
int index = -1;
for (int i = 0; i < authorships.size(); i++) {
if (authorships.get(i).getAuthorshipId() == authorshipId) {
authorship = authorships.get(i);
index = i;
break;
}
}
if (index < authorships.size() && authorship != null) {
final long order = authorship.getAuthorOrder();
final Authorship nextAuthorship = authorships.get(index + 1);
final long nextOrder = nextAuthorship.getAuthorOrder();
authorship.setAuthorOrder(nextOrder);
nextAuthorship.setAuthorOrder(order);
publicationRepository.save(publication);
}
}
private boolean filterAuthorship(final Authorship authorship,
final Publication publication,
final Person author) {
return authorship.getPublication().equals(publication)
&& authorship.getAuthor().equals(author);
}
}

View File

@ -0,0 +1,92 @@
/*
* 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.scientificcms.publications;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.configuration.Configuration;
import org.libreccm.configuration.ConfigurationManager;
import org.libreccm.configuration.Setting;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@Configuration
public class SciPublicationsConfig {
@Setting
private boolean firstPublishedPropertyEnabled = false;
@Setting
private boolean languagePropertyEnabled = false;
@Setting
private boolean abstractHtmlEnabled = true;
@Setting
private boolean shortDescriptionHtmlEnabled = true;
@Setting
private boolean miscHtmlEnabled = true;
public SciPublicationsConfig() {
super();
}
public static SciPublicationsConfig getConfig() {
final ConfigurationManager confManager = CdiUtil
.createCdiUtil()
.findBean(ConfigurationManager.class);
return confManager.findConfiguration(SciPublicationsConfig.class);
}
public boolean isFirstPublishedPropertyEnabled() {
return firstPublishedPropertyEnabled;
}
public void setFirstPublishedPropertyEnabled(
final boolean firstPublishedPropertyEnabled
) {
this.firstPublishedPropertyEnabled = firstPublishedPropertyEnabled;
}
public boolean isLanguagePropertyEnabled() {
return languagePropertyEnabled;
}
public void setLanguagePropertyEnabled(
final boolean languagePropertyEnabled
) {
this.languagePropertyEnabled = languagePropertyEnabled;
}
public boolean isAbstractHtmlEnabled() {
return abstractHtmlEnabled;
}
public void setAbstractHtmlEnabled(final boolean abstractHtmlEnabled) {
this.abstractHtmlEnabled = abstractHtmlEnabled;
}
public boolean isMiscHtmlEnabled() {
return miscHtmlEnabled;
}
public void setMiscHtmlEnabled(final boolean miscHtmlEnabled) {
this.miscHtmlEnabled = miscHtmlEnabled;
}
public boolean isShortDescriptionHtmlEnabled() {
return shortDescriptionHtmlEnabled;
}
public void setShortDescriptionHtmlEnabled(
final boolean shortDescriptionHtmlEnabled
) {
this.shortDescriptionHtmlEnabled = shortDescriptionHtmlEnabled;
}
}

View File

@ -13,4 +13,7 @@ public class SciPublicationsConstants {
public static final String DB_SCHEMA = "SCI_PUBLICATIONS";
public static final String BUNDLE
= "org.scientificcms.publications.PublicationResources";
}

View File

@ -341,8 +341,8 @@ class SciProjectController {
}
private Map<String, Object> buildMembershipEntry(
final Membership membership) {
final Membership membership
) {
Objects.requireNonNull(membership);
final Map<String, Object> result = new HashMap<>();
@ -401,7 +401,8 @@ class SciProjectController {
.findById(memberId)
.orElseThrow(
() -> new IllegalArgumentException(
String.format("No Person with ID %d found.",
String.format(
"No Person with ID %d found.",
memberId)
)
);
@ -435,8 +436,9 @@ class SciProjectController {
)
);
final MembershipStatus membershipStatus = MembershipStatus
.valueOf(status);
final MembershipStatus membershipStatus = MembershipStatus.valueOf(
status
);
final Optional<Membership> membership = project
.getMembers()
@ -476,8 +478,7 @@ class SciProjectController {
}
@Transactional(Transactional.TxType.REQUIRED)
public boolean hasMember(final long projectId,
final long memberId) {
public boolean hasMember(final long projectId, final long memberId) {
final SciProject project = projectRepository
.findById(projectId, SciProject.class)
@ -724,7 +725,7 @@ class SciProjectController {
}
}
if (index > 0 && sponsoring != null) {
if (index < sponsoringList.size() && sponsoring != null) {
final long order = sponsoring.getOrder();
final Sponsoring nextSponsoring = sponsoringList.get(index + 1);
final long nextOrder = nextSponsoring.getOrder();
@ -776,8 +777,10 @@ class SciProjectController {
.findById(projectId, SciProject.class)
.orElseThrow(
() -> new IllegalArgumentException(
String.format("No SciProject with ID %d found.",
projectId))
String.format(
"No SciProject with ID %d found.", projectId
)
)
);
final Date begin = (Date) data.get(SciProjectUiConstants.BEGIN);

View File

@ -26,6 +26,7 @@ import org.libreccm.cdi.utils.CdiUtil;
import org.scientificcms.contenttypes.sciproject.SciProject;
import org.scientificcms.contenttypes.sciproject.SciProjectConstants;
import java.time.ZoneId;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
@ -88,8 +89,27 @@ public class SciProjectPropertyForm
final FormData data = event.getFormData();
final SciProject project = (SciProject) super.initBasicWidgets(event);
throw new UnsupportedOperationException("ToDo");
data.put(
SciProjectUiConstants.BEGIN,
java.util.Date.from(
project.getBegin().atStartOfDay().atZone(
ZoneId.systemDefault()).toInstant()
)
);
data.put(
SciProjectUiConstants.END,
java.util.Date.from(
project.getEnd().atStartOfDay().atZone(
ZoneId.systemDefault()).toInstant()
)
);
final Locale selectedLangauge = SelectedLanguageUtil.selectedLocale(
event.getPageState(), selectedLanguageParameter
);
data.put(
SciProjectUiConstants.PROJECT_SHORT_DESCRIPTION,
project.getShortDescription().getValue(selectedLangauge)
);
}
@Override