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() {

View File

@ -21,13 +21,12 @@
<joined-subclass name="com.wisemapping.model.User" table="USER">
<key column="COLABORATOR_ID"/>
<property name="username" not-null="true"/>
<property name="firstname"/>
<property name="lastname"/>
<property name="password"/>
<property name="activationDate" column="activation_date"/>
<property name="activationCode"/>
<property name="allowSendEmail"/>
<property name="activationCode" column="activation_code"/>
<property name="allowSendEmail" column="allow_send_email"/>
<property name="locale"/>
<set name="tags" table="TAG">
<key column="user_id"/>

View File

@ -13,11 +13,11 @@
<property name="public"/>
<property name="description"/>
<property name="zippedXml" column="XML"/>
<property name="lastModifierUser" column="last_editor"/>
<property name="lastModificationTime" column="edition_date"/>
<property name="creationTime" column="creation_date"/>
<property name="tags" column="tags"/>
<many-to-one name="creator" column="creator_id" unique="true" not-null="true"/>
<many-to-one name="creator" column="creator_id" unique="true" not-null="false" lazy="proxy"/>
<many-to-one name="lastEditor" column="last_editor_id" unique="false" not-null="true" lazy="proxy"/>
<set name="collaborations"
cascade="all,delete-orphan"

View File

@ -11,9 +11,9 @@
</id>
<property name="mindmapId" column="mindmap_id"/>
<property name="xml" column="XML"/>
<property name="creationTime" column="creation_date"/>
<property name="creator" column="creator_user"/>
<property name="xml" column="XML"/>
<property name="creationTime" column="creation_date"/>
<many-to-one name="editor" column="editor_id" unique="false" not-null="false" lazy="proxy"/>
</class>
</hibernate-mapping>

View File

@ -4,7 +4,7 @@
<div>
<ul class="nav nav-tabs">
<li class="active"><a href="#general" data-toggle="pill">General</a></li>
<li class="active"><a href="#general" data-toggle="pill"><spring:message code="DESCRIPTION"/></a></li>
<li><a href="#collaborators" data-toggle="pill"><spring:message code="SHARED"/></a></li>
<li><a href="#publish" data-toggle="pill"><spring:message code="PUBLIC"/></a></li>
</ul>
@ -14,7 +14,7 @@
<ul class="unstyled">
<li><strong><spring:message code="NAME"/>:</strong> ${mindmap.title}</li>
<li><strong><spring:message code="DESCRIPTION"/>:</strong> ${mindmap.description}</li>
<li><strong><spring:message code="CREATOR"/>:</strong> ${mindmap.creator.username}</li>
<li><strong><spring:message code="CREATOR"/>:</strong> ${mindmap.creator.fullName}</li>
<li><strong><spring:message code="CREATION_TIME"/>:</strong> ${mindmap.creationTime}</li>
<li><strong><spring:message code="LAST_UPDATE"/>:</strong> ${mindmap.lastEditTime}</li>
<li><strong><spring:message code="LAST_UPDATE_BY"/>:</strong> ${mindmap.lastEditor}</li>

View File

@ -13,11 +13,6 @@
<form:input path="email" id="email" type="email" required="required"/>
<form:errors path="email" cssClass="errorMsg"/>
<label for="username"> <spring:message code="USERNAME"/></label>
<form:input path="username" id="username" required="required"/>
<form:errors path="username" cssClass="errorMsg"/>
<label for="firstname"><spring:message code="FIRSTNAME"/></label>
<form:input path="firstname" id="firstname" required="required"/>
<form:errors path="firstname" cssClass="errorMsg"/>

View File

@ -75,25 +75,6 @@ public class RestAdminITCase {
}
}
@Test(dataProvider = "ContentType-Provider-Function")
public void findUserByUsername(final @NotNull MediaType mediaType) { // Configure media types ...
final HttpHeaders requestHeaders = createHeaders(mediaType);
final RestTemplate templateRest = createTemplate();
final RestUser restUser = createDummyUser();
// User has been created ...
createUser(requestHeaders, templateRest, restUser);
// Check that the user has been created ...
HttpEntity<RestUser> findUserEntity = new HttpEntity<RestUser>(requestHeaders);
final ResponseEntity<RestUser> responseEntity = templateRest.exchange(BASE_REST_URL + "/admin/users/username/" + restUser.getUsername(), HttpMethod.GET, findUserEntity, RestUser.class);
assertEquals(responseEntity.getBody().getUsername(), restUser.getUsername());
}
public String createNewUser(final @NotNull MediaType mediaType) {
// Configure media types ...
@ -172,7 +153,6 @@ public class RestAdminITCase {
final String username = "foo-to-delete" + System.nanoTime();
final String email = username + "@example.org";
restUser.setEmail(email);
restUser.setUsername(username);
restUser.setFirstname("foo first name");
restUser.setLastname("foo last name");
restUser.setPassword("admin");

View File

@ -6,13 +6,12 @@ creation_date date);
CREATE TABLE USER (
id INTEGER NOT NULL IDENTITY,
colaborator_id INTEGER NOT NULL,
username varchar(255) NOT NULL,
firstname varchar(255) NOT NULL,
lastname varchar(255) NOT NULL,
password varchar(255) NOT NULL,
activationCode BIGINT NOT NULL,
activation_code BIGINT NOT NULL,
activation_date DATE,
allowSendEmail CHAR(1) NOT NULL,
allow_send_email CHAR(1) NOT NULL,
locale varchar(5),
FOREIGN KEY(colaborator_id) REFERENCES COLLABORATOR(id)
);
@ -27,7 +26,7 @@ creation_date DATETIME,
edition_date DATETIME,
creator_id INTEGER NOT NULL,
tags varchar(1014) ,
last_editor varchar(255) ,
last_editor_id INTEGER NOT NULL
--FOREIGN KEY(creator_id) REFERENCES USER(colaborator_id)
);
@ -36,7 +35,7 @@ CREATE TABLE MINDMAP_HISTORY
xml LONGVARBINARY NOT NULL,
mindmap_id INTEGER NOT NULL,
creation_date DATETIME,
creator_user varchar(255));
editor_id INTEGER NOT NULL);
CREATE TABLE COLLABORATION_PROPERTIES
(id INTEGER NOT NULL IDENTITY,

View File

@ -1,10 +1,10 @@
INSERT INTO COLLABORATOR(id,email,creation_date) values (1,'test@wisemapping.org',CURDATE());
INSERT INTO USER (colaborator_id,username,firstname, lastname, password, activationCode,activation_date,allowSendEmail)
values(1,'wise-test','Test','User', 'ENC:a94a8fe5ccb19ba61c4c0873d391e987982fbbd3',1237,CURDATE(),1);
INSERT INTO USER (colaborator_id,firstname, lastname, password, activation_code,activation_date,allow_send_email)
values(1,'Test','User', 'ENC:a94a8fe5ccb19ba61c4c0873d391e987982fbbd3',1237,CURDATE(),1);
INSERT INTO COLLABORATOR(id,email,creation_date) values (2,'admin@wisemapping.org',CURDATE());
INSERT INTO USER (colaborator_id,username,firstname, lastname, password, activationCode,activation_date,allowSendEmail)
values(2,'wise-admin','Admin','User', 'admin',1237,CURDATE(),1);
INSERT INTO USER (colaborator_id,firstname, lastname, password, activation_code,activation_date,allow_send_email)
values(2,'Admin','User', 'admin',1237,CURDATE(),1);
COMMIT;

View File

@ -7,7 +7,6 @@ creation_date date
CREATE TABLE USER (
id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
colaborator_id INTEGER NOT NULL,
username varchar(255) CHARACTER SET utf8 NOT NULL,
firstname varchar(255) CHARACTER SET utf8 NOT NULL,
lastname varchar(255) CHARACTER SET utf8 NOT NULL,
password varchar(255) CHARACTER SET utf8 NOT NULL,
@ -28,7 +27,7 @@ creation_date datetime,
edition_date datetime,
creator_id INTEGER not null,
tags varchar(1014) CHARACTER SET utf8 ,
last_editor varchar(255) CHARACTER SET utf8 ,
last_editor_id INTEGER NOT NULL,
FOREIGN KEY(creator_id) REFERENCES USER(colaborator_id) ON DELETE CASCADE ON UPDATE NO ACTION
) CHARACTER SET utf8 ;
@ -38,7 +37,7 @@ CREATE TABLE MINDMAP_HISTORY
xml blob NOT NULL,
mindmap_id INTEGER NOT NULL,
creation_date datetime,
creator_user varchar(255) CHARACTER SET utf8
editor_id INTEGER NOT NULL
) CHARACTER SET utf8 ;
CREATE TABLE COLLABORATION_PROPERTIES(

View File

@ -1,10 +1,10 @@
INSERT INTO COLLABORATOR(id,email,creation_date) values (1,'test@wisemapping.org',CURRENT_DATE());
INSERT INTO USER (colaborator_id,username,firstname, lastname, password, activationCode,activation_date,allowSendEmail)
values(1,'wise-test','Test','User', 'ENC:a94a8fe5ccb19ba61c4c0873d391e987982fbbd3',1237,CURRENT_DATE(),1);
INSERT INTO USER (colaborator_id,firstname, lastname, password, activation_code,activation_date,allow_send_email)
values(1,'Test','User', 'ENC:a94a8fe5ccb19ba61c4c0873d391e987982fbbd3',1237,CURRENT_DATE(),1);
INSERT INTO COLLABORATOR(id,email,creation_date) values (2,'admin@wisemapping.org',CURRENT_DATE());
INSERT INTO USER (colaborator_id,username,firstname, lastname, password, activationCode,activation_date,allowSendEmail)
values(2,'wise-admin','Admin','User', 'admin',1237,CURRENT_DATE(),1);
INSERT INTO USER (colaborator_id,firstname, lastname, password, activation_code,activation_date,allow_send_email)
values(2,'Admin','User', 'admin',1237,CURRENT_DATE(),1);
COMMIT;

View File

@ -30,9 +30,15 @@ ALTER TABLE ACCESS_AUDITORY
ON UPDATE NO ACTION
, ADD INDEX `user_id` () ;
ALTER TABLE `wisemapping`.`mindmap_history` DROP COLUMN `creator_user` , ADD COLUMN `editor_id` INT(11) NULL DEFAULT NULL AFTER `creation_date`;
ALTER TABLE `wisemapping`.`user` ADD COLUMN `locale` VARCHAR(5) NULL AFTER `allowSendEmail` ;
ALTER TABLE `wisemapping`.`mindmap` DROP COLUMN `last_editor` , ADD COLUMN `last_editor_id` INT(11) NULL DEFAULT NULL AFTER `tags` ;
ALTER TABLE `wisemapping2`.`user` DROP COLUMN `username` , CHANGE COLUMN `activationCode` `activation_code` BIGINT(20) NOT NULL , CHANGE COLUMN `allowSendEmail` `allow_send_email` CHAR(1) NOT NULL DEFAULT '0' ;
# INSERT INTO `wisemapping`.`collaborator` (`id`, `email`, `creation_date`) VALUES (8081, 'fake@wisemapping.com', '2007-10-09');
# DELETE FROM `wisemapping`.`USER` where activation_date is null;
# DROP TABLE FEEDBACK;