Forms for WorkingPapers
parent
c9ed92fd1c
commit
7acb09ccf4
|
|
@ -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 <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class ReviewController {
|
||||
|
||||
}
|
||||
|
|
@ -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 <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@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<String, Object> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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 <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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 <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
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<String, Object> 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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue