ItEr39S19CUAltaGrupoUsuarios: Updated the entity User and created entity Profile
Added the field 'email' to User. Created the entity Profile, with its DAO and a basic unit test.
This commit is contained in:
parent
5eb03935a8
commit
bccd7a2047
6 changed files with 272 additions and 0 deletions
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* This file is part of ###PROJECT_NAME###
|
||||
*
|
||||
* Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
|
||||
* Desenvolvemento Tecnolóxico de Galicia
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.navalplanner.business.users.daos;
|
||||
|
||||
import org.navalplanner.business.common.daos.IGenericDAO;
|
||||
import org.navalplanner.business.users.entities.Profile;
|
||||
|
||||
/**
|
||||
* DAO interface for the <code>Profile</code> entity.
|
||||
*
|
||||
* @author Jacobo Aragunde Perez <jaragunde@igalia.com>
|
||||
*/
|
||||
public interface IProfileDAO extends IGenericDAO<Profile, Long>{
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* This file is part of ###PROJECT_NAME###
|
||||
*
|
||||
* Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
|
||||
* Desenvolvemento Tecnolóxico de Galicia
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.navalplanner.business.users.daos;
|
||||
|
||||
import org.navalplanner.business.common.daos.GenericDAOHibernate;
|
||||
import org.navalplanner.business.users.entities.Profile;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* Hibernate DAO for the <code>Profile</code> entity.
|
||||
*
|
||||
* @author Jacobo Aragunde Perez <jaragunde@igalia.com>
|
||||
*/
|
||||
@Repository
|
||||
public class ProfileDAO extends GenericDAOHibernate<Profile, Long> implements
|
||||
IProfileDAO {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* This file is part of ###PROJECT_NAME###
|
||||
*
|
||||
* Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
|
||||
* Desenvolvemento Tecnolóxico de Galicia
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.navalplanner.business.users.entities;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.validator.NotEmpty;
|
||||
import org.navalplanner.business.common.BaseEntity;
|
||||
|
||||
/**
|
||||
* Entity for modeling a profile.
|
||||
*
|
||||
* @author Jacobo Aragunde Perez <jaragunde@igalia.com>
|
||||
*/
|
||||
public class Profile extends BaseEntity {
|
||||
|
||||
@NotEmpty(message="profile name not specified")
|
||||
private String profileName;
|
||||
|
||||
private Set<UserRole> roles = new HashSet<UserRole>();
|
||||
|
||||
/**
|
||||
* Necessary for Hibernate.
|
||||
*/
|
||||
public Profile() {}
|
||||
|
||||
private Profile(String profileName, Set<UserRole> roles) {
|
||||
this.profileName = profileName;
|
||||
this.setRoles(roles);
|
||||
}
|
||||
|
||||
public static Profile create(String loginName, Set<UserRole> roles) {
|
||||
return create(new Profile(loginName, roles));
|
||||
}
|
||||
|
||||
public void setProfileName(String profileName) {
|
||||
this.profileName = profileName;
|
||||
}
|
||||
|
||||
public String getProfileName() {
|
||||
return profileName;
|
||||
}
|
||||
|
||||
public void setRoles(Set<UserRole> roles) {
|
||||
this.roles = roles;
|
||||
}
|
||||
|
||||
public Set<UserRole> getRoles() {
|
||||
return roles;
|
||||
}
|
||||
|
||||
public void addRole(UserRole role) {
|
||||
roles.add(role);
|
||||
}
|
||||
|
||||
public void removeRole(UserRole role) {
|
||||
roles.remove(role);
|
||||
}
|
||||
}
|
||||
|
|
@ -46,6 +46,8 @@ public class User extends BaseEntity {
|
|||
@NotEmpty(message="user roles not specified")
|
||||
private Set<UserRole> roles = new HashSet<UserRole>();
|
||||
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* Necessary for Hibernate. Please, do not call it.
|
||||
*/
|
||||
|
|
@ -88,6 +90,14 @@ public class User extends BaseEntity {
|
|||
this.roles = roles;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
@AssertTrue(message="login name is already being used by another user")
|
||||
public boolean checkConstraintUniqueLoginName() {
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
<version name="version" access="property" type="long" />
|
||||
<property name="loginName" not-null="true" unique="true"/>
|
||||
<property name="password" not-null="true"/>
|
||||
<property name="email"/>
|
||||
<set name="roles" table="USER_ROLES">
|
||||
<key column="userId"/>
|
||||
<element>
|
||||
|
|
@ -33,4 +34,25 @@
|
|||
</set>
|
||||
</class>
|
||||
|
||||
<class name="Profile" table="NAVAL_PROFILE">
|
||||
<id name="id" access="property" type="long">
|
||||
<generator class="hilo">
|
||||
<param name="max_lo">100</param>
|
||||
</generator>
|
||||
</id>
|
||||
<version name="version" access="property" type="long" />
|
||||
|
||||
<property name="profileName" not-null="true" unique="true"/>
|
||||
|
||||
<set name="roles" table="PROFILE_ROLES">
|
||||
<key column="profileId"/>
|
||||
<element>
|
||||
<type name="org.hibernate.type.EnumType">
|
||||
<param name="enumClass">org.navalplanner.business.users.entities.UserRole</param>
|
||||
<!-- 12 is java.sql.Types.VARCHAR -->
|
||||
<param name="type">12</param>
|
||||
</type>
|
||||
</element>
|
||||
</set>
|
||||
</class>
|
||||
</hibernate-mapping>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* This file is part of ###PROJECT_NAME###
|
||||
*
|
||||
* Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
|
||||
* Desenvolvemento Tecnolóxico de Galicia
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.navalplanner.business.test.users.daos;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.navalplanner.business.BusinessGlobalNames.BUSINESS_SPRING_CONFIG_FILE;
|
||||
import static org.navalplanner.business.test.BusinessGlobalNames.BUSINESS_SPRING_CONFIG_TEST_FILE;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.users.daos.IProfileDAO;
|
||||
import org.navalplanner.business.users.entities.Profile;
|
||||
import org.navalplanner.business.users.entities.UserRole;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { BUSINESS_SPRING_CONFIG_FILE,
|
||||
BUSINESS_SPRING_CONFIG_TEST_FILE })
|
||||
/**
|
||||
* Test for {@ProfileDAO}
|
||||
*
|
||||
* @author Jacobo Aragunde Perez <jaragunde@igalia.com>
|
||||
*
|
||||
*/
|
||||
@Transactional
|
||||
public class ProfileDAOTest {
|
||||
|
||||
@Autowired
|
||||
IProfileDAO profileDAO;
|
||||
|
||||
@Test
|
||||
public void testInSpringContainer() {
|
||||
assertNotNull(profileDAO);
|
||||
}
|
||||
|
||||
private Profile createValidProfile() {
|
||||
Set<UserRole> roles = new HashSet<UserRole>();
|
||||
roles.add(UserRole.ROLE_BASIC_USER);
|
||||
return Profile.create(UUID.randomUUID().toString(), roles);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveProfile() {
|
||||
Profile profile = createValidProfile();
|
||||
profileDAO.save(profile);
|
||||
assertNotNull(profile.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveProfile() throws InstanceNotFoundException {
|
||||
Profile profile = createValidProfile();
|
||||
profileDAO.save(profile);
|
||||
profileDAO.remove(profile.getId());
|
||||
assertFalse(profileDAO.exists(profile.getId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListProfiles() {
|
||||
int previous = profileDAO.list(Profile.class).size();
|
||||
Profile profile = createValidProfile();
|
||||
profileDAO.save(profile);
|
||||
assertEquals(previous + 1, profileDAO.list(Profile.class).size());
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue