Skip to content
This repository was archived by the owner on May 5, 2021. It is now read-only.

Commit 76628a6

Browse files
Merge pull request SORMAS-Foundation#3569 from hzi-braunschweig/2902-fix_event_participant_save
SORMAS-Foundation#2902 - extend event participant jurisdiction calculation
2 parents 675d8d2 + 77d1bfd commit 76628a6

2 files changed

Lines changed: 49 additions & 10 deletions

File tree

sormas-backend/src/main/java/de/symeda/sormas/backend/event/EventParticipantFacadeEjb.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ public EventParticipantDto saveEventParticipant(EventParticipantDto dto) {
193193
Event event = eventService.getByUuid(eventReferenceDto.getUuid());
194194

195195
if (!eventJurisdictionChecker.isInJurisdiction(event) && (dto.getRegion() == null || dto.getDistrict() == null)) {
196-
dto.setRegion(new RegionReferenceDto(user.getRegion().getUuid()));
197-
dto.setDistrict(new DistrictReferenceDto(user.getDistrict().getUuid()));
196+
dto.setRegion(user.getRegion() != null ? new RegionReferenceDto(user.getRegion().getUuid()) : null);
197+
dto.setDistrict(user.getDistrict() != null ? new DistrictReferenceDto(user.getDistrict().getUuid()) : null);
198198
}
199199

200200
Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight);

sormas-ui/src/main/java/de/symeda/sormas/ui/events/EventParticipantsController.java

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
import de.symeda.sormas.api.i18n.Strings;
4343
import de.symeda.sormas.api.person.PersonDto;
4444
import de.symeda.sormas.api.person.PersonFacade;
45+
import de.symeda.sormas.api.region.DistrictReferenceDto;
46+
import de.symeda.sormas.api.region.RegionReferenceDto;
4547
import de.symeda.sormas.api.user.UserDto;
4648
import de.symeda.sormas.api.user.UserRight;
4749
import de.symeda.sormas.ui.ControllerProvider;
@@ -206,9 +208,40 @@ private CommitDiscardWrapperComponent<EventParticipantEditForm> createEventParti
206208
if (!editForm.getFieldGroup().isModified()) {
207209

208210
EventParticipantDto dto = editForm.getValue();
211+
EventDto eventDto = FacadeProvider.getEventFacade().getEventByUuid(dto.getEvent().getUuid());
209212
UserDto user = UserProvider.getCurrent().getUser();
210-
if ((user.getRegion() != null && !user.getRegion().equals(dto.getRegion()))
211-
|| (user.getDistrict() != null && !user.getDistrict().equals(dto.getDistrict()))) {
213+
214+
RegionReferenceDto userRegion = user.getRegion();
215+
DistrictReferenceDto userDistrict = user.getDistrict();
216+
217+
RegionReferenceDto epResponsibleRegion = dto.getRegion();
218+
DistrictReferenceDto epResponsibleDistrict = dto.getDistrict();
219+
220+
RegionReferenceDto epEventRegion = eventDto.getEventLocation().getRegion();
221+
DistrictReferenceDto epEventDistrict = eventDto.getEventLocation().getDistrict();
222+
223+
//Responsible region of the event participant is filled and differs from user Region - warning about loosing full access rights to the event participant should be triggered
224+
Boolean responsibleRegionDiffersFromUserRegion =
225+
(userRegion != null && epResponsibleRegion != null && !userRegion.equals(epResponsibleRegion));
226+
227+
//Responsible district of the event participant is filled and differs from user District - warning about loosing full access rights to the event participant should be triggered
228+
Boolean responsibleDistrictDiffersFromUserDistrict =
229+
(userDistrict != null && epResponsibleDistrict != null && !userDistrict.equals(epResponsibleDistrict));
230+
231+
//both responsible region and district of the event participant are empty and the fall back towards event location:
232+
// event region or event district is different from user's region or district - warning about loosing full access rights to the event participant should be triggered
233+
Boolean responsibleFieldsEmptyAndEventOutsideJurisdiction = (epResponsibleRegion == null
234+
&& epResponsibleDistrict == null
235+
&& (userRegion != null && !userRegion.equals(epEventRegion) || userDistrict != null && !userDistrict.equals(epEventDistrict)));
236+
237+
//if only district is not filled and either responsible region or district are different from user region or district - warning about loosing full access rights to the event participant should be triggered
238+
Boolean responsibleDistrictIsEmpty = ((epResponsibleRegion != null && epResponsibleDistrict == null)
239+
&& (userRegion != null && !userRegion.equals(epResponsibleRegion) || userDistrict != null));
240+
241+
if (responsibleRegionDiffersFromUserRegion
242+
|| responsibleDistrictDiffersFromUserDistrict
243+
|| responsibleFieldsEmptyAndEventOutsideJurisdiction
244+
|| responsibleDistrictIsEmpty) {
212245
VaadinUiUtil.showConfirmationPopup(
213246
I18nProperties.getString(Strings.headingEventParticipantResponsibleJurisdictionUpdated),
214247
new Label(I18nProperties.getString(Strings.messageEventParticipantResponsibleJurisdictionUpdated)),
@@ -217,17 +250,23 @@ private CommitDiscardWrapperComponent<EventParticipantEditForm> createEventParti
217250
500,
218251
confirmed -> {
219252
if (confirmed) {
220-
personFacade.savePerson(dto.getPerson());
221-
eventParticipantFacade.saveEventParticipant(dto);
222-
Notification.show(I18nProperties.getString(Strings.messageEventParticipantSaved), Type.WARNING_MESSAGE);
223-
if (doneConsumer != null)
224-
doneConsumer.accept(null);
225-
SormasUI.refreshView();
253+
savePersonAndEventParticipant(doneConsumer, dto);
226254
}
227255
});
256+
} else {
257+
savePersonAndEventParticipant(doneConsumer, dto);
228258
}
229259
}
230260
});
231261
return editComponent;
232262
}
263+
264+
private void savePersonAndEventParticipant(Consumer<EventParticipantReferenceDto> doneConsumer, EventParticipantDto dto) {
265+
personFacade.savePerson(dto.getPerson());
266+
eventParticipantFacade.saveEventParticipant(dto);
267+
Notification.show(I18nProperties.getString(Strings.messageEventParticipantSaved), Type.WARNING_MESSAGE);
268+
if (doneConsumer != null)
269+
doneConsumer.accept(null);
270+
SormasUI.refreshView();
271+
}
233272
}

0 commit comments

Comments
 (0)