[Bug #1137] Fix bug. Project name is now unique
FEA: ItEr75S04BugFixing
This commit is contained in:
parent
cb73c5f6ea
commit
2a226bf407
7 changed files with 191 additions and 4 deletions
|
|
@ -97,4 +97,6 @@ public interface IOrderDAO extends IIntegrationEntityDAO<Order> {
|
|||
|
||||
public List<Order> loadOrdersAvoidingProxyFor(
|
||||
List<OrderElement> orderElement);
|
||||
|
||||
boolean existsByNameAnotherTransaction(String name);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -401,4 +401,15 @@ public class OrderDAO extends IntegrationEntityDAO<Order> implements
|
|||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true, propagation = Propagation.REQUIRES_NEW)
|
||||
public boolean existsByNameAnotherTransaction(String name) {
|
||||
try {
|
||||
Order order = findByName(name);
|
||||
return order.getName().equals(name);
|
||||
} catch (InstanceNotFoundException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,8 +38,11 @@ import org.navalplanner.business.advance.bootstrap.PredefinedAdvancedTypes;
|
|||
import org.navalplanner.business.advance.entities.AdvanceType;
|
||||
import org.navalplanner.business.advance.entities.DirectAdvanceAssignment;
|
||||
import org.navalplanner.business.calendars.entities.BaseCalendar;
|
||||
import org.navalplanner.business.common.Registry;
|
||||
import org.navalplanner.business.common.entities.EntitySequence;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.externalcompanies.entities.ExternalCompany;
|
||||
import org.navalplanner.business.orders.daos.IOrderDAO;
|
||||
import org.navalplanner.business.planner.entities.DayAssignment;
|
||||
import org.navalplanner.business.planner.entities.Task;
|
||||
import org.navalplanner.business.planner.entities.TaskElement;
|
||||
|
|
@ -538,4 +541,23 @@ public class Order extends OrderLineGroup {
|
|||
return getAdvanceAssignmentByType(advanceType);
|
||||
}
|
||||
|
||||
@AssertTrue(message = "project name is already being used")
|
||||
public boolean checkConstraintProjectUniqueName() {
|
||||
|
||||
IOrderDAO orderDAO = Registry.getOrderDAO();
|
||||
|
||||
if (isNewObject()) {
|
||||
return !orderDAO.existsByNameAnotherTransaction(getName());
|
||||
} else {
|
||||
try {
|
||||
Order o = orderDAO.findByNameAnotherTransaction(getName());
|
||||
return o.getId().equals(getId());
|
||||
} catch (InstanceNotFoundException e) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ import static org.navalplanner.business.workingday.EffortDuration.zero;
|
|||
import static org.navalplanner.business.workingday.IntraDayDate.PartialDay.wholeDay;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
import org.junit.Test;
|
||||
|
|
@ -82,7 +83,7 @@ public class BaseCalendarTest {
|
|||
public static BaseCalendar createBasicCalendar() {
|
||||
BaseCalendar calendar = BaseCalendar.create();
|
||||
|
||||
calendar.setName("Test");
|
||||
calendar.setName("test-" + UUID.randomUUID());
|
||||
|
||||
Capacity eightHours = withNormalDuration(hours(8));
|
||||
calendar.setCapacityAt(Days.MONDAY, eightHours);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,151 @@
|
|||
/*
|
||||
* This file is part of NavalPlan
|
||||
*
|
||||
* Copyright (C) 2011 Igalia, S.L.
|
||||
*
|
||||
* 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.orders.daos;
|
||||
|
||||
import static junit.framework.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.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.navalplanner.business.calendars.daos.IBaseCalendarDAO;
|
||||
import org.navalplanner.business.calendars.entities.BaseCalendar;
|
||||
import org.navalplanner.business.common.IAdHocTransactionService;
|
||||
import org.navalplanner.business.common.IOnTransaction;
|
||||
import org.navalplanner.business.common.exceptions.ValidationException;
|
||||
import org.navalplanner.business.orders.daos.IOrderDAO;
|
||||
import org.navalplanner.business.orders.entities.Order;
|
||||
import org.navalplanner.business.scenarios.IScenarioManager;
|
||||
import org.navalplanner.business.scenarios.bootstrap.IScenariosBootstrap;
|
||||
import org.navalplanner.business.scenarios.entities.OrderVersion;
|
||||
import org.navalplanner.business.test.calendars.entities.BaseCalendarTest;
|
||||
import org.navalplanner.business.test.planner.daos.ResourceAllocationDAOTest;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Test for {@link IOrderDAO}
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <rego@igalia.com>
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { BUSINESS_SPRING_CONFIG_FILE,
|
||||
BUSINESS_SPRING_CONFIG_TEST_FILE })
|
||||
@Transactional
|
||||
public class OrderDAOTest {
|
||||
|
||||
@Before
|
||||
public void loadRequiredaData() {
|
||||
transactionService.runOnAnotherTransaction(new IOnTransaction<Void>() {
|
||||
@Override
|
||||
public Void execute() {
|
||||
scenariosBootstrap.loadRequiredData();
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private IOrderDAO orderDAO;
|
||||
|
||||
@Autowired
|
||||
private IBaseCalendarDAO calendarDAO;
|
||||
|
||||
@Autowired
|
||||
private IScenariosBootstrap scenariosBootstrap;
|
||||
|
||||
@Autowired
|
||||
private IScenarioManager scenarioManager;
|
||||
|
||||
@Autowired
|
||||
private IAdHocTransactionService transactionService;
|
||||
|
||||
@Test
|
||||
public void testInSpringContainer() {
|
||||
assertNotNull(orderDAO);
|
||||
}
|
||||
|
||||
private Order createValidOrder(String name) {
|
||||
Order order = Order.create();
|
||||
order.setName(name);
|
||||
order.setCode(UUID.randomUUID().toString());
|
||||
order.setInitDate(new Date());
|
||||
BaseCalendar basicCalendar = BaseCalendarTest.createBasicCalendar();
|
||||
calendarDAO.save(basicCalendar);
|
||||
order.setCalendar(basicCalendar);
|
||||
OrderVersion orderVersion = ResourceAllocationDAOTest
|
||||
.setupVersionUsing(scenarioManager, order);
|
||||
order.useSchedulingDataFor(orderVersion);
|
||||
return order;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveTwoOrdersWithDifferentNames() {
|
||||
transactionService.runOnAnotherTransaction(new IOnTransaction<Void>() {
|
||||
@Override
|
||||
public Void execute() {
|
||||
Order order = createValidOrder("test");
|
||||
orderDAO.save(order);
|
||||
orderDAO.flush();
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
transactionService.runOnAnotherTransaction(new IOnTransaction<Void>() {
|
||||
@Override
|
||||
public Void execute() {
|
||||
Order order = createValidOrder("test2");
|
||||
orderDAO.save(order);
|
||||
orderDAO.flush();
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = ValidationException.class)
|
||||
public void testSaveTwoOrdersWithSameNames() {
|
||||
transactionService.runOnAnotherTransaction(new IOnTransaction<Void>() {
|
||||
@Override
|
||||
public Void execute() {
|
||||
Order order = createValidOrder("test");
|
||||
orderDAO.save(order);
|
||||
orderDAO.flush();
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
transactionService.runOnAnotherTransaction(new IOnTransaction<Void>() {
|
||||
@Override
|
||||
public Void execute() {
|
||||
Order order = createValidOrder("test");
|
||||
orderDAO.save(order);
|
||||
orderDAO.flush();
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -172,7 +172,7 @@ public class TaskElementDAOTest {
|
|||
Order order = Order.create();
|
||||
OrderVersion orderVersion = ResourceAllocationDAOTest
|
||||
.setupVersionUsing(scenarioManager, order);
|
||||
order.setName("bla");
|
||||
order.setName("bla-" + UUID.randomUUID());
|
||||
order.setInitDate(new Date());
|
||||
order.setCode("code-" + UUID.randomUUID());
|
||||
order.useSchedulingDataFor(orderVersion);
|
||||
|
|
|
|||
|
|
@ -37,9 +37,9 @@ import java.util.Date;
|
|||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
|
|
@ -282,7 +282,7 @@ public class ReportAdvancesServiceTest {
|
|||
private Order givenValidOrderAlreadyStored() {
|
||||
Order order = Order.create();
|
||||
order.setCode(UUID.randomUUID().toString());
|
||||
order.setName("Order name");
|
||||
order.setName("Order name " + UUID.randomUUID());
|
||||
order.setInitDate(new Date());
|
||||
order.setCalendar(configurationDAO.getConfiguration()
|
||||
.getDefaultCalendar());
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue