Bugfixes for adding a contact to a SciProject
parent
f194231550
commit
c198617f0d
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -99,6 +102,9 @@ public class SciProjectDescriptionStep extends AbstractMvcAuthoringStep {
|
|||
@Inject
|
||||
private GlobalizationHelper globalizationHelper;
|
||||
|
||||
@Inject
|
||||
private IdentifierParser identifierParser;
|
||||
|
||||
@Context
|
||||
private HttpServletRequest request;
|
||||
|
||||
|
|
@ -362,15 +368,34 @@ public class SciProjectDescriptionStep extends AbstractMvcAuthoringStep {
|
|||
}
|
||||
|
||||
if (itemPermissionChecker.canEditItem(getProject())) {
|
||||
final Optional<ContactableEntity> result = assetRepo
|
||||
.findByUuidAndType(contactableUuid, ContactableEntity.class);
|
||||
|
||||
if (!result.isPresent()) {
|
||||
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);
|
||||
}
|
||||
|
||||
final ContactableEntity contactable = result.get();
|
||||
if (!result.isPresent()
|
||||
|| !(result.get() instanceof ContactableEntity)) {
|
||||
models.put("contactableNotFound", contactableUuid);
|
||||
return showStep(sectionIdentifier, documentPath);
|
||||
}
|
||||
|
||||
final ContactableEntity contactable = (ContactableEntity) result
|
||||
.get();
|
||||
projectManager.addContact(contactable, getProject(), type);
|
||||
|
||||
return buildRedirectPathForStep();
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Reference in New Issue