Skip to content

Commit ed406cd

Browse files
authored
Merge pull request #13757 from SORMAS-Foundation/epipulse-no-config-message
eipipulse - show specific error message if any reference data table is missing
2 parents 2ec2828 + 9178f93 commit ed406cd

File tree

6 files changed

+87
-39
lines changed

6 files changed

+87
-39
lines changed

sormas-api/src/main/java/de/symeda/sormas/api/epipulse/EpipulseExportFacade.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,6 @@ public interface EpipulseExportFacade extends DeletableFacade {
3939
void cancelEpipulseExport(String uuid);
4040

4141
void deleteEpipulseExport(String uuid);
42+
43+
boolean configured();
4244
}

sormas-api/src/main/java/de/symeda/sormas/api/i18n/Strings.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,6 +1407,7 @@ public interface Strings {
14071407
String messageEpipulseExportDownloadNoFileName = "messageEpipulseExportDownloadNoFileName";
14081408
String messageEpipulseExportNoCancel = "messageEpipulseExportNoCancel";
14091409
String messageEpipulseExportNoDelete = "messageEpipulseExportNoDelete";
1410+
String messageEpipulseInvalidConfigError = "messageEpipulseInvalidConfigError";
14101411
String messageErrorReportNotAvailable = "messageErrorReportNotAvailable";
14111412
String messageEventArchived = "messageEventArchived";
14121413
String messageEventCreated = "messageEventCreated";

sormas-api/src/main/resources/strings.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,3 +2002,4 @@ messageEpipulseExportDeleteConfirmationCaption=Confirm deletion
20022002
messageEpipulseExportDeleteConfirmationDescription=Are you sure you want to delete this EpiPulse Export?
20032003
messageEpipulseExportDeleted=Export deleted successfully
20042004
messageEpipulseExportNoDelete=Export cannot be deleted at this time.
2005+
messageEpipulseInvalidConfigError=<b>Invalid Epipulse Configuration!</b><br/>Incomplete Reference data configuration. Please contact your admin and inform them about this issue.

sormas-backend/src/main/java/de/symeda/sormas/backend/epipulse/EpipulseExportFacadeEjb.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,11 @@ private void validate(EpipulseExportDto epipulseExportDto) throws ValidationRunt
337337
}
338338
}
339339

340+
@Override
341+
public boolean configured() {
342+
return epipulseExportService.configured();
343+
}
344+
340345
@RightsAllowed({
341346
UserRight._EPIPULSE_EXPORT_CREATE })
342347
@Override

sormas-backend/src/main/java/de/symeda/sormas/backend/epipulse/EpipulseExportService.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515

1616
package de.symeda.sormas.backend.epipulse;
1717

18+
import java.util.Arrays;
19+
import java.util.List;
1820
import java.util.logging.Logger;
21+
import java.util.stream.Collectors;
1922

2023
import javax.ejb.LocalBean;
2124
import javax.ejb.Stateless;
@@ -77,6 +80,34 @@ public Predicate buildCriteriaFilter(EpipulseExportCriteria criteria, EpipulseEx
7780
return filter;
7881
}
7982

