Skip to content

Commit

Permalink
#13194 Add a "Survey" Card to the case view - don't allow sending sur…
Browse files Browse the repository at this point in the history
…vay if the case person doesn't have an email address
  • Loading branch information
Levente Gal committed Feb 5, 2025
1 parent bd5aea9 commit 1aa0337
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 22 deletions.
15 changes: 11 additions & 4 deletions sormas-ui/src/main/java/de/symeda/sormas/ui/caze/CaseDataView.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*/
package de.symeda.sormas.ui.caze;

import org.apache.commons.collections4.CollectionUtils;

import com.vaadin.ui.VerticalLayout;

import de.symeda.sormas.api.EditPermissionType;
Expand All @@ -24,6 +26,7 @@
import de.symeda.sormas.api.feature.FeatureType;
import de.symeda.sormas.api.feature.FeatureTypeProperty;
import de.symeda.sormas.api.immunization.ImmunizationListCriteria;
import de.symeda.sormas.api.person.PersonDto;
import de.symeda.sormas.api.sample.SampleAssociationType;
import de.symeda.sormas.api.sample.SampleCriteria;
import de.symeda.sormas.api.selfreport.SelfReportCriteria;
Expand Down Expand Up @@ -226,9 +229,12 @@ protected void initView(String params) {

QuarantineOrderDocumentsComponent.addComponentToLayout(layout, caze, documentList);

PersonDto casePerson = FacadeProvider.getPersonFacade().getByUuid(caze.getPerson().getUuid());
boolean isSendEmailAllowed = CollectionUtils.isNotEmpty(casePerson.getAllEmailAddresses());

if (UiUtil.permitted(FeatureType.EXTERNAL_EMAILS, UserRight.EXTERNAL_EMAIL_SEND)) {
ExternalEmailSideComponent externalEmailSideComponent =
ExternalEmailSideComponent.forCase(caze, isEditAllowed, SormasUI::refreshView, this::showUnsavedChangesPopup);
ExternalEmailSideComponent externalEmailSideComponent = ExternalEmailSideComponent
.forCase(caze, isEditAllowed, caze.getPerson(), isSendEmailAllowed, SormasUI::refreshView, this::showUnsavedChangesPopup);
layout.addSidePanelComponent(new SideComponentLayout(externalEmailSideComponent), EXTERNAL_EMAILS_LOC);
}

Expand All @@ -242,8 +248,9 @@ protected void initView(String params) {
SelfReportListComponentLayout selfReportListComponentLayout = new SelfReportListComponentLayout(selfReportListComponent);
layout.addSidePanelComponent(selfReportListComponentLayout, SELF_REPORT_LOC);

if(UiUtil.permitted(FeatureType.SURVEYS)) {
SurveyListComponentLayout surveyList = new SurveyListComponentLayout(getCaseRef(), isEditAllowed, this::showUnsavedChangesPopup);
if (UiUtil.permitted(FeatureType.SURVEYS)) {
SurveyListComponentLayout surveyList =
new SurveyListComponentLayout(getCaseRef(), isEditAllowed, isSendEmailAllowed, this::showUnsavedChangesPopup);
layout.addSidePanelComponent(surveyList, SURVEYS_LOC);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,17 @@ public class ExternalEmailSideComponent extends SideComponent {
public static ExternalEmailSideComponent forCase(
CaseDataDto caze,
boolean isEditAllowed,
PersonReferenceDto personRef,
boolean isSendAllowed,
Runnable callback,
Consumer<Runnable> sendEmailWrapper) {
return new ExternalEmailSideComponent(
DocumentWorkflow.CASE_EMAIL,
RootEntityType.ROOT_CASE,
DocumentRelatedEntityType.CASE,
caze.toReference(),
caze.getPerson(),
personRef,
isSendAllowed,
Strings.messageCasePersonHasNoEmail,
Strings.messageNoExternalEmailToCaseSent,
new ManualMessageLogCriteria().caze(caze.toReference()),
Expand All @@ -68,7 +71,7 @@ public static ExternalEmailSideComponent forCase(
}

public static ExternalEmailSideComponent forContact(ContactDto contact, boolean isEditAllowed, Consumer<Runnable> sendEmailWrapper) {
return new ExternalEmailSideComponent(
return withPersonRef(
DocumentWorkflow.CONTACT_EMAIL,
RootEntityType.ROOT_CONTACT,
DocumentRelatedEntityType.CONTACT,
Expand All @@ -79,15 +82,14 @@ public static ExternalEmailSideComponent forContact(ContactDto contact, boolean
new ManualMessageLogCriteria().contact(contact.toReference()),
isEditAllowed,
contact.isInJurisdiction(),
null,
sendEmailWrapper);
}

public static ExternalEmailSideComponent forEventParticipant(
EventParticipantDto eventParticipant,
boolean isEditAllowed,
Consumer<Runnable> sendEmailWrapper) {
return new ExternalEmailSideComponent(
return withPersonRef(
DocumentWorkflow.EVENT_PARTICIPANT_EMAIL,
RootEntityType.ROOT_EVENT_PARTICIPANT,
null,
Expand All @@ -98,12 +100,11 @@ public static ExternalEmailSideComponent forEventParticipant(
new ManualMessageLogCriteria().eventParticipant(eventParticipant.toReference()),
isEditAllowed,
eventParticipant.isInJurisdiction(),
null,
sendEmailWrapper);
}

public static ExternalEmailSideComponent forTravelEntry(TravelEntryDto travelEntry, boolean isEditAllowed, Consumer<Runnable> sendEmailWrapper) {
return new ExternalEmailSideComponent(
return withPersonRef(
DocumentWorkflow.TRAVEL_ENTRY_EMAIL,
RootEntityType.ROOT_TRAVEL_ENTRY,
DocumentRelatedEntityType.TRAVEL_ENTRY,
Expand All @@ -114,6 +115,37 @@ public static ExternalEmailSideComponent forTravelEntry(TravelEntryDto travelEnt
new ManualMessageLogCriteria().travelEntry(travelEntry.toReference()),
isEditAllowed,
travelEntry.isInJurisdiction(),
sendEmailWrapper);
}

private static ExternalEmailSideComponent withPersonRef(
DocumentWorkflow documentWorkflow,
RootEntityType rootEntityType,
DocumentRelatedEntityType documentRelatedEntityType,
ReferenceDto rootEntityReference,
PersonReferenceDto personRef,
String noRecipientStringKey,
String noEmailsStringKey,
ManualMessageLogCriteria baseCriteria,
boolean isEditAllowed,
boolean isInJurisdiction,
Consumer<Runnable> sendEmailWrapper) {

PersonDto person = FacadeProvider.getPersonFacade().getByUuid(personRef.getUuid());
boolean isSendAllowed = CollectionUtils.isNotEmpty(person.getAllEmailAddresses());

return new ExternalEmailSideComponent(
documentWorkflow,
rootEntityType,
documentRelatedEntityType,
rootEntityReference,
personRef,
isSendAllowed,
noRecipientStringKey,
noEmailsStringKey,
baseCriteria,
isEditAllowed,
isInJurisdiction,
null,
sendEmailWrapper);
}
Expand All @@ -126,6 +158,7 @@ private ExternalEmailSideComponent(
DocumentRelatedEntityType documentRelatedEntityType,
ReferenceDto rootEntityReference,
PersonReferenceDto personRef,
boolean isSendAllowed,
String noRecipientStringKey,
String noEmailsStringKey,
ManualMessageLogCriteria baseCriteria,
Expand All @@ -150,8 +183,7 @@ private ExternalEmailSideComponent(
UserRight.EXTERNAL_EMAIL_SEND);
}

PersonDto person = FacadeProvider.getPersonFacade().getByUuid(personRef.getUuid());
if (isEditAllowed && CollectionUtils.isEmpty(person.getAllEmailAddresses())) {
if (isEditAllowed && !isSendAllowed) {
if (createButton != null) {
createButton.setEnabled(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,24 @@ public class SurveyListComponentLayout extends SideComponentLayout {

private static final long serialVersionUID = -4364573774979104517L;

public SurveyListComponentLayout(CaseReferenceDto caseRef, boolean isEditAllowed, Consumer<Runnable> actionCallback) {
public SurveyListComponentLayout(CaseReferenceDto caseRef, boolean isEditAllowed, boolean isEmailAllowed, Consumer<Runnable> actionCallback) {
super(
new SurveyListComponent(
I18nProperties.getString(Strings.headingSurveySideComponent),
new SurveyTokenCriteria().caseAssignedTo(caseRef),
actionCallback,
isEditAllowed));
isEditAllowed, isEmailAllowed));
}

private static class SurveyListComponent extends SideComponent {

private static final long serialVersionUID = 4793190763340951494L;

public SurveyListComponent(
String heading,
SurveyTokenCriteria surveyTokenCriteria,
Consumer<Runnable> actionCallback,
boolean isEditAllowed) {
String heading,
SurveyTokenCriteria surveyTokenCriteria,
Consumer<Runnable> actionCallback,
boolean isEditAllowed, boolean isEmailAllowed) {
super(heading, actionCallback);

setWidth(100, Unit.PERCENTAGE);
Expand All @@ -82,12 +82,19 @@ public SurveyListComponent(
uploadLayout.setMargin(true);
uploadLayout.addStyleName(CssStyles.LAYOUT_MINIMAL);

Button sebdSurveyButton = ButtonHelper.createButton(Captions.surveySend, I18nProperties.getCaption(Captions.surveySend), (e) -> {
}, ValoTheme.BUTTON_PRIMARY);
sebdSurveyButton.setWidth(100, Unit.PERCENTAGE);
uploadLayout.addComponent(sebdSurveyButton);
if (isEmailAllowed) {
Button sendSurveyButton = ButtonHelper.createButton(Captions.surveySend, I18nProperties.getCaption(Captions.surveySend), (e) -> {
}, ValoTheme.BUTTON_PRIMARY);
sendSurveyButton.setWidth(100, Unit.PERCENTAGE);
uploadLayout.addComponent(sendSurveyButton);
}

Button generateSurveyDocButton = ButtonHelper.createButton(Captions.surveyGenerate, I18nProperties.getCaption(Captions.surveyGenerate), (e) -> {
});
if( !isEmailAllowed) {
generateSurveyDocButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
}

generateSurveyDocButton.setWidth(100, Unit.PERCENTAGE);
uploadLayout.addComponent(generateSurveyDocButton);

Expand Down

0 comments on commit 1aa0337

Please sign in to comment.