package gal.udc.fic.muei.tfm.dap.flipper.web.rest.dto; import gal.udc.fic.muei.tfm.dap.flipper.domain.User; import org.hibernate.validator.constraints.Email; import javax.validation.constraints.NotNull; import javax.validation.constraints.Pattern; import javax.validation.constraints.Size; import java.util.Set; import java.util.stream.Collectors; /** * A DTO representing a user, with his authorities. * * This file is part of Flipper Open Reverse Image Search. Flipper Open Reverse Image Search is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Flipper Open Reverse Image Search is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Flipper Open Reverse Image Search. If not, see <http://www.gnu.org/licenses/>. */ public class UserDTO { public static final int PASSWORD_MIN_LENGTH = 5; public static final int PASSWORD_MAX_LENGTH = 100; @Pattern(regexp = "^[a-z0-9]*$") @NotNull @Size(min = 1, max = 50) private String login; @NotNull @Size(min = PASSWORD_MIN_LENGTH, max = PASSWORD_MAX_LENGTH) private String password; @Size(max = 50) private String firstName; @Size(max = 50) private String lastName; @Email @Size(min = 5, max = 100) private String email; private boolean activated = false; @Size(min = 2, max = 5) private String langKey; private Set<String> authorities; public UserDTO() { } public UserDTO(User user) { this(user.getLogin(), null, user.getFirstName(), user.getLastName(), user.getEmail(), user.getActivated(), user.getLangKey(), user.getAuthorities()); } public UserDTO(String login, String password, String firstName, String lastName, String email, boolean activated, String langKey, Set<String> authorities) { this.login = login; this.password = password; this.firstName = firstName; this.lastName = lastName; this.email = email; this.activated = activated; this.langKey = langKey; this.authorities = authorities; } public String getPassword() { return password; } public String getLogin() { return login; } public String getFirstName() { return firstName; } public String getLastName() { return lastName; } public String getEmail() { return email; } public boolean isActivated() { return activated; } public String getLangKey() { return langKey; } public Set<String> getAuthorities() { return authorities; } @Override public String toString() { return "UserDTO{" + "login='" + login + '\'' + ", password='" + password + '\'' + ", firstName='" + firstName + '\'' + ", lastName='" + lastName + '\'' + ", email='" + email + '\'' + ", activated=" + activated + ", langKey='" + langKey + '\'' + ", authorities=" + authorities + '}'; } }