Controller for the properties step of InProceedings publication
parent
1209d799d1
commit
458b1b21fd
|
|
@ -0,0 +1,501 @@
|
|||
package org.scientificcms.publications.ui.contenttypes;
|
||||
|
||||
import org.libreccm.api.Identifier;
|
||||
import org.libreccm.api.IdentifierParser;
|
||||
import org.libreccm.l10n.GlobalizationHelper;
|
||||
import org.libreccm.security.AuthorizationRequired;
|
||||
import org.librecms.ui.contentsections.ContentSectionNotFoundException;
|
||||
import org.librecms.ui.contentsections.ItemPermissionChecker;
|
||||
import org.librecms.ui.contentsections.documents.DocumentNotFoundException;
|
||||
import org.librecms.ui.contentsections.documents.DocumentUi;
|
||||
import org.librecms.ui.contentsections.documents.MvcAuthoringStepDef;
|
||||
import org.librecms.ui.contentsections.documents.MvcAuthoringSteps;
|
||||
import org.scientificcms.publications.InProceedings;
|
||||
import org.scientificcms.publications.Proceedings;
|
||||
import org.scientificcms.publications.ProceedingsManager;
|
||||
import org.scientificcms.publications.PublicationRepository;
|
||||
import org.scientificcms.publications.contenttypes.ArticleInCollectedVolumeItem;
|
||||
import org.scientificcms.publications.contenttypes.InProceedingsItem;
|
||||
import org.scientificcms.publications.ui.SciPublicationsUiConstants;
|
||||
import org.scientificcms.publications.ui.SciPublicationsUiMessageBundle;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.mvc.Controller;
|
||||
import javax.mvc.Models;
|
||||
import javax.transaction.Transactional;
|
||||
import javax.ws.rs.DefaultValue;
|
||||
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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RequestScoped
|
||||
@Path(
|
||||
MvcAuthoringSteps.PATH_PREFIX
|
||||
+ InProceedingsPropertiesStep.EDIT_STEP_URL_FRAGMENT
|
||||
)
|
||||
@Controller
|
||||
@MvcAuthoringStepDef(
|
||||
bundle = SciPublicationsUiConstants.BUNDLE,
|
||||
descriptionKey = "authoringsteps.basicproperties.description",
|
||||
labelKey = "authoringsteps.basicproperties.label",
|
||||
supportedDocumentType = ArticleInCollectedVolumeItem.class
|
||||
)
|
||||
public class InProceedingsPropertiesStep
|
||||
extends AbstractPublicationPropertiesStep<InProceedingsItem, InProceedings> {
|
||||
|
||||
public static final String EDIT_STEP_URL_FRAGMENT
|
||||
= "inproceedings-basicproperties";
|
||||
|
||||
@Inject
|
||||
private ProceedingsManager proceedingsManager;
|
||||
|
||||
@Inject
|
||||
private DocumentUi documentUi;
|
||||
|
||||
@Inject
|
||||
private GlobalizationHelper globalizationHelper;
|
||||
|
||||
@Inject
|
||||
private IdentifierParser identifierParser;
|
||||
|
||||
@Inject
|
||||
private ItemPermissionChecker itemPermissionChecker;
|
||||
|
||||
@Inject
|
||||
private Models models;
|
||||
|
||||
@Inject
|
||||
private InProceedingsPropertiesStepModel propertiesStepModel;
|
||||
|
||||
@Inject
|
||||
private PublicationRepository publicationRepo;
|
||||
|
||||
@Inject
|
||||
private SciPublicationsUiMessageBundle messageBundle;
|
||||
|
||||
@Override
|
||||
public Class<InProceedingsPropertiesStep> getStepClass() {
|
||||
return InProceedingsPropertiesStep.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEditStepUrlFragment() {
|
||||
return EDIT_STEP_URL_FRAGMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getStepTemplatePath() {
|
||||
return "org/scientificcms/contenttypes/ui/inproceedings/edit-inproceedings.xhtml";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<InProceedings> getPublicationClass() {
|
||||
return InProceedings.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public void init() throws ContentSectionNotFoundException,
|
||||
DocumentNotFoundException {
|
||||
super.init();
|
||||
|
||||
propertiesStepModel.setEndPage(getPublication().getEndPage());
|
||||
|
||||
propertiesStepModel.setProceedingsTitle(
|
||||
Optional
|
||||
.ofNullable(getPublication().getProceedings())
|
||||
.map(Proceedings::getTitle)
|
||||
.map(globalizationHelper::getValueFromLocalizedString)
|
||||
.orElse(null)
|
||||
);
|
||||
|
||||
propertiesStepModel.setStartPage(getPublication().getStartPage());
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/")
|
||||
@AuthorizationRequired
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
@Override
|
||||
public String showStep(
|
||||
@PathParam(MvcAuthoringSteps.SECTION_IDENTIFIER_PATH_PARAM)
|
||||
final String sectionIdentifier,
|
||||
@PathParam(MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM_NAME)
|
||||
final String documentPath
|
||||
) {
|
||||
return super.showStep(sectionIdentifier, documentPath);
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/name")
|
||||
@AuthorizationRequired
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
@Override
|
||||
public String updateName(
|
||||
@PathParam(MvcAuthoringSteps.SECTION_IDENTIFIER_PATH_PARAM)
|
||||
final String sectionIdentifier,
|
||||
@PathParam(MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM_NAME)
|
||||
final String documentPath,
|
||||
@FormParam("name") @DefaultValue("")
|
||||
final String name
|
||||
) {
|
||||
return super.updateName(sectionIdentifier, documentPath, name);
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/title/@add")
|
||||
@AuthorizationRequired
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
@Override
|
||||
public String addTitle(
|
||||
@PathParam(MvcAuthoringSteps.SECTION_IDENTIFIER_PATH_PARAM)
|
||||
final String sectionIdentifier,
|
||||
@PathParam(MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM_NAME)
|
||||
final String documentPath,
|
||||
@FormParam("locale") final String localeParam,
|
||||
@FormParam("value") final String value
|
||||
) {
|
||||
return super.addTitle(
|
||||
sectionIdentifier,
|
||||
documentPath,
|
||||
localeParam,
|
||||
value
|
||||
);
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/title/@edit/{locale}")
|
||||
@AuthorizationRequired
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
@Override
|
||||
public String editTitle(
|
||||
@PathParam(MvcAuthoringSteps.SECTION_IDENTIFIER_PATH_PARAM)
|
||||
final String sectionIdentifier,
|
||||
@PathParam(MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM_NAME)
|
||||
final String documentPath,
|
||||
@PathParam("locale") final String localeParam,
|
||||
@FormParam("value") final String value
|
||||
) {
|
||||
return super.editTitle(
|
||||
sectionIdentifier,
|
||||
documentPath,
|
||||
localeParam,
|
||||
value
|
||||
);
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/title/@remove/{locale}")
|
||||
@AuthorizationRequired
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
@Override
|
||||
public String removeTitle(
|
||||
@PathParam(MvcAuthoringSteps.SECTION_IDENTIFIER_PATH_PARAM)
|
||||
final String sectionIdentifier,
|
||||
@PathParam(MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM_NAME)
|
||||
final String documentPath,
|
||||
@PathParam("locale") final String localeParam
|
||||
) {
|
||||
return super.removeTitle(sectionIdentifier, documentPath, localeParam);
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/shortdescription/@add")
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
@Override
|
||||
public String addShortDescription(
|
||||
@PathParam(MvcAuthoringSteps.SECTION_IDENTIFIER_PATH_PARAM)
|
||||
final String sectionIdentifier,
|
||||
@PathParam(MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM_NAME)
|
||||
final String documentPath,
|
||||
@FormParam("locale") final String localeParam,
|
||||
@FormParam("value") final String value
|
||||
) {
|
||||
return super.addShortDescription(
|
||||
sectionIdentifier,
|
||||
documentPath,
|
||||
localeParam,
|
||||
value
|
||||
);
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/shortdescription/@edit/{locale}")
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
@Override
|
||||
public String editShortDescription(
|
||||
@PathParam(MvcAuthoringSteps.SECTION_IDENTIFIER_PATH_PARAM)
|
||||
final String sectionIdentifier,
|
||||
@PathParam(MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM_NAME)
|
||||
final String documentPath,
|
||||
@PathParam("locale") final String localeParam,
|
||||
@FormParam("value") final String value
|
||||
) {
|
||||
return super.editShortDescription(
|
||||
sectionIdentifier,
|
||||
documentPath,
|
||||
localeParam,
|
||||
value
|
||||
);
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/shortdescription/@remove/{locale}")
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
@Override
|
||||
public String removeShortDescription(
|
||||
@PathParam(MvcAuthoringSteps.SECTION_IDENTIFIER_PATH_PARAM)
|
||||
final String sectionIdentifier,
|
||||
@PathParam(MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM_NAME)
|
||||
final String documentPath,
|
||||
@PathParam("locale") final String localeParam
|
||||
) {
|
||||
return super.removeShortDescription(
|
||||
sectionIdentifier,
|
||||
documentPath,
|
||||
localeParam
|
||||
);
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/authors")
|
||||
@AuthorizationRequired
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
@Override
|
||||
public String addAuthor(
|
||||
@PathParam(MvcAuthoringSteps.SECTION_IDENTIFIER_PATH_PARAM)
|
||||
final String sectionIdentifier,
|
||||
@PathParam(MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM_NAME)
|
||||
final String documentPath,
|
||||
@FormParam("authorIdentifier")
|
||||
final String authorIdentifier,
|
||||
@FormParam("editor")
|
||||
final String editorParam
|
||||
) {
|
||||
return super.addAuthor(
|
||||
sectionIdentifier,
|
||||
documentPath,
|
||||
authorIdentifier,
|
||||
editorParam
|
||||
);
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/authors/{authorshipUuid}")
|
||||
@AuthorizationRequired
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
@Override
|
||||
public String editAuthorship(
|
||||
@PathParam(MvcAuthoringSteps.SECTION_IDENTIFIER_PATH_PARAM)
|
||||
final String sectionIdentifier,
|
||||
@PathParam(MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM_NAME)
|
||||
final String documentPath,
|
||||
@PathParam("authorshipUuid")
|
||||
final String authorshipUuid,
|
||||
@FormParam("editor")
|
||||
final String editorParam
|
||||
) {
|
||||
return super.editAuthorship(
|
||||
sectionIdentifier,
|
||||
documentPath,
|
||||
authorshipUuid,
|
||||
editorParam
|
||||
);
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/authors/{authorshipUuid}/remove")
|
||||
@AuthorizationRequired
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
@Override
|
||||
public String removeAuthorship(
|
||||
@PathParam(MvcAuthoringSteps.SECTION_IDENTIFIER_PATH_PARAM)
|
||||
final String sectionIdentifier,
|
||||
@PathParam(MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM_NAME)
|
||||
final String documentPath,
|
||||
@PathParam("authorshipUuid")
|
||||
final String authorshipUuid
|
||||
) {
|
||||
return super.removeAuthorship(
|
||||
sectionIdentifier,
|
||||
documentPath,
|
||||
authorshipUuid
|
||||
);
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/proceedings")
|
||||
@AuthorizationRequired
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public String setProceedings(
|
||||
@PathParam(MvcAuthoringSteps.SECTION_IDENTIFIER_PATH_PARAM)
|
||||
final String sectionIdentifier,
|
||||
@PathParam(MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM_NAME)
|
||||
final String documentPath,
|
||||
@FormParam("proceedingsIdentifier")
|
||||
final String proceedingsIdentifier
|
||||
) {
|
||||
try {
|
||||
init();
|
||||
} catch (ContentSectionNotFoundException ex) {
|
||||
return ex.showErrorMessage();
|
||||
} catch (DocumentNotFoundException ex) {
|
||||
return ex.showErrorMessage();
|
||||
}
|
||||
|
||||
if (itemPermissionChecker.canEditItem(getDocument())) {
|
||||
final Identifier identifier = identifierParser.parseIdentifier(
|
||||
proceedingsIdentifier
|
||||
);
|
||||
final Optional<Proceedings> proceedingsResult;
|
||||
switch (identifier.getType()) {
|
||||
case ID:
|
||||
proceedingsResult = publicationRepo.findByIdAndType(
|
||||
Long.parseLong(identifier.getIdentifier()),
|
||||
Proceedings.class
|
||||
);
|
||||
break;
|
||||
case UUID:
|
||||
proceedingsResult = publicationRepo.findByUuidAndType(
|
||||
identifier.getIdentifier(),
|
||||
Proceedings.class
|
||||
);
|
||||
break;
|
||||
default:
|
||||
proceedingsResult = Optional.empty();
|
||||
break;
|
||||
}
|
||||
|
||||
if (proceedingsResult.isEmpty()) {
|
||||
return showProceedingsNotFound(
|
||||
sectionIdentifier,
|
||||
documentPath,
|
||||
proceedingsIdentifier
|
||||
);
|
||||
}
|
||||
|
||||
final Proceedings proceedings = proceedingsResult.get();
|
||||
proceedingsManager.addPaperToProceedings(
|
||||
getPublication(),
|
||||
proceedings
|
||||
);
|
||||
|
||||
return buildRedirectPathForStep();
|
||||
} else {
|
||||
return documentUi.showAccessDenied(
|
||||
getContentSection(),
|
||||
getDocument(),
|
||||
getLabel()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/proceedings/remove")
|
||||
@AuthorizationRequired
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public String removeProceedings(
|
||||
@PathParam(MvcAuthoringSteps.SECTION_IDENTIFIER_PATH_PARAM)
|
||||
final String sectionIdentifier,
|
||||
@PathParam(MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM_NAME)
|
||||
final String documentPath
|
||||
) {
|
||||
try {
|
||||
init();
|
||||
} catch (ContentSectionNotFoundException ex) {
|
||||
return ex.showErrorMessage();
|
||||
} catch (DocumentNotFoundException ex) {
|
||||
return ex.showErrorMessage();
|
||||
}
|
||||
|
||||
if (itemPermissionChecker.canEditItem(getDocument())) {
|
||||
if (getPublication().getProceedings() != null) {
|
||||
proceedingsManager.removeArticleFromProceedings(
|
||||
getPublication(),
|
||||
getPublication().getProceedings()
|
||||
);
|
||||
}
|
||||
|
||||
return buildRedirectPathForStep();
|
||||
} else {
|
||||
return documentUi.showAccessDenied(
|
||||
getContentSection(),
|
||||
getDocument(),
|
||||
getLabel()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/properties")
|
||||
@AuthorizationRequired
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public String updateProperties(
|
||||
@PathParam(MvcAuthoringSteps.SECTION_IDENTIFIER_PATH_PARAM)
|
||||
final String sectionIdentifier,
|
||||
@PathParam(MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM_NAME)
|
||||
final String documentPath,
|
||||
@FormParam("yearOfPublication")
|
||||
final String yearOfPublicationParam,
|
||||
@FormParam("startPage")
|
||||
final String startPageParam,
|
||||
@FormParam("endPage")
|
||||
final String endPageParam
|
||||
) {
|
||||
try {
|
||||
init();
|
||||
} catch (ContentSectionNotFoundException ex) {
|
||||
return ex.showErrorMessage();
|
||||
} catch (DocumentNotFoundException ex) {
|
||||
return ex.showErrorMessage();
|
||||
}
|
||||
|
||||
if (itemPermissionChecker.canEditItem(getDocument())) {
|
||||
updateProperties(
|
||||
sectionIdentifier,
|
||||
documentPath,
|
||||
yearOfPublicationParam
|
||||
);
|
||||
|
||||
if (endPageParam.matches("\\d*")) {
|
||||
getPublication().setEndPage(
|
||||
Integer.parseInt(endPageParam)
|
||||
);
|
||||
}
|
||||
|
||||
if (startPageParam.matches("\\d*")) {
|
||||
getPublication().setStartPage(
|
||||
Integer.parseInt(startPageParam)
|
||||
);
|
||||
}
|
||||
|
||||
return buildRedirectPathForStep();
|
||||
} else {
|
||||
return documentUi.showAccessDenied(
|
||||
getContentSection(),
|
||||
getDocument(),
|
||||
messageBundle.getMessage("publication.edit.denied")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private String showProceedingsNotFound(
|
||||
final String sectionIdentifier,
|
||||
final String documentPath,
|
||||
final String proceedingsIdentifier
|
||||
) {
|
||||
models.put("proceedingsNotFound", proceedingsIdentifier);
|
||||
return showStep(sectionIdentifier, documentPath);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue