ItEr41S15CUImportacionRecursosProductivosItEr40S20: Constraint added to verify criterion satisfactions are of a CriterionType compatible with the resource
-- Fernando Bellas Permuy Associate Professor (Titular) at University of A Coruña Department of Information and Communications Technologies Facultad de Informática - Campus de Elviña, S/N 15071 - A Coruña - Spain http://www.tic.udc.es/~fbellas - fbellas@udc.es Tel: +34 981 167 000 (ext: 1353) - Fax: +34 981 167 160 >From c9af4778e28e370fb2a8dc2c63a4d75e41a07d7f Mon Sep 17 00:00:00 2001 From: Fernando Bellas Permuy <fbellas@udc.es> Date: Thu, 31 Dec 2009 13:14:28 +0100 Subject: [PATCH 6/7] ItEr41S15CUImportacionRecursosProductivosItEr40S20: Constraint added to verify criterion satisfactions are of a CriterionType compatible with the resource. A test case has also been added.
This commit is contained in:
parent
0dad7ade89
commit
77a236a5e8
6 changed files with 99 additions and 2 deletions
|
|
@ -282,4 +282,9 @@ public class CriterionSatisfaction extends BaseEntity {
|
|||
Validate.isTrue(finishDate == null || startDate.equals(finishDate)
|
||||
|| startDate.before(finishDate));
|
||||
}
|
||||
|
||||
public ResourceEnum getResourceType() {
|
||||
return criterion.getType().getResource();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -132,4 +132,14 @@ public class Machine extends Resource {
|
|||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isCriterionSatisfactionOfCorrectType(
|
||||
CriterionSatisfaction c) {
|
||||
|
||||
return super.isCriterionSatisfactionOfCorrectType(c) ||
|
||||
c.getResourceType().equals(ResourceEnum.MACHINE);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ import java.util.Set;
|
|||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.hibernate.validator.AssertFalse;
|
||||
import org.hibernate.validator.AssertTrue;
|
||||
import org.hibernate.validator.InvalidValue;
|
||||
import org.hibernate.validator.Valid;
|
||||
import org.joda.time.Days;
|
||||
|
|
@ -823,4 +824,25 @@ public abstract class Resource extends BaseEntity{
|
|||
return false;
|
||||
}
|
||||
|
||||
@AssertTrue(message="There are criterion satisfactions referring to " +
|
||||
"criterion types not applicable to this resource")
|
||||
public boolean checkConstraintCriterionSatisfactionsWithCorrectType() {
|
||||
|
||||
for (CriterionSatisfaction c : getCriterionSatisfactions()) {
|
||||
if (!isCriterionSatisfactionOfCorrectType(c)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
protected boolean isCriterionSatisfactionOfCorrectType(
|
||||
CriterionSatisfaction c) {
|
||||
|
||||
return c.getResourceType().equals(ResourceEnum.RESOURCE);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -163,4 +163,13 @@ public class Worker extends Resource {
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isCriterionSatisfactionOfCorrectType(
|
||||
CriterionSatisfaction c) {
|
||||
|
||||
return super.isCriterionSatisfactionOfCorrectType(c) ||
|
||||
c.getResourceType().equals(ResourceEnum.WORKER);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ import org.navalplanner.business.resources.entities.CriterionSatisfaction;
|
|||
import org.navalplanner.business.resources.entities.CriterionType;
|
||||
import org.navalplanner.business.resources.entities.Machine;
|
||||
import org.navalplanner.business.resources.entities.Resource;
|
||||
import org.navalplanner.business.resources.entities.ResourceEnum;
|
||||
import org.navalplanner.business.resources.entities.Worker;
|
||||
import org.navalplanner.ws.common.api.InstanceConstraintViolationsDTO;
|
||||
import org.navalplanner.ws.common.api.InstanceConstraintViolationsListDTO;
|
||||
|
|
@ -135,7 +136,7 @@ public class ResourceServiceTest {
|
|||
CriterionType ct = createCriterionType();
|
||||
|
||||
/* Create a resource DTO. */
|
||||
MachineDTO machineDTO = new MachineDTO(ct.getName(), "name", "desc");
|
||||
MachineDTO machineDTO = new MachineDTO(getUniqueName(), "name", "desc");
|
||||
machineDTO.criterionSatisfactions.add(
|
||||
new CriterionSatisfactionDTO(
|
||||
' ' + ct.getName() + ' ', " c1 ", // Blank spaces intentionally
|
||||
|
|
@ -172,7 +173,7 @@ public class ResourceServiceTest {
|
|||
CriterionType ct = createCriterionType();
|
||||
|
||||
/* Create a machine DTO. */
|
||||
MachineDTO machineDTO = new MachineDTO(ct.getName(), "name", "desc");
|
||||
MachineDTO machineDTO = new MachineDTO(getUniqueName(), "name", "desc");
|
||||
machineDTO.criterionSatisfactions.add(
|
||||
new CriterionSatisfactionDTO(ct.getName() , "c1",
|
||||
null, Calendar.getInstance().getTime())); // Missing start date.
|
||||
|
|
@ -185,6 +186,36 @@ public class ResourceServiceTest {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
@NotTransactional
|
||||
public void testAddResourceWithCriterionSatisfactionsWithIncorrectType() {
|
||||
|
||||
/* Create two criterion types. */
|
||||
CriterionType machineCt = createCriterionType(ResourceEnum.MACHINE);
|
||||
CriterionType workerCt = createCriterionType(ResourceEnum.WORKER);
|
||||
|
||||
/* Create resource DTOs. */
|
||||
MachineDTO machineDTO = new MachineDTO(getUniqueName(), "name", "desc");
|
||||
machineDTO.criterionSatisfactions.add(
|
||||
new CriterionSatisfactionDTO(workerCt.getName() , "c1",
|
||||
Calendar.getInstance().getTime(), null)); // Incorrect type.
|
||||
WorkerDTO workerDTO = new WorkerDTO(getUniqueName(), "surname", "nif");
|
||||
workerDTO.criterionSatisfactions.add(
|
||||
new CriterionSatisfactionDTO(machineCt.getName() , "c1",
|
||||
Calendar.getInstance().getTime(), null)); // Incorrect type.
|
||||
|
||||
/* Test. */
|
||||
assertOneConstraintViolation(
|
||||
resourceService.addResources(createResourceListDTO(machineDTO)));
|
||||
assertFalse(machineDAO.existsMachineWithCodeInAnotherTransaction(
|
||||
machineDTO.code));
|
||||
assertOneConstraintViolation(
|
||||
resourceService.addResources(createResourceListDTO(workerDTO)));
|
||||
assertTrue(workerDAO.findByFirstNameSecondNameAndNifAnotherTransaction(
|
||||
workerDTO.firstName, workerDTO.surname, workerDTO.nif).size() == 0);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@NotTransactional
|
||||
public void testAddResourceWithCriterionSatisfactionsWithIncorrectNames() {
|
||||
|
|
@ -282,6 +313,10 @@ public class ResourceServiceTest {
|
|||
}
|
||||
|
||||
private CriterionType createCriterionType() {
|
||||
return createCriterionType(ResourceEnum.RESOURCE);
|
||||
}
|
||||
|
||||
private CriterionType createCriterionType(final ResourceEnum resourceType) {
|
||||
|
||||
IOnTransaction<CriterionType> createCriterionType =
|
||||
new IOnTransaction<CriterionType>() {
|
||||
|
|
@ -291,6 +326,7 @@ public class ResourceServiceTest {
|
|||
|
||||
CriterionType ct = CriterionType.create(getUniqueName(),
|
||||
"desc");
|
||||
ct.setResource(resourceType);
|
||||
Criterion c1 = Criterion.create("c1", ct);
|
||||
Criterion c2 = Criterion.create("c2", ct);
|
||||
ct.getCriterions().add(c1);
|
||||
|
|
|
|||
|
|
@ -3,12 +3,26 @@
|
|||
<resource-list xmlns="http://rest.ws.navalplanner.org">
|
||||
|
||||
<!-- *** Machines *** -->
|
||||
|
||||
<!-- OK -->
|
||||
<machine code=" m1 " name="m1-name" description="m1-desc"/>
|
||||
|
||||
<!-- Missing code and name (description is optional). -->
|
||||
<machine code="" description=""/>
|
||||
|
||||
<!-- Criterion satisfaction of incorrect type. -->
|
||||
<machine code="m2" name="m2-name" description="m2-desc">
|
||||
<criterion-satisfaction-list>
|
||||
<criterion-satisfaction
|
||||
criterion-type-name=" WORK_RELATIONSHIP "
|
||||
criterion-name=" hiredResourceWorkingRelationship "
|
||||
start-date="2009-01-01"
|
||||
finish-date=""/>
|
||||
</criterion-satisfaction-list>
|
||||
</machine>
|
||||
|
||||
<!-- *** Workers *** -->
|
||||
|
||||
<!-- OK -->
|
||||
<worker first-name="w1-firstName" surname="w1-surname" nif=" w1-nif ">
|
||||
<criterion-satisfaction-list>
|
||||
|
|
@ -24,6 +38,7 @@
|
|||
finish-date="2009-12-25"/>
|
||||
</criterion-satisfaction-list>
|
||||
</worker>
|
||||
|
||||
<!-- Missing first name, surname, and nif. -->
|
||||
<worker first-name="" nif=""/>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue