Java part of UI for Publisher asset

pull/1/head
Jens Pelzetter 2022-05-24 20:37:57 +02:00
parent 236866d93e
commit e892273c02
8 changed files with 377 additions and 4 deletions

View File

@ -8,8 +8,11 @@ package org.scientificcms.publications.assets;
import org.hibernate.envers.Audited; import org.hibernate.envers.Audited;
import org.librecms.assets.AssetType; import org.librecms.assets.AssetType;
import org.librecms.contentsection.Asset; import org.librecms.contentsection.Asset;
import org.librecms.ui.contentsections.assets.MvcAssetEditKit;
import org.scientificcms.publications.Publisher; import org.scientificcms.publications.Publisher;
import org.scientificcms.publications.SciPublicationsConstants; import org.scientificcms.publications.SciPublicationsConstants;
import org.scientificcms.publications.ui.assets.PublisherCreateStep;
import org.scientificcms.publications.ui.assets.PublisherEditStep;
import java.util.Objects; import java.util.Objects;
@ -36,6 +39,10 @@ import static org.scientificcms.publications.SciPublicationsConstants.*;
descriptionBundle = SciPublicationsConstants.BUNDLE, descriptionBundle = SciPublicationsConstants.BUNDLE,
descriptionKey = "publisher.description" descriptionKey = "publisher.description"
) )
@MvcAssetEditKit(
createStep = PublisherCreateStep.class,
editStep = PublisherEditStep.class
)
public class PublisherAsset extends Asset { public class PublisherAsset extends Asset {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;

View File

@ -0,0 +1,16 @@
package org.scientificcms.publications.ui;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public final class SciPublicationsUiConstants {
public static final String BUNDLE
= "org.scientificcms.publications.ui.SciPublicationsBundle";
private SciPublicationsUiConstants() {
// Nothing
}
}

View File

@ -0,0 +1,104 @@
/*
* Copyright (C) 2022 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.assets;
import org.libreccm.l10n.GlobalizationHelper;
import org.librecms.ui.contentsections.assets.AbstractMvcAssetCreateStep;
import org.scientificcms.publications.Publisher;
import org.scientificcms.publications.PublisherRepository;
import org.scientificcms.publications.assets.PublisherAsset;
import org.scientificcms.publications.ui.SciPublicationsUiConstants;
import java.util.Map;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;
import javax.transaction.Transactional;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
@Named("SciCmsPublisherCreateStep")
public class PublisherCreateStep
extends AbstractMvcAssetCreateStep<PublisherAsset> {
@Inject
private GlobalizationHelper globalizationHelper;
@Inject
private PublisherRepository publisherRepo;
@Override
public String showCreateStep() {
return "org/scientificcms/assets/publisher/ui/create-publisher.xhtml";
}
@Override
public String getLabel() {
return globalizationHelper
.getLocalizedTextsUtil(getBundle())
.getText("publisher.label");
}
@Override
public String getDescription() {
return globalizationHelper
.getLocalizedTextsUtil(getBundle())
.getText("publisher.description");
}
@Override
public String getBundle() {
return SciPublicationsUiConstants.BUNDLE;
}
@Override
protected Class<PublisherAsset> getAssetClass() {
return PublisherAsset.class;
}
@Override
@Transactional(Transactional.TxType.REQUIRED)
protected String setAssetProperties(
final PublisherAsset publisherAsset,
final Map<String, String[]> formParams
) {
final Publisher publisher = new Publisher();
publisher.setName(formParams.get("name")[0]);
if (formParams.get("place") != null
&& formParams.get("place").length > 0) {
publisher.setPlace(formParams.get("place")[0]);
}
publisherRepo.save(publisher);
publisherAsset.setPublisher(publisher);
return String.format(
"redirect:/%s/assets/%s/%s/@publisher-edit",
getContentSectionLabel(),
getFolderPath(),
getName()
);
}
}

View File

@ -0,0 +1,204 @@
/*
* Copyright (C) 2022 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.assets;
import org.libreccm.api.IdentifierParser;
import org.libreccm.l10n.GlobalizationHelper;
import org.libreccm.security.AuthorizationRequired;
import org.librecms.contentsection.AssetRepository;
import org.librecms.ui.contentsections.AssetPermissionsChecker;
import org.librecms.ui.contentsections.ContentSectionNotFoundException;
import org.librecms.ui.contentsections.assets.AbstractMvcAssetEditStep;
import org.librecms.ui.contentsections.assets.AssetNotFoundException;
import org.librecms.ui.contentsections.assets.AssetStepsDefaultMessagesBundle;
import org.librecms.ui.contentsections.assets.AssetUi;
import org.librecms.ui.contentsections.assets.MvcAssetEditStep;
import org.librecms.ui.contentsections.assets.MvcAssetEditStepDef;
import org.librecms.ui.contentsections.assets.MvcAssetEditSteps;
import org.scientificcms.publications.Publisher;
import org.scientificcms.publications.PublisherRepository;
import org.scientificcms.publications.assets.PublisherAsset;
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;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
@Path(MvcAssetEditSteps.PATH_PREFIX + "publisher-edit")
@Controller
@MvcAssetEditStepDef(
bundle = SciPublicationsUiConstants.BUNDLE,
descriptionKey = "publisher.editstep.description",
labelKey = "publisher.editstep.label",
supportedAssetType = PublisherAsset.class
)
public class PublisherEditStep extends AbstractMvcAssetEditStep {
@Inject
private AssetPermissionsChecker assetPermissionsChecker;
@Inject
private AssetStepsDefaultMessagesBundle messageBundle;
@Inject
private AssetRepository assetRepo;
@Inject
private AssetUi assetUi;
private GlobalizationHelper globalizationHelper;
@Context
private HttpServletRequest request;
@Inject
private IdentifierParser identifierParser;
@Inject
private Models models;
@Inject
private PublisherRepository publisherRepo;
@Inject
private PublisherEditStepModel editStepModel;
@Override
public Class<? extends MvcAssetEditStep> getStepClass() {
return PublisherEditStep.class;
}
@Override
@Transactional(Transactional.TxType.REQUIRED)
protected void init() throws ContentSectionNotFoundException,
AssetNotFoundException {
super.init();
if (getAsset() instanceof PublisherAsset) {
final Publisher publisher = getPublisher();
editStepModel.setName(publisher.getName());
editStepModel.setPlace(publisher.getPlace());
} else {
throw new AssetNotFoundException(
assetUi.showAssetNotFound(
getContentSection(), getAssetPath()
),
String.format(
"No PublisherAsset for path %s found in section %s.",
getAssetPath(),
getContentSection().getLabel()
)
);
}
}
protected PublisherAsset getPublisherAsset() {
return (PublisherAsset) getAsset();
}
protected Publisher getPublisher() {
return getPublisherAsset().getPublisher();
}
@GET
@Path("/")
@AuthorizationRequired
@Transactional(Transactional.TxType.REQUIRED)
@Override
public String showStep(
@PathParam(MvcAssetEditSteps.SECTION_IDENTIFIER_PATH_PARAM)
final String sectionIdentifier,
@PathParam(MvcAssetEditSteps.ASSET_PATH_PATH_PARAM_NAME)
final String assetPath
) {
try {
init();
} catch (ContentSectionNotFoundException ex) {
return ex.showErrorMessage();
} catch (AssetNotFoundException ex) {
return ex.showErrorMessage();
}
if (assetPermissionsChecker.canEditAsset(getAsset())) {
return "org/scientificcms/assets/publisher/ui/edit-publisher.xhtml";
} else {
return assetUi.showAccessDenied(
getContentSection(),
getAsset(),
messageBundle.get("asset.edit.denied"));
}
}
@POST
@Path("/properties")
@AuthorizationRequired
@Transactional(Transactional.TxType.REQUIRED)
public String updateProperties(
@PathParam(MvcAssetEditSteps.SECTION_IDENTIFIER_PATH_PARAM)
final String sectionIdentifier,
@PathParam(MvcAssetEditSteps.ASSET_PATH_PATH_PARAM_NAME)
final String assetPath,
@FormParam("name")
final String name,
@FormParam("place")
final String place
) {
try {
init();
} catch (ContentSectionNotFoundException ex) {
return ex.showErrorMessage();
} catch (AssetNotFoundException ex) {
return ex.showErrorMessage();
}
if (assetPermissionsChecker.canEditAsset(getAsset())) {
final PublisherAsset publisherAsset = getPublisherAsset();
final Publisher publisher = getPublisher();
publisherAsset.setDisplayName(name);
publisher.setName(name);
publisher.setPlace(place);
assetRepo.save(publisherAsset);
publisherRepo.save(publisher);
return buildRedirectPathForStep();
} else {
return assetUi.showAccessDenied(
getContentSection(),
getAsset(),
messageBundle.get("asset.edit.denied"));
}
}
}

View File

@ -0,0 +1,36 @@
package org.scientificcms.publications.ui.assets;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
@Named("SciCmsPublisherEditStepModel")
public class PublisherEditStepModel {
private String name;
private String place;
public String getName() {
return name;
}
public void setName(final String name) {
this.name = name;
}
public String getPlace() {
return place;
}
public void setPlace(final String place) {
this.place = place;
}
}

View File

@ -0,0 +1,3 @@
publisher.label=Publisher
publisher.description=A publisher record that holds the information about a publisher.

View File

@ -0,0 +1,3 @@
publisher.label=Verlag
publisher.description=Ein Verlag.

View File

@ -54,11 +54,11 @@
<artifactId>ccm-cms-js</artifactId> <artifactId>ccm-cms-js</artifactId>
<version>7.0.0-SNAPSHOT</version> <version>7.0.0-SNAPSHOT</version>
</dependency> --> </dependency> -->
<dependency> <!-- <dependency>
<groupId>org.librecms</groupId> <groupId>org.librecms</groupId>
<artifactId>ccm-cms-tinymce</artifactId> <artifactId>ccm-cms-tinymce</artifactId>
<version>${project.parent.version}</version> <version>${project.parent.version}</version>
</dependency> </dependency>-->
</dependencies> </dependencies>
<build> <build>
@ -222,14 +222,14 @@
<include>templates/</include> <include>templates/</include>
</includes> </includes>
</overlay> </overlay>
<overlay> <!-- <overlay>
<groupId>org.librecms</groupId> <groupId>org.librecms</groupId>
<artifactId>ccm-cms-tinymce</artifactId> <artifactId>ccm-cms-tinymce</artifactId>
<type>jar</type> <type>jar</type>
<includes> <includes>
<include>scripts/</include> <include>scripts/</include>
</includes> </includes>
</overlay> </overlay>-->
<overlay> <overlay>
<groupId>org.scientificcms</groupId> <groupId>org.scientificcms</groupId>
<artifactId>sci-types-project</artifactId> <artifactId>sci-types-project</artifactId>