Upgrade Spring to 3.2.8 and Hibernate to 4.2.8
Now Libreplan can be run on Java8. This implied some changes: * Latest versions of hibernate use the Bean Validation API. This implied renaming the imports and use ConstraintViolationException instead of InvalidValue. Besides some constraints had to be renamed, otherwise they wouldn't be recognized by Hibernate validation. In the new version of Hibernate validator @AssertTrue can only be applied to properties. So all methods it was applied to must follow the is.* format. Automatic execution of Bean Validation API is disabled, otherwise an infinite loop would happen. This is because there are some validation constraints that do launch queries to the database. This causes a flush of the objects in the session and automatic validation is called again. * A new library for persisting JodaTime is necessary since joda-time-hibernate is incompatible with hibernate 4. This library can automatically register its types for Date conversion so they're removed from configuration. * Now, in some places, an InvalidDataAccessApiUsageException is thrown instead of a DataIntegrityViolationException. This is because no constraint is violated, the API is being used incorrectly because a transient instance is being provided where a persisted one was expected. * In hibernate 4 listeners cannot be configured via properties. HibernateDatabaseModificationsListener registers itself in its @PostConstruct method. * ehcache classes used are now different.
This commit is contained in:
parent
b52ad5de23
commit
7b54a5063e
177 changed files with 1033 additions and 1680 deletions
|
|
@ -113,11 +113,11 @@
|
||||||
<groupId>commons-lang</groupId>
|
<groupId>commons-lang</groupId>
|
||||||
<artifactId>commons-lang</artifactId>
|
<artifactId>commons-lang</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- Commons collections -->
|
<dependency>
|
||||||
<dependency>
|
<groupId>commons-collections</groupId>
|
||||||
<groupId>commons-collections</groupId>
|
<artifactId>commons-collections</artifactId>
|
||||||
<artifactId>commons-collections</artifactId>
|
</dependency>
|
||||||
</dependency>
|
|
||||||
<!-- ZK -->
|
<!-- ZK -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.zkoss.zk</groupId>
|
<groupId>org.zkoss.zk</groupId>
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,12 @@
|
||||||
|
|
||||||
package org.zkoss.ganttz.timetracker.zoom;
|
package org.zkoss.ganttz.timetracker.zoom;
|
||||||
|
|
||||||
|
import static java.util.Arrays.asList;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -266,20 +269,15 @@ public abstract class TimeTrackerState {
|
||||||
|
|
||||||
protected abstract Period getMinimumPeriod();
|
protected abstract Period getMinimumPeriod();
|
||||||
|
|
||||||
private Interval calculateIntervalWithMinimum(Interval interval) {
|
private Interval ensureMinimumInterval(Interval interval) {
|
||||||
Period minimumPeriod = getMinimumPeriod();
|
LocalDate newEnd = interval.getStart().plus(
|
||||||
BaseSingleFieldPeriod intervalAsPeriod = minimumPeriod
|
getMinimumPeriod().toPeriod());
|
||||||
.asPeriod(interval);
|
return new Interval(interval.getStart(), Collections.max(asList(newEnd,
|
||||||
if (intervalAsPeriod.compareTo(minimumPeriod.toPeriod()) >= 0) {
|
interval.getFinish())));
|
||||||
return interval;
|
|
||||||
}
|
|
||||||
LocalDate newEnd = new LocalDate(interval.getStart())
|
|
||||||
.plus(minimumPeriod.toPeriod());
|
|
||||||
return new Interval(interval.getStart(), newEnd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Interval getRealIntervalFor(Interval testInterval) {
|
public Interval getRealIntervalFor(Interval testInterval) {
|
||||||
return calculateForAtLeastMinimum(calculateIntervalWithMinimum(testInterval));
|
return calculateForAtLeastMinimum(ensureMinimumInterval(testInterval));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Interval calculateForAtLeastMinimum(Interval atLeastMinimum) {
|
private Interval calculateForAtLeastMinimum(Interval atLeastMinimum) {
|
||||||
|
|
|
||||||
|
|
@ -30,24 +30,29 @@
|
||||||
<groupId>org.hibernate</groupId>
|
<groupId>org.hibernate</groupId>
|
||||||
<artifactId>hibernate-annotations</artifactId>
|
<artifactId>hibernate-annotations</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.hibernate</groupId>
|
||||||
|
<artifactId>hibernate-ehcache</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hibernate</groupId>
|
<groupId>org.hibernate</groupId>
|
||||||
<artifactId>hibernate-validator</artifactId>
|
<artifactId>hibernate-validator</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>joda-time</groupId>
|
<groupId>org.jadira.usertype</groupId>
|
||||||
<artifactId>joda-time-hibernate</artifactId>
|
<artifactId>usertype.core</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- JDBC driver -->
|
<!-- JDBC driver -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>${jdbcDriver.groupId}</groupId>
|
<groupId>${jdbcDriver.groupId}</groupId>
|
||||||
<artifactId>${jdbcDriver.artifactId}</artifactId>
|
<artifactId>${jdbcDriver.artifactId}</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.geronimo.specs</groupId>
|
<groupId>org.jboss.spec.javax.transaction</groupId>
|
||||||
<artifactId>geronimo-jta_1.0.1B_spec</artifactId>
|
<artifactId>jboss-transaction-api_1.1_spec</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Spring -->
|
<!-- Spring -->
|
||||||
|
|
@ -55,18 +60,11 @@
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-context-support</artifactId>
|
<artifactId>spring-context-support</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.aspectj</groupId>
|
|
||||||
<artifactId>aspectjrt</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.aspectj</groupId>
|
<groupId>org.aspectj</groupId>
|
||||||
<artifactId>aspectjweaver</artifactId>
|
<artifactId>aspectjweaver</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>javassist</groupId>
|
|
||||||
<artifactId>javassist</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- JUnit -->
|
<!-- JUnit -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
@ -102,19 +100,11 @@
|
||||||
<classifier>jdk15</classifier>
|
<classifier>jdk15</classifier>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>commons-lang</groupId>
|
|
||||||
<artifactId>commons-lang</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<!-- Commons Math-->
|
<!-- Commons Math-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-math</groupId>
|
<groupId>commons-math</groupId>
|
||||||
<artifactId>commons-math</artifactId>
|
<artifactId>commons-math</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>commons-logging</groupId>
|
|
||||||
<artifactId>commons-logging</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-log4j12</artifactId>
|
<artifactId>slf4j-log4j12</artifactId>
|
||||||
|
|
@ -129,10 +119,6 @@
|
||||||
<groupId>org.dbunit</groupId>
|
<groupId>org.dbunit</groupId>
|
||||||
<artifactId>dbunit</artifactId>
|
<artifactId>dbunit</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>net.sf.ehcache</groupId>
|
|
||||||
<artifactId>ehcache</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.liquibase</groupId>
|
<groupId>org.liquibase</groupId>
|
||||||
<artifactId>liquibase-core</artifactId>
|
<artifactId>liquibase-core</artifactId>
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
package org.libreplan.business.advance.entities;
|
package org.libreplan.business.advance.entities;
|
||||||
|
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.libreplan.business.common.BaseEntity;
|
import org.libreplan.business.common.BaseEntity;
|
||||||
import org.libreplan.business.orders.entities.OrderElement;
|
import org.libreplan.business.orders.entities.OrderElement;
|
||||||
import org.libreplan.business.orders.entities.OrderLineGroup;
|
import org.libreplan.business.orders.entities.OrderLineGroup;
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ package org.libreplan.business.advance.entities;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.libreplan.business.common.BaseEntity;
|
import org.libreplan.business.common.BaseEntity;
|
||||||
import org.libreplan.business.orders.entities.OrderElement;
|
import org.libreplan.business.orders.entities.OrderElement;
|
||||||
import org.libreplan.business.templates.entities.OrderElementTemplate;
|
import org.libreplan.business.templates.entities.OrderElementTemplate;
|
||||||
|
|
|
||||||
|
|
@ -26,9 +26,9 @@ import java.util.Date;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.hibernate.validator.AssertTrue;
|
import javax.validation.constraints.AssertTrue;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.hibernate.validator.Valid;
|
import javax.validation.Valid;
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
import org.libreplan.business.common.BaseEntity;
|
import org.libreplan.business.common.BaseEntity;
|
||||||
import org.libreplan.business.orders.entities.OrderElement;
|
import org.libreplan.business.orders.entities.OrderElement;
|
||||||
|
|
@ -153,7 +153,7 @@ public class AdvanceMeasurement extends BaseEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "The current value must be less than the max value.")
|
@AssertTrue(message = "The current value must be less than the max value.")
|
||||||
public boolean checkConstraintValueIsLessThanMaxValue() {
|
public boolean isValueIsLessThanMaxValueConstraint() {
|
||||||
if ((this.value == null) || (this.advanceAssignment == null)){
|
if ((this.value == null) || (this.advanceAssignment == null)){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -167,7 +167,7 @@ public class AdvanceMeasurement extends BaseEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "The current value must be less than the max value.")
|
@AssertTrue(message = "The current value must be less than the max value.")
|
||||||
public boolean checkConstraintValidPrecision() {
|
public boolean isValidPrecisionConstraint() {
|
||||||
if ((this.value == null) || (this.advanceAssignment == null)
|
if ((this.value == null) || (this.advanceAssignment == null)
|
||||||
|| (this.advanceAssignment.getAdvanceType() == null)) {
|
|| (this.advanceAssignment.getAdvanceType() == null)) {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -27,9 +27,9 @@ import java.math.BigDecimal;
|
||||||
|
|
||||||
import org.apache.commons.lang.BooleanUtils;
|
import org.apache.commons.lang.BooleanUtils;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.hibernate.validator.AssertTrue;
|
import javax.validation.constraints.AssertTrue;
|
||||||
import org.hibernate.validator.NotEmpty;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.libreplan.business.advance.daos.IAdvanceTypeDAO;
|
import org.libreplan.business.advance.daos.IAdvanceTypeDAO;
|
||||||
import org.libreplan.business.common.BaseEntity;
|
import org.libreplan.business.common.BaseEntity;
|
||||||
import org.libreplan.business.common.IHumanIdentifiable;
|
import org.libreplan.business.common.IHumanIdentifiable;
|
||||||
|
|
@ -219,7 +219,7 @@ public class AdvanceType extends BaseEntity implements IHumanIdentifiable{
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "progress type marked as quality form but is updatable")
|
@AssertTrue(message = "progress type marked as quality form but is updatable")
|
||||||
public boolean checkConstraintIfIsQualityFormIsNotUpdatable() {
|
public boolean isIfIsQualityFormIsNotUpdatableConstraint() {
|
||||||
if (isQualityForm()) {
|
if (isQualityForm()) {
|
||||||
if (isUpdatable()) {
|
if (isUpdatable()) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -229,7 +229,7 @@ public class AdvanceType extends BaseEntity implements IHumanIdentifiable{
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "default maximum value of percentage progress type must be 100")
|
@AssertTrue(message = "default maximum value of percentage progress type must be 100")
|
||||||
public boolean checkConstraintDefaultMaxValueMustBe100ForPercentage() {
|
public boolean isDefaultMaxValueMustBe100ForPercentageConstraint() {
|
||||||
if (percentage) {
|
if (percentage) {
|
||||||
if (defaultMaxValue.compareTo(new BigDecimal(100)) != 0) {
|
if (defaultMaxValue.compareTo(new BigDecimal(100)) != 0) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -244,7 +244,7 @@ public class AdvanceType extends BaseEntity implements IHumanIdentifiable{
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "progress type name is already in use")
|
@AssertTrue(message = "progress type name is already in use")
|
||||||
public boolean checkConstraintUniqueName() {
|
public boolean isUniqueNameConstraint() {
|
||||||
if (StringUtils.isBlank(unitName)) {
|
if (StringUtils.isBlank(unitName)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -266,7 +266,7 @@ public class AdvanceType extends BaseEntity implements IHumanIdentifiable{
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "default maximum value must be greater than precision value")
|
@AssertTrue(message = "default maximum value must be greater than precision value")
|
||||||
public boolean checkDefaultMaxValueGreaterThanPrecision() {
|
public boolean isDefaultMaxValueGreaterThanPrecisionConstraint() {
|
||||||
if (defaultMaxValue.compareTo(unitPrecision) == -1) {
|
if (defaultMaxValue.compareTo(unitPrecision) == -1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,9 +30,9 @@ import java.util.Set;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
|
||||||
import org.hibernate.validator.AssertTrue;
|
import javax.validation.constraints.AssertTrue;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.hibernate.validator.Valid;
|
import javax.validation.Valid;
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
import org.libreplan.business.orders.entities.OrderElement;
|
import org.libreplan.business.orders.entities.OrderElement;
|
||||||
import org.libreplan.business.planner.entities.consolidations.NonCalculatedConsolidation;
|
import org.libreplan.business.planner.entities.consolidations.NonCalculatedConsolidation;
|
||||||
|
|
@ -193,7 +193,7 @@ public class DirectAdvanceAssignment extends AdvanceAssignment {
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "Progress measurements must have a value lower than their following progress measurements.")
|
@AssertTrue(message = "Progress measurements must have a value lower than their following progress measurements.")
|
||||||
public boolean checkConstraintValidAdvanceMeasurements() {
|
public boolean isValidAdvanceMeasurementsConstraint() {
|
||||||
if (advanceMeasurements.isEmpty()) {
|
if (advanceMeasurements.isEmpty()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -224,7 +224,7 @@ public class DirectAdvanceAssignment extends AdvanceAssignment {
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "maxixum value of percentage progress type must be 100")
|
@AssertTrue(message = "maxixum value of percentage progress type must be 100")
|
||||||
public boolean checkConstraintMaxValueMustBe100ForPercentage() {
|
public boolean isMaxValueMustBe100ForPercentageConstraint() {
|
||||||
AdvanceType advanceType = getAdvanceType();
|
AdvanceType advanceType = getAdvanceType();
|
||||||
if ((advanceType != null) && (advanceType.getPercentage())) {
|
if ((advanceType != null) && (advanceType.getPercentage())) {
|
||||||
if (maxValue.compareTo(new BigDecimal(100)) != 0) {
|
if (maxValue.compareTo(new BigDecimal(100)) != 0) {
|
||||||
|
|
@ -235,7 +235,7 @@ public class DirectAdvanceAssignment extends AdvanceAssignment {
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "maximum value must be greater than zero")
|
@AssertTrue(message = "maximum value must be greater than zero")
|
||||||
public boolean checkConstraintMaxValueMustBeGreaterThanZero() {
|
public boolean isMaxValueMustBeGreaterThanZeroConstraint() {
|
||||||
return maxValue.compareTo(BigDecimal.ZERO) > 0;
|
return maxValue.compareTo(BigDecimal.ZERO) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ package org.libreplan.business.advance.entities;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.hibernate.validator.Valid;
|
import javax.validation.Valid;
|
||||||
import org.libreplan.business.orders.entities.OrderLineGroup;
|
import org.libreplan.business.orders.entities.OrderLineGroup;
|
||||||
import org.libreplan.business.planner.entities.consolidations.CalculatedConsolidation;
|
import org.libreplan.business.planner.entities.consolidations.CalculatedConsolidation;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -154,7 +154,7 @@ public class BaseCalendarDAO extends IntegrationEntityDAO<BaseCalendar>
|
||||||
.add(Restrictions.eq("calendarData.parent", calendar)).list();
|
.add(Restrictions.eq("calendarData.parent", calendar)).list();
|
||||||
if (!calendars.isEmpty()) {
|
if (!calendars.isEmpty()) {
|
||||||
throw ValidationException
|
throw ValidationException
|
||||||
.invalidValue(
|
.invalidValueException(
|
||||||
"Cannot delete calendar. It is being used at this moment by some resources.",
|
"Cannot delete calendar. It is being used at this moment by some resources.",
|
||||||
calendar);
|
calendar);
|
||||||
}
|
}
|
||||||
|
|
@ -165,7 +165,7 @@ public class BaseCalendarDAO extends IntegrationEntityDAO<BaseCalendar>
|
||||||
.add(Restrictions.eq("calendar", calendar)).list();
|
.add(Restrictions.eq("calendar", calendar)).list();
|
||||||
if (!orders.isEmpty()) {
|
if (!orders.isEmpty()) {
|
||||||
throw ValidationException
|
throw ValidationException
|
||||||
.invalidValue(
|
.invalidValueException(
|
||||||
"Cannot delete calendar. It is being used at this moment by some orders.",
|
"Cannot delete calendar. It is being used at this moment by some orders.",
|
||||||
calendar);
|
calendar);
|
||||||
}
|
}
|
||||||
|
|
@ -176,7 +176,7 @@ public class BaseCalendarDAO extends IntegrationEntityDAO<BaseCalendar>
|
||||||
.add(Restrictions.eq("calendar", calendar)).list();
|
.add(Restrictions.eq("calendar", calendar)).list();
|
||||||
if (!tasks.isEmpty()) {
|
if (!tasks.isEmpty()) {
|
||||||
throw ValidationException
|
throw ValidationException
|
||||||
.invalidValue(
|
.invalidValueException(
|
||||||
"Cannot delete calendar. It is being used at this moment by some tasks.",
|
"Cannot delete calendar. It is being used at this moment by some tasks.",
|
||||||
calendar);
|
calendar);
|
||||||
}
|
}
|
||||||
|
|
@ -187,7 +187,7 @@ public class BaseCalendarDAO extends IntegrationEntityDAO<BaseCalendar>
|
||||||
.add(Restrictions.eq("calendar", calendar)).list();
|
.add(Restrictions.eq("calendar", calendar)).list();
|
||||||
if (!templates.isEmpty()) {
|
if (!templates.isEmpty()) {
|
||||||
throw ValidationException
|
throw ValidationException
|
||||||
.invalidValue(
|
.invalidValueException(
|
||||||
"Cannot delete calendar. It is being used at this moment by some templates.",
|
"Cannot delete calendar. It is being used at this moment by some templates.",
|
||||||
calendar);
|
calendar);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,10 +30,10 @@ import java.util.Set;
|
||||||
import org.apache.commons.lang.ObjectUtils;
|
import org.apache.commons.lang.ObjectUtils;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.hibernate.validator.AssertTrue;
|
import javax.validation.constraints.AssertTrue;
|
||||||
import org.hibernate.validator.NotEmpty;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.hibernate.validator.Valid;
|
import javax.validation.Valid;
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
import org.libreplan.business.calendars.daos.IBaseCalendarDAO;
|
import org.libreplan.business.calendars.daos.IBaseCalendarDAO;
|
||||||
import org.libreplan.business.calendars.entities.AvailabilityTimeLine.IVetoer;
|
import org.libreplan.business.calendars.entities.AvailabilityTimeLine.IVetoer;
|
||||||
|
|
@ -1104,7 +1104,7 @@ public class BaseCalendar extends IntegrationEntity implements ICalendar,
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@AssertTrue(message = "dates must be sorted and cannot overlap")
|
@AssertTrue(message = "dates must be sorted and cannot overlap")
|
||||||
public boolean checkConstraintDateCouldNotOverlap() {
|
public boolean isDateCouldNotOverlapConstraint() {
|
||||||
|
|
||||||
if (calendarDataVersions == null || calendarDataVersions.isEmpty()) {
|
if (calendarDataVersions == null || calendarDataVersions.isEmpty()) {
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -1216,7 +1216,7 @@ public class BaseCalendar extends IntegrationEntity implements ICalendar,
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "calendars with zero hours are not allowed")
|
@AssertTrue(message = "calendars with zero hours are not allowed")
|
||||||
public boolean checkConstraintZeroHours() {
|
public boolean isZeroHoursConstraint() {
|
||||||
if ((calendarDataVersions != null) && (!calendarDataVersions.isEmpty())) {
|
if ((calendarDataVersions != null) && (!calendarDataVersions.isEmpty())) {
|
||||||
for (CalendarData each : calendarDataVersions) {
|
for (CalendarData each : calendarDataVersions) {
|
||||||
if (!each.isEmpty()) {
|
if (!each.isEmpty()) {
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ package org.libreplan.business.calendars.entities;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.joda.time.Interval;
|
import org.joda.time.Interval;
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
import org.libreplan.business.calendars.daos.ICalendarAvailabilityDAO;
|
import org.libreplan.business.calendars.daos.ICalendarAvailabilityDAO;
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@
|
||||||
package org.libreplan.business.calendars.entities;
|
package org.libreplan.business.calendars.entities;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
import org.libreplan.business.calendars.daos.ICalendarExceptionDAO;
|
import org.libreplan.business.calendars.daos.ICalendarExceptionDAO;
|
||||||
import org.libreplan.business.common.IntegrationEntity;
|
import org.libreplan.business.common.IntegrationEntity;
|
||||||
|
|
|
||||||
|
|
@ -29,9 +29,9 @@ import org.apache.commons.lang.BooleanUtils;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.hibernate.NonUniqueResultException;
|
import org.hibernate.NonUniqueResultException;
|
||||||
import org.hibernate.validator.AssertTrue;
|
import javax.validation.constraints.AssertTrue;
|
||||||
import org.hibernate.validator.NotEmpty;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.libreplan.business.calendars.daos.ICalendarExceptionTypeDAO;
|
import org.libreplan.business.calendars.daos.ICalendarExceptionTypeDAO;
|
||||||
import org.libreplan.business.common.IHumanIdentifiable;
|
import org.libreplan.business.common.IHumanIdentifiable;
|
||||||
import org.libreplan.business.common.IntegrationEntity;
|
import org.libreplan.business.common.IntegrationEntity;
|
||||||
|
|
@ -39,7 +39,7 @@ import org.libreplan.business.common.Registry;
|
||||||
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
|
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
|
||||||
import org.libreplan.business.workingday.EffortDuration;
|
import org.libreplan.business.workingday.EffortDuration;
|
||||||
import org.libreplan.business.workingday.EffortDuration.Granularity;
|
import org.libreplan.business.workingday.EffortDuration.Granularity;
|
||||||
import org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException;
|
import org.springframework.orm.hibernate4.HibernateOptimisticLockingFailureException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type of an exception day.
|
* Type of an exception day.
|
||||||
|
|
@ -180,7 +180,7 @@ public class CalendarExceptionType extends IntegrationEntity implements
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "name is already used")
|
@AssertTrue(message = "name is already used")
|
||||||
public boolean checkConstraintUniqueName() {
|
public boolean isUniqueNameConstraint() {
|
||||||
if (StringUtils.isBlank(name)) {
|
if (StringUtils.isBlank(name)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,8 @@
|
||||||
|
|
||||||
package org.libreplan.business.calendars.entities;
|
package org.libreplan.business.calendars.entities;
|
||||||
|
|
||||||
import org.hibernate.validator.AssertTrue;
|
import javax.validation.constraints.AssertTrue;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
import org.libreplan.business.resources.entities.Resource;
|
import org.libreplan.business.resources.entities.Resource;
|
||||||
|
|
||||||
|
|
@ -71,7 +71,7 @@ public class ResourceCalendar extends BaseCalendar {
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "Capacity must be a positive integer number")
|
@AssertTrue(message = "Capacity must be a positive integer number")
|
||||||
public boolean checkCapacityPositiveIntegerNumber() {
|
public boolean isCapacityPositiveIntegerNumberConstraint() {
|
||||||
return (capacity >= 1);
|
return (capacity >= 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,9 +27,13 @@ import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.validation.ConstraintViolation;
|
||||||
|
import javax.validation.Validation;
|
||||||
|
import javax.validation.Validator;
|
||||||
|
import javax.validation.ValidatorFactory;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.hibernate.validator.InvalidValue;
|
|
||||||
import org.libreplan.business.INewObject;
|
import org.libreplan.business.INewObject;
|
||||||
import org.libreplan.business.common.exceptions.ValidationException;
|
import org.libreplan.business.common.exceptions.ValidationException;
|
||||||
import org.libreplan.business.util.deepcopy.AfterCopy;
|
import org.libreplan.business.util.deepcopy.AfterCopy;
|
||||||
|
|
@ -67,6 +71,11 @@ public abstract class BaseEntity implements INewObject {
|
||||||
|
|
||||||
private static final Log LOG = LogFactory.getLog(BaseEntity.class);
|
private static final Log LOG = LogFactory.getLog(BaseEntity.class);
|
||||||
|
|
||||||
|
private static final ValidatorFactory validatorFactory = Validation
|
||||||
|
.buildDefaultValidatorFactory();
|
||||||
|
|
||||||
|
private static final Validator validator = validatorFactory.getValidator();
|
||||||
|
|
||||||
@OnCopy(Strategy.IGNORE)
|
@OnCopy(Strategy.IGNORE)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
|
|
@ -125,10 +134,10 @@ public abstract class BaseEntity implements INewObject {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void validate() throws ValidationException {
|
public void validate() throws ValidationException {
|
||||||
LibrePlanClassValidator classValidator = new LibrePlanClassValidator(this.getClass());
|
Set<ConstraintViolation<BaseEntity>> violations = validator
|
||||||
InvalidValue[] invalidValues = classValidator.getInvalidValues(this);
|
.validate(this);
|
||||||
if (invalidValues.length > 0) {
|
if (!violations.isEmpty()) {
|
||||||
throw new ValidationException(invalidValues);
|
throw new ValidationException(violations);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,8 @@ import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.hibernate.validator.AssertTrue;
|
import javax.validation.constraints.AssertTrue;
|
||||||
import org.hibernate.validator.NotEmpty;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
import org.libreplan.business.common.daos.IIntegrationEntityDAO;
|
import org.libreplan.business.common.daos.IIntegrationEntityDAO;
|
||||||
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
|
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
|
||||||
|
|
||||||
|
|
@ -107,7 +107,7 @@ public abstract class IntegrationEntity extends BaseEntity {
|
||||||
* calls on the abstract method <code>getIntegrationEntityDAO()</code>.
|
* calls on the abstract method <code>getIntegrationEntityDAO()</code>.
|
||||||
*/
|
*/
|
||||||
@AssertTrue(message="code is already used")
|
@AssertTrue(message="code is already used")
|
||||||
public boolean checkConstraintUniqueCode() {
|
public boolean isUniqueCodeConstraint() {
|
||||||
|
|
||||||
/* Check if it makes sense to check the constraint .*/
|
/* Check if it makes sense to check the constraint .*/
|
||||||
if (!iCodeSpecified()) {
|
if (!iCodeSpecified()) {
|
||||||
|
|
|
||||||
|
|
@ -1,799 +0,0 @@
|
||||||
/*
|
|
||||||
* This file is part of LibrePlan
|
|
||||||
*
|
|
||||||
* Copyright (C) 2010-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.libreplan.business.common;
|
|
||||||
|
|
||||||
import java.beans.Introspector;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.ObjectInputStream;
|
|
||||||
import java.io.ObjectOutputStream;
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.lang.annotation.Annotation;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.lang.reflect.Modifier;
|
|
||||||
import java.text.MessageFormat;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.MissingResourceException;
|
|
||||||
import java.util.ResourceBundle;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.StringTokenizer;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.hibernate.AssertionFailure;
|
|
||||||
import org.hibernate.Hibernate;
|
|
||||||
import org.hibernate.MappingException;
|
|
||||||
import org.hibernate.annotations.common.reflection.Filter;
|
|
||||||
import org.hibernate.annotations.common.reflection.ReflectionManager;
|
|
||||||
import org.hibernate.annotations.common.reflection.XClass;
|
|
||||||
import org.hibernate.annotations.common.reflection.XMember;
|
|
||||||
import org.hibernate.annotations.common.reflection.XMethod;
|
|
||||||
import org.hibernate.annotations.common.reflection.XProperty;
|
|
||||||
import org.hibernate.annotations.common.reflection.java.JavaReflectionManager;
|
|
||||||
import org.hibernate.mapping.Component;
|
|
||||||
import org.hibernate.mapping.PersistentClass;
|
|
||||||
import org.hibernate.mapping.Property;
|
|
||||||
import org.hibernate.util.IdentitySet;
|
|
||||||
import org.hibernate.validator.InvalidStateException;
|
|
||||||
import org.hibernate.validator.InvalidValue;
|
|
||||||
import org.hibernate.validator.MessageInterpolator;
|
|
||||||
import org.hibernate.validator.PersistentClassConstraint;
|
|
||||||
import org.hibernate.validator.PropertyConstraint;
|
|
||||||
import org.hibernate.validator.Valid;
|
|
||||||
import org.hibernate.validator.Validator;
|
|
||||||
import org.hibernate.validator.ValidatorClass;
|
|
||||||
import org.hibernate.validator.Version;
|
|
||||||
import org.hibernate.validator.interpolator.DefaultMessageInterpolatorAggregator;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class is copy-cat of HibernateValidator.ClassValidator
|
|
||||||
*
|
|
||||||
* Adds extra functionality to cache extra ClassValidators created for validating children elements (see getClassValidator)
|
|
||||||
*
|
|
||||||
* The function createChildValidator creates ClassValidators for getters and members marked for Validation, but it doesn't create
|
|
||||||
* ClassValidators for members that return Collections or ArrayList of entities. These ClassValidators are created later in getClasValidator
|
|
||||||
* but are not cached.
|
|
||||||
*
|
|
||||||
* Original code: http://anonsvn.jboss.org/repos/hibernate/validator/trunk/hibernate-validator-legacy/src/main/java/org/hibernate/validator/ClassValidator.java
|
|
||||||
*
|
|
||||||
* @author Diego Pino <dpino@igalia.com>
|
|
||||||
*/
|
|
||||||
public class LibrePlanClassValidator<T> implements Serializable {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog( LibrePlanClassValidator.class );
|
|
||||||
private static final InvalidValue[] EMPTY_INVALID_VALUE_ARRAY = new InvalidValue[]{};
|
|
||||||
private static final String DEFAULT_VALIDATOR_MESSAGE = "org.hibernate.validator.resources.DefaultValidatorMessages";
|
|
||||||
private static final String VALIDATOR_MESSAGE = "ValidatorMessages";
|
|
||||||
private static final Set<Class> INDEXABLE_CLASS = new HashSet<Class>();
|
|
||||||
|
|
||||||
static {
|
|
||||||
INDEXABLE_CLASS.add( Integer.class );
|
|
||||||
INDEXABLE_CLASS.add( Long.class );
|
|
||||||
INDEXABLE_CLASS.add( String.class );
|
|
||||||
}
|
|
||||||
|
|
||||||
static {
|
|
||||||
Version.touch(); //touch version
|
|
||||||
}
|
|
||||||
|
|
||||||
private final Class<T> beanClass;
|
|
||||||
private transient ResourceBundle messageBundle;
|
|
||||||
private transient ResourceBundle defaultMessageBundle;
|
|
||||||
private transient boolean isUserProvidedResourceBundle;
|
|
||||||
private transient ReflectionManager reflectionManager;
|
|
||||||
|
|
||||||
private final transient Map<XClass, LibrePlanClassValidator> childClassValidators;
|
|
||||||
private final transient Map<XClass, LibrePlanClassValidator> extraClassValidators;
|
|
||||||
private transient List<Validator> beanValidators;
|
|
||||||
private transient List<Validator> memberValidators;
|
|
||||||
private transient List<XMember> memberGetters;
|
|
||||||
private transient List<XMember> childGetters;
|
|
||||||
private transient DefaultMessageInterpolatorAggregator defaultInterpolator;
|
|
||||||
private transient MessageInterpolator userInterpolator;
|
|
||||||
private static final Filter GET_ALL_FILTER = new Filter() {
|
|
||||||
public boolean returnStatic() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean returnTransient() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* create the validator engine for this bean type
|
|
||||||
*/
|
|
||||||
public LibrePlanClassValidator(Class<T> beanClass) {
|
|
||||||
this( beanClass, (ResourceBundle) null );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* create the validator engine for a particular bean class, using a resource bundle
|
|
||||||
* for message rendering on violation
|
|
||||||
*/
|
|
||||||
public LibrePlanClassValidator(Class<T> beanClass, ResourceBundle resourceBundle) {
|
|
||||||
this( beanClass, resourceBundle, null, new HashMap<XClass, LibrePlanClassValidator>(), null );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* create the validator engine for a particular bean class, using a custom message interpolator
|
|
||||||
* for message rendering on violation
|
|
||||||
*/
|
|
||||||
public LibrePlanClassValidator(Class<T> beanClass, MessageInterpolator interpolator) {
|
|
||||||
this( beanClass, null, interpolator, new HashMap<XClass, LibrePlanClassValidator>(), null );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Not a public API
|
|
||||||
*/
|
|
||||||
public LibrePlanClassValidator(
|
|
||||||
Class<T> beanClass, ResourceBundle resourceBundle, MessageInterpolator interpolator,
|
|
||||||
Map<XClass, LibrePlanClassValidator> childClassValidators, ReflectionManager reflectionManager
|
|
||||||
) {
|
|
||||||
this.reflectionManager = reflectionManager != null ? reflectionManager : new JavaReflectionManager();
|
|
||||||
XClass beanXClass = this.reflectionManager.toXClass( beanClass );
|
|
||||||
this.beanClass = beanClass;
|
|
||||||
this.messageBundle = resourceBundle == null ?
|
|
||||||
getDefaultResourceBundle() :
|
|
||||||
resourceBundle;
|
|
||||||
this.defaultMessageBundle = ResourceBundle.getBundle( DEFAULT_VALIDATOR_MESSAGE );
|
|
||||||
this.userInterpolator = interpolator;
|
|
||||||
this.childClassValidators = childClassValidators != null ?
|
|
||||||
childClassValidators :
|
|
||||||
new HashMap<XClass, LibrePlanClassValidator>();
|
|
||||||
this.extraClassValidators = new HashMap<XClass, LibrePlanClassValidator>();
|
|
||||||
initValidator( beanXClass, this.childClassValidators );
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
protected LibrePlanClassValidator(
|
|
||||||
XClass beanXClass, ResourceBundle resourceBundle, MessageInterpolator userInterpolator,
|
|
||||||
Map<XClass, LibrePlanClassValidator> childClassValidators, ReflectionManager reflectionManager
|
|
||||||
) {
|
|
||||||
this.reflectionManager = reflectionManager;
|
|
||||||
this.beanClass = reflectionManager.toClass( beanXClass );
|
|
||||||
this.messageBundle = resourceBundle == null ?
|
|
||||||
getDefaultResourceBundle() :
|
|
||||||
resourceBundle;
|
|
||||||
this.defaultMessageBundle = ResourceBundle.getBundle( DEFAULT_VALIDATOR_MESSAGE );
|
|
||||||
this.userInterpolator = userInterpolator;
|
|
||||||
this.childClassValidators = childClassValidators;
|
|
||||||
this.extraClassValidators = new HashMap<XClass, LibrePlanClassValidator>();
|
|
||||||
initValidator( beanXClass, childClassValidators );
|
|
||||||
}
|
|
||||||
|
|
||||||
private ResourceBundle getDefaultResourceBundle() {
|
|
||||||
ResourceBundle rb;
|
|
||||||
try {
|
|
||||||
//use context class loader as a first citizen
|
|
||||||
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
|
|
||||||
if ( contextClassLoader == null ) {
|
|
||||||
throw new MissingResourceException( "No context classloader", null, VALIDATOR_MESSAGE );
|
|
||||||
}
|
|
||||||
rb = ResourceBundle.getBundle(
|
|
||||||
VALIDATOR_MESSAGE,
|
|
||||||
Locale.getDefault(),
|
|
||||||
contextClassLoader
|
|
||||||
);
|
|
||||||
}
|
|
||||||
catch (MissingResourceException e) {
|
|
||||||
log.trace( "ResourceBundle " + VALIDATOR_MESSAGE + " not found in thread context classloader" );
|
|
||||||
//then use the Validator Framework classloader
|
|
||||||
try {
|
|
||||||
rb = ResourceBundle.getBundle(
|
|
||||||
VALIDATOR_MESSAGE,
|
|
||||||
Locale.getDefault(),
|
|
||||||
this.getClass().getClassLoader()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
catch (MissingResourceException ee) {
|
|
||||||
log.debug(
|
|
||||||
"ResourceBundle ValidatorMessages not found in Validator classloader. Delegate to " + DEFAULT_VALIDATOR_MESSAGE
|
|
||||||
);
|
|
||||||
//the user did not override the default ValidatorMessages
|
|
||||||
rb = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
isUserProvidedResourceBundle = true;
|
|
||||||
return rb;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initValidator(
|
|
||||||
XClass xClass, Map<XClass, LibrePlanClassValidator> childClassValidators
|
|
||||||
) {
|
|
||||||
beanValidators = new ArrayList<Validator>();
|
|
||||||
memberValidators = new ArrayList<Validator>();
|
|
||||||
memberGetters = new ArrayList<XMember>();
|
|
||||||
childGetters = new ArrayList<XMember>();
|
|
||||||
defaultInterpolator = new DefaultMessageInterpolatorAggregator();
|
|
||||||
defaultInterpolator.initialize( messageBundle, defaultMessageBundle );
|
|
||||||
|
|
||||||
//build the class hierarchy to look for members in
|
|
||||||
childClassValidators.put( xClass, this );
|
|
||||||
Collection<XClass> classes = new HashSet<XClass>();
|
|
||||||
addSuperClassesAndInterfaces( xClass, classes );
|
|
||||||
for ( XClass currentClass : classes ) {
|
|
||||||
Annotation[] classAnnotations = currentClass.getAnnotations();
|
|
||||||
for ( int i = 0; i < classAnnotations.length ; i++ ) {
|
|
||||||
Annotation classAnnotation = classAnnotations[i];
|
|
||||||
Validator beanValidator = createValidator( classAnnotation );
|
|
||||||
if ( beanValidator != null ) beanValidators.add( beanValidator );
|
|
||||||
handleAggregateAnnotations(classAnnotation, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Check on all selected classes
|
|
||||||
for ( XClass currClass : classes ) {
|
|
||||||
List<XMethod> methods = currClass.getDeclaredMethods();
|
|
||||||
for ( XMethod method : methods ) {
|
|
||||||
createMemberValidator( method );
|
|
||||||
createChildValidator( method );
|
|
||||||
}
|
|
||||||
|
|
||||||
List<XProperty> fields = currClass.getDeclaredProperties(
|
|
||||||
"field", GET_ALL_FILTER
|
|
||||||
);
|
|
||||||
for ( XProperty field : fields ) {
|
|
||||||
createMemberValidator( field );
|
|
||||||
createChildValidator( field );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addSuperClassesAndInterfaces(XClass clazz, Collection<XClass> classes) {
|
|
||||||
for ( XClass currClass = clazz; currClass != null ; currClass = currClass.getSuperclass() ) {
|
|
||||||
if ( ! classes.add( currClass ) ) return;
|
|
||||||
XClass[] interfaces = currClass.getInterfaces();
|
|
||||||
for ( XClass interf : interfaces ) {
|
|
||||||
addSuperClassesAndInterfaces( interf, classes );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean handleAggregateAnnotations(Annotation annotation, XMember member) {
|
|
||||||
Object[] values;
|
|
||||||
try {
|
|
||||||
Method valueMethod = annotation.getClass().getMethod( "value" );
|
|
||||||
if ( valueMethod.getReturnType().isArray() ) {
|
|
||||||
values = (Object[]) valueMethod.invoke( annotation );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (NoSuchMethodException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
throw new IllegalStateException( e );
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean validatorPresent = false;
|
|
||||||
for ( Object value : values ) {
|
|
||||||
if ( value instanceof Annotation ) {
|
|
||||||
annotation = (Annotation) value;
|
|
||||||
Validator validator = createValidator( annotation );
|
|
||||||
if ( validator != null ) {
|
|
||||||
if ( member != null ) {
|
|
||||||
//member
|
|
||||||
memberValidators.add( validator );
|
|
||||||
setAccessible( member );
|
|
||||||
memberGetters.add( member );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
//bean
|
|
||||||
beanValidators.add( validator );
|
|
||||||
}
|
|
||||||
validatorPresent = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return validatorPresent;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private void createChildValidator( XMember member) {
|
|
||||||
if ( member.isAnnotationPresent( Valid.class ) ) {
|
|
||||||
setAccessible( member );
|
|
||||||
childGetters.add( member );
|
|
||||||
XClass clazz;
|
|
||||||
if ( member.isCollection() || member.isArray() ) {
|
|
||||||
clazz = member.getElementClass();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
clazz = member.getType();
|
|
||||||
}
|
|
||||||
if ( !childClassValidators.containsKey( clazz ) ) {
|
|
||||||
//ClassValidator added by side effect (added to childClassValidators during CV construction)
|
|
||||||
new LibrePlanClassValidator( clazz, messageBundle, userInterpolator, childClassValidators, reflectionManager );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createMemberValidator(XMember member) {
|
|
||||||
boolean validatorPresent = false;
|
|
||||||
Annotation[] memberAnnotations = member.getAnnotations();
|
|
||||||
for ( Annotation methodAnnotation : memberAnnotations ) {
|
|
||||||
Validator propertyValidator = createValidator( methodAnnotation );
|
|
||||||
if ( propertyValidator != null ) {
|
|
||||||
memberValidators.add( propertyValidator );
|
|
||||||
setAccessible( member );
|
|
||||||
memberGetters.add( member );
|
|
||||||
validatorPresent = true;
|
|
||||||
}
|
|
||||||
boolean agrValidPresent = handleAggregateAnnotations( methodAnnotation, member );
|
|
||||||
validatorPresent = validatorPresent || agrValidPresent;
|
|
||||||
}
|
|
||||||
if ( validatorPresent && !member.isTypeResolved() ) {
|
|
||||||
log.warn( "Original type of property " + member + " is unbound and has been approximated." );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void setAccessible(XMember member) {
|
|
||||||
if ( !Modifier.isPublic( member.getModifiers() ) ) {
|
|
||||||
member.setAccessible( true );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private Validator createValidator(Annotation annotation) {
|
|
||||||
try {
|
|
||||||
ValidatorClass validatorClass = annotation.annotationType().getAnnotation( ValidatorClass.class );
|
|
||||||
if ( validatorClass == null ) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
Validator beanValidator = validatorClass.value().newInstance();
|
|
||||||
beanValidator.initialize( annotation );
|
|
||||||
defaultInterpolator.addInterpolator( annotation, beanValidator );
|
|
||||||
return beanValidator;
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
throw new IllegalArgumentException( "could not instantiate LibrePlanClassValidator", e );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasValidationRules() {
|
|
||||||
return beanValidators.size() != 0 || memberValidators.size() != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* apply constraints on a bean instance and return all the failures.
|
|
||||||
* if <code>bean</code> is null, an empty array is returned
|
|
||||||
*/
|
|
||||||
public InvalidValue[] getInvalidValues(T bean) {
|
|
||||||
return this.getInvalidValues( bean, new IdentitySet() );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* apply constraints on a bean instance and return all the failures.
|
|
||||||
* if <code>bean</code> is null, an empty array is returned
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
protected InvalidValue[] getInvalidValues(T bean, Set<Object> circularityState) {
|
|
||||||
if ( bean == null || circularityState.contains( bean ) ) {
|
|
||||||
return EMPTY_INVALID_VALUE_ARRAY; //Avoid circularity
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
circularityState.add( bean );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !beanClass.isInstance( bean ) ) {
|
|
||||||
throw new IllegalArgumentException( "not an instance of: " + bean.getClass() );
|
|
||||||
}
|
|
||||||
|
|
||||||
List<InvalidValue> results = new ArrayList<InvalidValue>();
|
|
||||||
|
|
||||||
for ( int i = 0; i < beanValidators.size() ; i++ ) {
|
|
||||||
Validator validator = beanValidators.get( i );
|
|
||||||
if ( !validator.isValid( bean ) ) {
|
|
||||||
results.add( new InvalidValue( interpolate(validator), beanClass, null, bean, bean ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for ( int i = 0; i < memberValidators.size() ; i++ ) {
|
|
||||||
XMember getter = memberGetters.get( i );
|
|
||||||
if ( Hibernate.isPropertyInitialized( bean, getPropertyName( getter ) ) ) {
|
|
||||||
Object value = getMemberValue( bean, getter );
|
|
||||||
Validator validator = memberValidators.get( i );
|
|
||||||
if ( !validator.isValid( value ) ) {
|
|
||||||
String propertyName = getPropertyName( getter );
|
|
||||||
results.add( new InvalidValue( interpolate(validator), beanClass, propertyName, value, bean ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for ( int i = 0; i < childGetters.size() ; i++ ) {
|
|
||||||
XMember getter = childGetters.get( i );
|
|
||||||
if ( Hibernate.isPropertyInitialized( bean, getPropertyName( getter ) ) ) {
|
|
||||||
Object value = getMemberValue( bean, getter );
|
|
||||||
if ( value != null && Hibernate.isInitialized( value ) ) {
|
|
||||||
String propertyName = getPropertyName( getter );
|
|
||||||
if ( getter.isCollection() ) {
|
|
||||||
int index = 0;
|
|
||||||
boolean isIterable = value instanceof Iterable;
|
|
||||||
Map map = ! isIterable ? (Map) value : null;
|
|
||||||
Iterable elements = isIterable ?
|
|
||||||
(Iterable) value :
|
|
||||||
map.keySet();
|
|
||||||
for ( Object element : elements ) {
|
|
||||||
Object actualElement = isIterable ? element : map.get( element );
|
|
||||||
if ( actualElement == null ) {
|
|
||||||
index++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
InvalidValue[] invalidValues = getClassValidator( actualElement )
|
|
||||||
.getInvalidValues( actualElement, circularityState );
|
|
||||||
|
|
||||||
String indexedPropName = MessageFormat.format(
|
|
||||||
"{0}[{1}]",
|
|
||||||
propertyName,
|
|
||||||
INDEXABLE_CLASS.contains( element.getClass() ) ?
|
|
||||||
( "'" + element + "'" ) :
|
|
||||||
index
|
|
||||||
);
|
|
||||||
index++;
|
|
||||||
|
|
||||||
for ( InvalidValue invalidValue : invalidValues ) {
|
|
||||||
invalidValue.addParentBean( bean, indexedPropName );
|
|
||||||
results.add( invalidValue );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( getter.isArray() ) {
|
|
||||||
int index = 0;
|
|
||||||
for ( Object element : (Object[]) value ) {
|
|
||||||
if ( element == null ) {
|
|
||||||
index++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
InvalidValue[] invalidValues = getClassValidator( element )
|
|
||||||
.getInvalidValues( element, circularityState );
|
|
||||||
|
|
||||||
String indexedPropName = MessageFormat.format(
|
|
||||||
"{0}[{1}]",
|
|
||||||
propertyName,
|
|
||||||
index
|
|
||||||
);
|
|
||||||
index++;
|
|
||||||
|
|
||||||
for ( InvalidValue invalidValue : invalidValues ) {
|
|
||||||
invalidValue.addParentBean( bean, indexedPropName );
|
|
||||||
results.add( invalidValue );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
InvalidValue[] invalidValues = getClassValidator( value )
|
|
||||||
.getInvalidValues( value, circularityState );
|
|
||||||
for ( InvalidValue invalidValue : invalidValues ) {
|
|
||||||
invalidValue.addParentBean( bean, propertyName );
|
|
||||||
results.add( invalidValue );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return results.toArray( new InvalidValue[results.size()] );
|
|
||||||
}
|
|
||||||
|
|
||||||
private String interpolate(Validator validator) {
|
|
||||||
String message = defaultInterpolator.getAnnotationMessage( validator );
|
|
||||||
if (userInterpolator != null) {
|
|
||||||
return userInterpolator.interpolate( message, validator, defaultInterpolator );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return defaultInterpolator.interpolate( message, validator, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private LibrePlanClassValidator getClassValidator(Object value) {
|
|
||||||
Class clazz = value.getClass();
|
|
||||||
XClass xclass = reflectionManager.toXClass( clazz );
|
|
||||||
LibrePlanClassValidator validator = (LibrePlanClassValidator) childClassValidators.get( xclass );
|
|
||||||
if ( validator == null ) { //handles polymorphism
|
|
||||||
validator = extraClassValidators.get( xclass );
|
|
||||||
if (validator == null) {
|
|
||||||
validator = new LibrePlanClassValidator( clazz );
|
|
||||||
extraClassValidators.put( xclass, validator );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return validator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Apply constraints of a particular property on a bean instance and return all the failures.
|
|
||||||
* Note this is not recursive.
|
|
||||||
*/
|
|
||||||
//TODO should it be recursive?
|
|
||||||
public InvalidValue[] getInvalidValues(T bean, String propertyName) {
|
|
||||||
List<InvalidValue> results = new ArrayList<InvalidValue>();
|
|
||||||
|
|
||||||
for ( int i = 0; i < memberValidators.size() ; i++ ) {
|
|
||||||
XMember getter = memberGetters.get( i );
|
|
||||||
if ( getPropertyName( getter ).equals( propertyName ) ) {
|
|
||||||
Object value = getMemberValue( bean, getter );
|
|
||||||
Validator validator = memberValidators.get( i );
|
|
||||||
if ( !validator.isValid( value ) ) {
|
|
||||||
results.add( new InvalidValue( interpolate(validator), beanClass, propertyName, value, bean ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return results.toArray( new InvalidValue[results.size()] );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Apply constraints of a particular property value of a bean type and return all the failures.
|
|
||||||
* The InvalidValue objects returns return null for InvalidValue#getBean() and InvalidValue#getRootBean()
|
|
||||||
* Note this is not recursive.
|
|
||||||
*/
|
|
||||||
//TODO should it be recursive?
|
|
||||||
public InvalidValue[] getPotentialInvalidValues(String propertyName, Object value) {
|
|
||||||
List<InvalidValue> results = new ArrayList<InvalidValue>();
|
|
||||||
|
|
||||||
for ( int i = 0; i < memberValidators.size() ; i++ ) {
|
|
||||||
XMember getter = memberGetters.get( i );
|
|
||||||
if ( getPropertyName( getter ).equals( propertyName ) ) {
|
|
||||||
Validator validator = memberValidators.get( i );
|
|
||||||
if ( !validator.isValid( value ) ) {
|
|
||||||
results.add( new InvalidValue( interpolate(validator), beanClass, propertyName, value, null ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return results.toArray( new InvalidValue[results.size()] );
|
|
||||||
}
|
|
||||||
|
|
||||||
private Object getMemberValue(T bean, XMember getter) {
|
|
||||||
Object value;
|
|
||||||
try {
|
|
||||||
value = getter.invoke( bean );
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
throw new IllegalStateException( "Could not get property value", e );
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPropertyName(XMember member) {
|
|
||||||
//Do no try to cache the result in a map, it's actually much slower (2.x time)
|
|
||||||
String propertyName;
|
|
||||||
if ( XProperty.class.isAssignableFrom( member.getClass() ) ) {
|
|
||||||
propertyName = member.getName();
|
|
||||||
}
|
|
||||||
else if ( XMethod.class.isAssignableFrom( member.getClass() ) ) {
|
|
||||||
propertyName = member.getName();
|
|
||||||
if ( propertyName.startsWith( "is" ) ) {
|
|
||||||
propertyName = Introspector.decapitalize( propertyName.substring( 2 ) );
|
|
||||||
}
|
|
||||||
else if ( propertyName.startsWith( "get" ) ) {
|
|
||||||
propertyName = Introspector.decapitalize( propertyName.substring( 3 ) );
|
|
||||||
}
|
|
||||||
//do nothing for non getter method, in case someone want to validate a PO Method
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new AssertionFailure( "Unexpected member: " + member.getClass().getName() );
|
|
||||||
}
|
|
||||||
return propertyName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated */
|
|
||||||
private String replace(String message, Annotation parameters) {
|
|
||||||
StringTokenizer tokens = new StringTokenizer( message, "#{}", true );
|
|
||||||
StringBuilder buf = new StringBuilder( 30 );
|
|
||||||
boolean escaped = false;
|
|
||||||
boolean el = false;
|
|
||||||
while ( tokens.hasMoreTokens() ) {
|
|
||||||
String token = tokens.nextToken();
|
|
||||||
if ( !escaped && "#".equals( token ) ) {
|
|
||||||
el = true;
|
|
||||||
}
|
|
||||||
if ( !el && "{".equals( token ) ) {
|
|
||||||
escaped = true;
|
|
||||||
}
|
|
||||||
else if ( escaped && "}".equals( token ) ) {
|
|
||||||
escaped = false;
|
|
||||||
}
|
|
||||||
else if ( !escaped ) {
|
|
||||||
if ( "{".equals( token ) ) el = false;
|
|
||||||
buf.append( token );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Method member;
|
|
||||||
try {
|
|
||||||
member = parameters.getClass().getMethod( token, (Class[]) null );
|
|
||||||
}
|
|
||||||
catch (NoSuchMethodException nsfme) {
|
|
||||||
member = null;
|
|
||||||
}
|
|
||||||
if ( member != null ) {
|
|
||||||
try {
|
|
||||||
buf.append( member.invoke( parameters ) );
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
throw new IllegalArgumentException( "could not render message", e );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
String string = null;
|
|
||||||
try {
|
|
||||||
string = messageBundle != null ? messageBundle.getString( token ) : null;
|
|
||||||
}
|
|
||||||
catch( MissingResourceException e ) {
|
|
||||||
//give a second chance with the default resource bundle
|
|
||||||
}
|
|
||||||
if (string == null) {
|
|
||||||
try {
|
|
||||||
string = defaultMessageBundle.getString( token );
|
|
||||||
}
|
|
||||||
catch( MissingResourceException e) {
|
|
||||||
throw new MissingResourceException(
|
|
||||||
"Can't find resource in validator bundles, key " + token,
|
|
||||||
defaultMessageBundle.getClass().getName(),
|
|
||||||
token
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( string != null ) buf.append( replace( string, parameters ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return buf.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* apply the registred constraints rules on the hibernate metadata (to be applied on DB schema...)
|
|
||||||
*
|
|
||||||
* @param persistentClass hibernate metadata
|
|
||||||
*/
|
|
||||||
public void apply(PersistentClass persistentClass) {
|
|
||||||
|
|
||||||
for ( Validator validator : beanValidators ) {
|
|
||||||
if ( validator instanceof PersistentClassConstraint ) {
|
|
||||||
( (PersistentClassConstraint) validator ).apply( persistentClass );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Iterator<Validator> validators = memberValidators.iterator();
|
|
||||||
Iterator<XMember> getters = memberGetters.iterator();
|
|
||||||
while ( validators.hasNext() ) {
|
|
||||||
Validator validator = validators.next();
|
|
||||||
String propertyName = getPropertyName( getters.next() );
|
|
||||||
if ( validator instanceof PropertyConstraint ) {
|
|
||||||
try {
|
|
||||||
Property property = findPropertyByName(persistentClass, propertyName);
|
|
||||||
if (property != null) {
|
|
||||||
( (PropertyConstraint) validator ).apply( property );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (MappingException pnfe) {
|
|
||||||
//do nothing
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void assertValid(T bean) {
|
|
||||||
InvalidValue[] values = getInvalidValues( bean );
|
|
||||||
if ( values.length > 0 ) {
|
|
||||||
throw new InvalidStateException( values );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void writeObject(ObjectOutputStream oos) throws IOException {
|
|
||||||
ResourceBundle rb = messageBundle;
|
|
||||||
MessageInterpolator interpolator = this.userInterpolator;
|
|
||||||
if ( rb != null && ! ( rb instanceof Serializable ) ) {
|
|
||||||
messageBundle = null;
|
|
||||||
if ( ! isUserProvidedResourceBundle ) {
|
|
||||||
log.warn(
|
|
||||||
"Serializing a LibrePlanClassValidator with a non serializable ResourceBundle: ResourceBundle ignored"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (interpolator != null && ! (interpolator instanceof Serializable) ) {
|
|
||||||
userInterpolator = null;
|
|
||||||
log.warn( "Serializing a non serializable MessageInterpolator" );
|
|
||||||
}
|
|
||||||
oos.defaultWriteObject();
|
|
||||||
oos.writeObject( messageBundle );
|
|
||||||
oos.writeObject( userInterpolator );
|
|
||||||
messageBundle = rb;
|
|
||||||
userInterpolator = interpolator;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
|
|
||||||
ois.defaultReadObject();
|
|
||||||
ResourceBundle rb = (ResourceBundle) ois.readObject();
|
|
||||||
if ( rb == null ) rb = getDefaultResourceBundle();
|
|
||||||
this.messageBundle = rb;
|
|
||||||
this.userInterpolator = (MessageInterpolator) ois.readObject();
|
|
||||||
this.defaultMessageBundle = ResourceBundle.getBundle( DEFAULT_VALIDATOR_MESSAGE );
|
|
||||||
reflectionManager = new JavaReflectionManager();
|
|
||||||
initValidator( reflectionManager.toXClass( beanClass ), new HashMap<XClass, LibrePlanClassValidator>() );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve the property by path in a recursive way, including IndetifierProperty in the loop
|
|
||||||
* If propertyName is null or empty, the IdentifierProperty is returned
|
|
||||||
*/
|
|
||||||
public static Property findPropertyByName(PersistentClass associatedClass, String propertyName) {
|
|
||||||
Property property = null;
|
|
||||||
Property idProperty = associatedClass.getIdentifierProperty();
|
|
||||||
String idName = idProperty != null ? idProperty.getName() : null;
|
|
||||||
try {
|
|
||||||
if ( propertyName == null
|
|
||||||
|| propertyName.length() == 0
|
|
||||||
|| propertyName.equals( idName ) ) {
|
|
||||||
//default to id
|
|
||||||
property = idProperty;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if ( propertyName.indexOf( idName + "." ) == 0 ) {
|
|
||||||
property = idProperty;
|
|
||||||
propertyName = propertyName.substring( idName.length() + 1 );
|
|
||||||
}
|
|
||||||
StringTokenizer st = new StringTokenizer( propertyName, ".", false );
|
|
||||||
while ( st.hasMoreElements() ) {
|
|
||||||
String element = (String) st.nextElement();
|
|
||||||
if ( property == null ) {
|
|
||||||
property = associatedClass.getProperty( element );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if ( ! property.isComposite() ) return null;
|
|
||||||
property = ( (Component) property.getValue() ).getProperty( element );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (MappingException e) {
|
|
||||||
try {
|
|
||||||
//if we do not find it try to check the identifier mapper
|
|
||||||
if ( associatedClass.getIdentifierMapper() == null ) return null;
|
|
||||||
StringTokenizer st = new StringTokenizer( propertyName, ".", false );
|
|
||||||
while ( st.hasMoreElements() ) {
|
|
||||||
String element = (String) st.nextElement();
|
|
||||||
if ( property == null ) {
|
|
||||||
property = associatedClass.getIdentifierMapper().getProperty( element );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if ( ! property.isComposite() ) return null;
|
|
||||||
property = ( (Component) property.getValue() ).getProperty( element );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (MappingException ee) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return property;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -35,7 +35,7 @@ import org.libreplan.business.i18n.I18nHelper;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.config.BeanDefinition;
|
import org.springframework.beans.factory.config.BeanDefinition;
|
||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
import org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException;
|
import org.springframework.orm.hibernate4.HibernateOptimisticLockingFailureException;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
import org.springframework.transaction.annotation.Propagation;
|
import org.springframework.transaction.annotation.Propagation;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
|
||||||
|
|
@ -22,10 +22,10 @@
|
||||||
package org.libreplan.business.common.entities;
|
package org.libreplan.business.common.entities;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.hibernate.validator.AssertTrue;
|
import javax.validation.constraints.AssertTrue;
|
||||||
import org.hibernate.validator.Min;
|
import javax.validation.constraints.Min;
|
||||||
import org.hibernate.validator.NotEmpty;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.libreplan.business.calendars.entities.BaseCalendar;
|
import org.libreplan.business.calendars.entities.BaseCalendar;
|
||||||
import org.libreplan.business.common.BaseEntity;
|
import org.libreplan.business.common.BaseEntity;
|
||||||
import org.libreplan.business.costcategories.entities.TypeOfWorkHours;
|
import org.libreplan.business.costcategories.entities.TypeOfWorkHours;
|
||||||
|
|
@ -155,7 +155,7 @@ public class Configuration extends BaseEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "company code cannot contain whitespaces")
|
@AssertTrue(message = "company code cannot contain whitespaces")
|
||||||
public boolean checkConstraintCompanyCodeWithoutWhiteSpaces() {
|
public boolean isCompanyCodeWithoutWhiteSpacesConstraint() {
|
||||||
if ((companyCode == null) || (companyCode.isEmpty())) {
|
if ((companyCode == null) || (companyCode.isEmpty())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -163,7 +163,7 @@ public class Configuration extends BaseEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "host not specified")
|
@AssertTrue(message = "host not specified")
|
||||||
public boolean checkConstraintLdapHostWithoutWhiteSpaces() {
|
public boolean isLdapHostWithoutWhiteSpacesConstraint() {
|
||||||
if (getLdapConfiguration().getLdapAuthEnabled()) {
|
if (getLdapConfiguration().getLdapAuthEnabled()) {
|
||||||
if (StringUtils.isBlank(getLdapConfiguration().getLdapHost())) {
|
if (StringUtils.isBlank(getLdapConfiguration().getLdapHost())) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -173,7 +173,7 @@ public class Configuration extends BaseEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "port not specified")
|
@AssertTrue(message = "port not specified")
|
||||||
public boolean checkConstraintLdapPortWithoutWhiteSpaces() {
|
public boolean isLdapPortWithoutWhiteSpacesConstraint() {
|
||||||
if (getLdapConfiguration().getLdapAuthEnabled()) {
|
if (getLdapConfiguration().getLdapAuthEnabled()) {
|
||||||
if (StringUtils.isBlank(getLdapConfiguration().getLdapPort())) {
|
if (StringUtils.isBlank(getLdapConfiguration().getLdapPort())) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -183,7 +183,7 @@ public class Configuration extends BaseEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "base not specified")
|
@AssertTrue(message = "base not specified")
|
||||||
public boolean checkConstraintLdapBaseWithoutWhiteSpaces() {
|
public boolean isLdapBaseWithoutWhiteSpacesConstraint() {
|
||||||
if (getLdapConfiguration().getLdapAuthEnabled()) {
|
if (getLdapConfiguration().getLdapAuthEnabled()) {
|
||||||
if (StringUtils.isBlank(getLdapConfiguration().getLdapBase())) {
|
if (StringUtils.isBlank(getLdapConfiguration().getLdapBase())) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -193,7 +193,7 @@ public class Configuration extends BaseEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "userId not specified")
|
@AssertTrue(message = "userId not specified")
|
||||||
public boolean checkConstraintLdapUserIdWithoutWhiteSpaces() {
|
public boolean isLdapUserIdWithoutWhiteSpacesConstraint() {
|
||||||
if (getLdapConfiguration().getLdapAuthEnabled()) {
|
if (getLdapConfiguration().getLdapAuthEnabled()) {
|
||||||
if (StringUtils.isBlank(getLdapConfiguration().getLdapUserId())) {
|
if (StringUtils.isBlank(getLdapConfiguration().getLdapUserId())) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
package org.libreplan.business.common.entities;
|
package org.libreplan.business.common.entities;
|
||||||
|
|
||||||
import org.hibernate.validator.NotEmpty;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class which is used to store the configuration of the matching between the
|
* A class which is used to store the configuration of the matching between the
|
||||||
|
|
|
||||||
|
|
@ -28,9 +28,9 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.hibernate.validator.AssertTrue;
|
import javax.validation.constraints.AssertTrue;
|
||||||
import org.hibernate.validator.NotEmpty;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
import org.hibernate.validator.Valid;
|
import javax.validation.Valid;
|
||||||
import org.libreplan.business.common.BaseEntity;
|
import org.libreplan.business.common.BaseEntity;
|
||||||
import org.libreplan.business.common.Registry;
|
import org.libreplan.business.common.Registry;
|
||||||
import org.libreplan.business.common.daos.IConnectorDAO;
|
import org.libreplan.business.common.daos.IConnectorDAO;
|
||||||
|
|
@ -98,7 +98,7 @@ public class Connector extends BaseEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "connector name is already being used")
|
@AssertTrue(message = "connector name is already being used")
|
||||||
public boolean checkConstraintUniqueConnectorName() {
|
public boolean isUniqueConnectorNameConstraint() {
|
||||||
if (StringUtils.isBlank(name)) {
|
if (StringUtils.isBlank(name)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
package org.libreplan.business.common.entities;
|
package org.libreplan.business.common.entities;
|
||||||
|
|
||||||
import org.hibernate.validator.NotEmpty;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is intended to work as a Hibernate component. It's formed by two
|
* This class is intended to work as a Hibernate component. It's formed by two
|
||||||
|
|
|
||||||
|
|
@ -25,9 +25,9 @@ import java.text.DecimalFormat;
|
||||||
import java.text.NumberFormat;
|
import java.text.NumberFormat;
|
||||||
|
|
||||||
import org.hibernate.NonUniqueResultException;
|
import org.hibernate.NonUniqueResultException;
|
||||||
import org.hibernate.validator.AssertTrue;
|
import javax.validation.constraints.AssertTrue;
|
||||||
import org.hibernate.validator.NotEmpty;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.libreplan.business.common.BaseEntity;
|
import org.libreplan.business.common.BaseEntity;
|
||||||
import org.libreplan.business.common.IntegrationEntity;
|
import org.libreplan.business.common.IntegrationEntity;
|
||||||
import org.libreplan.business.common.Registry;
|
import org.libreplan.business.common.Registry;
|
||||||
|
|
@ -104,7 +104,7 @@ public class EntitySequence extends BaseEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "Prefix cannot contain whitespaces")
|
@AssertTrue(message = "Prefix cannot contain whitespaces")
|
||||||
public boolean checkConstraintPrefixWithoutWhiteSpaces() {
|
public boolean isPrefixWithoutWhiteSpacesConstraint() {
|
||||||
if ((prefix == null) || (prefix.isEmpty())) {
|
if ((prefix == null) || (prefix.isEmpty())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -143,7 +143,7 @@ public class EntitySequence extends BaseEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "number of digits out of range")
|
@AssertTrue(message = "number of digits out of range")
|
||||||
public boolean checkConstraintNumberOfDigitsInRange() {
|
public boolean isNumberOfDigitsInRangeConstraint() {
|
||||||
if ((numberOfDigits != null)
|
if ((numberOfDigits != null)
|
||||||
&& (numberOfDigits >= MIN_NUMBER_OF_DIGITS)
|
&& (numberOfDigits >= MIN_NUMBER_OF_DIGITS)
|
||||||
&& (numberOfDigits <= MAX_NUMBER_OF_DIGITS)) {
|
&& (numberOfDigits <= MAX_NUMBER_OF_DIGITS)) {
|
||||||
|
|
@ -153,7 +153,7 @@ public class EntitySequence extends BaseEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "format sequence code invalid. It must not contain '_'")
|
@AssertTrue(message = "format sequence code invalid. It must not contain '_'")
|
||||||
public boolean checkConstraintWithoutLowBar() {
|
public boolean isWithoutLowBarConstraint() {
|
||||||
if ((prefix == null) || (prefix.isEmpty())) {
|
if ((prefix == null) || (prefix.isEmpty())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -199,7 +199,7 @@ public class EntitySequence extends BaseEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "Only one sequence per entity can be active at the same time.")
|
@AssertTrue(message = "Only one sequence per entity can be active at the same time.")
|
||||||
public boolean checkConstraintOnlyOneSequenceForEachEntityIsActive() {
|
public boolean isOnlyOneSequenceForEachEntityIsActiveConstraint() {
|
||||||
if (!isActive()) {
|
if (!isActive()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,8 @@
|
||||||
package org.libreplan.business.common.entities;
|
package org.libreplan.business.common.entities;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.hibernate.validator.AssertTrue;
|
import javax.validation.constraints.AssertTrue;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.libreplan.business.common.BaseEntity;
|
import org.libreplan.business.common.BaseEntity;
|
||||||
import org.libreplan.business.common.IHumanIdentifiable;
|
import org.libreplan.business.common.IHumanIdentifiable;
|
||||||
import org.libreplan.business.common.Registry;
|
import org.libreplan.business.common.Registry;
|
||||||
|
|
@ -121,7 +121,7 @@ public class JobSchedulerConfiguration extends BaseEntity implements
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "job group and name are already being used")
|
@AssertTrue(message = "job group and name are already being used")
|
||||||
public boolean checkConstraintUniqueJobGroupAndName() {
|
public boolean isUniqueJobGroupAndNameConstraint() {
|
||||||
if (StringUtils.isBlank(jobGroup) && StringUtils.isBlank(jobName)) {
|
if (StringUtils.isBlank(jobGroup) && StringUtils.isBlank(jobName)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,16 @@
|
||||||
|
|
||||||
package org.libreplan.business.common.exceptions;
|
package org.libreplan.business.common.exceptions;
|
||||||
|
|
||||||
|
import static java.util.Collections.singleton;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.validation.ConstraintViolation;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.hibernate.validator.InvalidValue;
|
|
||||||
import org.libreplan.business.common.BaseEntity;
|
import org.libreplan.business.common.BaseEntity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -32,23 +40,114 @@ import org.libreplan.business.common.BaseEntity;
|
||||||
*/
|
*/
|
||||||
public class ValidationException extends RuntimeException {
|
public class ValidationException extends RuntimeException {
|
||||||
|
|
||||||
|
public static abstract class InvalidValue {
|
||||||
|
|
||||||
|
public abstract String getMessage();
|
||||||
|
|
||||||
|
public abstract String getPropertyPath();
|
||||||
|
|
||||||
|
public abstract Object getInvalidValue();
|
||||||
|
|
||||||
|
public abstract Object getRootBean();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class BasedOnConstraintViolation extends InvalidValue {
|
||||||
|
|
||||||
|
private ConstraintViolation<?> violation;
|
||||||
|
|
||||||
|
public BasedOnConstraintViolation(ConstraintViolation<?> violation) {
|
||||||
|
Validate.notNull(violation);
|
||||||
|
this.violation = violation;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMessage() {
|
||||||
|
return violation.getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPropertyPath() {
|
||||||
|
if (violation.getPropertyPath() == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return violation.getPropertyPath().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getRootBean() {
|
||||||
|
return violation.getRootBean();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getInvalidValue() {
|
||||||
|
return violation.getInvalidValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class InstantiatedInvalidValue extends InvalidValue {
|
||||||
|
|
||||||
|
private final String message;
|
||||||
|
private final String propertyPath;
|
||||||
|
private final Object invalidValue;
|
||||||
|
private final Object rootBean;
|
||||||
|
|
||||||
|
private InstantiatedInvalidValue(String message, String propertyPath,
|
||||||
|
Object invalidValue, Object rootBean) {
|
||||||
|
super();
|
||||||
|
this.message = message;
|
||||||
|
this.propertyPath = propertyPath;
|
||||||
|
this.invalidValue = invalidValue;
|
||||||
|
this.rootBean = rootBean;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPropertyPath() {
|
||||||
|
return propertyPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getInvalidValue() {
|
||||||
|
return invalidValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getRootBean() {
|
||||||
|
return rootBean;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static String getValidationErrorSummary(
|
private static String getValidationErrorSummary(
|
||||||
InvalidValue... invalidValues) {
|
Collection<? extends InvalidValue> violations) {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
for (InvalidValue each : invalidValues) {
|
for (InvalidValue each : violations) {
|
||||||
builder.append(summaryFor(each));
|
builder.append(summaryFor(each));
|
||||||
builder.append("; ");
|
builder.append("; ");
|
||||||
}
|
}
|
||||||
if (invalidValues.length > 0) {
|
if (builder.length() > 0) {
|
||||||
builder.delete(builder.length() - 2, builder.length());
|
builder.delete(builder.length() - 2, builder.length());
|
||||||
}
|
}
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String summaryFor(InvalidValue invalidValue) {
|
private static String summaryFor(InvalidValue invalid) {
|
||||||
return "at " + asString(invalidValue.getBean()) + " "
|
Object bean = invalid.getRootBean();
|
||||||
+ invalidValue.getPropertyPath() + ": "
|
Object propertyPath = invalid.getPropertyPath();
|
||||||
+ invalidValue.getMessage();
|
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
if (bean != null) {
|
||||||
|
builder = builder.append("at ").append(asString(bean));
|
||||||
|
if (propertyPath != null) {
|
||||||
|
builder = builder.append(" ").append(propertyPath).append(": ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return builder.append(invalid.getMessage()).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String asString(Object bean) {
|
private static String asString(Object bean) {
|
||||||
|
|
@ -64,61 +163,90 @@ public class ValidationException extends RuntimeException {
|
||||||
return bean.toString();
|
return bean.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ValidationException invalidValue(String message, Object value) {
|
public static ValidationException invalidValueException(String message,
|
||||||
InvalidValue invalidValue = new InvalidValue(message, null, "", value,
|
Object bean) {
|
||||||
null);
|
return new ValidationException(invalidValue(message, bean));
|
||||||
return new ValidationException(invalidValue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private InvalidValue[] invalidValues;
|
private static InvalidValue invalidValue(String message, Object bean) {
|
||||||
|
return invalidValue(message, null, null, bean);
|
||||||
|
}
|
||||||
|
|
||||||
public InvalidValue[] getInvalidValues() {
|
public static InvalidValue invalidValue(String message,
|
||||||
return invalidValues.clone();
|
String propertyPath, Object invalidValue, Object rootBean) {
|
||||||
|
return new InstantiatedInvalidValue(message, propertyPath,
|
||||||
|
invalidValue, rootBean);
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Set<? extends InvalidValue> invalidValues;
|
||||||
|
|
||||||
|
public Set<? extends InvalidValue> getInvalidValues() {
|
||||||
|
return invalidValues;
|
||||||
}
|
}
|
||||||
|
|
||||||
public InvalidValue getInvalidValue() {
|
public InvalidValue getInvalidValue() {
|
||||||
return (invalidValues.length > 0) ? invalidValues.clone()[0] : null;
|
return invalidValues.isEmpty() ? null : invalidValues.iterator().next();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ValidationException(ConstraintViolation<?> violation) {
|
||||||
|
super(getValidationErrorSummary(convert(violation)));
|
||||||
|
this.invalidValues = convert(violation);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ValidationException(InvalidValue invalidValue) {
|
public ValidationException(InvalidValue invalidValue) {
|
||||||
super(getValidationErrorSummary(invalidValue));
|
super(getValidationErrorSummary(singleton(invalidValue)));
|
||||||
storeInvalidValues(toArray(invalidValue));
|
this.invalidValues = singleton(invalidValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
private InvalidValue[] toArray(InvalidValue invalidValue) {
|
public ValidationException(Collection<? extends InvalidValue> invalidValues) {
|
||||||
InvalidValue[] result = new InvalidValue[1];
|
|
||||||
result[0] = invalidValue;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ValidationException(InvalidValue[] invalidValues) {
|
|
||||||
super(getValidationErrorSummary(invalidValues));
|
super(getValidationErrorSummary(invalidValues));
|
||||||
storeInvalidValues(invalidValues);
|
this.invalidValues = new HashSet<InvalidValue>(invalidValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void storeInvalidValues(InvalidValue[] invalidValues) {
|
public ValidationException(String message, InvalidValue invalidValue) {
|
||||||
Validate.noNullElements(invalidValues);
|
super(message);
|
||||||
this.invalidValues = invalidValues.clone();
|
this.invalidValues = singleton(invalidValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ValidationException(InvalidValue[] invalidValues, String message,
|
private static Set<? extends InvalidValue> convert(
|
||||||
|
ConstraintViolation<?> violation) {
|
||||||
|
return Collections.singleton(new BasedOnConstraintViolation(violation));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Set<? extends InvalidValue> convert(
|
||||||
|
Collection<? extends ConstraintViolation<?>> violations) {
|
||||||
|
Set<InvalidValue> result = new HashSet<InvalidValue>();
|
||||||
|
for (ConstraintViolation<?> each : violations) {
|
||||||
|
result.add(new BasedOnConstraintViolation(each));
|
||||||
|
}
|
||||||
|
return Collections.unmodifiableSet(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ValidationException(Set<? extends ConstraintViolation<?>> violations) {
|
||||||
|
super(getValidationErrorSummary(convert(violations)));
|
||||||
|
this.invalidValues = convert(violations);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public ValidationException(
|
||||||
|
Set<? extends ConstraintViolation<?>> violations, String message,
|
||||||
Throwable cause) {
|
Throwable cause) {
|
||||||
super(message, cause);
|
super(message, cause);
|
||||||
storeInvalidValues(invalidValues);
|
this.invalidValues = convert(violations);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ValidationException(InvalidValue[] invalidValues, String message) {
|
public ValidationException(Set<? extends ConstraintViolation<?>> violations, String message) {
|
||||||
super(message);
|
super(message);
|
||||||
storeInvalidValues(invalidValues);
|
this.invalidValues = convert(violations);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ValidationException(InvalidValue[] invalidValues, Throwable cause) {
|
public ValidationException(
|
||||||
super(cause);
|
Set<? extends ConstraintViolation<?>> violations, Throwable cause) {
|
||||||
storeInvalidValues(invalidValues);
|
this(violations, getValidationErrorSummary(convert(violations)), cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ValidationException(String message) {
|
public ValidationException(String message) {
|
||||||
this(new InvalidValue[] {}, message);
|
this(Collections.<ConstraintViolation<?>> emptySet(), message);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -165,7 +165,7 @@ public class TypeOfWorkHoursDAO extends IntegrationEntityDAO<TypeOfWorkHours>
|
||||||
.add(Restrictions.eq("typeOfWorkHours", type)).list();
|
.add(Restrictions.eq("typeOfWorkHours", type)).list();
|
||||||
if (!workReportLines.isEmpty()) {
|
if (!workReportLines.isEmpty()) {
|
||||||
throw ValidationException
|
throw ValidationException
|
||||||
.invalidValue(
|
.invalidValueException(
|
||||||
"Cannot delete type of work hours. It is being used at this moment in some timesheet line.",
|
"Cannot delete type of work hours. It is being used at this moment in some timesheet line.",
|
||||||
type);
|
type);
|
||||||
}
|
}
|
||||||
|
|
@ -176,7 +176,7 @@ public class TypeOfWorkHoursDAO extends IntegrationEntityDAO<TypeOfWorkHours>
|
||||||
.add(Restrictions.eq("type", type)).list();
|
.add(Restrictions.eq("type", type)).list();
|
||||||
if (!hoursCost.isEmpty()) {
|
if (!hoursCost.isEmpty()) {
|
||||||
throw ValidationException
|
throw ValidationException
|
||||||
.invalidValue(
|
.invalidValueException(
|
||||||
"Cannot delete type of work hours. It is being used at this moment in some cost category.",
|
"Cannot delete type of work hours. It is being used at this moment in some cost category.",
|
||||||
type);
|
type);
|
||||||
}
|
}
|
||||||
|
|
@ -187,7 +187,7 @@ public class TypeOfWorkHoursDAO extends IntegrationEntityDAO<TypeOfWorkHours>
|
||||||
if (configuration.getPersonalTimesheetsTypeOfWorkHours().getId()
|
if (configuration.getPersonalTimesheetsTypeOfWorkHours().getId()
|
||||||
.equals(type.getId())) {
|
.equals(type.getId())) {
|
||||||
throw ValidationException
|
throw ValidationException
|
||||||
.invalidValue(
|
.invalidValueException(
|
||||||
"Cannot delete the type of work hours. It is configured as type of work hours for personal timesheets.",
|
"Cannot delete the type of work hours. It is configured as type of work hours for personal timesheets.",
|
||||||
type);
|
type);
|
||||||
}
|
}
|
||||||
|
|
@ -208,7 +208,7 @@ public class TypeOfWorkHoursDAO extends IntegrationEntityDAO<TypeOfWorkHours>
|
||||||
PredefinedConnectorProperties.JIRA_HOURS_TYPE);
|
PredefinedConnectorProperties.JIRA_HOURS_TYPE);
|
||||||
if (name.equals(type.getName())) {
|
if (name.equals(type.getName())) {
|
||||||
throw ValidationException
|
throw ValidationException
|
||||||
.invalidValue(
|
.invalidValueException(
|
||||||
"Cannot delete the type of work hours. It is configured as type of work hours for JIRA connector.",
|
"Cannot delete the type of work hours. It is configured as type of work hours for JIRA connector.",
|
||||||
type);
|
type);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,12 +29,13 @@ import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import javax.validation.constraints.AssertFalse;
|
||||||
|
import javax.validation.constraints.AssertTrue;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.hibernate.validator.AssertFalse;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
import org.hibernate.validator.AssertTrue;
|
|
||||||
import org.hibernate.validator.NotEmpty;
|
|
||||||
import org.hibernate.validator.NotNull;
|
|
||||||
import org.hibernate.validator.Valid;
|
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
import org.libreplan.business.common.IHumanIdentifiable;
|
import org.libreplan.business.common.IHumanIdentifiable;
|
||||||
import org.libreplan.business.common.IntegrationEntity;
|
import org.libreplan.business.common.IntegrationEntity;
|
||||||
|
|
@ -106,7 +107,7 @@ public class CostCategory extends IntegrationEntity implements IHumanIdentifiabl
|
||||||
|| listHourCosts.get(i).getType() == null) {
|
|| listHourCosts.get(i).getType() == null) {
|
||||||
// this is not exactly an overlapping but a
|
// this is not exactly an overlapping but a
|
||||||
// problem with missing compulsory fields
|
// problem with missing compulsory fields
|
||||||
throw ValidationException.invalidValue(
|
throw ValidationException.invalidValueException(
|
||||||
"Hours cost type cannot be empty",
|
"Hours cost type cannot be empty",
|
||||||
listElement);
|
listElement);
|
||||||
}
|
}
|
||||||
|
|
@ -115,12 +116,12 @@ public class CostCategory extends IntegrationEntity implements IHumanIdentifiabl
|
||||||
if (initDate == null || listElement.getInitDate() == null) {
|
if (initDate == null || listElement.getInitDate() == null) {
|
||||||
// this is not exactly an overlapping but a
|
// this is not exactly an overlapping but a
|
||||||
// problem with missing compulsory fields
|
// problem with missing compulsory fields
|
||||||
throw ValidationException.invalidValue(
|
throw ValidationException.invalidValueException(
|
||||||
"Init date cannot be empty",
|
"Init date cannot be empty",
|
||||||
listElement);
|
listElement);
|
||||||
}
|
}
|
||||||
if (endDate == null && listElement.getEndDate() == null) {
|
if (endDate == null && listElement.getEndDate() == null) {
|
||||||
throw ValidationException.invalidValue(
|
throw ValidationException.invalidValueException(
|
||||||
"End date cannot be empty",
|
"End date cannot be empty",
|
||||||
listElement);
|
listElement);
|
||||||
} else if ((endDate == null && listElement.getEndDate()
|
} else if ((endDate == null && listElement.getEndDate()
|
||||||
|
|
@ -128,7 +129,7 @@ public class CostCategory extends IntegrationEntity implements IHumanIdentifiabl
|
||||||
|| (listElement.getEndDate() == null && listElement
|
|| (listElement.getEndDate() == null && listElement
|
||||||
.getInitDate().compareTo(endDate) <= 0)) {
|
.getInitDate().compareTo(endDate) <= 0)) {
|
||||||
throw ValidationException
|
throw ValidationException
|
||||||
.invalidValue(
|
.invalidValueException(
|
||||||
_("Two Hour Cost of the same type overlap in time"),
|
_("Two Hour Cost of the same type overlap in time"),
|
||||||
listElement);
|
listElement);
|
||||||
} else if ((endDate != null && listElement.getEndDate() != null)
|
} else if ((endDate != null && listElement.getEndDate() != null)
|
||||||
|
|
@ -137,7 +138,7 @@ public class CostCategory extends IntegrationEntity implements IHumanIdentifiabl
|
||||||
.getInitDate().compareTo(initDate) >= 0 && listElement
|
.getInitDate().compareTo(initDate) >= 0 && listElement
|
||||||
.getInitDate().compareTo(endDate) <= 0))) {
|
.getInitDate().compareTo(endDate) <= 0))) {
|
||||||
throw ValidationException
|
throw ValidationException
|
||||||
.invalidValue(
|
.invalidValueException(
|
||||||
_("Two Hour Cost of the same type overlap in time"),
|
_("Two Hour Cost of the same type overlap in time"),
|
||||||
listElement);
|
listElement);
|
||||||
}
|
}
|
||||||
|
|
@ -156,12 +157,18 @@ public class CostCategory extends IntegrationEntity implements IHumanIdentifiabl
|
||||||
ResourcesCostCategoryAssignment costCategory = costCategoryAssignments
|
ResourcesCostCategoryAssignment costCategory = costCategoryAssignments
|
||||||
.get(j);
|
.get(j);
|
||||||
if (endDate == null && costCategory.getEndDate() == null) {
|
if (endDate == null && costCategory.getEndDate() == null) {
|
||||||
throw ValidationException.invalidValue(_("Some cost category assignments overlap in time"), costCategory);
|
throw ValidationException
|
||||||
|
.invalidValueException(
|
||||||
|
_("Some cost category assignments overlap in time"),
|
||||||
|
costCategory);
|
||||||
} else if ((endDate == null && costCategory.getEndDate()
|
} else if ((endDate == null && costCategory.getEndDate()
|
||||||
.compareTo(initDate) >= 0)
|
.compareTo(initDate) >= 0)
|
||||||
|| (costCategory.getEndDate() == null && costCategory
|
|| (costCategory.getEndDate() == null && costCategory
|
||||||
.getInitDate().compareTo(endDate) <= 0)) {
|
.getInitDate().compareTo(endDate) <= 0)) {
|
||||||
throw ValidationException.invalidValue(_("Some cost category assignments overlap in time"), costCategory);
|
throw ValidationException
|
||||||
|
.invalidValueException(
|
||||||
|
_("Some cost category assignments overlap in time"),
|
||||||
|
costCategory);
|
||||||
} else if ((endDate != null && costCategory.getEndDate() != null)
|
} else if ((endDate != null && costCategory.getEndDate() != null)
|
||||||
&& ((costCategory.getEndDate().compareTo(initDate) >= 0 && // (1)
|
&& ((costCategory.getEndDate().compareTo(initDate) >= 0 && // (1)
|
||||||
// listElement.getEndDate()
|
// listElement.getEndDate()
|
||||||
|
|
@ -181,7 +188,10 @@ public class CostCategory extends IntegrationEntity implements IHumanIdentifiabl
|
||||||
costCategory.getEndDate().compareTo(endDate) >= 0))) { // contains
|
costCategory.getEndDate().compareTo(endDate) >= 0))) { // contains
|
||||||
// [initDate,
|
// [initDate,
|
||||||
// endDate]
|
// endDate]
|
||||||
throw ValidationException.invalidValue(_("Some cost category assignments overlap in time"), costCategory);
|
throw ValidationException
|
||||||
|
.invalidValueException(
|
||||||
|
_("Some cost category assignments overlap in time"),
|
||||||
|
costCategory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -269,7 +279,7 @@ public class CostCategory extends IntegrationEntity implements IHumanIdentifiabl
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertFalse(message="Two Hour Cost of the same type overlap in time")
|
@AssertFalse(message="Two Hour Cost of the same type overlap in time")
|
||||||
public boolean checkHourCostsOverlap() {
|
public boolean isHourCostsOverlapConstraint() {
|
||||||
try {
|
try {
|
||||||
validateHourCostsOverlap(getHourCosts());
|
validateHourCostsOverlap(getHourCosts());
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -284,7 +294,7 @@ public class CostCategory extends IntegrationEntity implements IHumanIdentifiabl
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "The hour cost codes must be unique.")
|
@AssertTrue(message = "The hour cost codes must be unique.")
|
||||||
public boolean checkConstraintNonRepeatedHourCostCodes() {
|
public boolean isNonRepeatedHourCostCodesConstraint() {
|
||||||
return getFirstRepeatedCode(this.hourCosts) == null;
|
return getFirstRepeatedCode(this.hourCosts) == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -337,7 +347,7 @@ public class CostCategory extends IntegrationEntity implements IHumanIdentifiabl
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "the cost category name has to be unique and it is already in use")
|
@AssertTrue(message = "the cost category name has to be unique and it is already in use")
|
||||||
public boolean checkConstraintUniqueName() {
|
public boolean isUniqueNameConstraint() {
|
||||||
if (StringUtils.isBlank(name)) {
|
if (StringUtils.isBlank(name)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,8 @@ package org.libreplan.business.costcategories.entities;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
import org.hibernate.validator.AssertTrue;
|
import javax.validation.constraints.AssertTrue;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
import org.libreplan.business.common.IntegrationEntity;
|
import org.libreplan.business.common.IntegrationEntity;
|
||||||
import org.libreplan.business.common.Registry;
|
import org.libreplan.business.common.Registry;
|
||||||
|
|
@ -151,7 +151,7 @@ public class HourCost extends IntegrationEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message="The end date cannot be before the start date")
|
@AssertTrue(message="The end date cannot be before the start date")
|
||||||
public boolean checkPositiveTimeInterval() {
|
public boolean isPositiveTimeIntervalConstraint() {
|
||||||
if (initDate == null) {
|
if (initDate == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,8 @@
|
||||||
package org.libreplan.business.costcategories.entities;
|
package org.libreplan.business.costcategories.entities;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.hibernate.validator.AssertTrue;
|
import javax.validation.constraints.AssertTrue;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
import org.libreplan.business.common.IntegrationEntity;
|
import org.libreplan.business.common.IntegrationEntity;
|
||||||
import org.libreplan.business.common.Registry;
|
import org.libreplan.business.common.Registry;
|
||||||
|
|
@ -143,7 +143,7 @@ public class ResourcesCostCategoryAssignment extends IntegrationEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message="cost assignment with end date before start date")
|
@AssertTrue(message="cost assignment with end date before start date")
|
||||||
public boolean checkConstraintPositiveTimeInterval() {
|
public boolean isPositiveTimeInterval() {
|
||||||
|
|
||||||
/* Check if it makes sense to check the constraint .*/
|
/* Check if it makes sense to check the constraint .*/
|
||||||
if (!isInitDateSpecified()) {
|
if (!isInitDateSpecified()) {
|
||||||
|
|
|
||||||
|
|
@ -24,9 +24,9 @@ package org.libreplan.business.costcategories.entities;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.hibernate.validator.AssertTrue;
|
import javax.validation.constraints.AssertTrue;
|
||||||
import org.hibernate.validator.NotEmpty;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.libreplan.business.common.IHumanIdentifiable;
|
import org.libreplan.business.common.IHumanIdentifiable;
|
||||||
import org.libreplan.business.common.IntegrationEntity;
|
import org.libreplan.business.common.IntegrationEntity;
|
||||||
import org.libreplan.business.common.Registry;
|
import org.libreplan.business.common.Registry;
|
||||||
|
|
@ -126,7 +126,7 @@ public class TypeOfWorkHours extends IntegrationEntity implements IHumanIdentifi
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "the type of work hours name has to be unique. It is already used")
|
@AssertTrue(message = "the type of work hours name has to be unique. It is already used")
|
||||||
public boolean checkConstraintUniqueName() {
|
public boolean isUniqueNameConstraint() {
|
||||||
|
|
||||||
if (StringUtils.isBlank(name)) {
|
if (StringUtils.isBlank(name)) {
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -147,7 +147,7 @@ public class TypeOfWorkHours extends IntegrationEntity implements IHumanIdentifi
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "type of work hours for personal timesheets cannot be disabled")
|
@AssertTrue(message = "type of work hours for personal timesheets cannot be disabled")
|
||||||
public boolean checkPersonalTimesheetsTypeOfWorkHoursNotDisabled() {
|
public boolean isPersonalTimesheetsTypeOfWorkHoursNotDisabledConstraint() {
|
||||||
if (!isNewObject() && !getEnabled()) {
|
if (!isNewObject() && !getEnabled()) {
|
||||||
TypeOfWorkHours typeOfWorkHours = Registry.getConfigurationDAO()
|
TypeOfWorkHours typeOfWorkHours = Registry.getConfigurationDAO()
|
||||||
.getConfiguration().getPersonalTimesheetsTypeOfWorkHours();
|
.getConfiguration().getPersonalTimesheetsTypeOfWorkHours();
|
||||||
|
|
@ -169,7 +169,7 @@ public class TypeOfWorkHours extends IntegrationEntity implements IHumanIdentifi
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "type of work hours for JIRA connector cannot be disabled")
|
@AssertTrue(message = "type of work hours for JIRA connector cannot be disabled")
|
||||||
public boolean checkJiraConnectorTypeOfWorkHoursNotDisabled() {
|
public boolean isJiraConnectorTypeOfWorkHoursNotDisabledConstraint() {
|
||||||
if (!isNewObject() && !getEnabled()) {
|
if (!isNewObject() && !getEnabled()) {
|
||||||
Connector connector = Registry.getConnectorDAO().findUniqueByName(
|
Connector connector = Registry.getConnectorDAO().findUniqueByName(
|
||||||
PredefinedConnectors.JIRA.getName());
|
PredefinedConnectors.JIRA.getName());
|
||||||
|
|
|
||||||
|
|
@ -25,11 +25,11 @@ import java.util.SortedSet;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.hibernate.validator.AssertTrue;
|
import javax.validation.constraints.AssertTrue;
|
||||||
import org.hibernate.validator.Min;
|
import javax.validation.constraints.Min;
|
||||||
import org.hibernate.validator.NotEmpty;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.hibernate.validator.Valid;
|
import javax.validation.Valid;
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
import org.libreplan.business.common.IHumanIdentifiable;
|
import org.libreplan.business.common.IHumanIdentifiable;
|
||||||
import org.libreplan.business.common.IntegrationEntity;
|
import org.libreplan.business.common.IntegrationEntity;
|
||||||
|
|
@ -138,7 +138,7 @@ public class ExpenseSheet extends IntegrationEntity implements IHumanIdentifiabl
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "The expense sheet line codes must be unique.")
|
@AssertTrue(message = "The expense sheet line codes must be unique.")
|
||||||
public boolean checkConstraintNonRepeatedExpenseSheetLinesCodes() {
|
public boolean isNonRepeatedExpenseSheetLinesCodesConstraint() {
|
||||||
return getFirstRepeatedCode(this.expenseSheetLines) == null;
|
return getFirstRepeatedCode(this.expenseSheetLines) == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -239,7 +239,7 @@ public class ExpenseSheet extends IntegrationEntity implements IHumanIdentifiabl
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "a personal expense sheet must have the same resource in all the lines")
|
@AssertTrue(message = "a personal expense sheet must have the same resource in all the lines")
|
||||||
public boolean checkConstraintPersonalExpenseSheetMustHaveTheSameResourceInAllLines() {
|
public boolean isPersonalExpenseSheetMustHaveTheSameResourceInAllLinesConstraint() {
|
||||||
if (!personal) {
|
if (!personal) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,8 @@ package org.libreplan.business.expensesheet.entities;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
import org.hibernate.validator.Min;
|
import javax.validation.constraints.Min;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
import org.libreplan.business.common.IntegrationEntity;
|
import org.libreplan.business.common.IntegrationEntity;
|
||||||
import org.libreplan.business.common.Registry;
|
import org.libreplan.business.common.Registry;
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,8 @@ package org.libreplan.business.externalcompanies.entities;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import org.hibernate.validator.NotEmpty;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.libreplan.business.common.BaseEntity;
|
import org.libreplan.business.common.BaseEntity;
|
||||||
import org.libreplan.business.orders.entities.Order;
|
import org.libreplan.business.orders.entities.Order;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,8 @@
|
||||||
package org.libreplan.business.externalcompanies.entities;
|
package org.libreplan.business.externalcompanies.entities;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import org.hibernate.validator.NotEmpty;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.libreplan.business.common.BaseEntity;
|
import org.libreplan.business.common.BaseEntity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,8 @@
|
||||||
package org.libreplan.business.externalcompanies.entities;
|
package org.libreplan.business.externalcompanies.entities;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.hibernate.validator.AssertTrue;
|
import javax.validation.constraints.AssertTrue;
|
||||||
import org.hibernate.validator.NotEmpty;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
import org.libreplan.business.common.BaseEntity;
|
import org.libreplan.business.common.BaseEntity;
|
||||||
import org.libreplan.business.common.IHumanIdentifiable;
|
import org.libreplan.business.common.IHumanIdentifiable;
|
||||||
import org.libreplan.business.common.Registry;
|
import org.libreplan.business.common.Registry;
|
||||||
|
|
@ -147,7 +147,7 @@ public class ExternalCompany extends BaseEntity implements IHumanIdentifiable,
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message="company name must be unique. Company name already used")
|
@AssertTrue(message="company name must be unique. Company name already used")
|
||||||
public boolean checkConstraintUniqueName() {
|
public boolean isUniqueNameConstraint() {
|
||||||
IExternalCompanyDAO dao = Registry.getExternalCompanyDAO();
|
IExternalCompanyDAO dao = Registry.getExternalCompanyDAO();
|
||||||
|
|
||||||
if (isNewObject()) {
|
if (isNewObject()) {
|
||||||
|
|
@ -164,7 +164,7 @@ public class ExternalCompany extends BaseEntity implements IHumanIdentifiable,
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message="Company ID already used. It must be unique")
|
@AssertTrue(message="Company ID already used. It must be unique")
|
||||||
public boolean checkConstraintUniqueNif() {
|
public boolean isUniqueNifConstraint() {
|
||||||
IExternalCompanyDAO dao = Registry.getExternalCompanyDAO();
|
IExternalCompanyDAO dao = Registry.getExternalCompanyDAO();
|
||||||
|
|
||||||
if (isNewObject()) {
|
if (isNewObject()) {
|
||||||
|
|
@ -181,7 +181,7 @@ public class ExternalCompany extends BaseEntity implements IHumanIdentifiable,
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "interaction fields are empty and company is marked as interact with applications")
|
@AssertTrue(message = "interaction fields are empty and company is marked as interact with applications")
|
||||||
public boolean checkConstraintInteractionFieldsNotEmptyIfNeeded() {
|
public boolean isInteractionFieldsNotEmptyIfNeededConstraint() {
|
||||||
if (!interactsWithApplications) {
|
if (!interactsWithApplications) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,25 +33,33 @@ import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
import javax.transaction.Status;
|
import javax.transaction.Status;
|
||||||
import javax.transaction.Synchronization;
|
import javax.transaction.Synchronization;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.hibernate.SessionFactory;
|
||||||
import org.hibernate.Transaction;
|
import org.hibernate.Transaction;
|
||||||
import org.hibernate.event.AbstractEvent;
|
import org.hibernate.event.service.spi.EventListenerRegistry;
|
||||||
import org.hibernate.event.PostDeleteEvent;
|
import org.hibernate.event.spi.AbstractEvent;
|
||||||
import org.hibernate.event.PostDeleteEventListener;
|
import org.hibernate.event.spi.EventType;
|
||||||
import org.hibernate.event.PostInsertEvent;
|
import org.hibernate.event.spi.PostDeleteEvent;
|
||||||
import org.hibernate.event.PostInsertEventListener;
|
import org.hibernate.event.spi.PostDeleteEventListener;
|
||||||
import org.hibernate.event.PostUpdateEvent;
|
import org.hibernate.event.spi.PostInsertEvent;
|
||||||
import org.hibernate.event.PostUpdateEventListener;
|
import org.hibernate.event.spi.PostInsertEventListener;
|
||||||
|
import org.hibernate.event.spi.PostUpdateEvent;
|
||||||
|
import org.hibernate.event.spi.PostUpdateEventListener;
|
||||||
|
import org.hibernate.internal.SessionFactoryImpl;
|
||||||
import org.hibernate.proxy.HibernateProxy;
|
import org.hibernate.proxy.HibernateProxy;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Óscar González Fernández
|
* @author Óscar González Fernández
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@Component
|
||||||
public class HibernateDatabaseModificationsListener implements
|
public class HibernateDatabaseModificationsListener implements
|
||||||
PostInsertEventListener, PostUpdateEventListener,
|
PostInsertEventListener, PostUpdateEventListener,
|
||||||
PostDeleteEventListener, ISnapshotRefresherService {
|
PostDeleteEventListener, ISnapshotRefresherService {
|
||||||
|
|
@ -126,10 +134,27 @@ public class HibernateDatabaseModificationsListener implements
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SessionFactory sessionFactory;
|
||||||
|
|
||||||
|
private volatile boolean hibernateListenersRegistered = false;
|
||||||
|
|
||||||
public HibernateDatabaseModificationsListener() {
|
public HibernateDatabaseModificationsListener() {
|
||||||
interested = new ConcurrentHashMap<Class<?>, BlockingQueue<NotBlockingAutoUpdatedSnapshot<?>>>();
|
interested = new ConcurrentHashMap<Class<?>, BlockingQueue<NotBlockingAutoUpdatedSnapshot<?>>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
private void registerHibernateListeners() {
|
||||||
|
SessionFactoryImpl impl = (SessionFactoryImpl) sessionFactory;
|
||||||
|
EventListenerRegistry registry = impl.getServiceRegistry().getService(EventListenerRegistry.class);
|
||||||
|
|
||||||
|
registry.appendListeners(EventType.POST_INSERT, this);
|
||||||
|
registry.appendListeners(EventType.POST_UPDATE, this);
|
||||||
|
registry.appendListeners(EventType.POST_DELETE, this);
|
||||||
|
|
||||||
|
hibernateListenersRegistered = true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPostDelete(PostDeleteEvent event) {
|
public void onPostDelete(PostDeleteEvent event) {
|
||||||
modificationOn(inferTransaction(event),
|
modificationOn(inferTransaction(event),
|
||||||
|
|
@ -202,6 +227,11 @@ public class HibernateDatabaseModificationsListener implements
|
||||||
@Override
|
@Override
|
||||||
public <T> IAutoUpdatedSnapshot<T> takeSnapshot(String name,
|
public <T> IAutoUpdatedSnapshot<T> takeSnapshot(String name,
|
||||||
Callable<T> callable, ReloadOn reloadOn) {
|
Callable<T> callable, ReloadOn reloadOn) {
|
||||||
|
if (!hibernateListenersRegistered) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"The hibernate listeners has not been registered. There is some configuration problem.");
|
||||||
|
}
|
||||||
|
|
||||||
final NotBlockingAutoUpdatedSnapshot<T> result;
|
final NotBlockingAutoUpdatedSnapshot<T> result;
|
||||||
result = new NotBlockingAutoUpdatedSnapshot<T>(name, callable);
|
result = new NotBlockingAutoUpdatedSnapshot<T>(name, callable);
|
||||||
for (Class<?> each : reloadOn.getClassesOnWhichToReload()) {
|
for (Class<?> each : reloadOn.getClassesOnWhichToReload()) {
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,8 @@ import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.hibernate.validator.NotEmpty;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.libreplan.business.common.IntegrationEntity;
|
import org.libreplan.business.common.IntegrationEntity;
|
||||||
import org.libreplan.business.common.Registry;
|
import org.libreplan.business.common.Registry;
|
||||||
import org.libreplan.business.labels.daos.ILabelDAO;
|
import org.libreplan.business.labels.daos.ILabelDAO;
|
||||||
|
|
|
||||||
|
|
@ -27,9 +27,9 @@ import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.hibernate.validator.AssertTrue;
|
import javax.validation.constraints.AssertTrue;
|
||||||
import org.hibernate.validator.NotEmpty;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.libreplan.business.common.IHumanIdentifiable;
|
import org.libreplan.business.common.IHumanIdentifiable;
|
||||||
import org.libreplan.business.common.IntegrationEntity;
|
import org.libreplan.business.common.IntegrationEntity;
|
||||||
import org.libreplan.business.common.Registry;
|
import org.libreplan.business.common.Registry;
|
||||||
|
|
@ -108,7 +108,7 @@ public class LabelType extends IntegrationEntity implements Comparable,
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "label names must be unique inside a label type")
|
@AssertTrue(message = "label names must be unique inside a label type")
|
||||||
public boolean checkConstraintNonRepeatedLabelNames() {
|
public boolean isNonRepeatedLabelNamesConstraint() {
|
||||||
Set<String> labelNames = new HashSet<String>();
|
Set<String> labelNames = new HashSet<String>();
|
||||||
|
|
||||||
for (Label label : labels) {
|
for (Label label : labels) {
|
||||||
|
|
@ -125,7 +125,7 @@ public class LabelType extends IntegrationEntity implements Comparable,
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "label type name is already in use")
|
@AssertTrue(message = "label type name is already in use")
|
||||||
public boolean checkConstraintUniqueLabelTypeName() {
|
public boolean isUniqueLabelTypeNameConstraint() {
|
||||||
if (!firstLevelValidationsPassed()) {
|
if (!firstLevelValidationsPassed()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -156,7 +156,7 @@ public class LabelType extends IntegrationEntity implements Comparable,
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "label code is already being used")
|
@AssertTrue(message = "label code is already being used")
|
||||||
public boolean checkConstraintNonRepeatedMaterialCodes() {
|
public boolean isNonRepeatedMaterialCodesConstraint() {
|
||||||
return getFirstRepeatedCode(this.getLabels()) == null;
|
return getFirstRepeatedCode(this.getLabels()) == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,8 @@ package org.libreplan.business.materials.entities;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.hibernate.validator.NotEmpty;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.libreplan.business.common.IntegrationEntity;
|
import org.libreplan.business.common.IntegrationEntity;
|
||||||
import org.libreplan.business.common.Registry;
|
import org.libreplan.business.common.Registry;
|
||||||
import org.libreplan.business.materials.bootstrap.UnitTypeBootstrap;
|
import org.libreplan.business.materials.bootstrap.UnitTypeBootstrap;
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ package org.libreplan.business.materials.entities;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import org.hibernate.validator.Valid;
|
import javax.validation.Valid;
|
||||||
import org.libreplan.business.common.BaseEntity;
|
import org.libreplan.business.common.BaseEntity;
|
||||||
import org.libreplan.business.orders.entities.OrderElement;
|
import org.libreplan.business.orders.entities.OrderElement;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,10 +29,10 @@ import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.hibernate.validator.AssertTrue;
|
import javax.validation.constraints.AssertTrue;
|
||||||
import org.hibernate.validator.NotEmpty;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.hibernate.validator.Valid;
|
import javax.validation.Valid;
|
||||||
import org.libreplan.business.common.IntegrationEntity;
|
import org.libreplan.business.common.IntegrationEntity;
|
||||||
import org.libreplan.business.common.Registry;
|
import org.libreplan.business.common.Registry;
|
||||||
import org.libreplan.business.common.entities.EntitySequence;
|
import org.libreplan.business.common.entities.EntitySequence;
|
||||||
|
|
@ -151,7 +151,7 @@ public class MaterialCategory extends IntegrationEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message="material category name has to be unique. It is already used")
|
@AssertTrue(message="material category name has to be unique. It is already used")
|
||||||
public boolean checkConstraintUniqueName() {
|
public boolean isUniqueNameConstraint() {
|
||||||
boolean result;
|
boolean result;
|
||||||
if (isNewObject()) {
|
if (isNewObject()) {
|
||||||
result = !existsMaterialCategoryWithTheName();
|
result = !existsMaterialCategoryWithTheName();
|
||||||
|
|
@ -220,7 +220,7 @@ public class MaterialCategory extends IntegrationEntity {
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@AssertTrue(message = "Subcategory names must be unique.")
|
@AssertTrue(message = "Subcategory names must be unique.")
|
||||||
public boolean checkConstraintUniqueSubcategoryName() {
|
public boolean isUniqueSubcategoryNameConstraint() {
|
||||||
Set<String> subcategoriesNames = new HashSet<String>();
|
Set<String> subcategoriesNames = new HashSet<String>();
|
||||||
for (MaterialCategory mc : this.getAllSubcategories()) {
|
for (MaterialCategory mc : this.getAllSubcategories()) {
|
||||||
if (!StringUtils.isBlank(mc.getName())) {
|
if (!StringUtils.isBlank(mc.getName())) {
|
||||||
|
|
@ -237,7 +237,7 @@ public class MaterialCategory extends IntegrationEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "There are repeated material category codes")
|
@AssertTrue(message = "There are repeated material category codes")
|
||||||
public boolean checkConstraintNonRepeatedMaterialCategoryCodes() {
|
public boolean isNonRepeatedMaterialCategoryCodesConstraint() {
|
||||||
Set<MaterialCategory> allSubcategories = getAllSubcategories();
|
Set<MaterialCategory> allSubcategories = getAllSubcategories();
|
||||||
allSubcategories.add(this);
|
allSubcategories.add(this);
|
||||||
return getFirstRepeatedCode(allSubcategories) == null;
|
return getFirstRepeatedCode(allSubcategories) == null;
|
||||||
|
|
@ -252,7 +252,7 @@ public class MaterialCategory extends IntegrationEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "There are repeated material codes")
|
@AssertTrue(message = "There are repeated material codes")
|
||||||
public boolean checkConstraintNonRepeatedMaterialCodes() {
|
public boolean isNonRepeatedMaterialCodesConstraint() {
|
||||||
Set<Material> allMaterials = getAllMaterials();
|
Set<Material> allMaterials = getAllMaterials();
|
||||||
return getFirstRepeatedCode(allMaterials) == null;
|
return getFirstRepeatedCode(allMaterials) == null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ package org.libreplan.business.materials.entities;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,8 @@
|
||||||
package org.libreplan.business.materials.entities;
|
package org.libreplan.business.materials.entities;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.hibernate.validator.AssertTrue;
|
import javax.validation.constraints.AssertTrue;
|
||||||
import org.hibernate.validator.NotEmpty;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
import org.libreplan.business.common.IHumanIdentifiable;
|
import org.libreplan.business.common.IHumanIdentifiable;
|
||||||
import org.libreplan.business.common.IntegrationEntity;
|
import org.libreplan.business.common.IntegrationEntity;
|
||||||
import org.libreplan.business.common.Registry;
|
import org.libreplan.business.common.Registry;
|
||||||
|
|
@ -83,7 +83,7 @@ public class UnitType extends IntegrationEntity implements IHumanIdentifiable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "the measure has to be unique")
|
@AssertTrue(message = "the measure has to be unique")
|
||||||
public boolean checkConstraintUniqueName() {
|
public boolean isUniqueNameConstraint() {
|
||||||
if (StringUtils.isBlank(measure)) {
|
if (StringUtils.isBlank(measure)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,11 +31,12 @@ import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.hibernate.validator.NotNull;
|
|
||||||
import org.hibernate.validator.Valid;
|
|
||||||
import org.libreplan.business.common.IntegrationEntity;
|
import org.libreplan.business.common.IntegrationEntity;
|
||||||
import org.libreplan.business.common.Registry;
|
import org.libreplan.business.common.Registry;
|
||||||
import org.libreplan.business.common.daos.IIntegrationEntityDAO;
|
import org.libreplan.business.common.daos.IIntegrationEntityDAO;
|
||||||
|
|
@ -399,7 +400,7 @@ public class HoursGroup extends IntegrationEntity implements Cloneable,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean checkConstraintUniqueCode() {
|
public boolean isUniqueCodeConstraint() {
|
||||||
// the automatic checking of this constraint is avoided because it uses
|
// the automatic checking of this constraint is avoided because it uses
|
||||||
// the wrong code property
|
// the wrong code property
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -33,11 +33,12 @@ import java.util.Set;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import javax.validation.constraints.AssertTrue;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.hibernate.validator.AssertTrue;
|
|
||||||
import org.hibernate.validator.NotNull;
|
|
||||||
import org.hibernate.validator.Valid;
|
|
||||||
import org.libreplan.business.advance.bootstrap.PredefinedAdvancedTypes;
|
import org.libreplan.business.advance.bootstrap.PredefinedAdvancedTypes;
|
||||||
import org.libreplan.business.advance.entities.AdvanceType;
|
import org.libreplan.business.advance.entities.AdvanceType;
|
||||||
import org.libreplan.business.advance.entities.DirectAdvanceAssignment;
|
import org.libreplan.business.advance.entities.DirectAdvanceAssignment;
|
||||||
|
|
@ -351,27 +352,27 @@ public class Order extends OrderLineGroup implements Comparable {
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@AssertTrue(message = "the project must have a start date")
|
@AssertTrue(message = "the project must have a start date")
|
||||||
private boolean ifSchedulingModeIsForwardOrderMustHaveStartDate() {
|
private boolean isIfSchedulingModeIsForwardOrderMustHaveStartDateConstraint() {
|
||||||
return getSchedulingMode() != SchedulingMode.FORWARD
|
return getSchedulingMode() != SchedulingMode.FORWARD
|
||||||
|| getInitDate() != null;
|
|| getInitDate() != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@AssertTrue(message = "the project must have a deadline")
|
@AssertTrue(message = "the project must have a deadline")
|
||||||
private boolean ifSchedulingModeIsBackwardsOrderMustHaveDeadline() {
|
private boolean isIfSchedulingModeIsBackwardsOrderMustHaveDeadlineConstraint() {
|
||||||
return getSchedulingMode() != SchedulingMode.BACKWARDS
|
return getSchedulingMode() != SchedulingMode.BACKWARDS
|
||||||
|| getDeadline() != null;
|
|| getDeadline() != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@AssertTrue(message = "deadline must be after start date")
|
@AssertTrue(message = "deadline must be after start date")
|
||||||
private boolean checkConstraintDeadlineMustBeAfterStart() {
|
private boolean isDeadlineMustBeAfterStartConstraint() {
|
||||||
return getInitDate() == null || !this.isDeadlineBeforeStart();
|
return getInitDate() == null || !this.isDeadlineBeforeStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@AssertTrue(message = "At least one hours group is needed for each task")
|
@AssertTrue(message = "At least one hours group is needed for each task")
|
||||||
private boolean checkConstraintAtLeastOneHoursGroupForEachOrderElement() {
|
private boolean isAtLeastOneHoursGroupForEachOrderElementConstraint() {
|
||||||
for (OrderElement orderElement : this.getOrderElements()) {
|
for (OrderElement orderElement : this.getOrderElements()) {
|
||||||
if (!orderElement.checkAtLeastOneHoursGroup()) {
|
if (!orderElement.checkAtLeastOneHoursGroup()) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -578,7 +579,7 @@ public class Order extends OrderLineGroup implements Comparable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "project name is already being used")
|
@AssertTrue(message = "project name is already being used")
|
||||||
public boolean checkConstraintProjectUniqueName() {
|
public boolean isProjectUniqueNameConstraint() {
|
||||||
|
|
||||||
IOrderDAO orderDAO = Registry.getOrderDAO();
|
IOrderDAO orderDAO = Registry.getOrderDAO();
|
||||||
|
|
||||||
|
|
@ -696,7 +697,7 @@ public class Order extends OrderLineGroup implements Comparable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "task code is repeated inside the project")
|
@AssertTrue(message = "task code is repeated inside the project")
|
||||||
public boolean checkConstraintUniqueCodeInsideOrder() {
|
public boolean isUniqueCodeInsideOrderConstraint() {
|
||||||
List<String> codes = new ArrayList<String>();
|
List<String> codes = new ArrayList<String>();
|
||||||
codes.add(getCode());
|
codes.add(getCode());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,12 +34,12 @@ import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import javax.validation.constraints.AssertTrue;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.hibernate.validator.AssertTrue;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
import org.hibernate.validator.InvalidValue;
|
|
||||||
import org.hibernate.validator.NotEmpty;
|
|
||||||
import org.hibernate.validator.Valid;
|
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
import org.libreplan.business.advance.bootstrap.PredefinedAdvancedTypes;
|
import org.libreplan.business.advance.bootstrap.PredefinedAdvancedTypes;
|
||||||
import org.libreplan.business.advance.entities.AdvanceAssignment;
|
import org.libreplan.business.advance.entities.AdvanceAssignment;
|
||||||
|
|
@ -1160,22 +1160,22 @@ public abstract class OrderElement extends IntegrationEntity implements
|
||||||
Validate.notNull(qualityForm);
|
Validate.notNull(qualityForm);
|
||||||
for (TaskQualityForm taskQualityForm : getTaskQualityForms()) {
|
for (TaskQualityForm taskQualityForm : getTaskQualityForms()) {
|
||||||
if (qualityForm.equals(taskQualityForm.getQualityForm())) {
|
if (qualityForm.equals(taskQualityForm.getQualityForm())) {
|
||||||
throw new ValidationException(new InvalidValue(
|
throw new ValidationException(ValidationException.invalidValue(
|
||||||
_("Quality form already exists"), QualityForm.class,
|
_("Quality form already exists"), "name",
|
||||||
"name", qualityForm.getName(), qualityForm));
|
qualityForm.getName(), qualityForm));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean checkConstraintUniqueCode() {
|
public boolean isUniqueCodeConstraint() {
|
||||||
// the automatic checking of this constraint is avoided because it uses
|
// the automatic checking of this constraint is avoided because it uses
|
||||||
// the wrong code property
|
// the wrong code property
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "code is already used in another project")
|
@AssertTrue(message = "code is already used in another project")
|
||||||
public boolean checkConstraintCodeRepeatedInAnotherOrder() {
|
public boolean isCodeRepeatedInAnotherOrderConstraint() {
|
||||||
if (StringUtils.isBlank(getCode())) {
|
if (StringUtils.isBlank(getCode())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -1185,7 +1185,7 @@ public abstract class OrderElement extends IntegrationEntity implements
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "a label can not be assigned twice in the same branch")
|
@AssertTrue(message = "a label can not be assigned twice in the same branch")
|
||||||
public boolean checkConstraintLabelNotRepeatedInTheSameBranch() {
|
public boolean isLabelNotRepeatedInTheSameBranchConstraint() {
|
||||||
return checkConstraintLabelNotRepeatedInTheSameBranch(new HashSet<Label>());
|
return checkConstraintLabelNotRepeatedInTheSameBranch(new HashSet<Label>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1501,7 +1501,7 @@ public abstract class OrderElement extends IntegrationEntity implements
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "a quality form cannot be assigned twice to the same task")
|
@AssertTrue(message = "a quality form cannot be assigned twice to the same task")
|
||||||
public boolean checkConstraintUniqueQualityForm() {
|
public boolean isUniqueQualityFormConstraint() {
|
||||||
Set<QualityForm> qualityForms = new HashSet<QualityForm>();
|
Set<QualityForm> qualityForms = new HashSet<QualityForm>();
|
||||||
for (TaskQualityForm each : taskQualityForms) {
|
for (TaskQualityForm each : taskQualityForms) {
|
||||||
QualityForm qualityForm = each.getQualityForm();
|
QualityForm qualityForm = each.getQualityForm();
|
||||||
|
|
|
||||||
|
|
@ -29,10 +29,11 @@ import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import javax.validation.constraints.AssertTrue;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.hibernate.validator.AssertTrue;
|
|
||||||
import org.hibernate.validator.NotNull;
|
|
||||||
import org.hibernate.validator.Valid;
|
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
import org.libreplan.business.advance.entities.AdvanceAssignment;
|
import org.libreplan.business.advance.entities.AdvanceAssignment;
|
||||||
import org.libreplan.business.advance.entities.AdvanceType;
|
import org.libreplan.business.advance.entities.AdvanceType;
|
||||||
|
|
@ -83,7 +84,6 @@ public class OrderLine extends OrderElement {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Valid
|
|
||||||
private Set<HoursGroup> hoursGroups = new HashSet<HoursGroup>();
|
private Set<HoursGroup> hoursGroups = new HashSet<HoursGroup>();
|
||||||
|
|
||||||
private Integer lastHoursGroupSequenceCode = 0;
|
private Integer lastHoursGroupSequenceCode = 0;
|
||||||
|
|
@ -329,7 +329,7 @@ public class OrderLine extends OrderElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "Code already included in Hours Group codes")
|
@AssertTrue(message = "Code already included in Hours Group codes")
|
||||||
public boolean checkConstraintHoursGroupsCodeNotRepeated() {
|
public boolean isHoursGroupsCodeNotRepeatedConstraint() {
|
||||||
Set<String> codes = new HashSet<String>();
|
Set<String> codes = new HashSet<String>();
|
||||||
|
|
||||||
for (HoursGroup hoursGroup : getHoursGroups()) {
|
for (HoursGroup hoursGroup : getHoursGroups()) {
|
||||||
|
|
|
||||||
|
|
@ -35,8 +35,9 @@ import java.util.Set;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
|
||||||
import org.hibernate.validator.AssertTrue;
|
import javax.validation.Valid;
|
||||||
import org.hibernate.validator.Valid;
|
import javax.validation.constraints.AssertTrue;
|
||||||
|
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
import org.libreplan.business.advance.bootstrap.PredefinedAdvancedTypes;
|
import org.libreplan.business.advance.bootstrap.PredefinedAdvancedTypes;
|
||||||
import org.libreplan.business.advance.entities.AdvanceAssignment;
|
import org.libreplan.business.advance.entities.AdvanceAssignment;
|
||||||
|
|
@ -804,9 +805,8 @@ public class OrderLineGroup extends OrderElement implements
|
||||||
private void checkAndSetValue(AdvanceMeasurement advanceMeasurement,
|
private void checkAndSetValue(AdvanceMeasurement advanceMeasurement,
|
||||||
BigDecimal previousResult) {
|
BigDecimal previousResult) {
|
||||||
advanceMeasurement.setValue(previousResult);
|
advanceMeasurement.setValue(previousResult);
|
||||||
boolean checkPrecision = advanceMeasurement
|
if (!advanceMeasurement
|
||||||
.checkConstraintValidPrecision();
|
.isValidPrecisionConstraint()) {
|
||||||
if (!checkPrecision) {
|
|
||||||
AdvanceAssignment advanceAssignment = advanceMeasurement
|
AdvanceAssignment advanceAssignment = advanceMeasurement
|
||||||
.getAdvanceAssignment();
|
.getAdvanceAssignment();
|
||||||
if ((previousResult == null) || (advanceAssignment == null)
|
if ((previousResult == null) || (advanceAssignment == null)
|
||||||
|
|
@ -1149,7 +1149,7 @@ public class OrderLineGroup extends OrderElement implements
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "indirect progress assignments should have different types")
|
@AssertTrue(message = "indirect progress assignments should have different types")
|
||||||
public boolean checkConstraintIndirectAdvanceAssignmentsWithDifferentType() {
|
public boolean isIndirectAdvanceAssignmentsWithDifferentTypeConstraint() {
|
||||||
Set<String> types = new HashSet<String>();
|
Set<String> types = new HashSet<String>();
|
||||||
for (IndirectAdvanceAssignment each : indirectAdvanceAssignments) {
|
for (IndirectAdvanceAssignment each : indirectAdvanceAssignments) {
|
||||||
String type = each.getAdvanceType().getUnitName();
|
String type = each.getAdvanceType().getUnitName();
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,8 @@ import java.util.Date;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.hibernate.validator.AssertTrue;
|
import javax.validation.constraints.AssertTrue;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.libreplan.business.common.BaseEntity;
|
import org.libreplan.business.common.BaseEntity;
|
||||||
import org.libreplan.business.common.Registry;
|
import org.libreplan.business.common.Registry;
|
||||||
import org.libreplan.business.common.entities.Connector;
|
import org.libreplan.business.common.entities.Connector;
|
||||||
|
|
@ -111,7 +111,7 @@ public class OrderSyncInfo extends BaseEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "project sync info is already being used")
|
@AssertTrue(message = "project sync info is already being used")
|
||||||
public boolean checkConstraintUniqueOrderSyncInfo() {
|
public boolean isUniqueOrderSyncInfoConstraint() {
|
||||||
if (StringUtils.isBlank(key) && order == null
|
if (StringUtils.isBlank(key) && order == null
|
||||||
&& StringUtils.isBlank(connectorName)) {
|
&& StringUtils.isBlank(connectorName)) {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,8 @@
|
||||||
package org.libreplan.business.orders.entities;
|
package org.libreplan.business.orders.entities;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.hibernate.validator.Valid;
|
import javax.validation.Valid;
|
||||||
import org.libreplan.business.common.BaseEntity;
|
import org.libreplan.business.common.BaseEntity;
|
||||||
import org.libreplan.business.orders.entities.SchedulingState.ITypeChangedListener;
|
import org.libreplan.business.orders.entities.SchedulingState.ITypeChangedListener;
|
||||||
import org.libreplan.business.orders.entities.SchedulingState.Type;
|
import org.libreplan.business.orders.entities.SchedulingState.Type;
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,8 @@ import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.hibernate.validator.Valid;
|
import javax.validation.Valid;
|
||||||
import org.libreplan.business.common.BaseEntity;
|
import org.libreplan.business.common.BaseEntity;
|
||||||
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
|
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
|
||||||
import org.libreplan.business.orders.entities.SchedulingState.Type;
|
import org.libreplan.business.orders.entities.SchedulingState.Type;
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.lang.ObjectUtils;
|
import org.apache.commons.lang.ObjectUtils;
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
import org.libreplan.business.common.BaseEntity;
|
import org.libreplan.business.common.BaseEntity;
|
||||||
import org.libreplan.business.resources.entities.Resource;
|
import org.libreplan.business.resources.entities.Resource;
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
import org.libreplan.business.common.BaseEntity;
|
import org.libreplan.business.common.BaseEntity;
|
||||||
import org.libreplan.business.common.Registry;
|
import org.libreplan.business.common.Registry;
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ package org.libreplan.business.planner.entities;
|
||||||
import static org.libreplan.business.workingday.EffortDuration.hours;
|
import static org.libreplan.business.workingday.EffortDuration.hours;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
import org.libreplan.business.common.BaseEntity;
|
import org.libreplan.business.common.BaseEntity;
|
||||||
import org.libreplan.business.resources.entities.Resource;
|
import org.libreplan.business.resources.entities.Resource;
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
import org.libreplan.business.common.BaseEntity;
|
import org.libreplan.business.common.BaseEntity;
|
||||||
import org.libreplan.business.resources.entities.Resource;
|
import org.libreplan.business.resources.entities.Resource;
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,8 @@ import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.hibernate.validator.Valid;
|
import javax.validation.Valid;
|
||||||
import org.libreplan.business.common.BaseEntity;
|
import org.libreplan.business.common.BaseEntity;
|
||||||
import org.libreplan.business.scenarios.entities.Scenario;
|
import org.libreplan.business.scenarios.entities.Scenario;
|
||||||
import org.libreplan.business.util.deepcopy.OnCopy;
|
import org.libreplan.business.util.deepcopy.OnCopy;
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.hibernate.validator.Valid;
|
import javax.validation.Valid;
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
import org.libreplan.business.calendars.entities.AvailabilityTimeLine;
|
import org.libreplan.business.calendars.entities.AvailabilityTimeLine;
|
||||||
import org.libreplan.business.calendars.entities.Capacity;
|
import org.libreplan.business.calendars.entities.Capacity;
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ import org.apache.commons.lang.ObjectUtils;
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
import org.libreplan.business.calendars.entities.AvailabilityTimeLine;
|
import org.libreplan.business.calendars.entities.AvailabilityTimeLine;
|
||||||
import org.libreplan.business.calendars.entities.BaseCalendar;
|
import org.libreplan.business.calendars.entities.BaseCalendar;
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
import org.libreplan.business.common.BaseEntity;
|
import org.libreplan.business.common.BaseEntity;
|
||||||
import org.libreplan.business.resources.entities.Resource;
|
import org.libreplan.business.resources.entities.Resource;
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,8 @@ import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.hibernate.validator.Valid;
|
import javax.validation.Valid;
|
||||||
import org.libreplan.business.common.BaseEntity;
|
import org.libreplan.business.common.BaseEntity;
|
||||||
import org.libreplan.business.scenarios.entities.Scenario;
|
import org.libreplan.business.scenarios.entities.Scenario;
|
||||||
import org.libreplan.business.util.deepcopy.OnCopy;
|
import org.libreplan.business.util.deepcopy.OnCopy;
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,8 @@ import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.hibernate.validator.Valid;
|
import javax.validation.Valid;
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
import org.libreplan.business.calendars.entities.AvailabilityTimeLine;
|
import org.libreplan.business.calendars.entities.AvailabilityTimeLine;
|
||||||
import org.libreplan.business.calendars.entities.AvailabilityTimeLine.FixedPoint;
|
import org.libreplan.business.calendars.entities.AvailabilityTimeLine.FixedPoint;
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.joda.time.Days;
|
import org.joda.time.Days;
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,9 +32,10 @@ import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import javax.validation.constraints.AssertTrue;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.hibernate.validator.AssertTrue;
|
|
||||||
import org.hibernate.validator.Valid;
|
|
||||||
import org.joda.time.Days;
|
import org.joda.time.Days;
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
|
|
||||||
|
|
@ -307,14 +308,14 @@ public class StretchesFunction extends AssignmentFunction {
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "At least one stretch is needed")
|
@AssertTrue(message = "At least one stretch is needed")
|
||||||
public boolean checkNoEmpty() {
|
public boolean isNoEmptyConstraint() {
|
||||||
// first 0%-0% and last 100%-100% stretches are added automatically
|
// first 0%-0% and last 100%-100% stretches are added automatically
|
||||||
return getStretchesPlusConsolidated().size() > 2;
|
return getStretchesPlusConsolidated().size() > 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "A stretch has lower or equal values than the "
|
@AssertTrue(message = "A stretch has lower or equal values than the "
|
||||||
+ "previous stretch")
|
+ "previous stretch")
|
||||||
public boolean checkStretchesOrder() {
|
public boolean isStretchesOrderConstraint() {
|
||||||
List<Stretch> stretchesPlusConsolidated = getStretchesPlusConsolidated();
|
List<Stretch> stretchesPlusConsolidated = getStretchesPlusConsolidated();
|
||||||
if (stretchesPlusConsolidated.isEmpty()) {
|
if (stretchesPlusConsolidated.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -349,7 +350,7 @@ public class StretchesFunction extends AssignmentFunction {
|
||||||
|
|
||||||
@AssertTrue(message = "Last stretch should have one hundred percent "
|
@AssertTrue(message = "Last stretch should have one hundred percent "
|
||||||
+ "length and one hundred percent of work percentage")
|
+ "length and one hundred percent of work percentage")
|
||||||
public boolean checkOneHundredPercent() {
|
public boolean isOneHundredPercentConstraint() {
|
||||||
List<Stretch> stretches = getStretchesPlusConsolidated();
|
List<Stretch> stretches = getStretchesPlusConsolidated();
|
||||||
if (stretches.isEmpty()) {
|
if (stretches.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -29,9 +29,9 @@ import java.util.Set;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
|
||||||
import org.hibernate.validator.AssertTrue;
|
import javax.validation.constraints.AssertTrue;
|
||||||
import org.hibernate.validator.NotEmpty;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.libreplan.business.common.BaseEntity;
|
import org.libreplan.business.common.BaseEntity;
|
||||||
import org.libreplan.business.externalcompanies.entities.DeliverDateComparator;
|
import org.libreplan.business.externalcompanies.entities.DeliverDateComparator;
|
||||||
import org.libreplan.business.externalcompanies.entities.EndDateCommunication;
|
import org.libreplan.business.externalcompanies.entities.EndDateCommunication;
|
||||||
|
|
@ -246,7 +246,7 @@ public class SubcontractedTaskData extends BaseEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "external company should be subcontractor")
|
@AssertTrue(message = "external company should be subcontractor")
|
||||||
public boolean checkConstraintExternalCompanyIsSubcontractor() {
|
public boolean isExternalCompanyIsSubcontractorConstraint() {
|
||||||
if (!firstLevelValidationsPassed()) {
|
if (!firstLevelValidationsPassed()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.libreplan.business.common.BaseEntity;
|
import org.libreplan.business.common.BaseEntity;
|
||||||
import org.libreplan.business.externalcompanies.entities.CommunicationType;
|
import org.libreplan.business.externalcompanies.entities.CommunicationType;
|
||||||
import org.libreplan.business.qualityforms.entities.QualityFormItem;
|
import org.libreplan.business.qualityforms.entities.QualityFormItem;
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ package org.libreplan.business.planner.entities;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import org.hibernate.validator.AssertTrue;
|
import javax.validation.constraints.AssertTrue;
|
||||||
import org.libreplan.business.INewObject;
|
import org.libreplan.business.INewObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -71,7 +71,7 @@ public class SubcontractorCommunicationValue implements INewObject {
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@AssertTrue(message = "progress should be greater than 0% and less than 100%")
|
@AssertTrue(message = "progress should be greater than 0% and less than 100%")
|
||||||
public boolean checkConstraintQualityFormItemPercentage() {
|
public boolean isQualityFormItemPercentageConstraint() {
|
||||||
if (getProgress() == null) {
|
if (getProgress() == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,11 +34,12 @@ import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import javax.validation.constraints.AssertTrue;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.hibernate.validator.AssertTrue;
|
|
||||||
import org.hibernate.validator.Valid;
|
|
||||||
import org.joda.time.Days;
|
import org.joda.time.Days;
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
import org.libreplan.business.calendars.entities.AvailabilityTimeLine;
|
import org.libreplan.business.calendars.entities.AvailabilityTimeLine;
|
||||||
|
|
@ -187,7 +188,7 @@ public class Task extends TaskElement implements ITaskPositionConstrained {
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@AssertTrue(message = "element associated to a task must be not empty")
|
@AssertTrue(message = "element associated to a task must be not empty")
|
||||||
private boolean theOrderElementMustBeNotNull() {
|
private boolean isTheOrderElementMustBeNotNullConstraint() {
|
||||||
return getOrderElement() != null;
|
return getOrderElement() != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ import org.apache.commons.lang.BooleanUtils;
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
import org.libreplan.business.calendars.entities.BaseCalendar;
|
import org.libreplan.business.calendars.entities.BaseCalendar;
|
||||||
import org.libreplan.business.common.BaseEntity;
|
import org.libreplan.business.common.BaseEntity;
|
||||||
|
|
|
||||||
|
|
@ -30,9 +30,10 @@ import java.util.List;
|
||||||
import java.util.ListIterator;
|
import java.util.ListIterator;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import javax.validation.constraints.AssertTrue;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.hibernate.validator.AssertTrue;
|
|
||||||
import org.hibernate.validator.Valid;
|
|
||||||
import org.libreplan.business.common.entities.ProgressType;
|
import org.libreplan.business.common.entities.ProgressType;
|
||||||
import org.libreplan.business.orders.entities.TaskSource;
|
import org.libreplan.business.orders.entities.TaskSource;
|
||||||
import org.libreplan.business.resources.daos.IResourcesSearcher;
|
import org.libreplan.business.resources.daos.IResourcesSearcher;
|
||||||
|
|
@ -108,7 +109,7 @@ public class TaskGroup extends TaskElement {
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@AssertTrue(message = "element associated to a task group have to be defined")
|
@AssertTrue(message = "element associated to a task group have to be defined")
|
||||||
private boolean theOrderElementMustBeNotNull() {
|
private boolean isTheOrderElementMustBeNotNullConstraint() {
|
||||||
return getOrderElement() != null;
|
return getOrderElement() != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,9 @@ import java.util.EnumSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.validation.constraints.AssertTrue;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.hibernate.validator.AssertTrue;
|
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.Days;
|
import org.joda.time.Days;
|
||||||
import org.libreplan.business.orders.entities.Order;
|
import org.libreplan.business.orders.entities.Order;
|
||||||
|
|
@ -119,7 +120,7 @@ public class TaskMilestone extends TaskElement implements ITaskPositionConstrain
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@AssertTrue(message = "a milestone cannot have a task associated")
|
@AssertTrue(message = "a milestone cannot have a task associated")
|
||||||
private boolean theOrderElementMustBeNull() {
|
private boolean isTheOrderElementMustBeNullConstraint() {
|
||||||
return getOrderElement() == null;
|
return getOrderElement() == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ package org.libreplan.business.planner.entities.consolidations;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
import org.libreplan.business.common.BaseEntity;
|
import org.libreplan.business.common.BaseEntity;
|
||||||
import org.libreplan.business.workingday.IntraDayDate;
|
import org.libreplan.business.workingday.IntraDayDate;
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.hibernate.validator.Valid;
|
import javax.validation.Valid;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.Duration;
|
import org.joda.time.Duration;
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
|
|
|
||||||
|
|
@ -159,7 +159,7 @@ public class QualityFormDAO extends GenericDAOHibernate<QualityForm, Long>
|
||||||
query.setParameterList("qualityForms", Collections.singleton(qualityForm));
|
query.setParameterList("qualityForms", Collections.singleton(qualityForm));
|
||||||
if (!query.list().isEmpty()) {
|
if (!query.list().isEmpty()) {
|
||||||
throw ValidationException
|
throw ValidationException
|
||||||
.invalidValue(
|
.invalidValueException(
|
||||||
"Cannot delete quality form. It is being used at this moment by some task.",
|
"Cannot delete quality form. It is being used at this moment by some task.",
|
||||||
qualityForm);
|
qualityForm);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,10 +33,10 @@ import java.util.List;
|
||||||
import org.apache.commons.lang.BooleanUtils;
|
import org.apache.commons.lang.BooleanUtils;
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.hibernate.NonUniqueResultException;
|
import org.hibernate.NonUniqueResultException;
|
||||||
import org.hibernate.validator.AssertTrue;
|
import javax.validation.constraints.AssertTrue;
|
||||||
import org.hibernate.validator.NotEmpty;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.hibernate.validator.Valid;
|
import javax.validation.Valid;
|
||||||
import org.libreplan.business.advance.entities.AdvanceType;
|
import org.libreplan.business.advance.entities.AdvanceType;
|
||||||
import org.libreplan.business.common.BaseEntity;
|
import org.libreplan.business.common.BaseEntity;
|
||||||
import org.libreplan.business.common.IHumanIdentifiable;
|
import org.libreplan.business.common.IHumanIdentifiable;
|
||||||
|
|
@ -190,7 +190,7 @@ public class QualityForm extends BaseEntity implements IHumanIdentifiable{
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@AssertTrue(message = "Quality form name is already being used")
|
@AssertTrue(message = "Quality form name is already being used")
|
||||||
public boolean checkConstraintUniqueQualityFormName() {
|
public boolean isUniqueQualityFormNameConstraint() {
|
||||||
IQualityFormDAO qualityFormDAO = Registry.getQualityFormDAO();
|
IQualityFormDAO qualityFormDAO = Registry.getQualityFormDAO();
|
||||||
if (isNewObject()) {
|
if (isNewObject()) {
|
||||||
return !qualityFormDAO.existsByNameAnotherTransaction(this);
|
return !qualityFormDAO.existsByNameAnotherTransaction(this);
|
||||||
|
|
@ -208,13 +208,13 @@ public class QualityForm extends BaseEntity implements IHumanIdentifiable{
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@AssertTrue(message = "Quality form item name must be unique")
|
@AssertTrue(message = "Quality form item name must be unique")
|
||||||
public boolean checkConstraintUniqueQualityFormItemsName() {
|
public boolean isUniqueQualityFormItemsNameConstraint() {
|
||||||
return (findQualityFormItemWithDuplicateName() == null);
|
return (findQualityFormItemWithDuplicateName() == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@AssertTrue(message = "The quality form item positions must be unique and consecutive.")
|
@AssertTrue(message = "The quality form item positions must be unique and consecutive.")
|
||||||
public boolean checkConstraintConsecutivesAndUniquesQualityFormItemPositions() {
|
public boolean isConsecutivesAndUniquesQualityFormItemPositionsConstraint() {
|
||||||
List<QualityFormItem> result = getListToNull(qualityFormItems);
|
List<QualityFormItem> result = getListToNull(qualityFormItems);
|
||||||
for (QualityFormItem qualityFormItem : qualityFormItems) {
|
for (QualityFormItem qualityFormItem : qualityFormItems) {
|
||||||
// Check if index is out of range
|
// Check if index is out of range
|
||||||
|
|
@ -246,7 +246,7 @@ public class QualityForm extends BaseEntity implements IHumanIdentifiable{
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@AssertTrue(message = "The quality item positions must be correct in function to the percentage.")
|
@AssertTrue(message = "The quality item positions must be correct in function to the percentage.")
|
||||||
public boolean checkConstraintCorrectPositionsQualityFormItemsByPercentage() {
|
public boolean isCorrectPositionsQualityFormItemsByPercentageConstraint() {
|
||||||
// check the position is correct in function to the percentage.
|
// check the position is correct in function to the percentage.
|
||||||
if ((qualityFormType != null)
|
if ((qualityFormType != null)
|
||||||
&& (qualityFormType.equals(QualityFormType.BY_PERCENTAGE))) {
|
&& (qualityFormType.equals(QualityFormType.BY_PERCENTAGE))) {
|
||||||
|
|
@ -264,7 +264,7 @@ public class QualityForm extends BaseEntity implements IHumanIdentifiable{
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@AssertTrue(message = "percentages in quality form items must be unique")
|
@AssertTrue(message = "percentages in quality form items must be unique")
|
||||||
public boolean checkConstraintDuplicatesQualityFormItemPercentage() {
|
public boolean isDuplicatesQualityFormItemPercentageConstraint() {
|
||||||
if ((qualityFormType != null)
|
if ((qualityFormType != null)
|
||||||
&& (qualityFormType.equals(QualityFormType.BY_PERCENTAGE))
|
&& (qualityFormType.equals(QualityFormType.BY_PERCENTAGE))
|
||||||
&& (findQualityFormItemWithDuplicatePercentage() != null)) {
|
&& (findQualityFormItemWithDuplicatePercentage() != null)) {
|
||||||
|
|
@ -275,7 +275,7 @@ public class QualityForm extends BaseEntity implements IHumanIdentifiable{
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@AssertTrue(message = "percentage should be greater than 0% and less than 100%")
|
@AssertTrue(message = "percentage should be greater than 0% and less than 100%")
|
||||||
public boolean checkConstraintQualityFormItemsPercentage() {
|
public boolean isQualityFormItemsPercentageConstraint() {
|
||||||
if ((qualityFormItems.size() > 0) && (qualityFormType != null)
|
if ((qualityFormItems.size() > 0) && (qualityFormType != null)
|
||||||
&& (qualityFormType.equals(QualityFormType.BY_ITEMS))) {
|
&& (qualityFormType.equals(QualityFormType.BY_ITEMS))) {
|
||||||
BigDecimal sum = new BigDecimal(0);
|
BigDecimal sum = new BigDecimal(0);
|
||||||
|
|
@ -404,7 +404,7 @@ public class QualityForm extends BaseEntity implements IHumanIdentifiable{
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "progress type should must be defined if quality form reports progress")
|
@AssertTrue(message = "progress type should must be defined if quality form reports progress")
|
||||||
public boolean checkConstraintAdvanceTypeIsNotNullIfReportAdvance() {
|
public boolean isAdvanceTypeIsNotNullIfReportAdvanceConstraint() {
|
||||||
if (advanceType == null) {
|
if (advanceType == null) {
|
||||||
return !isReportAdvance();
|
return !isReportAdvance();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,9 +26,9 @@ package org.libreplan.business.qualityforms.entities;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
import org.hibernate.validator.AssertTrue;
|
import javax.validation.constraints.AssertTrue;
|
||||||
import org.hibernate.validator.NotEmpty;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.libreplan.business.INewObject;
|
import org.libreplan.business.INewObject;
|
||||||
|
|
||||||
public class QualityFormItem implements INewObject {
|
public class QualityFormItem implements INewObject {
|
||||||
|
|
@ -110,7 +110,7 @@ public class QualityFormItem implements INewObject {
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@AssertTrue(message = "percentage should be greater than 0% and less than 100%")
|
@AssertTrue(message = "percentage should be greater than 0% and less than 100%")
|
||||||
public boolean checkConstraintQualityFormItemPercentage() {
|
public boolean isQualityFormItemPercentageConstraint() {
|
||||||
if (percentage == null) {
|
if (percentage == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,9 +28,9 @@ import java.util.List;
|
||||||
|
|
||||||
import org.apache.commons.lang.BooleanUtils;
|
import org.apache.commons.lang.BooleanUtils;
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.hibernate.validator.AssertTrue;
|
import javax.validation.constraints.AssertTrue;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.hibernate.validator.Valid;
|
import javax.validation.Valid;
|
||||||
import org.libreplan.business.common.BaseEntity;
|
import org.libreplan.business.common.BaseEntity;
|
||||||
import org.libreplan.business.orders.entities.OrderElement;
|
import org.libreplan.business.orders.entities.OrderElement;
|
||||||
|
|
||||||
|
|
@ -99,7 +99,7 @@ public class TaskQualityForm extends BaseEntity {
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@AssertTrue(message = "Each date must be greater than the dates of the previous task quality form items.")
|
@AssertTrue(message = "Each date must be greater than the dates of the previous task quality form items.")
|
||||||
public boolean checkConstraintCorrectConsecutivesDate() {
|
public boolean isCorrectConsecutivesDateConstraint() {
|
||||||
if (!isByItems()) {
|
if (!isByItems()) {
|
||||||
for (TaskQualityFormItem item : taskQualityFormItems) {
|
for (TaskQualityFormItem item : taskQualityFormItems) {
|
||||||
if (!isCorrectConsecutiveDate(item)) {
|
if (!isCorrectConsecutiveDate(item)) {
|
||||||
|
|
@ -112,7 +112,7 @@ public class TaskQualityForm extends BaseEntity {
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@AssertTrue(message = "items cannot be checked until the previous items are checked before.")
|
@AssertTrue(message = "items cannot be checked until the previous items are checked before.")
|
||||||
public boolean checkConstraintConsecutivePassedItems() {
|
public boolean isConsecutivePassedItemsConstraint() {
|
||||||
if (!isByItems()) {
|
if (!isByItems()) {
|
||||||
for (TaskQualityFormItem item : taskQualityFormItems) {
|
for (TaskQualityFormItem item : taskQualityFormItems) {
|
||||||
if (!isCorrectConsecutivePassed(item)) {
|
if (!isCorrectConsecutivePassed(item)) {
|
||||||
|
|
|
||||||
|
|
@ -24,10 +24,11 @@ package org.libreplan.business.qualityforms.entities;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
import javax.validation.constraints.AssertTrue;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.hibernate.validator.AssertTrue;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
import org.hibernate.validator.NotEmpty;
|
|
||||||
import org.hibernate.validator.NotNull;
|
|
||||||
import org.libreplan.business.INewObject;
|
import org.libreplan.business.INewObject;
|
||||||
|
|
||||||
public class TaskQualityFormItem implements INewObject {
|
public class TaskQualityFormItem implements INewObject {
|
||||||
|
|
@ -122,9 +123,8 @@ public class TaskQualityFormItem implements INewObject {
|
||||||
this.newObject = newObject;
|
this.newObject = newObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
@AssertTrue(message = "percentage should be greater than 0% and less than 100%")
|
@AssertTrue(message = "percentage should be greater than 0% and less than 100%")
|
||||||
public boolean checkConstraintQualityFormItemPercentage() {
|
public boolean isQualityFormItemPercentageConstraint() {
|
||||||
if (percentage == null) {
|
if (percentage == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -135,9 +135,8 @@ public class TaskQualityFormItem implements INewObject {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
@AssertTrue(message = "date not specified")
|
@AssertTrue(message = "date not specified")
|
||||||
public boolean checkConstraintIfDateCanBeNull() {
|
public boolean isIfDateCanBeNullConstraint() {
|
||||||
if ((passed == null) || (!passed)) {
|
if ((passed == null) || (!passed)) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.libreplan.business.requirements.entities;
|
package org.libreplan.business.requirements.entities;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.libreplan.business.common.BaseEntity;
|
import org.libreplan.business.common.BaseEntity;
|
||||||
import org.libreplan.business.orders.entities.HoursGroup;
|
import org.libreplan.business.orders.entities.HoursGroup;
|
||||||
import org.libreplan.business.orders.entities.OrderElement;
|
import org.libreplan.business.orders.entities.OrderElement;
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@
|
||||||
package org.libreplan.business.requirements.entities;
|
package org.libreplan.business.requirements.entities;
|
||||||
|
|
||||||
import org.apache.commons.lang.BooleanUtils;
|
import org.apache.commons.lang.BooleanUtils;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.libreplan.business.orders.entities.HoursGroup;
|
import org.libreplan.business.orders.entities.HoursGroup;
|
||||||
import org.libreplan.business.orders.entities.OrderElement;
|
import org.libreplan.business.orders.entities.OrderElement;
|
||||||
import org.libreplan.business.resources.entities.Criterion;
|
import org.libreplan.business.resources.entities.Criterion;
|
||||||
|
|
|
||||||
|
|
@ -39,8 +39,8 @@ import org.apache.commons.lang.Validate;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.hibernate.Criteria;
|
import org.hibernate.Criteria;
|
||||||
|
import org.hibernate.Session;
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
import org.hibernate.classic.Session;
|
|
||||||
import org.libreplan.business.common.IAdHocTransactionService;
|
import org.libreplan.business.common.IAdHocTransactionService;
|
||||||
import org.libreplan.business.common.IOnTransaction;
|
import org.libreplan.business.common.IOnTransaction;
|
||||||
import org.libreplan.business.resources.entities.Criterion;
|
import org.libreplan.business.resources.entities.Criterion;
|
||||||
|
|
|
||||||
|
|
@ -35,10 +35,10 @@ import org.apache.commons.collections.ComparatorUtils;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||||
import org.hibernate.validator.AssertTrue;
|
import javax.validation.constraints.AssertTrue;
|
||||||
import org.hibernate.validator.NotEmpty;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.hibernate.validator.Valid;
|
import javax.validation.Valid;
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
import org.libreplan.business.common.IntegrationEntity;
|
import org.libreplan.business.common.IntegrationEntity;
|
||||||
import org.libreplan.business.common.Registry;
|
import org.libreplan.business.common.Registry;
|
||||||
|
|
@ -424,7 +424,7 @@ public class Criterion extends IntegrationEntity implements ICriterion,
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message="a disabled resource has enabled subresources")
|
@AssertTrue(message="a disabled resource has enabled subresources")
|
||||||
public boolean checkConstraintActive() {
|
public boolean isActiveConstraint() {
|
||||||
|
|
||||||
if (!active) {
|
if (!active) {
|
||||||
for (Criterion c : children) {
|
for (Criterion c : children) {
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,8 @@ import java.util.Comparator;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||||
import org.hibernate.validator.AssertTrue;
|
import javax.validation.constraints.AssertTrue;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
import org.libreplan.business.common.IntegrationEntity;
|
import org.libreplan.business.common.IntegrationEntity;
|
||||||
import org.libreplan.business.common.Registry;
|
import org.libreplan.business.common.Registry;
|
||||||
|
|
@ -295,7 +295,7 @@ public class CriterionSatisfaction extends IntegrationEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "criterion satisfaction with end date before start")
|
@AssertTrue(message = "criterion satisfaction with end date before start")
|
||||||
public boolean checkConstraintPositiveTimeInterval() {
|
public boolean isPositiveTimeInterval() {
|
||||||
|
|
||||||
/* Check if it makes sense to check the constraint .*/
|
/* Check if it makes sense to check the constraint .*/
|
||||||
if (!isStartDateSpecified()) {
|
if (!isStartDateSpecified()) {
|
||||||
|
|
|
||||||
|
|
@ -28,12 +28,13 @@ import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import javax.validation.constraints.AssertTrue;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||||
import org.hibernate.validator.AssertTrue;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
import org.hibernate.validator.NotEmpty;
|
|
||||||
import org.hibernate.validator.NotNull;
|
|
||||||
import org.hibernate.validator.Valid;
|
|
||||||
import org.libreplan.business.advance.entities.AdvanceAssignment;
|
import org.libreplan.business.advance.entities.AdvanceAssignment;
|
||||||
import org.libreplan.business.common.IHumanIdentifiable;
|
import org.libreplan.business.common.IHumanIdentifiable;
|
||||||
import org.libreplan.business.common.IntegrationEntity;
|
import org.libreplan.business.common.IntegrationEntity;
|
||||||
|
|
@ -418,13 +419,13 @@ public class CriterionType extends IntegrationEntity implements
|
||||||
|
|
||||||
@AssertTrue(message="criterion codes must be unique inside a criterion " +
|
@AssertTrue(message="criterion codes must be unique inside a criterion " +
|
||||||
" type")
|
" type")
|
||||||
public boolean checkConstraintNonRepeatedCriterionCodes() {
|
public boolean isConstraintNonRepeatedCriterionCodesConstraint() {
|
||||||
return getFirstRepeatedCode(criterions) == null;
|
return getFirstRepeatedCode(criterions) == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message="criterion names must be unique inside a criterion " +
|
@AssertTrue(message="criterion names must be unique inside a criterion " +
|
||||||
" type")
|
" type")
|
||||||
public boolean checkConstraintNonRepeatedCriterionNames() {
|
public boolean isNonRepeatedCriterionNamesConstraint() {
|
||||||
|
|
||||||
Set<String> criterionNames = new HashSet<String>();
|
Set<String> criterionNames = new HashSet<String>();
|
||||||
|
|
||||||
|
|
@ -443,7 +444,7 @@ public class CriterionType extends IntegrationEntity implements
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message="Criterion Type name is already being used")
|
@AssertTrue(message="Criterion Type name is already being used")
|
||||||
public boolean checkConstraintUniqueCriterionTypeName() {
|
public boolean isUniqueCriterionTypeNameConstraint() {
|
||||||
|
|
||||||
/* Check if it makes sense to check the constraint .*/
|
/* Check if it makes sense to check the constraint .*/
|
||||||
if (!isNameSpecified()) {
|
if (!isNameSpecified()) {
|
||||||
|
|
@ -469,7 +470,7 @@ public class CriterionType extends IntegrationEntity implements
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message="criterion type does not allow hierarchy")
|
@AssertTrue(message="criterion type does not allow hierarchy")
|
||||||
public boolean checkConstraintAllowHierarchy() {
|
public boolean isAllowHierarchyConstraint() {
|
||||||
|
|
||||||
if (!allowHierarchy) {
|
if (!allowHierarchy) {
|
||||||
for (Criterion c : criterions) {
|
for (Criterion c : criterions) {
|
||||||
|
|
@ -484,7 +485,7 @@ public class CriterionType extends IntegrationEntity implements
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message="resource type does not allow enabled criteria")
|
@AssertTrue(message="resource type does not allow enabled criteria")
|
||||||
public boolean checkConstraintEnabled() {
|
public boolean isEnabledConstraint() {
|
||||||
|
|
||||||
if (!enabled) {
|
if (!enabled) {
|
||||||
for (Criterion c : criterions) {
|
for (Criterion c : criterions) {
|
||||||
|
|
@ -514,7 +515,7 @@ public class CriterionType extends IntegrationEntity implements
|
||||||
* @throws ChangeTypeCriterionTypeException
|
* @throws ChangeTypeCriterionTypeException
|
||||||
*/
|
*/
|
||||||
@AssertTrue(message = "Criteria of this criterion type have been assigned to some resource.")
|
@AssertTrue(message = "Criteria of this criterion type have been assigned to some resource.")
|
||||||
protected boolean checkConstraintChangeType() {
|
protected boolean isChangeTypeConstraint() {
|
||||||
/* Check the constraint. */
|
/* Check the constraint. */
|
||||||
ICriterionTypeDAO criterionTypeDAO = Registry.getCriterionTypeDAO();
|
ICriterionTypeDAO criterionTypeDAO = Registry.getCriterionTypeDAO();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,8 @@ import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.hibernate.validator.NotEmpty;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
import org.hibernate.validator.Valid;
|
import javax.validation.Valid;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Entity
|
* Entity
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,8 @@ import java.util.Date;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.hibernate.validator.AssertTrue;
|
import javax.validation.constraints.AssertTrue;
|
||||||
import org.hibernate.validator.Valid;
|
import javax.validation.Valid;
|
||||||
import org.libreplan.business.common.BaseEntity;
|
import org.libreplan.business.common.BaseEntity;
|
||||||
import org.libreplan.business.util.deepcopy.OnCopy;
|
import org.libreplan.business.util.deepcopy.OnCopy;
|
||||||
import org.libreplan.business.util.deepcopy.Strategy;
|
import org.libreplan.business.util.deepcopy.Strategy;
|
||||||
|
|
@ -167,12 +167,12 @@ public class MachineWorkersConfigurationUnit extends BaseEntity implements
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "Alpha must be greater than 0")
|
@AssertTrue(message = "Alpha must be greater than 0")
|
||||||
public boolean checkAlpha() {
|
public boolean isAlphaConstraint() {
|
||||||
return (this.alpha.compareTo(new BigDecimal(0)) > 0);
|
return (this.alpha.compareTo(new BigDecimal(0)) > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "All machine worker assignments must have a start date earlier than the end date")
|
@AssertTrue(message = "All machine worker assignments must have a start date earlier than the end date")
|
||||||
public boolean checkWorkerAssignmentsIntervalsProperlyDefined() {
|
public boolean isWorkerAssignmentsIntervalsProperlyDefinedConstraint() {
|
||||||
boolean correctIntervals = true;
|
boolean correctIntervals = true;
|
||||||
for (MachineWorkerAssignment each : workerAssignments) {
|
for (MachineWorkerAssignment each : workerAssignments) {
|
||||||
if (each.getStartDate() == null) {
|
if (each.getStartDate() == null) {
|
||||||
|
|
@ -186,7 +186,7 @@ public class MachineWorkersConfigurationUnit extends BaseEntity implements
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "The same resource is assigned twice inside an interval")
|
@AssertTrue(message = "The same resource is assigned twice inside an interval")
|
||||||
public boolean checkConstraintUniqueWorkerAssignmentInInterval() {
|
public boolean isUniqueWorkerAssignmentInIntervalConstraint() {
|
||||||
boolean unique = true;
|
boolean unique = true;
|
||||||
Interval range = null;
|
Interval range = null;
|
||||||
for (MachineWorkerAssignment each : workerAssignments) {
|
for (MachineWorkerAssignment each : workerAssignments) {
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
package org.libreplan.business.resources.entities;
|
package org.libreplan.business.resources.entities;
|
||||||
|
|
||||||
|
import static org.libreplan.business.common.exceptions.ValidationException.invalidValue;
|
||||||
import static org.libreplan.business.workingday.EffortDuration.zero;
|
import static org.libreplan.business.workingday.EffortDuration.zero;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
@ -35,12 +36,12 @@ import java.util.ListIterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import javax.validation.constraints.AssertFalse;
|
||||||
|
import javax.validation.constraints.AssertTrue;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.lang.Validate;
|
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.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
import org.libreplan.business.calendars.entities.AvailabilityTimeLine;
|
import org.libreplan.business.calendars.entities.AvailabilityTimeLine;
|
||||||
import org.libreplan.business.calendars.entities.BaseCalendar;
|
import org.libreplan.business.calendars.entities.BaseCalendar;
|
||||||
|
|
@ -989,9 +990,8 @@ public abstract class Resource extends IntegrationEntity implements
|
||||||
if (!canAddSatisfaction(satisfaction, satisfactions)) {
|
if (!canAddSatisfaction(satisfaction, satisfactions)) {
|
||||||
String message = getReasonForNotAddingSatisfaction(satisfaction
|
String message = getReasonForNotAddingSatisfaction(satisfaction
|
||||||
.getCriterion().getType());
|
.getCriterion().getType());
|
||||||
final InvalidValue invalidValue = new InvalidValue(message,
|
throw new ValidationException(invalidValue(message, "resource",
|
||||||
CriterionSatisfaction.class, "resource", this, satisfaction);
|
this, satisfaction));
|
||||||
throw new ValidationException(invalidValue);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1063,7 +1063,7 @@ public abstract class Resource extends IntegrationEntity implements
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message="Some criterion satisfactions overlap in time")
|
@AssertTrue(message="Some criterion satisfactions overlap in time")
|
||||||
public boolean checkConstraintCriterionSatisfactionsOverlapping() {
|
public boolean isCriterionSatisfactionsOverlappingConstraint() {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check if time intervals in criterion satisfactions are correct in
|
* Check if time intervals in criterion satisfactions are correct in
|
||||||
|
|
@ -1072,8 +1072,8 @@ public abstract class Resource extends IntegrationEntity implements
|
||||||
*/
|
*/
|
||||||
for (CriterionSatisfaction i : getCriterionSatisfactions()) {
|
for (CriterionSatisfaction i : getCriterionSatisfactions()) {
|
||||||
|
|
||||||
if (!(i.isStartDateSpecified() &&
|
if (!(i.isStartDateSpecified() && i
|
||||||
i.checkConstraintPositiveTimeInterval())) {
|
.isPositiveTimeInterval())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1093,7 +1093,7 @@ public abstract class Resource extends IntegrationEntity implements
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertFalse(message="Some cost category assignments overlap in time")
|
@AssertFalse(message="Some cost category assignments overlap in time")
|
||||||
public boolean checkConstraintAssignmentsOverlapping() {
|
public boolean isAssignmentsOverlappingConstraint() {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check if time intervals in cost assignments are correct in isolation.
|
* Check if time intervals in cost assignments are correct in isolation.
|
||||||
|
|
@ -1101,7 +1101,7 @@ public abstract class Resource extends IntegrationEntity implements
|
||||||
*/
|
*/
|
||||||
for (ResourcesCostCategoryAssignment each : getResourcesCostCategoryAssignments()) {
|
for (ResourcesCostCategoryAssignment each : getResourcesCostCategoryAssignments()) {
|
||||||
if (!(each.isInitDateSpecified() && each
|
if (!(each.isInitDateSpecified() && each
|
||||||
.checkConstraintPositiveTimeInterval())) {
|
.isPositiveTimeInterval())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1130,7 +1130,7 @@ public abstract class Resource extends IntegrationEntity implements
|
||||||
|
|
||||||
@AssertTrue(message="there exist criterion satisfactions referring to " +
|
@AssertTrue(message="there exist criterion satisfactions referring to " +
|
||||||
"criterion types not applicable to this resource")
|
"criterion types not applicable to this resource")
|
||||||
public boolean checkConstraintCriterionSatisfactionsWithCorrectType() {
|
public boolean isCriterionSatisfactionsWithCorrectTypeConstraint() {
|
||||||
|
|
||||||
for (CriterionSatisfaction c : getCriterionSatisfactions()) {
|
for (CriterionSatisfaction c : getCriterionSatisfactions()) {
|
||||||
if (!isCriterionSatisfactionOfCorrectType(c)) {
|
if (!isCriterionSatisfactionOfCorrectType(c)) {
|
||||||
|
|
@ -1144,13 +1144,13 @@ public abstract class Resource extends IntegrationEntity implements
|
||||||
|
|
||||||
@AssertTrue(message="criterion satisfaction codes must be unique inside " +
|
@AssertTrue(message="criterion satisfaction codes must be unique inside " +
|
||||||
"a resource")
|
"a resource")
|
||||||
public boolean checkConstraintNonRepeatedCriterionSatisfactionCodes() {
|
public boolean isNonRepeatedCriterionSatisfactionCodesConstraint() {
|
||||||
return getFirstRepeatedCode(criterionSatisfactions) == null;
|
return getFirstRepeatedCode(criterionSatisfactions) == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message="resource cost category assignments codes must be " +
|
@AssertTrue(message="resource cost category assignments codes must be " +
|
||||||
"unique inside a resource")
|
"unique inside a resource")
|
||||||
public boolean checkConstraintNonRepeatedResourcesCostCategoryAssignmentCodes() {
|
public boolean isNonRepeatedResourcesCostCategoryAssignmentCodesConstraint() {
|
||||||
return getFirstRepeatedCode(resourcesCostCategoryAssignments) == null;
|
return getFirstRepeatedCode(resourcesCostCategoryAssignments) == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1189,7 +1189,7 @@ public abstract class Resource extends IntegrationEntity implements
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "You have exceeded the maximum limit of resources")
|
@AssertTrue(message = "You have exceeded the maximum limit of resources")
|
||||||
public boolean checkMaxResources() {
|
public boolean isMaxResourcesConstraint() {
|
||||||
return Registry.getTransactionService()
|
return Registry.getTransactionService()
|
||||||
.runOnAnotherReadOnlyTransaction(new IOnTransaction<Boolean>() {
|
.runOnAnotherReadOnlyTransaction(new IOnTransaction<Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,8 @@ package org.libreplan.business.resources.entities;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.hibernate.validator.AssertTrue;
|
import javax.validation.constraints.AssertTrue;
|
||||||
|
|
||||||
import org.libreplan.business.common.Registry;
|
import org.libreplan.business.common.Registry;
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -90,12 +91,12 @@ public class VirtualWorker extends Worker {
|
||||||
|
|
||||||
@AssertTrue
|
@AssertTrue
|
||||||
@Override
|
@Override
|
||||||
public boolean checkConstraintUniqueFiscalCode() {
|
public boolean isUniqueFiscalCodeConstraint() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "Virtual worker group name must be unique")
|
@AssertTrue(message = "Virtual worker group name must be unique")
|
||||||
public boolean checkConstraintUniqueVirtualGroupName() {
|
public boolean isUniqueVirtualGroupNameConstraint() {
|
||||||
|
|
||||||
List<Worker> list = Registry.getWorkerDAO()
|
List<Worker> list = Registry.getWorkerDAO()
|
||||||
.findByFirstNameAnotherTransactionCaseInsensitive(
|
.findByFirstNameAnotherTransactionCaseInsensitive(
|
||||||
|
|
|
||||||
|
|
@ -23,9 +23,9 @@ package org.libreplan.business.resources.entities;
|
||||||
|
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.hibernate.validator.AssertTrue;
|
import javax.validation.constraints.AssertTrue;
|
||||||
import org.hibernate.validator.NotEmpty;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
import org.hibernate.validator.Valid;
|
import javax.validation.Valid;
|
||||||
import org.libreplan.business.common.Registry;
|
import org.libreplan.business.common.Registry;
|
||||||
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
|
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
|
||||||
import org.libreplan.business.users.daos.IUserDAO;
|
import org.libreplan.business.users.daos.IUserDAO;
|
||||||
|
|
@ -159,7 +159,7 @@ public class Worker extends Resource {
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "ID already used. It has to be be unique")
|
@AssertTrue(message = "ID already used. It has to be be unique")
|
||||||
public boolean checkConstraintUniqueFiscalCode() {
|
public boolean isUniqueFiscalCodeConstraint() {
|
||||||
if (!areFirstNameSurnameNifSpecified()) {
|
if (!areFirstNameSurnameNifSpecified()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -222,7 +222,7 @@ public class Worker extends Resource {
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "User already bound to other worker")
|
@AssertTrue(message = "User already bound to other worker")
|
||||||
public boolean checkConstraintUserNotBoundToOtherWorker() {
|
public boolean isUserNotBoundToOtherWorkerConstraint() {
|
||||||
if (user == null || user.isNewObject()) {
|
if (user == null || user.isNewObject()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -246,7 +246,7 @@ public class Worker extends Resource {
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "Queue-based resources cannot be bound to any user")
|
@AssertTrue(message = "Queue-based resources cannot be bound to any user")
|
||||||
public boolean checkConstraintLimitingResourceNotBoundToUser() {
|
public boolean isLimitingResourceNotBoundToUserConstraint() {
|
||||||
if (isLimitingResource()) {
|
if (isLimitingResource()) {
|
||||||
return user == null;
|
return user == null;
|
||||||
}
|
}
|
||||||
|
|
@ -254,7 +254,7 @@ public class Worker extends Resource {
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "Virtual resources cannot be bound to any user")
|
@AssertTrue(message = "Virtual resources cannot be bound to any user")
|
||||||
public boolean checkConstraintVirtualResourceNotBoundToUser() {
|
public boolean isVirtualResourceNotBoundToUserConstraint() {
|
||||||
if (isVirtual()) {
|
if (isVirtual()) {
|
||||||
return user == null;
|
return user == null;
|
||||||
}
|
}
|
||||||
|
|
@ -269,7 +269,7 @@ public class Worker extends Resource {
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "Bound user does not have the proper role")
|
@AssertTrue(message = "Bound user does not have the proper role")
|
||||||
public boolean checkConstraintBoundUserHaveProperRole() {
|
public boolean isBoundUserHaveProperRoleConstraint() {
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@
|
||||||
package org.libreplan.business.scenarios.entities;
|
package org.libreplan.business.scenarios.entities;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.libreplan.business.common.BaseEntity;
|
import org.libreplan.business.common.BaseEntity;
|
||||||
import org.libreplan.business.orders.entities.Order;
|
import org.libreplan.business.orders.entities.Order;
|
||||||
|
|
|
||||||
|
|
@ -33,8 +33,8 @@ import java.util.Set;
|
||||||
import org.apache.commons.lang.ObjectUtils;
|
import org.apache.commons.lang.ObjectUtils;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.hibernate.validator.AssertTrue;
|
import javax.validation.constraints.AssertTrue;
|
||||||
import org.hibernate.validator.NotEmpty;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.libreplan.business.common.BaseEntity;
|
import org.libreplan.business.common.BaseEntity;
|
||||||
import org.libreplan.business.common.IHumanIdentifiable;
|
import org.libreplan.business.common.IHumanIdentifiable;
|
||||||
|
|
@ -143,7 +143,7 @@ public class Scenario extends BaseEntity implements IHumanIdentifiable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "name is already used")
|
@AssertTrue(message = "name is already used")
|
||||||
public boolean checkConstraintUniqueName() {
|
public boolean isUniqueNameConstraint() {
|
||||||
if (StringUtils.isBlank(name)) {
|
if (StringUtils.isBlank(name)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,10 +33,10 @@ import org.apache.commons.lang.Validate;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.hibernate.NonUniqueResultException;
|
import org.hibernate.NonUniqueResultException;
|
||||||
import org.hibernate.validator.AssertTrue;
|
import javax.validation.constraints.AssertTrue;
|
||||||
import org.hibernate.validator.Min;
|
import javax.validation.constraints.Min;
|
||||||
import org.hibernate.validator.NotEmpty;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
import org.hibernate.validator.Valid;
|
import javax.validation.Valid;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.Days;
|
import org.joda.time.Days;
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
|
|
@ -63,7 +63,7 @@ import org.libreplan.business.requirements.entities.DirectCriterionRequirement;
|
||||||
import org.libreplan.business.requirements.entities.IndirectCriterionRequirement;
|
import org.libreplan.business.requirements.entities.IndirectCriterionRequirement;
|
||||||
import org.libreplan.business.templates.daos.IOrderElementTemplateDAO;
|
import org.libreplan.business.templates.daos.IOrderElementTemplateDAO;
|
||||||
import org.libreplan.business.trees.ITreeNode;
|
import org.libreplan.business.trees.ITreeNode;
|
||||||
import org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException;
|
import org.springframework.orm.hibernate4.HibernateOptimisticLockingFailureException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||||
|
|
@ -481,7 +481,7 @@ public abstract class OrderElementTemplate extends BaseEntity implements
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "template name is already in use")
|
@AssertTrue(message = "template name is already in use")
|
||||||
public boolean checkConstraintUniqueRootTemplateName() {
|
public boolean isUniqueRootTemplateNameConstraint() {
|
||||||
if (getParent() != null) {
|
if (getParent() != null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.hibernate.validator.Valid;
|
import javax.validation.Valid;
|
||||||
import org.libreplan.business.i18n.I18nHelper;
|
import org.libreplan.business.i18n.I18nHelper;
|
||||||
import org.libreplan.business.orders.entities.CriterionRequirementOrderElementHandler;
|
import org.libreplan.business.orders.entities.CriterionRequirementOrderElementHandler;
|
||||||
import org.libreplan.business.orders.entities.HoursGroup;
|
import org.libreplan.business.orders.entities.HoursGroup;
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,8 @@ import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.hibernate.validator.Valid;
|
import javax.validation.Valid;
|
||||||
import org.libreplan.business.orders.entities.HoursGroup;
|
import org.libreplan.business.orders.entities.HoursGroup;
|
||||||
import org.libreplan.business.orders.entities.OrderElement;
|
import org.libreplan.business.orders.entities.OrderElement;
|
||||||
import org.libreplan.business.orders.entities.OrderLine;
|
import org.libreplan.business.orders.entities.OrderLine;
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ package org.libreplan.business.templates.entities;
|
||||||
|
|
||||||
import static org.libreplan.business.i18n.I18nHelper._;
|
import static org.libreplan.business.i18n.I18nHelper._;
|
||||||
|
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.libreplan.business.calendars.entities.BaseCalendar;
|
import org.libreplan.business.calendars.entities.BaseCalendar;
|
||||||
import org.libreplan.business.orders.entities.Order;
|
import org.libreplan.business.orders.entities.Order;
|
||||||
import org.libreplan.business.orders.entities.OrderElement;
|
import org.libreplan.business.orders.entities.OrderElement;
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ public class ProfileDAO extends GenericDAOHibernate<Profile, Long> implements
|
||||||
query.setParameterList("profiles", Collections.singleton(profile));
|
query.setParameterList("profiles", Collections.singleton(profile));
|
||||||
if (!query.list().isEmpty()) {
|
if (!query.list().isEmpty()) {
|
||||||
throw ValidationException
|
throw ValidationException
|
||||||
.invalidValue(
|
.invalidValueException(
|
||||||
"Cannot delete profile. It is being used at this moment by some users.",
|
"Cannot delete profile. It is being used at this moment by some users.",
|
||||||
profile);
|
profile);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
package org.libreplan.business.users.entities;
|
package org.libreplan.business.users.entities;
|
||||||
|
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.libreplan.business.common.BaseEntity;
|
import org.libreplan.business.common.BaseEntity;
|
||||||
import org.libreplan.business.orders.entities.Order;
|
import org.libreplan.business.orders.entities.Order;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,8 @@ package org.libreplan.business.users.entities;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.hibernate.validator.AssertTrue;
|
import javax.validation.constraints.AssertTrue;
|
||||||
import org.hibernate.validator.NotEmpty;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
import org.libreplan.business.common.BaseEntity;
|
import org.libreplan.business.common.BaseEntity;
|
||||||
import org.libreplan.business.common.IHumanIdentifiable;
|
import org.libreplan.business.common.IHumanIdentifiable;
|
||||||
import org.libreplan.business.common.Registry;
|
import org.libreplan.business.common.Registry;
|
||||||
|
|
@ -87,7 +87,7 @@ public class Profile extends BaseEntity implements IHumanIdentifiable{
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message="profile name is already being used by another profile")
|
@AssertTrue(message="profile name is already being used by another profile")
|
||||||
public boolean checkConstraintUniqueLoginName() {
|
public boolean isUniqueLoginNameConstraint() {
|
||||||
|
|
||||||
IProfileDAO dao = Registry.getProfileDAO();
|
IProfileDAO dao = Registry.getProfileDAO();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,8 @@ import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.hibernate.validator.AssertTrue;
|
import javax.validation.constraints.AssertTrue;
|
||||||
import org.hibernate.validator.NotEmpty;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
import org.libreplan.business.common.BaseEntity;
|
import org.libreplan.business.common.BaseEntity;
|
||||||
import org.libreplan.business.common.IHumanIdentifiable;
|
import org.libreplan.business.common.IHumanIdentifiable;
|
||||||
import org.libreplan.business.common.IOnTransaction;
|
import org.libreplan.business.common.IOnTransaction;
|
||||||
|
|
@ -246,7 +246,7 @@ public class User extends BaseEntity implements IHumanIdentifiable{
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "username is already being used by another user")
|
@AssertTrue(message = "username is already being used by another user")
|
||||||
public boolean checkConstraintUniqueLoginName() {
|
public boolean isUniqueLoginNameConstraint() {
|
||||||
|
|
||||||
IUserDAO userDAO = Registry.getUserDAO();
|
IUserDAO userDAO = Registry.getUserDAO();
|
||||||
|
|
||||||
|
|
@ -378,7 +378,7 @@ public class User extends BaseEntity implements IHumanIdentifiable{
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "You have exceeded the maximum limit of users")
|
@AssertTrue(message = "You have exceeded the maximum limit of users")
|
||||||
public boolean checkMaxUsers() {
|
public boolean isMaxUsersConstraint() {
|
||||||
return Registry.getTransactionService()
|
return Registry.getTransactionService()
|
||||||
.runOnAnotherReadOnlyTransaction(new IOnTransaction<Boolean>() {
|
.runOnAnotherReadOnlyTransaction(new IOnTransaction<Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ import java.util.NoSuchElementException;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||||
import org.hibernate.validator.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.Days;
|
import org.joda.time.Days;
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue