13
13
import java .io .Serial ;
14
14
import java .util .Arrays ;
15
15
import java .util .HashSet ;
16
+ import java .util .Locale ;
17
+ import java .util .Objects ;
16
18
import java .util .Set ;
17
19
import life .qbic .application .commons .ApplicationException ;
18
20
import life .qbic .application .commons .Result ;
21
23
import life .qbic .datamanager .views .general .Main ;
22
24
import life .qbic .datamanager .views .general .contact .Contact ;
23
25
import life .qbic .datamanager .views .notifications .CancelConfirmationDialogFactory ;
24
- import life .qbic .datamanager .views .notifications .StyledNotification ;
25
- import life .qbic .datamanager .views .notifications .SuccessMessage ;
26
+ import life .qbic .datamanager .views .notifications .MessageSourceNotificationFactory ;
27
+ import life .qbic .datamanager .views .notifications .Toast ;
26
28
import life .qbic .datamanager .views .projects .create .AddProjectDialog ;
27
29
import life .qbic .datamanager .views .projects .create .AddProjectDialog .ConfirmEvent ;
28
30
import life .qbic .datamanager .views .projects .overview .components .ProjectCollectionComponent ;
31
+ import life .qbic .datamanager .views .register .EmailConfirmationMain ;
29
32
import life .qbic .finances .api .FinanceService ;
30
33
import life .qbic .identity .api .UserInformationService ;
31
34
import life .qbic .logging .api .Logger ;
@@ -62,6 +65,7 @@ public class ProjectOverviewMain extends Main {
62
65
private final transient AddExperimentToProjectService addExperimentToProjectService ;
63
66
private final transient UserInformationService userInformationService ;
64
67
private final transient AuthenticationToUserIdTranslationService userIdTranslator ;
68
+ private final transient MessageSourceNotificationFactory messageSourceNotificationFactory ;
65
69
66
70
public ProjectOverviewMain (@ Autowired ProjectCollectionComponent projectCollectionComponent ,
67
71
ProjectCreationService projectCreationService , FinanceService financeService ,
@@ -71,7 +75,8 @@ public ProjectOverviewMain(@Autowired ProjectCollectionComponent projectCollecti
71
75
UserInformationService userInformationService ,
72
76
AuthenticationToUserIdTranslationService userIdTranslator ,
73
77
TerminologyService terminologyService ,
74
- CancelConfirmationDialogFactory cancelConfirmationDialogFactory ) {
78
+ CancelConfirmationDialogFactory cancelConfirmationDialogFactory ,
79
+ MessageSourceNotificationFactory messageSourceNotificationFactory ) {
75
80
this .projectCollectionComponent = requireNonNull (projectCollectionComponent ,
76
81
"project collection component can not be null" );
77
82
this .projectCreationService = requireNonNull (projectCreationService ,
@@ -110,6 +115,21 @@ public ProjectOverviewMain(@Autowired ProjectCollectionComponent projectCollecti
110
115
this .getClass ().getSimpleName (), System .identityHashCode (this ),
111
116
projectCollectionComponent .getClass ().getSimpleName (),
112
117
System .identityHashCode (projectCollectionComponent )));
118
+ this .messageSourceNotificationFactory = messageSourceNotificationFactory ;
119
+ }
120
+
121
+ private static Toast notificationFor (NotificationType type , ConfirmEvent confirmEvent ,
122
+ MessageSourceNotificationFactory factory , Locale locale ) {
123
+ return switch (type ) {
124
+ case PROJECT_CREATED_SUCCESSFULLY -> factory .toast ("project.created.success" ,
125
+ new Object []{confirmEvent .getProjectDesign ().getProjectTitle ()}, locale );
126
+ case PROJECT_CREATION_FAILED ->
127
+ factory .toast ("project.created.error" , new Object []{}, locale );
128
+ case EXPERIMENT_CREATED_SUCCESSFULLY -> factory .toast ("experiment.created.success" ,
129
+ new Object []{confirmEvent .getExperimentalInformation ().getExperimentName ()}, locale );
130
+ case EXPERIMENT_CREATION_FAILED ->
131
+ factory .toast ("experiment.created.error" , new Object []{}, locale );
132
+ };
113
133
}
114
134
115
135
private void addTitleAndDescription () {
@@ -158,11 +178,7 @@ private void createProject(ConfirmEvent confirmEvent) {
158
178
.map (Contact ::toDomainContact ).orElse (null ),
159
179
confirmEvent .getProjectCollaborators ().getProjectManager ().toDomainContact (),
160
180
funding );
161
- project
162
- .onValue (result -> onProjectCreated (confirmEvent ))
163
- .onError (e -> {
164
- throw e ;
165
- });
181
+ handleResultProject (project , confirmEvent );
166
182
var experiment = addExperimentToProjectService .addExperimentToProject (
167
183
project .getValue ().getId (),
168
184
confirmEvent .getExperimentalInformation ().getExperimentName (),
@@ -171,22 +187,43 @@ private void createProject(ConfirmEvent confirmEvent) {
171
187
confirmEvent .getExperimentalInformation ().getAnalytes (),
172
188
confirmEvent .getExperimentalInformation ().getSpeciesIcon ().getLabel (),
173
189
confirmEvent .getExperimentalInformation ().getSpecimenIcon ().getLabel ());
174
- experiment .onError (e -> {
175
- throw e ;
176
- });
190
+ handleResultExperiment (experiment , confirmEvent );
191
+ projectCollectionComponent .refresh ();
192
+ projectCollectionComponent .resetSearch ();
193
+ }
194
+
195
+ private void handleResultProject (Result <?, ?> result , ConfirmEvent event ) {
196
+ if (result .isError ()) {
197
+ processNotification (notificationFor (NotificationType .PROJECT_CREATION_FAILED , event ,
198
+ messageSourceNotificationFactory , getLocale ()));
199
+ return ;
200
+ }
201
+ processNotification (notificationFor (NotificationType .PROJECT_CREATED_SUCCESSFULLY , event ,
202
+ messageSourceNotificationFactory , getLocale ()));
203
+ closeDialog (event );
177
204
}
178
205
179
- private void onProjectCreated (ConfirmEvent confirmEvent ) {
180
- displaySuccessfulProjectCreationNotification ();
181
- confirmEvent .getSource ().close ();
206
+ private void handleResultExperiment (Result <?, ?> result , ConfirmEvent event ) {
207
+ if (result .isError ()) {
208
+ processNotification (notificationFor (NotificationType .EXPERIMENT_CREATION_FAILED , event ,
209
+ messageSourceNotificationFactory , getLocale ()));
210
+ return ;
211
+ }
212
+ closeDialog (event );
213
+ }
182
214
183
- projectCollectionComponent .refresh ();
184
- projectCollectionComponent .resetSearch ();
215
+ private void processNotification (Toast t ) {
216
+ t .open ();
217
+ }
218
+
219
+ private void closeDialog (ConfirmEvent event ) {
220
+ event .getSource ().close ();
185
221
}
186
222
187
- private void displaySuccessfulProjectCreationNotification () {
188
- var successMessage = new SuccessMessage ("Project creation succeeded." , "" );
189
- var notification = new StyledNotification (successMessage );
190
- notification .open ();
223
+ enum NotificationType {
224
+ PROJECT_CREATED_SUCCESSFULLY ,
225
+ PROJECT_CREATION_FAILED ,
226
+ EXPERIMENT_CREATED_SUCCESSFULLY ,
227
+ EXPERIMENT_CREATION_FAILED ,
191
228
}
192
229
}
0 commit comments