Java tutorial
/* * Copyright 2011 GantzGulch, Inc. * * This file is part of GantzFileSharing. * * GantzFileSharing 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. * * GantzFileSharing 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 GantzFileSharing. If not, see <http://www.gnu.org/licenses/>. */ package com.gantzgulch.sharing.form; import java.util.List; import javax.validation.constraints.Size; import org.hibernate.validator.constraints.NotEmpty; import com.gantzgulch.sharing.domain.User; import com.gantzgulch.sharing.domain.UserRole; import com.google.common.collect.Lists; public class UserForm { public static UserForm create(User user) { return user != null ? new UserForm(user) : new UserForm(); } private String id; @NotEmpty @Size(max = 50) private String username; @NotEmpty @Size(max = 50) private String password; @NotEmpty @Size(max = 128) private String name; @Size(max = 256) private String email; private boolean isEnabled; private List<String> roles; public UserForm() { } public UserForm(User user) { this.id = user.getId(); this.username = user.getUsername(); this.password = user.getPassword(); this.name = user.getName(); this.email = user.getEmail(); this.roles = Lists.transform(user.getUserRoles(), new UserRole.UserRoleToStringFunction()); } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getName() { return name; } public void setName(String name) { this.name = name; } public List<String> getRoles() { return roles; } public void setRoles(List<String> roles) { this.roles = roles; } public boolean getIsEnabled() { return isEnabled; } public void setIsEnabled(boolean isEnabled) { this.isEnabled = isEnabled; } }