Remove username attribute

This commit is contained in:
Paulo Gustavo Veiga
2012-07-15 00:57:44 -03:00
parent 80cafc0c0d
commit 853aa0ad5c
30 changed files with 65 additions and 168 deletions

View File

@@ -201,16 +201,16 @@ public class MindmapManagerImpl
}
@Override
public void removeMindmap(MindMap mindMap) {
public void removeMindmap(@NotNull final MindMap mindMap) {
getHibernateTemplate().delete(mindMap);
}
private void saveHistory(MindMap mindMap) {
private void saveHistory(@NotNull final MindMap mindMap) {
final MindMapHistory history = new MindMapHistory();
history.setXml(mindMap.getXml());
history.setCreationTime(Calendar.getInstance());
history.setCreator(mindMap.getLastModifierUser());
history.setEditor(mindMap.getLastEditor());
history.setMindmapId(mindMap.getId());
getHibernateTemplate().saveOrUpdate(history);
}

View File

@@ -33,8 +33,6 @@ public interface UserManager {
public User getUserBy(long id);
User getUserByUsername(String username);
void createUser(User user);
void auditLogin(@NotNull AccessAuditory accessAuditory);

View File

@@ -73,19 +73,6 @@ public class UserManagerImpl
return getHibernateTemplate().get(User.class, id);
}
@Override
public User getUserByUsername(String username) {
final User user;
final List users = getHibernateTemplate().find("from com.wisemapping.model.User colaborator where username=?", username);
if (users != null && !users.isEmpty()) {
assert users.size() == 1 : "More than one user with the same username!";
user = (User) users.get(0);
} else {
user = null;
}
return user;
}
@Override
public void createUser(User user) {
assert user != null : "Trying to store a null user";

View File

@@ -40,7 +40,7 @@ public class MindMap {
private boolean isPublic;
private Calendar lastModificationTime;
private String lastModifierUser;
private User lastEditor;
private Set<Collaboration> collaborations = new HashSet<Collaboration>();
@@ -144,12 +144,13 @@ public class MindMap {
this.lastModificationTime = lastModificationTime;
}
public String getLastModifierUser() {
return lastModifierUser;
@Nullable
public User getLastEditor() {
return lastEditor;
}
public void setLastModifierUser(String lastModifierUser) {
this.lastModifierUser = lastModifierUser;
public void setLastEditor(@Nullable User lastEditor) {
this.lastEditor = lastEditor;
}
public int getId() {

View File

@@ -18,21 +18,19 @@
package com.wisemapping.model;
import com.wisemapping.util.ZipUtils;
import org.jetbrains.annotations.Nullable;
import java.util.Calendar;
import java.io.IOException;
public class MindMapHistory {
private int id;
private Calendar creationTime;
private String creator;
private User editor;
private byte[] xml;
private int mindmapId;
public MindMapHistory()
{
public MindMapHistory() {
}
@@ -60,12 +58,13 @@ public class MindMapHistory {
this.creationTime = creationTime;
}
public String getCreator() {
return creator;
@Nullable
public User getEditor() {
return editor;
}
public void setCreator(String creator) {
this.creator = creator;
public void setEditor(@Nullable User editor) {
this.editor = editor;
}
public byte[] getXml() {

View File

@@ -32,7 +32,6 @@ public class User
private String password;
private long activationCode;
private Calendar activationDate;
private String username;
private Set<String> tags = new HashSet<String>();
private boolean allowSendEmail = false;
private String locale;
@@ -118,9 +117,7 @@ public class User
final String email = getEmail();
if (email != null ? !email.equals(user.getEmail()) : user.getEmail() != null) return false;
if (firstname != null ? !firstname.equals(user.firstname) : user.firstname != null) return false;
if (lastname != null ? !lastname.equals(user.lastname) : user.lastname != null) return false;
return !(username != null ? !username.equals(user.username) : user.username != null);
return !(lastname != null ? !lastname.equals(user.lastname) : user.lastname != null);
}
@@ -133,14 +130,6 @@ public class User
return result;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
@Nullable
public String getLocale() {
return locale;

View File

@@ -108,7 +108,6 @@ public class UsersController {
// trim() the email email in order to remove spaces ...
user.setEmail(userBean.getEmail().trim());
user.setUsername(userBean.getUsername());
user.setFirstname(userBean.getFirstname());
user.setLastname(userBean.getLastname());
user.setPassword(userBean.getPassword());

View File

@@ -58,16 +58,6 @@ public class AdminController extends BaseController {
return new ModelAndView("userView", "user", new RestUser(user));
}
@RequestMapping(method = RequestMethod.GET, value = "admin/users/username/{username}", produces = {"application/json", "text/html", "application/xml"})
@ResponseBody
public ModelAndView getUserByUsername(@PathVariable String username) throws IOException {
final User user = userService.getUserByUsername(username);
if (user == null) {
throw new IllegalArgumentException("User '" + username + "' could not be found");
}
return new ModelAndView("userView", "user", new RestUser(user));
}
@RequestMapping(method = RequestMethod.POST, value = "admin/users", consumes = {"application/xml", "application/json"}, produces = {"application/json", "text/html", "application/xml"})
@ResponseStatus(value = HttpStatus.CREATED)
public void createUser(@RequestBody RestUser user, HttpServletResponse response) throws IOException, WiseMappingException {
@@ -81,15 +71,6 @@ public class AdminController extends BaseController {
throw new IllegalArgumentException("User already exists with this email.");
}
final String username = user.getUsername();
if (username == null || username.isEmpty()) {
throw new IllegalArgumentException("username can not be null");
}
if (userService.getUserByUsername(username) != null) {
throw new IllegalArgumentException("User already exists with this username.");
}
// Run some other validations ...
final User delegated = user.getDelegated();
final String lastname = delegated.getLastname();

View File

@@ -438,7 +438,7 @@ public class MindmapController extends BaseController {
private void saveMindmap(boolean minor, @NotNull final MindMap mindMap, @NotNull final User user) throws WiseMappingException {
final Calendar now = Calendar.getInstance();
mindMap.setLastModificationTime(now);
mindMap.setLastModifierUser(user.getUsername());
mindMap.setLastEditor(user);
mindmapService.updateMindmap(mindMap, !minor);
}

View File

@@ -81,8 +81,8 @@ public class RestMindmap {
return mindmap.getCreator().getEmail();
}
public String getLastModifierUser() {
return mindmap.getLastModifierUser();
public Collaborator getLastModifierUser() {
return mindmap.getLastEditor();
}
public String getLastModificationTime() {

View File

@@ -44,7 +44,7 @@ public class RestMindmapHistory {
public RestMindmapHistory(@NotNull MindMapHistory history) {
this.id = history.getId();
this.creation = history.getCreationTime();
this.creator = history.getCreator();
this.creator = history.getEditor().getFullName();
}
public String getCreationTime() {

View File

@@ -88,7 +88,8 @@ public class RestMindmapInfo {
}
public String getLastModifierUser() {
return mindmap.getLastModifierUser();
final User user = mindmap.getLastEditor();
return user != null ? user.getFullName() : "unknown";
}
public String getLastModificationTime() {

View File

@@ -66,14 +66,6 @@ public class RestUser {
// return user.isActive();
// }
public String getUsername() {
return user.getUsername();
}
public void setUsername(String username) {
user.setUsername(username);
}
public long getId() {
return user.getId();
}

View File

@@ -137,8 +137,7 @@ public class MindmapServiceImpl
}
final Calendar creationTime = Calendar.getInstance();
final String username = user.getUsername();
map.setLastModifierUser(username);
map.setLastEditor(user);
map.setCreationTime(creationTime);
map.setLastModificationTime(creationTime);
map.setCreator(user);

View File

@@ -34,8 +34,6 @@ public interface UserService {
public User getUserBy(long id);
public User getUserByUsername(String username);
public void updateUser(User user);
public void resetPassword(@NotNull String email) throws InvalidUserEmailException;

View File

@@ -176,11 +176,6 @@ public class UserServiceImpl
return userManager.getUserBy(email);
}
@Override
public User getUserByUsername(String username) {
return userManager.getUserByUsername(username);
}
@Override
public User getUserBy(long id) {
return userManager.getUserBy(id);

View File

@@ -56,14 +56,6 @@ public class UserValidator
Utils.validateEmailAddress(email, errors);
}
// Validate username ...
final String username = user.getUsername();
if (username != null && userService.getUserByUsername(username) != null) {
errors.rejectValue("username", Messages.USERNAME_ALREADY_EXIST);
} else {
ValidationUtils.rejectIfEmpty(errors, "username", Messages.FIELD_REQUIRED);
}
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstname", Messages.FIELD_REQUIRED);
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastname", Messages.FIELD_REQUIRED);
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", Messages.FIELD_REQUIRED);
@@ -78,11 +70,6 @@ public class UserValidator
"The lastname must have less than " + Constants.MAX_USER_LASTNAME_LENGTH + " characters.",
user.getLastname(),
Constants.MAX_USER_LASTNAME_LENGTH);
ValidatorUtils.rejectIfExceeded(errors,
"username",
"The username must have less than " + Constants.MAX_USER_USERNAME_LENGTH + " characters.",
username,
Constants.MAX_USER_USERNAME_LENGTH);
ValidatorUtils.rejectIfExceeded(errors,
"password",
"The password must have less than " + Constants.MAX_USER_PASSWORD_LENGTH + " characters.",

View File

@@ -22,48 +22,40 @@ import com.wisemapping.model.CollaborationRole;
import com.wisemapping.model.Collaborator;
import com.wisemapping.model.User;
public class CollaboratorBean
{
public class CollaboratorBean {
private CollaborationRole collaborationRole;
private boolean isUser;
private Collaborator collaborator;
public CollaboratorBean(Collaborator collaborator, CollaborationRole role)
{
public CollaboratorBean(Collaborator collaborator, CollaborationRole role) {
this.collaborator = collaborator;
this.collaborationRole = role;
this.isUser = false;
}
public CollaboratorBean(User user, CollaborationRole role)
{
public CollaboratorBean(User user, CollaborationRole role) {
this.collaborator = user;
this.collaborationRole = role;
this.isUser = true;
}
public boolean isUser()
{
public boolean isUser() {
return isUser;
}
public String getRole()
{
public String getRole() {
return collaborationRole.name();
}
public String getUsername()
{
return isUser ? ((User) collaborator).getUsername() : collaborator.getEmail();
public String getUsername() {
return isUser ? ((User) collaborator).getFullName() : collaborator.getEmail();
}
public String getEmail()
{
public String getEmail() {
return collaborator.getEmail();
}
public long getId()
{
public long getId() {
return collaborator.getId();
}
}

View File

@@ -69,7 +69,8 @@ public class MindMapBean {
}
public String getLastEditor() {
return mindmap.getLastModifierUser();
final User lastEditor = mindmap.getLastEditor();
return lastEditor != null ? lastEditor.getFullName() : "";
}
public String getLastEditTime() {