83+
public boolean configured() {
84+
try {
85+
//@formatter:off
86+
List<String> requiredTables =
87+
Arrays.asList(
88+
EpipulseDatasourceConfiguration.TABLE_NAME,
89+
EpipulseLocationConfiguration.TABLE_NAME,
90+
EpipulseSubjectcodeConfiguration.TABLE_NAME
91+
);
92+
93+
String query = "SELECT COUNT(*) " +
94+
"FROM information_schema.tables " +
95+
"WHERE table_schema = 'public' " +
96+
"AND table_name IN (" +
97+
String.join(",", requiredTables.stream()
98+
.map(table -> "'" + table + "'")
99+
.collect(Collectors.toList())) +
100+
")";
101+
//@formatter:on
102+
103+
Number count = (Number) em.createNativeQuery(query).getSingleResult();
104+
return count.intValue() == requiredTables.size();
105+
} catch (Exception e) {
106+
logger.warning("Error checking epipulse configuration tables: " + e.getMessage());
107+
return false;
108+
}
109+
}
110+
80111
public boolean isArchived(String uuid) {
81112

82113
CriteriaBuilder cb = em.getCriteriaBuilder();

sormas-ui/src/main/java/de/symeda/sormas/ui/epipulse/EpiPulseExportController.java

Lines changed: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -50,48 +50,56 @@ public EpiPulseExportController() {
5050

5151
public void create(Runnable callback) {
5252

53-
EpipulseEditForm createForm = new EpipulseEditForm(true);
54-
createForm.setValue(EpipulseExportDto.build(UserProvider.getCurrent().getUserReference()));
55-
final CommitDiscardWrapperComponent<EpipulseEditForm> editView = new CommitDiscardWrapperComponent<EpipulseEditForm>(
56-
createForm,
57-
UiUtil.permitted(UserRight.EPIPULSE_EXPORT_CREATE),
58-
createForm.getFieldGroup());
59-
60-
editView.addCommitListener(() -> {
61-
if (!createForm.getFieldGroup().isModified()) {
62-
EpipulseExportDto dto = createForm.getValue();
63-
dto.setStatus(EpipulseExportStatus.PENDING);
64-
dto.setStatusChangeDate(new Date());
65-
66-
EpipulseExportDto savedEpipulseExport = FacadeProvider.getEpipulseExportFacade().saveEpipulseExport(dto);
67-
68-
Notification notification;
69-
if (savedEpipulseExport != null) {
70-
notification = new Notification(
71-
I18nProperties.getString(Strings.messageEpipulseExportCreatedCaption),
72-
I18nProperties.getString(Strings.messageEpipulseExportCreatedDescription),
73-
Notification.Type.TRAY_NOTIFICATION,
74-
true);
75-
notification.setDelayMsec(-1);
76-
} else {
77-
notification = new Notification(
78-
"",
79-
I18nProperties.getString(Strings.messageEpipulseExportCreatedError),
80-
Notification.Type.ERROR_MESSAGE,
81-
true);
82-
notification.setDelayMsec(-1);
83-
}
84-
85-
notification.show(Page.getCurrent());
53+
boolean configured = FacadeProvider.getEpipulseExportFacade().configured();
54+
if (configured) {
55+
EpipulseEditForm createForm = new EpipulseEditForm(true);
56+
createForm.setValue(EpipulseExportDto.build(UserProvider.getCurrent().getUserReference()));
57+
final CommitDiscardWrapperComponent<EpipulseEditForm> editView = new CommitDiscardWrapperComponent<EpipulseEditForm>(
58+
createForm,
59+
UiUtil.permitted(UserRight.EPIPULSE_EXPORT_CREATE),
60+
createForm.getFieldGroup());
61+
62+
editView.addCommitListener(() -> {
63+
if (!createForm.getFieldGroup().isModified()) {
64+
EpipulseExportDto dto = createForm.getValue();
65+
dto.setStatus(EpipulseExportStatus.PENDING);
66+
dto.setStatusChangeDate(new Date());
67+
68+
EpipulseExportDto savedEpipulseExport = FacadeProvider.getEpipulseExportFacade().saveEpipulseExport(dto);
69+
70+
Notification notification;
71+
if (savedEpipulseExport != null) {
72+
notification = new Notification(
73+
I18nProperties.getString(Strings.messageEpipulseExportCreatedCaption),
74+
I18nProperties.getString(Strings.messageEpipulseExportCreatedDescription),
75+
Notification.Type.TRAY_NOTIFICATION,
76+
true);
77+
notification.setDelayMsec(-1);
78+
} else {
79+
notification = new Notification(
80+
"",
81+
I18nProperties.getString(Strings.messageEpipulseExportCreatedError),
82+
Notification.Type.ERROR_MESSAGE,
83+
true);
84+
notification.setDelayMsec(-1);
85+
}
86+
87+
notification.show(Page.getCurrent());
88+
89+
if (callback != null) {
90+
callback.run();
91+
}
8692

87-
if (callback != null) {
88-
callback.run();
8993
}
94+
});
9095

91-
}
92-
});
93-
94-
VaadinUiUtil.showModalPopupWindow(editView, I18nProperties.getString(Strings.headingCreateNewEpipulseExport));
96+
VaadinUiUtil.showModalPopupWindow(editView, I18nProperties.getString(Strings.headingCreateNewEpipulseExport));
97+
} else {
98+
Notification notification =
99+
new Notification("", I18nProperties.getString(Strings.messageEpipulseInvalidConfigError), Notification.Type.ERROR_MESSAGE, true);
100+
notification.setDelayMsec(-1);
101+
notification.show(Page.getCurrent());
102+
}
95103
}
96104

97105
public void view(EpipulseExportIndexDto exportIndexDto, Runnable callback) {

0 commit comments

Comments
 (0)