fixed user multi selection
This commit is contained in:
		
							parent
							
								
									a076c62d46
								
							
						
					
					
						commit
						db143e1b37
					
				
					 3 changed files with 49 additions and 43 deletions
				
			
		| 
						 | 
				
			
			@ -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;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue