From db143e1b3794e218bbf1946dd7d65b5452a8b319 Mon Sep 17 00:00:00 2001 From: anhefti Date: Wed, 4 Mar 2020 09:30:49 +0100 Subject: [PATCH] fixed user multi selection --- .../sebserver/gbl/model/user/UserInfo.java | 9 +++ .../gui/widget/MultiSelectionCombo.java | 2 +- .../webservice/AdminUserInitializer.java | 81 +++++++++---------- 3 files changed, 49 insertions(+), 43 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/model/user/UserInfo.java b/src/main/java/ch/ethz/seb/sebserver/gbl/model/user/UserInfo.java index f828a0a5..c3c3daf9 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/model/user/UserInfo.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/model/user/UserInfo.java @@ -21,6 +21,7 @@ import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; +import ch.ethz.seb.sebserver.gbl.model.EntityName; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; import org.joda.time.DateTime; @@ -243,6 +244,14 @@ public final class UserInfo implements UserAccount, Serializable { return new EntityKey(this.uuid, entityType()); } + @Override + public EntityName toName() { + return new EntityName( + this.getModelId(), + this.entityType(), + this.getUsername() + " (" + this.getSurname() + " " + this.getName() + ")"); + } + @Override public int hashCode() { final int prime = 31; diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/widget/MultiSelectionCombo.java b/src/main/java/ch/ethz/seb/sebserver/gui/widget/MultiSelectionCombo.java index 054fbd75..10509f4c 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/widget/MultiSelectionCombo.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/widget/MultiSelectionCombo.java @@ -74,6 +74,7 @@ public final class MultiSelectionCombo extends Composite implements Selection { this.dropDown = new DropDown(this.textInput, SWT.NONE); this.textInput.addListener(SWT.FocusIn, event -> openDropDown()); this.textInput.addListener(SWT.Modify, event -> openDropDown()); + this.textInput.addListener(SWT.MouseUp, event -> openDropDown()); this.dropDown.addListener(SWT.Selection, event -> { final int selectionIndex = this.dropDown.getSelectionIndex(); if (selectionIndex >= 0) { @@ -171,7 +172,6 @@ public final class MultiSelectionCombo extends Composite implements Selection { this.availableValues.remove(item); PageService.updateScrolledComposite(this); this.updateAnchor.layout(true, true); - } private void removeComboSelection(final Event event) { diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/AdminUserInitializer.java b/src/main/java/ch/ethz/seb/sebserver/webservice/AdminUserInitializer.java index ed4c8b39..acdf426e 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/AdminUserInitializer.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/AdminUserInitializer.java @@ -89,51 +89,48 @@ class AdminUserInitializer { } } else { final CharSequence generateAdminPassword = this.generateAdminPassword(); - if (generateAdminPassword != null) { + Long institutionId = this.institutionDAO.allMatching(new FilterMap()) + .getOrElse(Collections::emptyList) + .stream() + .findFirst() + .filter(Institution::isActive) + .map(Institution::getInstitutionId) + .orElse(-1L); - Long institutionId = this.institutionDAO.allMatching(new FilterMap()) - .getOrElse(Collections::emptyList) - .stream() - .findFirst() - .filter(Institution::isActive) + if (institutionId < 0) { + + log.debug("Create new initial institution"); + institutionId = this.institutionDAO.createNew(new Institution( + null, + this.orgName, + null, + null, + null, + true)) + .map(inst -> this.institutionDAO.setActive(inst, true).getOrThrow()) .map(Institution::getInstitutionId) - .orElse(-1L); - - if (institutionId < 0) { - - log.debug("Create new initial institution"); - institutionId = this.institutionDAO.createNew(new Institution( - null, - this.orgName, - null, - null, - null, - true)) - .map(inst -> this.institutionDAO.setActive(inst, true).getOrThrow()) - .map(Institution::getInstitutionId) - .getOrThrow(); - } - - this.userDAO.createNew(new UserMod( - this.adminName, - institutionId, - this.adminName, - this.adminName, - this.adminName, - generateAdminPassword, - generateAdminPassword, - null, - null, - null, - new HashSet<>(Arrays.asList(UserRole.SEB_SERVER_ADMIN.name())))) - .flatMap(account -> this.userDAO.setActive(account, true)) - .map(account -> { - writeAdminCredentials(this.adminName, generateAdminPassword); - return account; - }) .getOrThrow(); } - } + + this.userDAO.createNew(new UserMod( + this.adminName, + institutionId, + this.adminName, + this.adminName, + this.adminName, + generateAdminPassword, + generateAdminPassword, + null, + null, + null, + new HashSet<>(Arrays.asList(UserRole.SEB_SERVER_ADMIN.name())))) + .flatMap(account -> this.userDAO.setActive(account, true)) + .map(account -> { + writeAdminCredentials(this.adminName, generateAdminPassword); + return account; + }) + .getOrThrow(); + } } catch (final Exception e) { SEBServerInit.INIT_LOGGER.error("---->"); SEBServerInit.INIT_LOGGER.error("----> SEB Server initial admin-account creation failed: ", e); @@ -161,7 +158,7 @@ class AdminUserInitializer { return ClientCredentialServiceImpl.generateClientSecret(); } catch (final Exception e) { log.error("Unable to generate admin password: ", e); - return null; + throw e; } }