Steps and forms for managing the sponsors of a SciProject

pull/1/head
Jens Pelzetter 2019-08-13 19:19:10 +02:00
parent afb642498e
commit 9e3dfc8265
10 changed files with 950 additions and 27 deletions

View File

@ -21,7 +21,6 @@ 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.dispatcher.DispatcherHelper;
import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.util.LockableImpl;
@ -149,10 +148,10 @@ public class SciProjectContactsTable
controller.removeContact(selected.getObjectId(),
contact.getContactId());
} else if(TABLE_COL_UP.equals(column.getHeaderKey())) {
controller.swapWithPrevious(selected.getObjectId(),
controller.swapWithPreviousContact(selected.getObjectId(),
contact.getContactId());
} else if(TABLE_COL_DOWN.equals(column.getHeaderKey())) {
controller.swapWithNext(selected.getObjectId(),
controller.swapWithNextContact(selected.getObjectId(),
contact.getContactId());
}
}
@ -362,6 +361,7 @@ public class SciProjectContactsTable
extends LockableImpl
implements TableCellRenderer {
@Override
public Component getComponent(
Table table,
PageState state,

View File

@ -9,11 +9,14 @@ import org.libreccm.configuration.ConfigurationManager;
import org.libreccm.l10n.LocalizedString;
import org.librecms.assets.ContactableEntity;
import org.librecms.assets.ContactableEntityRepository;
import org.librecms.assets.Organization;
import org.librecms.contentsection.AssetRepository;
import org.scientificcms.contenttypes.sciproject.Contact;
import org.scientificcms.contenttypes.sciproject.SciProject;
import org.scientificcms.contenttypes.sciproject.SciProjectConfig;
import org.scientificcms.contenttypes.sciproject.SciProjectMananger;
import org.scientificcms.contenttypes.sciproject.SciProjectRepository;
import org.scientificcms.contenttypes.sciproject.Sponsoring;
import java.time.LocalDate;
import java.util.Date;
@ -37,8 +40,19 @@ import javax.transaction.Transactional;
class SciProjectController {
public static final String CONTACT_NAME = "name";
public static final String CONTACT_TYPE = "contactType";
public static final String CONTACT_ID = "contactId";
public static final String SPONSOR_ID = "sponsorId";
public static final String SPONSOR_NAME = "name";
public static final String SPONSOR_FUNDING_CODE = "fundingCode";
@Inject
private AssetRepository assetRepository;
@Inject
private ConfigurationManager confManager;
@ -190,7 +204,8 @@ class SciProjectController {
}
@Transactional(Transactional.TxType.REQUIRED)
public void swapWithPrevious(final long projectId, final long contactId) {
public void swapWithPreviousContact(final long projectId,
final long contactId) {
final SciProject project = projectRepository
.findById(projectId, SciProject.class)
@ -216,16 +231,17 @@ class SciProjectController {
final long order = contact.getOrder();
final Contact prevContact = contacts.get(index - 1);
final long prevOrder = prevContact.getOrder();
contact.setOrder(prevOrder);
prevContact.setOrder(order);
projectRepository.save(project);
}
}
@Transactional(Transactional.TxType.REQUIRED)
public void swapWithNext(final long projectId, final long contactId) {
public void swapWithNextContact(final long projectId,
final long contactId) {
final SciProject project = projectRepository
.findById(projectId, SciProject.class)
@ -251,10 +267,10 @@ class SciProjectController {
final long order = contact.getOrder();
final Contact nextContact = contacts.get(index + 1);
final long nextOrder = nextContact.getOrder();
contact.setOrder(nextOrder);
nextContact.setOrder(order);
projectRepository.save(project);
}
}
@ -282,12 +298,12 @@ class SciProjectController {
.stream()
.anyMatch(current -> filterContact(current, project, contactable));
}
@Transactional(Transactional.TxType.REQUIRED)
public void updateDescription(final long projectId,
final String descriptionText,
final Locale language) {
final SciProject project = projectRepository
.findById(projectId, SciProject.class)
.orElseThrow(
@ -297,12 +313,226 @@ class SciProjectController {
);
final LocalizedString desc = project.getDescription();
desc.addValue(Objects.requireNonNull(language),
desc.addValue(Objects.requireNonNull(language),
descriptionText);
projectRepository.save(project);
}
@Transactional(Transactional.TxType.REQUIRED)
public Optional<Sponsoring> findSponsoring(final long projectId,
final Object key) {
final SciProject project = projectRepository
.findById(projectId, SciProject.class)
.orElseThrow(
() -> new IllegalArgumentException(
String.format("No SciProject with ID %d found.",
projectId))
);
final long sponsoringId = (long) key;
return project
.getSponsoring()
.stream()
.filter(sponsoring -> sponsoring.getSponsoringId() == sponsoringId)
.findAny();
}
@Transactional(Transactional.TxType.REQUIRED)
public List<Map<String, Object>> getSponsors(final long forProjectId) {
final SciProject project = projectRepository
.findById(forProjectId, SciProject.class)
.orElseThrow(
() -> new IllegalArgumentException(
String.format("No SciProject with ID %d found.",
forProjectId))
);
return project
.getSponsoring()
.stream()
.map(this::buildSponsorEntry)
.collect(Collectors.toList());
}
private Map<String, Object> buildSponsorEntry(final Sponsoring sponsoring) {
Objects.requireNonNull(sponsoring);
final Map<String, Object> result = new HashMap<>();
result.put(SPONSOR_ID, sponsoring.getSponsoringId());
result.put(SPONSOR_NAME, sponsoring.getSponsor().getName());
result.put(SPONSOR_FUNDING_CODE, sponsoring.getFundingCode());
return result;
}
@Transactional(Transactional.TxType.REQUIRED)
public void addSponsor(final long projectId,
final long sponsorId,
final String withFundingCode) {
final SciProject project = projectRepository
.findById(projectId, SciProject.class)
.orElseThrow(
() -> new IllegalArgumentException(
String.format("No SciProject with ID %d found.",
projectId))
);
final Organization sponsor = assetRepository
.findById(sponsorId, Organization.class)
.orElseThrow(() -> new IllegalArgumentException(
String.format("No Organization with ID %d found.", sponsorId)));
projectMananger.addSponsor(sponsor, project, withFundingCode);
}
public void removeSponsor(final long projectId, final long sponsoringId) {
final SciProject project = projectRepository
.findById(projectId, SciProject.class)
.orElseThrow(
() -> new IllegalArgumentException(
String.format("No SciProject with ID %d found.",
projectId))
);
final Optional<Sponsoring> sponsoring = project
.getSponsoring()
.stream()
.filter(current -> current.getSponsoringId() == sponsoringId)
.findAny();
if (sponsoring.isPresent()) {
projectMananger.removeSponsor(sponsoring.get().getSponsor(),
project);
}
}
public boolean hasSponsor(final long projectId, final long sponsorId) {
final SciProject project = projectRepository
.findById(projectId, SciProject.class)
.orElseThrow(
() -> new IllegalArgumentException(
String.format("No SciProject with ID %d found.",
projectId))
);
final Organization sponsor = assetRepository
.findById(sponsorId, Organization.class)
.orElseThrow(() -> new IllegalArgumentException(
String.format("No Organization with ID %d found.", sponsorId)));
return project
.getSponsoring()
.stream()
.anyMatch(sponsoring -> sponsoring.getSponsor().equals(sponsor));
}
@Transactional(Transactional.TxType.REQUIRED)
public void updateFundingCode(final long projectId,
final long sponsorId,
final String fundingCode) {
final SciProject project = projectRepository
.findById(projectId, SciProject.class)
.orElseThrow(
() -> new IllegalArgumentException(
String.format("No SciProject with ID %d found.",
projectId))
);
final Optional<Sponsoring> result = project
.getSponsoring()
.stream()
.filter(
sponsoring -> sponsoring.getSponsor().getObjectId() == sponsorId
)
.findAny();
if (result.isPresent()) {
final Sponsoring sponsoring = result.get();
sponsoring.setFundingCode(fundingCode);
projectRepository.save(project);
}
}
@Transactional(Transactional.TxType.REQUIRED)
public void swapWithPrevSponsoring(final long projectId,
final long sponsoringId) {
final SciProject project = projectRepository
.findById(projectId, SciProject.class)
.orElseThrow(
() -> new IllegalArgumentException(
String.format("No SciProject with ID %d found.",
projectId))
);
final List<Sponsoring> sponsoringList = project.getSponsoring();
Sponsoring sponsoring = null;
int index = -1;
for (int i = 0; i < sponsoringList.size(); i++) {
if (sponsoringList.get(i).getSponsoringId() == sponsoringId) {
sponsoring = sponsoringList.get(i);
index = i;
break;
}
}
if (index > 0 && sponsoring != null) {
final long order = sponsoring.getOrder();
final Sponsoring prevSponsoring = sponsoringList.get(index - 1);
final long prevOrder = prevSponsoring.getOrder();
sponsoring.setOrder(prevOrder);
prevSponsoring.setOrder(order);
projectRepository.save(project);
}
}
@Transactional(Transactional.TxType.REQUIRED)
public void swapWithNextSponsoring(final long projectId,
final long sponsoringId) {
final SciProject project = projectRepository
.findById(projectId, SciProject.class)
.orElseThrow(
() -> new IllegalArgumentException(
String.format("No SciProject with ID %d found.",
projectId))
);
final List<Sponsoring> sponsoringList = project.getSponsoring();
Sponsoring sponsoring = null;
int index = -1;
for (int i = 0; i < sponsoringList.size(); i++) {
if (sponsoringList.get(i).getSponsoringId() == sponsoringId) {
sponsoring = sponsoringList.get(i);
index = i;
break;
}
}
if (index > 0 && sponsoring != null) {
final long order = sponsoring.getOrder();
final Sponsoring nextSponsoring = sponsoringList.get(index + 1);
final long nextOrder = nextSponsoring.getOrder();
sponsoring.setOrder(nextOrder);
nextSponsoring.setOrder(order);
projectRepository.save(project);
}
}
@Transactional(Transactional.TxType.REQUIRED)
public void save(final long projectId,
final Locale selectedLocale,

View File

@ -23,6 +23,7 @@ import org.scientificcms.contenttypes.sciproject.SciProjectConstants;
public class SciProjectDescriptionStep extends SimpleEditStep {
private final SegmentedPanel segmentedPanel;
private final StringParameter selectedLanguageParam;
public SciProjectDescriptionStep(
@ -56,7 +57,9 @@ public class SciProjectDescriptionStep extends SimpleEditStep {
final SciProjectConfig config = SciProjectConfig.getConfig();
if (config.isEnableSponsor()) {
addStep(new SciProjectSponsorStep(itemModel, parent),
addStep(new SciProjectSponsorsStep(itemModel,
parent,
selectedLanguageParam),
"sciproject.ui.steps.sponsor.title");
}

View File

@ -0,0 +1,214 @@
/*
* 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.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.TextField;
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.cms.ui.authoring.SelectedLanguageUtil;
import com.arsdigita.cms.ui.authoring.SimpleEditStep;
import com.arsdigita.globalization.GlobalizedMessage;
import org.libreccm.cdi.utils.CdiUtil;
import org.librecms.assets.Organization;
import org.scientificcms.contenttypes.sciproject.SciProject;
import org.scientificcms.contenttypes.sciproject.SciProjectConstants;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class SciProjectSponsorForm
extends BasicItemForm
implements FormInitListener, FormProcessListener, FormSubmissionListener {
private final SimpleEditStep editStep;
private AssetSearchWidget itemSearch;
private TextField fundingCode;
private Text selectedSponsorLabel;
private StringParameter selectedLanguageParam;
public SciProjectSponsorForm(final ItemSelectionModel itemModel,
final SimpleEditStep editStep,
final StringParameter selectedLanguageParam) {
super("SciProjectSetSponsor", itemModel, selectedLanguageParam);
this.editStep = editStep;
addSubmissionListener(this);
}
@Override
public void addWidgets() {
itemSearch = new AssetSearchWidget(
SciProjectUiConstants.SPONSOR_SEARCH,
Organization.class);
itemSearch.setLabel(new GlobalizedMessage(
"sciproject.ui.sponsor", SciProjectConstants.SCI_PROJECT_BUNDLE));
add(itemSearch);
selectedSponsorLabel = new Text();
add(selectedSponsorLabel);
fundingCode = new TextField(SciProjectUiConstants.FUNDING_CODE);
fundingCode.setLabel(new GlobalizedMessage(
"sciproject.ui.sponsor_fundingcode",
SciProjectConstants.SCI_PROJECT_BUNDLE));
add(fundingCode);
}
@Override
public void init(final FormSectionEvent event) throws FormProcessException {
final FormData data = event.getFormData();
final PageState state = event.getPageState();
final Organization sponsor = ((SciProjectSponsorsStep) editStep).
getSelectedSponsor();
final String sponsorFundingCode = ((SciProjectSponsorsStep) editStep).
getSelectedSponsorFundingCode();
if (sponsor == null) {
itemSearch.setVisible(state, true);
selectedSponsorLabel.setVisible(state, false);
} else {
data.put(SciProjectUiConstants.SPONSOR_SEARCH, sponsor);
if ((sponsorFundingCode == null) || sponsorFundingCode.isEmpty()) {
fundingCode.setValue(state, null);
} else {
fundingCode.setValue(state, sponsorFundingCode);
}
itemSearch.setVisible(state, false);
selectedSponsorLabel
.setText(
sponsor.getTitle().getValue(
SelectedLanguageUtil.selectedLocale(
state, selectedLanguageParam)
)
);
selectedSponsorLabel.setVisible(state, true);
}
setVisible(state, true);
}
@Override
public void process(final FormSectionEvent event)
throws FormProcessException {
final FormData data = event.getFormData();
final PageState state = event.getPageState();
final SciProject project = (SciProject) getItemSelectionModel()
.getSelectedObject(state);
if (getSaveCancelSection().getSaveButton().isSelected(state)) {
final Organization sponsor = ((SciProjectSponsorsStep) editStep).
getSelectedSponsor();
String sponsorFundingCode;
if (fundingCode.getValue(state) == null) {
sponsorFundingCode = null;
} else {
sponsorFundingCode = (String) fundingCode.getValue(state);
}
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final SciProjectController controller = cdiUtil
.findBean(SciProjectController.class);
if (sponsor == null) {
final Organization sponsorToAdd = (Organization) data
.get(SciProjectUiConstants.SPONSOR_SEARCH);
if ((sponsorFundingCode == null) || sponsorFundingCode.isEmpty()) {
controller.addSponsor(project.getObjectId(),
sponsorToAdd.getObjectId(),
"");
} else {
controller.addSponsor(project.getObjectId(),
sponsorToAdd.getObjectId(),
sponsorFundingCode);
}
} else {
controller.updateFundingCode(project.getObjectId(),
sponsor.getObjectId(),
sponsorFundingCode);
}
}
init(event);
}
@Override
public void submitted(final FormSectionEvent event)
throws FormProcessException {
if (getSaveCancelSection()
.getCancelButton()
.isSelected(event.getPageState())) {
((SciProjectSponsorsStep) editStep).setSelectedSponsor(null);
((SciProjectSponsorsStep) editStep)
.setSelectedSponsorFundingCode(null);
init(event);
}
}
@Override
public void validate(final FormSectionEvent event)
throws FormProcessException {
final PageState state = event.getPageState();
final FormData data = event.getFormData();
boolean editing = false; //Are we editing the association?
if ((((SciProjectSponsorsStep) editStep).getSelectedSponsor() == null)
&& (data.get(SciProjectUiConstants.SPONSOR_SEARCH) == null)) {
data.addError(new GlobalizedMessage(
"sciproject.ui.sponsor_no_sponsor_selected",
SciProjectConstants.SCI_PROJECT_BUNDLE));
return;
}
final SciProject project = (SciProject) getItemSelectionModel()
.getSelectedObject(state);
Organization sponsor = (Organization) data
.get(SciProjectUiConstants.SPONSOR_SEARCH);
if (sponsor == null) {
sponsor = ((SciProjectSponsorsStep) editStep).getSelectedSponsor();
editing = true;
}
if (!editing) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final SciProjectController controller = cdiUtil
.findBean(SciProjectController.class);
if (controller.hasSponsor(project.getObjectId(),
sponsor.getObjectId())) {
data.addError(new GlobalizedMessage(
"sciproject.ui.sponsor.already_added",
SciProjectConstants.SCI_PROJECT_BUNDLE));
}
}
}
}

View File

@ -0,0 +1,395 @@
/*
* 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.FormProcessException;
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.ui.authoring.SimpleEditStep;
import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.util.LockableImpl;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.security.PermissionChecker;
import org.librecms.contentsection.privileges.ItemPrivileges;
import org.scientificcms.contenttypes.sciproject.Contact;
import org.scientificcms.contenttypes.sciproject.SciProject;
import org.scientificcms.contenttypes.sciproject.SciProjectConstants;
import org.scientificcms.contenttypes.sciproject.Sponsoring;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class SciProjectSponsorSheet
extends Table implements TableActionListener {
private final String TABLE_COL_EDIT = "table_col_edit";
private final String TABLE_COL_EDIT_ASSOC = "table_col_edit_assoc";
private final String TABLE_COL_DEL = "table_col_del";
private final String TABLE_COL_UP = "table_col_up";
private final String TABLE_COL_DOWN = "table_col_down";
private final String SELECTED_PROJECT
= "selected_project_sponsor_association_project";
private final String SELECTED_SPONSOR
= "selected_project_sponsor_association_sponsor";
private final ItemSelectionModel itemModel;
private final SciProjectSponsorsStep editStep;
public SciProjectSponsorSheet(final ItemSelectionModel itemModel,
final SciProjectSponsorsStep editStep) {
super();
this.itemModel = itemModel;
this.editStep = editStep;
setEmptyView(new Label(new GlobalizedMessage(
"sciproject.ui.sponsor_none",
SciProjectConstants.SCI_PROJECT_BUNDLE)));
final TableColumnModel columnModel = getColumnModel();
columnModel.add(new TableColumn(
0,
new GlobalizedMessage("sciproject.ui.sponsor_name",
SciProjectConstants.SCI_PROJECT_BUNDLE),
TABLE_COL_EDIT));
columnModel.add(new TableColumn(
1,
new GlobalizedMessage("sciproject.ui.sponsor_fundingcode",
SciProjectConstants.SCI_PROJECT_BUNDLE)));
columnModel.add(new TableColumn(
2,
new GlobalizedMessage("sciproject.ui.sponsor_edit_assoc",
SciProjectConstants.SCI_PROJECT_BUNDLE),
TABLE_COL_EDIT_ASSOC));
columnModel.add(new TableColumn(
3,
new GlobalizedMessage("sciproject.ui.sponsor_remove",
SciProjectConstants.SCI_PROJECT_BUNDLE),
TABLE_COL_DEL));
columnModel.add(new TableColumn(
4,
new GlobalizedMessage(
"sciproject.ui.sponsor.up",
SciProjectConstants.SCI_PROJECT_BUNDLE),
TABLE_COL_UP));
columnModel.add(new TableColumn(
5,
new GlobalizedMessage(
"sciproject.ui.sponsor.down",
SciProjectConstants.SCI_PROJECT_BUNDLE),
TABLE_COL_DOWN));
setModelBuilder(new ModelBuilder(itemModel));
columnModel.get(0).setCellRenderer(new EditCellRenderer());
columnModel.get(2).setCellRenderer(new EditAssocCellRenderer());
columnModel.get(3).setCellRenderer(new DeleteCellRenderer());
columnModel.get(4).setCellRenderer(new UpCellRenderer());
columnModel.get(5).setCellRenderer(new DownCellRenderer());
addTableActionListener(this);
}
@Override
public void cellSelected(final TableActionEvent event) throws
FormProcessException {
final PageState state = event.getPageState();
final SciProject selected = (SciProject) itemModel
.getSelectedItem(state);
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final SciProjectController controller = cdiUtil
.findBean(SciProjectController.class);
final Sponsoring sponsoring = controller
.findSponsoring(selected.getObjectId(), event.getRowKey())
.get();
final TableColumn column = getColumnModel().get(event.getColumn());
if (TABLE_COL_EDIT_ASSOC.equals(column.getHeaderKey())) {
editStep.setSelectedSponsor(sponsoring.getSponsor());
editStep.setSelectedSponsorFundingCode(sponsoring.getFundingCode());
editStep.showComponent(state,
SciProjectUiConstants.ADD_CONTACT_SHEET_NAME);
} else if (TABLE_COL_DEL.equals(column.getHeaderKey())) {
controller.removeContact(selected.getObjectId(),
sponsoring.getSponsoringId());
} else if (TABLE_COL_UP.equals(column.getHeaderKey())) {
controller.swapWithPreviousContact(selected.getObjectId(),
sponsoring.getSponsoringId());
} else if (TABLE_COL_DOWN.equals(column.getHeaderKey())) {
controller.swapWithNextContact(selected.getObjectId(),
sponsoring.getSponsoringId());
}
}
@Override
public void headSelected(final TableActionEvent event) {
// Nothing
}
private class ModelBuilder
extends LockableImpl implements TableModelBuilder {
private final ItemSelectionModel itemModel;
public ModelBuilder(final ItemSelectionModel itemModel) {
this.itemModel = itemModel;
}
@Override
public TableModel makeModel(final Table table, final PageState state) {
table.getRowSelectionModel().clearSelection(state);
final SciProject project = (SciProject) itemModel
.getSelectedObject(state);
return new Model(table, state, project);
}
}
private class Model implements TableModel {
private final Table table;
private final Iterator<Map<String, Object>> sponsors;
private Map<String, Object> currentRow;
public Model(final Table table, final PageState state,
final SciProject project) {
this.table = table;
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final SciProjectController controller = cdiUtil
.findBean(SciProjectController.class);
sponsors = controller.getSponsors(project.getObjectId()).iterator();
}
@Override
public int getColumnCount() {
return table.getColumnModel().size();
}
@Override
public boolean nextRow() {
if (sponsors.hasNext()) {
currentRow = sponsors.next();
return true;
} else {
return false;
}
}
@Override
public Object getElementAt(final int columnIndex) {
switch (columnIndex) {
case 0:
return currentRow.get(SciProjectController.SPONSOR_NAME);
case 1:
return currentRow
.get(SciProjectController.SPONSOR_FUNDING_CODE);
case 2:
return new Label(new GlobalizedMessage(
"sciproject.ui.sponsor.edit_assoc",
SciProjectConstants.SCI_PROJECT_BUNDLE));
case 3:
return new Label(new GlobalizedMessage(
"sciproject.ui.sponsor.remove",
SciProjectConstants.SCI_PROJECT_BUNDLE));
default:
return null;
}
}
@Override
public Object getKeyAt(final int columnIndex) {
return currentRow.get(SciProjectController.SPONSOR_ID);
}
}
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) {
final SciProject selected = (SciProject) itemModel
.getSelectedItem(state);
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final SciProjectController controller = cdiUtil
.findBean(SciProjectController.class);
final Optional<Sponsoring> sponsoring = controller
.findSponsoring(selected.getObjectId(), key);
return new Text(sponsoring.get().getSponsor().getName());
}
}
private class EditAssocCellRenderer
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 SciProject selected = (SciProject) itemModel
.getSelectedItem(state);
final boolean canEdit = permissionChecker
.isPermitted(ItemPrivileges.EDIT, selected);
if (canEdit) {
return new ControlLink((Component) value);
} else {
return new Text("");
}
}
}
private class DeleteCellRenderer
extends LockableImpl
implements TableCellRenderer {
@Override
public Component getComponent(
Table table,
PageState state,
Object value,
boolean isSelected,
Object key,
int row,
int col) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final PermissionChecker permissionChecker = cdiUtil
.findBean(PermissionChecker.class);
final SciProject selected = (SciProject) itemModel
.getSelectedItem(state);
final boolean canEdit = permissionChecker
.isPermitted(ItemPrivileges.EDIT, selected);
if (canEdit) {
final ControlLink link = new ControlLink((Component) value);
link.setConfirmation(new GlobalizedMessage(
"cms.contenttypes.ui.sciproject.confirm_delete",
SciProjectConstants.SCI_PROJECT_BUNDLE
));
return link;
} else {
return new Text("");
}
}
}
private class UpCellRenderer extends LockableImpl implements
TableCellRenderer {
@Override
public Component getComponent(
Table table,
PageState state,
Object value,
boolean isSelected,
Object key,
int row,
int col) {
if (0 == row) {
return new Label();
} else {
ControlLink link = new ControlLink("up");
return link;
}
}
}
private class DownCellRenderer extends LockableImpl implements
TableCellRenderer {
@Override
public Component getComponent(
Table table,
PageState state,
Object value,
boolean isSelected,
Object key,
int row,
int col) {
final SciProject selected = (SciProject) itemModel
.getSelectedItem(state);
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final SciProjectController controller = cdiUtil
.findBean(SciProjectController.class);
final List<Map<String, Object>> contacts = controller
.getContacts(selected.getObjectId());
if ((contacts.size() - 1) == row) {
return new Label();
} else {
ControlLink link = new ControlLink("down");
return link;
}
}
}
}

View File

@ -20,26 +20,27 @@ import org.scientificcms.contenttypes.sciproject.SciProjectConstants;
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class SciProjectSponsorStep extends SimpleEditStep {
public class SciProjectSponsorsStep extends SimpleEditStep {
private Organization selectedSponsor;
private String selectedSponsorFundingCode;
public SciProjectSponsorStep(final ItemSelectionModel itemModel,
public SciProjectSponsorsStep(final ItemSelectionModel itemModel,
final AuthoringKitWizard parent,
final StringParameter selectedLanguageParam) {
this(itemModel, parent, selectedLanguageParam, null);
}
public SciProjectSponsorStep(final ItemSelectionModel itemModel,
public SciProjectSponsorsStep(final ItemSelectionModel itemModel,
final AuthoringKitWizard parent,
final StringParameter selectedLanguageParam,
final String prefix) {
super(itemModel, parent, selectedLanguageParam, prefix);
final BasicItemForm sponsorForm = new SciProjectSponsorForm(itemModel,
this);
final BasicItemForm sponsorForm = new SciProjectSponsorForm(
itemModel, this, selectedLanguageParam);
add(SciProjectUiConstants.SPONSOR_STEP,
new GlobalizedMessage("sciproject.ui.sponsor.add",
SciProjectConstants.SCI_PROJECT_BUNDLE),

View File

@ -21,8 +21,7 @@ public final class SciProjectUiConstants {
public static final String EDIT_DESC_TEXT_SHEET_NAME = "editProjectDescText";
public static final String UPLOAD_DESC_TEXT_SHEET_NAME
= "uploadProjectDescText";
public static final String FUNDING_CODE = "fundingCode";
public static final String END = "end";
@ -33,9 +32,14 @@ public final class SciProjectUiConstants {
public static final String PROJECT_DESCRIPTION = "description";
public static final String SPONSOR_STEP = "SciProjectSponsorStep";
public static final String SPONSOR_SEARCH = "setSponsor";
public static final String TITLE = "title";
public static final String UPLOAD_DESC_TEXT_SHEET_NAME
= "uploadProjectDescText";
private SciProjectUiConstants() {
// Nothing
}

View File

@ -12,6 +12,7 @@ import javax.persistence.Entity;
import org.hibernate.envers.Audited;
import org.libreccm.l10n.LocalizedString;
import org.librecms.assets.Organization;
import org.librecms.contentsection.ContentItem;
import org.librecms.contenttypes.AuthoringKit;
import org.librecms.contenttypes.AuthoringStep;
@ -151,6 +152,9 @@ public class SciProject extends ContentItem implements Serializable {
@OneToMany(mappedBy = "project", cascade = CascadeType.ALL)
private List<Membership> members;
@OneToMany(mappedBy = "project", cascade = CascadeType.ALL)
private List<Sponsoring> sponsoring;
public SciProject() {
super();
@ -245,6 +249,30 @@ public class SciProject extends ContentItem implements Serializable {
protected void setMembers(final List<Membership> members) {
this.members = new ArrayList<>(members);
}
public List<Sponsoring> getSponsoring() {
if (sponsoring == null) {
return null;
} else {
return Collections.unmodifiableList(sponsoring);
}
}
protected void addSponsor(final Sponsoring sponsor) {
sponsoring.add(sponsor);
}
protected void removeSponsor(final Sponsoring sponsor) {
sponsoring.remove(sponsor);
}
protected void setSponsoring(final List<Sponsoring> sponsoring) {
this.sponsoring = new ArrayList<>(sponsoring);
}
@Override
public int hashCode() {
@ -257,6 +285,7 @@ public class SciProject extends ContentItem implements Serializable {
hash = 53 * hash + Objects.hashCode(fundingVolume);
hash = 53 * hash + Objects.hashCode(contacts);
hash = 53 * hash + Objects.hashCode(members);
hash = 53 * hash + Objects.hashCode(sponsoring);
return hash;
}
@ -303,7 +332,10 @@ public class SciProject extends ContentItem implements Serializable {
if (!Objects.equals(contacts, other.getContacts())) {
return false;
}
return Objects.equals(members, other.getMembers());
if (!Objects.equals(members, other.getMembers())) {
return false;
}
return Objects.equals(sponsoring, other.getSponsoring());
}
@Override
@ -323,7 +355,8 @@ public class SciProject extends ContentItem implements Serializable {
+ "funding = %s, "
+ "fundingVolume = %s, "
+ "contacts = %s, "
+ "members = %s%s",
+ "members = %s,"
+ "sponsoring = %s%s",
Objects.toString(begin),
Objects.toString(end),
Objects.toString(shortDescription),
@ -332,6 +365,7 @@ public class SciProject extends ContentItem implements Serializable {
Objects.toString(fundingVolume),
Objects.toString(contacts),
Objects.toString(members),
Objects.toString(sponsoring),
data
));
}

View File

@ -6,6 +6,7 @@
package org.scientificcms.contenttypes.sciproject;
import org.librecms.assets.ContactableEntity;
import org.librecms.assets.Organization;
import org.librecms.assets.Person;
import java.io.Serializable;
@ -119,7 +120,7 @@ public class SciProjectMananger implements Serializable {
person,
fromProject))
.findFirst();
if (result.isPresent()) {
final Membership remove = result.get();
fromProject.removeMembership(remove);
@ -127,6 +128,47 @@ public class SciProjectMananger implements Serializable {
}
}
@Transactional(Transactional.TxType.REQUIRED)
public void addSponsor(final Organization sponsor,
final SciProject toProject,
final String withFundingCode) {
Objects.requireNonNull(sponsor, "Can't add null as sponsor.");
Objects.requireNonNull(toProject,
"Can't add a sponsor to project null.");
final Sponsoring sponsoring = new Sponsoring();
sponsoring.setFundingCode(withFundingCode);
sponsoring.setOrder(toProject.getSponsoring().size());
sponsoring.setProject(toProject);
sponsoring.setSponsor(sponsor);
toProject.addSponsor(sponsoring);
sciProjectRepository.save(toProject);
}
@Transactional(Transactional.TxType.REQUIRED)
public void removeSponsor(final Organization sponsor,
final SciProject fromProject) {
Objects.requireNonNull(sponsor, "Can't remove null as sponsor.");
Objects.requireNonNull(fromProject,
"Can't remove a sponsor from project null.");
final Optional<Sponsoring> result = fromProject
.getSponsoring()
.stream()
.filter(sponsoring -> sponsoring.getSponsor().equals(sponsor))
.findFirst();
if (result.isPresent()) {
final Sponsoring sponsoring = result.get();
fromProject.removeSponsor(sponsoring);
sciProjectRepository.save(fromProject);
}
}
private boolean filterContact(final Contact contact,
final ContactableEntity byContactable,
final SciProject byProject) {

View File

@ -73,7 +73,7 @@ public class Sponsoring implements Serializable {
return order;
}
protected void setOrder(final long order) {
public void setOrder(final long order) {
this.order = order;
}