Create and Edit Step for Organization Assets

pull/10/head
Jens Pelzetter 2021-06-12 14:57:31 +02:00
parent 11d17341a8
commit f7ae8f8238
10 changed files with 326 additions and 5 deletions

View File

@ -21,6 +21,9 @@ package org.librecms.assets;
import com.arsdigita.cms.ui.assets.forms.OrganizationForm;
import org.hibernate.envers.Audited;
import org.librecms.ui.contentsections.assets.MvcAssetEditKit;
import org.librecms.ui.contentsections.assets.OrganizationCreateStep;
import org.librecms.ui.contentsections.assets.OrganizationEditStep;
import java.util.Objects;
@ -41,6 +44,10 @@ import static org.librecms.assets.AssetConstants.*;
labelKey = "organization.label",
descriptionBundle = ASSETS_BUNDLE,
descriptionKey = "organization.description")
@MvcAssetEditKit(
createStep = OrganizationCreateStep.class,
editStep = OrganizationEditStep.class
)
@Entity
@Audited
@Table(name = "ORGANIZATIONS", schema = DB_SCHEMA)

View File

@ -212,7 +212,7 @@ public abstract class AbstractMvcAssetCreateStep<T extends Asset>
"danger",
globalizationHelper
.getLocalizedTextsUtil(getBundle())
.getText("postaladdress.createstep.name.error.invalid")
.getText("createstep.name.error.invalid")
);
return showCreateStep();
}
@ -224,7 +224,7 @@ public abstract class AbstractMvcAssetCreateStep<T extends Asset>
"danger",
globalizationHelper
.getLocalizedTextsUtil(getBundle())
.getText("postaladdress.createstep.title.error.missing")
.getText("createstep.title.error.missing")
);
return showCreateStep();
}

View File

