ItEr40S22CUAsignarUsuarioAProxectoTraballo: created the entity OrderAuthorization and its children.
The relations with Order, User and Profile are not implemented yet.
This commit is contained in:
parent
795dd8d184
commit
22c788e779
8 changed files with 380 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.OrderAuthorization;
|
||||
|
||||
/**
|
||||
* DAO interface for the {@link OrderAuthorization} entity.
|
||||
*
|
||||
* @author Jacobo Aragunde Perez <jaragunde@igalia.com>
|
||||
*/
|
||||
public interface IOrderAuthorizationDAO extends IGenericDAO<OrderAuthorization, 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.OrderAuthorization;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* Hibernate DAO for the {@link OrderAuthorization} entity.
|
||||
*
|
||||
* @author Jacobo Aragunde Perez <jaragunde@igalia.com>
|
||||
*/
|
||||
@Repository
|
||||
public class OrderAuthorizationDAO extends GenericDAOHibernate<OrderAuthorization, Long>
|
||||
implements IOrderAuthorizationDAO {
|
||||
|
||||
}
|
||||
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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 <jaragunde@igalia.com>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.navalplanner.business.users.entities;
|
||||
|
||||
import static org.navalplanner.business.i18n.I18nHelper._;
|
||||
|
||||
/**
|
||||
* Available types of {@link OrderAuthorization}.
|
||||
*
|
||||
* @author Jacobo Aragunde Perez <jaragunde@igalia.com>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.navalplanner.business.users.entities;
|
||||
|
||||
/**
|
||||
* Entity for modeling a order authorization related with a {@link Profile}.
|
||||
*
|
||||
* @author Jacobo Aragunde Perez <jaragunde@igalia.com>
|
||||
*/
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.navalplanner.business.users.entities;
|
||||
|
||||
/**
|
||||
* Entity for modeling a order authorization related with a {@link User}.
|
||||
*
|
||||
* @author Jacobo Aragunde Perez <jaragunde@igalia.com>
|
||||
*/
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
|
@ -61,4 +61,32 @@
|
|||
</element>
|
||||
</set>
|
||||
</class>
|
||||
|
||||
<class name="OrderAuthorization" table="ORDER_AUTHORIZATION">
|
||||
<id name="id" access="property" type="long">
|
||||
<generator class="hilo">
|
||||
<param name="max_lo">100</param>
|
||||
</generator>
|
||||
</id>
|
||||
|
||||
<discriminator column="ORDER_AUTHORIZATION_SUBCLASS" type="string"/>
|
||||
|
||||
<version name="version" access="property" type="long" />
|
||||
|
||||
<property name="authorizationType" not-null="true">
|
||||
<type name="org.hibernate.type.EnumType">
|
||||
<param name="enumClass">org.navalplanner.business.users.entities.OrderAuthorizationType</param>
|
||||
<!-- 12 is java.sql.Types.VARCHAR -->
|
||||
<param name="type">12</param>
|
||||
</type>
|
||||
</property>
|
||||
|
||||
<subclass name="UserOrderAuthorization" discriminator-value="USER">
|
||||
</subclass>
|
||||
|
||||
<subclass name="ProfileOrderAuthorization" discriminator-value="PROFILE">
|
||||
</subclass>
|
||||
|
||||
</class>
|
||||
|
||||
</hibernate-mapping>
|
||||
|
|
|
|||
|
|
@ -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 <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 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 <jaragunde@igalia.com>
|
||||
*
|
||||
*/
|
||||
@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());
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue