28
28
import java .util .Set ;
29
29
import life .qbic .datamodel .persons .Affiliation ;
30
30
import life .qbic .datamodel .persons .CollaboratorWithResponsibility ;
31
- import life .qbic .datamodel .persons .Person ;
32
- import life .qbic .datamodel .projects .ProjectInfo ;
33
31
import life .qbic .openbis .openbisclient .IOpenBisClient ;
34
32
import life .qbic .openbis .openbisclient .OpenBisClient ;
35
33
import life .qbic .portal .Styles ;
39
37
import life .qbic .portal .utils .PortalUtils ;
40
38
import life .qbic .userdb .Config ;
41
39
import life .qbic .userdb .DBManager ;
40
+ import life .qbic .userdb .model .Person ;
41
+ import life .qbic .userdb .model .Person .PersonBuilder ;
42
+ import life .qbic .userdb .model .ProjectInfo ;
43
+ import life .qbic .userdb .model .ProjectInfo .ProjectInfoBuilder ;
42
44
import life .qbic .userdb .views .AffiliationInput ;
43
45
import life .qbic .userdb .views .AffiliationVIPTab ;
44
46
import life .qbic .userdb .views .MultiAffiliationTab ;
55
57
* found in the {@code portal-utils-lib} library.
56
58
*/
57
59
@ Theme ("mytheme" )
58
- @ SuppressWarnings ("serial" )
59
60
@ Widgetset ("life.qbic.portlet.AppWidgetSet" )
60
61
public class UserDBPortletUI extends QBiCPortletUI {
61
62
62
63
private static final Logger logger = LogManager .getLogger (UserDBPortletUI .class );
63
64
private DBManager dbControl ;
64
65
private Map <String , Integer > affiMap ;
65
- private Map <String , Integer > personMap ;
66
+ private Map <String , Person > personMap ;
66
67
private Map <String , ProjectInfo > projectMap ;
67
68
68
69
private TabSheet options ;
69
70
70
- private ConfigurationManager manager ;
71
71
private Config config ;
72
72
public static String tmpFolder ;
73
73
@@ -84,7 +84,7 @@ protected Layout getPortletContent(final VaadinRequest request) {
84
84
85
85
String userID = "" ;
86
86
boolean success = true ;
87
- manager = ConfigurationManagerFactory .getInstance ();
87
+ ConfigurationManager manager = ConfigurationManagerFactory .getInstance ();
88
88
tmpFolder = manager .getTmpFolder ();
89
89
if (PortalUtils .isLiferayPortlet ()) {
90
90
// read in the configuration file
@@ -151,47 +151,6 @@ private void initTabs() {
151
151
} else {
152
152
personMap = dbControl .getPersonMap ();
153
153
154
- /*
155
- * Removed since 1.8.0 as most of the functionality moved to offer-manager-portlet 2
156
- *
157
- *
158
- * affiMap = dbControl.getAffiliationMap();
159
- *
160
- * Map<String, Integer> colNamesToMaxLength = fillMaxInputLengthMap();
161
- *
162
- * Set<String> instituteNames = dbControl.getInstituteNames(); List<String> facultyEnums =
163
- * dbControl.getPossibleEnumsForColumnsInTable("organizations", "faculty"); List<String>
164
- * affiliationRoles = dbControl.getPossibleEnumsForColumnsInTable("persons_organizations",
165
- * "occupation"); List<String> titleEnums =
166
- * dbControl.getPossibleEnumsForColumnsInTable("persons", "title");
167
- *
168
- * PersonInput addUserTab = new PersonInput(titleEnums, affiMap, affiliationRoles,
169
- * colNamesToMaxLength, new AffiliationInput(instituteNames, facultyEnums, personMap,
170
- * colNamesToMaxLength)); options.addTab(addUserTab, "New Person");
171
- *
172
- * AffiliationInput addAffilTab = new AffiliationInput(instituteNames, facultyEnums,
173
- * personMap, colNamesToMaxLength); options.addTab(addAffilTab, "New Affiliation");
174
- *
175
- * SearchView searchView = new SearchView(); options.addTab(searchView, "Search Entries");
176
- *
177
- * List<Affiliation> affiTable = dbControl.getAffiliationTable(); Map<Integer, Pair<String,
178
- * String>> affiPeople = new HashMap<Integer, Pair<String, String>>(); for (Affiliation a :
179
- * affiTable) { int id = a.getID(); affiPeople.put(id, new ImmutablePair<String,
180
- * String>(a.getContactPerson(), a.getHeadName())); } PersonBatchUpload batchTab = new
181
- * PersonBatchUpload(titleEnums, affiliationRoles, affiMap); options.addTab(batchTab,
182
- * "Upload Person Table");
183
- *
184
- * AffiliationVIPTab vipTab = new AffiliationVIPTab(personMap, affiMap, affiPeople);
185
- * options.addTab(vipTab, "Edit Affiliation VIPs");
186
- *
187
- * MultiAffiliationTab multiAffilTab = new MultiAffiliationTab(personMap, affiMap,
188
- * affiliationRoles); options.addTab(multiAffilTab, "Additional Person-Affiliations");
189
- *
190
- * if (!admin) { options.getTab(multiAffilTab).setEnabled(false);
191
- * options.getTab(vipTab).setEnabled(false);
192
- *
193
- * options.getTab(3).setEnabled(false); options.getTab(4).setEnabled(false); }
194
- */
195
154
String userID = "" ;
196
155
if (PortalUtils .isLiferayPortlet ()) {
197
156
logger .info ("DB Tools running on Liferay, fetching user ID." );
@@ -202,9 +161,9 @@ private void initTabs() {
202
161
userID = "admin" ;
203
162
}
204
163
}
205
- Map <String , ProjectInfo > userProjects = new HashMap <String , ProjectInfo >();
164
+ Map <String , ProjectInfo > userProjects = new HashMap <>();
206
165
207
- List <Project > openbisProjectsForUser = new ArrayList <Project >();
166
+ List <Project > openbisProjectsForUser = new ArrayList <>();
208
167
Set <String > spaces = new HashSet <>(openbis .getUserSpaces (userID ));
209
168
210
169
List <Project > allOpenbisProjects = openbis .listProjects ();
@@ -221,8 +180,10 @@ private void initTabs() {
221
180
desc = desc .replaceAll ("\n +" , ". " );
222
181
String projectID = p .getIdentifier ().getIdentifier ();
223
182
String code = p .getCode ();
224
- if (dbProjects .get (projectID ) == null )
225
- userProjects .put (projectID , new ProjectInfo (p .getSpace ().getCode (), code , desc , "" , -1 ));
183
+ if (dbProjects .get (projectID ) == null ) {
184
+ ProjectInfoBuilder infoBuilder = new ProjectInfoBuilder ().createProjectInfo (p .getSpace ().getCode (), code , desc , "" ).withId (-1 );
185
+ userProjects .put (projectID , infoBuilder .getProjectInfo ());
186
+ }
226
187
else {
227
188
ProjectInfo info = dbProjects .get (projectID );
228
189
info .setDescription (desc );
@@ -243,7 +204,7 @@ private void initTabs() {
243
204
// searchView, projectView);
244
205
projectView .getProjectTable ().addValueChangeListener (new ValueChangeListener () {
245
206
246
- private Map <String , String > expTypeCodeTranslation = new HashMap <String , String >() {
207
+ private final Map <String , String > expTypeCodeTranslation = new HashMap <String , String >() {
247
208
{
248
209
put ("Q_EXPERIMENTAL_DESIGN" , "Patients/Sources" );
249
210
put ("Q_SAMPLE_EXTRACTION" , "Sample Extracts" );
@@ -262,7 +223,7 @@ public void valueChange(ValueChangeEvent event) {
262
223
List <CollaboratorWithResponsibility > collaborators =
263
224
dbControl .getCollaboratorsOfProject (project );
264
225
// get openbis experiments and type
265
- Map <String , String > existingExps = new HashMap <String , String >();
226
+ Map <String , String > existingExps = new HashMap <>();
266
227
for (Experiment e : openbis .getExperimentsOfProjectByCode (project )) {
267
228
String type = expTypeCodeTranslation .get (e .getType ().getCode ());
268
229
String id = e .getIdentifier ().getIdentifier ();
@@ -285,22 +246,14 @@ public void valueChange(ValueChangeEvent event) {
285
246
}
286
247
projectView .setCollaboratorsOfProject (collaborators );
287
248
288
- Person investigator = getPersonOrNull (projectMap .get (item ).getInvestigator ());
289
- Person manager = getPersonOrNull (projectMap .get (item ).getManager ());
290
- Person contact = getPersonOrNull (projectMap .get (item ).getContact ());
249
+ ProjectInfo info = projectMap .get (item );
291
250
292
- projectView .handleProjectValueChange (item , investigator , contact , manager );
251
+ projectView .handleProjectValueChange (item , info . getInvestigator (), info . getContact (), info . getManager () );
293
252
} else {
294
253
projectView .handleProjectDeselect ();
295
254
}
296
255
}
297
256
298
- private Person getPersonOrNull (String name ) {
299
- if (personMap .get (name ) != null ) {
300
- return dbControl .getPersonWithAffiliations (personMap .get (name )).get (0 );
301
- }
302
- return null ;
303
- }
304
257
});
305
258
306
259
projectView .getInfoCommitButton ().addClickListener (new ClickListener () {
@@ -316,18 +269,18 @@ public void buttonClick(ClickEvent event) {
316
269
info .getSecondaryName ());
317
270
else
318
271
dbControl .addOrChangeSecondaryNameForProject (id , info .getSecondaryName ());
319
- if (info .getInvestigator () == null || info . getInvestigator (). isEmpty () )
272
+ if (info .getInvestigator () == null )
320
273
dbControl .removePersonFromProject (id , "PI" );
321
274
else
322
- dbControl .addOrUpdatePersonToProject (id , personMap . get ( info .getInvestigator ()), "PI" );
323
- if (info .getContact () == null || info . getContact (). isEmpty () )
275
+ dbControl .addOrUpdatePersonToProject (id , info .getInvestigator (). getId ( ), "PI" );
276
+ if (info .getContact () == null )
324
277
dbControl .removePersonFromProject (id , "Contact" );
325
278
else
326
- dbControl .addOrUpdatePersonToProject (id , personMap . get ( info .getContact ()), "Contact" );
327
- if (info .getManager () == null || info . getManager (). isEmpty () )
279
+ dbControl .addOrUpdatePersonToProject (id , info .getContact (). getId ( ), "Contact" );
280
+ if (info .getManager () == null )
328
281
dbControl .removePersonFromProject (id , "Manager" );
329
282
else
330
- dbControl .addOrUpdatePersonToProject (id , personMap . get ( info .getManager ()), "Manager" );
283
+ dbControl .addOrUpdatePersonToProject (id , info .getManager (). getId ( ), "Manager" );
331
284
projectView .updateChangedInfo (info );
332
285
}
333
286
}
@@ -344,7 +297,7 @@ public void buttonClick(ClickEvent event) {
344
297
String name = c .getPerson ();
345
298
int personID = -1 ;
346
299
if (personMap .get (name ) != null )
347
- personID = personMap .get (name );
300
+ personID = personMap .get (name ). getId () ;
348
301
if (personID < 1 )
349
302
dbControl .removePersonFromExperiment (experimentID );
350
303
else
@@ -424,7 +377,7 @@ private void initPortletToDBFunctionality(final AffiliationInput addAffilTab,
424
377
@ Override
425
378
public void buttonClick (ClickEvent event ) {
426
379
if (batchUpload .isValid ()) {
427
- List <String > registered = new ArrayList <String >();
380
+ List <String > registered = new ArrayList <>();
428
381
batchUpload .setRegEnabled (false );
429
382
for (Person p : batchUpload .getPeople ()) {
430
383
if (dbControl .personExists (p )) {
@@ -453,18 +406,18 @@ public void buttonClick(ClickEvent event) {
453
406
if (affi != null && !affi .isEmpty ()) {
454
407
search .setAffiliations (dbControl .getAffiliationsContaining (affi ));
455
408
} else
456
- search .setAffiliations (new ArrayList <Affiliation >());
409
+ search .setAffiliations (new ArrayList <>());
457
410
}
458
411
});
459
412
460
413
search .getSearchPersonButton ().addClickListener (new Button .ClickListener () {
461
414
@ Override
462
415
public void buttonClick (ClickEvent event ) {
463
- String person = search .getPersonSearchField ().getValue ();
464
- if (person != null && !person .isEmpty ()) {
465
- search .setPersons (dbControl .getPersonsContaining (person ));
416
+ String personName = search .getPersonSearchField ().getValue ();
417
+ if (personName != null && !personName .isEmpty ()) {
418
+ search .setPersons (dbControl .getPersonsContaining (personName ));
466
419
} else
467
- search .setPersons (new ArrayList <Person >());
420
+ search .setPersons (new ArrayList <>());
468
421
}
469
422
});
470
423
@@ -550,7 +503,7 @@ public void buttonClick(ClickEvent event) {
550
503
public void buttonClick (ClickEvent event ) {
551
504
if (multiAffilTab .isValid ()) {
552
505
if (dbControl .addOrUpdatePersonAffiliationConnections (
553
- personMap .get (multiAffilTab .getPersonBox ().getValue ()),
506
+ personMap .get (multiAffilTab .getPersonBox ().getValue ()). getId () ,
554
507
multiAffilTab .getChangedAndNewConnections ()))
555
508
successfulCommit ();
556
509
else
@@ -565,12 +518,16 @@ public void buttonClick(ClickEvent event) {
565
518
@ Override
566
519
public void buttonClick (ClickEvent event ) {
567
520
String personName = multiAffilTab .getPersonBox ().getValue ().toString ();
568
- Person p = dbControl . getPerson ( personMap .get (personName ) );
521
+ Person p = personMap .get (personName );
569
522
570
523
String affiName = multiAffilTab .getOrganizationBox ().getValue ().toString ();
571
- Person newP = new Person (p .getUsername (), p .getTitle (), p .getFirstName (), p .getLastName (),
572
- p .getEmail (), p .getPhone (), affiMap .get (affiName ), affiName , "" );
573
- multiAffilTab .addDataToTable (new ArrayList <Person >(Arrays .asList (newP )));
524
+ PersonBuilder personBuilder = new PersonBuilder ();
525
+ personBuilder .createPerson (p .getTitle (), p .getFirstName (), p .getLastName (),
526
+ p .getEmail ())
527
+ .withUsername (p .getUsername ())
528
+ .withPhoneNumber (p .getPhone ())
529
+ .withRoleAtAffiliation (affiMap .get (affiName ), affiName , "" );
530
+ multiAffilTab .addDataToTable (new ArrayList <>(Arrays .asList (personBuilder .getPerson ())));
574
531
multiAffilTab .getAddButton ().setEnabled (false );
575
532
}
576
533
});
@@ -582,7 +539,7 @@ public void valueChange(ValueChangeEvent event) {
582
539
if (multiAffilTab .getPersonBox ().getValue () != null ) {
583
540
String personName = multiAffilTab .getPersonBox ().getValue ().toString ();
584
541
multiAffilTab .reactToPersonSelection (personName ,
585
- dbControl .getPersonWithAffiliations (personMap .get (personName )));
542
+ dbControl .getPersonWithAffiliations (personMap .get (personName ). getId () ));
586
543
multiAffilTab .getAddButton ().setEnabled (multiAffilTab .newAffiliationPossible ());
587
544
}
588
545
}
@@ -621,14 +578,5 @@ private void inputError() {
621
578
private void commitError (String reason ) {
622
579
Styles .notification ("There has been an error." , reason , NotificationType .ERROR );
623
580
}
624
- //
625
- // private String getPortletContextName(VaadinRequest request) {
626
- // WrappedPortletSession wrappedPortletSession =
627
- // (WrappedPortletSession) request.getWrappedSession();
628
- // PortletSession portletSession = wrappedPortletSession.getPortletSession();
629
- //
630
- // final PortletContext context = portletSession.getPortletContext();
631
- // final String portletContextName = context.getPortletContextName();
632
- // return portletContextName;
633
- // }
581
+
634
582
}
0 commit comments