diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/costcategories/entities/CostCategory.java b/navalplanner-business/src/main/java/org/navalplanner/business/costcategories/entities/CostCategory.java index 8f18bab12..f7ed34315 100644 --- a/navalplanner-business/src/main/java/org/navalplanner/business/costcategories/entities/CostCategory.java +++ b/navalplanner-business/src/main/java/org/navalplanner/business/costcategories/entities/CostCategory.java @@ -31,7 +31,6 @@ import java.util.Set; import org.apache.commons.lang.StringUtils; import org.hibernate.validator.AssertFalse; import org.hibernate.validator.AssertTrue; -import org.hibernate.validator.InvalidValue; import org.hibernate.validator.NotEmpty; import org.hibernate.validator.NotNull; import org.hibernate.validator.Valid; @@ -144,6 +143,47 @@ public class CostCategory extends IntegrationEntity { } } + public static void checkOverlapping( + List costCategoryAssignments) { + + for (int i = 0; i < costCategoryAssignments.size(); i++) { + LocalDate initDate = costCategoryAssignments.get(i).getInitDate(); + LocalDate endDate = costCategoryAssignments.get(i).getEndDate(); + for (int j = i + 1; j < costCategoryAssignments.size(); j++) { + ResourcesCostCategoryAssignment costCategory = costCategoryAssignments + .get(j); + if (endDate == null && costCategory.getEndDate() == null) { + throw ValidationException.invalidValue(_("Some cost category assignments overlap in time"), costCategory); + } else if ((endDate == null && costCategory.getEndDate() + .compareTo(initDate) >= 0) + || (costCategory.getEndDate() == null && costCategory + .getInitDate().compareTo(endDate) <= 0)) { + throw ValidationException.invalidValue(_("Some cost category assignments overlap in time"), costCategory); + } else if ((endDate != null && costCategory.getEndDate() != null) + && ((costCategory.getEndDate().compareTo(initDate) >= 0 && // (1) + // listElement.getEndDate() + // inside + // [initDate, + // endDate] + costCategory.getEndDate().compareTo(endDate) <= 0) + || (costCategory.getInitDate().compareTo( + initDate) >= 0 && // (2) + // listElement.getInitDate() + // inside [initDate, + // endDate] + costCategory.getInitDate().compareTo(endDate) <= 0) || (costCategory + .getInitDate().compareTo(initDate) <= 0 && // (3) + // [listElement.getInitDate(), + // listElement.getEndDate()] + costCategory.getEndDate().compareTo(endDate) >= 0))) { // contains + // [initDate, + // endDate] + throw ValidationException.invalidValue(_("Some cost category assignments overlap in time"), costCategory); + } + } + } + } + protected CostCategory(String name) { this.name = name; } @@ -271,49 +311,4 @@ public class CostCategory extends IntegrationEntity { return lastHourCostSequenceCode; } - public static void checkOverlapping( - List costCategoryAssignments) { - - for (int i = 0; i < costCategoryAssignments.size(); i++) { - LocalDate initDate = costCategoryAssignments.get(i).getInitDate(); - LocalDate endDate = costCategoryAssignments.get(i).getEndDate(); - for (int j = i + 1; j < costCategoryAssignments.size(); j++) { - ResourcesCostCategoryAssignment costCategory = costCategoryAssignments - .get(j); - if (endDate == null && costCategory.getEndDate() == null) { - throw new ValidationException(invalidValue(_("Some cost category assignments overlap in time"), costCategory)); - } else if ((endDate == null && costCategory.getEndDate() - .compareTo(initDate) >= 0) - || (costCategory.getEndDate() == null && costCategory - .getInitDate().compareTo(endDate) <= 0)) { - throw new ValidationException(invalidValue(_("Some cost category assignments overlap in time"), costCategory)); - } else if ((endDate != null && costCategory.getEndDate() != null) - && ((costCategory.getEndDate().compareTo(initDate) >= 0 && // (1) - // listElement.getEndDate() - // inside - // [initDate, - // endDate] - costCategory.getEndDate().compareTo(endDate) <= 0) - || (costCategory.getInitDate().compareTo( - initDate) >= 0 && // (2) - // listElement.getInitDate() - // inside [initDate, - // endDate] - costCategory.getInitDate().compareTo(endDate) <= 0) || (costCategory - .getInitDate().compareTo(initDate) <= 0 && // (3) - // [listElement.getInitDate(), - // listElement.getEndDate()] - costCategory.getEndDate().compareTo(endDate) >= 0))) { // contains - // [initDate, - // endDate] - throw new ValidationException(invalidValue(_("Some cost category assignments overlap in time"), costCategory)); - } - } - } - } - - private static InvalidValue invalidValue(String message, ResourcesCostCategoryAssignment each) { - return new InvalidValue(message, null, "", each, null); - } - } \ No newline at end of file