2828import java .util .Set ;
2929import life .qbic .datamodel .persons .Affiliation ;
3030import life .qbic .datamodel .persons .CollaboratorWithResponsibility ;
31- import life .qbic .datamodel .persons .Person ;
32- import life .qbic .datamodel .projects .ProjectInfo ;
3331import life .qbic .openbis .openbisclient .IOpenBisClient ;
3432import life .qbic .openbis .openbisclient .OpenBisClient ;
3533import life .qbic .portal .Styles ;
3937import life .qbic .portal .utils .PortalUtils ;
4038import life .qbic .userdb .Config ;
4139import 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 ;
4244import life .qbic .userdb .views .AffiliationInput ;
4345import life .qbic .userdb .views .AffiliationVIPTab ;
4446import life .qbic .userdb .views .MultiAffiliationTab ;
5557 * found in the {@code portal-utils-lib} library.
5658 */
5759@ Theme ("mytheme" )
58- @ SuppressWarnings ("serial" )
5960@ Widgetset ("life.qbic.portlet.AppWidgetSet" )
6061public class UserDBPortletUI extends QBiCPortletUI {
6162
6263 private static final Logger logger = LogManager .getLogger (UserDBPortletUI .class );
6364 private DBManager dbControl ;
6465 private Map <String , Integer > affiMap ;
65- private Map <String , Integer > personMap ;
66+ private Map <String , Person > personMap ;
6667 private Map <String , ProjectInfo > projectMap ;
6768
6869 private TabSheet options ;
6970
70- private ConfigurationManager manager ;
7171 private Config config ;
7272 public static String tmpFolder ;
7373
@@ -84,7 +84,7 @@ protected Layout getPortletContent(final VaadinRequest request) {
8484
8585 String userID = "" ;
8686 boolean success = true ;
87- manager = ConfigurationManagerFactory .getInstance ();
87+ ConfigurationManager manager = ConfigurationManagerFactory .getInstance ();
8888 tmpFolder = manager .getTmpFolder ();
8989 if (PortalUtils .isLiferayPortlet ()) {
9090 // read in the configuration file
@@ -151,47 +151,6 @@ private void initTabs() {
151151 } else {
152152 personMap = dbControl .getPersonMap ();
153153
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- */
195154 String userID = "" ;
196155 if (PortalUtils .isLiferayPortlet ()) {
197156 logger .info ("DB Tools running on Liferay, fetching user ID." );
@@ -202,9 +161,9 @@ private void initTabs() {
202161 userID = "admin" ;
203162 }
204163 }
205- Map <String , ProjectInfo > userProjects = new HashMap <String , ProjectInfo >();
164+ Map <String , ProjectInfo > userProjects = new HashMap <>();
206165
207- List <Project > openbisProjectsForUser = new ArrayList <Project >();
166+ List <Project > openbisProjectsForUser = new ArrayList <>();
208167 Set <String > spaces = new HashSet <>(openbis .getUserSpaces (userID ));
209168
210169 List <Project > allOpenbisProjects = openbis .listProjects ();
@@ -221,8 +180,10 @@ private void initTabs() {
221180 desc = desc .replaceAll ("\n +" , ". " );
222181 String projectID = p .getIdentifier ().getIdentifier ();
223182 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+ }
226187 else {
227188 ProjectInfo info = dbProjects .get (projectID );
228189 info .setDescription (desc );
@@ -243,7 +204,7 @@ private void initTabs() {
243204 // searchView, projectView);
244205 projectView .getProjectTable ().addValueChangeListener (new ValueChangeListener () {
245206
246- private Map <String , String > expTypeCodeTranslation = new HashMap <String , String >() {
207+ private final Map <String , String > expTypeCodeTranslation = new HashMap <String , String >() {
247208 {
248209 put ("Q_EXPERIMENTAL_DESIGN" , "Patients/Sources" );
249210 put ("Q_SAMPLE_EXTRACTION" , "Sample Extracts" );
@@ -262,7 +223,7 @@ public void valueChange(ValueChangeEvent event) {
262223 List <CollaboratorWithResponsibility > collaborators =
263224 dbControl .getCollaboratorsOfProject (project );
264225 // get openbis experiments and type
265- Map <String , String > existingExps = new HashMap <String , String >();
226+ Map <String , String > existingExps = new HashMap <>();
266227 for (Experiment e : openbis .getExperimentsOfProjectByCode (project )) {
267228 String type = expTypeCodeTranslation .get (e .getType ().getCode ());
268229 String id = e .getIdentifier ().getIdentifier ();
@@ -285,22 +246,14 @@ public void valueChange(ValueChangeEvent event) {
285246 }
286247 projectView .setCollaboratorsOfProject (collaborators );
287248
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 );
291250
292- projectView .handleProjectValueChange (item , investigator , contact , manager );
251+ projectView .handleProjectValueChange (item , info . getInvestigator (), info . getContact (), info . getManager () );
293252 } else {
294253 projectView .handleProjectDeselect ();
295254 }
296255 }
297256
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- }
304257 });
305258
306259 projectView .getInfoCommitButton ().addClickListener (new ClickListener () {
@@ -316,18 +269,18 @@ public void buttonClick(ClickEvent event) {
316269 info .getSecondaryName ());
317270 else
318271 dbControl .addOrChangeSecondaryNameForProject (id , info .getSecondaryName ());
319- if (info .getInvestigator () == null || info . getInvestigator (). isEmpty () )
272+ if (info .getInvestigator () == null )
320273 dbControl .removePersonFromProject (id , "PI" );
321274 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 )
324277 dbControl .removePersonFromProject (id , "Contact" );
325278 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 )
328281 dbControl .removePersonFromProject (id , "Manager" );
329282 else
330- dbControl .addOrUpdatePersonToProject (id , personMap . get ( info .getManager ()), "Manager" );
283+ dbControl .addOrUpdatePersonToProject (id , info .getManager (). getId ( ), "Manager" );
331284 projectView .updateChangedInfo (info );
332285 }
333286 }
@@ -344,7 +297,7 @@ public void buttonClick(ClickEvent event) {
344297 String name = c .getPerson ();
345298 int personID = -1 ;
346299 if (personMap .get (name ) != null )
347- personID = personMap .get (name );
300+ personID = personMap .get (name ). getId () ;
348301 if (personID < 1 )
349302 dbControl .removePersonFromExperiment (experimentID );
350303 else
@@ -424,7 +377,7 @@ private void initPortletToDBFunctionality(final AffiliationInput addAffilTab,
424377 @ Override
425378 public void buttonClick (ClickEvent event ) {
426379 if (batchUpload .isValid ()) {
427- List <String > registered = new ArrayList <String >();
380+ List <String > registered = new ArrayList <>();
428381 batchUpload .setRegEnabled (false );
429382 for (Person p : batchUpload .getPeople ()) {
430383 if (dbControl .personExists (p )) {
@@ -453,18 +406,18 @@ public void buttonClick(ClickEvent event) {
453406 if (affi != null && !affi .isEmpty ()) {
454407 search .setAffiliations (dbControl .getAffiliationsContaining (affi ));
455408 } else
456- search .setAffiliations (new ArrayList <Affiliation >());
409+ search .setAffiliations (new ArrayList <>());
457410 }
458411 });
459412
460413 search .getSearchPersonButton ().addClickListener (new Button .ClickListener () {
461414 @ Override
462415 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 ));
466419 } else
467- search .setPersons (new ArrayList <Person >());
420+ search .setPersons (new ArrayList <>());
468421 }
469422 });
470423
@@ -550,7 +503,7 @@ public void buttonClick(ClickEvent event) {
550503 public void buttonClick (ClickEvent event ) {
551504 if (multiAffilTab .isValid ()) {
552505 if (dbControl .addOrUpdatePersonAffiliationConnections (
553- personMap .get (multiAffilTab .getPersonBox ().getValue ()),
506+ personMap .get (multiAffilTab .getPersonBox ().getValue ()). getId () ,
554507 multiAffilTab .getChangedAndNewConnections ()))
555508 successfulCommit ();
556509 else
@@ -565,12 +518,16 @@ public void buttonClick(ClickEvent event) {
565518 @ Override
566519 public void buttonClick (ClickEvent event ) {
567520 String personName = multiAffilTab .getPersonBox ().getValue ().toString ();
568- Person p = dbControl . getPerson ( personMap .get (personName ) );
521+ Person p = personMap .get (personName );
569522
570523 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 ())));
574531 multiAffilTab .getAddButton ().setEnabled (false );
575532 }
576533 });
@@ -582,7 +539,7 @@ public void valueChange(ValueChangeEvent event) {
582539 if (multiAffilTab .getPersonBox ().getValue () != null ) {
583540 String personName = multiAffilTab .getPersonBox ().getValue ().toString ();
584541 multiAffilTab .reactToPersonSelection (personName ,
585- dbControl .getPersonWithAffiliations (personMap .get (personName )));
542+ dbControl .getPersonWithAffiliations (personMap .get (personName ). getId () ));
586543 multiAffilTab .getAddButton ().setEnabled (multiAffilTab .newAffiliationPossible ());
587544 }
588545 }
@@ -621,14 +578,5 @@ private void inputError() {
621578 private void commitError (String reason ) {
622579 Styles .notification ("There has been an error." , reason , NotificationType .ERROR );
623580 }
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+
634582}
0 commit comments