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() {}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
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 {
|
||||
|
||||
for (Criterion c : criterions) {
|
||||
if (c.getName().trim().equalsIgnoreCase(criterionName)) {
|
||||
if (c.getName().equalsIgnoreCase(criterionName)) {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import static org.navalplanner.web.I18nHelper._;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.navalplanner.business.common.StringUtils;
|
||||
import org.navalplanner.business.common.exceptions.CreateUnvalidatedException;
|
||||
import org.navalplanner.business.resources.entities.CriterionSatisfaction;
|
||||
import org.navalplanner.business.resources.entities.Machine;
|
||||
|
|
@ -68,14 +69,16 @@ public class ResourceConverter {
|
|||
|
||||
private final static Machine createResourceWithBasicData(
|
||||
MachineDTO machineDTO) {
|
||||
return Machine.createUnvalidated(machineDTO.code,machineDTO.name,
|
||||
machineDTO.description);
|
||||
return Machine.createUnvalidated(StringUtils.trim(machineDTO.code),
|
||||
StringUtils.trim(machineDTO.name),
|
||||
StringUtils.trim(machineDTO.description));
|
||||
}
|
||||
|
||||
private final static Worker createResourceWithBasicData(
|
||||
WorkerDTO workerDTO) {
|
||||
return Worker.createUnvalidated(workerDTO.firstName, workerDTO.surname,
|
||||
workerDTO.nif);
|
||||
return Worker.createUnvalidated(StringUtils.trim(workerDTO.firstName),
|
||||
StringUtils.trim(workerDTO.surname),
|
||||
StringUtils.trim(workerDTO.nif));
|
||||
}
|
||||
|
||||
private static void addCriterionSatisfactions(Resource resource,
|
||||
|
|
@ -99,8 +102,8 @@ public class ResourceConverter {
|
|||
throws CreateUnvalidatedException {
|
||||
|
||||
return CriterionSatisfaction.createUnvalidated(
|
||||
criterionSatisfactionDTO.criterionTypeName,
|
||||
criterionSatisfactionDTO.criterionName,
|
||||
StringUtils.trim(criterionSatisfactionDTO.criterionTypeName),
|
||||
StringUtils.trim(criterionSatisfactionDTO.criterionName),
|
||||
resource,
|
||||
DateConverter.toDate(criterionSatisfactionDTO.startDate),
|
||||
DateConverter.toDate(criterionSatisfactionDTO.finishDate));
|
||||
|
|
|
|||
|
|
@ -87,12 +87,16 @@ public class ResourceServiceTest {
|
|||
public void testAddResourcesWithBasicContraintViolations()
|
||||
throws InstanceNotFoundException {
|
||||
|
||||
String m1Code = getUniqueName();
|
||||
String m1Code = ' ' + getUniqueName() + ' '; // Blank spaces
|
||||
// intentionally
|
||||
// added (OK).
|
||||
MachineDTO m1 = new MachineDTO(m1Code, "name", "desc");
|
||||
MachineDTO m2 = new MachineDTO("", null, ""); // Missing code and name
|
||||
// (description is
|
||||
// optional).
|
||||
String w1Nif = getUniqueName();
|
||||
String w1Nif = ' ' + getUniqueName() + ' '; // Blank spaces
|
||||
// intentionally
|
||||
// added (OK).
|
||||
WorkerDTO w1 = new WorkerDTO("w1-first-name", "w1-surname", w1Nif);
|
||||
WorkerDTO w2 = new WorkerDTO("", null, ""); // Missing first name,
|
||||
// surname, and nif.
|
||||
|
|
@ -112,8 +116,8 @@ public class ResourceServiceTest {
|
|||
constraintViolations.size() == 2); // m2 constraint violations.
|
||||
assertTrue(instanceConstraintViolationsList.get(1).
|
||||
constraintViolations.size() == 3); // w2 constraint violations.
|
||||
assertTrue(machineDAO.findByNameOrCode(m1Code).size() == 1);
|
||||
workerDAO.findUniqueByNif(w1Nif);
|
||||
assertTrue(machineDAO.findByNameOrCode(m1Code.trim()).size() == 1);
|
||||
workerDAO.findUniqueByNif(w1Nif.trim());
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -128,7 +132,9 @@ public class ResourceServiceTest {
|
|||
/* Create a resource DTO. */
|
||||
MachineDTO machineDTO = new MachineDTO(ct.getName(), "name", "desc");
|
||||
machineDTO.criterionSatisfactions.add(
|
||||
new CriterionSatisfactionDTO(ct.getName(), "c1",
|
||||
new CriterionSatisfactionDTO(
|
||||
' ' + ct.getName() + ' ', " c1 ", // Blank spaces intentionally
|
||||
// added (OK).
|
||||
Calendar.getInstance().getTime(), null));
|
||||
machineDTO.criterionSatisfactions.add(
|
||||
new CriterionSatisfactionDTO(ct.getName(), "c2",
|
||||
|
|
|
|||
|
|
@ -4,17 +4,17 @@
|
|||
|
||||
<!-- *** Machines *** -->
|
||||
<!-- 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). -->
|
||||
<machine code="" description=""/>
|
||||
|
||||
<!-- *** Workers *** -->
|
||||
<!-- 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
|
||||
criterion-type-name="WORK_RELATIONSHIP"
|
||||
criterion-name="hiredResourceWorkingRelationship"
|
||||
criterion-type-name=" WORK_RELATIONSHIP "
|
||||
criterion-name=" hiredResourceWorkingRelationship "
|
||||
start-date="2009-01-01"
|
||||
finish-date=""/>
|
||||
<criterion-satisfaction
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue