Base class for create step of publication assets.
parent
fc0efffe4d
commit
c654460b0a
|
|
@ -1,8 +1,3 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.scientificcms.publications.assets;
|
||||
|
||||
import org.hibernate.envers.Audited;
|
||||
|
|
@ -41,7 +36,9 @@ import static org.scientificcms.publications.SciPublicationsConstants.*;
|
|||
createStep = CollectedVolumeAssetCreateStep.class,
|
||||
editStep = CollectedVolumeAssetEditStep.class
|
||||
)
|
||||
public class CollectedVolumeAsset extends Asset {
|
||||
public class CollectedVolumeAsset
|
||||
extends Asset
|
||||
implements PublicationAsset<CollectedVolume> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
|
@ -53,6 +50,16 @@ public class CollectedVolumeAsset extends Asset {
|
|||
@JoinColumn(name = "COLLECTED_VOLUME_ID")
|
||||
private CollectedVolume collectedVolume;
|
||||
|
||||
@Override
|
||||
public CollectedVolume getPublication() {
|
||||
return collectedVolume;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPublication(final CollectedVolume publication) {
|
||||
this.collectedVolume = publication;
|
||||
}
|
||||
|
||||
public CollectedVolume getCollectedVolume() {
|
||||
return collectedVolume;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,9 @@ import static org.scientificcms.publications.SciPublicationsConstants.*;
|
|||
createStep = ProceedingsAssetCreateStep.class,
|
||||
editStep = ProceedingsAssetEditStep.class
|
||||
)
|
||||
public class ProceedingsAsset extends Asset {
|
||||
public class ProceedingsAsset
|
||||
extends Asset
|
||||
implements PublicationAsset<Proceedings> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
|
@ -48,6 +50,16 @@ public class ProceedingsAsset extends Asset {
|
|||
@JoinColumn(name = "PROCEEDINGS_ID")
|
||||
private Proceedings proceedings;
|
||||
|
||||
@Override
|
||||
public Proceedings getPublication() {
|
||||
return proceedings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPublication(final Proceedings publication) {
|
||||
this.proceedings = publication;
|
||||
}
|
||||
|
||||
public Proceedings getProceedings() {
|
||||
return proceedings;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
package org.scientificcms.publications.assets;
|
||||
|
||||
import org.librecms.contentsection.Asset;
|
||||
import org.scientificcms.publications.Publication;
|
||||
|
||||
/**
|
||||
* Interface for {@link Asset} wrapping a {@link Publication}.To avoid an
|
||||
* additional layer of inheritence is the JPA entitites, this was defined as
|
||||
* interface instead of a class.
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
* @param <T> The type of publication wrapped by the implementing {@link Asset}.
|
||||
*/
|
||||
public interface PublicationAsset<T extends Publication> {
|
||||
|
||||
T getPublication();
|
||||
|
||||
void setPublication(T publication);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,125 @@
|
|||
package org.scientificcms.publications.ui.assets;
|
||||
|
||||
import org.librecms.contentsection.Asset;
|
||||
import org.librecms.contentsection.AssetRepository;
|
||||
import org.librecms.ui.contentsections.assets.AbstractMvcAssetCreateStep;
|
||||
import org.scientificcms.publications.Publication;
|
||||
import org.scientificcms.publications.PublicationRepository;
|
||||
import org.scientificcms.publications.assets.PublicationAsset;
|
||||
import org.scientificcms.publications.ui.SciPublicationsUiConstants;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
* @param <A> Type of {@link Asset}. Must implement {@link PublicationAsset}
|
||||
* @param <P> Type of {@link Publication}
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractPublicationAssetCreateStep<A extends Asset & PublicationAsset<P>, P extends Publication>
|
||||
extends AbstractMvcAssetCreateStep<A> {
|
||||
|
||||
private static final String FORM_PARAMS_YEAR_OF_PUBLICATION
|
||||
= "yearOfPublication";
|
||||
|
||||
private static final String FORM_PARAMS_SHORT_DESCRIPTION
|
||||
= "shortDescription";
|
||||
|
||||
@Inject
|
||||
private AssetRepository assetRepo;
|
||||
|
||||
@Inject
|
||||
private PublicationRepository publicationRepo;
|
||||
|
||||
private int yearOfPublication;
|
||||
|
||||
private String shortDescription;
|
||||
|
||||
@Override
|
||||
public String getBundle() {
|
||||
return SciPublicationsUiConstants.BUNDLE;
|
||||
}
|
||||
|
||||
public int getYearOfPublication() {
|
||||
return yearOfPublication;
|
||||
}
|
||||
|
||||
public String getShortDescription() {
|
||||
return shortDescription;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the publication instance.
|
||||
*
|
||||
* @return The publication instance.
|
||||
*/
|
||||
protected abstract P createPublication();
|
||||
|
||||
@Override
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
protected String setAssetProperties(
|
||||
final A publicationAsset,
|
||||
final Map<String, String[]> formParams
|
||||
) {
|
||||
final P publication = createPublication();
|
||||
final Locale locale = new Locale(getInitialLocale());
|
||||
publication.getTitle().putValue(
|
||||
locale,
|
||||
publicationAsset.getTitle().getValue(locale)
|
||||
);
|
||||
|
||||
shortDescription = Optional
|
||||
.ofNullable(formParams.get(FORM_PARAMS_SHORT_DESCRIPTION))
|
||||
.filter(value -> value.length > 0)
|
||||
.map(value -> value[0])
|
||||
.filter(value -> !value.isBlank())
|
||||
.orElse(null);
|
||||
|
||||
if (shortDescription != null) {
|
||||
publication.getShortDescription().putValue(
|
||||
locale,
|
||||
shortDescription
|
||||
);
|
||||
}
|
||||
|
||||
final String yearOfPublicationParam = Optional
|
||||
.ofNullable(formParams.get(FORM_PARAMS_YEAR_OF_PUBLICATION))
|
||||
.filter(value -> value.length > 0)
|
||||
.map(value -> value[0])
|
||||
.filter(value -> value.matches("\\d*"))
|
||||
.orElse(null);
|
||||
if (yearOfPublicationParam != null) {
|
||||
publication.setYearOfPublication(
|
||||
Integer.parseInt(yearOfPublicationParam)
|
||||
);
|
||||
}
|
||||
|
||||
publicationRepo.save(publication);
|
||||
|
||||
publicationAsset.setPublication(publication);
|
||||
assetRepo.save(publicationAsset);
|
||||
|
||||
return String.format(
|
||||
"redirect:/%s/assets/%s/%s/@%s",
|
||||
getContentSectionLabel(),
|
||||
getFolderPath(),
|
||||
getName(),
|
||||
getEditStepName()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns name (the last path fragment) of the edit step, without the
|
||||
* leading <code>@</code>. For example, <code>collectedvolume-edit</code>.
|
||||
*
|
||||
* @return The last path fragment of the edit step.
|
||||
*/
|
||||
protected abstract String getEditStepName();
|
||||
|
||||
}
|
||||
|
|
@ -1,20 +1,12 @@
|
|||
package org.scientificcms.publications.ui.assets;
|
||||
|
||||
import org.libreccm.l10n.GlobalizationHelper;
|
||||
import org.librecms.ui.contentsections.assets.AbstractMvcAssetCreateStep;
|
||||
import org.scientificcms.publications.CollectedVolume;
|
||||
import org.scientificcms.publications.PublicationRepository;
|
||||
import org.scientificcms.publications.assets.CollectedVolumeAsset;
|
||||
import org.scientificcms.publications.ui.SciPublicationsUiConstants;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -23,24 +15,11 @@ import javax.transaction.Transactional;
|
|||
@RequestScoped
|
||||
@Named("SciCmsCollectedVolumeAssetCreateStep")
|
||||
public class CollectedVolumeAssetCreateStep
|
||||
extends AbstractMvcAssetCreateStep<CollectedVolumeAsset> {
|
||||
|
||||
private static final String FORM_PARAMS_YEAR_OF_PUBLICATION
|
||||
= "yearOfPublication";
|
||||
|
||||
private static final String FORM_PARAMS_SHORT_DESCRIPTION
|
||||
= "shortDescription";
|
||||
|
||||
private int yearOfPublication;
|
||||
|
||||
private String shortDescription;
|
||||
extends AbstractPublicationAssetCreateStep<CollectedVolumeAsset, CollectedVolume> {
|
||||
|
||||
@Inject
|
||||
private GlobalizationHelper globalizationHelper;
|
||||
|
||||
@Inject
|
||||
private PublicationRepository publicationRepo;
|
||||
|
||||
@Override
|
||||
public String showCreateStep() {
|
||||
return "org/scientificcms/assets/collectedvolume/ui/create-collectedvolume.xhtml";
|
||||
|
|
@ -60,73 +39,19 @@ public class CollectedVolumeAssetCreateStep
|
|||
.getText("collectedvolume.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBundle() {
|
||||
return SciPublicationsUiConstants.BUNDLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<CollectedVolumeAsset> getAssetClass() {
|
||||
return CollectedVolumeAsset.class;
|
||||
}
|
||||
|
||||
public int getYearOfPublication() {
|
||||
return yearOfPublication;
|
||||
}
|
||||
|
||||
public String getShortDescription() {
|
||||
return shortDescription;
|
||||
@Override
|
||||
protected CollectedVolume createPublication() {
|
||||
return new CollectedVolume();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
protected String setAssetProperties(
|
||||
final CollectedVolumeAsset collectedVolumeAsset,
|
||||
final Map<String, String[]> formParams
|
||||
) {
|
||||
final CollectedVolume collectedVolume = new CollectedVolume();
|
||||
final Locale locale = new Locale(getInitialLocale());
|
||||
collectedVolume.getTitle().putValue(
|
||||
locale,
|
||||
collectedVolumeAsset.getTitle().getValue(locale)
|
||||
);
|
||||
|
||||
shortDescription = Optional
|
||||
.ofNullable(formParams.get(FORM_PARAMS_SHORT_DESCRIPTION))
|
||||
.filter(value -> value.length > 0)
|
||||
.map(value -> value[0])
|
||||
.filter(value -> !value.isBlank())
|
||||
.orElse(null);
|
||||
|
||||
if (shortDescription != null) {
|
||||
collectedVolume.getShortDescription().putValue(
|
||||
locale,
|
||||
shortDescription
|
||||
);
|
||||
}
|
||||
|
||||
final String yearOfPublicationParam = Optional
|
||||
.ofNullable(formParams.get(FORM_PARAMS_YEAR_OF_PUBLICATION))
|
||||
.filter(value -> value.length > 0)
|
||||
.map(value -> value[0])
|
||||
.filter(value -> value.matches("\\d*"))
|
||||
.orElse(null);
|
||||
if (yearOfPublicationParam != null) {
|
||||
collectedVolume.setYearOfPublication(
|
||||
Integer.parseInt(yearOfPublicationParam)
|
||||
);
|
||||
}
|
||||
|
||||
publicationRepo.save(collectedVolume);
|
||||
|
||||
collectedVolumeAsset.setCollectedVolume(collectedVolume);
|
||||
|
||||
return String.format(
|
||||
"redirect:/%s/assets/%s/%s/@collectedvolume-edit",
|
||||
getContentSectionLabel(),
|
||||
getFolderPath(),
|
||||
getName()
|
||||
);
|
||||
protected String getEditStepName() {
|
||||
return "collectedvolume-edit";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,12 @@
|
|||
package org.scientificcms.publications.ui.assets;
|
||||
|
||||
import org.libreccm.l10n.GlobalizationHelper;
|
||||
import org.librecms.ui.contentsections.assets.AbstractMvcAssetCreateStep;
|
||||
import org.scientificcms.publications.Proceedings;
|
||||
import org.scientificcms.publications.PublicationRepository;
|
||||
import org.scientificcms.publications.assets.ProceedingsAsset;
|
||||
import org.scientificcms.publications.ui.SciPublicationsUiConstants;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -23,24 +15,11 @@ import javax.transaction.Transactional;
|
|||
@RequestScoped
|
||||
@Named("SciCmsProceedingsAssetCreateStep")
|
||||
public class ProceedingsAssetCreateStep
|
||||
extends AbstractMvcAssetCreateStep<ProceedingsAsset> {
|
||||
|
||||
private static final String FORM_PARAMS_YEAR_OF_PUBLICATION
|
||||
= "yearOfPublication";
|
||||
|
||||
private static final String FORM_PARAMS_SHORT_DESCRIPTION
|
||||
= "shortDescription";
|
||||
|
||||
private int yearOfPublication;
|
||||
|
||||
private String shortDescription;
|
||||
extends AbstractPublicationAssetCreateStep<ProceedingsAsset, Proceedings> {
|
||||
|
||||
@Inject
|
||||
private GlobalizationHelper globalizationHelper;
|
||||
|
||||
@Inject
|
||||
private PublicationRepository publicationRepo;
|
||||
|
||||
@Override
|
||||
public String showCreateStep() {
|
||||
return "org/scientificcms/assets/proceedings/ui/create-proceedings.xhtml";
|
||||
|
|
@ -61,8 +40,13 @@ public class ProceedingsAssetCreateStep
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getBundle() {
|
||||
return SciPublicationsUiConstants.BUNDLE;
|
||||
protected Proceedings createPublication() {
|
||||
return new Proceedings();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getEditStepName() {
|
||||
return "proceedings-edit";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -70,62 +54,4 @@ public class ProceedingsAssetCreateStep
|
|||
return ProceedingsAsset.class;
|
||||
}
|
||||
|
||||
public int getYearOfPublication() {
|
||||
return yearOfPublication;
|
||||
}
|
||||
|
||||
public String getShortDescription() {
|
||||
return shortDescription;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
protected String setAssetProperties(
|
||||
final ProceedingsAsset proceedingsAsset,
|
||||
final Map<String, String[]> formParams
|
||||
) {
|
||||
final Proceedings proceedings = new Proceedings();
|
||||
final Locale locale = new Locale(getInitialLocale());
|
||||
proceedings.getTitle().putValue(
|
||||
locale,
|
||||
proceedingsAsset.getTitle().getValue(locale)
|
||||
);
|
||||
|
||||
shortDescription = Optional
|
||||
.ofNullable(formParams.get(FORM_PARAMS_SHORT_DESCRIPTION))
|
||||
.filter(value -> value.length > 0)
|
||||
.map(value -> value[0])
|
||||
.filter(value -> !value.isBlank())
|
||||
.orElse(null);
|
||||
|
||||
if (shortDescription != null) {
|
||||
proceedings.getShortDescription().putValue(
|
||||
locale,
|
||||
shortDescription
|
||||
);
|
||||
}
|
||||
|
||||
final String yearOfPublicationParam = Optional
|
||||
.ofNullable(formParams.get(FORM_PARAMS_YEAR_OF_PUBLICATION))
|
||||
.filter(value -> value.length > 0)
|
||||
.map(value -> value[0])
|
||||
.filter(value -> value.matches("\\d*"))
|
||||
.orElse(null);
|
||||
if (yearOfPublicationParam != null) {
|
||||
proceedings.setYearOfPublication(
|
||||
Integer.parseInt(yearOfPublicationParam)
|
||||
);
|
||||
}
|
||||
|
||||
publicationRepo.save(proceedings);
|
||||
|
||||
proceedingsAsset.setProceedings(proceedings);
|
||||
|
||||
return String.format(
|
||||
"redirect:/%s/assets/%s/%s/@proceedings-edit",
|
||||
getContentSectionLabel(),
|
||||
getFolderPath(),
|
||||
getName()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue