ItEr41S15CUImportacionRecursosProductivosItEr40S20: String fields when importing resources are trimmed.
String fields when importing resources are trimmed.
This commit is contained in:
parent
ec0da2601e
commit
746ce17bf1
5 changed files with 35 additions and 17 deletions
|
|
@ -30,10 +30,19 @@ public class StringUtils {
|
||||||
private StringUtils() {}
|
private StringUtils() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a String is null or "" after being trimmed.
|
* Checks if a string is <code>null</code> or empty ("" after being
|
||||||
|
* trimmed).
|
||||||
*/
|
*/
|
||||||
public static boolean isEmpty(String s) {
|
public static boolean isEmpty(String s) {
|
||||||
return s == null ? true : s.trim().equals("");
|
return s == null ? true : s.trim().equals("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trims a string if is not <code>null</code>; otherwise, it returns
|
||||||
|
* <code>null</code>.
|
||||||
|
*/
|
||||||
|
public static String trim(String s) {
|
||||||
|
return s == null ? null : s.trim();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -288,7 +288,7 @@ public class CriterionType extends BaseEntity implements
|
||||||
throws InstanceNotFoundException {
|
throws InstanceNotFoundException {
|
||||||
|
|
||||||
for (Criterion c : criterions) {
|
for (Criterion c : criterions) {
|
||||||
if (c.getName().trim().equalsIgnoreCase(criterionName)) {
|
if (c.getName().equalsIgnoreCase(criterionName)) {
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ import static org.navalplanner.web.I18nHelper._;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.navalplanner.business.common.StringUtils;
|
||||||
import org.navalplanner.business.common.exceptions.CreateUnvalidatedException;
|
import org.navalplanner.business.common.exceptions.CreateUnvalidatedException;
|
||||||
import org.navalplanner.business.resources.entities.CriterionSatisfaction;
|
import org.navalplanner.business.resources.entities.CriterionSatisfaction;
|
||||||
import org.navalplanner.business.resources.entities.Machine;
|
import org.navalplanner.business.resources.entities.Machine;
|
||||||
|
|
@ -68,14 +69,16 @@ public class ResourceConverter {
|
||||||
|
|
||||||
private final static Machine createResourceWithBasicData(
|
private final static Machine createResourceWithBasicData(
|
||||||
MachineDTO machineDTO) {
|
MachineDTO machineDTO) {
|
||||||
return Machine.createUnvalidated(machineDTO.code,machineDTO.name,
|
return Machine.createUnvalidated(StringUtils.trim(machineDTO.code),
|
||||||
machineDTO.description);
|
StringUtils.trim(machineDTO.name),
|
||||||
|
StringUtils.trim(machineDTO.description));
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static Worker createResourceWithBasicData(
|
private final static Worker createResourceWithBasicData(
|
||||||
WorkerDTO workerDTO) {
|
WorkerDTO workerDTO) {
|
||||||
return Worker.createUnvalidated(workerDTO.firstName, workerDTO.surname,
|
return Worker.createUnvalidated(StringUtils.trim(workerDTO.firstName),
|
||||||
workerDTO.nif);
|
StringUtils.trim(workerDTO.surname),
|
||||||
|
StringUtils.trim(workerDTO.nif));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addCriterionSatisfactions(Resource resource,
|
private static void addCriterionSatisfactions(Resource resource,
|
||||||
|
|
@ -99,8 +102,8 @@ public class ResourceConverter {
|
||||||
throws CreateUnvalidatedException {
|
throws CreateUnvalidatedException {
|
||||||
|
|
||||||
return CriterionSatisfaction.createUnvalidated(
|
return CriterionSatisfaction.createUnvalidated(
|
||||||
criterionSatisfactionDTO.criterionTypeName,
|
StringUtils.trim(criterionSatisfactionDTO.criterionTypeName),
|
||||||
criterionSatisfactionDTO.criterionName,
|
StringUtils.trim(criterionSatisfactionDTO.criterionName),
|
||||||
resource,
|
resource,
|
||||||
DateConverter.toDate(criterionSatisfactionDTO.startDate),
|
DateConverter.toDate(criterionSatisfactionDTO.startDate),
|
||||||
DateConverter.toDate(criterionSatisfactionDTO.finishDate));
|
DateConverter.toDate(criterionSatisfactionDTO.finishDate));
|
||||||
|
|
|
||||||
|
|
@ -87,12 +87,16 @@ public class ResourceServiceTest {
|
||||||
public void testAddResourcesWithBasicContraintViolations()
|
public void testAddResourcesWithBasicContraintViolations()
|
||||||
throws InstanceNotFoundException {
|
throws InstanceNotFoundException {
|
||||||
|
|
||||||
String m1Code = getUniqueName();
|
String m1Code = ' ' + getUniqueName() + ' '; // Blank spaces
|
||||||
|
// intentionally
|
||||||
|
// added (OK).
|
||||||
MachineDTO m1 = new MachineDTO(m1Code, "name", "desc");
|
MachineDTO m1 = new MachineDTO(m1Code, "name", "desc");
|
||||||
MachineDTO m2 = new MachineDTO("", null, ""); // Missing code and name
|
MachineDTO m2 = new MachineDTO("", null, ""); // Missing code and name
|
||||||
// (description is
|
// (description is
|
||||||
// optional).
|
// optional).
|
||||||
String w1Nif = getUniqueName();
|
String w1Nif = ' ' + getUniqueName() + ' '; // Blank spaces
|
||||||
|
// intentionally
|
||||||
|
// added (OK).
|
||||||
WorkerDTO w1 = new WorkerDTO("w1-first-name", "w1-surname", w1Nif);
|
WorkerDTO w1 = new WorkerDTO("w1-first-name", "w1-surname", w1Nif);
|
||||||
WorkerDTO w2 = new WorkerDTO("", null, ""); // Missing first name,
|
WorkerDTO w2 = new WorkerDTO("", null, ""); // Missing first name,
|
||||||
// surname, and nif.
|
// surname, and nif.
|
||||||
|
|
@ -112,8 +116,8 @@ public class ResourceServiceTest {
|
||||||
constraintViolations.size() == 2); // m2 constraint violations.
|
constraintViolations.size() == 2); // m2 constraint violations.
|
||||||
assertTrue(instanceConstraintViolationsList.get(1).
|
assertTrue(instanceConstraintViolationsList.get(1).
|
||||||
constraintViolations.size() == 3); // w2 constraint violations.
|
constraintViolations.size() == 3); // w2 constraint violations.
|
||||||
assertTrue(machineDAO.findByNameOrCode(m1Code).size() == 1);
|
assertTrue(machineDAO.findByNameOrCode(m1Code.trim()).size() == 1);
|
||||||
workerDAO.findUniqueByNif(w1Nif);
|
workerDAO.findUniqueByNif(w1Nif.trim());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -128,7 +132,9 @@ public class ResourceServiceTest {
|
||||||
/* Create a resource DTO. */
|
/* Create a resource DTO. */
|
||||||
MachineDTO machineDTO = new MachineDTO(ct.getName(), "name", "desc");
|
MachineDTO machineDTO = new MachineDTO(ct.getName(), "name", "desc");
|
||||||
machineDTO.criterionSatisfactions.add(
|
machineDTO.criterionSatisfactions.add(
|
||||||
new CriterionSatisfactionDTO(ct.getName(), "c1",
|
new CriterionSatisfactionDTO(
|
||||||
|
' ' + ct.getName() + ' ', " c1 ", // Blank spaces intentionally
|
||||||
|
// added (OK).
|
||||||
Calendar.getInstance().getTime(), null));
|
Calendar.getInstance().getTime(), null));
|
||||||
machineDTO.criterionSatisfactions.add(
|
machineDTO.criterionSatisfactions.add(
|
||||||
new CriterionSatisfactionDTO(ct.getName(), "c2",
|
new CriterionSatisfactionDTO(ct.getName(), "c2",
|
||||||
|
|
|
||||||
|
|
@ -4,17 +4,17 @@
|
||||||
|
|
||||||
<!-- *** Machines *** -->
|
<!-- *** Machines *** -->
|
||||||
<!-- OK -->
|
<!-- OK -->
|
||||||
<machine code="m1" name="m1-name" description="m1-desc"/>
|
<machine code=" m1 " name="m1-name" description="m1-desc"/>
|
||||||
<!-- Missing code and name (description is optional). -->
|
<!-- Missing code and name (description is optional). -->
|
||||||
<machine code="" description=""/>
|
<machine code="" description=""/>
|
||||||
|
|
||||||
<!-- *** Workers *** -->
|
<!-- *** Workers *** -->
|
||||||
<!-- OK -->
|
<!-- OK -->
|
||||||
<worker first-name="w1-firstName" surname="w1-surname" nif="w1-nif">
|
<worker first-name="w1-firstName" surname="w1-surname" nif=" w1-nif ">
|
||||||
<criterion-satisfaction-list>
|
<criterion-satisfaction-list>
|
||||||
<criterion-satisfaction
|
<criterion-satisfaction
|
||||||
criterion-type-name="WORK_RELATIONSHIP"
|
criterion-type-name=" WORK_RELATIONSHIP "
|
||||||
criterion-name="hiredResourceWorkingRelationship"
|
criterion-name=" hiredResourceWorkingRelationship "
|
||||||
start-date="2009-01-01"
|
start-date="2009-01-01"
|
||||||
finish-date=""/>
|
finish-date=""/>
|
||||||
<criterion-satisfaction
|
<criterion-satisfaction
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue