From 22c788e7793f5ff870e46161c779b39e75da1159 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacobo=20Aragunde=20P=C3=A9rez?= Date: Wed, 30 Dec 2009 21:43:46 +0100 Subject: [PATCH] ItEr40S22CUAsignarUsuarioAProxectoTraballo: created the entity OrderAuthorization and its children. The relations with Order, User and Profile are not implemented yet. --- .../users/daos/IOrderAuthorizationDAO.java | 33 ++++++ .../users/daos/OrderAuthorizationDAO.java | 36 ++++++ .../users/entities/OrderAuthorization.java | 44 ++++++++ .../entities/OrderAuthorizationType.java | 44 ++++++++ .../entities/ProfileOrderAuthorization.java | 46 ++++++++ .../entities/UserOrderAuthorization.java | 46 ++++++++ .../business/users/entities/Users.hbm.xml | 28 +++++ .../users/daos/OrderAuthorizationDAOTest.java | 103 ++++++++++++++++++ 8 files changed, 380 insertions(+) create mode 100644 navalplanner-business/src/main/java/org/navalplanner/business/users/daos/IOrderAuthorizationDAO.java create mode 100644 navalplanner-business/src/main/java/org/navalplanner/business/users/daos/OrderAuthorizationDAO.java create mode 100644 navalplanner-business/src/main/java/org/navalplanner/business/users/entities/OrderAuthorization.java create mode 100644 navalplanner-business/src/main/java/org/navalplanner/business/users/entities/OrderAuthorizationType.java create mode 100644 navalplanner-business/src/main/java/org/navalplanner/business/users/entities/ProfileOrderAuthorization.java create mode 100644 navalplanner-business/src/main/java/org/navalplanner/business/users/entities/UserOrderAuthorization.java create mode 100644 navalplanner-business/src/test/java/org/navalplanner/business/test/users/daos/OrderAuthorizationDAOTest.java diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/users/daos/IOrderAuthorizationDAO.java b/navalplanner-business/src/main/java/org/navalplanner/business/users/daos/IOrderAuthorizationDAO.java new file mode 100644 index 000000000..cb1e655e3 --- /dev/null +++ b/navalplanner-business/src/main/java/org/navalplanner/business/users/daos/IOrderAuthorizationDAO.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.OrderAuthorization; + +/** + * DAO interface for the {@link OrderAuthorization} entity. + * + * @author Jacobo Aragunde Perez + */ +public interface IOrderAuthorizationDAO extends IGenericDAO { + +} diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/users/daos/OrderAuthorizationDAO.java b/navalplanner-business/src/main/java/org/navalplanner/business/users/daos/OrderAuthorizationDAO.java new file mode 100644 index 000000000..4d3ac20a8 --- /dev/null +++ b/navalplanner-business/src/main/java/org/navalplanner/business/users/daos/OrderAuthorizationDAO.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.OrderAuthorization; +import org.springframework.stereotype.Repository; + +/** + * Hibernate DAO for the {@link OrderAuthorization} entity. + * + * @author Jacobo Aragunde Perez + */ +@Repository +public class OrderAuthorizationDAO extends GenericDAOHibernate + implements IOrderAuthorizationDAO { + +} diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/users/entities/OrderAuthorization.java b/navalplanner-business/src/main/java/org/navalplanner/business/users/entities/OrderAuthorization.java new file mode 100644 index 000000000..d1f51163d --- /dev/null +++ b/navalplanner-business/src/main/java/org/navalplanner/business/users/entities/OrderAuthorization.java @@ -0,0 +1,44 @@ +/* + * 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 org.hibernate.validator.NotNull; +import org.navalplanner.business.common.BaseEntity; + +/** + * Base entity for modeling a order authorization. + * + * @author Jacobo Aragunde Perez + */ +public abstract class OrderAuthorization extends BaseEntity { + + private OrderAuthorizationType authorizationType; + + public void setAuthorizationType(OrderAuthorizationType authorizationType) { + this.authorizationType = authorizationType; + } + + @NotNull(message="an authorization type must be set") + public OrderAuthorizationType getAuthorizationType() { + return authorizationType; + } + +} diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/users/entities/OrderAuthorizationType.java b/navalplanner-business/src/main/java/org/navalplanner/business/users/entities/OrderAuthorizationType.java new file mode 100644 index 000000000..f9a7a103f --- /dev/null +++ b/navalplanner-business/src/main/java/org/navalplanner/business/users/entities/OrderAuthorizationType.java @@ -0,0 +1,44 @@ +/* + * 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 static org.navalplanner.business.i18n.I18nHelper._; + +/** + * Available types of {@link OrderAuthorization}. + * + * @author Jacobo Aragunde Perez + */ +public enum OrderAuthorizationType { + + READ_AUTHORIZATION(_("Read authorization")), + WRITE_AUTHORIZATION(_("Write authorization")); + + private final String displayName; + + private OrderAuthorizationType(String displayName) { + this.displayName = displayName; + } + + public String getDisplayName() { + return displayName; + } +} diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/users/entities/ProfileOrderAuthorization.java b/navalplanner-business/src/main/java/org/navalplanner/business/users/entities/ProfileOrderAuthorization.java new file mode 100644 index 000000000..1b64bc8ee --- /dev/null +++ b/navalplanner-business/src/main/java/org/navalplanner/business/users/entities/ProfileOrderAuthorization.java @@ -0,0 +1,46 @@ +/* + * 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; + +/** + * Entity for modeling a order authorization related with a {@link Profile}. + * + * @author Jacobo Aragunde Perez + */ +public class ProfileOrderAuthorization extends OrderAuthorization { + + /** + * Necessary for Hibernate. + */ + public ProfileOrderAuthorization() {} + + public ProfileOrderAuthorization(OrderAuthorizationType type) { + setAuthorizationType(type); + } + + public static ProfileOrderAuthorization create() { + return create(new ProfileOrderAuthorization()); + } + + public static ProfileOrderAuthorization create(OrderAuthorizationType type) { + return create(new ProfileOrderAuthorization(type)); + } +} diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/users/entities/UserOrderAuthorization.java b/navalplanner-business/src/main/java/org/navalplanner/business/users/entities/UserOrderAuthorization.java new file mode 100644 index 000000000..4e6ca7d52 --- /dev/null +++ b/navalplanner-business/src/main/java/org/navalplanner/business/users/entities/UserOrderAuthorization.java @@ -0,0 +1,46 @@ +/* + * 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; + +/** + * Entity for modeling a order authorization related with a {@link User}. + * + * @author Jacobo Aragunde Perez + */ +public class UserOrderAuthorization extends OrderAuthorization { + + /** + * Necessary for Hibernate. + */ + public UserOrderAuthorization() {} + + public UserOrderAuthorization(OrderAuthorizationType type) { + setAuthorizationType(type); + } + + public static UserOrderAuthorization create() { + return create(new UserOrderAuthorization()); + } + + public static UserOrderAuthorization create(OrderAuthorizationType type) { + return create(new UserOrderAuthorization(type)); + } +} 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 b1781da69..6ff6a17fe 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 @@ -61,4 +61,32 @@ + + + + + 100 + + + + + + + + + + org.navalplanner.business.users.entities.OrderAuthorizationType + + 12 + + + + + + + + + + + diff --git a/navalplanner-business/src/test/java/org/navalplanner/business/test/users/daos/OrderAuthorizationDAOTest.java b/navalplanner-business/src/test/java/org/navalplanner/business/test/users/daos/OrderAuthorizationDAOTest.java new file mode 100644 index 000000000..8a70ef32d --- /dev/null +++ b/navalplanner-business/src/test/java/org/navalplanner/business/test/users/daos/OrderAuthorizationDAOTest.java @@ -0,0 +1,103 @@ +/* + * 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 org.junit.Test; +import org.junit.runner.RunWith; +import org.navalplanner.business.common.exceptions.InstanceNotFoundException; +import org.navalplanner.business.users.daos.IOrderAuthorizationDAO; +import org.navalplanner.business.users.entities.OrderAuthorization; +import org.navalplanner.business.users.entities.OrderAuthorizationType; +import org.navalplanner.business.users.entities.ProfileOrderAuthorization; +import org.navalplanner.business.users.entities.UserOrderAuthorization; +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 {@link OrderAuthorizationDAO} + * + * @author Jacobo Aragunde Perez + * + */ +@Transactional +public class OrderAuthorizationDAOTest { + + @Autowired + IOrderAuthorizationDAO orderAuthorizationDAO; + + private UserOrderAuthorization createValidUserOrderAuthorization() { + return UserOrderAuthorization.create(OrderAuthorizationType.READ_AUTHORIZATION); + } + + private ProfileOrderAuthorization createValidProfileOrderAuthorization() { + return ProfileOrderAuthorization.create(OrderAuthorizationType.READ_AUTHORIZATION); + } + + @Test + public void testInSpringContainer() { + assertNotNull(orderAuthorizationDAO); + } + + @Test + public void testSaveOrderAuthorization() { + UserOrderAuthorization userOrderAuthorization = createValidUserOrderAuthorization(); + orderAuthorizationDAO.save(userOrderAuthorization); + assertNotNull(userOrderAuthorization.getId()); + + ProfileOrderAuthorization profileOrderAuthorization = createValidProfileOrderAuthorization(); + orderAuthorizationDAO.save(profileOrderAuthorization); + assertNotNull(profileOrderAuthorization.getId()); + } + + @Test + public void testRemoveOrderAuthorization() throws InstanceNotFoundException { + UserOrderAuthorization userOrderAuthorization = createValidUserOrderAuthorization(); + orderAuthorizationDAO.save(userOrderAuthorization); + orderAuthorizationDAO.remove(userOrderAuthorization.getId()); + assertFalse(orderAuthorizationDAO.exists(userOrderAuthorization.getId())); + + ProfileOrderAuthorization profileOrderAuthorization = createValidProfileOrderAuthorization(); + orderAuthorizationDAO.save(profileOrderAuthorization); + orderAuthorizationDAO.remove(profileOrderAuthorization.getId()); + assertFalse(orderAuthorizationDAO.exists(profileOrderAuthorization.getId())); + } + + @Test + public void testListOrderAuthorizations() { + int previous = orderAuthorizationDAO.list(OrderAuthorization.class).size(); + UserOrderAuthorization userOrderAuthorization = createValidUserOrderAuthorization(); + orderAuthorizationDAO.save(userOrderAuthorization); + ProfileOrderAuthorization profileOrderAuthorization = createValidProfileOrderAuthorization(); + orderAuthorizationDAO.save(profileOrderAuthorization); + assertEquals(previous + 2, orderAuthorizationDAO.list(OrderAuthorization.class).size()); + } +}