Skip to content

Commit

Permalink
#183 added archive and delete
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony4m committed Jan 17, 2025
1 parent 953e185 commit 9ede23c
Showing 1 changed file with 43 additions and 41 deletions.
84 changes: 43 additions & 41 deletions sormas-ui/src/main/java/de/symeda/sormas/ui/ebs/EbsController.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@
import static com.vaadin.ui.Notification.Type.TRAY_NOTIFICATION;
import static de.symeda.sormas.api.utils.DataHelper.isNullOrEmpty;

import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;

import com.vaadin.ui.UI;
import de.symeda.sormas.api.externalsurveillancetool.ExternalSurveillanceToolRuntimeException;
import de.symeda.sormas.api.i18n.Captions;
import de.symeda.sormas.ui.utils.ArchiveHandlers;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

Expand Down Expand Up @@ -67,14 +72,7 @@
import de.symeda.sormas.ui.utils.VaadinUiUtil;
import de.symeda.sormas.ui.utils.components.automaticdeletion.DeletionLabel;
import de.symeda.sormas.ui.utils.components.page.title.TitleLayout;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.Collection;
import java.util.List;
import java.util.function.Consumer;

import static com.vaadin.ui.Notification.Type.TRAY_NOTIFICATION;

public class EbsController {

Expand Down Expand Up @@ -170,7 +168,7 @@ public CommitDiscardWrapperComponent<EbsDataForm> getEbsCreateComponent() {

final CommitDiscardWrapperComponent<EbsDataForm> component =
new CommitDiscardWrapperComponent<>(form, UserProvider.getCurrent().hasAllUserRights(), form.getFieldGroup());
component.getDiscardButton().setCaption("Cancel");
component.getDiscardButton().setCaption(Captions.actionCancel);
component.addCommitListener(() -> {
if (!form.getFieldGroup().isModified()) {
EbsDto newEvent = form.getValue();
Expand All @@ -193,19 +191,17 @@ public CommitDiscardWrapperComponent<TriagingDataForm> getEbsCreateTriagingCompo

final CommitDiscardWrapperComponent<TriagingDataForm> editView =
new CommitDiscardWrapperComponent<TriagingDataForm>(triagingDataForm, triagingDataForm.getFieldGroup());
editView.getDiscardButton().setCaption("Cancel");
TriagingDto newEvent = triagingDataForm.getValue();
editView.getDiscardButton().setCaption(Captions.actionCancel);
editView.addCommitListener(() -> {
ebs.setTriaging(triagingDataForm.getValue());
FacadeProvider.getEbsFacade().save(ebs);
SormasUI.refreshView();
navigateToSignalVerification(ebs.getUuid(), false);
});

return editView;
}

public CommitDiscardWrapperComponent<SignalVerificationDataForm> getEbsCreateSignalVerficationComponent(
public CommitDiscardWrapperComponent<SignalVerificationDataForm> getEbsCreateSignalVerificationComponent(
final String ebsUuid,
boolean isEditAllowed) {
EbsDto ebs = findEbs(ebsUuid);
Expand All @@ -214,7 +210,7 @@ public CommitDiscardWrapperComponent<SignalVerificationDataForm> getEbsCreateSig
signalVerificationDataForm.setValue(ebs.getSignalVerification());
final CommitDiscardWrapperComponent<SignalVerificationDataForm> editView =
new CommitDiscardWrapperComponent<SignalVerificationDataForm>(signalVerificationDataForm, signalVerificationDataForm.getFieldGroup());
editView.getDiscardButton().setCaption("Cancel");
editView.getDiscardButton().setCaption(Captions.actionCancel);
editView.addCommitListener(() -> {
ebs.setSignalVerification(signalVerificationDataForm.getValue());
callDeathCount(signalVerificationDataForm);
Expand Down Expand Up @@ -246,7 +242,7 @@ public CommitDiscardWrapperComponent<RiskAssessmentDataForm> getEbsCreateRiskAss
riskAssessmentDataForm.setValue(riskAssessmentDto);
final CommitDiscardWrapperComponent<RiskAssessmentDataForm> editView =
new CommitDiscardWrapperComponent<RiskAssessmentDataForm>(riskAssessmentDataForm, riskAssessmentDataForm.getFieldGroup());
editView.getDiscardButton().setCaption("Cancel");
editView.getDiscardButton().setCaption(Captions.actionCancel);
editView.addCommitListener(() -> {
ebs.setRiskAssessment(riskAssessmentDataForm.getValue());
riskAssessmentDto.setRiskAssessment(riskAssessmentDataForm.getValue().getRiskAssessment());
Expand Down Expand Up @@ -379,7 +375,7 @@ public CommitDiscardWrapperComponent<EbsAlertDataForm> getEbsCreateAlertComponen
alertDataForm.setValue(ebsAlertDto);
final CommitDiscardWrapperComponent<EbsAlertDataForm> editView =
new CommitDiscardWrapperComponent<EbsAlertDataForm>(alertDataForm, alertDataForm.getFieldGroup());
editView.getDiscardButton().setCaption("Cancel");
editView.getDiscardButton().setCaption(Captions.actionCancel);
editView.addCommitListener(() -> {
ebs.setAlert(alertDataForm.getValue());
ebsAlertDto.setAlertIssued(alertDataForm.getValue().getAlertIssued());
Expand All @@ -397,10 +393,8 @@ private EbsDto findEvent(String uuid) {

private String getDeleteConfirmationDetails(List<String> eventUuids) {
// boolean hasPendingRequest = FacadeProvider.getSormasToSormasEbsFacade().hasPendingRequest(eventUuids);
//
// return hasPendingRequest ? "<br/>" + I18nProperties.getString(Strings.messageDeleteWithPendingShareRequest) + "<br/>" : "";

return "";
return "<br/>" + I18nProperties.getString(Strings.messageDeleteWithPendingShareRequest) + "<br/>";
}

private Consumer<List<EbsIndexDto>> bulkOperationCallback(EbsSignalGrid eventGrid, Window popupWindow) {
Expand Down Expand Up @@ -471,27 +465,35 @@ public CommitDiscardWrapperComponent<EbsDataForm> getEbsDataEditComponent(final
});

final String uuid = event.getUuid();
// if (UserProvider.getCurrent().hasUserRight(UserRight.EVENT_DELETE)) {
// editView.addDeleteWithReasonOrRestoreListener((deleteDetails) -> {
// VaadinUiUtil.showSimplePopupWindow(
// I18nProperties.getString(Strings.headingEventNotDeleted),
// I18nProperties.getString(Strings.messageEventsNotDeletedLinkedEntitiesReason));
// UI.getCurrent().getNavigator().navigateTo(EventsView.VIEW_NAME);
// },
// getDeleteConfirmationDetails(Collections.singletonList(eventUuid)), (deleteDetails) -> {
// FacadeProvider.getEbsFacade().restore(uuid);
// UI.getCurrent().getNavigator().navigateTo(EBSView.VIEW_NAME);
// },
// I18nProperties.getString(Strings.entityEvent), uuid, FacadeProvider.getEbsFacade());
// }

// Initialize 'Archive' button
// if (UserProvider.getCurrent().hasUserRight(UserRight.EVENT_ARCHIVE)) {
// ControllerProvider.getArchiveController().addArchivingButton(event, ArchiveHandlers.forEbs(), editView, () -> {
// navigateToData(uuid);
// });
// }
editView.getDiscardButton().setCaption("Cancel");
if (UserProvider.getCurrent().hasUserRight(UserRight.EVENT_DELETE)) {
editView.addDeleteWithReasonOrRestoreListener((deleteDetails) -> {
try {
FacadeProvider.getEbsFacade().delete(uuid, deleteDetails);
} catch (ExternalSurveillanceToolRuntimeException e) {
Notification.show(
String.format(
I18nProperties.getString(Strings.ExternalSurveillanceToolGateway_notificationEntryNotDeleted),
DataHelper.getShortUuid(uuid)),
"",
Type.ERROR_MESSAGE);

VaadinUiUtil.showSimplePopupWindow(
I18nProperties.getString(Strings.headingEventNotDeleted),
I18nProperties.getString(Strings.messageEventsNotDeletedLinkedEntitiesReason));
}
UI.getCurrent().getNavigator().navigateTo(EBSView.VIEW_NAME);
}, getDeleteConfirmationDetails(Collections.singletonList(eventUuid)), (deleteDetails) -> {
FacadeProvider.getEbsFacade().restore(uuid);
UI.getCurrent().getNavigator().navigateTo(EBSView.VIEW_NAME);
}, I18nProperties.getString(Strings.entityEvent), uuid, FacadeProvider.getEbsFacade());
}

// Initialize 'Archive' button
if (UserProvider.getCurrent().hasUserRight(UserRight.EVENT_ARCHIVE)) {
ControllerProvider.getArchiveController()
.addArchivingButton(event, ArchiveHandlers.forEbs(), editView, () -> navigateToData(uuid));
}
editView.getDiscardButton().setCaption(Captions.actionCancel);

return editView;
}
Expand All @@ -506,7 +508,7 @@ public CommitDiscardWrapperComponent<RiskAssessmentDataForm> getRiskAssessmented
riskAssessmentDataForm.setValue(riskAssessmentDto);
final CommitDiscardWrapperComponent<RiskAssessmentDataForm> editView =
new CommitDiscardWrapperComponent<RiskAssessmentDataForm>(riskAssessmentDataForm, riskAssessmentDataForm.getFieldGroup());
editView.getDiscardButton().setCaption("Cancel");
editView.getDiscardButton().setCaption(Captions.actionCancel);
editView.addCommitListener(() -> {
ebs.setRiskAssessment(riskAssessmentDataForm.getValue());
riskAssessmentDto.setRiskAssessment(riskAssessmentDataForm.getValue().getRiskAssessment());
Expand All @@ -532,7 +534,7 @@ public CommitDiscardWrapperComponent<EbsAlertDataForm> getEbsCreateAlertEditComp
alertDataForm.setValue(ebsAlertDto);
final CommitDiscardWrapperComponent<EbsAlertDataForm> editView =
new CommitDiscardWrapperComponent<EbsAlertDataForm>(alertDataForm, alertDataForm.getFieldGroup());
editView.getDiscardButton().setCaption("Cancel");
editView.getDiscardButton().setCaption(Captions.actionCancel);
editView.addCommitListener(() -> {
ebs.setAlert(alertDataForm.getValue());
ebsAlertDto.setAlertIssued(alertDataForm.getValue().getAlertIssued());
Expand Down

0 comments on commit 9ede23c

Please sign in to comment.