@ -35,6 +35,7 @@ public class CmsAssetEditSteps implements MvcAssetEditSteps {
classes.add(BookmarkEditStep.class);
classes.add(FileAssetEditStep.class);
classes.add(LegalMetadataEditStep.class);
classes.add(OrganizationEditStep.class);
classes.add(PersonEditStep.class);
classes.add(PostalAddressEditStep.class);
classes.add(SideNoteEditStep.class);

View File

@ -0,0 +1,84 @@
/*
* 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.librecms.ui.contentsections.assets;
import org.libreccm.l10n.GlobalizationHelper;
import org.librecms.assets.Organization;
import java.util.Map;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
@Named("CmsOrganizationCreateStep")
public class OrganizationCreateStep extends AbstractMvcAssetCreateStep<Organization> {
@Inject
private GlobalizationHelper globalizationHelper;
@Override
public String showCreateStep() {
return "org/librecms/ui/contentsection/assets/organization/create-organization.xhtml";
}
@Override
public String getLabel() {
return globalizationHelper
.getLocalizedTextsUtil(getBundle())
.getText("organization.label");
}
@Override
public String getDescription() {
return globalizationHelper
.getLocalizedTextsUtil(getBundle())
.getText("organization.description");
}
@Override
public String getBundle() {
return MvcAssetStepsConstants.BUNDLE;
}
@Override
protected Class<Organization> getAssetClass() {
return Organization.class;
}
@Override
protected String setAssetProperties(
final Organization organization, final Map<String, String[]> formParams
) {
organization.setName(formParams.get("name")[0]);
return String.format(
"redirect:/%s/assets/%s/%s/@organization-edit",
getContentSectionLabel(),
getFolderPath(),
getName()
);
}
}

View File

@ -0,0 +1,127 @@
/*
* 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.librecms.ui.contentsections.assets;
import org.libreccm.security.AuthorizationRequired;
import org.librecms.assets.Organization;
import org.librecms.assets.Person;
import org.librecms.contentsection.AssetRepository;
import org.librecms.ui.contentsections.AssetPermissionsChecker;
import org.librecms.ui.contentsections.ContentSectionNotFoundException;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.mvc.Controller;
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(MvcAssetEditSteps.PATH_PREFIX + "organization-edit")
@Controller
@MvcAssetEditStepDef(
bundle = MvcAssetStepsConstants.BUNDLE,
descriptionKey = "organization.editstep.description",
labelKey = "organization.editstep.label",
supportedAssetType = Person.class
)
public class OrganizationEditStep extends AbstractContactableEntityEditStep {
@Inject
private AssetStepsDefaultMessagesBundle messageBundle;
@Inject
private AssetPermissionsChecker assetPermissionsChecker;
@Inject
private AssetRepository assetRepo;
@Inject
private AssetUi assetUi;
@Override
public Class<? extends MvcAssetEditStep> getStepClass() {
return OrganizationEditStep.class;
}
@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/librecms/ui/contentsection/assets/organization/edit-organization.xhtml";
} else {
return assetUi.showAccessDenied(
getContentSection(),
getAsset(),
messageBundle.get("asset.edit.denied"));
}
}
@POST
@Path("/name")
@AuthorizationRequired
@Transactional(Transactional.TxType.REQUIRED)
@Override
public String updateName(
@PathParam(MvcAssetEditSteps.SECTION_IDENTIFIER_PATH_PARAM)
final String sectionIdentifier,
@PathParam(MvcAssetEditSteps.ASSET_PATH_PATH_PARAM_NAME)
final String assetPath,
@FormParam("name") @DefaultValue("") final String name
) {
super.updateName(sectionIdentifier, assetPath, name);
if (assetPermissionsChecker.canEditAsset(getAsset())) {
((Organization) getAsset()).setName(name);
assetRepo.save(getAsset());
return buildRedirectPathForStep();
} else {
return assetUi.showAccessDenied(
getContentSection(),
getAsset(),
messageBundle.get("asset.edit.denied"));
}
}
}

View File

@ -38,9 +38,6 @@ import javax.inject.Inject;
@Named("CmsPersonCreateStep")
public class PersonCreateStep extends AbstractMvcAssetCreateStep<Person> {
@Inject
private AssetRepository assetRepo;
@Inject
private GlobalizationHelper globalizationHelper;

View File

@ -0,0 +1,64 @@
<!DOCTYPE html [<!ENTITY times '&#215;'>]>
<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>#{CmsAssetsStepsDefaultMessagesBundle["organization.createform.title"]}</h1>
<c:forEach items="#{CmsOrganizationCreateStep.messages.entrySet()}"
var="message">
<div class="alert alert-#{message.key}" role="alert">
#{message.value}
</div>
</c:forEach>
<form action="#{mvc.basePath}/#{ContentSectionModel.sectionName}/assets/#{CmsOrganizationCreateStep.folderPath}@create/#{CmsOrganizationCreateStep.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="#{CmsOrganizationCreateStep.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="#{CmsAssetsStepsDefaultMessagesBundle['createform.title.help']}"
inputId="title"
label="#{CmsAssetsStepsDefaultMessagesBundle['createform.title.label']}"
name="title"
required="true"
/>
<a class="btn btn-warning"
href="#{mvc.basePath}/#{ContentSectionModel.sectionName}/assetfolders/#{CmOrganizationCreateStep.folderPath}">
#{CmsAssetsStepsDefaultMessagesBundle['createform.cancel']}
</a>
<button class="btn btn-success"
type="submit">
#{CmsAssetsStepsDefaultMessagesBundle['createform.submit']}
</button>
</form>
</div>
</ui:define>
</ui:composition>
</html>

View File

@ -0,0 +1,29 @@
<!DOCTYPE html [<!ENTITY times '&#215;'>]>
<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="@organization-edit"
/>
<ui:param name="title"
value="#{CmsAssetsStepsDefaultMessagesBundle.getMessage('organization.editstep.header', [MvcAssetEditStepModel.name])}"
/>
<ui:define name="editStep">
<ui:include src="../edit-contactable.xhtml">
<ui:param name="actionBaseUrl"
value="#{mvc.basePath}/#{ContentSectionModel.sectionName}/assets/#{CmsSelectedAssetModel.assetPath}/@organization-edit" />
<ui:param name="contactEntryAction"
value="#{mvc.basePath}/#{ContentSectionModel.sectionName}/assets/#{CmsSelectedAssetModel.assetPath}/@organization-edit/contactentries" />
<ui:param name="postalAddressAction"
value="#{mvc.basePath}/#{ContentSectionModel.sectionName}/assets/#{CmsSelectedAssetModel.assetPath}/@organization-edit/postaladdress" />
</ui:include>
</ui:define>
</ui:composition>
</html>

View File

@ -283,3 +283,9 @@ assetpicker.select=Select asset
assetpicker.column.name=Name
assetpicker.column.type=Type
assetpicker.column.action=Action
organization.label=Organization
organization.description=A record with the contact data of an organization.
organization.editstep.description=Edit an organization.
organization.editstep.label=Edit organization
organization.createform.title=Create new organization
organization.editstep.header=Edit Organization {0}

View File

@ -283,3 +283,9 @@ assetpicker.select=Asset ausw\u00e4hlen
assetpicker.column.name=Name
assetpicker.column.type=Typ
assetpicker.column.action=Aktion
organization.label=Organisation
organization.description=Ein Datensatz mit den Kontaktdaten einer Organization.
organization.editstep.description=Organization bearbeiten.
organization.editstep.label=Organization bearbeiten
organization.createform.title=Neue Organization anlegen
organization.editstep.header=Organization {0} bearbeiten