All forms for SciProject migrated

pull/1/head
Jens Pelzetter 2019-08-18 09:32:35 +02:00
parent 9e3dfc8265
commit 55e3fda082
10 changed files with 439 additions and 52 deletions

View File

@ -20,7 +20,7 @@
<groupId>org.scientificcms</groupId> <groupId>org.scientificcms</groupId>
<artifactId>sci-types-project</artifactId> <artifactId>sci-types-project</artifactId>
<name>sci-types-project</name> <name>ScientificCMS SciProject Content Type</name>
<dependencies> <dependencies>
<dependency> <dependency>

View File

@ -323,7 +323,7 @@ class SciProjectController {
public Optional<Sponsoring> findSponsoring(final long projectId, public Optional<Sponsoring> findSponsoring(final long projectId,
final Object key) { final Object key) {
final SciProject project = projectRepository final SciProject project = projectRepository
.findById(projectId, SciProject.class) .findById(projectId, SciProject.class)
.orElseThrow( .orElseThrow(
() -> new IllegalArgumentException( () -> new IllegalArgumentException(
@ -343,7 +343,7 @@ class SciProjectController {
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
public List<Map<String, Object>> getSponsors(final long forProjectId) { public List<Map<String, Object>> getSponsors(final long forProjectId) {
final SciProject project = projectRepository final SciProject project = projectRepository
.findById(forProjectId, SciProject.class) .findById(forProjectId, SciProject.class)
.orElseThrow( .orElseThrow(
() -> new IllegalArgumentException( () -> new IllegalArgumentException(
@ -509,7 +509,7 @@ class SciProjectController {
projectId)) projectId))
); );
final List<Sponsoring> sponsoringList = project.getSponsoring(); final List<Sponsoring> sponsoringList = project.getSponsoring();
Sponsoring sponsoring = null; Sponsoring sponsoring = null;
int index = -1; int index = -1;
for (int i = 0; i < sponsoringList.size(); i++) { for (int i = 0; i < sponsoringList.size(); i++) {
@ -533,6 +533,37 @@ class SciProjectController {
} }
} }
@Transactional(Transactional.TxType.REQUIRED)
public void updateFundingData(final long projectId,
final Locale locale,
final Map<String, Object> data) {
final SciProject project = projectRepository
.findById(projectId, SciProject.class)
.orElseThrow(
() -> new IllegalArgumentException(
String.format("No SciProject with ID %d found.",
projectId))
);
final SciProjectConfig config = confManager
.findConfiguration(SciProjectConfig.class);
if (config.isEnableFunding()) {
final String funding = (String) data
.get(SciProjectUiConstants.FUNDING);
project.getFunding().addValue(locale, funding);
}
if (config.isEnableFundingVolume()) {
final String volume = (String) data
.get(SciProjectUiConstants.FUNDING_VOLUME);
project.getFundingVolume().addValue(locale, volume);
}
projectRepository.save(project);
}
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
public void save(final long projectId, public void save(final long projectId,
final Locale selectedLocale, final Locale selectedLocale,

View File

@ -64,7 +64,9 @@ public class SciProjectDescriptionStep extends SimpleEditStep {
} }
if (config.isEnableFunding()) { if (config.isEnableFunding()) {
addStep(new SciProjectFundingStep(itemModel, parent), addStep(new SciProjectFundingStep(itemModel,
parent,
selectedLanguageParam),
"sciproject.ui.steps.funding.title"); "sciproject.ui.steps.funding.title");
} }
} }

View File

@ -0,0 +1,159 @@
/* ;
* Copyright (c) 2013 Jens Pelzetter
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
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.form.TextArea;
import com.arsdigita.bebop.form.TextField;
import com.arsdigita.bebop.parameters.ParameterModel;
import com.arsdigita.bebop.parameters.StringInRangeValidationListener;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.ui.CMSDHTMLEditor;
import com.arsdigita.cms.ui.authoring.BasicItemForm;
import com.arsdigita.cms.ui.authoring.SelectedLanguageUtil;
import com.arsdigita.globalization.GlobalizedMessage;
import org.libreccm.cdi.utils.CdiUtil;
import org.scientificcms.contenttypes.sciproject.SciProject;
import org.scientificcms.contenttypes.sciproject.SciProjectConfig;
import org.scientificcms.contenttypes.sciproject.SciProjectConstants;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
/**
*
* @author Jens Pelzetter <jens@jp-digital.de>
*/
public class SciProjectFundingEditForm
extends BasicItemForm
implements FormProcessListener, FormInitListener {
private final static SciProjectConfig CONFIG = SciProjectConfig.getConfig();
private final StringParameter selectedLanguageParam;
public SciProjectFundingEditForm(
final ItemSelectionModel itemModel,
final StringParameter selectedLanguageParam) {
super("SciProjectFundingForm", itemModel, selectedLanguageParam);
this.selectedLanguageParam = selectedLanguageParam;
}
@Override
public void addWidgets() {
if (CONFIG.isEnableFunding()) {
final ParameterModel fundingParam = new StringParameter(
SciProjectUiConstants.FUNDING);
final TextArea funding;
if (CONFIG.isEnableFundingDhtml()) {
funding = new CMSDHTMLEditor(fundingParam);
} else {
funding = new TextArea(fundingParam);
}
funding.setLabel(new GlobalizedMessage(
"sciproject.ui.funding",
SciProjectConstants.SCI_PROJECT_BUNDLE));
funding.setCols(75);
funding.setRows(8);
add(funding);
}
if (CONFIG.isEnableFundingVolume()) {
final ParameterModel fundingVolumeParam = new StringParameter(
SciProjectUiConstants.FUNDING_VOLUME);
final TextField fundingVolume = new TextField(fundingVolumeParam);
fundingVolume.addValidationListener(
new StringInRangeValidationListener(
0,
CONFIG.getFundingVolumeLength()));
fundingVolume.setLabel(new GlobalizedMessage(
"sciproject.ui.funding.volume",
SciProjectConstants.SCI_PROJECT_BUNDLE));
add(fundingVolume);
}
}
@Override
public void init(final FormSectionEvent event) throws FormProcessException {
final PageState state = event.getPageState();
final FormData data = event.getFormData();
final Locale locale = SelectedLanguageUtil
.selectedLocale(state, selectedLanguageParam);
final SciProject project = (SciProject) getItemSelectionModel()
.getSelectedObject(state);
if (CONFIG.isEnableFunding()) {
data.put(SciProjectUiConstants.FUNDING,
project.getFunding().getValue(locale));
}
if (CONFIG.isEnableFundingVolume()) {
data.put(SciProjectUiConstants.FUNDING_VOLUME,
project.getFundingVolume().getValue(locale));
}
setVisible(state, true);
}
@Override
public void process(final FormSectionEvent event) throws
FormProcessException {
final PageState state = event.getPageState();
final FormData formData = event.getFormData();
final Locale locale = SelectedLanguageUtil
.selectedLocale(state, selectedLanguageParam);
final SciProject project = (SciProject) getItemSelectionModel()
.getSelectedObject(state);
if ((project != null)
&& getSaveCancelSection().getSaveButton().isSelected(state)) {
final Map<String, Object> data = new HashMap<>();
if (CONFIG.isEnableFunding()) {
data.put(SciProjectUiConstants.FUNDING,
formData.get(SciProjectUiConstants.FUNDING));
}
if (CONFIG.isEnableFundingVolume()) {
data.put(SciProjectUiConstants.FUNDING_VOLUME,
formData.get(SciProjectUiConstants.FUNDING_VOLUME));
}
final SciProjectController controller = CdiUtil
.createCdiUtil()
.findBean(SciProjectController.class);
controller.updateFundingData(project.getObjectId(), locale, data);
}
init(event);
}
}

View File

@ -0,0 +1,83 @@
package com.arsdigita.cms.contenttypes.ui;
import com.arsdigita.bebop.Component;
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 com.arsdigita.toolbox.ui.DomainObjectPropertySheet;
import org.scientificcms.contenttypes.sciproject.SciProjectConfig;
import org.scientificcms.contenttypes.sciproject.SciProjectConstants;
/**
*
* @author Jens Pelzetter <jens@jp-digital.de>
* @version $Id: SciProjectFundingStep.java 2334 2013-10-03 07:51:31Z jensp $
*/
public class SciProjectFundingStep extends SimpleEditStep {
private static final String EDIT_PROJECT_FUNDING_SHEET_NAME
= "editProjectFunding";
private static final String UPLOAD_PROJECT_FUNDING_SHEET_NAME
= "uploadProjectFunding";
public SciProjectFundingStep(final ItemSelectionModel itemModel,
final AuthoringKitWizard parent,
final StringParameter selectedLanguageParam) {
this(itemModel, parent, selectedLanguageParam, null);
}
public SciProjectFundingStep(final ItemSelectionModel itemModel,
final AuthoringKitWizard parent,
final StringParameter selectedLanguageParam,
final String prefix) {
super(itemModel, parent, selectedLanguageParam, prefix);
final BasicItemForm editFundingForm = new SciProjectFundingEditForm(
itemModel, selectedLanguageParam);
add(EDIT_PROJECT_FUNDING_SHEET_NAME,
new GlobalizedMessage("sciproject.ui.funding.edit",
SciProjectConstants.SCI_PROJECT_BUNDLE),
new WorkflowLockedComponentAccess(editFundingForm, itemModel),
editFundingForm.getSaveCancelSection().getCancelButton());
final SciProjectFundingUploadForm uploadFundingForm
= new SciProjectFundingUploadForm(
itemModel, selectedLanguageParam);
add(UPLOAD_PROJECT_FUNDING_SHEET_NAME,
new GlobalizedMessage("sciproject.ui.funding.upload",
SciProjectConstants.SCI_PROJECT_BUNDLE),
new WorkflowLockedComponentAccess(uploadFundingForm, itemModel),
uploadFundingForm.getSaveCancelSection().getCancelButton());
setDisplayComponent(getSciProjectEditFundingSheet(itemModel));
}
public static Component getSciProjectEditFundingSheet(
final ItemSelectionModel itemModel) {
final DomainObjectPropertySheet sheet = new DomainObjectPropertySheet(
itemModel);
if (SciProjectConfig.getConfig().isEnableFunding()) {
sheet.add(
new GlobalizedMessage("sciproject.ui.funding",
SciProjectConstants.SCI_PROJECT_BUNDLE),
SciProjectUiConstants.FUNDING);
}
if (SciProjectConfig.getConfig().isEnableFundingVolume()) {
sheet.add(
new GlobalizedMessage("sciproject.ui.funding.volume",
SciProjectConstants.SCI_PROJECT_BUNDLE),
SciProjectUiConstants.FUNDING_VOLUME);
}
return sheet;
}
}

View File

@ -0,0 +1,67 @@
package com.arsdigita.cms.contenttypes.ui;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.ui.authoring.SelectedLanguageUtil;
import com.arsdigita.cms.ui.contenttypes.AbstractTextUploadForm;
import com.arsdigita.globalization.GlobalizedMessage;
import org.libreccm.cdi.utils.CdiUtil;
import org.scientificcms.contenttypes.sciproject.SciProject;
import org.scientificcms.contenttypes.sciproject.SciProjectConstants;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
/**
*
* @author Jens Pelzetter <jens@jp-digital.de>
* @version $Id: SciProjectFundingUploadForm.java 2334 2013-10-03 07:51:31Z
* jensp $
*/
public class SciProjectFundingUploadForm extends AbstractTextUploadForm {
private final StringParameter selectedLanguageParam;
public SciProjectFundingUploadForm(
final ItemSelectionModel itemModel,
final StringParameter selectedLanguageParam) {
super(itemModel);
this.selectedLanguageParam = selectedLanguageParam;
}
@Override
public GlobalizedMessage getLabelText() {
return new GlobalizedMessage("sciproject.ui.funding.upload",
SciProjectConstants.SCI_PROJECT_BUNDLE);
}
@Override
public GlobalizedMessage getMimeTypeLabel() {
return new GlobalizedMessage("sciproject.ui.funding.upload.mimetype",
SciProjectConstants.SCI_PROJECT_BUNDLE);
}
@Override
public void setText(final ItemSelectionModel itemModel,
final PageState state,
final String text) {
final SciProject project = (SciProject) itemModel.getSelectedObject(
state);
final Locale locale = SelectedLanguageUtil
.selectedLocale(state,
selectedLanguageParam);
final Map<String, Object> data = new HashMap<>();
data.put(SciProjectUiConstants.FUNDING, text);
CdiUtil
.createCdiUtil()
.findBean(SciProjectController.class)
.updateFundingData(project.getObjectId(), locale, data);
}
}

View File

@ -21,6 +21,10 @@ public final class SciProjectUiConstants {
public static final String EDIT_DESC_TEXT_SHEET_NAME = "editProjectDescText"; public static final String EDIT_DESC_TEXT_SHEET_NAME = "editProjectDescText";
public static final String FUNDING = "funding";
public static final String FUNDING_VOLUME = "fundingVolume";
public static final String FUNDING_CODE = "fundingCode"; public static final String FUNDING_CODE = "fundingCode";
public static final String END = "end"; public static final String END = "end";

View File

@ -12,7 +12,6 @@ import javax.persistence.Entity;
import org.hibernate.envers.Audited; import org.hibernate.envers.Audited;
import org.libreccm.l10n.LocalizedString; import org.libreccm.l10n.LocalizedString;
import org.librecms.assets.Organization;
import org.librecms.contentsection.ContentItem; import org.librecms.contentsection.ContentItem;
import org.librecms.contenttypes.AuthoringKit; import org.librecms.contenttypes.AuthoringKit;
import org.librecms.contenttypes.AuthoringStep; import org.librecms.contenttypes.AuthoringStep;

View File

@ -27,6 +27,15 @@ public class SciProjectConfig {
@Setting @Setting
private boolean enableFunding = true; private boolean enableFunding = true;
@Setting
private boolean enableFundingDhtml = true;
@Setting
private boolean enableFundingVolume = true;
@Setting
private int fundingVolumeLength = 128;
public static SciProjectConfig getConfig() { public static SciProjectConfig getConfig() {
final ConfigurationManager confManager = CdiUtil.createCdiUtil() final ConfigurationManager confManager = CdiUtil.createCdiUtil()
.findBean(ConfigurationManager.class); .findBean(ConfigurationManager.class);
@ -61,6 +70,30 @@ public class SciProjectConfig {
this.enableFunding = enableFunding; this.enableFunding = enableFunding;
} }
public boolean isEnableFundingDhtml() {
return enableFundingDhtml;
}
public void setEnableFundingDhtml(boolean enableFundingDhtml) {
this.enableFundingDhtml = enableFundingDhtml;
}
public boolean isEnableFundingVolume() {
return enableFundingVolume;
}
public void setEnableFundingVolume(final boolean enableFundingVolume) {
this.enableFundingVolume = enableFundingVolume;
}
public int getFundingVolumeLength() {
return fundingVolumeLength;
}
public void setFundingVolumeLength(final int fundingVolumeLength) {
this.fundingVolumeLength = fundingVolumeLength;
}
} }

View File

@ -5,25 +5,24 @@
*/ */
package org.scientificcms.contenttypes.sciproject; package org.scientificcms.contenttypes.sciproject;
import nl.jqno.equalsverifier.Warning;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.Parameterized; import org.junit.runners.Parameterized;
import org.libreccm.categorization.Category; import org.libreccm.categorization.Category;
import org.libreccm.core.CcmObject; import org.libreccm.core.CcmObject;
import org.libreccm.l10n.LocalizedString; import org.libreccm.l10n.LocalizedString;
import org.libreccm.security.Group;
import org.libreccm.security.Role;
import org.libreccm.security.SecurityEntitiesPrefabProvider; import org.libreccm.security.SecurityEntitiesPrefabProvider;
import org.libreccm.security.User;
import org.libreccm.tests.categories.UnitTest; import org.libreccm.tests.categories.UnitTest;
import org.libreccm.testutils.EqualsVerifier; import org.libreccm.testutils.EqualsVerifier;
import org.libreccm.workflow.Workflow; import org.libreccm.workflow.Workflow;
import org.librecms.assets.ContactableEntity; import org.librecms.assets.ContactableEntity;
import org.librecms.assets.Organization;
import org.librecms.assets.Person; import org.librecms.assets.Person;
import org.librecms.assets.PostalAddress; import org.librecms.assets.PostalAddress;
import org.librecms.contentsection.AttachmentList;
import org.librecms.contentsection.ContentItem; import org.librecms.contentsection.ContentItem;
import org.librecms.contentsection.ContentSection; import org.librecms.contentsection.ContentSection;
import org.librecms.contentsection.ContentType; import org.librecms.contentsection.ContentType;
import org.librecms.contentsection.ItemAttachment;
import org.librecms.lifecycle.Lifecycle; import org.librecms.lifecycle.Lifecycle;
import java.util.Arrays; import java.util.Arrays;
@ -151,18 +150,6 @@ public class EqualsAndHashCodeTest extends EqualsVerifier {
verifier.withPrefabValues(ContentItem.class, item1, item2); verifier.withPrefabValues(ContentItem.class, item1, item2);
final AttachmentList attachmentList1 = new AttachmentList();
attachmentList1.setListId(701);
attachmentList1.setName("list1");
final AttachmentList attachmentList2 = new AttachmentList();
attachmentList2.setListId(702);
attachmentList2.setName("list2");
verifier.withPrefabValues(AttachmentList.class,
attachmentList1,
attachmentList2);
final Lifecycle lifecycle1 = new Lifecycle(); final Lifecycle lifecycle1 = new Lifecycle();
lifecycle1.setLifecycleId(801); lifecycle1.setLifecycleId(801);
lifecycle1.setStarted(true); lifecycle1.setStarted(true);
@ -206,6 +193,28 @@ public class EqualsAndHashCodeTest extends EqualsVerifier {
category2.setName("category2"); category2.setName("category2");
verifier.withPrefabValues(Category.class, category1, category2); verifier.withPrefabValues(Category.class, category1, category2);
final Organization organization1 = new Organization();
organization1.setName("orga1");
final Organization organization2 = new Organization();
organization1.setName("orga2");
verifier.withPrefabValues(Organization.class,
organization1,
organization2);
final ItemAttachment<?> itemAttachment1 = new ItemAttachment<>();
itemAttachment1.setUuid("927ac9de-029d-4233-9015-1135eb861c34");
final ItemAttachment<?> itemAttachment2 = new ItemAttachment<>();
itemAttachment2.setUuid("d1bd98a1-75c2-4e61-8f9f-2e2eadd30812");
verifier.withPrefabValues(ItemAttachment.class,
itemAttachment1,
itemAttachment2);
verifier.suppress(Warning.REFERENCE_EQUALITY);
} }
} }