Forms for InternetArticle
parent
d64a65d4e0
commit
af1964c745
|
|
@ -0,0 +1,153 @@
|
|||
/*
|
||||
* 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.Organization;
|
||||
import org.librecms.contentsection.AssetRepository;
|
||||
import org.scientificcms.publications.InternetArticle;
|
||||
import org.scientificcms.publications.PublicationRepository;
|
||||
|
||||
import java.time.LocalDate;
|
||||
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 InternetArticleController {
|
||||
|
||||
public static final String PLACE = "place";
|
||||
|
||||
public static final String NUMBER = "number";
|
||||
|
||||
public static final String NUMBER_OF_PAGES = "numberOfPages";
|
||||
|
||||
public static final String EDITION = "edition";
|
||||
|
||||
public static final String ISSN = "issn";
|
||||
|
||||
public static final String LAST_ACCESSED = "lastAccessed";
|
||||
|
||||
public static final String URL = "url";
|
||||
|
||||
public static final String URN = "urn";
|
||||
|
||||
public static final String DOI = "doi";
|
||||
|
||||
@Inject
|
||||
private AssetRepository assetRepository;
|
||||
|
||||
@Inject
|
||||
private PublicationRepository publicationRepository;
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public void saveInternetArticle(
|
||||
final long internetArticleId, final Map<String, Object> data
|
||||
) {
|
||||
final InternetArticle internetArticle = publicationRepository
|
||||
.findByIdAndType(internetArticleId, InternetArticle.class)
|
||||
.orElseThrow(
|
||||
() -> new IllegalArgumentException(
|
||||
String.format(
|
||||
"No InternetArticle with ID %d found.",
|
||||
internetArticleId
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
if (data.containsKey(PLACE)) {
|
||||
internetArticle.setPlace((String) data.get(PLACE));
|
||||
}
|
||||
|
||||
if (data.containsKey(NUMBER)) {
|
||||
internetArticle.setNumber((String) data.get(NUMBER));
|
||||
}
|
||||
|
||||
if (data.containsKey(NUMBER_OF_PAGES)) {
|
||||
internetArticle.setNumberOfPages(
|
||||
(Integer) data.get(NUMBER_OF_PAGES)
|
||||
);
|
||||
}
|
||||
|
||||
if (data.containsKey(EDITION)) {
|
||||
internetArticle.setEdition((String) data.get(EDITION));
|
||||
}
|
||||
|
||||
if (data.containsKey(ISSN)) {
|
||||
internetArticle.setIssn((String) data.get(ISSN));
|
||||
}
|
||||
|
||||
if (data.containsKey(LAST_ACCESSED)) {
|
||||
internetArticle.setLastAccessed((LocalDate) data.get(LAST_ACCESSED));
|
||||
}
|
||||
|
||||
if (data.containsKey(URL)) {
|
||||
internetArticle.setUrl((String) data.get(URL));
|
||||
}
|
||||
|
||||
if (data.containsKey(URN)) {
|
||||
internetArticle.setUrn((String) data.get(URN));
|
||||
}
|
||||
|
||||
if (data.containsKey(DOI)) {
|
||||
internetArticle.setDoi((String) data.get(DOI));
|
||||
}
|
||||
|
||||
publicationRepository.save(internetArticle);
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public void setOrganization(
|
||||
final long internetArticleId,
|
||||
final long organizationId
|
||||
) {
|
||||
final InternetArticle internetArticle = publicationRepository
|
||||
.findByIdAndType(internetArticleId, InternetArticle.class)
|
||||
.orElseThrow(
|
||||
() -> new IllegalArgumentException(
|
||||
String.format(
|
||||
"No InternetArticle with ID %d found.",
|
||||
internetArticleId
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
final Organization organization = assetRepository
|
||||
.findById(organizationId, Organization.class)
|
||||
.orElseThrow(
|
||||
() -> new IllegalArgumentException(
|
||||
String.format(
|
||||
"No Organization with ID %d found.", organizationId
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
internetArticle.setOrganization(organization);
|
||||
publicationRepository.save(internetArticle);
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public void unsetOrganization(final long internetArticleId) {
|
||||
final InternetArticle internetArticle = publicationRepository
|
||||
.findByIdAndType(internetArticleId, InternetArticle.class)
|
||||
.orElseThrow(
|
||||
() -> new IllegalArgumentException(
|
||||
String.format(
|
||||
"No InternetArticle with ID %d found.",
|
||||
internetArticleId
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
internetArticle.setOrganization(null);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* 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.PageState;
|
||||
import com.arsdigita.bebop.event.FormInitListener;
|
||||
import com.arsdigita.bebop.event.FormProcessListener;
|
||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||
import com.arsdigita.bebop.parameters.StringParameter;
|
||||
import com.arsdigita.cms.ItemSelectionModel;
|
||||
import com.arsdigita.cms.ui.assets.AssetSearchWidget;
|
||||
import com.arsdigita.cms.ui.authoring.BasicItemForm;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.librecms.assets.Organization;
|
||||
import org.scientificcms.publications.SciPublicationsConstants;
|
||||
import org.scientificcms.publications.contenttypes.InternetArticleItem;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class InternetArticleOrganizationForm
|
||||
extends BasicItemForm
|
||||
implements FormProcessListener, FormInitListener {
|
||||
|
||||
private static final String ORGA_SEARCH = "internetArticleOrga";
|
||||
|
||||
private AssetSearchWidget orgaSearch;
|
||||
|
||||
public InternetArticleOrganizationForm(
|
||||
final ItemSelectionModel itemModel,
|
||||
final StringParameter selectedLangParam
|
||||
) {
|
||||
super("InternetArticleOrganizationForm", itemModel, selectedLangParam);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addWidgets() {
|
||||
orgaSearch = new AssetSearchWidget(ORGA_SEARCH, Organization.class);
|
||||
orgaSearch.setLabel(
|
||||
new GlobalizedMessage(
|
||||
"publications.ui.internetarticle.select_organization",
|
||||
SciPublicationsConstants.BUNDLE
|
||||
)
|
||||
);
|
||||
add(orgaSearch);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(final FormSectionEvent event) throws FormProcessException {
|
||||
final PageState state = event.getPageState();
|
||||
setVisible(state, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(final FormSectionEvent event)
|
||||
throws FormProcessException {
|
||||
final FormData formData = event.getFormData();
|
||||
final PageState state = event.getPageState();
|
||||
|
||||
final InternetArticleItem articleItem
|
||||
= (InternetArticleItem) getItemSelectionModel()
|
||||
.getSelectedItem(state);
|
||||
|
||||
if (getSaveCancelSection().getSaveButton().isSelected(state)) {
|
||||
final Organization orga
|
||||
= (Organization) formData
|
||||
.get(ORGA_SEARCH);
|
||||
final InternetArticleController controller = CdiUtil
|
||||
.createCdiUtil()
|
||||
.findBean(InternetArticleController.class);
|
||||
|
||||
controller.setOrganization(
|
||||
articleItem.getPublication().getPublicationId(),
|
||||
orga.getObjectId()
|
||||
);
|
||||
}
|
||||
|
||||
init(event);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,267 @@
|
|||
/*
|
||||
* 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.ControlLink;
|
||||
import com.arsdigita.bebop.Label;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.Table;
|
||||
import com.arsdigita.bebop.Text;
|
||||
import com.arsdigita.bebop.event.TableActionEvent;
|
||||
import com.arsdigita.bebop.event.TableActionListener;
|
||||
import com.arsdigita.bebop.table.TableCellRenderer;
|
||||
import com.arsdigita.bebop.table.TableColumn;
|
||||
import com.arsdigita.bebop.table.TableColumnModel;
|
||||
import com.arsdigita.bebop.table.TableModel;
|
||||
import com.arsdigita.bebop.table.TableModelBuilder;
|
||||
import com.arsdigita.cms.ItemSelectionModel;
|
||||
import com.arsdigita.cms.dispatcher.Utilities;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
import com.arsdigita.util.LockableImpl;
|
||||
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.security.PermissionChecker;
|
||||
import org.librecms.assets.Organization;
|
||||
import org.librecms.contentsection.privileges.ItemPrivileges;
|
||||
import org.scientificcms.publications.InternetArticle;
|
||||
import org.scientificcms.publications.SciPublicationsConstants;
|
||||
import org.scientificcms.publications.contenttypes.InternetArticleItem;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class InternetArticleOrganizationSheet
|
||||
extends Table
|
||||
implements TableActionListener {
|
||||
|
||||
private static final String TABLE_COL_EDIT = "table_col_edit";
|
||||
|
||||
private static final String TABLE_COL_DEL = "table_col_del";
|
||||
|
||||
private final ItemSelectionModel itemModel;
|
||||
|
||||
public InternetArticleOrganizationSheet(final ItemSelectionModel itemModel) {
|
||||
super();
|
||||
this.itemModel = itemModel;
|
||||
|
||||
setEmptyView(
|
||||
new Label(
|
||||
new GlobalizedMessage(
|
||||
"publications.ui.internetarticle.organization.none",
|
||||
SciPublicationsConstants.BUNDLE
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
final TableColumnModel columnModel = getColumnModel();
|
||||
columnModel.add(
|
||||
new TableColumn(
|
||||
0,
|
||||
new Label(
|
||||
new GlobalizedMessage(
|
||||
"publications.ui.internetarticle.organization",
|
||||
SciPublicationsConstants.BUNDLE
|
||||
)
|
||||
),
|
||||
TABLE_COL_EDIT
|
||||
)
|
||||
);
|
||||
columnModel.add(
|
||||
new TableColumn(
|
||||
1,
|
||||
new Label(
|
||||
new GlobalizedMessage(
|
||||
"publications.ui.internetarticle.organization.remove",
|
||||
SciPublicationsConstants.BUNDLE
|
||||
)
|
||||
),
|
||||
TABLE_COL_DEL));
|
||||
|
||||
setModelBuilder(
|
||||
new InternetArticleOrganizationSheetModelBuilder(itemModel)
|
||||
);
|
||||
columnModel.get(0).setCellRenderer(new EditCellRenderer());
|
||||
columnModel.get(1).setCellRenderer(new DeleteCellRenderer());
|
||||
|
||||
addTableActionListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cellSelected(final TableActionEvent event) {
|
||||
final PageState state = event.getPageState();
|
||||
|
||||
final InternetArticleItem articleItem = (InternetArticleItem) itemModel
|
||||
.getSelectedObject(state);
|
||||
|
||||
final TableColumn column = getColumnModel().get(event.getColumn());
|
||||
|
||||
if (column.getHeaderKey().toString().equals(TABLE_COL_EDIT)) {
|
||||
// Nothing
|
||||
} else if (column.getHeaderKey().toString().equals(TABLE_COL_DEL)) {
|
||||
final InternetArticleController controller = CdiUtil
|
||||
.createCdiUtil()
|
||||
.findBean(InternetArticleController.class);
|
||||
controller.unsetOrganization(
|
||||
articleItem.getPublication().getPublicationId()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void headSelected(final TableActionEvent event) {
|
||||
//Nothing to do
|
||||
}
|
||||
|
||||
private class InternetArticleOrganizationSheetModelBuilder
|
||||
extends LockableImpl
|
||||
implements TableModelBuilder {
|
||||
|
||||
private final ItemSelectionModel itemModel;
|
||||
|
||||
public InternetArticleOrganizationSheetModelBuilder(
|
||||
final ItemSelectionModel itemModel
|
||||
) {
|
||||
this.itemModel = itemModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableModel makeModel(final Table table, final PageState state) {
|
||||
table.getRowSelectionModel().clearSelection(state);
|
||||
final InternetArticleItem articleItem
|
||||
= (InternetArticleItem) itemModel.
|
||||
getSelectedObject(state);
|
||||
return new InternetArticleOrganizationSheetModel(
|
||||
table, state, articleItem.getPublication()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class InternetArticleOrganizationSheetModel
|
||||
implements TableModel {
|
||||
|
||||
private final Table table;
|
||||
|
||||
private final Organization orga;
|
||||
|
||||
private boolean done;
|
||||
|
||||
public InternetArticleOrganizationSheetModel(
|
||||
final Table table,
|
||||
final PageState state,
|
||||
final InternetArticle article
|
||||
) {
|
||||
this.table = table;
|
||||
orga = article.getOrganization();
|
||||
done = orga != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumnCount() {
|
||||
return table.getColumnModel().size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean nextRow() {
|
||||
boolean ret;
|
||||
|
||||
if (done) {
|
||||
ret = true;
|
||||
done = false;
|
||||
} else {
|
||||
ret = false;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getElementAt(final int columnIndex) {
|
||||
switch (columnIndex) {
|
||||
case 0:
|
||||
return orga.getTitle();
|
||||
case 1:
|
||||
return new Label(
|
||||
new GlobalizedMessage(
|
||||
"publication.ui.internetarticle.organization.remove",
|
||||
SciPublicationsConstants.BUNDLE
|
||||
)
|
||||
);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getKeyAt(final int columnIndex) {
|
||||
return orga.getObjectId();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class EditCellRenderer
|
||||
extends LockableImpl
|
||||
implements TableCellRenderer {
|
||||
|
||||
@Override
|
||||
public Component getComponent(
|
||||
final Table table,
|
||||
final PageState state,
|
||||
final Object value,
|
||||
final boolean isSelected,
|
||||
final Object key,
|
||||
final int row,
|
||||
final int column
|
||||
) {
|
||||
return new Text((String) value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class DeleteCellRenderer
|
||||
extends LockableImpl
|
||||
implements TableCellRenderer {
|
||||
|
||||
@Override
|
||||
public Component getComponent(
|
||||
final Table table,
|
||||
final PageState state,
|
||||
final Object value,
|
||||
final boolean isSelected,
|
||||
final Object key,
|
||||
final int row,
|
||||
final int col
|
||||
) {
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final PermissionChecker permissionChecker = cdiUtil.findBean(
|
||||
PermissionChecker.class
|
||||
);
|
||||
|
||||
final InternetArticleItem articleItem
|
||||
= (InternetArticleItem) itemModel
|
||||
.getSelectedObject(state);
|
||||
final boolean canEdit = permissionChecker
|
||||
.isPermitted(ItemPrivileges.EDIT, articleItem);
|
||||
|
||||
if (canEdit) {
|
||||
final ControlLink link = new ControlLink((Component) value);
|
||||
link.setConfirmation(
|
||||
new GlobalizedMessage(
|
||||
"publications.ui.internetarticle.organization.remove.confirm",
|
||||
SciPublicationsConstants.BUNDLE
|
||||
)
|
||||
);
|
||||
return link;
|
||||
} else {
|
||||
return new Text("");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* 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 InternetArticleOrganizationStep extends SimpleEditStep {
|
||||
|
||||
private static final String SET_INTERNET_ARTICLE_ORGANIZATION_STEP
|
||||
= "setInternetArticleOrganizationStep";
|
||||
|
||||
public InternetArticleOrganizationStep(
|
||||
final ItemSelectionModel itemModel,
|
||||
final AuthoringKitWizard parent,
|
||||
final StringParameter selectedLangParam
|
||||
) {
|
||||
this(itemModel, parent, selectedLangParam, null);
|
||||
}
|
||||
|
||||
public InternetArticleOrganizationStep(
|
||||
final ItemSelectionModel itemModel,
|
||||
final AuthoringKitWizard parent,
|
||||
final StringParameter selectedLangParam,
|
||||
final String prefix
|
||||
) {
|
||||
super(itemModel, parent, selectedLangParam, prefix);
|
||||
|
||||
final BasicItemForm setOrgaForm = new InternetArticleOrganizationForm(
|
||||
itemModel, selectedLangParam
|
||||
);
|
||||
add(
|
||||
SET_INTERNET_ARTICLE_ORGANIZATION_STEP,
|
||||
new GlobalizedMessage(
|
||||
"publications.ui.internetarticle.setOrganization",
|
||||
SciPublicationsConstants.BUNDLE
|
||||
),
|
||||
new WorkflowLockedComponentAccess(setOrgaForm, itemModel),
|
||||
setOrgaForm.getSaveCancelSection().getCancelButton());
|
||||
|
||||
final InternetArticleOrganizationSheet sheet
|
||||
= new InternetArticleOrganizationSheet(
|
||||
itemModel);
|
||||
setDisplayComponent(sheet);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,180 @@
|
|||
/*
|
||||
* 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.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.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 InternetArticlePropertiesStep extends PublicationPropertiesStep {
|
||||
|
||||
private final StringParameter selectedLangParam;
|
||||
|
||||
public InternetArticlePropertiesStep(
|
||||
final ItemSelectionModel itemModel,
|
||||
final AuthoringKitWizard parent,
|
||||
final StringParameter selectedLangParam
|
||||
) {
|
||||
super(itemModel, parent, selectedLangParam);
|
||||
this.selectedLangParam = selectedLangParam;
|
||||
}
|
||||
|
||||
public static Component getInternetArticlePropertySheet(
|
||||
final ItemSelectionModel itemModel,
|
||||
final StringParameter selectedLangParam
|
||||
) {
|
||||
final DomainObjectPropertySheet sheet
|
||||
= (DomainObjectPropertySheet) PublicationPropertiesStep
|
||||
.getPublicationPropertySheet(itemModel, selectedLangParam);
|
||||
|
||||
sheet.add(
|
||||
new GlobalizedMessage(
|
||||
"publications.ui.internetarticle.place",
|
||||
SciPublicationsConstants.BUNDLE
|
||||
),
|
||||
InternetArticleController.PLACE
|
||||
);
|
||||
|
||||
sheet.add(
|
||||
new GlobalizedMessage(
|
||||
"publications.ui.internetarticle.number",
|
||||
SciPublicationsConstants.BUNDLE
|
||||
),
|
||||
InternetArticleController.NUMBER
|
||||
);
|
||||
|
||||
sheet.add(
|
||||
new GlobalizedMessage(
|
||||
"publications.ui.internetarticle.number_of_pages",
|
||||
SciPublicationsConstants.BUNDLE
|
||||
),
|
||||
InternetArticleController.NUMBER_OF_PAGES
|
||||
);
|
||||
|
||||
sheet.add(
|
||||
new GlobalizedMessage(
|
||||
"publications.ui.internetarticle.edition",
|
||||
SciPublicationsConstants.BUNDLE
|
||||
),
|
||||
InternetArticleController.EDITION
|
||||
);
|
||||
|
||||
sheet.add(
|
||||
new GlobalizedMessage(
|
||||
"publications.ui.internetarticle.issn",
|
||||
SciPublicationsConstants.BUNDLE
|
||||
),
|
||||
InternetArticleController.ISSN
|
||||
);
|
||||
|
||||
sheet.add(
|
||||
new GlobalizedMessage(
|
||||
"publications.ui.internetarticle.lastAccessed",
|
||||
SciPublicationsConstants.BUNDLE
|
||||
),
|
||||
InternetArticleController.LAST_ACCESSED
|
||||
);
|
||||
|
||||
sheet.add(
|
||||
new GlobalizedMessage(
|
||||
"publications.ui.internetarticle.url",
|
||||
SciPublicationsConstants.BUNDLE
|
||||
),
|
||||
InternetArticleController.URL
|
||||
);
|
||||
|
||||
sheet.add(
|
||||
new GlobalizedMessage(
|
||||
"publications.ui.internetarticle.urn",
|
||||
SciPublicationsConstants.BUNDLE
|
||||
),
|
||||
InternetArticleController.URN
|
||||
);
|
||||
|
||||
sheet.add(
|
||||
new GlobalizedMessage(
|
||||
"publications.ui.internetarticle.doi",
|
||||
SciPublicationsConstants.BUNDLE
|
||||
),
|
||||
InternetArticleController.DOI
|
||||
);
|
||||
|
||||
return sheet;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addBasicProperties(
|
||||
final ItemSelectionModel itemModel, final AuthoringKitWizard parent
|
||||
) {
|
||||
final SimpleEditStep basicProperties = new SimpleEditStep(
|
||||
itemModel,
|
||||
parent,
|
||||
selectedLangParam,
|
||||
EDIT_SHEET_NAME
|
||||
);
|
||||
|
||||
final BasicPageForm editBasicSheet
|
||||
= new InternetArticlePropertyForm(
|
||||
itemModel,
|
||||
this,
|
||||
selectedLangParam
|
||||
);
|
||||
|
||||
basicProperties.add(
|
||||
EDIT_SHEET_NAME,
|
||||
new GlobalizedMessage(
|
||||
"publications.ui.internetarticle.edit_basic_sheet",
|
||||
SciPublicationsConstants.BUNDLE
|
||||
),
|
||||
new WorkflowLockedComponentAccess(editBasicSheet, itemModel),
|
||||
editBasicSheet.getSaveCancelSection().getCancelButton()
|
||||
);
|
||||
|
||||
basicProperties.setDisplayComponent(
|
||||
getInternetArticlePropertySheet(itemModel, selectedLangParam));
|
||||
|
||||
getSegmentedPanel().addSegment(
|
||||
new Label(
|
||||
new GlobalizedMessage(
|
||||
"publications.ui.publication.basic_properties",
|
||||
SciPublicationsConstants.BUNDLE
|
||||
)
|
||||
),
|
||||
basicProperties
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addSteps(
|
||||
final ItemSelectionModel itemModel, final AuthoringKitWizard parent
|
||||
) {
|
||||
super.addSteps(itemModel, parent);
|
||||
|
||||
addStep(
|
||||
new InternetArticleOrganizationStep(
|
||||
itemModel, parent, selectedLangParam
|
||||
),
|
||||
new GlobalizedMessage(
|
||||
"publications.ui.internetarticle.setOrganization",
|
||||
SciPublicationsConstants.BUNDLE
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,318 @@
|
|||
/*
|
||||
* 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.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.event.ParameterEvent;
|
||||
import com.arsdigita.bebop.event.ParameterListener;
|
||||
import com.arsdigita.bebop.form.TextField;
|
||||
import com.arsdigita.bebop.parameters.DateParameter;
|
||||
import com.arsdigita.bebop.parameters.IntegerParameter;
|
||||
import com.arsdigita.bebop.parameters.ParameterData;
|
||||
import com.arsdigita.bebop.parameters.ParameterModel;
|
||||
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.InternetArticle;
|
||||
import org.scientificcms.publications.SciPublicationsConstants;
|
||||
import org.scientificcms.publications.contenttypes.InternetArticleItem;
|
||||
|
||||
import java.time.ZoneId;
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class InternetArticlePropertyForm
|
||||
extends PublicationPropertyForm
|
||||
implements FormInitListener, FormProcessListener, FormSubmissionListener {
|
||||
|
||||
public static final String ID = "InternetArticleEdit";
|
||||
|
||||
private final InternetArticlePropertiesStep step;
|
||||
|
||||
private final StringParameter selectedLangParam;
|
||||
|
||||
public InternetArticlePropertyForm(
|
||||
final ItemSelectionModel itemModel,
|
||||
final StringParameter selectedLangParam
|
||||
) {
|
||||
this(itemModel, null, selectedLangParam);
|
||||
}
|
||||
|
||||
public InternetArticlePropertyForm(
|
||||
final ItemSelectionModel itemModel,
|
||||
final InternetArticlePropertiesStep step,
|
||||
final StringParameter selectedLangParam
|
||||
) {
|
||||
super(itemModel, step, selectedLangParam);
|
||||
this.step = step;
|
||||
this.selectedLangParam = selectedLangParam;
|
||||
addSubmissionListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addWidgets() {
|
||||
super.addWidgets();
|
||||
|
||||
final ParameterModel placeParam = new StringParameter(
|
||||
InternetArticleController.PLACE
|
||||
);
|
||||
final TextField place = new TextField(placeParam);
|
||||
place.setLabel(
|
||||
new GlobalizedMessage(
|
||||
"publications.ui.internetarticle.place",
|
||||
SciPublicationsConstants.BUNDLE
|
||||
)
|
||||
);
|
||||
add(place);
|
||||
|
||||
final ParameterModel numberParam = new StringParameter(
|
||||
InternetArticleController.NUMBER
|
||||
);
|
||||
final TextField number = new TextField(numberParam);
|
||||
number.setLabel(
|
||||
new GlobalizedMessage(
|
||||
"publications.ui.internetarticle.number",
|
||||
SciPublicationsConstants.BUNDLE
|
||||
)
|
||||
);
|
||||
add(number);
|
||||
|
||||
final ParameterModel numberOfPagesParam = new IntegerParameter(
|
||||
InternetArticleController.NUMBER_OF_PAGES
|
||||
);
|
||||
final TextField numberOfPages = new TextField(numberOfPagesParam);
|
||||
numberOfPages.setLabel(
|
||||
new GlobalizedMessage(
|
||||
"publications.ui.internetarticle.number_of_pages",
|
||||
SciPublicationsConstants.BUNDLE
|
||||
)
|
||||
);
|
||||
add(numberOfPages);
|
||||
|
||||
final ParameterModel editionParam = new StringParameter(
|
||||
InternetArticleController.EDITION
|
||||
);
|
||||
final TextField edition = new TextField(editionParam);
|
||||
edition.setLabel(
|
||||
new GlobalizedMessage(
|
||||
"publications.ui.internetarticle.edition",
|
||||
SciPublicationsConstants.BUNDLE
|
||||
)
|
||||
);
|
||||
add(edition);
|
||||
|
||||
final ParameterModel issnParam = new StringParameter(
|
||||
InternetArticleController.ISSN
|
||||
);
|
||||
final TextField issn = new TextField(issnParam);
|
||||
issn.setLabel(
|
||||
new GlobalizedMessage(
|
||||
"publications.ui.internetarticle.issn",
|
||||
SciPublicationsConstants.BUNDLE
|
||||
)
|
||||
);
|
||||
issn.setMaxLength(9);
|
||||
issn.addValidationListener(new ParameterListener() {
|
||||
|
||||
@Override
|
||||
public void validate(final ParameterEvent event)
|
||||
throws FormProcessException {
|
||||
final ParameterData data = event.getParameterData();
|
||||
String value = (String) data.getValue();
|
||||
|
||||
if (value.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
value = value.replace("-", "");
|
||||
|
||||
if (value.length() != 8) {
|
||||
data.invalidate();
|
||||
data.addError(new GlobalizedMessage(
|
||||
"publications.ui.invalid_issn"));
|
||||
}
|
||||
|
||||
try {
|
||||
Long num = Long.parseLong(value);
|
||||
} catch (NumberFormatException ex) {
|
||||
data.invalidate();
|
||||
data.addError(new GlobalizedMessage(
|
||||
"publications.ui.invalid_issn"));
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
add(issn);
|
||||
|
||||
final Calendar today = new GregorianCalendar();
|
||||
final ParameterModel pubDateParam = new DateParameter(
|
||||
InternetArticleController.LAST_ACCESSED
|
||||
);
|
||||
final com.arsdigita.bebop.form.Date pubDate
|
||||
= new com.arsdigita.bebop.form.Date(
|
||||
pubDateParam
|
||||
);
|
||||
pubDate.setYearRange(1900, today.get(Calendar.YEAR) + 2);
|
||||
pubDate.setLabel(
|
||||
new GlobalizedMessage(
|
||||
"publications.ui.internetarticle.lastAccessed",
|
||||
SciPublicationsConstants.BUNDLE
|
||||
)
|
||||
);
|
||||
add(pubDate);
|
||||
|
||||
ParameterModel urlModel = new StringParameter(
|
||||
InternetArticleController.URL
|
||||
);
|
||||
TextField url = new TextField(urlModel);
|
||||
url.setLabel(new GlobalizedMessage(
|
||||
"publications.ui.internetarticle.url"));
|
||||
add(url);
|
||||
|
||||
final ParameterModel urnModel = new StringParameter(
|
||||
InternetArticleController.URN
|
||||
);
|
||||
final TextField urn = new TextField(urnModel);
|
||||
urn.setLabel(
|
||||
new GlobalizedMessage(
|
||||
"publications.ui.internetarticle.urn",
|
||||
SciPublicationsConstants.BUNDLE
|
||||
)
|
||||
);
|
||||
add(urn);
|
||||
|
||||
final ParameterModel doiModel = new StringParameter(
|
||||
InternetArticleController.DOI
|
||||
);
|
||||
final TextField doi = new TextField(doiModel);
|
||||
doi.setLabel(
|
||||
new GlobalizedMessage(
|
||||
"publications.ui.internetarticle.doi",
|
||||
SciPublicationsConstants.BUNDLE
|
||||
)
|
||||
);
|
||||
add(doi);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(final FormSectionEvent event) throws FormProcessException {
|
||||
super.init(event);
|
||||
|
||||
final FormData data = event.getFormData();
|
||||
final InternetArticleItem articleItem
|
||||
= (InternetArticleItem) initBasicWidgets(
|
||||
event);
|
||||
final InternetArticle article = articleItem.getPublication();
|
||||
|
||||
data.put(InternetArticleController.PLACE, article.getPlace());
|
||||
data.put(InternetArticleController.NUMBER, article.getNumber());
|
||||
data.put(InternetArticleController.NUMBER_OF_PAGES, article
|
||||
.getNumberOfPages());
|
||||
data.put(InternetArticleController.EDITION, article.getEdition());
|
||||
data.put(InternetArticleController.ISSN, article.getIssn());
|
||||
data.put(
|
||||
InternetArticleController.LAST_ACCESSED,
|
||||
java.util.Date.from(
|
||||
article.getLastAccessed().atStartOfDay().atZone(
|
||||
ZoneId.systemDefault()
|
||||
).toInstant()
|
||||
)
|
||||
);
|
||||
data.put(InternetArticleController.URL, article.getUrl());
|
||||
data.put(InternetArticleController.URN, article.getUrn());
|
||||
data.put(InternetArticleController.DOI, article.getDoi());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(final FormSectionEvent event)
|
||||
throws FormProcessException {
|
||||
super.process(event);
|
||||
|
||||
final FormData formData = event.getFormData();
|
||||
final PageState state = event.getPageState();
|
||||
|
||||
final InternetArticleItem articleItem
|
||||
= (InternetArticleItem) processBasicWidgets(
|
||||
event);
|
||||
|
||||
if ((articleItem != null)
|
||||
&& getSaveCancelSection().getSaveButton().isSelected(state)) {
|
||||
final Map<String, Object> data = new HashMap<>();
|
||||
|
||||
data.put(
|
||||
InternetArticleController.PLACE,
|
||||
formData.get(InternetArticleController.PLACE
|
||||
)
|
||||
);
|
||||
data.put(
|
||||
InternetArticleController.NUMBER,
|
||||
formData.get(InternetArticleController.NUMBER
|
||||
)
|
||||
);
|
||||
data.put(
|
||||
InternetArticleController.NUMBER_OF_PAGES,
|
||||
formData.get(InternetArticleController.NUMBER_OF_PAGES
|
||||
)
|
||||
);
|
||||
data.put(
|
||||
InternetArticleController.EDITION,
|
||||
formData.get(InternetArticleController.EDITION
|
||||
)
|
||||
);
|
||||
data.put(
|
||||
InternetArticleController.ISSN,
|
||||
formData.get(InternetArticleController.ISSN
|
||||
)
|
||||
);
|
||||
final java.util.Date lastAccessed = (java.util.Date) formData.get(
|
||||
InternetArticleController.LAST_ACCESSED
|
||||
);
|
||||
data.put(
|
||||
InternetArticleController.LAST_ACCESSED,
|
||||
lastAccessed.toInstant().atZone(
|
||||
ZoneId.systemDefault()
|
||||
).toLocalDate()
|
||||
);
|
||||
data.put(
|
||||
InternetArticleController.URL,
|
||||
formData.get(InternetArticleController.URL
|
||||
)
|
||||
);
|
||||
data.put(
|
||||
InternetArticleController.URN,
|
||||
formData.get(InternetArticleController.URN
|
||||
)
|
||||
);
|
||||
data.put(
|
||||
InternetArticleController.DOI,
|
||||
formData.get(InternetArticleController.DOI
|
||||
)
|
||||
);
|
||||
|
||||
final InternetArticleController controller = CdiUtil
|
||||
.createCdiUtil()
|
||||
.findBean(InternetArticleController.class);
|
||||
controller.saveInternetArticle(
|
||||
articleItem.getPublication().getPublicationId(), data
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue