Bugfixes for adding a contact to a SciProject

pull/1/head
Jens Pelzetter 2022-05-09 20:16:44 +02:00
parent f194231550
commit c198617f0d
5 changed files with 48 additions and 15 deletions

View File

@ -1,6 +1,7 @@
package org.scientificcms.contenttypes.sciproject.ui;
import org.librecms.assets.ContactableEntity;
import org.librecms.assets.Organization;
import org.librecms.assets.Person;
import java.util.ArrayList;
import java.util.Collections;
@ -39,8 +40,10 @@ public class SciProjectDescriptionContactsModel {
this.contacts = new ArrayList<>(contacts);
}
public String getContactableType() {
return ContactableEntity.class.getName();
public String getContactableTypes() {
return String.join(
",", Person.class.getName(), Organization.class.getName()
);
}
public String getBaseUrl() {

View File

@ -18,11 +18,14 @@
*/
package org.scientificcms.contenttypes.sciproject.ui;
import org.libreccm.api.Identifier;
import org.libreccm.api.IdentifierParser;
import org.libreccm.l10n.GlobalizationHelper;
import org.libreccm.security.AuthorizationRequired;
import org.libreccm.ui.BaseUrl;
import org.librecms.assets.ContactableEntity;
import org.librecms.assets.Person;
import org.librecms.contentsection.Asset;
import org.librecms.contentsection.AssetRepository;
import org.librecms.contentsection.ContentItemRepository;
import org.librecms.ui.contentsections.ContentSectionNotFoundException;
@ -83,8 +86,8 @@ public class SciProjectDescriptionStep extends AbstractMvcAuthoringStep {
@Inject
private AssetRepository assetRepo;
@Inject
@Inject
private BaseUrl baseUrl;
@Inject
@ -99,9 +102,12 @@ public class SciProjectDescriptionStep extends AbstractMvcAuthoringStep {
@Inject
private GlobalizationHelper globalizationHelper;
@Inject
private IdentifierParser identifierParser;
@Context
private HttpServletRequest request;
@Inject
private ItemPermissionChecker itemPermissionChecker;
@ -362,15 +368,34 @@ public class SciProjectDescriptionStep extends AbstractMvcAuthoringStep {
}
if (itemPermissionChecker.canEditItem(getProject())) {
final Optional<ContactableEntity> result = assetRepo
.findByUuidAndType(contactableUuid, ContactableEntity.class);
final Optional<Asset> result;
final Identifier identifier = identifierParser.parseIdentifier(
contactableUuid
);
switch (identifier.getType()) {
case ID:
result = assetRepo.findById(
Long.parseLong(identifier.getIdentifier())
);
break;
case UUID:
result = assetRepo.findByUuid(
identifier.getIdentifier()
);
break;
default:
models.put("contactableNotFound", contactableUuid);
return showStep(sectionIdentifier, documentPath);
}
if (!result.isPresent()) {
if (!result.isPresent()
|| !(result.get() instanceof ContactableEntity)) {
models.put("contactableNotFound", contactableUuid);
return showStep(sectionIdentifier, documentPath);
}
final ContactableEntity contactable = result.get();
final ContactableEntity contactable = (ContactableEntity) result
.get();
projectManager.addContact(contactable, getProject(), type);
return buildRedirectPathForStep();

View File

@ -13,6 +13,12 @@
<ui:define name="authoringStep">
<h2>#{SciProjectMessageBundle['description_step.header']}</h2>
<c:if test="#{contactableNotFound != null}">
<div class="alert alert-warning">
#{SciProjectMessageBundle.getMessage('description_step.errors.contactable_not_found', [contactableNotFound])}
</div>
</c:if>
<librecms:cmsEditorVariants
addButtonLabel="#{SciProjectMessageBundle['description.editor.add_variant']}"
addDialogLocaleSelectHelp="#{SciProjectMessageBundle['description.editor.add.locale.help']}"
@ -43,7 +49,7 @@
</div>
<librecms:assetPicker
actionUrl="#{mvc.basePath}/#{ContentSectionModel.sectionName}/documents/#{CmsSelectedDocumentModel.itemPath}/@sciproject-description/contacts/add"
assetType="#{SciProjectDescriptionContacts.contactableType}"
assetType="#{SciProjectDescriptionContacts.contactableTypes}"
assetPickerId="contacts-picker"
baseUrl="#{SciProjectDescriptionContacts.baseUrl}"
contentSection="#{ContentSectionModel.sectionName}"
@ -60,8 +66,6 @@
<p>#{SciProjectMessageBundle['contacts.none']}</p>
</c:when>
<c:otherwise>
<table>
<thead>
<tr>
@ -153,10 +157,9 @@
<div class="mb-2">
<div class="text-right">
<librecms:assetPickerButton
assetPickerId="contacts-picker"
assetPickerId="members-picker"
buttonIcon="plus-circle"
buttonText="#{SciProjectMessageBundle['memberships.add_button.label']}"
/>
</div>
</div>

View File

@ -171,3 +171,4 @@ authoringsteps.projectdescription.description=Detailed description of the resear
authoringsteps.projectdescription.label=Description
memberships.none=No memberships assigned yet.
contacts.none=No contacts assigned yet.
description_step.errors.contactable_not_found=Selected contactable entity {0} not found.

View File

@ -171,3 +171,4 @@ authoringsteps.projectdescription.description=Ausf\u00fchrliche Beschreibung des
authoringsteps.projectdescription.label=Beschreibung
memberships.none=Es wurden noch keine Mitglieder hinzugef\u00fcgt.
contacts.none=Es wurden noch keine Kontakte hinzugef\u00fcgt.
description_step.errors.contactable_not_found=Die als Kontakt ausgew\u00e4hlte Entity {0} wurde nicht gefunden.