diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/users/daos/IProfileDAO.java b/navalplanner-business/src/main/java/org/navalplanner/business/users/daos/IProfileDAO.java new file mode 100644 index 000000000..4be55d130 --- /dev/null +++ b/navalplanner-business/src/main/java/org/navalplanner/business/users/daos/IProfileDAO.java @@ -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 . + */ + +package org.navalplanner.business.users.daos; + +import org.navalplanner.business.common.daos.IGenericDAO; +import org.navalplanner.business.users.entities.Profile; + +/** + * DAO interface for the Profile entity. + * + * @author Jacobo Aragunde Perez + */ +public interface IProfileDAO extends IGenericDAO{ + +} diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/users/daos/ProfileDAO.java b/navalplanner-business/src/main/java/org/navalplanner/business/users/daos/ProfileDAO.java new file mode 100644 index 000000000..c295029f6 --- /dev/null +++ b/navalplanner-business/src/main/java/org/navalplanner/business/users/daos/ProfileDAO.java @@ -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 . + */ + +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 Profile entity. + * + * @author Jacobo Aragunde Perez + */ +@Repository +public class ProfileDAO extends GenericDAOHibernate implements + IProfileDAO { + +} diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/users/entities/Profile.java b/navalplanner-business/src/main/java/org/navalplanner/business/users/entities/Profile.java new file mode 100644 index 000000000..0ca042e22 --- /dev/null +++ b/navalplanner-business/src/main/java/org/navalplanner/business/users/entities/Profile.java @@ -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 . + */ + +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 + */ +public class Profile extends BaseEntity { + + @NotEmpty(message="profile name not specified") + private String profileName; + + private Set roles = new HashSet(); + + /** + * Necessary for Hibernate. + */ + public Profile() {} + + private Profile(String profileName, Set roles) { + this.profileName = profileName; + this.setRoles(roles); + } + + public static Profile create(String loginName, Set roles) { + return create(new Profile(loginName, roles)); + } + + public void setProfileName(String profileName) { + this.profileName = profileName; + } + + public String getProfileName() { + return profileName; + } + + public void setRoles(Set roles) { + this.roles = roles; + } + + public Set getRoles() { + return roles; + } + + public void addRole(UserRole role) { + roles.add(role); + } + + public void removeRole(UserRole role) { + roles.remove(role); + } +} diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/users/entities/User.java b/navalplanner-business/src/main/java/org/navalplanner/business/users/entities/User.java index 77f99ecc4..97d6783e5 100644 --- a/navalplanner-business/src/main/java/org/navalplanner/business/users/entities/User.java +++ b/navalplanner-business/src/main/java/org/navalplanner/business/users/entities/User.java @@ -46,6 +46,8 @@ public class User extends BaseEntity { @NotEmpty(message="user roles not specified") private Set roles = new HashSet(); + 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() { diff --git a/navalplanner-business/src/main/resources/org/navalplanner/business/users/entities/Users.hbm.xml b/navalplanner-business/src/main/resources/org/navalplanner/business/users/entities/Users.hbm.xml index 2129d2fb4..17d80e00b 100644 --- a/navalplanner-business/src/main/resources/org/navalplanner/business/users/entities/Users.hbm.xml +++ b/navalplanner-business/src/main/resources/org/navalplanner/business/users/entities/Users.hbm.xml @@ -21,6 +21,7 @@ + @@ -33,4 +34,25 @@ + + + + 100 + + + + + + + + + + + org.navalplanner.business.users.entities.UserRole + + 12 + + + + diff --git a/navalplanner-business/src/test/java/org/navalplanner/business/test/users/daos/ProfileDAOTest.java b/navalplanner-business/src/test/java/org/navalplanner/business/test/users/daos/ProfileDAOTest.java new file mode 100644 index 000000000..0f96bd121 --- /dev/null +++ b/navalplanner-business/src/test/java/org/navalplanner/business/test/users/daos/ProfileDAOTest.java @@ -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 . + */ + +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 + * + */ +@Transactional +public class ProfileDAOTest { + + @Autowired + IProfileDAO profileDAO; + + @Test + public void testInSpringContainer() { + assertNotNull(profileDAO); + } + + private Profile createValidProfile() { + Set roles = new HashSet(); + 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()); + } + +}