Publisher Asset
parent
e892273c02
commit
99eac9dbfa
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright (C) 2021 LibreCCM Foundation.
|
||||
*
|
||||
* 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., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.scientificcms.publications.ui;
|
||||
|
||||
import org.libreccm.ui.AbstractMessagesBean;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Named;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RequestScoped
|
||||
@Named("SciPublicationsUiMessageBundle")
|
||||
public class SciPublicationsUiMessageBundle extends AbstractMessagesBean {
|
||||
|
||||
@Override
|
||||
public String getMessageBundle() {
|
||||
return SciPublicationsUiConstants.BUNDLE;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -18,7 +18,11 @@
|
|||
*/
|
||||
package org.scientificcms.publications.ui.assets;
|
||||
|
||||
import com.arsdigita.kernel.KernelConfig;
|
||||
|
||||
import org.libreccm.configuration.ConfigurationManager;
|
||||
import org.libreccm.l10n.GlobalizationHelper;
|
||||
import org.libreccm.security.AuthorizationRequired;
|
||||
import org.librecms.ui.contentsections.assets.AbstractMvcAssetCreateStep;
|
||||
import org.scientificcms.publications.Publisher;
|
||||
import org.scientificcms.publications.PublisherRepository;
|
||||
|
|
@ -26,6 +30,7 @@ import org.scientificcms.publications.assets.PublisherAsset;
|
|||
import org.scientificcms.publications.ui.SciPublicationsUiConstants;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
|
|
@ -41,6 +46,17 @@ import javax.transaction.Transactional;
|
|||
public class PublisherCreateStep
|
||||
extends AbstractMvcAssetCreateStep<PublisherAsset> {
|
||||
|
||||
private static final String FORM_PARAMS_PUBLISHER_NAME = "publisherName";
|
||||
|
||||
private static final String FORM_PARAMS_PLACE = "place";
|
||||
|
||||
private String publisherName;
|
||||
|
||||
private String place;
|
||||
|
||||
@Inject
|
||||
private ConfigurationManager confManager;
|
||||
|
||||
@Inject
|
||||
private GlobalizationHelper globalizationHelper;
|
||||
|
||||
|
|
@ -76,21 +92,68 @@ public class PublisherCreateStep
|
|||
return PublisherAsset.class;
|
||||
}
|
||||
|
||||
public String getPublisherName() {
|
||||
return publisherName;
|
||||
}
|
||||
|
||||
public String getPlace() {
|
||||
return place;
|
||||
}
|
||||
|
||||
@AuthorizationRequired
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
@Override
|
||||
public String createAsset(final Map<String, String[]> formParams) {
|
||||
if (!formParams.containsKey(FORM_PARAMS_PUBLISHER_NAME)
|
||||
|| formParams.get(FORM_PARAMS_PUBLISHER_NAME) == null
|
||||
|| formParams.get(FORM_PARAMS_PUBLISHER_NAME).length == 0) {
|
||||
addMessage(
|
||||
"danger",
|
||||
globalizationHelper
|
||||
.getLocalizedTextsUtil(getBundle())
|
||||
.getText("publisher.createstep.publishername.error.missing")
|
||||
);
|
||||
return showCreateStep();
|
||||
}
|
||||
|
||||
formParams.put("title", formParams.get(FORM_PARAMS_PUBLISHER_NAME));
|
||||
|
||||
final KernelConfig kernelConfig = confManager
|
||||
.findConfiguration(KernelConfig.class);
|
||||
formParams.put(
|
||||
"locale",
|
||||
new String[]{kernelConfig.getDefaultLocale().toString()}
|
||||
);
|
||||
|
||||
return super.createAsset(formParams);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
protected String setAssetProperties(
|
||||
final PublisherAsset publisherAsset,
|
||||
final Map<String, String[]> formParams
|
||||
) {
|
||||
publisherName = Optional
|
||||
.ofNullable(formParams.get(FORM_PARAMS_PUBLISHER_NAME))
|
||||
.filter(value -> value.length > 0)
|
||||
.map(value -> value[0])
|
||||
.orElse(null);
|
||||
place = Optional
|
||||
.ofNullable(formParams.get(FORM_PARAMS_PLACE))
|
||||
.filter(value -> value.length > 0)
|
||||
.map(value -> value[0])
|
||||
.orElse(null);
|
||||
|
||||
final Publisher publisher = new Publisher();
|
||||
publisher.setName(formParams.get("name")[0]);
|
||||
publisher.setName(formParams.get(FORM_PARAMS_PUBLISHER_NAME)[0]);
|
||||
|
||||
if (formParams.get("place") != null
|
||||
&& formParams.get("place").length > 0) {
|
||||
publisher.setPlace(formParams.get("place")[0]);
|
||||
publisher.setPlace(formParams.get(FORM_PARAMS_PLACE)[0]);
|
||||
}
|
||||
publisherRepo.save(publisher);
|
||||
|
||||
|
||||
publisherAsset.setPublisher(publisher);
|
||||
|
||||
return String.format(
|
||||
|
|
|
|||
|
|
@ -18,8 +18,9 @@
|
|||
*/
|
||||
package org.scientificcms.publications.ui.assets;
|
||||
|
||||
import org.libreccm.api.IdentifierParser;
|
||||
import org.libreccm.l10n.GlobalizationHelper;
|
||||
import com.arsdigita.kernel.KernelConfig;
|
||||
|
||||
import org.libreccm.configuration.ConfigurationManager;
|
||||
import org.libreccm.security.AuthorizationRequired;
|
||||
import org.librecms.contentsection.AssetRepository;
|
||||
import org.librecms.ui.contentsections.AssetPermissionsChecker;
|
||||
|
|
@ -39,15 +40,12 @@ import org.scientificcms.publications.ui.SciPublicationsUiConstants;
|
|||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.mvc.Controller;
|
||||
import javax.mvc.Models;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.transaction.Transactional;
|
||||
import javax.ws.rs.FormParam;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.core.Context;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -76,16 +74,8 @@ public class PublisherEditStep extends AbstractMvcAssetEditStep {
|
|||
@Inject
|
||||
private AssetUi assetUi;
|
||||
|
||||
private GlobalizationHelper globalizationHelper;
|
||||
|
||||
@Context
|
||||
private HttpServletRequest request;
|
||||
|
||||
@Inject
|
||||
private IdentifierParser identifierParser;
|
||||
|
||||
@Inject
|
||||
private Models models;
|
||||
private ConfigurationManager confManager;
|
||||
|
||||
@Inject
|
||||
private PublisherRepository publisherRepo;
|
||||
|
|
@ -106,7 +96,7 @@ public class PublisherEditStep extends AbstractMvcAssetEditStep {
|
|||
|
||||
if (getAsset() instanceof PublisherAsset) {
|
||||
final Publisher publisher = getPublisher();
|
||||
editStepModel.setName(publisher.getName());
|
||||
editStepModel.setPublisherName(publisher.getName());
|
||||
editStepModel.setPlace(publisher.getPlace());
|
||||
} else {
|
||||
throw new AssetNotFoundException(
|
||||
|
|
@ -170,6 +160,8 @@ public class PublisherEditStep extends AbstractMvcAssetEditStep {
|
|||
final String assetPath,
|
||||
@FormParam("name")
|
||||
final String name,
|
||||
@FormParam("publisherName")
|
||||
final String publisherName,
|
||||
@FormParam("place")
|
||||
final String place
|
||||
) {
|
||||
|
|
@ -184,14 +176,19 @@ public class PublisherEditStep extends AbstractMvcAssetEditStep {
|
|||
if (assetPermissionsChecker.canEditAsset(getAsset())) {
|
||||
final PublisherAsset publisherAsset = getPublisherAsset();
|
||||
final Publisher publisher = getPublisher();
|
||||
|
||||
publisherAsset.setDisplayName(name);
|
||||
publisher.setName(name);
|
||||
|
||||
final KernelConfig kernelConfig = confManager.findConfiguration(
|
||||
KernelConfig.class
|
||||
);
|
||||
publisherAsset
|
||||
.getTitle()
|
||||
.putValue(kernelConfig.getDefaultLocale(), publisherName);
|
||||
publisher.setName(publisherName);
|
||||
publisher.setPlace(place);
|
||||
|
||||
|
||||
assetRepo.save(publisherAsset);
|
||||
publisherRepo.save(publisher);
|
||||
|
||||
|
||||
return buildRedirectPathForStep();
|
||||
} else {
|
||||
return assetUi.showAccessDenied(
|
||||
|
|
|
|||
|
|
@ -11,16 +11,16 @@ import javax.inject.Named;
|
|||
@Named("SciCmsPublisherEditStepModel")
|
||||
public class PublisherEditStepModel {
|
||||
|
||||
private String name;
|
||||
private String publisherName;
|
||||
|
||||
private String place;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
public String getPublisherName() {
|
||||
return publisherName;
|
||||
}
|
||||
|
||||
public void setName(final String name) {
|
||||
this.name = name;
|
||||
public void setPublisherName(final String publisherName) {
|
||||
this.publisherName = publisherName;
|
||||
}
|
||||
|
||||
public String getPlace() {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
package org.scientificcms.publications.ui.assets;
|
||||
|
||||
import org.librecms.ui.contentsections.assets.MvcAssetEditSteps;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class SciPublicationsAssetSteps implements MvcAssetEditSteps {
|
||||
|
||||
@Override
|
||||
public Set<Class<?>> getClasses() {
|
||||
return Set.of(
|
||||
PublisherEditStep.class
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
<!DOCTYPE html [<!ENTITY times '×'>]>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||
xmlns:bootstrap="http://xmlns.jcp.org/jsf/composite/components/bootstrap"
|
||||
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
|
||||
xmlns:libreccm="http://xmlns.jcp.org/jsf/composite/components/libreccm"
|
||||
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
|
||||
<ui:composition template="/WEB-INF/views/org/librecms/ui/contentsection/contentsection.xhtml">
|
||||
|
||||
<ui:define name="main">
|
||||
<div class="container">
|
||||
<h1>#{SciPublicationsUiMessageBundle['publisher.createform.title']}</h1>
|
||||
|
||||
<c:forEach items="#{SciCmsPublisherCreateStep.messages.entrySet()}"
|
||||
var="messages">
|
||||
<div class="alert alert-#{message.key}" role="alert">
|
||||
#{message.value}
|
||||
</div>
|
||||
</c:forEach>
|
||||
|
||||
<form action="#{mvc.basePath}/#{SciCmsPublisherCreateStep.contentSectionLabel}/assets/#{SciCmsPublisherCreateStep.folderPath}@create/#{SciCmsPublisherCreateStep.assetType}"
|
||||
method="post">
|
||||
<bootstrap:formGroupText
|
||||
help="#{CmsAssetsStepsDefaultMessagesBundle['createform.name.help']}"
|
||||
inputId="name"
|
||||
label="#{CmsAssetsStepsDefaultMessagesBundle['createform.name.label']}"
|
||||
name="name"
|
||||
pattern="^([a-zA-Z0-9_-]*)$"
|
||||
required="true"
|
||||
value="#{SciCmsPublisherCreateStep.name}"
|
||||
/>
|
||||
|
||||
<!-- <bootstrap:formGroupSelect
|
||||
help="#{CmsAssetsStepsDefaultMessagesBundle['createform.initial_locale.help']}"
|
||||
inputId="locale"
|
||||
label="#{CmsAssetsStepsDefaultMessagesBundle['createform.initial_locale.label']}"
|
||||
name="locale"
|
||||
options="#{CmsPostalAddressCreateStep.availableLocales}"
|
||||
required="true"
|
||||
selectedOptions="#{[CmsPostalAddressCreateStep.initialLocale]}"
|
||||
/>-->
|
||||
|
||||
<bootstrap:formGroupText
|
||||
help="#{SciPublicationsUiMessageBundle['publisher.createform.publishername.help']}"
|
||||
inputId="publisherName"
|
||||
label="#{SciPublicationsUiMessageBundle['publisher.createform.publishername.label']}"
|
||||
name="publisherName"
|
||||
required="true"
|
||||
value="#{SciCmsPublisherCreateStep.publisherName}"
|
||||
/>
|
||||
|
||||
<bootstrap:formGroupText
|
||||
help="#{SciPublicationsUiMessageBundle['publisher.createform.place.help']}"
|
||||
inputId="publisherName"
|
||||
label="#{SciPublicationsUiMessageBundle['publisher.createform.place.label']}"
|
||||
name="place"
|
||||
value="#{SciCmsPublisherCreateStep.place}"
|
||||
/>
|
||||
|
||||
<a class="btn btn-warning"
|
||||
href="#{mvc.basePath}/#{SciCmsPublisherCreateStep.contentSectionLabel}/assetsfolders/#{SciCmsPublisherCreateStep.folderPath}">
|
||||
#{CmsAssetsStepsDefaultMessagesBundle['createform.cancel']}
|
||||
</a>
|
||||
<button class="btn btn-success"
|
||||
type="submit">
|
||||
#{CmsAssetsStepsDefaultMessagesBundle['createform.submit']}
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</ui:define>
|
||||
|
||||
</ui:composition>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,98 @@
|
|||
<!DOCTYPE html [<!ENTITY times '×'>]>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||
xmlns:bootstrap="http://xmlns.jcp.org/jsf/composite/components/bootstrap"
|
||||
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
|
||||
xmlns:libreccm="http://xmlns.jcp.org/jsf/composite/components/libreccm"
|
||||
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
|
||||
|
||||
<ui:composition template="/WEB-INF/views/org/librecms/ui/contentsection/assets/editstep.xhtml">
|
||||
|
||||
<ui:param name="stepControllerUrl"
|
||||
value="@publisher-edit"
|
||||
/>
|
||||
<ui:param name="title"
|
||||
value="#{SciPublicationsUiMessageBundle.getMessage('publisher.editstep.header', [MvcAssetEditStepModel.name])}"
|
||||
/>
|
||||
|
||||
<ui:define name="editStep">
|
||||
<h3>#{SciPublicationsUiMessageBundle['publisher.editstep.properties.header']}</h3>
|
||||
|
||||
<c:if test="#{MvcAssetEditStepModel.canEdit}">
|
||||
<div class="text-right">
|
||||
<button class="btn btn-primary"
|
||||
data-toggle="modal"
|
||||
data-target="#properties-edit-dialog"
|
||||
type="button">
|
||||
<bootstrap:svgIcon icon="pen" />
|
||||
<span class="sr-only">#{SciPublicationsUiMessageBundle['publisher.editstep.properties.edit']}</span>
|
||||
</button>
|
||||
</div>
|
||||
<div aria-hidden="true"
|
||||
aria-labelledby="properties-edit-dialog-title"
|
||||
class="modal fade"
|
||||
id="properties-edit-dialog"
|
||||
tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
<form action="#{mvc.basePath}/#{ContentSectionModel.sectionName}/assets/#{CmsSelectedAssetModel.assetPath}/@publisher-edit/properties"
|
||||
class="modal-content"
|
||||
method="post">
|
||||
<div class="modal-header">
|
||||
<h4 class="modal-title"
|
||||
id="properties-edit-dialog-title">
|
||||
#{SciPublicationsUiMessageBundle['publisher.editstep.properties.edit.title']}
|
||||
</h4>
|
||||
<button
|
||||
aria-label="#{SciPublicationsUiMessageBundle['publisher.editstep.properties.edit.close']}"
|
||||
class="close"
|
||||
data-dismiss="modal"
|
||||
type="button">
|
||||
<bootstrap:svgIcon icon="x" />
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<bootstrap:formGroupText
|
||||
help="#{SciPublicationsUiMessageBundle['publisher.editstep.properties.edit.publishername.help']}"
|
||||
inputId="publisherName"
|
||||
label="#{SciPublicationsUiMessageBundle['publisher.editstep.properties.edit.publishername.label']}"
|
||||
name="publisherName"
|
||||
value="#{SciCmsPublisherEditStepModel.publisherName}"
|
||||
/>
|
||||
<bootstrap:formGroupText
|
||||
help="#{SciPublicationsUiMessageBundle['publisher.editstep.properties.edit.place.help']}"
|
||||
inputId="place"
|
||||
label="#{SciPublicationsUiMessageBundle['publisher.editstep.properties.edit.place.label']}"
|
||||
name="place"
|
||||
value="#{SciCmsPublisherEditStepModel.place}"
|
||||
/>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button class="btn btn-warning"
|
||||
data-dismiss="modal"
|
||||
type="button">
|
||||
#{SciPublicationsUiMessageBundle['publisher.editstep.properties.edit.close']}
|
||||
</button>
|
||||
<button class="btn btn-success"
|
||||
type="submit">
|
||||
#{SciPublicationsUiMessageBundle['publisher.editstep.properties.edit.submit']}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</c:if>
|
||||
<dl>
|
||||
<div>
|
||||
<dt>#{SciPublicationsUiMessageBundle['publisher.editstep.properties.publishername.label']}</dt>
|
||||
<dd>#{SciCmsPublisherEditStepModel.publisherName}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>#{SciPublicationsUiMessageBundle['publisher.editstep.properties.place.label']}</dt>
|
||||
<dd>#{SciCmsPublisherEditStepModel.place}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
|
||||
</ui:define>
|
||||
|
||||
</ui:composition>
|
||||
|
||||
</html>
|
||||
|
|
@ -1,3 +1,21 @@
|
|||
|
||||
publisher.label=Publisher
|
||||
publisher.description=A publisher record that holds the information about a publisher.
|
||||
publisher.createstep.publishername.error.missing=The name of the publisher is missing.
|
||||
publisher.createform.title=Create a new publisher
|
||||
publisher.createform.publishername.help=The name of the publisher.
|
||||
publisher.createform.publishername.label=Publisher name
|
||||
publisher.createform.place.help=The place of the publisher.
|
||||
publisher.createform.place.label=Place
|
||||
publisher.editstep.header=Edit publisher {0}
|
||||
publisher.editstep.properties.header=Properties
|
||||
publisher.editstep.properties.edit=Edit properties
|
||||
publisher.editstep.properties.edit.title=Edit properties
|
||||
publisher.editstep.properties.edit.close=Cancel
|
||||
publisher.editstep.properties.edit.publishername.help=The name of the publisher.
|
||||
publisher.editstep.properties.edit.publishername.label=Publisher name
|
||||
publisher.editstep.properties.edit.place.help=The place of the publisher.
|
||||
publisher.editstep.properties.edit.place.label=Place
|
||||
publisher.editstep.properties.edit.submit=Save
|
||||
publisher.editstep.properties.publishername.label=Publisher name
|
||||
publisher.editstep.properties.place.label=Place
|
||||
|
|
|
|||
|
|
@ -1,3 +1,21 @@
|
|||
|
||||
publisher.label=Verlag
|
||||
publisher.description=Ein Verlag.
|
||||
publisher.createstep.publishername.error.missing=Der Name des Verlages wurde nicht angegeben.
|
||||
publisher.createform.title=Einen neuen Verlag anlegen
|
||||
publisher.createform.publishername.help=Der Name des Verlages.
|
||||
publisher.createform.publishername.label=Name des Verlages
|
||||
publisher.createform.place.help=Der Ort des Verlages.
|
||||
publisher.createform.place.label=Ort
|
||||
publisher.editstep.header=Verlag {0} bearbeiten
|
||||
publisher.editstep.properties.header=Eigenschaften
|
||||
publisher.editstep.properties.edit=Eigenschaften bearbeiten
|
||||
publisher.editstep.properties.edit.title=Eigenschaften bearbeiten
|
||||
publisher.editstep.properties.edit.close=Abbrechen
|
||||
publisher.editstep.properties.edit.publishername.help=Der Name des Verlages.
|
||||
publisher.editstep.properties.edit.publishername.label=Name des Verlages
|
||||
publisher.editstep.properties.edit.place.help=Der Ort des Verlages.
|
||||
publisher.editstep.properties.edit.place.label=Ort
|
||||
publisher.editstep.properties.edit.submit=Speichern
|
||||
publisher.editstep.properties.publishername.label=Name des Verlages
|
||||
publisher.editstep.properties.place.label=Ort
|
||||
|
|
|
|||
|
|
@ -246,6 +246,14 @@
|
|||
<include>WEB-INF/</include>
|
||||
</includes>
|
||||
</overlay>
|
||||
<overlay>
|
||||
<groupId>org.scientificcms</groupId>
|
||||
<artifactId>sci-publications</artifactId>
|
||||
<type>jar</type>
|
||||
<includes>
|
||||
<include>WEB-INF/</include>
|
||||
</includes>
|
||||
</overlay>
|
||||
</overlays>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
|
|
|||
Loading…
Reference in New Issue