Merge libreplan-business module with ZK branch.

Code refactoring.
This commit is contained in:
Vova Perebykivskyi 2016-10-17 16:54:49 +03:00 committed by Dgray16
parent 1fe6156527
commit 0f25b227fe
154 changed files with 3312 additions and 4073 deletions

View file

@ -33,12 +33,26 @@ import org.zkoss.ganttz.data.IDependency;
/**
* Represents a dependency in the domain.
*
* @author Óscar González Fernández <ogonzalez@igalia.com>
*/
public class DomainDependency<T> implements IDependency<T> {
private static final Log LOG = LogFactory.getLog(DomainDependency.class);
private final T source;
private final T destination;
private final DependencyType type;
private DomainDependency(T source, T destination, DependencyType type) {
super();
this.source = source;
this.destination = destination;
this.type = type;
}
public static <T> List<Dependency> toDependencies(
IDomainAndBeansMapper<T> mapper, Collection<DomainDependency<T>> dependencies) {
@ -55,20 +69,7 @@ public class DomainDependency<T> implements IDependency<T> {
}
public static <T> DomainDependency<T> createDependency(T source, T destination, DependencyType type) {
return new DomainDependency<T>(source, destination, type);
}
private final T source;
private final T destination;
private final DependencyType type;
private DomainDependency(T source, T destination, DependencyType type) {
super();
this.source = source;
this.destination = destination;
this.type = type;
return new DomainDependency<>(source, destination, type);
}
public T getSource() {

View file

@ -1,5 +1,6 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
@ -79,7 +80,7 @@
<artifactId>junit</artifactId>
</dependency>
<!-- datasource for testing -->
<!-- Datasource for testing -->
<dependency>
<groupId>com.jolbox</groupId>
<artifactId>bonecp</artifactId>
@ -115,6 +116,11 @@
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
</dependency>
<!-- Log4j -->
<dependency>
<groupId>org.slf4j</groupId>
@ -127,12 +133,6 @@
<artifactId>joda-time</artifactId>
</dependency>
<!-- DBUnit -->
<dependency>
<groupId>org.dbunit</groupId>
<artifactId>dbunit</artifactId>
</dependency>
<!-- Liquibase -->
<dependency>
<groupId>org.liquibase</groupId>

View file

@ -29,11 +29,10 @@ import java.lang.annotation.Target;
/**
* <p>
* It can be applied to a {@link IDataBootstrap} to indicate the order in which it will be executed.
* It's ensured that if a data bootstrap has a priority value greater than another one it will be executed before.
*
* If two data bootstraps have the same priority value the order is unspecified.
* If a data bootstrap doesn't have this annotation it's like it would have a value of zero.
* It can be applied to a {@link IDataBootstrap} to indicate the order in which it will be executed.
* It's ensured that if a data bootstrap has a priority value greater than another one it will be executed before.
* If two data bootstraps have the same priority value the order is unspecified.
* If a data bootstrap doesn't have this annotation it's like it would have a value of zero.
* </p>
*
* It accepts negative values.

View file

@ -24,12 +24,13 @@ package org.libreplan.business.advance.bootstrap;
import org.libreplan.business.IDataBootstrap;
import org.libreplan.business.advance.daos.IAdvanceTypeDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
@Component
@Scope("singleton")
@Scope(BeanDefinition.SCOPE_SINGLETON)
public class DefaultAdvanceTypesBootstrapListener implements IDataBootstrap {
@Autowired

View file

@ -91,7 +91,7 @@ public class AdvanceType extends BaseEntity implements IHumanIdentifiable{
private Boolean qualityForm = false;
private IAdvanceTypeDAO avancedTypeDAO = Registry.getAdvanceTypeDao();
private IAdvanceTypeDAO advanceTypeDAO = Registry.getAdvanceTypeDao();
private boolean readOnly = false;
@ -255,7 +255,7 @@ public class AdvanceType extends BaseEntity implements IHumanIdentifiable{
}
if ( isNewObject() ) {
return !avancedTypeDAO.existsByNameInAnotherTransaction(unitName);
return !advanceTypeDAO.existsByNameInAnotherTransaction(unitName);
} else {
return checkNotExistsOrIsTheSame();
}
@ -263,7 +263,7 @@ public class AdvanceType extends BaseEntity implements IHumanIdentifiable{
private boolean checkNotExistsOrIsTheSame() {
try {
AdvanceType advanceType = avancedTypeDAO.findUniqueByNameInAnotherTransaction(unitName);
AdvanceType advanceType = advanceTypeDAO.findUniqueByNameInAnotherTransaction(unitName);
return advanceType.getId().equals(getId());
} catch (InstanceNotFoundException e) {

View file

@ -38,8 +38,7 @@ import org.libreplan.business.orders.entities.OrderElement;
import org.libreplan.business.planner.entities.consolidations.NonCalculatedConsolidation;
/**
* Represents an {@link AdvanceAssignment} that is own of this
* {@link OrderElement}.
* Represents an {@link AdvanceAssignment} that is own of this {@link OrderElement}.
*
* @author Manuel Rego Casasnovas <mrego@igalia.com>
*/
@ -52,7 +51,7 @@ public class DirectAdvanceAssignment extends AdvanceAssignment {
}
public static DirectAdvanceAssignment create(boolean reportGlobalAdvance,
BigDecimal maxValue) {
BigDecimal maxValue) {
DirectAdvanceAssignment advanceAssignment = new DirectAdvanceAssignment(
reportGlobalAdvance, maxValue);
advanceAssignment.setNewObject(true);
@ -62,8 +61,7 @@ public class DirectAdvanceAssignment extends AdvanceAssignment {
private BigDecimal maxValue;
@Valid
private SortedSet<AdvanceMeasurement> advanceMeasurements = new TreeSet<AdvanceMeasurement>(
new AdvanceMeasurementComparator());
private SortedSet<AdvanceMeasurement> advanceMeasurements = new TreeSet<>(new AdvanceMeasurementComparator());
@Valid
private Set<NonCalculatedConsolidation> nonCalculatedConsolidations = new HashSet<NonCalculatedConsolidation>();
@ -75,7 +73,7 @@ public class DirectAdvanceAssignment extends AdvanceAssignment {
}
private DirectAdvanceAssignment(boolean reportGlobalAdvance,
BigDecimal maxValue) {
BigDecimal maxValue) {
super(reportGlobalAdvance);
this.maxValue = maxValue;
this.maxValue.setScale(2, BigDecimal.ROUND_HALF_UP);
@ -207,7 +205,7 @@ public class DirectAdvanceAssignment extends AdvanceAssignment {
&& (currentAdvance.getDate() != null)
&& (nextAdvance.getDate() != null)
&& (currentAdvance.getValue().compareTo(
nextAdvance.getValue()) < 0)) {
nextAdvance.getValue()) < 0)) {
return false;
}
currentAdvance = nextAdvance;

View file

@ -32,67 +32,54 @@ import org.libreplan.business.common.IntegrationEntity;
import org.libreplan.business.common.Registry;
/**
* Stores information about activating periods, that define the availability of
* the resource.
* Stores information about activating periods, that define the availability of the resource.
*
* @author Manuel Rego Casasnovas <mrego@igalia.com>
*/
public class CalendarAvailability extends IntegrationEntity {
public static CalendarAvailability craete() {
return create(new CalendarAvailability(new LocalDate(), null));
}
public static CalendarAvailability craete(Date startDate, Date endDate) {
return create(new CalendarAvailability(new LocalDate(startDate),
new LocalDate(endDate)));
}
public static CalendarAvailability create(LocalDate startDate,
LocalDate endDate) {
return create(new CalendarAvailability(startDate, endDate));
}
public static final Comparator<CalendarAvailability> BY_START_DATE_COMPARATOR =
(o1, o2) -> o1.getStartDate().compareTo(o2.getStartDate());
@NotNull
private LocalDate startDate;
private LocalDate endDate;
public static final Comparator<CalendarAvailability> BY_START_DATE_COMPARATOR = new Comparator<CalendarAvailability>() {
@Override
public int compare(CalendarAvailability o1, CalendarAvailability o2) {
return o1.getStartDate().compareTo(o2.getStartDate());
}
};
/**
* Constructor for hibernate. Do not use!
*/
public CalendarAvailability() {
}
public CalendarAvailability() {}
private CalendarAvailability(LocalDate startDate, LocalDate endDate)
throws IllegalArgumentException {
private CalendarAvailability(LocalDate startDate, LocalDate endDate) {
setStartDate(startDate);
setEndDate(endDate);
}
public static CalendarAvailability create() {
return create(new CalendarAvailability(new LocalDate(), null));
}
public static CalendarAvailability create(Date startDate, Date endDate) {
return create(new CalendarAvailability(new LocalDate(startDate), new LocalDate(endDate)));
}
public static CalendarAvailability create(LocalDate startDate, LocalDate endDate) {
return create(new CalendarAvailability(startDate, endDate));
}
public LocalDate getStartDate() {
return startDate;
}
public void setStartDate(LocalDate startDate)
throws IllegalArgumentException {
public void setStartDate(LocalDate startDate) {
if (startDate == null) {
throw new IllegalArgumentException("Start date must not be null");
}
if (endDate != null) {
if (startDate.compareTo(endDate) > 0) {
throw new IllegalArgumentException(
"End date must be greater or equal than start date");
}
if (endDate != null && startDate.compareTo(endDate) > 0) {
throw new IllegalArgumentException("End date must be greater or equal than start date");
}
this.startDate = startDate;
}
@ -100,26 +87,16 @@ public class CalendarAvailability extends IntegrationEntity {
return endDate;
}
public void setEndDate(LocalDate endDate) throws IllegalArgumentException {
if (endDate != null) {
if (startDate.compareTo(endDate) > 0) {
throw new IllegalArgumentException(
"End date must be greater or equal than start date");
}
public void setEndDate(LocalDate endDate) {
if (endDate != null && startDate.compareTo(endDate) > 0) {
throw new IllegalArgumentException("End date must be greater or equal than start date");
}
this.endDate = endDate;
}
public boolean isActive(LocalDate date) {
if (startDate.compareTo(date) > 0) {
return false;
}
return startDate.compareTo(date) <= 0 && !((endDate != null) && (endDate.compareTo(date) < 0));
if ((endDate != null) && (endDate.compareTo(date) < 0)) {
return false;
}
return true;
}
@Override
@ -127,8 +104,7 @@ public class CalendarAvailability extends IntegrationEntity {
return Registry.getCalendarAvailabilityDAO();
}
public boolean isActiveBetween(LocalDate filterStartDate,
LocalDate filterEndDate) {
public boolean isActiveBetween(LocalDate filterStartDate, LocalDate filterEndDate) {
if (filterStartDate == null && filterEndDate == null) {
return true;
}
@ -137,29 +113,25 @@ public class CalendarAvailability extends IntegrationEntity {
if (endDate == null) {
return startDate.compareTo(filterEndDate) <= 0;
}
return startDate.compareTo(filterEndDate) <= 0
|| endDate.compareTo(filterEndDate) <= 0;
return startDate.compareTo(filterEndDate) <= 0 || endDate.compareTo(filterEndDate) <= 0;
}
if (filterEndDate == null) {
if (endDate == null) {
return true;
}
return startDate.compareTo(filterStartDate) >= 0
|| endDate.compareTo(filterStartDate) >= 0;
return endDate == null || startDate.compareTo(filterStartDate) >= 0 ||
endDate.compareTo(filterStartDate) >= 0;
}
if (endDate == null) {
return startDate.compareTo(filterStartDate) <= 0
|| startDate.compareTo(filterEndDate) <= 0;
return startDate.compareTo(filterStartDate) <= 0 || startDate.compareTo(filterEndDate) <= 0;
}
Interval filterPeriod = new Interval(
filterStartDate.toDateTimeAtStartOfDay(), filterEndDate
.plusDays(1).toDateTimeAtStartOfDay());
Interval activationPeriod = new Interval(
startDate.toDateTimeAtStartOfDay(), endDate.plusDays(1)
.toDateTimeAtStartOfDay());
Interval filterPeriod = new Interval(filterStartDate.toDateTimeAtStartOfDay(),
filterEndDate.plusDays(1).toDateTimeAtStartOfDay());
Interval activationPeriod = new Interval(startDate.toDateTimeAtStartOfDay(),
endDate.plusDays(1).toDateTimeAtStartOfDay());
return filterPeriod.overlaps(activationPeriod);
}

View file

@ -25,6 +25,7 @@ import org.libreplan.business.calendars.daos.ICalendarExceptionTypeDAO;
import org.libreplan.business.common.daos.IEntitySequenceDAO;
import org.libreplan.business.common.entities.EntityNameEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
@ -35,7 +36,7 @@ import org.springframework.transaction.annotation.Transactional;
* @author Manuel Rego Casasnovas <mrego@igalia.com>
*/
@Component
@Scope("singleton")
@Scope(BeanDefinition.SCOPE_SINGLETON)
public class CalendarBootstrap implements ICalendarBootstrap {
@Autowired

View file

@ -23,8 +23,6 @@ package org.libreplan.business.calendars.entities;
import static org.libreplan.business.i18n.I18nHelper._;
import java.util.EnumMap;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
@ -38,7 +36,6 @@ import org.libreplan.business.common.IntegrationEntity;
import org.libreplan.business.common.Registry;
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
import org.libreplan.business.workingday.EffortDuration;
import org.libreplan.business.workingday.EffortDuration.Granularity;
import org.springframework.orm.hibernate5.HibernateOptimisticLockingFailureException;
/**
@ -57,6 +54,18 @@ public class CalendarExceptionType extends IntegrationEntity implements IHumanId
private Capacity capacity = Capacity.zero();
/**
* Constructor for hibernate. Do not use!
*/
protected CalendarExceptionType() {}
public CalendarExceptionType(String name, CalendarExceptionTypeColor color, Boolean notOverAssignable) {
this.name = name;
this.color = color;
this.capacity = Capacity.zero();
this.capacity = this.capacity.overAssignableWithoutLimit(!BooleanUtils.isTrue(notOverAssignable));
}
public static CalendarExceptionType create() {
return create(new CalendarExceptionType());
}
@ -92,19 +101,6 @@ public class CalendarExceptionType extends IntegrationEntity implements IHumanId
return create(calendarExceptionType, code);
}
/**
* Constructor for hibernate. Do not use!
*/
protected CalendarExceptionType() {
}
public CalendarExceptionType(String name, CalendarExceptionTypeColor color, Boolean notOverAssignable) {
this.name = name;
this.color = color;
this.capacity = Capacity.zero();
this.capacity = this.capacity.overAssignableWithoutLimit(!BooleanUtils.isTrue(notOverAssignable));
}
public boolean isUpdatable() {
return this.updatable;
}
@ -155,18 +151,6 @@ public class CalendarExceptionType extends IntegrationEntity implements IHumanId
return capacity.getStandardEffort();
}
private String asString(EffortDuration duration) {
if ( duration == null ) {
return "";
}
EnumMap<Granularity, Integer> values = duration.decompose();
Integer hours = values.get(Granularity.HOURS);
Integer minutes = values.get(Granularity.MINUTES);
return hours + ":" + minutes;
}
public void setDuration(EffortDuration duration) {
this.capacity = this.capacity.withStandardEffort(duration);
}
@ -191,12 +175,10 @@ public class CalendarExceptionType extends IntegrationEntity implements IHumanId
calendarExceptionTypeDAO.findUniqueByNameAnotherTransaction(name);
return calendarExceptionType.getId().equals(getId());
} catch (InstanceNotFoundException e) {
} catch (InstanceNotFoundException | HibernateOptimisticLockingFailureException e) {
return true;
} catch (NonUniqueResultException e) {
return false;
} catch (HibernateOptimisticLockingFailureException e) {
return true;
}
}

View file

@ -22,8 +22,7 @@ package org.libreplan.business.calendars.entities;
import static org.libreplan.business.i18n.I18nHelper._;
/**
* Enum representing the possible colors to choose for a
* {@link CalendarExceptionType}
* Enum representing the possible colors to choose for a {@link CalendarExceptionType}.
*
* @author Manuel Rego Casasnovas <rego@igalia.com>
*/
@ -39,7 +38,9 @@ public enum CalendarExceptionTypeColor {
PURPLE(_("purple"), "#801a80", "#b38eb3");
private final String name;
private final String colorOwnException;
private final String colorDerivedException;
CalendarExceptionTypeColor(String name, String colorOwnException, String colorDerivedException) {

View file

@ -33,13 +33,18 @@ import org.libreplan.business.workingday.EffortDuration.Granularity;
/**
* This class is intended as a Hibernate component. It's formed by two
* components, the standard effort and the allowed extra effort. It represents
* the capacity for a resource.
* This class is intended as a Hibernate component.
* It's formed by two components, the standard effort and the allowed extra effort.
* It represents the capacity for a resource.
*
* @author Óscar González Fernández <ogonzalez@igalia.com>
*/
public class Capacity {
private EffortDuration standardEffort;
private EffortDuration allowedExtraEffort;
public static Capacity sum(Capacity... capacities) {
return sum(Arrays.asList(capacities));
}
@ -56,8 +61,7 @@ public class Capacity {
}
public static Capacity min(Capacity a, Capacity b) {
return new Capacity(EffortDuration.min(a.getStandardEffort(),
b.getStandardEffort()), minExtraEffort(a, b));
return new Capacity(EffortDuration.min(a.getStandardEffort(), b.getStandardEffort()), minExtraEffort(a, b));
}
private static EffortDuration minExtraEffort(Capacity a, Capacity b) {
@ -90,17 +94,14 @@ public class Capacity {
}
private static Capacity noCapacity() {
return Capacity.create(EffortDuration.zero())
.notOverAssignableWithoutLimit();
return Capacity.create(EffortDuration.zero()).notOverAssignableWithoutLimit();
}
public static Capacity zero() {
return new Capacity(EffortDuration.zero(), EffortDuration.zero());
}
private EffortDuration standardEffort;
private EffortDuration allowedExtraEffort;
/**
* Default constructor for hibernate. DO NOT USE!
@ -111,7 +112,7 @@ public class Capacity {
}
private Capacity(EffortDuration standardEffort,
EffortDuration extraHours) {
EffortDuration extraHours) {
Validate.notNull(standardEffort);
this.standardEffort = standardEffort;
this.allowedExtraEffort = extraHours;
@ -229,7 +230,7 @@ public class Capacity {
Validate.notNull(assignedDuration);
return isOverAssignableWithoutLimit()
|| assignedDuration.compareTo(standardEffort
.plus(allowedExtraEffort)) < 0;
.plus(allowedExtraEffort)) < 0;
}
public Capacity minus(EffortDuration assignment) {
@ -243,7 +244,7 @@ public class Capacity {
standardEffort, assignment));
EffortDuration newExtra = allowedExtraEffort == null ? null
: allowedExtraEffort.minus(EffortDuration.min(pending,
allowedExtraEffort));
allowedExtraEffort));
return Capacity.create(newStandard).withAllowedExtraEffort(newExtra);
}

View file

@ -29,39 +29,39 @@ import org.libreplan.business.workingday.ResourcesPerDay;
public interface ICalendar {
/**
* Translates the received amount into the corresponding duration at the
* given date. It takes into account the partial capacity of the day.
* Translates the received amount into the corresponding duration at the given date.
* It takes into account the partial capacity of the day.
*
* @param day
* @param amount
* @return
*/
public EffortDuration asDurationOn(PartialDay day, ResourcesPerDay amount);
EffortDuration asDurationOn(PartialDay day, ResourcesPerDay amount);
/**
* Calculates the capacity duration at a given day. It means all the time
* that could be worked without having overtime. It considers the
* {@link PartialDay} so if the day it's not complete the capacity is
* reduced
* Calculates the capacity duration at a given day.
* It means all the time that could be worked without having overtime.
* It considers the {@link PartialDay} so if the day it's not complete the capacity is reduced.
*
* @param date
* the date at which the capacity is calculated
* @return the capacity at which the resource can work at the day specified
*/
public EffortDuration getCapacityOn(PartialDay partialDay);
EffortDuration getCapacityOn(PartialDay partialDay);
/**
* Calculates the capacity information for a given date. It contains
* information about the normal effort and the extra effort, i.e., the
* overtime effort.
* Calculates the capacity information for a given date.
* It contains information about the normal effort and the extra effort, i.e., the overtime effort.
*
* @param date
* a not null date
* @return the capacity for the date provided
*/
public Capacity getCapacityWithOvertime(LocalDate date);
Capacity getCapacityWithOvertime(LocalDate date);
public AvailabilityTimeLine getAvailability();
AvailabilityTimeLine getAvailability();
public boolean thereAreCapacityFor(AvailabilityTimeLine availability,
ResourcesPerDay resourcesPerDay, EffortDuration durationToAllocate);
boolean thereAreCapacityFor(AvailabilityTimeLine availability,
ResourcesPerDay resourcesPerDay,
EffortDuration durationToAllocate);
}

View file

@ -28,6 +28,7 @@ import org.libreplan.business.resources.entities.Resource;
/**
* Calendar for a {@link Resource}.
*
* @author Manuel Rego Casasnovas <mrego@igalia.com>
* @author Lorenzo Tilve Álvaro <ltilve@igalia.com>
*/
@ -41,6 +42,7 @@ public class ResourceCalendar extends BaseCalendar {
if (capacity == null) {
return 1;
}
return capacity;
}
@ -60,8 +62,7 @@ public class ResourceCalendar extends BaseCalendar {
private ResourceCalendar(CalendarData calendarData) {
super(calendarData);
CalendarAvailability calendarAvailability = CalendarAvailability
.create(new LocalDate(), null);
CalendarAvailability calendarAvailability = CalendarAvailability.create(new LocalDate(), null);
addNewCalendarAvailability(calendarAvailability);
}

View file

@ -32,10 +32,13 @@ import org.springframework.transaction.annotation.Transactional;
@Service
public class AdHocTransactionService implements IAdHocTransactionService {
private static <T> T proxy(
IAdHocTransactionService transactionService, boolean readOnly, Class<T> interfaceClass, T interfaceObject) {
private static <T> T proxy(IAdHocTransactionService transactionService,
boolean readOnly,
Class<T> interfaceClass,
T interfaceObject) {
Class<?>[] interfaces = { interfaceClass };
return interfaceClass.cast(Proxy.newProxyInstance(
interfaceClass.getClassLoader(),
interfaces,
@ -43,51 +46,54 @@ public class AdHocTransactionService implements IAdHocTransactionService {
}
/**
* Returns a new object implementing the same interface but with its calls
* wrapped on read only transactions
* Returns a new object implementing the same interface but with its calls wrapped on read only transactions.
*
* @param transactionService
* @param interfaceClass
* @param interfaceObject
* @return
* @return <T> T
*/
public static <T> T readOnlyProxy(
IAdHocTransactionService transactionService, Class<T> interfaceClass, T interfaceObject) {
public static <T> T readOnlyProxy(IAdHocTransactionService transactionService,
Class<T> interfaceClass,
T interfaceObject) {
return proxy(transactionService, true, interfaceClass, interfaceObject);
}
/**
* Returns a new object implementing the same interface but with its calls
* wrapped on transactions
* Returns a new object implementing the same interface but with its calls wrapped on transactions.
*
* @param transactionService
* @param interfaceClass
* @param interfaceObject
* @return
* @return <T> T
*/
public static <T> T proxy(IAdHocTransactionService transactionService, Class<T> interfaceClass, T interfaceObject) {
public static <T> T proxy(IAdHocTransactionService transactionService,
Class<T> interfaceClass,
T interfaceObject) {
return proxy(transactionService, false, interfaceClass, interfaceObject);
}
private static InvocationHandler createHandler(
final Object originalObject, final IAdHocTransactionService transactionService, final boolean readOnly) {
private static InvocationHandler createHandler(final Object originalObject,
final IAdHocTransactionService transactionService,
final boolean readOnly) {
return (proxy, method, args) -> {
IOnTransaction<Object> onTransaction = createOnTransaction(originalObject, method, args);
try {
if ( readOnly ) {
return transactionService.runOnReadOnlyTransaction(onTransaction);
} else {
return transactionService.runOnTransaction(onTransaction);
}
return readOnly
? transactionService.runOnReadOnlyTransaction(onTransaction)
: transactionService.runOnTransaction(onTransaction);
} catch (RuntimeException e) {
throw e.getCause();
}
};
}
private static IOnTransaction<Object> createOnTransaction(
final Object originalObject, final Method method, final Object[] args) {
private static IOnTransaction<Object> createOnTransaction(final Object originalObject,
final Method method,
final Object[] args) {
return () -> {
try {
return method.invoke(originalObject, args);

View file

@ -43,7 +43,6 @@ import org.libreplan.business.util.deepcopy.Strategy;
/**
* Base class for all the application entities.
*
* It provides the basic behavior for id and version fields.
*
* @author Manuel Rego Casasnovas <mrego@igalia.com>
@ -126,8 +125,9 @@ public abstract class BaseEntity implements INewObject {
/**
* Once the has been really saved in DB (not a readonly transaction), it
* could be necessary to unmark the object as newObject. This is the case if
* you must use the same instance after the transaction. <br />
* could be necessary to unmark the object as newObject.
* This is the case if you must use the same instance after the transaction.
* <br />
*/
public void dontPoseAsTransientObjectAnymore() {
setNewObject(false);

View file

@ -28,12 +28,12 @@ import org.apache.commons.lang3.BooleanUtils;
*
* Currently we have three options:
* <ul>
* <li>Enable/Disable the warning changing default password</li>
*
* <li>Enable/Disable default users
* (such as wsreader, wswriter, wssubcontracting, manager, hresources, outsourcing and reports)</li>
*
* <li>Enable/Disable E-mail sending functionality</li>
* <li>Enable/Disable the warning changing default password</li>
* <li>
* Enable/Disable default users
* (such as wsreader, wswriter, wssubcontracting, manager, hresources, outsourcing and reports)
* </li>
* <li>Enable/Disable E-mail sending functionality</li>
* </ul>
*
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>

View file

@ -69,8 +69,8 @@ import org.libreplan.business.workreports.daos.IWorkReportTypeDAO;
import org.springframework.beans.factory.annotation.Autowired;
/**
* A registry, AKA service locator, for objects in which dependency injection (DI) is not directly supported by Spring
* (e.g. entities) must use this class to access DAOs.
* A registry, AKA service locator, for objects in which dependency injection
* (DI) is not directly supported by Spring (e.g. entities) must use this class to access DAOs.
* For the rest of classes (e.g. services, tests, etc.), Spring DI is a more convenient option.
* The DAOs or services are added to the registry as needed.
*
@ -223,8 +223,7 @@ public class Registry {
@Autowired
private IAdHocTransactionService transactionServiceDAO;
private Registry() {
}
private Registry() {}
public static Registry getInstance() {
return singleton;

View file

@ -22,7 +22,8 @@ package org.libreplan.business.common;
import java.util.Collection;
/**
* Utilities class. <br />
* Utilities class.
* <br />
* @author Manuel Rego Casasnovas <mrego@igalia.com>
*/
public class Util {
@ -34,16 +35,17 @@ public class Util {
if (entity1.getId() == null || entity2.getId() == null) {
return false;
}
return entity1.getId().equals(entity2.getId());
}
public static boolean contains(Collection<? extends BaseEntity> collection,
BaseEntity entity) {
public static boolean contains(Collection<? extends BaseEntity> collection, BaseEntity entity) {
for (BaseEntity each : collection) {
if (each.getId().equals(entity.getId())) {
if ( each.getId().equals(entity.getId()) ) {
return true;
}
}
return false;
}

View file

@ -30,13 +30,12 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* It contains the current version of project and implements of singleton
* pattern. <br />
* It also has a cached value with information about last project version
* published. It checks the last version against a URL.
* It contains the current version of project and implements of singleton pattern. <br />
* It also has a cached value with information about last project version published.
* It checks the last version against a URL.
*
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
* @author Vova Perebykivskiy <vova@libreplan-enterprise.com>
* @author Vova Perebykivskyi <vova@libreplan-enterprise.com>
*/
public class VersionInformation {
@ -47,14 +46,11 @@ public class VersionInformation {
*/
private static final String LIBREPLAN_VERSION_URL = "http://libreplan.org/VERSION";
private static final String LIBREPLAN_USAGE_STATS_PARAM = "stats";
private static final String LIBREPLAN_VERSION_PARAM = "version";
/**
* Delay to wait till we check the URL again
*/
private static final long DELAY_TO_CHECK_URL = 24 * 60 * 60 * 1000; // 1 day
private static final long DELAY_TO_CHECK_URL = 24 * 60 * 60 * 1000L; // 1 day
private static final VersionInformation singleton = new VersionInformation();
@ -64,31 +60,27 @@ public class VersionInformation {
private Date lastVersionCachedDate = new Date();
private VersionInformation() {
}
private VersionInformation() {}
private void loadNewVersionFromURL() {
lastVersionCachedDate = new Date();
try {
URL url = getURL();
String lastVersion = (new BufferedReader(new InputStreamReader(
url.openStream()))).readLine();
String lastVersion = (new BufferedReader(new InputStreamReader(url.openStream()))).readLine();
if (projectVersion != null && lastVersion != null) {
newVersionCached = !projectVersion.equals(lastVersion);
}
} catch (MalformedURLException e) {
LOG.warn("Problems generating URL to check LibrePlan version. MalformedURLException: "
+ e.getMessage());
LOG.warn("Problems generating URL to check LibrePlan version. MalformedURLException: " + e.getMessage());
} catch (IOException e) {
LOG.info("Could not check LibrePlan version information from "
+ LIBREPLAN_VERSION_URL + ". IOException: "
+ e.getMessage());
LOG.info(
"Could not check LibrePlan version information from " +
LIBREPLAN_VERSION_URL + ". IOException: " + e.getMessage());
}
}
private URL getURL() throws MalformedURLException {
String url = LIBREPLAN_VERSION_URL;
return new URL(url);
return new URL(LIBREPLAN_VERSION_URL);
}
public static VersionInformation getInstance() {
@ -120,13 +112,11 @@ public class VersionInformation {
/**
* If there is a new version already detected, it doesn't check it again.
* Otherwise, during one day it returns the cached value. And it checks it
* again after that time.
* Otherwise, during one day it returns the cached value. And it checks it again after that time.
*/
private boolean checkIsNewVersionAvailable() {
if ( !newVersionCached ) {
long oneDayLater = lastVersionCachedDate.getTime()
+ DELAY_TO_CHECK_URL;
long oneDayLater = lastVersionCachedDate.getTime() + DELAY_TO_CHECK_URL;
if ( oneDayLater < new Date().getTime() ) {
loadNewVersionFromURL();
}
@ -138,10 +128,7 @@ public class VersionInformation {
String lastVersion = "";
try {
URL url = new URL(LIBREPLAN_VERSION_URL);
lastVersion = (new BufferedReader(new InputStreamReader(
url.openStream()))).readLine();
} catch (MalformedURLException e) {
e.printStackTrace();
lastVersion = (new BufferedReader(new InputStreamReader(url.openStream()))).readLine();
} catch (IOException e) {
e.printStackTrace();
}

View file

@ -41,12 +41,11 @@ import org.springframework.transaction.annotation.Transactional;
public class ConfigurationDAO extends GenericDAOHibernate<Configuration, Long> implements IConfigurationDAO {
@Override
@Transactional(readOnly = true)
public Configuration getConfiguration() {
List<Configuration> list = list(Configuration.class);
if ( list.isEmpty() ) {
return null;
}
return list.get(0);
return list.isEmpty() ? null : list.get(0);
}
@Override
@ -60,6 +59,7 @@ public class ConfigurationDAO extends GenericDAOHibernate<Configuration, Long> i
public void saveChangedDefaultPassword(String user, boolean change) {
user = user.substring(0, 1).toUpperCase() + user.substring(1).toLowerCase();
String sql = "UPDATE Configuration e SET e.changedDefault" + user + "Password = :change";
Query query = getSession().createQuery(sql);
query.setParameter("change", change);
query.executeUpdate();

View file

@ -40,6 +40,7 @@ import org.springframework.transaction.annotation.Transactional;
/**
* DAO for {@link EntitySequence}.
*
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
*/
@Repository
@ -53,7 +54,7 @@ public class EntitySequenceDAO extends GenericDAOHibernate<EntitySequence, Long>
@Override
@SuppressWarnings("unchecked")
public List<EntitySequence> findEntitySquencesNotIn(List<EntitySequence> entitySequences) {
public List<EntitySequence> findEntitySequencesNotIn(List<EntitySequence> entitySequences) {
List<Long> entitySequenceIds = new ArrayList<>();
for (EntitySequence entitySequence : entitySequences) {
if ( !entitySequence.isNewObject() ) {
@ -61,8 +62,10 @@ public class EntitySequenceDAO extends GenericDAOHibernate<EntitySequence, Long>
}
}
return getSession().createCriteria(EntitySequence.class)
.add(Restrictions.not(Restrictions.in("id", entitySequenceIds))).list();
return getSession()
.createCriteria(EntitySequence.class)
.add(Restrictions.not(Restrictions.in("id", entitySequenceIds)))
.list();
}
@Override

View file

@ -43,9 +43,9 @@ import org.springframework.transaction.annotation.Transactional;
/**
* An implementation of <code>IGenericDao</code> based on Hibernate's native API.
* Concrete DAOs must extend directly from this class.
* This constraint is imposed by the constructor of this class that must infer the
* type of the entity from the declaration of the concrete DAO.
* <p/>
* This constraint is imposed by the constructor of this class that must infer the type of the
* entity from the declaration of the concrete DAO.
*
* This class autowires a <code>SessionFactory</code> bean and allows to implement DAOs with Hibernate's native API.
* Subclasses access Hibernate's <code>Session</code> by calling on <code>getSession()</code> method.
* Operations must be implemented by catching <code>HibernateException</code>
@ -87,8 +87,8 @@ public class GenericDAOHibernate<E extends BaseEntity, PK extends Serializable>
/**
* It's necessary to save and validate later.
*
* Validate may retrieve the entity from DB and put it into the Session,
* which can eventually lead to a NonUniqueObject exception.
* Validate may retrieve the entity from DB and put it into the Session, which can eventually lead to
* a NonUniqueObject exception.
* Save works here to reattach the object as well as saving.
*/
public void save(E entity) throws ValidationException {
@ -96,16 +96,16 @@ public class GenericDAOHibernate<E extends BaseEntity, PK extends Serializable>
entity.validate();
}
public void saveWithoutValidating(E entity) {
getSession().saveOrUpdate(entity);
}
public void saveWithoutValidating(E entity) {
getSession().saveOrUpdate(entity);
}
public void reattachUnmodifiedEntity(E entity) {
if ( Hibernate.isInitialized(entity) && entity.isNewObject() ) {
return;
}
// TODO resolve deprecated
getSession().lock(entity, LockMode.NONE);
}
public E merge(E entity) {
@ -114,7 +114,7 @@ public class GenericDAOHibernate<E extends BaseEntity, PK extends Serializable>
public void checkVersion(E entity) {
/* Get id and version from entity. */
/* Get id and version from entity */
Serializable id;
Long versionValueInMemory;
@ -138,10 +138,12 @@ public class GenericDAOHibernate<E extends BaseEntity, PK extends Serializable>
throw new RuntimeException(e);
}
/* Check version. */
Long versionValueInDB = (Long) getSession().createCriteria(entityClass)
/* Check version */
Long versionValueInDB = (Long) getSession()
.createCriteria(entityClass)
.add(Restrictions.idEq(id))
.setProjection(Projections.property("version")).uniqueResult();
.setProjection(Projections.property("version"))
.uniqueResult();
if ( versionValueInDB == null ) {
return;
@ -159,15 +161,11 @@ public class GenericDAOHibernate<E extends BaseEntity, PK extends Serializable>
}
public void associateToSession(E entity) {
getSession().lock(entity, LockMode.NONE);
}
@SuppressWarnings("unchecked")
@Transactional(readOnly = true)
public E find(PK id) throws InstanceNotFoundException {
E entity = getSession().get(entityClass, id);
E entity = (E) getSession().get(entityClass, id);
if ( entity == null ) {
throw new InstanceNotFoundException(id, entityClass.getName());
@ -188,7 +186,8 @@ public class GenericDAOHibernate<E extends BaseEntity, PK extends Serializable>
public boolean exists(final PK id) {
return getSession().createCriteria(entityClass)
return getSession()
.createCriteria(entityClass)
.add(Restrictions.idEq(id))
.setProjection(Projections.id())
.uniqueResult() != null;
@ -212,6 +211,7 @@ public class GenericDAOHibernate<E extends BaseEntity, PK extends Serializable>
}
@Override
@Transactional
public void reattach(E entity) {
getSession().saveOrUpdate(entity);
}

View file

@ -33,6 +33,7 @@ import org.springframework.stereotype.Repository;
/**
* DAO interface for {@link EntitySequenceDAO}.
*
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
*/
@Repository
@ -41,12 +42,12 @@ public interface IEntitySequenceDAO extends IGenericDAO<EntitySequence, Long> {
List<EntitySequence> getAll();
List<EntitySequence> findEntitySquencesNotIn(List<EntitySequence> entitySequences);
List<EntitySequence> findEntitySequencesNotIn(List<EntitySequence> entitySequences);
void remove(EntitySequence entitySequence) throws InstanceNotFoundException, IllegalArgumentException;
EntitySequence getActiveEntitySequence(EntityNameEnum entityName) throws InstanceNotFoundException,
NonUniqueResultException;
EntitySequence getActiveEntitySequence(EntityNameEnum entityName)
throws InstanceNotFoundException, NonUniqueResultException;
String getNextEntityCode(EntityNameEnum entityName);

View file

@ -25,15 +25,15 @@ import java.util.List;
/**
* DAO interface for the <code>Limits</code> entity.
* Contract for {@link LimitsDAO}
* Contract for {@link LimitsDAO}.
*
* Created by
* @author Vova Perebykivskiy <vova@libreplan-enterprise.com>
* on 17.12.2015.
* @author Created by Vova Perebykivskyi <vova@libreplan-enterprise.com> on 17.12.2015.
*/
public interface ILimitsDAO extends IGenericDAO<Limits, Long> {
List<Limits> getAll();
Limits getUsersType();
Limits getResourcesType();
}

View file

@ -33,13 +33,13 @@ import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
/**
* Default implementation of <code>IIntegrationEntityDAO</code>. DAOs of
* entities used in application integration may extend from this interface.
* Default implementation of <code>IIntegrationEntityDAO</code>.
* DAOs of entities used in application integration may extend from this interface.
*
* @author Fernando Bellas Permuy <fbellas@udc.es>
*/
public class IntegrationEntityDAO<E extends IntegrationEntity>
extends GenericDAOHibernate<E, Long> implements IIntegrationEntityDAO<E> {
extends GenericDAOHibernate<E, Long> implements IIntegrationEntityDAO<E> {
@Override
public boolean existsByCode(String code) {
@ -66,15 +66,15 @@ public class IntegrationEntityDAO<E extends IntegrationEntity>
if (StringUtils.isBlank(code)) {
throw new InstanceNotFoundException(null,
getEntityClass().getName());
getEntityClass().getName());
}
E entity = (E) getSession().createCriteria(getEntityClass()).add(
Restrictions.eq("code", code.trim()).ignoreCase()).uniqueResult();
Restrictions.eq("code", code.trim()).ignoreCase()).uniqueResult();
if (entity == null) {
throw new InstanceNotFoundException(
code, getEntityClass().getName());
code, getEntityClass().getName());
} else {
return entity;
}
@ -84,7 +84,7 @@ public class IntegrationEntityDAO<E extends IntegrationEntity>
@Override
@Transactional(readOnly = true, propagation = Propagation.REQUIRES_NEW)
public E findByCodeAnotherTransaction(String code)
throws InstanceNotFoundException {
throws InstanceNotFoundException {
return findByCode(code);
@ -104,8 +104,7 @@ public class IntegrationEntityDAO<E extends IntegrationEntity>
@SuppressWarnings("unchecked")
@Override
public List<E> findAll() {
return getSession().createCriteria(getEntityClass()).
addOrder(Order.asc("code")).list();
return getSession().createCriteria(getEntityClass()).addOrder(Order.asc("code")).list();
}
}

View file

@ -25,11 +25,9 @@ import org.springframework.stereotype.Repository;
import java.util.List;
/**
* DAO for {@link Limits}
* DAO for {@link Limits}.
*
* Created by
* @author Vova Perebykivskiy <vova@libreplan-enterprise.com>
* on 24.09.15.
* @author Created by Vova Perebykivskyi <vova@libreplan-enterprise.com> on 24.09.2015.
*/
@Repository

View file

@ -37,14 +37,10 @@ import org.libreplan.business.costcategories.entities.TypeOfWorkHours;
* @author Cristina Alvarino Perez <cristina.alvarino@comtecsf.es>
* @author Ignacio Diaz Teijido <ignacio.diaz@comtecsf.es>
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
* @author Vova Perebykivskiy <vova@libreplan-enterprise.com>
* @author Vova Perebykivskyi <vova@libreplan-enterprise.com>
*/
public class Configuration extends BaseEntity {
public static Configuration create() {
return create(new Configuration());
}
private BaseCalendar defaultCalendar;
private String companyCode;
@ -111,6 +107,7 @@ public class Configuration extends BaseEntity {
* Currency code according to ISO-4217 (3 letters)
*/
private String currencyCode = "EUR";
private String currencySymbol = "";
private TypeOfWorkHours personalTimesheetsTypeOfWorkHours;
@ -137,6 +134,10 @@ public class Configuration extends BaseEntity {
private String repositoryLocation;
public static Configuration create() {
return create(new Configuration());
}
public void setDefaultCalendar(BaseCalendar defaultCalendar) {
this.defaultCalendar = defaultCalendar;
@ -151,6 +152,7 @@ public class Configuration extends BaseEntity {
if (companyCode != null) {
companyCode = companyCode.trim();
}
this.companyCode = companyCode;
}
@ -161,53 +163,30 @@ public class Configuration extends BaseEntity {
@AssertTrue(message = "company code cannot contain whitespaces")
public boolean isCompanyCodeWithoutWhiteSpacesConstraint() {
if ((companyCode == null) || (companyCode.isEmpty())) {
return false;
}
return !companyCode.contains(" ");
return !((companyCode == null) || (companyCode.isEmpty())) && !companyCode.contains(" ");
}
@AssertTrue(message = "host not specified")
public boolean isLdapHostWithoutWhiteSpacesConstraint() {
if (getLdapConfiguration().getLdapAuthEnabled()) {
if (StringUtils.isBlank(getLdapConfiguration().getLdapHost())) {
return false;
}
}
return true;
return !getLdapConfiguration().getLdapAuthEnabled() || !StringUtils.isBlank(getLdapConfiguration().getLdapHost());
}
@AssertTrue(message = "port not specified")
public boolean isLdapPortWithoutWhiteSpacesConstraint() {
if (getLdapConfiguration().getLdapAuthEnabled()) {
if (StringUtils.isBlank(getLdapConfiguration().getLdapPort())) {
return false;
}
}
return true;
return !getLdapConfiguration().getLdapAuthEnabled() || !StringUtils.isBlank(getLdapConfiguration().getLdapPort());
}
@AssertTrue(message = "base not specified")
public boolean isLdapBaseWithoutWhiteSpacesConstraint() {
if (getLdapConfiguration().getLdapAuthEnabled()) {
if (StringUtils.isBlank(getLdapConfiguration().getLdapBase())) {
return false;
}
}
return true;
return !getLdapConfiguration().getLdapAuthEnabled() || !StringUtils.isBlank(getLdapConfiguration().getLdapBase());
}
@AssertTrue(message = "userId not specified")
public boolean isLdapUserIdWithoutWhiteSpacesConstraint() {
if (getLdapConfiguration().getLdapAuthEnabled()) {
if (StringUtils.isBlank(getLdapConfiguration().getLdapUserId())) {
return false;
}
}
return true;
return !getLdapConfiguration().getLdapAuthEnabled() || !StringUtils.isBlank(getLdapConfiguration().getLdapUserId());
}
//TODO 2 added methods follow below
public void setGeneratedCodeForProjectLog(Boolean generateCodeForProjectLog) {
this.generateCodeForProjectLog = generateCodeForProjectLog;
}
@ -245,8 +224,7 @@ public class Configuration extends BaseEntity {
return generateCodeForResources;
}
public void setGenerateCodeForTypesOfWorkHours(
Boolean generateCodeForTypesOfWorkHours) {
public void setGenerateCodeForTypesOfWorkHours(Boolean generateCodeForTypesOfWorkHours) {
this.generateCodeForTypesOfWorkHours = generateCodeForTypesOfWorkHours;
}
@ -254,8 +232,7 @@ public class Configuration extends BaseEntity {
return generateCodeForTypesOfWorkHours;
}
public void setGenerateCodeForMaterialCategories(
Boolean generateCodeForMaterialCategories) {
public void setGenerateCodeForMaterialCategories(Boolean generateCodeForMaterialCategories) {
this.generateCodeForMaterialCategories = generateCodeForMaterialCategories;
}
@ -287,8 +264,7 @@ public class Configuration extends BaseEntity {
this.scenariosVisible = scenariosVisible;
}
public void setGenerateCodeForBaseCalendars(
Boolean generateCodeForBaseCalendars) {
public void setGenerateCodeForBaseCalendars(Boolean generateCodeForBaseCalendars) {
this.generateCodeForBaseCalendars = generateCodeForBaseCalendars;
}
@ -296,8 +272,7 @@ public class Configuration extends BaseEntity {
return generateCodeForBaseCalendars;
}
public void setGenerateCodeForWorkReportType(
Boolean generateCodeForWorkReportType) {
public void setGenerateCodeForWorkReportType(Boolean generateCodeForWorkReportType) {
this.generateCodeForWorkReportType = generateCodeForWorkReportType;
}
@ -305,8 +280,7 @@ public class Configuration extends BaseEntity {
return generateCodeForWorkReportType;
}
public void setGenerateCodeForCalendarExceptionType(
Boolean generateCodeForCalendarExceptionType) {
public void setGenerateCodeForCalendarExceptionType(Boolean generateCodeForCalendarExceptionType) {
this.generateCodeForCalendarExceptionType = generateCodeForCalendarExceptionType;
}
@ -314,8 +288,7 @@ public class Configuration extends BaseEntity {
return this.generateCodeForCalendarExceptionType;
}
public void setGenerateCodeForCostCategory(
Boolean generateCodeForCostCategory) {
public void setGenerateCodeForCostCategory(Boolean generateCodeForCostCategory) {
this.generateCodeForCostCategory = generateCodeForCostCategory;
}
@ -336,14 +309,14 @@ public class Configuration extends BaseEntity {
}
public ProgressType getProgressType() {
return (progressType == null) ? ProgressType.SPREAD_PROGRESS
: progressType;
return (progressType == null) ? ProgressType.SPREAD_PROGRESS : progressType;
}
public void setCompanyLogoURL(String companyLogoURL) {
if (companyLogoURL != null) {
companyLogoURL = companyLogoURL.trim();
}
this.companyLogoURL = companyLogoURL;
}
@ -351,84 +324,68 @@ public class Configuration extends BaseEntity {
return companyLogoURL;
}
public void setChangedDefaultAdminPassword(
Boolean changedDefaultAdminPassword) {
public void setChangedDefaultAdminPassword(Boolean changedDefaultAdminPassword) {
this.changedDefaultAdminPassword = changedDefaultAdminPassword;
}
public Boolean getChangedDefaultAdminPassword() {
return changedDefaultAdminPassword == null ? false
: changedDefaultAdminPassword;
return changedDefaultAdminPassword == null ? false : changedDefaultAdminPassword;
}
public void setChangedDefaultWsreaderPassword(
Boolean changedDefaultWsreaderPassword) {
public void setChangedDefaultWsreaderPassword(Boolean changedDefaultWsreaderPassword) {
this.changedDefaultWsreaderPassword = changedDefaultWsreaderPassword;
}
public Boolean getChangedDefaultWsreaderPassword() {
return changedDefaultWsreaderPassword != null ? changedDefaultWsreaderPassword
: false;
return changedDefaultWsreaderPassword != null ? changedDefaultWsreaderPassword : false;
}
public void setChangedDefaultWswriterPassword(
Boolean changedDefaultWswriterPassword) {
public void setChangedDefaultWswriterPassword(Boolean changedDefaultWswriterPassword) {
this.changedDefaultWswriterPassword = changedDefaultWswriterPassword;
}
public Boolean getChangedDefaultWswriterPassword() {
return changedDefaultWswriterPassword != null ? changedDefaultWswriterPassword
: false;
return changedDefaultWswriterPassword != null ? changedDefaultWswriterPassword : false;
}
public void setChangedDefaultWssubcontractingPassword(
Boolean changedDefaultWssubcontractingPassword) {
public void setChangedDefaultWssubcontractingPassword(Boolean changedDefaultWssubcontractingPassword) {
this.changedDefaultWssubcontractingPassword = changedDefaultWssubcontractingPassword;
}
public Boolean getChangedDefaultWssubcontractingPassword() {
return changedDefaultWssubcontractingPassword != null ? changedDefaultWssubcontractingPassword
: false;
return changedDefaultWssubcontractingPassword != null ? changedDefaultWssubcontractingPassword : false;
}
public void setChangedDefaultManagerPassword(
Boolean changedDefaultManagerPassword) {
public void setChangedDefaultManagerPassword(Boolean changedDefaultManagerPassword) {
this.changedDefaultManagerPassword = changedDefaultManagerPassword;
}
public Boolean getChangedDefaultManagerPassword() {
return changedDefaultManagerPassword != null ? changedDefaultManagerPassword
: false;
return changedDefaultManagerPassword != null ? changedDefaultManagerPassword : false;
}
public void setChangedDefaultHresourcesPassword(
Boolean changedDefaultHresourcesPassword) {
public void setChangedDefaultHresourcesPassword(Boolean changedDefaultHresourcesPassword) {
this.changedDefaultHresourcesPassword = changedDefaultHresourcesPassword;
}
public Boolean getChangedDefaultHresourcesPassword() {
return changedDefaultHresourcesPassword != null ? changedDefaultHresourcesPassword
: false;
return changedDefaultHresourcesPassword != null ? changedDefaultHresourcesPassword : false;
}
public void setChangedDefaultOutsourcingPassword(
Boolean changedDefaultOutsourcingPassword) {
public void setChangedDefaultOutsourcingPassword(Boolean changedDefaultOutsourcingPassword) {
this.changedDefaultOutsourcingPassword = changedDefaultOutsourcingPassword;
}
public Boolean getChangedDefaultOutsourcingPassword() {
return changedDefaultOutsourcingPassword != null ? changedDefaultOutsourcingPassword
: false;
return changedDefaultOutsourcingPassword != null ? changedDefaultOutsourcingPassword : false;
}
public void setChangedDefaultReportsPassword(
Boolean changedDefaultReportsPassword) {
public void setChangedDefaultReportsPassword(Boolean changedDefaultReportsPassword) {
this.changedDefaultReportsPassword = changedDefaultReportsPassword;
}
public Boolean getChangedDefaultReportsPassword() {
return changedDefaultReportsPassword != null ? changedDefaultReportsPassword
: false;
return changedDefaultReportsPassword != null ? changedDefaultReportsPassword : false;
}
public LDAPConfiguration getLdapConfiguration() {
@ -455,13 +412,11 @@ public class Configuration extends BaseEntity {
this.checkNewVersionEnabled = checkNewVersionEnabled;
}
public boolean isAllowToGatherUsageStatsEnabled() {
return allowToGatherUsageStatsEnabled != null ? allowToGatherUsageStatsEnabled
: false;
public boolean isAllowedToGatherUsageStatsEnabled() {
return allowToGatherUsageStatsEnabled != null ? allowToGatherUsageStatsEnabled : false;
}
public void setAllowToGatherUsageStatsEnabled(
boolean allowToGatherUsageStatsEnabled) {
public void setAllowToGatherUsageStatsEnabled(boolean allowToGatherUsageStatsEnabled) {
this.allowToGatherUsageStatsEnabled = allowToGatherUsageStatsEnabled;
}
@ -487,8 +442,7 @@ public class Configuration extends BaseEntity {
return personalTimesheetsTypeOfWorkHours;
}
public void setPersonalTimesheetsTypeOfWorkHours(
TypeOfWorkHours typeOfWorkHours) {
public void setPersonalTimesheetsTypeOfWorkHours(TypeOfWorkHours typeOfWorkHours) {
personalTimesheetsTypeOfWorkHours = typeOfWorkHours;
}
@ -504,8 +458,7 @@ public class Configuration extends BaseEntity {
return personalTimesheetsPeriodicity;
}
public void setPersonalTimesheetsPeriodicity(
PersonalTimesheetsPeriodicityEnum personalTimesheetsPeriodicity) {
public void setPersonalTimesheetsPeriodicity(PersonalTimesheetsPeriodicityEnum personalTimesheetsPeriodicity) {
this.personalTimesheetsPeriodicity = personalTimesheetsPeriodicity;
}
@ -538,6 +491,7 @@ public class Configuration extends BaseEntity {
public String getRepositoryLocation() {
return repositoryLocation;
}
public void setRepositoryLocation(String repositoryLocation) {
this.repositoryLocation = repositoryLocation;
}

View file

@ -35,17 +35,18 @@ import org.libreplan.business.common.daos.IConfigurationDAO;
import org.libreplan.business.common.daos.IEntitySequenceDAO;
import org.libreplan.business.workingday.EffortDuration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
/**
* Creates a default {@link Configuration} with default values. It also creates
* a default {@link OrderSequence}.
* Creates a default {@link Configuration} with default values.
*
* @author Manuel Rego Casasnovas <mrego@igalia.com>
*/
@Component
@Scope("singleton")
@Scope(BeanDefinition.SCOPE_SINGLETON)
@BootstrapOrder(-1)
public class ConfigurationBootstrap implements IConfigurationBootstrap {
@ -94,9 +95,9 @@ public class ConfigurationBootstrap implements IConfigurationBootstrap {
}
private Map<EntityNameEnum, List<EntitySequence>> initEntitySequences() {
Map<EntityNameEnum, List<EntitySequence>> entitySequences = new HashMap<EntityNameEnum, List<EntitySequence>>();
Map<EntityNameEnum, List<EntitySequence>> entitySequences = new HashMap<>();
for (EntityNameEnum entityName : EntityNameEnum.values()) {
entitySequences.put(entityName, new ArrayList<EntitySequence>());
entitySequences.put(entityName, new ArrayList<>());
}
for (EntitySequence entitySequence : entitySequenceDAO.getAll()) {
entitySequences.get(entitySequence.getEntityName()).add(

View file

@ -27,29 +27,28 @@ import org.libreplan.business.costcategories.entities.TypeOfWorkHours;
import org.libreplan.business.costcategories.entities.TypeOfWorkHoursBootstrap;
import org.libreplan.business.workreports.entities.PredefinedWorkReportTypes;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
/**
* Fills the attributes {@link Configuration#personalTimesheetsTypeOfWorkHours}
* and {@link JiraConfiguration#jiraConnectorTypeOfWorkHours} with a default
* values.<br />
* Fills the attributes {@link Configuration#personalTimesheetsTypeOfWorkHours} with a default values.
* <br />
*
* If possible it uses the "Default" {@link TypeOfWorkHours}, but if it doesn't
* exist, it uses the first {@link TypeOfWorkHours} found.<br />
* exist, it uses the first {@link TypeOfWorkHours} found.
* <br />
*
* This bootstrap have to be executed after {@link ConfigurationBootstrap} and
* {@link TypeOfWorkHoursBootstrap}, this is why it's marked with
* {@link BootstrapOrder BootstrapOrder(1)}.
* {@link TypeOfWorkHoursBootstrap}, this is why it's marked with {@link BootstrapOrder BootstrapOrder(1)}.
*
* @author Manuel Rego Casasnovas <mrego@igalia.com>
*/
@Component
@Scope("singleton")
@Scope(BeanDefinition.SCOPE_SINGLETON)
@BootstrapOrder(1)
public class ConfigurationTypeOfWorkHoursBootstrap implements
IConfigurationTypeOfWorkHoursBootstrap {
public class ConfigurationTypeOfWorkHoursBootstrap implements IConfigurationTypeOfWorkHoursBootstrap {
@Autowired
private IConfigurationDAO configurationDAO;
@ -63,13 +62,10 @@ public class ConfigurationTypeOfWorkHoursBootstrap implements
Configuration configuration = configurationDAO.getConfiguration();
// TypeOfWorkHoursBootstrap creates the TypeOfWorkHours objects
// specified by PredefinedWorkReportTypes if there isn't any
// TypeOfWorkHours in the database
// specified by PredefinedWorkReportTypes if there isn't any TypeOfWorkHours in the database
TypeOfWorkHours typeOfWorkHours;
try {
typeOfWorkHours = typeOfWorkHoursDAO
.findUniqueByName(PredefinedWorkReportTypes.DEFAULT
.getName());
typeOfWorkHours = typeOfWorkHoursDAO.findUniqueByName(PredefinedWorkReportTypes.DEFAULT.getName());
} catch (InstanceNotFoundException e) {
typeOfWorkHours = typeOfWorkHoursDAO.findActive().get(0);
}

View file

@ -21,6 +21,7 @@ package org.libreplan.business.common.entities;
import org.libreplan.business.common.daos.IConnectorDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
@ -32,7 +33,7 @@ import org.springframework.transaction.annotation.Transactional;
* @author Manuel Rego Casasnovas <rego@igalia.com>
*/
@Component
@Scope("singleton")
@Scope(BeanDefinition.SCOPE_SINGLETON)
public class ConnectorBootstrap implements IConnectorBootstrap {
@Autowired

View file

@ -21,11 +21,10 @@ package org.libreplan.business.common.entities;
/**
* Defines the job class package and name to be used as data type in
* {@link JobSchedulerConfiguration}
* Defines the job class package and name to be used as data type in {@link JobSchedulerConfiguration}.
*
* @author Miciele Ghiorghis <m.ghiorghis@antoniusziekenhuis.nl>
* @author Vova Perebykivskiy <vova@libreplan-enterprise.com>
* @author Vova Perebykivskyi <vova@libreplan-enterprise.com>
*/
public enum JobClassNameEnum {
@ -43,7 +42,7 @@ public enum JobClassNameEnum {
private String packageName;
private String name;
private JobClassNameEnum(String packageName, String name) {
JobClassNameEnum(String packageName, String name) {
this.packageName = packageName;
this.name = name;
}

View file

@ -26,11 +26,9 @@ import org.libreplan.business.common.BaseEntity;
* This class is intended to work as a Hibernate component.
* It represents the limit that can be modified only in database.
*
* Created by
* @author Vova Perebykivskiy <vova@libreplan-enterprise.com>
* on 17.12.2015.
* @author Created by Vova Perebykivskyi <vova@libreplan-enterprise.com> on 17.12.2015.
*/
public class Limits extends BaseEntity{
public class Limits extends BaseEntity {
private String type;

View file

@ -22,12 +22,11 @@ package org.libreplan.business.common.entities;
import static org.libreplan.business.i18n.I18nHelper._;
/**
* Simply class to keep constants of {@link ConnectorProperty properties} for
* LibrePlan {@link Connector connectors}.
* Simply class to keep constants of {@link ConnectorProperty properties} for LibrePlan {@link Connector connectors}.
*
* @author Miciele Ghiorghis <m.ghiorghis@antoniusziekenhuis.nl>
* @author Manuel Rego Casasnovas <rego@igalia.com>
* @author Vova Perebykivskiy <vova@libreplan-enterprise.com>
* @author Vova Perebykivskyi <vova@libreplan-enterprise.com>
*/
public class PredefinedConnectorProperties {

View file

@ -23,35 +23,32 @@ import java.util.Arrays;
import java.util.List;
/**
* Defines the LibrePlan {@link Connector Connectors} together with its
* configuration properties.
* Defines the LibrePlan {@link Connector Connectors} together with its configuration properties.
*
* @author Miciele Ghiorghis <m.ghiorghis@antoniusziekenhuis.nl>
* @author Manuel Rego Casasnovas <rego@igalia.com>
* @author Vova Perebykivskiy <vova@libreplan-enterprise.com>
* @author Vova Perebykivskyi <vova@libreplan-enterprise.com>
*/
public enum PredefinedConnectors {
TIM("Tim",
ConnectorProperty.create(PredefinedConnectorProperties.ACTIVATED, "N"),
ConnectorProperty.create(PredefinedConnectorProperties.SERVER_URL, ""),
ConnectorProperty.create(PredefinedConnectorProperties.USERNAME, ""),
ConnectorProperty.create(PredefinedConnectorProperties.PASSWORD, ""),
ConnectorProperty.create(PredefinedConnectorProperties.TIM_NR_DAYS_TIMESHEET, "7"),
ConnectorProperty.create(PredefinedConnectorProperties.TIM_NR_DAYS_ROSTER, "90"),
ConnectorProperty.create(PredefinedConnectorProperties.TIM_PRODUCTIVITY_FACTOR, "100"),
ConnectorProperty.create(
PredefinedConnectorProperties.TIM_DEPARTAMENTS_IMPORT_ROSTER,
"0")),
ConnectorProperty.create(PredefinedConnectorProperties.ACTIVATED, "N"),
ConnectorProperty.create(PredefinedConnectorProperties.SERVER_URL, ""),
ConnectorProperty.create(PredefinedConnectorProperties.USERNAME, ""),
ConnectorProperty.create(PredefinedConnectorProperties.PASSWORD, ""),
ConnectorProperty.create(PredefinedConnectorProperties.TIM_NR_DAYS_TIMESHEET, "7"),
ConnectorProperty.create(PredefinedConnectorProperties.TIM_NR_DAYS_ROSTER, "90"),
ConnectorProperty.create(PredefinedConnectorProperties.TIM_PRODUCTIVITY_FACTOR, "100"),
ConnectorProperty.create(PredefinedConnectorProperties.TIM_DEPARTAMENTS_IMPORT_ROSTER, "0")),
JIRA("Jira",
ConnectorProperty.create(PredefinedConnectorProperties.ACTIVATED, "N"),
ConnectorProperty.create(PredefinedConnectorProperties.SERVER_URL, ""),
ConnectorProperty.create(PredefinedConnectorProperties.USERNAME, ""),
ConnectorProperty.create(PredefinedConnectorProperties.PASSWORD, ""),
ConnectorProperty
.create(PredefinedConnectorProperties.JIRA_LABELS, ""),
ConnectorProperty.create(
PredefinedConnectorProperties.JIRA_HOURS_TYPE, "Default")),
ConnectorProperty.create(PredefinedConnectorProperties.ACTIVATED, "N"),
ConnectorProperty.create(PredefinedConnectorProperties.SERVER_URL, ""),
ConnectorProperty.create(PredefinedConnectorProperties.USERNAME, ""),
ConnectorProperty.create(PredefinedConnectorProperties.PASSWORD, ""),
ConnectorProperty.create(PredefinedConnectorProperties.JIRA_LABELS, ""),
ConnectorProperty.create(PredefinedConnectorProperties.JIRA_HOURS_TYPE, "Default")),
EMAIL("E-mail",
ConnectorProperty.create(PredefinedConnectorProperties.ACTIVATED, "N"),
ConnectorProperty.create(PredefinedConnectorProperties.PROTOCOL, ""),
@ -64,10 +61,10 @@ public enum PredefinedConnectors {
);
private String name;
private List<ConnectorProperty> properties;
private PredefinedConnectors(String name,
ConnectorProperty... properties) {
PredefinedConnectors(String name, ConnectorProperty... properties) {
this.name = name;
this.properties = Arrays.asList(properties);
}

View file

@ -26,19 +26,17 @@ package org.libreplan.business.common.exceptions;
* It contains a message, the key of the instance, and its class name.
*
* @author Fernando Bellas Permuy <fbellas@udc.es>
*
*/
@SuppressWarnings("serial")
public abstract class InstanceException extends Exception {
private Object key;
private String className;
private final Object key;
protected InstanceException(String specificMessage, Object key,
String className) {
private final String className;
super(specificMessage + " (key = '" + key + "' - className = '" +
className + "')");
protected InstanceException(String specificMessage, Object key, String className) {
super(specificMessage + " (key = '" + key + "' - className = '" + className + "')");
this.key = key;
this.className = className;

View file

@ -23,6 +23,7 @@ import org.libreplan.business.common.daos.IEntitySequenceDAO;
import org.libreplan.business.common.entities.EntityNameEnum;
import org.libreplan.business.costcategories.daos.ITypeOfWorkHoursDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
@ -33,7 +34,7 @@ import org.springframework.transaction.annotation.Transactional;
* @author Ignacio Díaz Teijido <ignacio.diaz@cafedered.com>
*/
@Component
@Scope("singleton")
@Scope(BeanDefinition.SCOPE_SINGLETON)
public class TypeOfWorkHoursBootstrap implements ITypeOfWorkHoursBootstrap {
@Autowired
@ -46,10 +47,8 @@ public class TypeOfWorkHoursBootstrap implements ITypeOfWorkHoursBootstrap {
@Transactional
public void loadRequiredData() {
if (typeOfWorkHoursDAO.findActive().size() == 0) {
for (PredefinedTypeOfWorkHours predefinedTypeOfWorkHours : PredefinedTypeOfWorkHours
.values()) {
TypeOfWorkHours typeOfWorkHours = predefinedTypeOfWorkHours
.getTypeOfWorkHours();
for (PredefinedTypeOfWorkHours predefinedTypeOfWorkHours : PredefinedTypeOfWorkHours.values()) {
TypeOfWorkHours typeOfWorkHours = predefinedTypeOfWorkHours.getTypeOfWorkHours();
typeOfWorkHours.setCodeAutogenerated(true);
typeOfWorkHours
.setCode(entitySequenceDAO

View file

@ -30,7 +30,7 @@ import java.util.List;
/**
* Dao for {@link EmailNotification}
*
* @author Created by Vova Perebykivskiy <vova@libreplan-enterprise.com> on 19.10.2015.
* @author Created by Vova Perebykivskyi <vova@libreplan-enterprise.com> on 19.10.2015.
*/
@Repository
public class EmailNotificationDAO

View file

@ -33,7 +33,7 @@ import java.util.List;
/**
* DAO for {@link EmailTemplate}
*
* @author Created by Vova Perebykivskiy <vova@libreplan-enterprise.com> on 24.09.2015.
* @author Created by Vova Perebykivskyi <vova@libreplan-enterprise.com> on 24.09.2015.
*/
@Repository
public class EmailTemplateDAO extends GenericDAOHibernate<EmailTemplate, Long> implements IEmailTemplateDAO{
@ -68,7 +68,6 @@ public class EmailTemplateDAO extends GenericDAOHibernate<EmailTemplate, Long> i
public void delete(EmailTemplate entity) {
try {
remove(entity.getId());
} catch (InstanceNotFoundException ignored) {
}
} catch (InstanceNotFoundException ignored) {}
}
}

View file

@ -28,7 +28,7 @@ import java.util.List;
/**
* Contract for {@link EmailNotificationDAO}
*
* @author Created by Vova Perebykivskiy <vova@libreplan-enterprise.com> on 19.10.2015.
* @author Created by Vova Perebykivskyi <vova@libreplan-enterprise.com> on 19.10.2015.
*/
public interface IEmailNotificationDAO extends IGenericDAO<EmailNotification, Long> {

View file

@ -28,9 +28,9 @@ import java.util.List;
/**
* DAO interface for the <code>EmailTemplate</code> entity.
* Contract for {@link EmailTemplateDAO}
* Contract for {@link EmailTemplateDAO}.
*
* @author Created by Vova Perebykivskiy <vova@libreplan-enterprise.com> on 29.09.2015.
* @author Created by Vova Perebykivskyi <vova@libreplan-enterprise.com> on 29.09.2015.
*/
public interface IEmailTemplateDAO extends IGenericDAO<EmailTemplate, Long>{

View file

@ -24,7 +24,7 @@ import java.util.Date;
import org.libreplan.business.common.BaseEntity;
/**
* Entity EndDateCommunication
* Entity EndDateCommunication.
*
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
*/
@ -46,8 +46,7 @@ public class EndDateCommunication extends BaseEntity {
this.setSaveDate(new Date());
}
protected EndDateCommunication(Date saveDate, Date endDate,
Date communicationDate) {
protected EndDateCommunication(Date saveDate, Date endDate, Date communicationDate) {
this.setSaveDate(saveDate);
this.setEndDate(endDate);
this.setCommunicationDate(communicationDate);
@ -61,8 +60,7 @@ public class EndDateCommunication extends BaseEntity {
return create(new EndDateCommunication(endDate));
}
public static EndDateCommunication create(Date saveDate, Date endDate,
Date communicationDate) {
public static EndDateCommunication create(Date saveDate, Date endDate, Date communicationDate) {
return create(new EndDateCommunication(saveDate, endDate, communicationDate));
}

View file

@ -32,12 +32,11 @@ import org.libreplan.business.externalcompanies.daos.IExternalCompanyDAO;
import org.libreplan.business.users.entities.User;
/**
* Entity ExternalCompany
* Entity ExternalCompany.
*
* @author Jacobo Aragunde Perez <jaragunde@igalia.com>
*/
public class ExternalCompany extends BaseEntity implements IHumanIdentifiable,
Comparable<ExternalCompany> {
public class ExternalCompany extends BaseEntity implements IHumanIdentifiable, Comparable<ExternalCompany> {
private String name;
@ -60,7 +59,7 @@ public class ExternalCompany extends BaseEntity implements IHumanIdentifiable,
protected ExternalCompany() {}
public static ExternalCompany create() {
return (ExternalCompany) create(new ExternalCompany());
return create(new ExternalCompany());
}
protected ExternalCompany(String name, String nif) {
@ -69,7 +68,7 @@ public class ExternalCompany extends BaseEntity implements IHumanIdentifiable,
}
public static ExternalCompany create(String name, String nif) {
return (ExternalCompany) create(new ExternalCompany(name,nif));
return create(new ExternalCompany(name,nif));
}
public void setName(String name) {
@ -154,8 +153,8 @@ public class ExternalCompany extends BaseEntity implements IHumanIdentifiable,
return !dao.existsByNameInAnotherTransaction(name);
} else {
try {
ExternalCompany company =
dao.findUniqueByNameInAnotherTransaction(name);
ExternalCompany company = dao.findUniqueByNameInAnotherTransaction(name);
return company.getId().equals(getId());
} catch (InstanceNotFoundException e) {
return true;
@ -171,8 +170,8 @@ public class ExternalCompany extends BaseEntity implements IHumanIdentifiable,
return !dao.existsByNifInAnotherTransaction(nif);
} else {
try {
ExternalCompany company =
dao.findUniqueByNifInAnotherTransaction(nif);
ExternalCompany company = dao.findUniqueByNifInAnotherTransaction(nif);
return company.getId().equals(getId());
} catch (InstanceNotFoundException e) {
return true;
@ -182,13 +181,9 @@ public class ExternalCompany extends BaseEntity implements IHumanIdentifiable,
@AssertTrue(message = "interaction fields are empty and company is marked as interact with applications")
public boolean isInteractionFieldsNotEmptyIfNeededConstraint() {
if (!interactsWithApplications) {
return true;
}
return !interactsWithApplications || !StringUtils.isEmpty(appURI) && !StringUtils.isEmpty(ourCompanyLogin) &&
!StringUtils.isEmpty(ourCompanyPassword);
return !StringUtils.isEmpty(appURI)
&& !StringUtils.isEmpty(ourCompanyLogin)
&& !StringUtils.isEmpty(ourCompanyPassword);
}
@Override

View file

@ -23,18 +23,23 @@ package org.libreplan.business.i18n;
/**
* This class provides a function to mark strings to be translated. Real
* translation have to be done in webapp module depending on user language and
* This class provides a function to mark strings to be translated.
* Real translation have to be done in webapp module depending on user language and
* not done here depending on server language.
*
* @author Manuel Rego Casasnovas <rego@igalia.com>
*/
public class I18nHelper {
private I18nHelper() {
}
private I18nHelper() {}
//TODO It should be changed since JDK9.
/**
* Use of '_' as an identifier might not be supported in releases after Java SE 8.
*
* @param str
* @return Text depends on locale
*/
public static String _(String text) {
return text;
}

View file

@ -23,6 +23,7 @@ import org.libreplan.business.common.daos.IEntitySequenceDAO;
import org.libreplan.business.common.entities.EntityNameEnum;
import org.libreplan.business.labels.daos.ILabelTypeDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
@ -33,7 +34,7 @@ import org.springframework.transaction.annotation.Transactional;
* @author Ignacio Díaz Teijido <ignacio.diaz@cafedered.com>
*/
@Component
@Scope("singleton")
@Scope(BeanDefinition.SCOPE_SINGLETON)
public class LabelBootstrap implements ILabelBootstrap {
@Autowired
@ -45,17 +46,16 @@ public class LabelBootstrap implements ILabelBootstrap {
@Override
@Transactional
public void loadRequiredData() {
if (labelTypeDAO.getAll().size() == 0) {
if (labelTypeDAO.getAll().isEmpty()) {
LabelType priorityType = LabelType.create("Priority");
priorityType.setCodeAutogenerated(true);
priorityType.setCode(entitySequenceDAO
.getNextEntityCodeWithoutTransaction(EntityNameEnum.LABEL));
priorityType.setCode(entitySequenceDAO.getNextEntityCodeWithoutTransaction(EntityNameEnum.LABEL));
for (PredefinedLabels predefinedLabel : PredefinedLabels.values()) {
Label label = predefinedLabel.getLabel();
priorityType.addLabel(label);
}
priorityType.generateLabelCodes(entitySequenceDAO
.getNumberOfDigitsCode(EntityNameEnum.LABEL));
priorityType.generateLabelCodes(entitySequenceDAO.getNumberOfDigitsCode(EntityNameEnum.LABEL));
labelTypeDAO.save(priorityType);
}

View file

@ -27,22 +27,30 @@ import org.libreplan.business.common.daos.IIntegrationEntityDAO;
import org.libreplan.business.users.entities.User;
/**
* IssueLog entity, represents parameters to be able to administrate issues that
* come up in the project
*
* IssueLog entity, represents parameters to be able to administrate issues that come up in the project.
*
* @author Misha Gozhda <misha@libreplan-enterprise.com>
*/
public class IssueLog extends ProjectLog {
private IssueTypeEnum type = IssueTypeEnum.getDefault();
private String status = "LOW";
private LowMediumHighEnum priority = LowMediumHighEnum.getDefault();
private LowMediumHighEnum severity = LowMediumHighEnum.getDefault();
private Date dateRaised;
private User createdBy;
private String assignedTo;
private Date dateResolved;
private Date deadline;
private String notes;
@ -151,7 +159,6 @@ public class IssueLog extends ProjectLog {
@Override
protected IIntegrationEntityDAO<? extends IntegrationEntity> getIntegrationEntityDAO() {
return (IIntegrationEntityDAO<? extends IntegrationEntity>) Registry
.getIssueLogDAO();
return Registry.getIssueLogDAO();
}
}

View file

@ -27,24 +27,34 @@ import org.libreplan.business.users.entities.User;
import java.util.Date;
/**
* RiskLog entity, represents parameters to be able to administrate risks that
* come up in the project
*
* RiskLog entity, represents parameters to be able to administrate risks that come up in the project.
*
* @author Misha Gozhda <misha@libreplan-enterprise.com>
*/
public class RiskLog extends ProjectLog {
private String projectName;
private String status;
private LowMediumHighEnum probability = LowMediumHighEnum.getDefault();
private LowMediumHighEnum impact = LowMediumHighEnum.getDefault();
private Date dateCreated;
private User createdBy;
private String counterMeasures;
private String contingency;
private String responsible;
private Date actionWhen;
private String notes;
private RiskScoreStatesEnum score = RiskScoreStatesEnum.getDefault();
public static RiskLog create() {
@ -169,8 +179,7 @@ public class RiskLog extends ProjectLog {
@Override
protected IIntegrationEntityDAO<? extends IntegrationEntity> getIntegrationEntityDAO() {
return (IIntegrationEntityDAO<? extends IntegrationEntity>) Registry
.getRiskLogDAO();
return Registry.getRiskLogDAO();
}
}

View file

@ -27,6 +27,7 @@ import org.libreplan.business.common.entities.EntityNameEnum;
import org.libreplan.business.materials.daos.IMaterialCategoryDAO;
import org.libreplan.business.materials.entities.MaterialCategory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
@ -37,7 +38,7 @@ import org.springframework.transaction.annotation.Transactional;
* @author Manuel Rego Casasnovas <mrego@igalia.com>
*/
@Component
@Scope("singleton")
@Scope(BeanDefinition.SCOPE_SINGLETON)
public class MaterialCategoryBootstrap implements IMaterialCategoryBootstrap {
@Autowired
@ -49,13 +50,10 @@ public class MaterialCategoryBootstrap implements IMaterialCategoryBootstrap {
@Override
@Transactional
public void loadRequiredData() {
for (PredefinedMaterialCategories predefinedMaterialCategory : PredefinedMaterialCategories
.values()) {
for (PredefinedMaterialCategories predefinedMaterialCategory : PredefinedMaterialCategories.values()) {
if (!materialCategoryDAO
.existsMaterialCategoryWithNameInAnotherTransaction(predefinedMaterialCategory
.getName())) {
MaterialCategory materialCategory = predefinedMaterialCategory
.createMaterialCategory();
.existsMaterialCategoryWithNameInAnotherTransaction(predefinedMaterialCategory.getName())) {
MaterialCategory materialCategory = predefinedMaterialCategory.createMaterialCategory();
materialCategory
.setCode(entitySequenceDAO
.getNextEntityCodeWithoutTransaction(EntityNameEnum.MATERIAL_CATEGORY));

View file

@ -28,17 +28,19 @@ import org.libreplan.business.common.exceptions.InstanceNotFoundException;
import org.libreplan.business.materials.daos.IUnitTypeDAO;
import org.libreplan.business.materials.entities.UnitType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
/**
* Creates the bootstrap of the predefined {@link UnitType}.
*
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
*/
@Component
@Scope("singleton")
@Scope(BeanDefinition.SCOPE_SINGLETON)
public class UnitTypeBootstrap implements IDataBootstrap {
@Autowired
@ -52,24 +54,21 @@ public class UnitTypeBootstrap implements IDataBootstrap {
@Transactional
@Override
public void loadRequiredData() {
for (PredefinedUnitTypes predefinedUnitType : PredefinedUnitTypes
.values()) {
UnitType type = null;
for (PredefinedUnitTypes predefinedUnitType : PredefinedUnitTypes.values()) {
UnitType type;
try {
type = unitTypeDAO
.findUniqueByNameInAnotherTransaction(predefinedUnitType
.getMeasure());
} catch (InstanceNotFoundException e) {
type = predefinedUnitType.createUnitType();
type
.setCode(entitySequenceDAO
.getNextEntityCodeWithoutTransaction(EntityNameEnum.UNIT_TYPE));
type.setCode(entitySequenceDAO
.getNextEntityCodeWithoutTransaction(EntityNameEnum.UNIT_TYPE));
type.setCodeAutogenerated(true);
unitTypeDAO.save(type);
}
if (predefinedUnitType
.equals(PredefinedUnitTypes.defaultUnitType())) {
defaultUnitType = type;
if (predefinedUnitType.equals(PredefinedUnitTypes.defaultUnitType())) {
UnitTypeBootstrap.defaultUnitType = type;
}
}
}
@ -78,6 +77,7 @@ public class UnitTypeBootstrap implements IDataBootstrap {
if (defaultUnitType.isNewObject()) {
defaultUnitType.dontPoseAsTransientObjectAnymore();
}
return defaultUnitType;
}
}

View file

@ -40,30 +40,31 @@ import org.libreplan.business.common.exceptions.InstanceNotFoundException;
import org.libreplan.business.materials.daos.IMaterialCategoryDAO;
/**
* MaterialCategory entity
* MaterialCategory entity.
*
* @author Jacobo Aragunde Perez <jaragunde@igalia.com>
*
*/
public class MaterialCategory extends IntegrationEntity {
public static List<Material> getAllMaterialsFrom(
Collection<? extends MaterialCategory> categories) {
List<Material> result = new ArrayList<Material>();
public static List<Material> getAllMaterialsFrom(Collection<? extends MaterialCategory> categories) {
List<Material> result = new ArrayList<>();
for (MaterialCategory each : categories) {
result.addAll(each.getMaterials());
}
return result;
}
public static List<Material> getAllMaterialsWithoutAutogeneratedCodeFrom(
Collection<? extends MaterialCategory> categories) {
List<Material> result = new ArrayList<Material>();
List<Material> result = new ArrayList<>();
for (MaterialCategory each : categories) {
if (!each.isCodeAutogenerated()) {
result.addAll(each.getMaterials());
}
}
return result;
}
@ -86,12 +87,13 @@ public class MaterialCategory extends IntegrationEntity {
}
public static MaterialCategory create(String name) {
return (MaterialCategory) create(new MaterialCategory(name));
return create(new MaterialCategory(name));
}
public static MaterialCategory createUnvalidated(String code, String name) {
MaterialCategory materialCategory = create(new MaterialCategory(), code);
materialCategory.name = name;
return materialCategory;
}
@ -153,32 +155,34 @@ public class MaterialCategory extends IntegrationEntity {
@AssertTrue(message="material category name has to be unique. It is already used")
public boolean isUniqueNameConstraint() {
boolean result;
if (isNewObject()) {
result = !existsMaterialCategoryWithTheName();
} else {
result = isIfExistsTheExistentMaterialCategoryThisOne();
}
return result;
}
private boolean existsMaterialCategoryWithTheName() {
IMaterialCategoryDAO materialCategoryDAO = Registry.getMaterialCategoryDAO();
return materialCategoryDAO.existsMaterialCategoryWithNameInAnotherTransaction(name);
}
private boolean isIfExistsTheExistentMaterialCategoryThisOne() {
IMaterialCategoryDAO materialCategoryDAO = Registry.getMaterialCategoryDAO();
try {
MaterialCategory materialCategory =
materialCategoryDAO.findUniqueByNameInAnotherTransaction(name);
MaterialCategory materialCategory = materialCategoryDAO.findUniqueByNameInAnotherTransaction(name);
return materialCategory.getId().equals(getId());
} catch (InstanceNotFoundException e) {
return true;
}
}
public Material getMaterialByCode(String code)
throws InstanceNotFoundException {
public Material getMaterialByCode(String code) throws InstanceNotFoundException {
if (StringUtils.isBlank(code)) {
throw new InstanceNotFoundException(code, Material.class.getName());
@ -194,12 +198,10 @@ public class MaterialCategory extends IntegrationEntity {
}
public MaterialCategory getSubcategoryByCode(String code)
throws InstanceNotFoundException {
public MaterialCategory getSubcategoryByCode(String code) throws InstanceNotFoundException {
if (StringUtils.isBlank(code)) {
throw new InstanceNotFoundException(code, MaterialCategory.class
.getName());
throw new InstanceNotFoundException(code, MaterialCategory.class.getName());
}
for (MaterialCategory s : this.subcategories) {
@ -208,8 +210,7 @@ public class MaterialCategory extends IntegrationEntity {
}
}
throw new InstanceNotFoundException(code, MaterialCategory.class
.getName());
throw new InstanceNotFoundException(code, MaterialCategory.class.getName());
}
@ -221,11 +222,13 @@ public class MaterialCategory extends IntegrationEntity {
@SuppressWarnings("unused")
@AssertTrue(message = "Subcategory names must be unique.")
public boolean isUniqueSubcategoryNameConstraint() {
Set<String> subcategoriesNames = new HashSet<String>();
Set<String> subcategoriesNames = new HashSet<>();
for (MaterialCategory mc : this.getAllSubcategories()) {
if (!StringUtils.isBlank(mc.getName())) {
String name = StringUtils.deleteWhitespace(mc.getName()
.toLowerCase());
String name = StringUtils.deleteWhitespace(mc.getName().toLowerCase());
if (subcategoriesNames.contains(name)) {
return false;
} else {
@ -240,42 +243,43 @@ public class MaterialCategory extends IntegrationEntity {
public boolean isNonRepeatedMaterialCategoryCodesConstraint() {
Set<MaterialCategory> allSubcategories = getAllSubcategories();
allSubcategories.add(this);
return getFirstRepeatedCode(allSubcategories) == null;
}
private Set<MaterialCategory> getAllSubcategories() {
Set<MaterialCategory> result = new HashSet<MaterialCategory>(subcategories);
Set<MaterialCategory> result = new HashSet<>(subcategories);
for (MaterialCategory subcategory : subcategories) {
result.addAll(subcategory.getAllSubcategories());
}
return result;
}
@AssertTrue(message = "There are repeated material codes")
public boolean isNonRepeatedMaterialCodesConstraint() {
Set<Material> allMaterials = getAllMaterials();
return getFirstRepeatedCode(allMaterials) == null;
}
private Set<Material> getAllMaterials() {
Set<Material> result = new HashSet<Material>(materials);
Set<Material> result = new HashSet<>(materials);
for (MaterialCategory subcategory : subcategories) {
result.addAll(subcategory.getAllMaterials());
}
return result;
}
public void generateMaterialCodes(int numberOfDigits) {
for (Material material : this.getMaterials()) {
if ((material.getCode() == null) || (material.getCode().isEmpty())
|| (!material.getCode().startsWith(this.getCode()))) {
if ((material.getCode() == null) || (material.getCode().isEmpty()) ||
(!material.getCode().startsWith(this.getCode()))) {
this.incrementLastMaterialSequenceCode();
String materialCode = EntitySequence.formatValue(
numberOfDigits, this.getLastMaterialSequenceCode());
material
.setCode(this.getCode()
+ EntitySequence.CODE_SEPARATOR_CHILDREN
+ materialCode);
String materialCode = EntitySequence.formatValue(numberOfDigits, this.getLastMaterialSequenceCode());
material.setCode(this.getCode() + EntitySequence.CODE_SEPARATOR_CHILDREN + materialCode);
}
}
}
@ -284,6 +288,7 @@ public class MaterialCategory extends IntegrationEntity {
if (this.lastMaterialSequenceCode == null) {
this.lastMaterialSequenceCode = 0;
}
this.lastMaterialSequenceCode++;
}

View file

@ -26,9 +26,7 @@ import org.libreplan.business.orders.entities.OrderFile;
import java.util.List;
/**
* Created by
* @author Vova Perebykivskiy <vova@libreplan-enterprise.com>
* on 12.24.2015.
* @author Created by Vova Perebykivskyi <vova@libreplan-enterprise.com> on 12.24.2015.
*/
public interface IOrderFileDAO extends IGenericDAO<OrderFile, Long> {

View file

@ -64,7 +64,7 @@ import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
/**
* Dao for {@link Order}
* DAO for {@link Order}.
*
* @author Óscar González Fernández <ogonzalez@igalia.com>
* @author Lorenzo Tilve Álvaro <ltilve@igalia.com>
@ -72,8 +72,7 @@ import org.springframework.transaction.annotation.Transactional;
*/
@Repository
@Scope(BeanDefinition.SCOPE_SINGLETON)
public class OrderDAO extends IntegrationEntityDAO<Order> implements
IOrderDAO {
public class OrderDAO extends IntegrationEntityDAO<Order> implements IOrderDAO {
@Autowired
private ITaskSourceDAO taskSourceDAO;
@ -90,6 +89,8 @@ public class OrderDAO extends IntegrationEntityDAO<Order> implements
@Autowired
private IAdHocTransactionService transactionService;
private String STATE_PARAMETER = "state";
@Override
public List<Order> getOrders() {
return list(Order.class);
@ -111,34 +112,39 @@ public class OrderDAO extends IntegrationEntityDAO<Order> implements
return false;
}
private boolean matchFilterCriterion(OrderElement orderElement,
List<Criterion> criterions) {
private boolean matchFilterCriterion(OrderElement orderElement, List<Criterion> criterions) {
if ((criterions != null) && (!criterions.isEmpty())) {
List<OrderElement> orderElements = new ArrayList<OrderElement>();
List<OrderElement> orderElements = new ArrayList<>();
orderElements.add(orderElement);
List<Task> tasks = this.getFilteredTask(orderElements, criterions);
return (!tasks.isEmpty());
return !tasks.isEmpty();
}
return true;
}
@Transactional(readOnly = true)
public List<OrderCostsPerResourceDTO> getOrderCostsPerResource(
List<Order> orders, Date startingDate, Date endingDate,
List<Order> orders,
Date startingDate,
Date endingDate,
List<Criterion> criterions) {
String strQuery = "SELECT new org.libreplan.business.reports.dtos.OrderCostsPerResourceDTO(worker, wrl) "
+ "FROM Worker worker, WorkReportLine wrl "
+ "LEFT OUTER JOIN wrl.resource resource "
+ "WHERE resource.id = worker.id ";
String strQuery = "SELECT new org.libreplan.business.reports.dtos.OrderCostsPerResourceDTO(worker, wrl) " +
"FROM Worker worker, WorkReportLine wrl " +
"LEFT OUTER JOIN wrl.resource resource " +
"WHERE resource.id = worker.id ";
// Set date range
if (startingDate != null && endingDate != null) {
strQuery += "AND wrl.date BETWEEN :startingDate AND :endingDate ";
}
if (startingDate != null && endingDate == null) {
strQuery += "AND wrl.date >= :startingDate ";
}
if (startingDate == null && endingDate != null) {
strQuery += "AND wrl.date <= :endingDate ";
}
@ -151,34 +157,32 @@ public class OrderDAO extends IntegrationEntityDAO<Order> implements
if (startingDate != null) {
query.setParameter("startingDate", startingDate);
}
if (endingDate != null) {
query.setParameter("endingDate", endingDate);
}
List<OrderCostsPerResourceDTO> list = query.list();
List<OrderCostsPerResourceDTO> filteredList = new ArrayList<OrderCostsPerResourceDTO>();
List<OrderCostsPerResourceDTO> filteredList = new ArrayList<>();
for (OrderCostsPerResourceDTO each : list) {
Order order = loadOrderAvoidingProxyFor(each.getOrderElement());
// Apply filtering
if (matchFilterCriterion(each.getOrderElement(), criterions)
&& isOrderContained(order, orders)) {
if (matchFilterCriterion(each.getOrderElement(), criterions) && isOrderContained(order, orders)) {
// Attach ordername value
each.setOrderName(order.getName());
each.setOrderCode(order.getCode());
// Attach calculated pricePerHour
BigDecimal pricePerHour = CostCategoryDAO
.getPriceByResourceDateAndHourType(each.getWorker(),
new LocalDate(each.getDate()), each
.getHoursTypeCode());
BigDecimal pricePerHour = CostCategoryDAO.getPriceByResourceDateAndHourType(
each.getWorker(), new LocalDate(each.getDate()), each.getHoursTypeCode());
if (pricePerHour == null) {
for (TypeOfWorkHours defaultprice : typeOfWorkHoursDAO
.list(TypeOfWorkHours.class)) {
if (defaultprice.getCode().equals(
each.getHoursTypeCode())) {
for (TypeOfWorkHours defaultprice : typeOfWorkHoursDAO.list(TypeOfWorkHours.class)) {
if (defaultprice.getCode().equals(each.getHoursTypeCode())) {
pricePerHour = defaultprice.getDefaultPrice();
}
}
@ -194,21 +198,24 @@ public class OrderDAO extends IntegrationEntityDAO<Order> implements
@Override
public List<Order> getOrdersByReadAuthorization(User user) {
if (user.isInRole(UserRole.ROLE_SUPERUSER)
|| user.isInRole(UserRole.ROLE_READ_ALL_PROJECTS)
|| user.isInRole(UserRole.ROLE_EDIT_ALL_PROJECTS)) {
if (user.isInRole(UserRole.ROLE_SUPERUSER) ||
user.isInRole(UserRole.ROLE_READ_ALL_PROJECTS) ||
user.isInRole(UserRole.ROLE_EDIT_ALL_PROJECTS)) {
return getOrders();
}
else {
List<Order> orders = new ArrayList<Order>();
List<Order> orders = new ArrayList<>();
List<OrderAuthorization> authorizations = orderAuthorizationDAO.listByUserAndItsProfiles(user);
for(OrderAuthorization authorization : authorizations) {
if (authorization.getAuthorizationType() == OrderAuthorizationType.READ_AUTHORIZATION ||
authorization.getAuthorizationType() == OrderAuthorizationType.WRITE_AUTHORIZATION) {
authorization.getAuthorizationType() == OrderAuthorizationType.WRITE_AUTHORIZATION) {
Order order = authorization.getOrder();
if(!orders.contains(order)) {
order.getName(); //this lines forces the load of the basic attributes of the order
if (!orders.contains(order)) {
// These lines forces the load of the basic attributes of the order
order.getName();
orders.add(order);
}
}
@ -218,11 +225,15 @@ public class OrderDAO extends IntegrationEntityDAO<Order> implements
}
private List<Order> getOrdersByReadAuthorizationBetweenDatesByLabelsCriteriaCustomerAndState(
User user, Date startDate, Date endDate, List<Label> labels,
List<Criterion> criteria, ExternalCompany customer,
User user,
Date startDate,
Date endDate,
List<Label> labels,
List<Criterion> criteria,
ExternalCompany customer,
OrderStatusEnum state) {
List<Long> ordersIdsFiltered = getOrdersIdsFiltered(user, labels,
criteria, customer, state);
List<Long> ordersIdsFiltered = getOrdersIdsFiltered(user, labels, criteria, customer, state);
if (ordersIdsFiltered != null && ordersIdsFiltered.isEmpty()) {
return Collections.emptyList();
}
@ -232,19 +243,22 @@ public class OrderDAO extends IntegrationEntityDAO<Order> implements
return Collections.emptyList();
}
List<Long> ordersIdsUnscheduled = getOrdersIdsUnscheduled(startDate,
endDate);
List<Long> ordersIdsUnscheduled = getOrdersIdsUnscheduled(startDate, endDate);
Criteria c = getSession().createCriteria(Order.class);
if (ordersIdsFiltered != null && ordersIdsByDates != null) {
org.hibernate.criterion.Criterion and = Restrictions.and(
Restrictions.in("id", ordersIdsFiltered),
Restrictions.in("id", ordersIdsByDates));
c.add(and);
} else {
if (ordersIdsFiltered != null) {
c.add(Restrictions.in("id", ordersIdsFiltered));
}
if (ordersIdsByDates != null) {
if (ordersIdsUnscheduled.isEmpty()) {
c.add(Restrictions.in("id", ordersIdsByDates));
@ -258,13 +272,15 @@ public class OrderDAO extends IntegrationEntityDAO<Order> implements
c.addOrder(org.hibernate.criterion.Order.desc("initDate"));
c.addOrder(org.hibernate.criterion.Order.asc("infoComponent.name"));
return c.list();
}
private List<Long> getOrdersIdsUnscheduled(Date startDate, Date endDate) {
String strQuery = "SELECT s.orderElement.id "
+ "FROM SchedulingDataForVersion s "
+ "WHERE s.schedulingStateType = :type";
String strQuery = "SELECT s.orderElement.id " +
"FROM SchedulingDataForVersion s " +
"WHERE s.schedulingStateType = :type";
Query query = getSession().createQuery(strQuery);
query.setParameter("type", SchedulingState.Type.NO_SCHEDULED);
@ -273,9 +289,7 @@ public class OrderDAO extends IntegrationEntityDAO<Order> implements
return Collections.emptyList();
}
String strQueryDates = "SELECT o.id "
+ "FROM Order o "
+ "WHERE o.id IN (:ids) ";
String strQueryDates = "SELECT o.id " + "FROM Order o " + "WHERE o.id IN (:ids) ";
if (startDate != null) {
strQueryDates += "AND o.initDate >= :startDate ";
@ -298,28 +312,32 @@ public class OrderDAO extends IntegrationEntityDAO<Order> implements
/**
* If both params are <code>null</code> it returns <code>null</code>.
* Otherwise it filters the list of tasks to return the ones wihtout parent
* between the dates.
* Otherwise it filters the list of tasks to return the ones without parent between the dates.
*/
private List<Long> getOrdersIdsByDates(Date startDate, Date endDate) {
if (startDate == null && endDate == null) {
/* Don't replace null with Collections.emptyList(), as the prompt says (sometimes), because it breaks logic */
return null;
}
String strQuery = "SELECT t.taskSource.schedulingData.orderElement.id "
+ "FROM TaskElement t "
+ "WHERE t.parent IS NULL ";
if (endDate != null) {
strQuery += "AND t.startDate.date <= :endDate ";
}
if (startDate != null) {
strQuery += "AND t.endDate.date >= :startDate ";
}
Query query = getSession().createQuery(strQuery);
if (startDate != null) {
query.setParameter("startDate", LocalDate.fromDateFields(startDate));
}
if (endDate != null) {
query.setParameter("endDate", LocalDate.fromDateFields(endDate));
}
@ -328,13 +346,16 @@ public class OrderDAO extends IntegrationEntityDAO<Order> implements
}
/**
* If user has permissions over all orders and not filters are passed it
* returns <code>null</code>. Otherwise, it returns the list of orders
* If user has permissions over all orders and not filters are passed it returns <code>null</code>.
* Otherwise, it returns the list of orders
* identifiers for which the user has read permissions and the filters pass.
*/
private List<Long> getOrdersIdsFiltered(User user, List<Label> labels,
List<Criterion> criteria, ExternalCompany customer,
OrderStatusEnum state) {
private List<Long> getOrdersIdsFiltered(User user,
List<Label> labels,
List<Criterion> criteria,
ExternalCompany customer,
OrderStatusEnum state) {
List<Long> ordersIdsByReadAuthorization = getOrdersIdsByReadAuthorization(user);
String strQuery = "SELECT o.id ";
@ -389,8 +410,7 @@ public class OrderDAO extends IntegrationEntityDAO<Order> implements
return ordersIdsByReadAuthorization;
}
if (ordersIdsByReadAuthorization != null
&& !ordersIdsByReadAuthorization.isEmpty()) {
if (ordersIdsByReadAuthorization != null && !ordersIdsByReadAuthorization.isEmpty()) {
if (where.isEmpty()) {
where += "WHERE ";
} else {
@ -401,6 +421,7 @@ public class OrderDAO extends IntegrationEntityDAO<Order> implements
strQuery += where + whereFinal;
Query query = getSession().createQuery(strQuery);
if (labels != null && !labels.isEmpty()) {
int i = 0;
for (Label label : labels) {
@ -408,6 +429,7 @@ public class OrderDAO extends IntegrationEntityDAO<Order> implements
i++;
}
}
if (criteria != null && !criteria.isEmpty()) {
query.setParameterList("criteria", criteria);
query.setParameter("criteriaSize", (long) criteria.size());
@ -418,11 +440,10 @@ public class OrderDAO extends IntegrationEntityDAO<Order> implements
}
if (state != null) {
query.setParameter("state", state);
query.setParameter(STATE_PARAMETER, state);
}
if (ordersIdsByReadAuthorization != null
&& !ordersIdsByReadAuthorization.isEmpty()) {
if (ordersIdsByReadAuthorization != null && !ordersIdsByReadAuthorization.isEmpty()) {
query.setParameterList("ids", ordersIdsByReadAuthorization);
}
@ -431,8 +452,7 @@ public class OrderDAO extends IntegrationEntityDAO<Order> implements
/**
* If user has permissions over all orders it returns <code>null</code>.
* Otherwise, it returns the list of orders identifiers for which the user
* has read permissions.
* Otherwise, it returns the list of orders identifiers for which the user has read permissions.
*/
private List<Long> getOrdersIdsByReadAuthorization(User user) {
if (user.isInRole(UserRole.ROLE_SUPERUSER)
@ -464,7 +484,7 @@ public class OrderDAO extends IntegrationEntityDAO<Order> implements
return getOrders();
}
else {
List<Order> orders = new ArrayList<Order>();
List<Order> orders = new ArrayList<>();
List<OrderAuthorization> authorizations = orderAuthorizationDAO.listByUserAndItsProfiles(user);
for(OrderAuthorization authorization : authorizations) {
if (authorization.getAuthorizationType() == OrderAuthorizationType.WRITE_AUTHORIZATION) {
@ -481,8 +501,10 @@ public class OrderDAO extends IntegrationEntityDAO<Order> implements
@Override
public List<Order> findAll() {
return getSession().createCriteria(getEntityClass()).addOrder(
org.hibernate.criterion.Order.asc("infoComponent.code")).list();
return getSession()
.createCriteria(getEntityClass())
.addOrder(org.hibernate.criterion.Order.asc("infoComponent.code"))
.list();
}
@SuppressWarnings("unchecked")
@ -491,18 +513,16 @@ public class OrderDAO extends IntegrationEntityDAO<Order> implements
public Order findByCode(String code) throws InstanceNotFoundException {
if (StringUtils.isBlank(code)) {
throw new InstanceNotFoundException(null, getEntityClass()
.getName());
throw new InstanceNotFoundException(null, getEntityClass().getName());
}
Order entity = (Order) getSession().createCriteria(getEntityClass())
.add(
Restrictions.eq("infoComponent.code", code.trim())
.ignoreCase()).uniqueResult();
Order entity = (Order) getSession()
.createCriteria(getEntityClass())
.add(Restrictions.eq("infoComponent.code", code.trim()).ignoreCase())
.uniqueResult();
if (entity == null) {
throw new InstanceNotFoundException(code, getEntityClass()
.getName());
throw new InstanceNotFoundException(code, getEntityClass().getName());
} else {
return entity;
}
@ -510,8 +530,7 @@ public class OrderDAO extends IntegrationEntityDAO<Order> implements
}
@Override
public List<Order> getOrdersByReadAuthorizationByScenario(String username,
Scenario scenario) {
public List<Order> getOrdersByReadAuthorizationByScenario(String username, Scenario scenario) {
User user;
try {
user = userDAO.findByLoginName(username);
@ -523,23 +542,27 @@ public class OrderDAO extends IntegrationEntityDAO<Order> implements
@Override
public List<Order> getOrdersByReadAuthorizationBetweenDatesByLabelsCriteriaCustomerAndState(
String username, Scenario scenario, Date startDate, Date endDate,
List<Label> labels, List<Criterion> criteria,
ExternalCompany customer, OrderStatusEnum state) {
String username,
Scenario scenario,
Date startDate,
Date endDate,
List<Label> labels,
List<Criterion> criteria,
ExternalCompany customer,
OrderStatusEnum state) {
User user;
try {
user = userDAO.findByLoginName(username);
} catch (InstanceNotFoundException e) {
throw new RuntimeException(e);
}
return existsInScenario(
getOrdersByReadAuthorizationBetweenDatesByLabelsCriteriaCustomerAndState(
user, startDate, endDate, labels, criteria, customer,
state), scenario);
return existsInScenario(getOrdersByReadAuthorizationBetweenDatesByLabelsCriteriaCustomerAndState(
user, startDate, endDate, labels, criteria, customer, state), scenario);
}
private List<Order> existsInScenario(List<Order> orders, Scenario scenario) {
List<Order> result = new ArrayList<Order>();
List<Order> result = new ArrayList<>();
for (Order each : orders) {
if (scenario.contains(each)) {
result.add(each);
@ -549,28 +572,24 @@ public class OrderDAO extends IntegrationEntityDAO<Order> implements
}
@Transactional(readOnly = true, propagation = Propagation.REQUIRES_NEW)
public Order findByNameAnotherTransaction(String name)
throws InstanceNotFoundException {
public Order findByNameAnotherTransaction(String name) throws InstanceNotFoundException {
return findByName(name);
}
@SuppressWarnings("unchecked")
private Order findByName(String name) throws InstanceNotFoundException {
if (StringUtils.isBlank(name)) {
throw new InstanceNotFoundException(null,
getEntityClass().getName());
throw new InstanceNotFoundException(null, getEntityClass().getName());
}
Order order = (Order) getSession().createCriteria(getEntityClass())
Order order = (Order) getSession()
.createCriteria(getEntityClass())
.add(Restrictions.eq("infoComponent.name", name).ignoreCase())
.uniqueResult();
if (order == null) {
throw new InstanceNotFoundException(
name, getEntityClass().getName());
throw new InstanceNotFoundException(name, getEntityClass().getName());
} else {
return order;
}
@ -584,26 +603,25 @@ public class OrderDAO extends IntegrationEntityDAO<Order> implements
@Override
@Transactional(readOnly = true)
public List<Task> getFilteredTask(List<OrderElement> orderElements,
List<Criterion> criterions) {
public List<Task> getFilteredTask(List<OrderElement> orderElements, List<Criterion> criterions) {
if (orderElements == null || orderElements.isEmpty()) {
return new ArrayList<Task>();
return new ArrayList<>();
}
String strQuery = "SELECT taskSource.task "
+ "FROM OrderElement orderElement, TaskSource taskSource, Task task "
+ "LEFT OUTER JOIN taskSource.schedulingData.orderElement taskSourceOrderElement "
+ "LEFT OUTER JOIN taskSource.task taskElement "
+ "WHERE taskSourceOrderElement.id = orderElement.id "
+ "AND taskElement.id = task.id AND orderElement IN (:orderElements) ";
String strQuery = "SELECT taskSource.task " +
"FROM OrderElement orderElement, TaskSource taskSource, Task task " +
"LEFT OUTER JOIN taskSource.schedulingData.orderElement taskSourceOrderElement " +
"LEFT OUTER JOIN taskSource.task taskElement " +
"WHERE taskSourceOrderElement.id = orderElement.id " +
"AND taskElement.id = task.id AND orderElement IN (:orderElements) ";
// Set Criterions
if (criterions != null && !criterions.isEmpty()) {
strQuery += " AND (EXISTS (FROM task.resourceAllocations as allocation, GenericResourceAllocation as generic "
+ " WHERE generic.id = allocation.id "
+ " AND EXISTS( FROM generic.criterions criterion WHERE criterion IN (:criterions))))";
strQuery += " AND (EXISTS (FROM task.resourceAllocations as allocation, GenericResourceAllocation as generic " +
" WHERE generic.id = allocation.id " +
" AND EXISTS( FROM generic.criterions criterion WHERE criterion IN (:criterions))))";
}
// Order by
@ -614,29 +632,24 @@ public class OrderDAO extends IntegrationEntityDAO<Order> implements
query.setParameterList("orderElements", orderElements);
if (criterions != null && !criterions.isEmpty()) {
query.setParameterList("criterions",
Criterion.withAllDescendants(criterions));
query.setParameterList("criterions", Criterion.withAllDescendants(criterions));
}
// Get result
return query.list();
}
@Override
public Order loadOrderAvoidingProxyFor(final OrderElement orderElement) {
return loadOrdersAvoidingProxyFor(
Collections.singletonList(orderElement)).get(0);
return loadOrdersAvoidingProxyFor(Collections.singletonList(orderElement)).get(0);
}
@Override
public List<Order> loadOrdersAvoidingProxyFor(
final List<OrderElement> orderElements) {
List<OrderElement> orders = transactionService
.runOnAnotherTransaction(new IOnTransaction<List<OrderElement>>() {
public List<Order> loadOrdersAvoidingProxyFor(final List<OrderElement> orderElements) {
List<OrderElement> orders =
transactionService.runOnAnotherTransaction(new IOnTransaction<List<OrderElement>>() {
@Override
public List<OrderElement> execute() {
List<OrderElement> result = new ArrayList<OrderElement>();
List<OrderElement> result = new ArrayList<>();
for (OrderElement each : orderElements) {
if (each.isNewObject()) {
result.add(each.getOrder());
@ -650,6 +663,7 @@ public class OrderDAO extends IntegrationEntityDAO<Order> implements
private OrderElement orderFrom(OrderElement initial) {
OrderElement current = initial;
OrderElement result = current;
while (current != null) {
result = current;
current = findParent(current);
@ -659,14 +673,14 @@ public class OrderDAO extends IntegrationEntityDAO<Order> implements
private OrderElement findParent(OrderElement orderElement) {
Query query = getSession()
.createQuery(
"select e.parent from OrderElement e where e.id = :id")
.createQuery("select e.parent from OrderElement e where e.id = :id")
.setParameter("id", orderElement.getId());
return (OrderElement) query.uniqueResult();
}
});
List<Order> result = new ArrayList<Order>();
List<Order> result = new ArrayList<>();
for (OrderElement each : orders) {
if (each != null) {
result.add(findExistingEntity(each.getId()));
@ -692,26 +706,31 @@ public class OrderDAO extends IntegrationEntityDAO<Order> implements
@SuppressWarnings("unchecked")
public List<Order> getActiveOrders() {
Criteria criteria = getSession().createCriteria(getEntityClass());
criteria.add(Restrictions.not(Restrictions.eq("state", OrderStatusEnum.CANCELLED)));
criteria.add(Restrictions.not(Restrictions.eq("state", OrderStatusEnum.STORED)));
criteria.add(Restrictions.not(Restrictions.eq(STATE_PARAMETER, OrderStatusEnum.CANCELLED)));
criteria.add(Restrictions.not(Restrictions.eq(STATE_PARAMETER, OrderStatusEnum.STORED)));
return criteria.list();
}
@Override
public List<CostExpenseSheetDTO> getCostExpenseSheet(List<Order> orders, Date startingDate,
Date endingDate, List<Criterion> criterions) {
public List<CostExpenseSheetDTO> getCostExpenseSheet(List<Order> orders,
Date startingDate,
Date endingDate,
List<Criterion> criterions) {
String strQuery = "SELECT new org.libreplan.business.reports.dtos.CostExpenseSheetDTO(expense) "
+ "FROM OrderElement orderElement, ExpenseSheetLine expense "
+ "LEFT OUTER JOIN expense.orderElement exp_ord "
+ "WHERE orderElement.id = exp_ord.id ";
String strQuery = "SELECT new org.libreplan.business.reports.dtos.CostExpenseSheetDTO(expense) " +
"FROM OrderElement orderElement, ExpenseSheetLine expense " +
"LEFT OUTER JOIN expense.orderElement exp_ord " +
"WHERE orderElement.id = exp_ord.id ";
if (startingDate != null && endingDate != null) {
strQuery += "AND expense.date BETWEEN :startingDate AND :endingDate ";
}
if (startingDate != null && endingDate == null) {
strQuery += "AND expense.date >= :startingDate ";
}
if (startingDate == null && endingDate != null) {
strQuery += "AND expense.date <= :endingDate ";
}
@ -725,18 +744,19 @@ public class OrderDAO extends IntegrationEntityDAO<Order> implements
if (startingDate != null) {
query.setParameter("startingDate", new LocalDate(startingDate));
}
if (endingDate != null) {
query.setParameter("endingDate", new LocalDate(endingDate));
}
List<CostExpenseSheetDTO> list = query.list();
List<CostExpenseSheetDTO> filteredList = new ArrayList<CostExpenseSheetDTO>();
List<CostExpenseSheetDTO> filteredList = new ArrayList<>();
for (CostExpenseSheetDTO each : list) {
Order order = loadOrderAvoidingProxyFor(each.getOrderElement());
// Apply filtering
if (matchFilterCriterion(each.getOrderElement(), criterions)
&& isOrderContained(order, orders)) {
if (matchFilterCriterion(each.getOrderElement(), criterions) && isOrderContained(order, orders)) {
each.setOrder(order);
filteredList.add(each);
}

View file

@ -61,7 +61,7 @@ import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
/**
* Dao for {@link OrderElement}
* Dao for {@link OrderElement}.
*
* @author Manuel Rego Casasnovas <mrego@igalia.com>
* @author Diego Pino García <dpino@igalia.com>
@ -86,10 +86,10 @@ public class OrderElementDAO extends IntegrationEntityDAO<OrderElement> implemen
@Override
public List<OrderElement> findWithoutParent() {
Criteria c = getSession().createCriteria(OrderElement.class);
c.add(Restrictions.isNull("parent"));
return (List<OrderElement>) c.list();
return getSession()
.createCriteria(OrderElement.class)
.add(Restrictions.isNull("parent"))
.list();
}
public List<OrderElement> findByCodeAndParent(OrderElement parent, String code) {
@ -116,11 +116,11 @@ public class OrderElementDAO extends IntegrationEntityDAO<OrderElement> implemen
@Transactional(readOnly = true)
public EffortDuration getAssignedDirectEffort(OrderElement orderElement) {
List<WorkReportLine> listWRL = this.workReportLineDAO.findByOrderElement(orderElement);
EffortDuration asignedDirectHours = EffortDuration.zero();
EffortDuration assignedDirectHours = EffortDuration.zero();
for (WorkReportLine aListWRL : listWRL) {
asignedDirectHours = asignedDirectHours.plus(aListWRL.getEffort());
assignedDirectHours = assignedDirectHours.plus(aListWRL.getEffort());
}
return asignedDirectHours;
return assignedDirectHours;
}
@Override
@ -134,11 +134,9 @@ public class OrderElementDAO extends IntegrationEntityDAO<OrderElement> implemen
BigDecimal assignedHours = totalChargedEffort.toHoursAsDecimalWithScale(2);
BigDecimal estimatedHours = new BigDecimal(orderElement.getWorkHours()).setScale(2);
if ( estimatedHours.compareTo(BigDecimal.ZERO) <= 0 ) {
return BigDecimal.ZERO;
}
return assignedHours.divide(estimatedHours, RoundingMode.DOWN);
return estimatedHours.compareTo(BigDecimal.ZERO) <= 0
? BigDecimal.ZERO
: assignedHours.divide(estimatedHours, RoundingMode.DOWN);
}
@Override
@ -185,7 +183,8 @@ public class OrderElementDAO extends IntegrationEntityDAO<OrderElement> implemen
public List<OrderElement> findAll() {
return getSession()
.createCriteria(getEntityClass())
.addOrder(org.hibernate.criterion.Order.asc("infoComponent.code")).list();
.addOrder(org.hibernate.criterion.Order.asc("infoComponent.code"))
.list();
}
@SuppressWarnings("unchecked")
@ -211,10 +210,10 @@ public class OrderElementDAO extends IntegrationEntityDAO<OrderElement> implemen
}
public List<OrderElement> findByTemplate(OrderElementTemplate template) {
Criteria c = getSession().createCriteria(OrderElement.class);
c.add(Restrictions.eq("template", template));
return (List<OrderElement>) c.list();
return getSession()
.createCriteria(OrderElement.class)
.add(Restrictions.eq("template", template))
.list();
}
@Override
@ -244,10 +243,10 @@ public class OrderElementDAO extends IntegrationEntityDAO<OrderElement> implemen
@Override
public List<OrderElement> findOrderElementsWithExternalCode() {
Criteria c = getSession().createCriteria(OrderElement.class);
c.add(Restrictions.isNotNull("externalCode"));
return c.list();
return getSession()
.createCriteria(OrderElement.class)
.add(Restrictions.isNotNull("externalCode"))
.list();
}
@ -259,9 +258,10 @@ public class OrderElementDAO extends IntegrationEntityDAO<OrderElement> implemen
throw new InstanceNotFoundException(null, getEntityClass().getName());
}
Criteria c = getSession().createCriteria(OrderElement.class);
c.add(Restrictions.eq("externalCode", code.trim()).ignoreCase());
OrderElement entity = (OrderElement) c.uniqueResult();
OrderElement entity = (OrderElement) getSession()
.createCriteria(OrderElement.class)
.add(Restrictions.eq("externalCode", code.trim()).ignoreCase())
.uniqueResult();
if ( entity == null ) {
throw new InstanceNotFoundException(code, getEntityClass().getName());
@ -273,20 +273,17 @@ public class OrderElementDAO extends IntegrationEntityDAO<OrderElement> implemen
/**
* Methods to calculate statistics with the estimated hours and worked hours of a set of order elements.
* @param List
*
* @param list
* <{@link OrderElement}>
*/
public BigDecimal calculateAverageEstimatedHours(final List<OrderElement> list) {
BigDecimal sum = sumEstimatedHours(list);
return average(new BigDecimal(list.size()), sum);
return average(new BigDecimal(list.size()), sumEstimatedHours(list));
}
public EffortDuration calculateAverageWorkedHours(final List<OrderElement> list) {
EffortDuration sum = sumWorkedHours(list);
return (list.size() == 0) ? EffortDuration.zero() : EffortDuration.average(sum, list.size());
return list.isEmpty() ? EffortDuration.zero() : EffortDuration.average(sumWorkedHours(list), list.size());
}
private BigDecimal average(BigDecimal divisor, BigDecimal sum) {
@ -484,16 +481,12 @@ public class OrderElementDAO extends IntegrationEntityDAO<OrderElement> implemen
@Override
public boolean hasImputedExpenseSheet(Long id) throws InstanceNotFoundException {
OrderElement orderElement = find(id);
return (!expenseSheetLineDAO.findByOrderElement(orderElement).isEmpty());
return !expenseSheetLineDAO.findByOrderElement(find(id)).isEmpty();
}
@Override
public boolean hasImputedExpenseSheetThisOrAnyOfItsChildren(Long id) throws InstanceNotFoundException {
OrderElement orderElement = find(id);
return (!expenseSheetLineDAO.findByOrderElementAndChildren(orderElement).isEmpty());
return !expenseSheetLineDAO.findByOrderElementAndChildren(find(id)).isEmpty();
}
@SuppressWarnings("unchecked")
@ -517,11 +510,13 @@ public class OrderElementDAO extends IntegrationEntityDAO<OrderElement> implemen
if ( criteria != null && !criteria.isEmpty() ) {
strQuery += "JOIN oe.criterionRequirements cr ";
if ( where.isEmpty() ) {
where += "WHERE ";
} else {
where += "AND ";
}
where += "cr.criterion IN (:criteria) ";
where += "AND cr.class = DirectCriterionRequirement ";
where += "GROUP BY oe.id ";
@ -562,9 +557,7 @@ public class OrderElementDAO extends IntegrationEntityDAO<OrderElement> implemen
private boolean existsByCodeInAnotherOrder(OrderElement orderElement) {
try {
OrderElement found = findUniqueByCode(orderElement.getCode());
return !areInTheSameOrder(orderElement, found);
return !areInTheSameOrder(orderElement, findUniqueByCode(orderElement.getCode()));
} catch (InstanceNotFoundException e) {
return false;
}

View file

@ -29,9 +29,8 @@ import org.springframework.stereotype.Repository;
import java.util.List;
/**
* Created by
* @author Vova Perebykivskyi <vova@libreplan-enterprise.com>
* on 12.24.2015.
*
* @author Created by Vova Perebykivskyi <vova@libreplan-enterprise.com> on 12.24.2015.
*/
@Repository
@ -46,12 +45,14 @@ public class OrderFileDAO extends GenericDAOHibernate<OrderFile, Long> implement
public void delete(OrderFile file) {
try {
remove(file.getId());
} catch (InstanceNotFoundException ignored) {
}
} catch (InstanceNotFoundException ignored) {}
}
@Override
public List<OrderFile> findByParent(OrderElement parent) {
return getSession().createCriteria(OrderFile.class).add(Restrictions.eq("parent", parent)).list();
return getSession()
.createCriteria(OrderFile.class)
.add(Restrictions.eq("parent", parent))
.list();
}
}

View file

@ -51,8 +51,7 @@ import org.springframework.transaction.annotation.Transactional;
@Repository
@Scope(BeanDefinition.SCOPE_SINGLETON)
public class SumExpensesDAO extends GenericDAOHibernate<SumExpenses, Long> implements
ISumExpensesDAO {
public class SumExpensesDAO extends GenericDAOHibernate<SumExpenses, Long> implements ISumExpensesDAO {
@Autowired
private SessionFactory sessionFactory;
@ -69,8 +68,7 @@ public class SumExpensesDAO extends GenericDAOHibernate<SumExpenses, Long> imple
private Map<OrderElement, SumExpenses> mapSumExpenses;
@Override
public void updateRelatedSumExpensesWithExpenseSheetLineSet(
Set<ExpenseSheetLine> expenseSheetLineSet) {
public void updateRelatedSumExpensesWithExpenseSheetLineSet(Set<ExpenseSheetLine> expenseSheetLineSet) {
resetMapSumExpenses();
for (ExpenseSheetLine expenseSheetLine : expenseSheetLineSet) {

View file

@ -37,30 +37,32 @@ import org.libreplan.business.resources.entities.Criterion;
import org.libreplan.business.resources.entities.ResourceEnum;
/**
* A collection of HoursGroup with the same name required <br />
* A collection of HoursGroup with the same name required.
* <br />
*
* @author Óscar González Fernández <ogonzalez@igalia.com>
*/
public class AggregatedHoursGroup {
private static class GroupingCriteria {
private static Map<GroupingCriteria, List<HoursGroup>> byCriterions(
Collection<? extends HoursGroup> hours) {
Map<GroupingCriteria, List<HoursGroup>> result = new HashMap<GroupingCriteria, List<HoursGroup>>();
private static Map<GroupingCriteria, List<HoursGroup>> byCriterions(Collection<? extends HoursGroup> hours) {
Map<GroupingCriteria, List<HoursGroup>> result = new HashMap<>();
for (HoursGroup each : hours) {
GroupingCriteria key = asGroupingCriteria(each);
if (!result.containsKey(key)) {
result.put(key,
new ArrayList<HoursGroup>());
result.put(key, new ArrayList<>());
}
result.get(key).add(each);
}
return result;
}
private static GroupingCriteria asGroupingCriteria(HoursGroup hoursGroup) {
return new GroupingCriteria(hoursGroup.getResourceType(),
hoursGroup.getValidCriterions());
return new GroupingCriteria(hoursGroup.getResourceType(), hoursGroup.getValidCriterions());
}
private final ResourceEnum type;
@ -74,18 +76,16 @@ public class AggregatedHoursGroup {
@Override
public int hashCode() {
return new HashCodeBuilder().append(type).append(criterions)
.toHashCode();
return new HashCodeBuilder().append(type).append(criterions).toHashCode();
}
@Override
public boolean equals(Object obj) {
if (obj instanceof GroupingCriteria) {
GroupingCriteria other = (GroupingCriteria) obj;
return new EqualsBuilder().append(type, other.type).append(
criterions,
other.criterions).isEquals();
return new EqualsBuilder().append(type, other.type).append(criterions, other.criterions).isEquals();
}
return false;
}
}
@ -94,15 +94,12 @@ public class AggregatedHoursGroup {
return aggregate(Arrays.asList(hours));
}
public static List<AggregatedHoursGroup> aggregate(
Collection<? extends HoursGroup> hours) {
List<AggregatedHoursGroup> result = new ArrayList<AggregatedHoursGroup>();
for (Entry<GroupingCriteria, List<HoursGroup>> entry : GroupingCriteria
.byCriterions(hours)
.entrySet()) {
result.add(new AggregatedHoursGroup(entry.getKey(), entry
.getValue()));
public static List<AggregatedHoursGroup> aggregate(Collection<? extends HoursGroup> hours) {
List<AggregatedHoursGroup> result = new ArrayList<>();
for (Entry<GroupingCriteria, List<HoursGroup>> entry : GroupingCriteria.byCriterions(hours).entrySet()) {
result.add(new AggregatedHoursGroup(entry.getKey(), entry.getValue()));
}
return result;
}
@ -111,6 +108,7 @@ public class AggregatedHoursGroup {
for (AggregatedHoursGroup each : aggregated) {
result += each.getHours();
}
return result;
}
@ -121,10 +119,8 @@ public class AggregatedHoursGroup {
private ResourceEnum resourceType;
private AggregatedHoursGroup(GroupingCriteria groupingCriteria,
List<HoursGroup> hours) {
this.criterions = Collections
.unmodifiableSet(groupingCriteria.criterions);
private AggregatedHoursGroup(GroupingCriteria groupingCriteria, List<HoursGroup> hours) {
this.criterions = Collections.unmodifiableSet(groupingCriteria.criterions);
this.hoursGroup = Collections.unmodifiableList(hours);
this.resourceType = groupingCriteria.type;
}
@ -146,20 +142,23 @@ public class AggregatedHoursGroup {
for (HoursGroup each : hoursGroup) {
result += each.getWorkingHours();
}
return result;
}
public String getCriterionsJoinedByComma() {
List<String> criterionNames = asNames(criterions);
Collections.sort(criterionNames);
return StringUtils.join(criterionNames, ", ");
}
private List<String> asNames(Set<Criterion> criterions) {
List<String> result = new ArrayList<String>();
List<String> result = new ArrayList<>();
for (Criterion each : criterions) {
result.add(each.getName());
}
return result;
}

View file

@ -64,8 +64,24 @@ public class HoursGroup extends IntegrationEntity implements Cloneable, ICriteri
private HoursGroup origin;
protected CriterionRequirementOrderElementHandler criterionRequirementHandler =
CriterionRequirementOrderElementHandler.getInstance();
CriterionRequirementOrderElementHandler.getInstance();
/**
* Constructor for hibernate. Do not use!
*/
public HoursGroup() {}
private HoursGroup(OrderLine parentOrderLine) {
this.parentOrderLine = parentOrderLine;
String code = parentOrderLine.getCode();
this.setCode(code != null ? code : "");
this.setOrderLineTemplate(null);
}
private HoursGroup(OrderLineTemplate orderLineTemplate) {
this.orderLineTemplate = orderLineTemplate;
this.setParentOrderLine(null);
}
public static HoursGroup create(OrderLine parentOrderLine) {
HoursGroup result = new HoursGroup(parentOrderLine);
@ -91,17 +107,17 @@ public class HoursGroup extends IntegrationEntity implements Cloneable, ICriteri
}
/**
* Returns a copy of hoursGroup, and sets parent as its parent
* Returns a copy of hoursGroup, and sets parent as its parent.
*
* @param hoursGroup
* @param parent
* @return
* @return {@link HoursGroup}
*/
public static HoursGroup copyFrom(HoursGroup hoursGroup, OrderLineTemplate parent) {
HoursGroup result = copyFrom(hoursGroup);
result.setCriterionRequirements(copyDirectCriterionRequirements(
result, hoursGroup.getDirectCriterionRequirement()));
result.setCriterionRequirements(
copyDirectCriterionRequirements(result, hoursGroup.getDirectCriterionRequirement()));
result.setOrderLineTemplate(parent);
result.setParentOrderLine(null);
@ -128,8 +144,8 @@ public class HoursGroup extends IntegrationEntity implements Cloneable, ICriteri
public static HoursGroup copyFrom(HoursGroup hoursGroup, OrderLine parent) {
HoursGroup result = copyFrom(hoursGroup);
result.setCriterionRequirements(copyDirectCriterionRequirements(
result, hoursGroup.getDirectCriterionRequirement()));
result.setCriterionRequirements(
copyDirectCriterionRequirements(result, hoursGroup.getDirectCriterionRequirement()));
result.setOrderLineTemplate(null);
result.setParentOrderLine(parent);
@ -151,25 +167,6 @@ public class HoursGroup extends IntegrationEntity implements Cloneable, ICriteri
return result;
}
/**
* Constructor for hibernate. Do not use!
*/
public HoursGroup() {
}
private HoursGroup(OrderLine parentOrderLine) {
this.parentOrderLine = parentOrderLine;
String code = parentOrderLine.getCode();
this.setCode(code != null ? code : "");
this.setOrderLineTemplate(null);
}
private HoursGroup(OrderLineTemplate orderLineTemplate) {
this.orderLineTemplate = orderLineTemplate;
this.setParentOrderLine(null);
}
public ResourceEnum getResourceType() {
return resourceType;
}
@ -259,6 +256,7 @@ public class HoursGroup extends IntegrationEntity implements Cloneable, ICriteri
throw new IllegalStateException(
"Criterion cannot be assigned to this Hours Group. Criterion Resource Type is of a different type");
}
if ( existSameCriterionRequirement(requirement) ) {
throw new IllegalStateException(
"Criterion cannot be assigned to this Hours Group. Criterion already exist within Hours Group");
@ -327,14 +325,15 @@ public class HoursGroup extends IntegrationEntity implements Cloneable, ICriteri
}
private Set<CriterionRequirement> getCriterionRequirementsFromParent() {
return (parentOrderLine != null) ? parentOrderLine.getCriterionRequirements() :
orderLineTemplate.getCriterionRequirements();
return (parentOrderLine != null)
? parentOrderLine.getCriterionRequirements()
: orderLineTemplate.getCriterionRequirements();
}
public Set<IndirectCriterionRequirement> getIndirectCriterionRequirement() {
Set<IndirectCriterionRequirement> list = new HashSet<>();
for(CriterionRequirement criterionRequirement : criterionRequirements ){
if ( criterionRequirement instanceof IndirectCriterionRequirement ){
for (CriterionRequirement criterionRequirement : criterionRequirements ) {
if ( criterionRequirement instanceof IndirectCriterionRequirement ) {
list.add((IndirectCriterionRequirement) criterionRequirement);
}
}
@ -343,8 +342,8 @@ public class HoursGroup extends IntegrationEntity implements Cloneable, ICriteri
public Set<DirectCriterionRequirement> getDirectCriterionRequirement() {
Set<DirectCriterionRequirement> list = new HashSet<>();
for(CriterionRequirement criterionRequirement : criterionRequirements ){
if ( criterionRequirement instanceof DirectCriterionRequirement ){
for (CriterionRequirement criterionRequirement : criterionRequirements ) {
if ( criterionRequirement instanceof DirectCriterionRequirement ) {
list.add((DirectCriterionRequirement) criterionRequirement);
}
}
@ -359,6 +358,14 @@ public class HoursGroup extends IntegrationEntity implements Cloneable, ICriteri
(resourceTypeRequirement.equals(ResourceEnum.getDefault())));
}
/**
* Duplicate of {@link HoursGroup#isValidResourceType(CriterionRequirement)}.
* Needed because in my case I do not need to check equality with {@link ResourceEnum#getDefault()}.
*/
public boolean isValidResourceTypeChanged(CriterionRequirement newRequirement) {
return resourceType == null || resourceType.equals(newRequirement.getCriterion().getType().getResource());
}
boolean existSameCriterionRequirement(CriterionRequirement newRequirement) {
Criterion criterion = newRequirement.getCriterion();
for (CriterionRequirement requirement : getCriterionRequirements()){
@ -390,9 +397,11 @@ public class HoursGroup extends IntegrationEntity implements Cloneable, ICriteri
return Registry.getHoursGroupDAO();
}
/**
* The automatic checking of this constraint is avoided because it uses the wrong code property.
*/
@Override
public boolean isUniqueCodeConstraint() {
// The automatic checking of this constraint is avoided because it uses the wrong code property
return true;
}

View file

@ -75,24 +75,6 @@ import org.libreplan.business.util.deepcopy.DeepCopy;
*/
public class Order extends OrderLineGroup implements Comparable {
public static Order create() {
Order order = new Order();
order.setNewObject(true);
return order;
}
public static Order createUnvalidated(String code) {
Order order = create(new Order(), code);
return order;
}
/**
* Constructor for hibernate. Do not use!
*/
public Order() {
}
private String responsible;
private Boolean dependenciesConstraintsHavePriority;
@ -113,24 +95,24 @@ public class Order extends OrderLineGroup implements Comparable {
private String customerReference;
private Map<Scenario, OrderVersion> scenarios = new HashMap<Scenario, OrderVersion>();
private Map<Scenario, OrderVersion> scenarios = new HashMap<>();
private Set<OrderAuthorization> orderAuthorizations = new HashSet<OrderAuthorization>();
private Set<OrderAuthorization> orderAuthorizations = new HashSet<>();
private CurrentVersionInfo currentVersionInfo;
private Set<CustomerCommunication> customerCommunications = new HashSet<CustomerCommunication>();
private Set<CustomerCommunication> customerCommunications = new HashSet<>();
@Valid
private SortedSet<DeadlineCommunication> deliveringDates = new TreeSet<DeadlineCommunication>(
new DeliverDateComparator());
private SortedSet<DeadlineCommunication> deliveringDates = new TreeSet<>(new DeliverDateComparator());
@Valid
private SortedSet<EndDateCommunication> endDateCommunicationToCustomer = new TreeSet<EndDateCommunication>(
private SortedSet<EndDateCommunication> endDateCommunicationToCustomer = new TreeSet<>(
new EndDateCommunicationComparator());
public enum SchedulingMode {
FORWARD, BACKWARDS;
FORWARD,
BACKWARDS
}
private SchedulingMode schedulingMode = SchedulingMode.FORWARD;
@ -143,14 +125,31 @@ public class Order extends OrderLineGroup implements Comparable {
private Integer budgetMargin;
public Order() {
/**
* Constructor for hibernate. Do not use!
*/
}
public static Order create() {
Order order = new Order();
order.setNewObject(true);
return order;
}
public static Order createUnvalidated(String code) {
Order order = create(new Order(), code);
return order;
}
public static class CurrentVersionInfo {
private final OrderVersion orderVersion;
private final boolean modifyingTheOwnerScenario;
static CurrentVersionInfo create(Scenario scenario,
OrderVersion orderVersion) {
static CurrentVersionInfo create(Scenario scenario, OrderVersion orderVersion) {
return new CurrentVersionInfo(scenario, orderVersion);
}
@ -205,7 +204,7 @@ public class Order extends OrderLineGroup implements Comparable {
}
public void writeSchedulingDataChangesTo(Scenario currentScenario,
OrderVersion newOrderVersion) {
OrderVersion newOrderVersion) {
setVersionForScenario(currentScenario, newOrderVersion);
writeSchedulingDataChangesTo(
deepCopyWithNeededReplaces(newOrderVersion),
@ -403,7 +402,7 @@ public class Order extends OrderLineGroup implements Comparable {
@Override
protected boolean applyConstraintBasedOnInitOrEndDate(Task task,
boolean scheduleBackwards) {
boolean scheduleBackwards) {
// the initDate or the deadline of a order doesn't imply a start
// constraint at a task
return false;
@ -470,7 +469,7 @@ public class Order extends OrderLineGroup implements Comparable {
if ((hoursGroup.getCode() == null)
|| (hoursGroup.getCode().isEmpty())
|| (!hoursGroup.getCode().startsWith(
orderElement.getCode()))) {
orderElement.getCode()))) {
((OrderLine) orderElement)
.incrementLastHoursGroupSequenceCode();
String hoursGroupCode = EntitySequence.formatValue(
@ -493,7 +492,7 @@ public class Order extends OrderLineGroup implements Comparable {
result = prime
* result
+ ((getId() == null || isNewObject()) ? super.hashCode()
: getId().hashCode());
: getId().hashCode());
return result;
}
@ -520,7 +519,7 @@ public class Order extends OrderLineGroup implements Comparable {
}
public void setVersionForScenario(Scenario currentScenario,
OrderVersion orderVersion) {
OrderVersion orderVersion) {
scenarios.put(currentScenario, orderVersion);
}
@ -570,8 +569,7 @@ public class Order extends OrderLineGroup implements Comparable {
return null;
}
AdvanceType advanceType = PredefinedAdvancedTypes.SUBCONTRACTOR
.getType();
AdvanceType advanceType = PredefinedAdvancedTypes.SUBCONTRACTOR.getType();
return getAdvanceAssignmentByType(advanceType);
}
@ -696,7 +694,7 @@ public class Order extends OrderLineGroup implements Comparable {
@AssertTrue(message = "task code is repeated inside the project")
public boolean isUniqueCodeInsideOrderConstraint() {
List<String> codes = new ArrayList<String>();
List<String> codes = new ArrayList<>();
codes.add(getCode());
for (OrderElement child : getAllChildren()) {

View file

@ -29,9 +29,8 @@ import java.util.Date;
* This class is intended to work as a Hibernate component.
* It represents the LibrePlan File to be stored in customer`s HDD.
*
* Created by
* @author Vova Perebykivskiy <vova@libreplan-enterprise.com>
* on 25.12.2015.
*
* @author Created by Vova Perebykivskyi <vova@libreplan-enterprise.com> on 25.12.2015.
*/
public class OrderFile extends BaseEntity {

View file

@ -47,6 +47,19 @@ public class OrderLine extends OrderElement {
private HoursGroupOrderLineHandler hoursGroupOrderLineHandler = HoursGroupOrderLineHandler.getInstance();
private BigDecimal budget = BigDecimal.ZERO.setScale(2);
private Set<HoursGroup> hoursGroups = new HashSet<>();
private Integer lastHoursGroupSequenceCode = 0;
private boolean convertedToContainer = false;
/**
* Constructor for hibernate. Do not use!
*/
public OrderLine() {}
public static OrderLine create() {
OrderLine result = new OrderLine();
result.setNewObject(true);
@ -75,20 +88,6 @@ public class OrderLine extends OrderElement {
return result;
}
private BigDecimal budget = BigDecimal.ZERO.setScale(2);
/**
* Constructor for hibernate. Do not use!
*/
public OrderLine() {
}
private Set<HoursGroup> hoursGroups = new HashSet<>();
private Integer lastHoursGroupSequenceCode = 0;
private boolean convertedToContainer = false;
@Override
public Integer getWorkHours() {
return hoursGroupOrderLineHandler.calculateTotalHours(hoursGroups);
@ -352,7 +351,6 @@ public class OrderLine extends OrderElement {
@Override
public DirectAdvanceAssignment calculateFakeDirectAdvanceAssignment(
IndirectAdvanceAssignment indirectAdvanceAssignment) {
return null;
}

View file

@ -60,8 +60,8 @@ import org.libreplan.business.trees.ITreeParentNode;
/**
* Represents every container in the WBS view. A task of the WBS that has some children.<br />
*
* Represents every container in the WBS view. A task of the WBS that has some children.
* <br />
* The project itself is also an {@link OrderLineGroup}.
*
* @author Manuel Rego Casasnovas <rego@igalia.com>

View file

@ -33,15 +33,18 @@ import org.libreplan.business.util.deepcopy.DeepCopy;
/**
* @author Óscar González Fernández <ogonzalez@igalia.com>
*
*/
public class SchedulingDataForVersion extends BaseEntity {
public static class Data {
@NotNull
private SchedulingState.Type schedulingStateType;
private static Data from(SchedulingDataForVersion version, OrderVersion orderVersion) {
return new Data(orderVersion, version, version.getTaskSource(), version.getSchedulingStateType());
}
@NotNull
private OrderElement orderElement;
private TaskSource taskSource;
public static class Data {
private SchedulingDataForVersion originVersion;
@ -68,6 +71,10 @@ public class SchedulingDataForVersion extends BaseEntity {
this.initialSchedulingStateType = schedulingStateType;
}
private static Data from(SchedulingDataForVersion version, OrderVersion orderVersion) {
return new Data(orderVersion, version, version.getTaskSource(), version.getSchedulingStateType());
}
public TaskSource getTaskSource() {
return taskSource;
}
@ -134,12 +141,11 @@ public class SchedulingDataForVersion extends BaseEntity {
return hasPendingChanges;
}
public Data pointsTo(DeepCopy deepCopy, OrderVersion orderVersion,
SchedulingDataForVersion schedulingVersion) {
public Data pointsTo(DeepCopy deepCopy, OrderVersion orderVersion, SchedulingDataForVersion schedulingVersion) {
Validate.isTrue(!this.originVersion.equals(schedulingVersion));
Data data = new Data(orderVersion, schedulingVersion, copy(
deepCopy, taskSource), schedulingStateType);
Data data = new Data(orderVersion, schedulingVersion, copy(deepCopy, taskSource), schedulingStateType);
data.hasPendingChanges = true;
return data;
}
@ -161,14 +167,6 @@ public class SchedulingDataForVersion extends BaseEntity {
return orderElement.isLeaf() ? Type.SCHEDULING_POINT : Type.NO_SCHEDULED;
}
@NotNull
private SchedulingState.Type schedulingStateType;
@NotNull
private OrderElement orderElement;
private TaskSource taskSource;
public SchedulingState.Type getSchedulingStateType() {
return schedulingStateType;
}

View file

@ -45,9 +45,32 @@ import org.libreplan.business.util.deepcopy.Strategy;
*/
public class TaskSource extends BaseEntity {
@NotNull
private TaskElement task;
private SchedulingDataForVersion schedulingData;
@OnCopy(Strategy.SHARE_COLLECTION_ELEMENTS)
private Set<HoursGroup> hoursGroups = new HashSet<>();
public TaskSource() {}
public TaskSource(SchedulingDataForVersion schedulingState) {
Validate.notNull(schedulingState);
Validate.notNull(schedulingState.getOrderElement());
this.schedulingData = schedulingState;
OrderElement orderElement = schedulingState.getOrderElement();
Type orderElementType = orderElement.getSchedulingState().getType();
if (orderElementType == SchedulingState.Type.SCHEDULING_POINT) {
this.setHoursGroups(new HashSet<>(orderElement.getHoursGroups()));
}
}
public static TaskSource create(SchedulingDataForVersion schedulingState, List<HoursGroup> hoursGroups) {
TaskSource result = create(new TaskSource(schedulingState));
result.setHoursGroups(new HashSet<HoursGroup>(hoursGroups));
result.setHoursGroups(new HashSet<>(hoursGroups));
return result;
}
@ -59,6 +82,7 @@ public class TaskSource extends BaseEntity {
public Task createTaskWithoutDatesInitializedAndLinkItToTaskSource() {
TaskElement task = Task.createTaskWithoutDatesInitialized(this);
this.setTask(task);
return (Task) task;
}
@ -70,17 +94,18 @@ public class TaskSource extends BaseEntity {
public TaskGroup createTaskGroupWithoutDatesInitializedAndLinkItToTaskSource() {
TaskElement task = TaskGroup.create(this);
this.setTask(task);
return (TaskGroup) task;
}
public static TaskSourceSynchronization mustAdd(
TaskSource taskSource) {
public static TaskSourceSynchronization mustAdd(TaskSource taskSource) {
return new TaskSourceMustBeAdded(taskSource);
}
public static TaskSourceSynchronization mustAddGroup(TaskSource taskSource,
List<TaskSourceSynchronization> childrenOfGroup) {
List<TaskSourceSynchronization> childrenOfGroup) {
return new TaskGroupMustBeAdded(taskSource, childrenOfGroup);
}
@ -90,18 +115,16 @@ public class TaskSource extends BaseEntity {
public interface IOptionalPersistence {
public void save(TaskSource taskSource);
void save(TaskSource taskSource);
public void remove(TaskSource taskSource);
void remove(TaskSource taskSource);
}
public static IOptionalPersistence persistTaskSources(
ITaskSourceDAO taskSourceDAO) {
public static IOptionalPersistence persistTaskSources(ITaskSourceDAO taskSourceDAO) {
return new RealPersistence(taskSourceDAO, true);
}
public static IOptionalPersistence persistButDontRemoveTaskSources(
ITaskSourceDAO taskSourceDAO) {
public static IOptionalPersistence persistButDontRemoveTaskSources(ITaskSourceDAO taskSourceDAO) {
return new RealPersistence(taskSourceDAO, false);
}
@ -115,8 +138,7 @@ public class TaskSource extends BaseEntity {
private final boolean removeTaskSources;
public RealPersistence(ITaskSourceDAO taskSourceDAO,
boolean removeTaskSources) {
public RealPersistence(ITaskSourceDAO taskSourceDAO, boolean removeTaskSources) {
Validate.notNull(taskSourceDAO);
this.taskSourceDAO = taskSourceDAO;
this.removeTaskSources = removeTaskSources;
@ -132,34 +154,27 @@ public class TaskSource extends BaseEntity {
if (!removeTaskSources) {
return;
}
try {
taskSourceDAO.remove(taskSource.getId());
} catch (InstanceNotFoundException e) {
throw new RuntimeException(e);
}
// Flushing is required in order to avoid violation of
// unique
// constraint. If flush is not done and there is a task
// source
// that must be removed and another is created for the same
// order element the unique constraint
// "tasksource_orderelement_key" would be violated by
// hibernate
// Flushing is required in order to avoid violation of unique constraint.
// If flush is not done and there is a task source that must be removed and another is created for the same
// order element the unique constraint "tasksource_orderelement_key" would be violated by Hibernate.
taskSourceDAO.flush();
}
}
private static class NoPersistence implements IOptionalPersistence {
@Override
public void save(TaskSource taskSource) {}
@Override
public void save(TaskSource taskSource) {
}
@Override
public void remove(TaskSource taskSource) {
}
public void remove(TaskSource taskSource) {}
}
public static abstract class TaskSourceSynchronization {
@ -180,6 +195,7 @@ public class TaskSource extends BaseEntity {
Task result = Task.createTask(taskSource);
taskSource.setTask(result);
persistence.save(taskSource);
return result;
}
}
@ -197,6 +213,7 @@ public class TaskSource extends BaseEntity {
updateTaskWithOrderElement(taskSource.getTask(), taskSource.getOrderElement());
updatePositionRestrictions();
persistence.save(taskSource);
return taskSource.getTask();
}
@ -204,25 +221,22 @@ public class TaskSource extends BaseEntity {
if (hasSomeAllocationDone(taskSource.getTask())) {
return;
}
taskSource.getOrderElement().updatePositionConstraintOf(
(Task) taskSource.getTask());
taskSource.getOrderElement().updatePositionConstraintOf((Task) taskSource.getTask());
}
}
private static boolean hasSomeAllocationDone(TaskElement taskElement) {
return !taskElement.getAllResourceAllocations().isEmpty();
private static boolean hasSomeAllocationDone(TaskElement taskElement) {
return !taskElement.getAllResourceAllocations().isEmpty();
}
}
/**
* This method updates the task with a name and a start date. The start date
* and end date should never be null, unless it's legacy data
* This method updates the task with a name and a start date.
* The start date and end date should never be null, unless it's legacy data.
*
* @param task
* @param orderElement
*/
private static void updateTaskWithOrderElement(TaskElement task,
OrderElement orderElement) {
private static void updateTaskWithOrderElement(TaskElement task, OrderElement orderElement) {
task.setName(orderElement.getName());
Date orderInitDate = orderElement.getOrder().getInitDate();
if (task.getIntraDayStartDate() == null && orderInitDate != null) {
@ -232,15 +246,13 @@ public class TaskSource extends BaseEntity {
task.updateDeadlineFromOrderElement();
}
public static abstract class TaskGroupSynchronization extends
TaskSourceSynchronization {
public abstract static class TaskGroupSynchronization extends TaskSourceSynchronization {
protected final TaskSource taskSource;
private final List<TaskSourceSynchronization> synchronizations;
protected TaskGroupSynchronization(TaskSource taskSource,
List<TaskSourceSynchronization> synchronizations) {
protected TaskGroupSynchronization(TaskSource taskSource, List<TaskSourceSynchronization> synchronizations) {
Validate.notNull(taskSource);
Validate.notNull(synchronizations);
this.taskSource = taskSource;
@ -254,11 +266,12 @@ public class TaskSource extends BaseEntity {
@Override
public TaskElement apply(IOptionalPersistence persistence) {
List<TaskElement> children = getChildren(persistence);
return apply(children, persistence);
}
private List<TaskElement> getChildren(IOptionalPersistence persistence) {
List<TaskElement> result = new ArrayList<TaskElement>();
List<TaskElement> result = new ArrayList<>();
for (TaskSourceSynchronization each : synchronizations) {
TaskElement t = each.apply(persistence);
if (t != null) {
@ -266,49 +279,46 @@ public class TaskSource extends BaseEntity {
result.add(t);
}
}
return result;
}
protected abstract TaskElement apply(List<TaskElement> children,
IOptionalPersistence persistence);
protected abstract TaskElement apply(List<TaskElement> children, IOptionalPersistence persistence);
}
static class TaskGroupMustBeAdded extends TaskGroupSynchronization {
private TaskGroupMustBeAdded(TaskSource taskSource,
List<TaskSourceSynchronization> synchronizations) {
private TaskGroupMustBeAdded(TaskSource taskSource, List<TaskSourceSynchronization> synchronizations) {
super(taskSource, synchronizations);
}
@Override
protected TaskElement apply(List<TaskElement> children,
IOptionalPersistence persistence) {
protected TaskElement apply(List<TaskElement> children, IOptionalPersistence persistence) {
TaskGroup result = TaskGroup.create(taskSource);
for (TaskElement taskElement : children) {
result.addTaskElement(taskElement);
}
taskSource.setTask(result);
persistence.save(taskSource);
return result;
}
}
static class TaskSourceForTaskGroupModified extends
TaskGroupSynchronization {
static class TaskSourceForTaskGroupModified extends TaskGroupSynchronization {
TaskSourceForTaskGroupModified(TaskSource taskSource,
List<TaskSourceSynchronization> synchronizations) {
TaskSourceForTaskGroupModified(TaskSource taskSource, List<TaskSourceSynchronization> synchronizations) {
super(taskSource, synchronizations);
}
@Override
protected TaskElement apply(List<TaskElement> children,
IOptionalPersistence persistence) {
protected TaskElement apply(List<TaskElement> children, IOptionalPersistence persistence) {
TaskGroup taskGroup = (TaskGroup) taskSource.getTask();
taskGroup.setTaskChildrenTo(children);
updateTaskWithOrderElement(taskGroup, taskSource.getOrderElement());
persistence.save(taskSource);
return taskGroup;
}
}
@ -325,13 +335,13 @@ public class TaskSource extends BaseEntity {
public TaskElement apply(IOptionalPersistence optionalPersistence) {
taskSource.getTask().detach();
optionalPersistence.remove(taskSource);
return null;
}
}
public static TaskSource withHoursGroupOf(
SchedulingDataForVersion schedulingState) {
public static TaskSource withHoursGroupOf(SchedulingDataForVersion schedulingState) {
return create(new TaskSource(schedulingState));
}
@ -339,38 +349,12 @@ public class TaskSource extends BaseEntity {
return create(new TaskSource(schedulingState));
}
@NotNull
private TaskElement task;
private SchedulingDataForVersion schedulingData;
@OnCopy(Strategy.SHARE_COLLECTION_ELEMENTS)
private Set<HoursGroup> hoursGroups = new HashSet<HoursGroup>();
public TaskSource() {
}
public TaskSource(SchedulingDataForVersion schedulingState) {
Validate.notNull(schedulingState);
Validate.notNull(schedulingState.getOrderElement());
this.schedulingData = schedulingState;
OrderElement orderElement = schedulingState.getOrderElement();
Type orderElementType = orderElement
.getSchedulingState().getType();
if (orderElementType == SchedulingState.Type.SCHEDULING_POINT) {
this.setHoursGroups(new HashSet<HoursGroup>(orderElement
.getHoursGroups()));
}
}
public TaskSourceSynchronization withCurrentHoursGroup(
List<HoursGroup> hoursGroups) {
setHoursGroups(new HashSet<HoursGroup>(hoursGroups));
public TaskSourceSynchronization withCurrentHoursGroup(List<HoursGroup> hoursGroups) {
setHoursGroups(new HashSet<>(hoursGroups));
return new TaskSourceForTaskModified(this);
}
public TaskSourceSynchronization modifyGroup(
List<TaskSourceSynchronization> childrenOfGroup) {
public TaskSourceSynchronization modifyGroup(List<TaskSourceSynchronization> childrenOfGroup) {
return new TaskSourceForTaskGroupModified(this, childrenOfGroup);
}
@ -408,6 +392,7 @@ public class TaskSource extends BaseEntity {
for (HoursGroup each : hoursGroups) {
result += each.getWorkingHours();
}
return result;
}

View file

@ -45,13 +45,13 @@ import org.libreplan.business.workingday.EffortDuration.IEffortFrom;
import org.libreplan.business.workingday.IntraDayDate.PartialDay;
/**
* This class groups the calculation of the three values needed for the
* chart of the company global resource load. The purpose of the class is
* having these data pre-calculated to prevent heavy algorithms being
* This class groups the calculation of the three values needed for the chart of the company global resource load.
* The purpose of the class is having these data pre-calculated to prevent heavy algorithms being
* run each time the chart is shown.
* @see PredefinedDatabaseSnapshots
* @author Jacobo Aragunde Pérez<jaragunde@igalia.com>
*
* @see PredefinedDatabaseSnapshots
*
* @author Jacobo Aragunde Pérez<jaragunde@igalia.com>
*/
public class ResourceLoadChartData implements ILoadChartData {
@ -66,25 +66,24 @@ public class ResourceLoadChartData implements ILoadChartData {
}
public ResourceLoadChartData(List<DayAssignment> dayAssignments,
List<Resource> resources, LocalDate startInclusive,
LocalDate endExclusive) {
List<Resource> resources,
LocalDate startInclusive,
LocalDate endExclusive) {
ContiguousDaysLine<List<DayAssignment>> assignments = ContiguousDaysLine.byDay(dayAssignments);
ContiguousDaysLine<List<DayAssignment>> assignments = ContiguousDaysLine
.byDay(dayAssignments);
if (startInclusive != null && endExclusive != null) {
assignments = assignments.subInterval(startInclusive, endExclusive);
}
ContiguousDaysLine<EffortDuration> load = assignments
.transform(extractLoad());
ContiguousDaysLine<EffortDuration> overload = assignments
.transform(extractOverload());
ContiguousDaysLine<EffortDuration> load = assignments.transform(extractLoad());
ContiguousDaysLine<EffortDuration> availabilityOnAllResources = assignments
.transform(extractAvailabilityOnAllResources(resources));
ContiguousDaysLine<EffortDuration> overload = assignments.transform(extractOverload());
this.load = toSortedMap(ContiguousDaysLine.min(load,
availabilityOnAllResources));
ContiguousDaysLine<EffortDuration> availabilityOnAllResources =
assignments.transform(extractAvailabilityOnAllResources(resources));
this.load = toSortedMap(ContiguousDaysLine.min(load, availabilityOnAllResources));
this.overload = toSortedMap(sum(overload, availabilityOnAllResources));
this.availability = toSortedMap(availabilityOnAllResources);
}
@ -97,15 +96,11 @@ public class ResourceLoadChartData implements ILoadChartData {
return new IValueTransformer<List<DayAssignment>, Map<Resource, EffortDuration>>() {
@Override
public Map<Resource, EffortDuration> transform(LocalDate day,
List<DayAssignment> previousValue) {
Map<Resource, List<DayAssignment>> byResource = DayAssignment
.byResource(previousValue);
Map<Resource, EffortDuration> result = new HashMap<Resource, EffortDuration>();
for (Entry<Resource, List<DayAssignment>> each : byResource
.entrySet()) {
result.put(each.getKey(),
DayAssignment.sum(each.getValue()));
public Map<Resource, EffortDuration> transform(LocalDate day, List<DayAssignment> previousValue) {
Map<Resource, List<DayAssignment>> byResource = DayAssignment.byResource(previousValue);
Map<Resource, EffortDuration> result = new HashMap<>();
for (Entry<Resource, List<DayAssignment>> each : byResource.entrySet()) {
result.put(each.getKey(), DayAssignment.sum(each.getValue()));
}
return result;
}
@ -114,24 +109,20 @@ public class ResourceLoadChartData implements ILoadChartData {
public static IValueTransformer<Map<Resource, EffortDuration>, EffortDuration> calculateOverload() {
return new IValueTransformer<Map<Resource, EffortDuration>, EffortDuration>() {
@Override
public EffortDuration transform(LocalDate day,
Map<Resource, EffortDuration> previousValue) {
public EffortDuration transform(LocalDate day, Map<Resource, EffortDuration> previousValue) {
final PartialDay wholeDay = PartialDay.wholeDay(day);
return EffortDuration.sum(previousValue.entrySet(),
new IEffortFrom<Entry<Resource, EffortDuration>>() {
@Override
public EffortDuration from(
Entry<Resource, EffortDuration> each) {
EffortDuration capacity = calendarCapacityFor(
each.getKey(), wholeDay);
EffortDuration assigned = each.getValue();
return assigned.minus(min(capacity, assigned));
}
});
return EffortDuration.sum(previousValue.entrySet(), new IEffortFrom<Entry<Resource, EffortDuration>>() {
@Override
public EffortDuration from(Entry<Resource, EffortDuration> each) {
EffortDuration capacity = calendarCapacityFor(each.getKey(), wholeDay);
EffortDuration assigned = each.getValue();
return assigned.minus(min(capacity, assigned));
}
});
}
};
}
@ -140,8 +131,7 @@ public class ResourceLoadChartData implements ILoadChartData {
return new IValueTransformer<List<DayAssignment>, EffortDuration>() {
@Override
public EffortDuration transform(LocalDate day,
List<DayAssignment> previousValue) {
public EffortDuration transform(LocalDate day, List<DayAssignment> previousValue) {
return DayAssignment.sum(previousValue);
}
};
@ -151,14 +141,14 @@ public class ResourceLoadChartData implements ILoadChartData {
return new IValueTransformer<List<DayAssignment>, EffortDuration>() {
@Override
public EffortDuration transform(LocalDate day,
List<DayAssignment> previousValue) {
public EffortDuration transform(LocalDate day, List<DayAssignment> previousValue) {
Set<Resource> resources = getResources(previousValue);
return sumCalendarCapacitiesForDay(resources, day);
}
private Set<Resource> getResources(List<DayAssignment> assignments) {
Set<Resource> resources = new HashSet<Resource>();
Set<Resource> resources = new HashSet<>();
for (DayAssignment dayAssignment : assignments) {
resources.add(dayAssignment.getResource());
}
@ -169,11 +159,11 @@ public class ResourceLoadChartData implements ILoadChartData {
private IValueTransformer<List<DayAssignment>, EffortDuration> extractAvailabilityOnAllResources(
final List<Resource> resources) {
return new IValueTransformer<List<DayAssignment>, EffortDuration>() {
@Override
public EffortDuration transform(LocalDate day,
List<DayAssignment> previousValue) {
public EffortDuration transform(LocalDate day, List<DayAssignment> previousValue) {
return sumCalendarCapacitiesForDay(resources, day);
}
};
@ -191,13 +181,14 @@ public class ResourceLoadChartData implements ILoadChartData {
return availability;
}
public ILoadChartData on(final LocalDate startInclusive,
final LocalDate endExclusive) {
public ILoadChartData on(final LocalDate startInclusive, final LocalDate endExclusive) {
final ResourceLoadChartData original = ResourceLoadChartData.this;
if (startInclusive == null && endExclusive == null) {
return original;
}
return new ILoadChartData() {
@Override
@ -215,21 +206,21 @@ public class ResourceLoadChartData implements ILoadChartData {
return filter(original.getAvailability());
}
private SortedMap<LocalDate, EffortDuration> filter(
SortedMap<LocalDate, EffortDuration> map) {
private SortedMap<LocalDate, EffortDuration> filter(SortedMap<LocalDate, EffortDuration> map) {
if (startInclusive != null) {
return map.tailMap(startInclusive);
}
if (endExclusive != null) {
return map.headMap(endExclusive);
}
return map.subMap(startInclusive, endExclusive);
}
};
}
private static EffortDuration sumCalendarCapacitiesForDay(
Collection<? extends Resource> resources, LocalDate day) {
private static EffortDuration sumCalendarCapacitiesForDay(Collection<? extends Resource> resources, LocalDate day) {
final PartialDay wholeDay = PartialDay.wholeDay(day);
@ -241,8 +232,7 @@ public class ResourceLoadChartData implements ILoadChartData {
});
}
protected static EffortDuration calendarCapacityFor(Resource resource,
PartialDay day) {
protected static EffortDuration calendarCapacityFor(Resource resource, PartialDay day) {
return resource.getCalendarOrDefault().getCapacityOn(day);
}

View file

@ -30,7 +30,7 @@ import org.libreplan.business.planner.entities.TaskGroup;
/**
* @author Óscar González Fernández <ogonzalez@igalia.com>
* @author Vova Perebykivskiy <vova@libreplan-enterprise.com>
* @author Vova Perebykivskyi <vova@libreplan-enterprise.com>
*/
public interface ITaskElementDAO extends IGenericDAO<TaskElement, Long> {

View file

@ -25,7 +25,5 @@ import org.libreplan.business.orders.entities.TaskSource;
/**
* @author Óscar González Fernández <ogonzalez@igalia.com>
*
*/
public interface ITaskSourceDAO extends IGenericDAO<TaskSource, Long> {
}
public interface ITaskSourceDAO extends IGenericDAO<TaskSource, Long> {}

View file

@ -21,7 +21,6 @@ package org.libreplan.business.planner.daos;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.libreplan.business.common.daos.GenericDAOHibernate;
import org.libreplan.business.planner.entities.SubcontractorCommunication;
@ -31,12 +30,14 @@ import org.springframework.stereotype.Repository;
/**
* DAO for {@link SubcontractorCommunication}
*
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
*/
@Repository
@Scope(BeanDefinition.SCOPE_SINGLETON)
public class SubcontractorCommunicationDAO extends GenericDAOHibernate<SubcontractorCommunication, Long>
public class SubcontractorCommunicationDAO
extends GenericDAOHibernate<SubcontractorCommunication, Long>
implements ISubcontractorCommunicationDAO {
@Override
@ -46,8 +47,9 @@ public class SubcontractorCommunicationDAO extends GenericDAOHibernate<Subcontra
@Override
public List<SubcontractorCommunication> getAllNotReviewed(){
Criteria c = getSession().createCriteria(SubcontractorCommunication.class);
c.add(Restrictions.eq("reviewed", false));
return c.list();
return getSession()
.createCriteria(SubcontractorCommunication.class)
.add(Restrictions.eq("reviewed", false))
.list();
}
}

View file

@ -42,12 +42,11 @@ import org.springframework.transaction.annotation.Transactional;
/**
* @author Óscar González Fernández <ogonzalez@igalia.com>
* @author Jacobo Aragunde Pérez <jaragunde@igalia.com>
* @author Vova Perebykivskiy <vova@libreplan-enterprise.com>
* @author Vova Perebykivskyi <vova@libreplan-enterprise.com>
*/
@Repository
@Scope(BeanDefinition.SCOPE_SINGLETON)
public class TaskElementDAO extends GenericDAOHibernate<TaskElement, Long>
implements ITaskElementDAO {
public class TaskElementDAO extends GenericDAOHibernate<TaskElement, Long> implements ITaskElementDAO {
@SuppressWarnings("unchecked")
@Override
@ -102,7 +101,8 @@ public class TaskElementDAO extends GenericDAOHibernate<TaskElement, Long>
}
private void updateSumOfAllocatedHoursToParent(TaskGroup taskGroup,
EffortDuration oldAssignedEffort, EffortDuration newAssignedEffort) {
EffortDuration oldAssignedEffort,
EffortDuration newAssignedEffort) {
if (taskGroup != null) {
if (!Hibernate.isInitialized(taskGroup)) {
reattach(taskGroup);

View file

@ -28,11 +28,7 @@ import org.springframework.stereotype.Repository;
/**
* @author Óscar González Fernández <ogonzalez@igalia.com>
*
*/
@Repository
@Scope(BeanDefinition.SCOPE_SINGLETON)
public class TaskSourceDAO extends GenericDAOHibernate<TaskSource, Long>
implements ITaskSourceDAO {
}
public class TaskSourceDAO extends GenericDAOHibernate<TaskSource, Long> implements ITaskSourceDAO {}

View file

@ -28,31 +28,27 @@ import java.util.List;
import org.libreplan.business.common.BaseEntity;
/**
* Represents entity AssignmentFunction.
*
* @author Diego Pino García <dpino@igalia.com>
*
*/
public abstract class AssignmentFunction extends BaseEntity {
/**
* This method goes over the {@link ResourceAllocation} list and apply the
* assignment function if it is defined.
* This method goes over the {@link ResourceAllocation} list and apply the assignment function if it is defined.
*
* As this is called at the end of {@link Task#doAllocation} and a flat
* allocation was already applied before. If assignment function was set to
* manual it is reseted to flat again.
* As this is called at the end of {@link Task#doAllocation} and a flat allocation was already applied before.
* If assignment function was set to manual it is reseted to flat again.
*
* @param resourceAllocations
* List of {@link ResourceAllocation}
*/
public static void applyAssignmentFunctionsIfAny(
List<ResourceAllocation<?>> resourceAllocations) {
public static void applyAssignmentFunctionsIfAny(List<ResourceAllocation<?>> resourceAllocations) {
for (ResourceAllocation<?> resourceAllocation : resourceAllocations) {
AssignmentFunction assignmentFunction = resourceAllocation
.getAssignmentFunction();
AssignmentFunction assignmentFunction = resourceAllocation.getAssignmentFunction();
if (assignmentFunction != null) {
if (assignmentFunction.isManual()) {
// reset to flat
// Reset to flat
resourceAllocation.setAssignmentFunctionWithoutApply(null);
} else {
assignmentFunction.applyTo(resourceAllocation);
@ -64,6 +60,7 @@ public abstract class AssignmentFunction extends BaseEntity {
/**
* This method applies the function to the received resourceAllocation
* <i>This method is intended to be overridden by subclasses</i>
*
* @param resourceAllocation
*/
public abstract void applyTo(ResourceAllocation<?> resourceAllocation);
@ -81,10 +78,11 @@ public abstract class AssignmentFunction extends BaseEntity {
private String name;
private AssignmentFunctionName(String name) {
AssignmentFunctionName(String name) {
this.name = name;
}
@Override
public String toString() {
return name;
}

View file

@ -56,86 +56,82 @@ import org.libreplan.business.workingday.ResourcesPerDay;
/**
* Represents the relation between {@link Task} and a generic {@link Resource}.
*
* @author Diego Pino García <dpino@igalia.com>
*/
public class GenericResourceAllocation extends
ResourceAllocation<GenericDayAssignment> {
public class GenericResourceAllocation extends ResourceAllocation<GenericDayAssignment> {
@OnCopy(Strategy.SHARE_COLLECTION_ELEMENTS)
private Set<Criterion> criterions = new HashSet<>();
@OnCopy(Strategy.SHARE)
private ResourceEnum resourceType;
private Set<GenericDayAssignmentsContainer> genericDayAssignmentsContainers = new HashSet<>();
private IAssignedEffortForResource assignedEffortForResource = null;
/**
* Constructor for Hibernate. DO NOT USE!
*/
public GenericResourceAllocation() {}
public static GenericResourceAllocation create() {
return create(new GenericResourceAllocation());
}
public static GenericResourceAllocation createForTesting(
ResourcesPerDay resourcesPerDay, Task task) {
return create(new GenericResourceAllocation(
resourcesPerDay, task));
public static GenericResourceAllocation createForTesting(ResourcesPerDay resourcesPerDay, Task task) {
return create(new GenericResourceAllocation(resourcesPerDay, task));
}
public static Map<Set<Criterion>, List<GenericResourceAllocation>> byCriterions(
Collection<GenericResourceAllocation> genericAllocations) {
Map<Set<Criterion>, List<GenericResourceAllocation>> result = new HashMap<Set<Criterion>, List<GenericResourceAllocation>>();
Map<Set<Criterion>, List<GenericResourceAllocation>> result = new HashMap<>();
for (GenericResourceAllocation genericResourceAllocation : genericAllocations) {
Set<Criterion> criterions = genericResourceAllocation.getCriterions();
if( !result.containsKey(criterions) ){
result.put(criterions, new ArrayList<GenericResourceAllocation>());
if ( !result.containsKey(criterions) ) {
result.put(criterions, new ArrayList<>());
}
result.get(criterions).add(genericResourceAllocation);
}
return result;
}
@OnCopy(Strategy.SHARE_COLLECTION_ELEMENTS)
private Set<Criterion> criterions = new HashSet<Criterion>();
@OnCopy(Strategy.SHARE)
private ResourceEnum resourceType;
private Set<GenericDayAssignmentsContainer> genericDayAssignmentsContainers = new HashSet<GenericDayAssignmentsContainer>();
@Valid
@SuppressWarnings("unused")
private Set<GenericDayAssignmentsContainer> getGenericDayAssignmentsContainers() {
return new HashSet<GenericDayAssignmentsContainer>(
genericDayAssignmentsContainers);
return new HashSet<>(genericDayAssignmentsContainers);
}
private GenericResourceAllocation(ResourcesPerDay resourcesPerDay, Task task) {
super(resourcesPerDay, task);
}
/**
* Constructor for Hibernate. DO NOT USE!
*/
public GenericResourceAllocation() {
}
public static GenericResourceAllocation create(Task task) {
return create(new GenericResourceAllocation(
task));
return create(new GenericResourceAllocation(task));
}
public static GenericResourceAllocation create(Task task,
Collection<? extends Criterion> criterions) {
public static GenericResourceAllocation create(Task task, Collection<? extends Criterion> criterions) {
return create(task, inferType(criterions), criterions);
}
public static ResourceEnum inferType(
Collection<? extends Criterion> criterions) {
if (criterions.isEmpty()) {
return ResourceEnum.WORKER;
}
Criterion first = criterions.iterator().next();
return first.getType().getResource();
public static ResourceEnum inferType(Collection<? extends Criterion> criterions) {
return criterions.isEmpty()
? ResourceEnum.WORKER
: criterions.iterator().next().getType().getResource();
}
public static GenericResourceAllocation create(Task task, ResourceEnum resourceType,
Collection<? extends Criterion> criterions) {
public static GenericResourceAllocation create(
Task task, ResourceEnum resourceType, Collection<? extends Criterion> criterions) {
Validate.notNull(resourceType);
GenericResourceAllocation result = new GenericResourceAllocation(task);
result.criterions = new HashSet<Criterion>(criterions);
result.criterions = new HashSet<>(criterions);
result.resourceType = resourceType;
result.setResourcesPerDayToAmount(1);
return create(result);
}
@ -145,27 +141,25 @@ public class GenericResourceAllocation extends
}
@Override
protected GenericDayAssignmentsContainer retrieveOrCreateContainerFor(
Scenario scenario) {
protected GenericDayAssignmentsContainer retrieveOrCreateContainerFor(Scenario scenario) {
GenericDayAssignmentsContainer retrieved = retrieveContainerFor(scenario);
if (retrieved != null) {
return retrieved;
}
GenericDayAssignmentsContainer result = GenericDayAssignmentsContainer
.create(this, scenario);
GenericDayAssignmentsContainer result = GenericDayAssignmentsContainer.create(this, scenario);
genericDayAssignmentsContainers.add(result);
return result;
}
@Override
protected GenericDayAssignmentsContainer retrieveContainerFor(
Scenario scenario) {
Map<Scenario, GenericDayAssignmentsContainer> containers = containersByScenario();
return containers.get(scenario);
protected GenericDayAssignmentsContainer retrieveContainerFor(Scenario scenario) {
return containersByScenario().get(scenario);
}
private Map<Scenario, GenericDayAssignmentsContainer> containersByScenario() {
Map<Scenario, GenericDayAssignmentsContainer> result = new HashMap<Scenario, GenericDayAssignmentsContainer>();
Map<Scenario, GenericDayAssignmentsContainer> result = new HashMap<>();
for (GenericDayAssignmentsContainer each : genericDayAssignmentsContainers) {
assert !result.containsKey(each);
result.put(each.getScenario(), each);
@ -174,30 +168,25 @@ public class GenericResourceAllocation extends
}
public List<GenericDayAssignment> getOrderedAssignmentsFor(Resource resource) {
List<GenericDayAssignment> list = getOrderedAssignmentsFor().get(
resource);
if (list == null) {
return Collections.emptyList();
}
return Collections.unmodifiableList(list);
List<GenericDayAssignment> list = getOrderedAssignmentsFor().get(resource);
return list == null ? Collections.emptyList() : Collections.unmodifiableList(list);
}
private Map<Resource, List<GenericDayAssignment>> getOrderedAssignmentsFor() {
return DayAssignment.byResourceAndOrdered(getDayAssignmentsState()
.getUnorderedAssignments());
return DayAssignment.byResourceAndOrdered(getDayAssignmentsState().getUnorderedAssignments());
}
public Set<Criterion> getCriterions() {
return Collections.unmodifiableSet(criterions);
}
private final class ResourcesSatisfyingCriterionsSelector implements
IResourceSelector {
private final class ResourcesSatisfyingCriterionsSelector implements IResourceSelector {
@Override
public boolean isSelectable(Resource resource, LocalDate day) {
ICriterion compoundCriterion = CriterionCompounder.buildAnd(
criterions).getResult();
ICriterion compoundCriterion = CriterionCompounder.buildAnd(criterions).getResult();
return compoundCriterion.isSatisfiedBy(resource, day);
}
}
@ -205,22 +194,21 @@ public class GenericResourceAllocation extends
private class GenericAllocation extends AssignmentsAllocator {
private EffortDistributor hoursDistributor;
private final List<Resource> resources;
public GenericAllocation(List<Resource> resources) {
this.resources = resources;
hoursDistributor = new EffortDistributor(resources, getAssignedEffortForResource(),
new ResourcesSatisfyingCriterionsSelector());
hoursDistributor = new EffortDistributor(
resources, getAssignedEffortForResource(), new ResourcesSatisfyingCriterionsSelector());
}
@Override
public List<GenericDayAssignment> distributeForDay(PartialDay day,
EffortDuration effort) {
List<GenericDayAssignment> result = new ArrayList<GenericDayAssignment>();
for (ResourceWithAssignedDuration each : hoursDistributor
.distributeForDay(day, effort)) {
result.add(GenericDayAssignment.create(day.getDate(),
each.duration, each.resource));
public List<GenericDayAssignment> distributeForDay(PartialDay day, EffortDuration effort) {
List<GenericDayAssignment> result = new ArrayList<>();
for (ResourceWithAssignedDuration each : hoursDistributor.distributeForDay(day, effort)) {
result.add(GenericDayAssignment.create(day.getDate(), each.duration, each.resource));
}
return result;
}
@ -237,19 +225,14 @@ public class GenericResourceAllocation extends
}
private IAssignedEffortForResource assignedEffortForResource = null;
public void setAssignedEffortForResource(
IAssignedEffortForResource assignedEffortForResource) {
public void setAssignedEffortForResource(IAssignedEffortForResource assignedEffortForResource) {
this.assignedEffortForResource = assignedEffortForResource;
}
private IAssignedEffortForResource getAssignedEffortForResource() {
if (assignedEffortForResource != null) {
return assignedEffortForResource;
}
return AssignedEffortForResource.effortDiscounting(Collections
.singletonList(this));
return assignedEffortForResource != null
? assignedEffortForResource
: AssignedEffortForResource.effortDiscounting(Collections.singletonList(this));
}
@Override
@ -258,7 +241,7 @@ public class GenericResourceAllocation extends
}
public IAllocatable forResources(Collection<? extends Resource> resources) {
return new GenericAllocation(new ArrayList<Resource>(resources));
return new GenericAllocation(new ArrayList<>(resources));
}
@Override
@ -273,8 +256,7 @@ public class GenericResourceAllocation extends
@Override
public List<Resource> getAssociatedResources() {
return new ArrayList<Resource>(DayAssignment
.getAllResources(getAssignments()));
return new ArrayList<>(DayAssignment.getAllResources(getAssignments()));
}
@Override
@ -285,34 +267,32 @@ public class GenericResourceAllocation extends
@Override
ResourceAllocation<GenericDayAssignment> createCopy(Scenario scenario) {
GenericResourceAllocation allocation = create();
allocation.criterions = new HashSet<Criterion>(criterions);
allocation.criterions = new HashSet<>(criterions);
return allocation;
}
@Override
public ResourcesPerDayModification withDesiredResourcesPerDay(
ResourcesPerDay resourcesPerDay) {
return ResourcesPerDayModification.create(this, resourcesPerDay,
getAssociatedResources());
public ResourcesPerDayModification withDesiredResourcesPerDay(ResourcesPerDay resourcesPerDay) {
return ResourcesPerDayModification.create(this, resourcesPerDay, getAssociatedResources());
}
@Override
public List<Resource> querySuitableResources(
IResourcesSearcher resourcesSearcher) {
return resourcesSearcher.searchBoth().byCriteria(getCriterions())
.execute();
public List<Resource> querySuitableResources(IResourcesSearcher resourcesSearcher) {
return resourcesSearcher.searchBoth().byCriteria(getCriterions()).execute();
}
public static Map<Criterion, List<GenericResourceAllocation>> byCriterion(
List<GenericResourceAllocation> generics) {
Map<Criterion, List<GenericResourceAllocation>> result = new HashMap<Criterion, List<GenericResourceAllocation>>();
Map<Criterion, List<GenericResourceAllocation>> result = new HashMap<>();
for (GenericResourceAllocation genericResourceAllocation : generics) {
Set<Criterion> criterions = genericResourceAllocation
.getCriterions();
Set<Criterion> criterions = genericResourceAllocation.getCriterions();
for (Criterion criterion : criterions) {
if (!result.containsKey(criterion)) {
result.put(criterion,
new ArrayList<GenericResourceAllocation>());
result.put(criterion, new ArrayList<>());
}
result.get(criterion).add(genericResourceAllocation);
}
@ -347,20 +327,16 @@ public class GenericResourceAllocation extends
@Override
protected void removeContainersFor(Scenario scenario) {
GenericDayAssignmentsContainer container = containersByScenario().get(
scenario);
GenericDayAssignmentsContainer container = containersByScenario().get(scenario);
if (container != null) {
genericDayAssignmentsContainers.remove(container);
}
}
public void overrideConsolidatedDayAssignments(
GenericResourceAllocation origin) {
public void overrideConsolidatedDayAssignments(GenericResourceAllocation origin) {
if (origin != null) {
List<GenericDayAssignment> originAssignments = origin
.getConsolidatedAssignments();
resetAssignmentsTo(GenericDayAssignment
.copyToAssignmentsWithoutParent(originAssignments));
List<GenericDayAssignment> originAssignments = origin.getConsolidatedAssignments();
resetAssignmentsTo(GenericDayAssignment.copyToAssignmentsWithoutParent(originAssignments));
}
}
@ -369,13 +345,13 @@ public class GenericResourceAllocation extends
}
@Override
public EffortDuration getAssignedEffort(Criterion criterion,
IntraDayDate startInclusive, IntraDayDate endExclusive) {
public EffortDuration getAssignedEffort(
Criterion criterion, IntraDayDate startInclusive, IntraDayDate endExclusive) {
return super.getAssignedDuration(startInclusive, endExclusive);
}
public IEffortDistributor<GenericDayAssignment> createEffortDistributor(
List<Resource> resources) {
public IEffortDistributor<GenericDayAssignment> createEffortDistributor(List<Resource> resources) {
return new GenericAllocation(resources);
}

View file

@ -49,7 +49,7 @@ import org.springframework.stereotype.Component;
* Cost calulator in terms of hours.
*
* @author Manuel Rego Casasnovas <mrego@igalia.com>
* @author Vova Perebykivskiy <vova@libreplan-enterprise.com>
* @author Vova Perebykivskyi <vova@libreplan-enterprise.com>
*/
@Component
@Scope(BeanDefinition.SCOPE_SINGLETON)
@ -64,7 +64,7 @@ public class HoursCostCalculator implements ICostCalculator {
}
@Override
public SortedMap<LocalDate, BigDecimal> getAdvanceCost(Task task, LocalDate filterStartDate,
public SortedMap<LocalDate, BigDecimal> getAdvanceCost(Task task, LocalDate filterStartDate,
LocalDate filterEndDate) {
DirectAdvanceAssignment advanceAssignment =
(task.getOrderElement() != null) ? task.getOrderElement().getReportGlobalAdvanceAssignment() : null;
@ -153,7 +153,7 @@ public class HoursCostCalculator implements ICostCalculator {
assert date != null;
LocalTime time = new LocalTime(date.getTime());
// Time time = new Time(date.getTime());
// Time time = new Time(date.getTime());
BigDecimal hours = new BigDecimal(time.getHourOfDay());
additionOfAllAssignmentsMinutes += time.getMinuteOfHour();

View file

@ -22,7 +22,6 @@
package org.libreplan.business.planner.entities;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@ -58,21 +57,28 @@ import org.libreplan.business.workingday.ResourcesPerDay;
/**
* Represents the relation between {@link Task} and a specific {@link Worker}.
*
* @author Manuel Rego Casasnovas <mrego@igalia.com>
*/
public class SpecificResourceAllocation extends ResourceAllocation<SpecificDayAssignment> implements IAllocatable {
@OnCopy(Strategy.SHARE)
private Resource resource;
private Set<SpecificDayAssignmentsContainer> specificDayAssignmentsContainers = new HashSet<>();
public SpecificResourceAllocation() {}
public static SpecificResourceAllocation create(Task task) {
return create(new SpecificResourceAllocation(task));
}
/**
* Creates a {@link SpecificResourceAllocation} for a
* {@link LimitingResourceQueueElement}
* Creates a {@link SpecificResourceAllocation} for a {@link LimitingResourceQueueElement}.
*
* The process of creating a specific resource allocation for a queue
* element is different as it's necessary to assign a resource and a number
* of resources per day without allocating day assignments
* of resources per day without allocating day assignments.
*
* @param resource
* @param task
@ -83,26 +89,19 @@ public class SpecificResourceAllocation extends ResourceAllocation<SpecificDayAs
SpecificResourceAllocation result = create(new SpecificResourceAllocation(task));
result.setResource(resource);
result.setResourcesPerDayToAmount(1);
return result;
}
@OnCopy(Strategy.SHARE)
private Resource resource;
private Set<SpecificDayAssignmentsContainer> specificDayAssignmentsContainers = new HashSet<SpecificDayAssignmentsContainer>();
@Valid
public Set<SpecificDayAssignmentsContainer> getSpecificDayAssignmentsContainers() {
return new HashSet<SpecificDayAssignmentsContainer>(specificDayAssignmentsContainers);
return new HashSet<>(specificDayAssignmentsContainers);
}
public static SpecificResourceAllocation createForTesting(ResourcesPerDay resourcesPerDay, Task task) {
return create(new SpecificResourceAllocation(resourcesPerDay, task));
}
public SpecificResourceAllocation() {
}
@Override
protected SpecificDayAssignmentsContainer retrieveOrCreateContainerFor(Scenario scenario) {
SpecificDayAssignmentsContainer retrieved = retrieveContainerFor(scenario);
@ -111,13 +110,13 @@ public class SpecificResourceAllocation extends ResourceAllocation<SpecificDayAs
}
SpecificDayAssignmentsContainer result = SpecificDayAssignmentsContainer.create(this, scenario);
specificDayAssignmentsContainers.add(result);
return result;
}
@Override
protected SpecificDayAssignmentsContainer retrieveContainerFor(Scenario scenario) {
Map<Scenario, SpecificDayAssignmentsContainer> containers = containersByScenario();
return containers.get(scenario);
return containersByScenario().get(scenario);
}
private SpecificResourceAllocation(ResourcesPerDay resourcesPerDay, Task task) {
@ -134,7 +133,7 @@ public class SpecificResourceAllocation extends ResourceAllocation<SpecificDayAs
}
private Map<Scenario, SpecificDayAssignmentsContainer> containersByScenario() {
Map<Scenario, SpecificDayAssignmentsContainer> result = new HashMap<Scenario, SpecificDayAssignmentsContainer>();
Map<Scenario, SpecificDayAssignmentsContainer> result = new HashMap<>();
for (SpecificDayAssignmentsContainer each : specificDayAssignmentsContainers) {
assert !result.containsKey(each);
result.put(each.getScenario(), each);
@ -160,8 +159,7 @@ public class SpecificResourceAllocation extends ResourceAllocation<SpecificDayAs
@Override
public IAllocateResourcesPerDay resourcesPerDayFromEndUntil(IntraDayDate start) {
SpecificAssignmentsAllocator allocator = new SpecificAssignmentsAllocator();
return allocator.resourcesPerDayFromEndUntil(start);
return new SpecificAssignmentsAllocator().resourcesPerDayFromEndUntil(start);
}
@Override
@ -174,12 +172,11 @@ public class SpecificResourceAllocation extends ResourceAllocation<SpecificDayAs
return new SpecificAssignmentsAllocator().fromEndUntil(start);
}
private final class SpecificAssignmentsAllocator extends
AssignmentsAllocator {
private final class SpecificAssignmentsAllocator extends AssignmentsAllocator {
@Override
public List<SpecificDayAssignment> distributeForDay(PartialDay day, EffortDuration effort) {
return Arrays.asList(SpecificDayAssignment.create(day.getDate(), effort, resource));
return Collections.singletonList(SpecificDayAssignment.create(day.getDate(), effort, resource));
}
@Override
@ -189,8 +186,7 @@ public class SpecificResourceAllocation extends ResourceAllocation<SpecificDayAs
@Override
protected Capacity getCapacityAt(PartialDay day) {
return day.limitCapacity(getAllocationCalendar()
.getCapacityWithOvertime(day.getDate()));
return day.limitCapacity(getAllocationCalendar().getCapacityWithOvertime(day.getDate()));
}
}
@ -236,25 +232,24 @@ public class SpecificResourceAllocation extends ResourceAllocation<SpecificDayAs
@Override
public List<Resource> getAssociatedResources() {
return Arrays.asList(resource);
return Collections.singletonList(resource);
}
@Override
ResourceAllocation<SpecificDayAssignment> createCopy(Scenario scenario) {
SpecificResourceAllocation result = create(getTask());
result.resource = getResource();
return result;
}
@Override
public ResourcesPerDayModification withDesiredResourcesPerDay(
ResourcesPerDay resourcesPerDay) {
public ResourcesPerDayModification withDesiredResourcesPerDay(ResourcesPerDay resourcesPerDay) {
return ResourcesPerDayModification.create(this, resourcesPerDay);
}
@Override
public List<Resource> querySuitableResources(
IResourcesSearcher resourcesSearcher) {
public List<Resource> querySuitableResources(IResourcesSearcher resourcesSearcher) {
return Collections.singletonList(resource);
}
@ -290,8 +285,7 @@ public class SpecificResourceAllocation extends ResourceAllocation<SpecificDayAs
@Override
protected void removeContainersFor(Scenario scenario) {
SpecificDayAssignmentsContainer container = containersByScenario().get(
scenario);
SpecificDayAssignmentsContainer container = containersByScenario().get(scenario);
if (container != null) {
specificDayAssignmentsContainers.remove(container);
}
@ -299,8 +293,8 @@ public class SpecificResourceAllocation extends ResourceAllocation<SpecificDayAs
/**
* It does an allocation using the provided {@link EffortDuration} in the
* not consolidated part in interval from the first day not consolidated to
* the end provided. All previous not consolidated assignments are removed.
* not consolidated part in interval from the first day not consolidated to the end provided.
* All previous not consolidated assignments are removed.
*
* @param effortForNotConsolidatedPart
* @param endExclusive
@ -329,7 +323,7 @@ public class SpecificResourceAllocation extends ResourceAllocation<SpecificDayAs
private List<SpecificDayAssignment> assignmentsForEfforts(List<DayAssignment> assignments,
EffortDuration[] newEffortsPerDay) {
List<SpecificDayAssignment> result = new ArrayList<SpecificDayAssignment>();
List<SpecificDayAssignment> result = new ArrayList<>();
int i = 0;
for (DayAssignment each : assignments) {
EffortDuration durationForAssignment = newEffortsPerDay[i++];
@ -356,12 +350,13 @@ public class SpecificResourceAllocation extends ResourceAllocation<SpecificDayAs
}
@Override
public EffortDuration getAssignedEffort(Criterion criterion, final IntraDayDate startInclusive,
public EffortDuration getAssignedEffort(Criterion criterion,
final IntraDayDate startInclusive,
final IntraDayDate endExclusive) {
return EffortDuration.sum(getIntervalsRelatedWith(criterion, startInclusive.getDate(),
endExclusive.asExclusiveEnd()), new IEffortFrom<Interval>() {
return EffortDuration.sum(
getIntervalsRelatedWith(criterion, startInclusive.getDate(), endExclusive.asExclusiveEnd()),
new IEffortFrom<Interval>() {
@Override
public EffortDuration from(Interval each) {
FixedPoint intervalStart = (FixedPoint) each.getStart();
@ -374,12 +369,13 @@ public class SpecificResourceAllocation extends ResourceAllocation<SpecificDayAs
});
}
private List<Interval> getIntervalsRelatedWith(Criterion criterion, LocalDate startInclusive,
private List<Interval> getIntervalsRelatedWith(Criterion criterion,
LocalDate startInclusive,
LocalDate endExclusive) {
Interval queryInterval = AvailabilityTimeLine.Interval.create(startInclusive, endExclusive);
List<Interval> result = new ArrayList<Interval>();
List<Interval> result = new ArrayList<>();
for (Interval each : getIntervalsThisAllocationInterferesWith(criterion)) {
if ( queryInterval.overlaps(each) ) {
@ -390,17 +386,18 @@ public class SpecificResourceAllocation extends ResourceAllocation<SpecificDayAs
}
private List<Interval> getIntervalsThisAllocationInterferesWith(Criterion criterion) {
AvailabilityTimeLine availability =
AvailabilityCalculator.getCriterionsAvailabilityFor(Collections.singleton(criterion), resource);
availability.invalidUntil(getStartDate());
availability.invalidFrom(getEndDate());
return availability.getValidPeriods();
}
public boolean interferesWith(Criterion criterion, LocalDate startInclusive, LocalDate endExclusive) {
List<Interval> intervalsRelatedWith = getIntervalsRelatedWith(criterion, startInclusive, endExclusive);
return !intervalsRelatedWith.isEmpty();
return !getIntervalsRelatedWith(criterion, startInclusive, endExclusive).isEmpty();
}

View file

@ -397,11 +397,9 @@ public class StretchesFunction extends AssignmentFunction {
@Override
public String getName() {
if ( StretchesFunctionTypeEnum.INTERPOLATED.equals(type) ) {
return AssignmentFunctionName.INTERPOLATION.toString();
} else {
return AssignmentFunctionName.STRETCHES.toString();
}
return StretchesFunctionTypeEnum.INTERPOLATED.equals(type)
? AssignmentFunctionName.INTERPOLATION.toString()
: AssignmentFunctionName.STRETCHES.toString();
}
public List<Interval> getIntervalsDefinedByStreches() {
@ -415,9 +413,9 @@ public class StretchesFunction extends AssignmentFunction {
}
private List<Stretch> stretchesFor() {
boolean condition = (getDesiredType().equals(StretchesFunctionTypeEnum.INTERPOLATED));
return condition ? getStretchesPlusConsolidated() : getStretches();
return getDesiredType().equals(StretchesFunctionTypeEnum.INTERPOLATED)
? getStretchesPlusConsolidated()
: getStretches();
}
private void checkStretchesSumOneHundredPercent() {

View file

@ -45,6 +45,46 @@ import org.libreplan.business.util.deepcopy.Strategy;
*/
public class SubcontractedTaskData extends BaseEntity {
private Task task;
@OnCopy(Strategy.SHARE)
private ExternalCompany externalCompany;
private Date subcontratationDate;
private Date subcontractCommunicationDate;
private String workDescription;
private BigDecimal subcontractPrice;
private String subcontractedCode;
private Boolean nodeWithoutChildrenExported;
private Boolean labelsExported;
private Boolean materialAssignmentsExported;
private Boolean hoursGroupsExported;
private SubcontractState state = SubcontractState.PENDING_INITIAL_SEND;
private final SortedSet<SubcontractorDeliverDate> requiredDeliveringDates =
new TreeSet<>(new DeliverDateComparator());
private SortedSet<EndDateCommunication> endDatesCommunicatedFromSubcontractor =
new TreeSet<>(new EndDateCommunicationComparator());
/**
* Constructor for hibernate. Do not use!
*/
public SubcontractedTaskData() {}
private SubcontractedTaskData(Task task) {
this.task = task;
}
public static SubcontractedTaskData create(Task task) {
SubcontractedTaskData subcontractedTaskData = new SubcontractedTaskData(task);
subcontractedTaskData.subcontratationDate = new Date();
@ -78,44 +118,6 @@ public class SubcontractedTaskData extends BaseEntity {
return create(result);
}
private Task task;
@OnCopy(Strategy.SHARE)
private ExternalCompany externalCompany;
private Date subcontratationDate;
private Date subcontractCommunicationDate;
private String workDescription;
private BigDecimal subcontractPrice;
private String subcontractedCode;
private Boolean nodeWithoutChildrenExported;
private Boolean labelsExported;
private Boolean materialAssignmentsExported;
private Boolean hoursGroupsExported;
private SubcontractState state = SubcontractState.PENDING_INITIAL_SEND;
private final SortedSet<SubcontractorDeliverDate> requiredDeliveringDates =
new TreeSet<>(new DeliverDateComparator());
private SortedSet<EndDateCommunication> endDatesCommunicatedFromSubcontractor =
new TreeSet<>(new EndDateCommunicationComparator());
/**
* Constructor for hibernate. Do not use!
*/
public SubcontractedTaskData() {
}
private SubcontractedTaskData(Task task) {
this.task = task;
}
@NotNull(message = "task not specified")
public Task getTask() {
return task;
@ -163,11 +165,7 @@ public class SubcontractedTaskData extends BaseEntity {
}
public boolean isNodeWithoutChildrenExported() {
if ( nodeWithoutChildrenExported == null ) {
return false;
}
return nodeWithoutChildrenExported;
return nodeWithoutChildrenExported == null ? false : nodeWithoutChildrenExported;
}
public void setNodeWithoutChildrenExported(Boolean nodeWithoutChildrenExported) {
@ -178,11 +176,7 @@ public class SubcontractedTaskData extends BaseEntity {
}
public boolean isLabelsExported() {
if ( labelsExported == null ) {
return false;
}
return labelsExported;
return labelsExported == null ? false : labelsExported;
}
public void setLabelsExported(Boolean labelsExported) {
@ -193,11 +187,7 @@ public class SubcontractedTaskData extends BaseEntity {
}
public Boolean isMaterialAssignmentsExported() {
if ( materialAssignmentsExported == null ) {
return false;
}
return materialAssignmentsExported;
return materialAssignmentsExported == null ? false : materialAssignmentsExported;
}
public void setMaterialAssignmentsExported(Boolean materialAssignmentsExported) {
@ -208,11 +198,7 @@ public class SubcontractedTaskData extends BaseEntity {
}
public Boolean isHoursGroupsExported() {
if ( hoursGroupsExported == null ) {
return false;
}
return hoursGroupsExported;
return hoursGroupsExported == null ? false : hoursGroupsExported;
}
public void setHoursGroupsExported(Boolean hoursGroupsExported) {
@ -246,7 +232,6 @@ public class SubcontractedTaskData extends BaseEntity {
@AssertTrue(message = "external company should be subcontractor")
public boolean isExternalCompanyIsSubcontractorConstraint() {
return !firstLevelValidationsPassed() || externalCompany.isSubcontractor();
}
private boolean firstLevelValidationsPassed() {
@ -291,11 +276,9 @@ public class SubcontractedTaskData extends BaseEntity {
}
public Date getLastRequiredDeliverDate() {
if ( this.requiredDeliveringDates != null && !this.requiredDeliveringDates.isEmpty() ) {
return this.requiredDeliveringDates.first().getSubcontractorDeliverDate();
}
return null;
return this.requiredDeliveringDates != null && !this.requiredDeliveringDates.isEmpty()
? this.requiredDeliveringDates.first().getSubcontractorDeliverDate()
: null;
}
public void setEndDatesCommunicatedFromSubcontractor(
@ -309,10 +292,8 @@ public class SubcontractedTaskData extends BaseEntity {
}
public EndDateCommunication getLastEndDatesCommunicatedFromSubcontractor() {
if ( getEndDatesCommunicatedFromSubcontractor() != null ) {
return getEndDatesCommunicatedFromSubcontractor().first();
}
return null;
return getEndDatesCommunicatedFromSubcontractor() != null
? getEndDatesCommunicatedFromSubcontractor().first()
: null;
}
}

View file

@ -44,10 +44,10 @@ public class SubcontractorCommunication extends BaseEntity {
private List<SubcontractorCommunicationValue> subcontractorCommunicationValues = new ArrayList<>();
// Default constructor, needed by Hibernate
protected SubcontractorCommunication() {
}
/**
* Default constructor, needed by Hibernate.
*/
protected SubcontractorCommunication() {}
private SubcontractorCommunication(SubcontractedTaskData subcontractedTaskData,
CommunicationType communicationType,
@ -116,17 +116,14 @@ public class SubcontractorCommunication extends BaseEntity {
return subcontractorCommunicationValues;
}
public SubcontractorCommunicationValue getLastSubcontractorCommunicationValues(){
if ( subcontractorCommunicationValues.isEmpty() ){
return null;
}
return subcontractorCommunicationValues.get(subcontractorCommunicationValues.size()-1);
public SubcontractorCommunicationValue getLastSubcontractorCommunicationValues() {
return subcontractorCommunicationValues.isEmpty()
? null
: subcontractorCommunicationValues.get(subcontractorCommunicationValues.size() - 1);
}
public Date getLastSubcontractorCommunicationValueDate(){
SubcontractorCommunicationValue value = getLastSubcontractorCommunicationValues();
return (value == null) ? null : value.getDate();
}
}

View file

@ -32,34 +32,34 @@ import org.libreplan.business.INewObject;
*/
public class SubcontractorCommunicationValue implements INewObject {
public static SubcontractorCommunicationValue create() {
SubcontractorCommunicationValue subcontractorCommunicationValue = new SubcontractorCommunicationValue();
subcontractorCommunicationValue.setNewObject(true);
return subcontractorCommunicationValue;
}
private boolean newObject = false;
public static SubcontractorCommunicationValue create(Date date,
BigDecimal progress) {
SubcontractorCommunicationValue subcontractorCommunicationValue = new SubcontractorCommunicationValue(
date, progress);
subcontractorCommunicationValue.setNewObject(true);
return subcontractorCommunicationValue;
}
private Date date;
protected SubcontractorCommunicationValue() {
private BigDecimal progress;
}
protected SubcontractorCommunicationValue() {}
private SubcontractorCommunicationValue(Date date, BigDecimal progress) {
this.setDate(date);
this.setProgress(progress);
}
private boolean newObject = false;
public static SubcontractorCommunicationValue create() {
SubcontractorCommunicationValue subcontractorCommunicationValue = new SubcontractorCommunicationValue();
subcontractorCommunicationValue.setNewObject(true);
private Date date;
return subcontractorCommunicationValue;
}
private BigDecimal progress;
public static SubcontractorCommunicationValue create(Date date, BigDecimal progress) {
SubcontractorCommunicationValue subcontractorCommunicationValue =
new SubcontractorCommunicationValue(date, progress);
subcontractorCommunicationValue.setNewObject(true);
return subcontractorCommunicationValue;
}
public boolean isNewObject() {
return newObject;
@ -72,11 +72,9 @@ public class SubcontractorCommunicationValue implements INewObject {
@SuppressWarnings("unused")
@AssertTrue(message = "progress should be greater than 0% and less than 100%")
public boolean isQualityFormItemPercentageConstraint() {
if (getProgress() == null) {
return true;
}
return ((getProgress().compareTo(new BigDecimal(100).setScale(2)) <= 0) && (getProgress()
.compareTo(new BigDecimal(0).setScale(2)) > 0));
return getProgress() == null ||
(getProgress().compareTo(new BigDecimal(100).setScale(2)) <= 0 &&
(getProgress().compareTo(new BigDecimal(0).setScale(2)) > 0));
}
public void setDate(Date date) {
@ -97,8 +95,6 @@ public class SubcontractorCommunicationValue implements INewObject {
@Override
public String toString() {
String progress_reported = progress != null ? progress.toString()
+ "% - " : "";
return progress_reported + date;
return progress != null ? progress.toString() + "% - " + date : date.toString();
}
}

View file

@ -70,6 +70,46 @@ public abstract class TaskElement extends BaseEntity {
private static final Log LOG = LogFactory.getLog(TaskElement.class);
private static final IDatesInterceptor EMPTY_INTERCEPTOR = new IDatesInterceptor() {
@Override
public void setStartDate(IntraDayDate previousStart, IntraDayDate previousEnd, IntraDayDate newStart) {}
@Override
public void setNewEnd(IntraDayDate previousEnd, IntraDayDate newEnd) {}
};
@OnCopy(Strategy.SHARE)
private IDatesInterceptor datesInterceptor = EMPTY_INTERCEPTOR;
@OnCopy(Strategy.SHARE)
private BaseCalendar calendar;
private IntraDayDate startDate;
private IntraDayDate endDate;
private LocalDate deadline;
private String name;
private String notes;
private BigDecimal advancePercentage = BigDecimal.ZERO;
private Boolean simplifiedAssignedStatusCalculationEnabled = false;
private Boolean updatedFromTimesheets = false;
private EffortDuration sumOfAssignedEffort = EffortDuration.zero();
private TaskGroup parent;
private Set<Dependency> dependenciesWithThisOrigin = new HashSet<>();
private Set<Dependency> dependenciesWithThisDestination = new HashSet<>();
private TaskSource taskSource;
public static List<Task> justTasks(Collection<? extends TaskElement> tasks) {
List<Task> result = new ArrayList<>();
for (TaskElement taskElement : tasks) {
@ -82,27 +122,14 @@ public abstract class TaskElement extends BaseEntity {
}
public interface IDatesInterceptor {
void setStartDate(IntraDayDate previousStart,
IntraDayDate previousEnd, IntraDayDate newStart);
void setStartDate(IntraDayDate previousStart, IntraDayDate previousEnd, IntraDayDate newStart);
void setNewEnd(IntraDayDate previousEnd, IntraDayDate newEnd);
}
private static final IDatesInterceptor EMPTY_INTERCEPTOR = new IDatesInterceptor() {
@Override
public void setStartDate(IntraDayDate previousStart, IntraDayDate previousEnd, IntraDayDate newStart) {
}
@Override
public void setNewEnd(IntraDayDate previousEnd, IntraDayDate newEnd) {
}
};
public static Comparator<TaskElement> getByStartDateComparator() {
Comparator<TaskElement> result = new Comparator<TaskElement>() {
@Override
public int compare(TaskElement o1, TaskElement o2) {
return o1.getStartDate().compareTo(o2.getStartDate());
@ -114,13 +141,10 @@ public abstract class TaskElement extends BaseEntity {
public static Comparator<? super TaskElement> getByEndAndDeadlineDateComparator() {
return new Comparator<TaskElement>() {
@Override
public int compare(TaskElement o1, TaskElement o2) {
return o1.getBiggestAmongEndOrDeadline().compareTo(
o2.getBiggestAmongEndOrDeadline());
return o1.getBiggestAmongEndOrDeadline().compareTo(o2.getBiggestAmongEndOrDeadline());
}
};
}
@ -129,11 +153,9 @@ public abstract class TaskElement extends BaseEntity {
*/
@SuppressWarnings("unchecked")
public LocalDate getBiggestAmongEndOrDeadline() {
if ( this.getDeadline() != null ) {
return Collections.max(asList(this.getDeadline(), this.getEndAsLocalDate()));
}
return this.getEndAsLocalDate();
return this.getDeadline() != null
? Collections.max(asList(this.getDeadline(), this.getEndAsLocalDate()))
: this.getEndAsLocalDate();
}
protected static <T extends TaskElement> T create(T taskElement, TaskSource taskSource) {
@ -142,6 +164,7 @@ public abstract class TaskElement extends BaseEntity {
taskElement.setName(taskElement.getOrderElement().getName());
taskElement.updateAdvancePercentageFromOrderElement();
Order order = taskElement.getOrderElement().getOrder();
if ( order.isScheduleBackwards() ) {
taskElement.setEndDate(order.getDeadline());
} else {
@ -154,36 +177,6 @@ public abstract class TaskElement extends BaseEntity {
return create(taskElement);
}
@OnCopy(Strategy.SHARE)
private IDatesInterceptor datesInterceptor = EMPTY_INTERCEPTOR;
private IntraDayDate startDate;
private IntraDayDate endDate;
private LocalDate deadline;
private String name;
private String notes;
private TaskGroup parent;
private Set<Dependency> dependenciesWithThisOrigin = new HashSet<Dependency>();
private Set<Dependency> dependenciesWithThisDestination = new HashSet<Dependency>();
@OnCopy(Strategy.SHARE)
private BaseCalendar calendar;
private TaskSource taskSource;
private BigDecimal advancePercentage = BigDecimal.ZERO;
private Boolean simplifiedAssignedStatusCalculationEnabled = false;
private Boolean updatedFromTimesheets = false;
public void initializeDatesIfNeeded() {
if ( getIntraDayEndDate() == null || getIntraDayStartDate() == null ) {
initializeDates();
@ -203,11 +196,7 @@ public abstract class TaskElement extends BaseEntity {
}
public Integer getWorkHours() {
if ( taskSource == null ) {
return 0;
}
return taskSource.getTotalHours();
return taskSource == null ? 0 : taskSource.getTotalHours();
}
protected void copyPropertiesFrom(TaskElement task) {
@ -227,12 +216,11 @@ public abstract class TaskElement extends BaseEntity {
protected void copyDependenciesTo(TaskElement result) {
for (Dependency dependency : getDependenciesWithThisOrigin()) {
Dependency.create(result, dependency.getDestination(),
dependency.getType());
Dependency.create(result, dependency.getDestination(), dependency.getType());
}
for (Dependency dependency : getDependenciesWithThisDestination()) {
Dependency.create(dependency.getOrigin(), result,
dependency.getType());
Dependency.create(dependency.getOrigin(), result, dependency.getType());
}
}
@ -274,11 +262,7 @@ public abstract class TaskElement extends BaseEntity {
}
public OrderElement getOrderElement() {
if ( getTaskSource() == null ) {
return null;
}
return getTaskSource().getOrderElement();
return getTaskSource() == null ? null : getTaskSource().getOrderElement();
}
public Set<Dependency> getDependenciesWithThisOrigin() {
@ -290,7 +274,7 @@ public abstract class TaskElement extends BaseEntity {
}
public Set<Dependency> getDependenciesWithThisDestinationAndAllParents() {
Set<Dependency> result = new HashSet<Dependency>(getDependenciesWithThisDestination());
Set<Dependency> result = new HashSet<>(getDependenciesWithThisDestination());
if ( parent != null ) {
result.addAll(parent.getDependenciesWithThisDestinationAndAllParents());
}
@ -323,6 +307,7 @@ public abstract class TaskElement extends BaseEntity {
if ( startDate == null ) {
LOG.error(doNotProvideNullsDiscouragingMessage());
}
IntraDayDate previousStart = getIntraDayStartDate();
IntraDayDate previousEnd = getIntraDayEndDate();
this.startDate = startDate;
@ -335,24 +320,26 @@ public abstract class TaskElement extends BaseEntity {
}
public void setEndDate(Date endDate) {
setIntraDayEndDate( (endDate != null) ?
IntraDayDate.create(LocalDate.fromDateFields(endDate), EffortDuration.zero()) : null);
setIntraDayEndDate( (endDate != null)
? IntraDayDate.create(LocalDate.fromDateFields(endDate), EffortDuration.zero())
: null);
}
public void setIntraDayEndDate(IntraDayDate endDate) {
if ( endDate == null ) {
LOG.error(doNotProvideNullsDiscouragingMessage());
}
IntraDayDate previousEnd = getIntraDayEndDate();
this.endDate = endDate;
datesInterceptor.setNewEnd(previousEnd, this.endDate);
}
private String doNotProvideNullsDiscouragingMessage() {
return "The provided date shouldn't be null.\n"
+ "Providing null values to start or end dates is not safe.\n"
+ "In a near future an exception will be thrown if you provide a null value to a start or end date.\n"
+ "Please detect the caller and fix it";
return "The provided date shouldn't be null.\n" +
"Providing null values to start or end dates is not safe.\n" +
"In a near future an exception will be thrown if you provide a null value to a start or end date.\n" +
"Please detect the caller and fix it";
}
@NotNull
@ -360,8 +347,7 @@ public abstract class TaskElement extends BaseEntity {
return endDate;
}
public IDatesHandler getDatesHandler(Scenario scenario,
IResourcesSearcher resourcesSearcher) {
public IDatesHandler getDatesHandler(Scenario scenario, IResourcesSearcher resourcesSearcher) {
return noNullDates(createDatesHandler(scenario, resourcesSearcher));
}
@ -388,15 +374,13 @@ public abstract class TaskElement extends BaseEntity {
};
}
protected abstract IDatesHandler createDatesHandler(Scenario scenario,
IResourcesSearcher resourcesSearcher);
protected abstract IDatesHandler createDatesHandler(Scenario scenario, IResourcesSearcher resourcesSearcher);
public interface IDatesHandler {
/**
* Sets the startDate to newStartDate. It can update the endDate
* Sets the startDate to newStartDate. It can update the endDate.
*
* @param scenario
* @param newStartDate
*/
void moveTo(IntraDayDate newStartDate);
@ -420,8 +404,10 @@ public abstract class TaskElement extends BaseEntity {
public void setDeadline(LocalDate deadline) {
this.deadline = deadline;
if ( taskSource != null && taskSource.getOrderElement() != null ) {
taskSource.getOrderElement().setDeadline(
(deadline == null)? null : deadline.toDateTimeAtStartOfDay().toDate());
taskSource.getOrderElement().setDeadline((deadline == null)
? null
: deadline.toDateTimeAtStartOfDay().toDate());
}
}
@ -429,6 +415,7 @@ public abstract class TaskElement extends BaseEntity {
if ( this.equals(dependency.getOrigin()) ) {
dependenciesWithThisOrigin.add(dependency);
}
if ( this.equals(dependency.getDestination()) ) {
dependenciesWithThisDestination.add(dependency);
}
@ -445,7 +432,7 @@ public abstract class TaskElement extends BaseEntity {
}
public void removeDependencyWithDestination(TaskElement destination, Type type) {
ArrayList<Dependency> toBeRemoved = new ArrayList<Dependency>();
ArrayList<Dependency> toBeRemoved = new ArrayList<>();
for (Dependency dependency : dependenciesWithThisOrigin) {
if ( dependency.getDestination().equals(destination) && dependency.getType().equals(type) ) {
toBeRemoved.add(dependency);
@ -498,7 +485,8 @@ public abstract class TaskElement extends BaseEntity {
private List<Dependency> getDependenciesWithOrigin(TaskElement t) {
ArrayList<Dependency> result = new ArrayList<>();
for (Dependency dependency : dependenciesWithThisDestination) {
if ( dependency.getOrigin().equals(t) ) {result.add(dependency);
if ( dependency.getOrigin().equals(t) ) {
result.add(dependency);
}
}
@ -511,7 +499,7 @@ public abstract class TaskElement extends BaseEntity {
}
private void detachIncomingDependencies() {
Set<TaskElement> tasksToNotify = new HashSet<TaskElement>();
Set<TaskElement> tasksToNotify = new HashSet<>();
for (Dependency dependency : dependenciesWithThisDestination) {
TaskElement origin = dependency.getOrigin();
if ( origin != null ) {
@ -525,7 +513,7 @@ public abstract class TaskElement extends BaseEntity {
}
private void detachOutcomingDependencies() {
Set<TaskElement> tasksToNotify = new HashSet<TaskElement>();
Set<TaskElement> tasksToNotify = new HashSet<>();
for (Dependency dependency : dependenciesWithThisOrigin) {
TaskElement destination = dependency.getDestination();
if ( destination != null ) {
@ -549,6 +537,7 @@ public abstract class TaskElement extends BaseEntity {
public BaseCalendar getCalendar() {
if ( calendar == null ) {
OrderElement orderElement = getOrderElement();
return orderElement != null ? orderElement.getOrder().getCalendar() : null;
}
@ -590,8 +579,10 @@ public abstract class TaskElement extends BaseEntity {
return DayAssignment.filter(dayAssignments, filter);
}
/**
* Just Task could be subcontracted.
*/
public boolean isSubcontracted() {
// Just Task could be subcontracted
return false;
}
@ -599,8 +590,10 @@ public abstract class TaskElement extends BaseEntity {
return "";
}
/**
* Just Task could be subcontracted.
*/
public boolean isSubcontractedAndWasAlreadySent() {
// Just Task could be subcontracted
return false;
}
@ -612,8 +605,10 @@ public abstract class TaskElement extends BaseEntity {
return false;
}
/**
* Just Task could be consolidated.
*/
public boolean hasConsolidations() {
// Just Task could be consolidated
return false;
}
@ -637,20 +632,19 @@ public abstract class TaskElement extends BaseEntity {
}
public String getAssignedStatus() {
if(isSimplifiedAssignedStatusCalculationEnabled()) {
//simplified calculation has only two states:
//unassigned, when hours allocated is zero, and
//assigned otherwise
if ( getSumOfAssignedEffort().isZero() ) {
return "unassigned";
}
if (isSimplifiedAssignedStatusCalculationEnabled()) {
// Simplified calculation has only two states:
// 1. Unassigned, when hours allocated is zero.
// 2. Assigned otherwise.
return "assigned";
return getSumOfAssignedEffort().isZero() ? "unassigned" : "assigned";
}
Set<ResourceAllocation<?>> resourceAllocations = getSatisfiedResourceAllocations();
if ( resourceAllocations.isEmpty() ) {
return "unassigned";
}
for (ResourceAllocation<?> resourceAllocation : resourceAllocations) {
final ResourcesPerDay resourcesPerDay = resourceAllocation.getResourcesPerDay();
if ( resourcesPerDay != null && resourcesPerDay.isZero() ) {
@ -662,16 +656,11 @@ public abstract class TaskElement extends BaseEntity {
}
public Boolean belongsClosedProject() {
EnumSet<OrderStatusEnum> CLOSED = EnumSet.of(OrderStatusEnum.CANCELLED,
OrderStatusEnum.FINISHED,
OrderStatusEnum.STORED);
Order order = getOrderElement().getOrder();
if( CLOSED.contains(order.getState()) ) {
return true;
}
EnumSet<OrderStatusEnum> CLOSED =
EnumSet.of(OrderStatusEnum.CANCELLED, OrderStatusEnum.FINISHED, OrderStatusEnum.STORED);
return false;
return CLOSED.contains(getOrderElement().getOrder().getState());
}
public abstract boolean hasLimitedResourceAllocation();
@ -695,15 +684,12 @@ public abstract class TaskElement extends BaseEntity {
/**
* For common tasks it just return the spread progress.
*
* It's overridden in {@link TaskGroup} to return different progresses
* depending on parameter
* It's overridden in {@link TaskGroup} to return different progresses depending on parameter.
*/
public BigDecimal getAdvancePercentage(ProgressType progressType) {
if ( progressType != null && progressType.equals(ProgressType.SPREAD_PROGRESS) ) {
return advancePercentage;
}
return BigDecimal.ZERO;
return progressType != null && progressType.equals(ProgressType.SPREAD_PROGRESS)
? advancePercentage
: BigDecimal.ZERO;
}
public void setAdvancePercentage(BigDecimal advancePercentage) {
@ -711,15 +697,13 @@ public abstract class TaskElement extends BaseEntity {
this.resetStatus();
}
private EffortDuration sumOfAssignedEffort = EffortDuration.zero();
public void setSumOfAssignedEffort(EffortDuration sumOfAssignedEffort) {
this.sumOfAssignedEffort = sumOfAssignedEffort;
}
public EffortDuration getSumOfAssignedEffort() {
if ( this.getParent() == null ) {
//it's an order, we use the cached value
// It's an order, we use the cached value
return sumOfAssignedEffort;
}
else {
@ -729,7 +713,7 @@ public abstract class TaskElement extends BaseEntity {
private EffortDuration getSumOfAssignedEffortCalculated() {
EffortDuration result = EffortDuration.zero();
for(ResourceAllocation<?> allocation : getAllResourceAllocations()) {
for (ResourceAllocation<?> allocation : getAllResourceAllocations()) {
result = result.plus(allocation.getAssignedEffort());
}
return result;
@ -743,7 +727,7 @@ public abstract class TaskElement extends BaseEntity {
public List<TaskElement> getAllChildren() {
List<TaskElement> children = getChildren();
List<TaskElement> result = new ArrayList<TaskElement>();
List<TaskElement> result = new ArrayList<>();
for (TaskElement child : children) {
result.add(child);
result.addAll(child.getAllChildren());
@ -755,12 +739,15 @@ public abstract class TaskElement extends BaseEntity {
public abstract EffortDuration getTheoreticalCompletedTimeUntilDate(Date date);
public BigDecimal getTheoreticalAdvancePercentageUntilDate(Date date) {
EffortDuration totalAllocatedTime = AggregateOfDayAssignments.create(
this.getDayAssignments(FilterType.KEEP_ALL)).getTotalTime();
EffortDuration totalAllocatedTime =
AggregateOfDayAssignments.create(this.getDayAssignments(FilterType.KEEP_ALL)).getTotalTime();
EffortDuration totalTheoreticalCompletedTime = this.getTheoreticalCompletedTimeUntilDate(date);
if ( totalAllocatedTime.isZero() || totalTheoreticalCompletedTime.isZero() ) {
return BigDecimal.ZERO;
}
Validate.isTrue(totalTheoreticalCompletedTime.getSeconds() <= totalAllocatedTime.getSeconds());
return totalTheoreticalCompletedTime.dividedByAndResultAsBigDecimal(totalAllocatedTime);
@ -779,23 +766,19 @@ public abstract class TaskElement extends BaseEntity {
}
public Boolean isRoot() {
return (this.getParent() == null);
return this.getParent() == null;
}
public BigDecimal getBudget() {
if ( (taskSource != null) && (taskSource.getOrderElement() != null) ) {
return taskSource.getOrderElement().getBudget();
}
return null;
return (taskSource != null) && (taskSource.getOrderElement() != null)
? taskSource.getOrderElement().getBudget()
: null;
}
public BigDecimal getResourcesBudget() {
if ( (taskSource != null) && (taskSource.getOrderElement() != null) ) {
return taskSource.getOrderElement().getResourcesBudget();
}
return null;
return (taskSource != null) && (taskSource.getOrderElement() != null)
? taskSource.getOrderElement().getResourcesBudget()
: null;
}
public ExternalCompany getSubcontractedCompany() {
@ -806,10 +789,13 @@ public abstract class TaskElement extends BaseEntity {
public TaskDeadlineViolationStatusEnum getDeadlineViolationStatus() {
LocalDate deadline = this.getDeadline();
if ( deadline == null ) {
return TaskDeadlineViolationStatusEnum.NO_DEADLINE;
} else if ( this.getEndAsLocalDate().isAfter(deadline) ) {
return TaskDeadlineViolationStatusEnum.DEADLINE_VIOLATED;
} else {
return TaskDeadlineViolationStatusEnum.ON_SCHEDULE;
}

View file

@ -98,16 +98,16 @@ public class QualityFormDAO extends GenericDAOHibernate<QualityForm, Long> imple
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true)
public QualityForm findUniqueByName(QualityForm qualityForm) throws InstanceNotFoundException {
Validate.notNull(qualityForm);
return findUniqueByName(qualityForm.getName());
}
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true)
public QualityForm findUniqueByName(String name) throws InstanceNotFoundException, NonUniqueResultException {
Criteria c = getSession().createCriteria(QualityForm.class);
c.add(Restrictions.eq("name", name));
QualityForm qualityForm = (QualityForm) c.uniqueResult();
QualityForm qualityForm = (QualityForm) getSession()
.createCriteria(QualityForm.class)
.add(Restrictions.eq("name", name))
.uniqueResult();
if (qualityForm == null) {
throw new InstanceNotFoundException(null, "QualityForm");
@ -120,7 +120,6 @@ public class QualityFormDAO extends GenericDAOHibernate<QualityForm, Long> imple
public boolean existsOtherWorkReportTypeByName(QualityForm qualityForm) {
try {
QualityForm t = findUniqueByName(qualityForm);
return t != null && t != qualityForm;
} catch (InstanceNotFoundException e) {
return false;

View file

@ -36,14 +36,13 @@ import org.libreplan.business.orders.entities.OrderElement;
public class TaskQualityForm extends BaseEntity {
public static TaskQualityForm create(OrderElement orderElement,
QualityForm qualityForm) {
return create(new TaskQualityForm(orderElement, qualityForm));
}
private OrderElement orderElement;
protected TaskQualityForm() {
private QualityForm qualityForm;
}
private List<TaskQualityFormItem> taskQualityFormItems = new ArrayList<>();
private Boolean reportAdvance = false;
private TaskQualityForm(OrderElement orderElement, QualityForm qualityForm) {
this.orderElement = orderElement;
@ -51,21 +50,21 @@ public class TaskQualityForm extends BaseEntity {
createTaskQualityFormItems();
}
private OrderElement orderElement;
protected TaskQualityForm() {
private QualityForm qualityForm;
}
private List<TaskQualityFormItem> taskQualityFormItems = new ArrayList<TaskQualityFormItem>();
private Boolean reportAdvance = false;
public static TaskQualityForm create(OrderElement orderElement,
QualityForm qualityForm) {
return create(new TaskQualityForm(orderElement, qualityForm));
}
@Valid
public List<TaskQualityFormItem> getTaskQualityFormItems() {
return Collections.unmodifiableList(taskQualityFormItems);
}
public void setTaskQualityFormItems(
List<TaskQualityFormItem> taskQualityFormItems) {
public void setTaskQualityFormItems(List<TaskQualityFormItem> taskQualityFormItems) {
this.taskQualityFormItems = taskQualityFormItems;
}
@ -89,10 +88,8 @@ public class TaskQualityForm extends BaseEntity {
private void createTaskQualityFormItems() {
Validate.notNull(qualityForm);
for (QualityFormItem qualityFormItem : qualityForm
.getQualityFormItems()) {
TaskQualityFormItem taskQualityFormItem = TaskQualityFormItem
.create(qualityFormItem);
for (QualityFormItem qualityFormItem : qualityForm.getQualityFormItems()) {
TaskQualityFormItem taskQualityFormItem = TaskQualityFormItem.create(qualityFormItem);
taskQualityFormItems.add(taskQualityFormItem);
}
}
@ -107,6 +104,7 @@ public class TaskQualityForm extends BaseEntity {
}
}
}
return true;
}
@ -120,52 +118,48 @@ public class TaskQualityForm extends BaseEntity {
}
}
}
return true;
}
public boolean isCorrectConsecutivePassed(TaskQualityFormItem item) {
if (item.getPassed()) {
return (isPassedPreviousItem(item));
}
return true;
return !item.getPassed() || (isPassedPreviousItem(item));
}
public boolean isCorrectConsecutiveDate(TaskQualityFormItem item) {
if (item.getPassed()) {
return ((isPassedPreviousItem(item)) && (isLaterToPreviousItemDate(item)));
return (isPassedPreviousItem(item)) && (isLaterToPreviousItemDate(item));
}
return (item.getDate() == null);
return item.getDate() == null;
}
public boolean isPassedPreviousItem(TaskQualityFormItem item) {
Integer previousPosition = item.getPosition() - 1;
if ((previousPosition >= 0)
&& (previousPosition < taskQualityFormItems.size())) {
return taskQualityFormItems.get(previousPosition).getPassed();
}
return true;
}
public boolean isLaterToPreviousItemDate(TaskQualityFormItem item) {
Integer previousPosition = item.getPosition() - 1;
if ((previousPosition >= 0)
&& (previousPosition < taskQualityFormItems.size())) {
Date previousDate = taskQualityFormItems.get(previousPosition)
.getDate();
return ((previousDate != null) && (item.getDate() != null) && ((previousDate
.before(item.getDate())) || (previousDate.equals(item
.getDate()))));
if ((previousPosition >= 0) && (previousPosition < taskQualityFormItems.size())) {
Date previousDate = taskQualityFormItems.get(previousPosition).getDate();
return (previousDate != null) && (item.getDate() != null) &&
((previousDate.before(item.getDate())) || (previousDate.equals(item.getDate())));
}
return true;
}
public boolean isByItems() {
if ((this.qualityForm != null)
&& (this.qualityForm.getQualityFormType() != null)) {
return (this.qualityForm.getQualityFormType()
.equals(QualityFormType.BY_ITEMS));
}
return true;
return !((this.qualityForm != null) && (this.qualityForm.getQualityFormType() != null)) ||
(this.qualityForm.getQualityFormType().equals(QualityFormType.BY_ITEMS));
}
@NotNull(message = "report progress not specified")
@ -177,12 +171,11 @@ public class TaskQualityForm extends BaseEntity {
this.reportAdvance = BooleanUtils.toBoolean(reportAdvance);
}
public static TaskQualityForm copy(TaskQualityForm origin,
OrderElement orderElement) {
TaskQualityForm copy = TaskQualityForm.create(orderElement, origin
.getQualityForm());
public static TaskQualityForm copy(TaskQualityForm origin, OrderElement orderElement) {
TaskQualityForm copy = TaskQualityForm.create(orderElement, origin.getQualityForm());
copy.setTaskQualityFormItems(origin.getTaskQualityFormItems());
copy.setReportAdvance(origin.isReportAdvance());
return copy;
}

View file

@ -54,17 +54,16 @@ public class HoursWorkedPerResourceDTO implements Comparable {
private HoursWorkedPerResourceDTO self;
public HoursWorkedPerResourceDTO(Resource resource,
WorkReportLine workReportLine) {
public HoursWorkedPerResourceDTO(Resource resource, WorkReportLine workReportLine) {
this.workerName = resource.getName();
this.date = workReportLine.getDate();
LocalTime clockStart = workReportLine.getClockStart();
this.clockStart = (clockStart != null) ? clockStart.toString("HH:mm")
: "";
this.clockStart = (clockStart != null) ? clockStart.toString("HH:mm") : "";
LocalTime clockFinish = workReportLine.getClockFinish();
this.clockFinish = (clockFinish != null) ? clockFinish
.toString("HH:mm") : "";
this.clockFinish = (clockFinish != null) ? clockFinish.toString("HH:mm") : "";
this.effort = workReportLine.getEffort();
this.orderElementCode = workReportLine.getOrderElement().getCode();
this.orderElementName = workReportLine.getOrderElement().getName();
@ -168,8 +167,7 @@ public class HoursWorkedPerResourceDTO implements Comparable {
@Override
public int compareTo(Object o) {
return this.workerName
.compareTo(((HoursWorkedPerResourceDTO) o).workerName);
return this.workerName.compareTo(((HoursWorkedPerResourceDTO) o).workerName);
}
/**

View file

@ -27,8 +27,6 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.libreplan.business.common.daos.IEntitySequenceDAO;
import org.libreplan.business.common.entities.EntityNameEnum;
import org.libreplan.business.resources.daos.ICriterionDAO;
@ -36,6 +34,7 @@ import org.libreplan.business.resources.daos.ICriterionTypeDAO;
import org.libreplan.business.resources.entities.Criterion;
import org.libreplan.business.resources.entities.CriterionType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
@ -47,11 +46,9 @@ import org.springframework.transaction.annotation.Transactional;
* @author Diego Pino García <dpino@igalia.com>
*/
@Component
@Scope("singleton")
@Scope(BeanDefinition.SCOPE_SINGLETON)
public class CriterionsBootstrap implements ICriterionsBootstrap {
private static final Log LOG = LogFactory.getLog(CriterionsBootstrap.class);
@Autowired
private ICriterionDAO criterionDAO;
@ -73,8 +70,7 @@ public class CriterionsBootstrap implements ICriterionsBootstrap {
if (criterionTypeDAO.findAll().isEmpty()) {
Map<CriterionType, List<String>> typesWithCriterions = getTypesWithCriterions();
// Insert predefined criterions
for (Entry<CriterionType, List<String>> entry : typesWithCriterions
.entrySet()) {
for (Entry<CriterionType, List<String>> entry : typesWithCriterions.entrySet()) {
CriterionType criterionType = retrieveOrCreate(entry.getKey());
// Create predefined criterions for criterionType
for (String criterionName : entry.getValue()) {
@ -84,10 +80,9 @@ public class CriterionsBootstrap implements ICriterionsBootstrap {
}
}
private void ensureCriterionExists(String criterionName,
CriterionType criterionType) {
Criterion criterion = Criterion.createPredefined(criterionName,
criterionType);
private void ensureCriterionExists(String criterionName, CriterionType criterionType) {
Criterion criterion = Criterion.createPredefined(criterionName, criterionType);
if (!criterionDAO.existsPredefinedCriterion(criterion)) {
int numberOfDigits = getNumberOfDigitsCode();
criterionType.setGenerateCode(criterion, numberOfDigits);
@ -104,26 +99,26 @@ public class CriterionsBootstrap implements ICriterionsBootstrap {
criterionTypeDAO.save(criterionType);
return criterionType;
}
return criterionTypeDAO.findPredefined(criterionType);
}
private Map<CriterionType, List<String>> getTypesWithCriterions() {
HashMap<CriterionType, List<String>> result = new HashMap<CriterionType, List<String>>();
HashMap<CriterionType, List<String>> result = new HashMap<>();
for (ICriterionTypeProvider provider : providers) {
for (Entry<CriterionType, List<String>> entry : provider
.getRequiredCriterions().entrySet()) {
for (Entry<CriterionType, List<String>> entry : provider.getRequiredCriterions().entrySet()) {
if (!result.containsKey(entry.getKey())) {
result.put(entry.getKey(), new ArrayList<String>());
}
result.get(entry.getKey()).addAll(entry.getValue());
}
}
return result;
}
protected Integer getNumberOfDigitsCode() {
return entitySequenceDAO
.getNumberOfDigitsCode(EntityNameEnum.CRITERION);
return entitySequenceDAO.getNumberOfDigitsCode(EntityNameEnum.CRITERION);
}
}

View file

@ -27,6 +27,7 @@ import java.util.Map;
import org.libreplan.business.resources.entities.CriterionType;
import org.libreplan.business.resources.entities.PredefinedCriterionTypes;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
@ -37,7 +38,7 @@ import org.springframework.stereotype.Component;
* @author Diego Pino García <dpino@igalia.com>
*/
@Component
@Scope("singleton")
@Scope(BeanDefinition.SCOPE_SINGLETON)
public class PredefinedCriterionTypesProvider implements ICriterionTypeProvider {
public PredefinedCriterionTypesProvider() {
@ -45,10 +46,12 @@ public class PredefinedCriterionTypesProvider implements ICriterionTypeProvider
@Override
public Map<CriterionType, List<String>> getRequiredCriterions() {
Map<CriterionType, List<String>> result = new HashMap<CriterionType, List<String>>();
Map<CriterionType, List<String>> result = new HashMap<>();
for (PredefinedCriterionTypes type : PredefinedCriterionTypes.values()) {
result.put(CriterionType.fromPredefined(type), type.getPredefined());
}
return result;
}
}

View file

@ -23,9 +23,9 @@ import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.joda.time.LocalDate;
import org.libreplan.business.common.IAdHocTransactionService;
import org.libreplan.business.planner.daos.IDayAssignmentDAO;
import org.libreplan.business.planner.entities.DayAssignment;
import org.libreplan.business.resources.entities.Resource;
@ -43,13 +43,11 @@ import org.springframework.transaction.annotation.Transactional;
* {@link IResourceLoadRatiosCalculator} interface.
*
* @author Javier Moran Rua <jmoran@igalia.com>
*
*/
@Service
@Scope(BeanDefinition.SCOPE_SINGLETON)
public class ResourceLoadRatiosCalculator implements
IResourceLoadRatiosCalculator {
public class ResourceLoadRatiosCalculator implements IResourceLoadRatiosCalculator {
@Autowired
private IDayAssignmentDAO dayAssigmentDAO;
@ -57,17 +55,14 @@ public class ResourceLoadRatiosCalculator implements
@Autowired
private IResourceDAO resourceDAO;
@Autowired
private IAdHocTransactionService adHocTransactionService;
private static class LoadRatiosDataType implements
IResourceLoadRatiosCalculator.ILoadRatiosDataType {
private static class LoadRatiosDataType implements IResourceLoadRatiosCalculator.ILoadRatiosDataType {
private EffortDuration load;
private EffortDuration overload;
private EffortDuration capacity;
public LoadRatiosDataType(EffortDuration load, EffortDuration overload,
EffortDuration capacity) {
public LoadRatiosDataType(EffortDuration load, EffortDuration overload, EffortDuration capacity) {
this.load = load;
this.overload = overload;
this.capacity = capacity;
@ -94,8 +89,7 @@ public class ResourceLoadRatiosCalculator implements
if (this.load.isZero() && this.overload.isZero()) {
result = BigDecimal.ZERO;
} else {
result = this.overload.dividedByAndResultAsBigDecimal(this.load
.plus(this.capacity));
result = this.overload.dividedByAndResultAsBigDecimal(this.load.plus(this.capacity));
}
return result.setScale(2, BigDecimal.ROUND_HALF_UP);
@ -104,12 +98,13 @@ public class ResourceLoadRatiosCalculator implements
@Override
public BigDecimal getAvailiabilityRatio() {
BigDecimal result;
if (this.capacity.isZero()) {
result = BigDecimal.ZERO;
} else {
result = BigDecimal.ONE.subtract(this.load
.dividedByAndResultAsBigDecimal(this.capacity));
result = BigDecimal.ONE.subtract(this.load.dividedByAndResultAsBigDecimal(this.capacity));
if (result.compareTo(BigDecimal.ZERO) < 0) {
result = BigDecimal.ZERO;
}
@ -121,35 +116,39 @@ public class ResourceLoadRatiosCalculator implements
@Override
@Transactional(readOnly = true)
public ILoadRatiosDataType calculateLoadRatios(final Resource resource,
final LocalDate startDate, final LocalDate endDate,
final Scenario scenario) {
final LocalDate startDate,
final LocalDate endDate,
final Scenario scenario) {
resourceDAO.reattach(resource);
EffortDuration totalLoad = EffortDuration.zero(), totalOverload = EffortDuration
.zero(), totalCapacity = EffortDuration.zero();
EffortDuration
totalLoad = EffortDuration.zero(),
totalOverload = EffortDuration.zero(),
totalCapacity;
for (Map.Entry<LocalDate, EffortDuration> each : getAllEffortPerDateFor(
scenario, startDate, endDate, resource).entrySet()) {
Set<Map.Entry<LocalDate, EffortDuration>> efforts =
getAllEffortPerDateFor(scenario, startDate, endDate, resource).entrySet();
for (Map.Entry<LocalDate, EffortDuration> each : efforts) {
totalLoad = totalLoad.plus(each.getValue());
totalOverload = addOverload(totalOverload, resource,
each.getValue(), each.getKey());
totalOverload = addOverload(totalOverload, resource, each.getValue(), each.getKey());
}
totalCapacity = calculateTotalCapacity(resource, startDate, endDate);
return new LoadRatiosDataType(totalLoad, totalOverload, totalCapacity);
}
private Map<LocalDate, EffortDuration> getAllEffortPerDateFor(
Scenario scenario, LocalDate startDate, LocalDate endDate,
Resource resource) {
Scenario scenario, LocalDate startDate, LocalDate endDate, Resource resource) {
HashMap<LocalDate, EffortDuration> result = new HashMap<LocalDate, EffortDuration>();
HashMap<LocalDate, EffortDuration> result;
result = new HashMap<>();
List<DayAssignment> l = dayAssigmentDAO.getAllFor(scenario, startDate,
endDate, resource);
List<DayAssignment> l = dayAssigmentDAO.getAllFor(scenario, startDate, endDate, resource);
EffortDuration newValue;
EffortDuration newValue = EffortDuration.zero();
for (DayAssignment each : l) {
if (result.containsKey(each.getDay())) {
newValue = result.get(each.getDay()).plus(each.getDuration());
@ -161,15 +160,16 @@ public class ResourceLoadRatiosCalculator implements
return result;
}
private EffortDuration calculateTotalCapacity(Resource resource,
LocalDate startDate, LocalDate endDate) {
private EffortDuration calculateTotalCapacity(Resource resource, LocalDate startDate, LocalDate endDate) {
return resource.getCalendar().getWorkableDuration(startDate, endDate);
}
private EffortDuration addOverload(EffortDuration currentOverload,
Resource resource, EffortDuration loadAtDate, LocalDate date) {
private EffortDuration addOverload(
EffortDuration currentOverload, Resource resource, EffortDuration loadAtDate, LocalDate date) {
EffortDuration result;
EffortDuration capacityAtDay = getCapacityAtDate(resource, date);
if (capacityAtDay.compareTo(loadAtDate) < 0) {
result = currentOverload.plus(loadAtDate.minus(capacityAtDay));
} else {

View file

@ -70,6 +70,7 @@ public class ResourcesSearcher implements IResourcesSearcher {
@Autowired
private SessionFactory sessionFactory;
@Override
public IResourcesQuery<Machine> searchMachines() {
return new Query<>(Machine.class);
}
@ -104,7 +105,6 @@ public class ResourcesSearcher implements IResourcesSearcher {
public IResourcesQuery<T> byCriteria(Collection<? extends Criterion> criteria) {
Validate.noNullElements(criteria);
this.criteria = new ArrayList<>(criteria);
return this;
}
@ -205,13 +205,13 @@ public class ResourcesSearcher implements IResourcesSearcher {
public IResourcesQuery<Resource> searchBoth() {
final IResourcesQuery<Worker> searchWorkers = searchWorkers();
final IResourcesQuery<Machine> searchMachines = searchMachines();
return new IResourcesQuery<Resource>() {
@Override
public IResourcesQuery<Resource> byName(String name) {
searchWorkers.byName(name);
searchMachines.byName(name);
return this;
}
@ -219,7 +219,6 @@ public class ResourcesSearcher implements IResourcesSearcher {
public IResourcesQuery<Resource> byCriteria(Collection<? extends Criterion> criteria) {
searchWorkers.byCriteria(criteria);
searchMachines.byCriteria(criteria);
return this;
}
@ -227,7 +226,6 @@ public class ResourcesSearcher implements IResourcesSearcher {
public IResourcesQuery<Resource> byResourceType(ResourceType type) {
searchWorkers.byResourceType(type);
searchMachines.byResourceType(type);
return this;
}

View file

@ -31,7 +31,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.commons.collections.ComparatorUtils;
import org.apache.commons.collections4.ComparatorUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.builder.EqualsBuilder;
@ -48,7 +48,8 @@ import org.libreplan.business.requirements.entities.CriterionRequirement;
import org.libreplan.business.resources.daos.ICriterionDAO;
/**
* A criterion stored in the database <br />
* A criterion stored in the database.
* <br />
* @author Óscar González Fernández <ogonzalez@igalia.com>
* @author Fernando Bellas Permuy <fbellas@udc.es>
*/
@ -165,8 +166,7 @@ public class Criterion extends IntegrationEntity implements ICriterion,
return getCaptionFor(ResourceEnum.WORKER, criteria);
}
public static String getCaptionFor(
GenericResourceAllocation allocation) {
public static String getCaptionFor(GenericResourceAllocation allocation) {
return getCaptionFor(allocation.getResourceType(),
allocation.getCriterions());
}
@ -178,7 +178,7 @@ public class Criterion extends IntegrationEntity implements ICriterion,
* @return
*/
public static String getCaptionFor(ResourceEnum resourceType,
Collection<? extends Criterion> criteria) {
Collection<? extends Criterion> criteria) {
if (criteria.isEmpty()) {
return allCaptionFor(resourceType);
}
@ -191,12 +191,12 @@ public class Criterion extends IntegrationEntity implements ICriterion,
private static String allCaptionFor(ResourceEnum resourceType) {
switch (resourceType) {
case WORKER:
return allWorkersCaption();
case MACHINE:
return allMachinesCaption();
default:
throw new RuntimeException("cant handle " + resourceType);
case WORKER:
return allWorkersCaption();
case MACHINE:
return allMachinesCaption();
default:
throw new RuntimeException("cant handle " + resourceType);
}
}
@ -463,9 +463,7 @@ public class Criterion extends IntegrationEntity implements ICriterion,
}
@Override
public void setCodeAutogenerated(Boolean codeAutogenerated) {
// do nothing
}
public void setCodeAutogenerated(Boolean codeAutogenerated) { /* Do nothing */ }
@Override
public Boolean isCodeAutogenerated() {

View file

@ -35,7 +35,9 @@ import org.libreplan.business.common.exceptions.InstanceNotFoundException;
import org.libreplan.business.resources.daos.ICriterionSatisfactionDAO;
import org.libreplan.business.resources.daos.ICriterionTypeDAO;
/**
* Declares a interval of time in which the criterion is satisfied <br />
* Declares a interval of time in which the criterion is satisfied.
* <br />
*
* @author Óscar González Fernández <ogonzalez@igalia.com>
* @author Fernando Bellas Permuy <fbellas@udc.es>
*/
@ -45,30 +47,55 @@ public class CriterionSatisfaction extends IntegrationEntity {
static {
BY_START_COMPARATOR = new Comparator<CriterionSatisfaction>() {
@Override
public int compare(CriterionSatisfaction o1,
CriterionSatisfaction o2) {
public int compare(CriterionSatisfaction o1, CriterionSatisfaction o2) {
return o1.getStartDate().compareTo(o2.getStartDate());
}
};
}
private LocalDate startDate;
private LocalDate finishDate;
private Criterion criterion;
private Resource resource;
private Boolean isDeleted = false;
/**
* Constructor for hibernate. Do not use!
*/
public CriterionSatisfaction() {}
private CriterionSatisfaction(LocalDate startDate, Criterion criterion, Resource resource) {
Validate.notNull(startDate, "startDate must be not null");
Validate.notNull(criterion, "criterion must be not null");
Validate.notNull(resource, "resource must be not null");
this.startDate = startDate;
this.criterion = criterion;
this.resource = resource;
}
private CriterionSatisfaction(Criterion criterion, Resource resource, Interval interval) {
this(interval.getStart(), criterion, resource);
if (interval.getEnd() != null) {
this.finish(interval.getEnd());
}
}
public static CriterionSatisfaction create() {
return create(new CriterionSatisfaction());
}
public static CriterionSatisfaction create(LocalDate startDate,
Criterion criterion, Resource resource) {
return create(
new CriterionSatisfaction(startDate, criterion, resource));
public static CriterionSatisfaction create(LocalDate startDate, Criterion criterion, Resource resource) {
return create(new CriterionSatisfaction(startDate, criterion, resource));
}
public static CriterionSatisfaction create(Criterion criterion,
Resource resource, Interval interval) {
public static CriterionSatisfaction create(Criterion criterion, Resource resource, Interval interval) {
return create(new CriterionSatisfaction(criterion, resource, interval));
}
/**
@ -76,24 +103,22 @@ public class CriterionSatisfaction extends IntegrationEntity {
* not exist
*/
public static CriterionSatisfaction createUnvalidated(String code,
String criterionTypeName, String criterionName, Resource resource,
LocalDate startDate, LocalDate finishDate)
throws InstanceNotFoundException {
String criterionTypeName,
String criterionName,
Resource resource,
LocalDate startDate,
LocalDate finishDate) throws InstanceNotFoundException {
ICriterionTypeDAO criterionTypeDAO =
Registry.getCriterionTypeDAO();
ICriterionTypeDAO criterionTypeDAO = Registry.getCriterionTypeDAO();
/* Get CriterionType. */
CriterionType criterionType = criterionTypeDAO.findUniqueByName(
criterionTypeName);
/* Get CriterionType */
CriterionType criterionType = criterionTypeDAO.findUniqueByName(criterionTypeName);
/* Get Criterion. */
Criterion criterion = criterionType.getCriterion(
criterionName);
/* Get Criterion */
Criterion criterion = criterionType.getCriterion(criterionName);
/* Create instance of CriterionSatisfaction. */
CriterionSatisfaction criterionSatisfaction =
create(new CriterionSatisfaction(), code);
/* Create instance of CriterionSatisfaction */
CriterionSatisfaction criterionSatisfaction = create(new CriterionSatisfaction(), code);
criterionSatisfaction.criterion = criterion;
criterionSatisfaction.resource = resource;
@ -109,19 +134,19 @@ public class CriterionSatisfaction extends IntegrationEntity {
* not exist
*/
public void updateUnvalidated(String criterionTypeName,
String criterionName, LocalDate startDate, LocalDate finishDate)
throws InstanceNotFoundException {
String criterionName,
LocalDate startDate,
LocalDate finishDate) throws InstanceNotFoundException {
CriterionType criterionType = null;
CriterionType criterionType;
if (StringUtils.isBlank(criterionTypeName)) {
criterionType = criterion.getType();
} else {
criterionType = Registry.getCriterionTypeDAO().findUniqueByName(
criterionTypeName);
criterionType = Registry.getCriterionTypeDAO().findUniqueByName(criterionTypeName);
}
String newCriterionName = null;
String newCriterionName;
if (StringUtils.isBlank(criterionName)) {
newCriterionName = StringUtils.trim(criterion.getName());
@ -138,44 +163,8 @@ public class CriterionSatisfaction extends IntegrationEntity {
if (finishDate != null) {
this.finishDate = finishDate;
}
}
/**
* Constructor for hibernate. Do not use!
*/
public CriterionSatisfaction() {
}
private CriterionSatisfaction(LocalDate startDate, Criterion criterion,
Resource resource) {
Validate.notNull(startDate, "startDate must be not null");
Validate.notNull(criterion, "criterion must be not null");
Validate.notNull(resource, "resource must be not null");
this.startDate = startDate;
this.criterion = criterion;
this.resource = resource;
}
private CriterionSatisfaction(Criterion criterion, Resource resource,
Interval interval) {
this(interval.getStart(), criterion, resource);
if (interval.getEnd() != null) {
this.finish(interval.getEnd());
}
}
private LocalDate startDate;
private LocalDate finishDate;
private Criterion criterion;
private Resource resource;
private Boolean isDeleted = false;
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
@ -187,6 +176,7 @@ public class CriterionSatisfaction extends IntegrationEntity {
result.finishDate = finishDate;
result.criterion = criterion;
result.resource = resource;
return result;
}
@ -237,10 +227,11 @@ public class CriterionSatisfaction extends IntegrationEntity {
public void finish(LocalDate finish) {
Validate.notNull(finish);
Validate.isTrue(getStartDate() == null
|| getStartDate().compareTo(finish) <= 0);
Validate.isTrue(finishDate == null || isNewObject()
|| getEndDate().equals(finish) || getEndDate().isBefore(finish));
Validate.isTrue(getStartDate() == null || getStartDate().compareTo(finish) <= 0);
Validate.isTrue(
finishDate == null || isNewObject() || getEndDate().equals(finish) || getEndDate().isBefore(finish));
this.finishDate = finish;
}
@ -260,10 +251,10 @@ public class CriterionSatisfaction extends IntegrationEntity {
}
public void setStartDate(LocalDate date) {
if(date != null){
Validate.isTrue(startDate == null || isNewObject()
|| getStartDate().equals(date)
|| getStartDate().isAfter(date));
if(date != null) {
Validate.isTrue(
startDate == null || isNewObject() || getStartDate().equals(date) || getStartDate().isAfter(date));
}
startDate = date;
}
@ -297,17 +288,17 @@ public class CriterionSatisfaction extends IntegrationEntity {
@AssertTrue(message = "criterion satisfaction with end date before start")
public boolean isPositiveTimeInterval() {
/* Check if it makes sense to check the constraint .*/
/* Check if it makes sense to check the constraint */
if (!isStartDateSpecified()) {
return true;
}
/* Check the constraint. */
/* Check the constraint */
if (finishDate == null) {
return true;
}
return (finishDate.isAfter(startDate) || startDate.equals(finishDate));
return finishDate.isAfter(startDate) || startDate.equals(finishDate);
}

View file

@ -30,7 +30,8 @@ import org.hibernate.validator.constraints.NotEmpty;
import javax.validation.Valid;
/**
* Entity
* Represents entity. It is another type of work resource.
*
* @author Javier Moran Rua <jmoran@igalia.com>
* @author Fernando Bellas Permuy <fbellas@udc.es>
*/
@ -42,25 +43,22 @@ public class Machine extends Resource {
private String description;
private Set<MachineWorkersConfigurationUnit> configurationUnits = new HashSet<MachineWorkersConfigurationUnit>();
private Set<MachineWorkersConfigurationUnit> configurationUnits = new HashSet<>();
@Valid
public Set<MachineWorkersConfigurationUnit> getConfigurationUnits() {
return Collections.unmodifiableSet(configurationUnits);
}
public void addMachineWorkersConfigurationUnit(
MachineWorkersConfigurationUnit unit) {
public void addMachineWorkersConfigurationUnit(MachineWorkersConfigurationUnit unit) {
configurationUnits.add(unit);
}
public void removeMachineWorkersConfigurationUnit(
MachineWorkersConfigurationUnit unit) {
public void removeMachineWorkersConfigurationUnit(MachineWorkersConfigurationUnit unit) {
configurationUnits.remove(unit);
}
public static Machine createUnvalidated(String code, String name,
String description) {
public static Machine createUnvalidated(String code, String name, String description) {
Machine machine = create(new Machine(), code);
@ -86,9 +84,7 @@ public class Machine extends Resource {
/**
* Used by Hibernate. Do not use!
*/
protected Machine() {
}
protected Machine() {}
public static Machine create() {
return create(new Machine());
@ -120,8 +116,7 @@ public class Machine extends Resource {
}
@Override
protected boolean isCriterionSatisfactionOfCorrectType(
CriterionSatisfaction c) {
protected boolean isCriterionSatisfactionOfCorrectType(CriterionSatisfaction c) {
return c.getResourceType().equals(ResourceEnum.MACHINE);
}
@ -139,5 +134,4 @@ public class Machine extends Resource {
public String getHumanId() {
return name;
}
}

View file

@ -71,6 +71,7 @@ import org.libreplan.business.workingday.IntraDayDate.PartialDay;
/**
* This class acts as the base class for all resources.
*
* @author Fernando Bellas Permuy <fbellas@udc.es>
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
* @author Jacobo Aragunde Perez <jaragunde@igalia.com>
@ -135,7 +136,7 @@ public abstract class Resource extends IntegrationEntity implements IHumanIdenti
private Map<LocalDate, List<DayAssignment>> assignmentsByDayCached = null;
private Set<ResourcesCostCategoryAssignment> resourcesCostCategoryAssignments =
new HashSet<ResourcesCostCategoryAssignment>();
new HashSet<ResourcesCostCategoryAssignment>();
private ResourceType resourceType = ResourceType.NON_LIMITING_RESOURCE;
@ -438,7 +439,7 @@ public abstract class Resource extends IntegrationEntity implements IHumanIdenti
private static class EnsureSatisfactionIsCorrect {
private EnsureSatisfactionIsCorrect(Resource resource,
ICriterionType<?> type, CriterionSatisfaction satisfaction) {
ICriterionType<?> type, CriterionSatisfaction satisfaction) {
Validate.notNull(resource);
Validate.notNull(satisfaction.getResource());
Validate.notNull(satisfaction);
@ -469,7 +470,7 @@ public abstract class Resource extends IntegrationEntity implements IHumanIdenti
}
public CriterionSatisfaction addSatisfaction(ICriterionType<?> type,
CriterionSatisfaction satisfaction) {
CriterionSatisfaction satisfaction) {
return new EnsureSatisfactionIsCorrect(this, type, satisfaction)
.addSatisfaction();
}
@ -503,7 +504,7 @@ public abstract class Resource extends IntegrationEntity implements IHumanIdenti
}
private CriterionSatisfaction createNewSatisfaction(Interval interval,
Criterion criterion) {
Criterion criterion) {
CriterionSatisfaction newSatisfaction = CriterionSatisfaction.create(criterion, this, interval);
return newSatisfaction;
}
@ -521,7 +522,7 @@ public abstract class Resource extends IntegrationEntity implements IHumanIdenti
* </ul>
*/
private int findPlace(List<CriterionSatisfaction> orderedSatisfactions,
CriterionSatisfaction newSatisfaction) {
CriterionSatisfaction newSatisfaction) {
int position = Collections.binarySearch(orderedSatisfactions,
newSatisfaction, CriterionSatisfaction.BY_START_COMPARATOR);
if (position >= 0) {
@ -538,7 +539,7 @@ public abstract class Resource extends IntegrationEntity implements IHumanIdenti
}
public List<CriterionSatisfaction> finishEnforcedAt(Criterion criterion,
LocalDate date) {
LocalDate date) {
ArrayList<CriterionSatisfaction> result = new ArrayList<CriterionSatisfaction>();
for (CriterionSatisfaction criterionSatisfaction : query()
.exactly(criterion).at(date).result()) {
@ -549,7 +550,7 @@ public abstract class Resource extends IntegrationEntity implements IHumanIdenti
}
public void modifySatisfaction(CriterionSatisfaction original,
Interval interval){
Interval interval){
/* Create a temporal criterion satisfaction. */
CriterionType type = original.getCriterion().getType();
CriterionSatisfaction temporal = createNewSatisfaction(interval,
@ -570,13 +571,13 @@ public abstract class Resource extends IntegrationEntity implements IHumanIdenti
criterionSatisfactions.add(original);
if(!canAdd){
throw new IllegalStateException(
"This interval "+original.getCriterion().getName()+" not is valid because exists overlap with other criterion satisfaction");
"This interval "+original.getCriterion().getName()+" not is valid because exists overlap with other criterion satisfaction");
}
}catch(IllegalArgumentException e){
throw new IllegalArgumentException (original.getCriterion().getName()+" : "+e.getMessage());
}
}else{
throw new IllegalStateException(
throw new IllegalStateException(
"The criterion satisfaction "+original.getCriterion().getName()+" not is activated for this resource");
}
}
@ -596,9 +597,9 @@ public abstract class Resource extends IntegrationEntity implements IHumanIdenti
}
CriterionSatisfaction previousSameCriterion = getPreviousSameCriterion
(criterion, satisfaction, satisfactions);
(criterion, satisfaction, satisfactions);
CriterionSatisfaction posteriorSameCriterion = getNextSameCriterion
(criterion, satisfaction, satisfactions);
(criterion, satisfaction, satisfactions);
boolean canAdd = ((previousSameCriterion == null ||
!previousSameCriterion.overlapsWith(interval)) &&
@ -616,7 +617,7 @@ public abstract class Resource extends IntegrationEntity implements IHumanIdenti
CriterionSatisfaction posterior = getNext(type, satisfaction, satisfactions);
return (previous == null || !previous.overlapsWith(interval)) &&
( posterior == null || !posterior.overlapsWith(interval));
( posterior == null || !posterior.overlapsWith(interval));
}
public boolean _canAddSatisfaction(
@ -638,7 +639,7 @@ public abstract class Resource extends IntegrationEntity implements IHumanIdenti
boolean canAdd = ((previousSameCriterion == null ||
!previousSameCriterion.overlapsWith(interval)) &&
( posteriorSameCriterion == null ||
!posteriorSameCriterion.overlapsWith(interval)));
!posteriorSameCriterion.overlapsWith(interval)));
if(!canAdd) {
return false;
@ -657,14 +658,14 @@ public abstract class Resource extends IntegrationEntity implements IHumanIdenti
}
public boolean canAddSatisfaction(ICriterionType<?> type,
CriterionSatisfaction satisfaction) {
CriterionSatisfaction satisfaction) {
EnsureSatisfactionIsCorrect ensureSatisfactionIsCorrect = new EnsureSatisfactionIsCorrect(
this, type, satisfaction);
return ensureSatisfactionIsCorrect.canAddSatisfaction();
}
private CriterionSatisfaction getNext(ICriterionType<?> type,
CriterionSatisfaction newSatisfaction,Set<CriterionSatisfaction> list) {
CriterionSatisfaction newSatisfaction,Set<CriterionSatisfaction> list) {
List<CriterionSatisfaction> ordered = query().from(type).result(list);
int position = findPlace(ordered, newSatisfaction);
CriterionSatisfaction next = position != ordered.size() ? ordered
@ -673,7 +674,7 @@ public abstract class Resource extends IntegrationEntity implements IHumanIdenti
}
private CriterionSatisfaction getPrevious(ICriterionType<?> type,
CriterionSatisfaction newSatisfaction,Set<CriterionSatisfaction> list) {
CriterionSatisfaction newSatisfaction,Set<CriterionSatisfaction> list) {
List<CriterionSatisfaction> ordered = query().from(type).result(list);
int position = findPlace(ordered, newSatisfaction);
CriterionSatisfaction previous = position > 0 ? ordered
@ -683,7 +684,7 @@ public abstract class Resource extends IntegrationEntity implements IHumanIdenti
private CriterionSatisfaction getNextSameCriterion(Criterion criterion,
CriterionSatisfaction newSatisfaction,Set<CriterionSatisfaction> list) {
CriterionSatisfaction newSatisfaction,Set<CriterionSatisfaction> list) {
List<CriterionSatisfaction> ordered = query().from(criterion).result(list);
int position = findPlace(ordered, newSatisfaction);
CriterionSatisfaction next = position != ordered.size() ? ordered
@ -692,7 +693,7 @@ public abstract class Resource extends IntegrationEntity implements IHumanIdenti
}
private CriterionSatisfaction getPreviousSameCriterion(Criterion criterion,
CriterionSatisfaction newSatisfaction,Set<CriterionSatisfaction> list) {
CriterionSatisfaction newSatisfaction,Set<CriterionSatisfaction> list) {
List<CriterionSatisfaction> ordered = query().from(criterion).result(list);
int position = findPlace(ordered, newSatisfaction);
CriterionSatisfaction previous = position > 0 ? ordered
@ -753,7 +754,7 @@ public abstract class Resource extends IntegrationEntity implements IHumanIdenti
* @throws IllegalArgumentException in case of overlapping
*/
private void checkNotOverlaps(CriterionSatisfaction before,
CriterionSatisfaction after) {
CriterionSatisfaction after) {
CriterionType criterionType = before.getCriterion().getType();
@ -763,10 +764,10 @@ public abstract class Resource extends IntegrationEntity implements IHumanIdenti
* criterion satisfactions per resource).
*/
if (before.getCriterion().equals(after.getCriterion()) &&
!before.goesBeforeWithoutOverlapping(after)) {
throw new IllegalArgumentException(createOverlapsMessage(before,
after));
}
!before.goesBeforeWithoutOverlapping(after)) {
throw new IllegalArgumentException(createOverlapsMessage(before,
after));
}
/*
* If CriterionType does not allow simultaneous criterion satisfactions
@ -774,7 +775,7 @@ public abstract class Resource extends IntegrationEntity implements IHumanIdenti
* of they refer to different Criterion objects).
*/
if (!criterionType.isAllowSimultaneousCriterionsPerResource() &&
!before.goesBeforeWithoutOverlapping(after)) {
!before.goesBeforeWithoutOverlapping(after)) {
throw new IllegalArgumentException(createOverlapsMessage(before,
after));
}
@ -782,7 +783,7 @@ public abstract class Resource extends IntegrationEntity implements IHumanIdenti
}
private String createOverlapsMessage(CriterionSatisfaction before,
CriterionSatisfaction after) {
CriterionSatisfaction after) {
return new StringBuilder("the satisfaction").append(before).append(
"overlaps with").append(after).toString();
}
@ -824,13 +825,13 @@ public abstract class Resource extends IntegrationEntity implements IHumanIdenti
}
public void setResourceCalendar(String calendarCode)
throws InstanceNotFoundException, MultipleInstancesException {
throws InstanceNotFoundException, MultipleInstancesException {
ResourceCalendar calendar;
if (StringUtils.isBlank(calendarCode)) {
calendar = Registry.getConfigurationDAO().getConfiguration().
getDefaultCalendar().newDerivedResourceCalendar();
getDefaultCalendar().newDerivedResourceCalendar();
} else {
BaseCalendar baseCalendar = Registry.getBaseCalendarDAO()
@ -849,7 +850,7 @@ public abstract class Resource extends IntegrationEntity implements IHumanIdenti
public EffortDuration getAssignedDurationDiscounting(
Map<Long, Set<BaseEntity>> allocationsFromWhichDiscountHours,
LocalDate day) {
EffortDuration result = zero();
for (DayAssignment dayAssignment : getAssignmentsForDay(day)) {
@ -886,19 +887,19 @@ public abstract class Resource extends IntegrationEntity implements IHumanIdenti
}
public int getTotalWorkHours(LocalDate start, LocalDate endExclusive,
ICriterion criterion) {
ICriterion criterion) {
return getTotalEffortFor(IntraDayDate.startOfDay(start),
IntraDayDate.startOfDay(endExclusive), criterion)
.roundToHours();
}
public EffortDuration getTotalEffortFor(IntraDayDate startInclusive,
IntraDayDate endExclusive) {
IntraDayDate endExclusive) {
return getTotalEffortFor(startInclusive, endExclusive, null);
}
public EffortDuration getTotalEffortFor(IntraDayDate startInclusive,
IntraDayDate endExclusive, ICriterion criterion) {
IntraDayDate endExclusive, ICriterion criterion) {
return getTotalEffortFor(getCalendarOrDefault(), startInclusive,
endExclusive, criterion);
}
@ -909,8 +910,8 @@ public abstract class Resource extends IntegrationEntity implements IHumanIdenti
}
private EffortDuration getTotalEffortFor(final ICalendar calendar,
IntraDayDate startInclusive, IntraDayDate endExclusive,
final ICriterion criterionToSatisfy) {
IntraDayDate startInclusive, IntraDayDate endExclusive,
final ICriterion criterionToSatisfy) {
Iterable<PartialDay> daysBetween = startInclusive
.daysUntil(endExclusive);
@ -923,7 +924,7 @@ public abstract class Resource extends IntegrationEntity implements IHumanIdenti
.getCapacityOn(current);
if (capacityCurrent != null
&& (criterionToSatisfy == null || satisfiesCriterionAt(
criterionToSatisfy, current.getDate()))) {
criterionToSatisfy, current.getDate()))) {
return capacityCurrent;
}
return zero();
@ -932,12 +933,12 @@ public abstract class Resource extends IntegrationEntity implements IHumanIdenti
}
private boolean satisfiesCriterionAt(ICriterion criterionToSatisfy,
LocalDate current) {
LocalDate current) {
return criterionToSatisfy.isSatisfiedBy(this, current);
}
public void addUnvalidatedSatisfaction(CriterionSatisfaction
criterionSatisfaction) {
criterionSatisfaction) {
criterionSatisfactions.add(criterionSatisfaction);
@ -975,7 +976,7 @@ public abstract class Resource extends IntegrationEntity implements IHumanIdenti
}
private void validateSatisfaction(CriterionSatisfaction satisfaction, Set<CriterionSatisfaction> satisfactions)
throws ValidationException {
throws ValidationException {
if ( !canAddSatisfaction(satisfaction, satisfactions) ) {
String message = getReasonForNotAddingSatisfaction(satisfaction.getCriterion().getType());
@ -1004,16 +1005,16 @@ public abstract class Resource extends IntegrationEntity implements IHumanIdenti
}
public ResourcesCostCategoryAssignment
getResourcesCostCategoryAssignmentByCode(String code)
throws InstanceNotFoundException {
getResourcesCostCategoryAssignmentByCode(String code)
throws InstanceNotFoundException {
if (StringUtils.isBlank(code)) {
throw new InstanceNotFoundException(code,
ResourcesCostCategoryAssignment.class.getName());
ResourcesCostCategoryAssignment.class.getName());
}
for (ResourcesCostCategoryAssignment i :
resourcesCostCategoryAssignments) {
resourcesCostCategoryAssignments) {
if (i.getCode().equalsIgnoreCase(StringUtils.trim(code))) {
return i;
@ -1022,7 +1023,7 @@ public abstract class Resource extends IntegrationEntity implements IHumanIdenti
}
throw new InstanceNotFoundException(code,
ResourcesCostCategoryAssignment.class.getName());
ResourcesCostCategoryAssignment.class.getName());
}
@ -1034,7 +1035,7 @@ public abstract class Resource extends IntegrationEntity implements IHumanIdenti
}
public void addUnvalidatedResourcesCostCategoryAssignment(
ResourcesCostCategoryAssignment assignment) {
ResourcesCostCategoryAssignment assignment) {
resourcesCostCategoryAssignments.add(assignment);
@ -1093,7 +1094,7 @@ public abstract class Resource extends IntegrationEntity implements IHumanIdenti
* Check assignment overlapping.
*/
List<ResourcesCostCategoryAssignment> assignmentsList =
new ArrayList<ResourcesCostCategoryAssignment>();
new ArrayList<ResourcesCostCategoryAssignment>();
assignmentsList.addAll(getResourcesCostCategoryAssignments());
try {
@ -1112,7 +1113,7 @@ public abstract class Resource extends IntegrationEntity implements IHumanIdenti
}
@AssertTrue(message="there exist criterion satisfactions referring to " +
"criterion types not applicable to this resource")
"criterion types not applicable to this resource")
public boolean isCriterionSatisfactionsWithCorrectTypeConstraint() {
for (CriterionSatisfaction c : getCriterionSatisfactions()) {
@ -1126,13 +1127,13 @@ public abstract class Resource extends IntegrationEntity implements IHumanIdenti
}
@AssertTrue(message="criterion satisfaction codes must be unique inside " +
"a resource")
"a resource")
public boolean isNonRepeatedCriterionSatisfactionCodesConstraint() {
return getFirstRepeatedCode(criterionSatisfactions) == null;
}
@AssertTrue(message="resource cost category assignments codes must be " +
"unique inside a resource")
"unique inside a resource")
public boolean isNonRepeatedResourcesCostCategoryAssignmentCodesConstraint() {
return getFirstRepeatedCode(resourcesCostCategoryAssignments) == null;
}
@ -1174,30 +1175,30 @@ public abstract class Resource extends IntegrationEntity implements IHumanIdenti
@AssertTrue(message = "You have exceeded the maximum limit of resources")
public boolean isMaxResourcesConstraint() {
return Registry.getTransactionService().runOnAnotherReadOnlyTransaction(new IOnTransaction<Boolean>() {
@Override
public Boolean execute() {
Configuration configuration = Registry.getConfigurationDAO().getConfiguration();
if ( configuration == null ) {
return true;
}
@Override
public Boolean execute() {
Configuration configuration = Registry.getConfigurationDAO().getConfiguration();
if ( configuration == null ) {
return true;
}
Integer maxResources = configuration.getMaxResources();
if ( maxResources != null && maxResources > 0 ) {
List<Resource> resources = Registry.getResourceDAO().findAll();
int resourcesNumber = resources.size();
if ( isNewObject() ) {
resourcesNumber++;
}
if ( resourcesNumber > maxResources ) {
return false;
}
}
return true;
Integer maxResources = configuration.getMaxResources();
if ( maxResources != null && maxResources > 0 ) {
List<Resource> resources = Registry.getResourceDAO().findAll();
int resourcesNumber = resources.size();
if ( isNewObject() ) {
resourcesNumber++;
}
});
if ( resourcesNumber > maxResources ) {
return false;
}
}
return true;
}
});
}
public boolean isActiveBetween(LocalDate startDate, LocalDate endDate) {

View file

@ -21,10 +21,7 @@
package org.libreplan.business.resources.entities;
/**
*
* @author Diego Pino Garcia<dpino@igalia.com>
*/
public enum ResourceEnum {
@ -32,21 +29,22 @@ public enum ResourceEnum {
WORKER(Worker.class, _("WORKER")),
MACHINE(Machine.class, _("MACHINE"));
private Class<? extends Resource> klass;
private final String displayName;
ResourceEnum(Class<? extends Resource> klass, String displayName) {
this.klass = klass;
this.displayName = displayName;
}
/**
* Forces to mark the string as needing translation
* Forces to mark the string as needing translation.
*/
private static String _(String string) {
return string;
}
private Class<? extends Resource> klass;
private final String displayName;
private ResourceEnum(Class<? extends Resource> klass, String displayName) {
this.klass = klass;
this.displayName = displayName;
}
public Class<? extends Resource> asClass() {
return klass;
}

View file

@ -52,14 +52,14 @@ public class Worker extends Resource {
}
public static Worker create(String firstName, String surname,
String nif) {
String nif) {
return create(new Worker(firstName, surname, nif));
}
public static Worker createUnvalidated(String code, String firstName,
String surname, String nif) {
String surname, String nif) {
Worker worker = create(new Worker(), code);
@ -110,6 +110,14 @@ public class Worker extends Resource {
this.nif = nif;
}
/**
* This method is needed by autocomplete component on _machineConfigurationUnits.zul
*/
@Override
public String toString () {
return this.getName() + " - " + this.getNif();
}
public String getDescription() {
return getSurname() + "," + getFirstName();
}
@ -180,18 +188,18 @@ public class Worker extends Resource {
protected boolean areFirstNameSurnameNifSpecified() {
return !StringUtils.isBlank(firstName) &&
!StringUtils.isBlank(surname) &&
!StringUtils.isBlank(nif);
return !StringUtils.isBlank(firstName) &&
!StringUtils.isBlank(surname) &&
!StringUtils.isBlank(nif);
}
}
@Override
protected boolean isCriterionSatisfactionOfCorrectType(
CriterionSatisfaction c) {
@Override
protected boolean isCriterionSatisfactionOfCorrectType(
CriterionSatisfaction c) {
return c.getResourceType().equals(ResourceEnum.WORKER);
}
}
@Override
public ResourceEnum getType() {

View file

@ -36,7 +36,7 @@ public enum PredefinedScenarios {
private final String name;
private PredefinedScenarios(String name) {
PredefinedScenarios(String name) {
this.name = name;
}

View file

@ -26,6 +26,7 @@ import org.libreplan.business.orders.entities.Order;
import org.libreplan.business.scenarios.daos.IScenarioDAO;
import org.libreplan.business.scenarios.entities.Scenario;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
@ -36,7 +37,7 @@ import org.springframework.transaction.annotation.Transactional;
* @author Manuel Rego Casasnovas <mrego@igalia.com>
*/
@Component
@Scope("singleton")
@Scope(BeanDefinition.SCOPE_SINGLETON)
public class ScenariosBootstrap implements IScenariosBootstrap {
@Autowired
@ -50,16 +51,16 @@ public class ScenariosBootstrap implements IScenariosBootstrap {
@Override
@Transactional
public void loadRequiredData() {
for (PredefinedScenarios predefinedScenario : PredefinedScenarios
.values()) {
if (!scenarioDAO.existsByNameAnotherTransaction(predefinedScenario
.getName())) {
for (PredefinedScenarios predefinedScenario : PredefinedScenarios.values()) {
if (!scenarioDAO.existsByNameAnotherTransaction(predefinedScenario.getName())) {
Scenario scenario = createAtDB(predefinedScenario);
if (predefinedScenario == PredefinedScenarios.MASTER) {
mainScenario = scenario;
}
}
}
if (mainScenario == null) {
mainScenario = PredefinedScenarios.MASTER.getScenario();
}
@ -67,11 +68,14 @@ public class ScenariosBootstrap implements IScenariosBootstrap {
private Scenario createAtDB(PredefinedScenarios predefinedScenario) {
Scenario scenario = predefinedScenario.createScenario();
for (Order each : orderDAO.getOrders()) {
scenario.addOrder(each);
}
scenarioDAO.save(scenario);
scenario.dontPoseAsTransientObjectAnymore();
return scenario;
}

View file

@ -27,7 +27,6 @@ import java.util.Collections;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.libreplan.business.common.daos.GenericDAOHibernate;
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
@ -49,8 +48,7 @@ import org.springframework.transaction.annotation.Transactional;
*/
@Repository
@Scope(BeanDefinition.SCOPE_SINGLETON)
public class ScenarioDAO extends GenericDAOHibernate<Scenario, Long> implements
IScenarioDAO {
public class ScenarioDAO extends GenericDAOHibernate<Scenario, Long> implements IScenarioDAO {
@Autowired
private IOrderVersionDAO orderVersionDAO;
@ -70,7 +68,7 @@ public class ScenarioDAO extends GenericDAOHibernate<Scenario, Long> implements
private List<OrderVersion> getNewOrders(Scenario scenario) {
Collection<OrderVersion> values = scenario.getOrders().values();
List<OrderVersion> newOrders = new ArrayList<OrderVersion>();
List<OrderVersion> newOrders = new ArrayList<>();
for (OrderVersion each : values) {
if (each.isNewObject()) {
newOrders.add(each);
@ -86,9 +84,9 @@ public class ScenarioDAO extends GenericDAOHibernate<Scenario, Long> implements
throw new InstanceNotFoundException(null, Scenario.class.getName());
}
Scenario scenario = (Scenario) getSession().createCriteria(
Scenario.class).add(
Restrictions.eq("name", name.trim()).ignoreCase())
Scenario scenario = (Scenario) getSession()
.createCriteria(Scenario.class)
.add(Restrictions.eq("name", name.trim()).ignoreCase())
.uniqueResult();
if (scenario == null) {
@ -132,10 +130,7 @@ public class ScenarioDAO extends GenericDAOHibernate<Scenario, Long> implements
}
private boolean areDifferentInDB(Scenario one, Scenario other) {
if ((one.getId() == null) || (other.getId() == null)) {
return true;
}
return !one.getId().equals(other.getId());
return (one.getId() == null) || (other.getId() == null) || !one.getId().equals(other.getId());
}
@Override
@ -144,14 +139,15 @@ public class ScenarioDAO extends GenericDAOHibernate<Scenario, Long> implements
return Collections.emptyList();
}
Criteria c = getSession().createCriteria(Scenario.class).add(
Restrictions.eq("predecessor", scenario));
return (List<Scenario>) c.list();
return getSession()
.createCriteria(Scenario.class)
.add(Restrictions.eq("predecessor", scenario))
.list();
}
@Override
public List<Scenario> getDerivedScenarios(Scenario scenario) {
List<Scenario> result = new ArrayList<Scenario>();
List<Scenario> result = new ArrayList<>();
List<Scenario> children = findByPredecessor(scenario);
result.addAll(children);
@ -165,8 +161,11 @@ public class ScenarioDAO extends GenericDAOHibernate<Scenario, Long> implements
@Override
public void updateDerivedScenariosWithNewVersion(
OrderVersion previousOrderVersion, Order order,
Scenario currentScenario, OrderVersion newOrderVersion) {
OrderVersion previousOrderVersion,
Order order,
Scenario currentScenario,
OrderVersion newOrderVersion) {
for (Scenario each : getDerivedScenarios(currentScenario)) {
if (each.usesVersion(previousOrderVersion, order)) {
if (newOrderVersion == null) {

View file

@ -44,8 +44,8 @@ import org.libreplan.business.trees.ITreeParentNode;
public class OrderLineGroupTemplate extends OrderElementTemplate implements
ITreeParentNode<OrderElementTemplate> {
private final CriterionRequirementTemplateHandler criterionRequirementTemplateHandler = CriterionRequirementTemplateHandler
.getInstance();
private final CriterionRequirementTemplateHandler criterionRequirementTemplateHandler =
CriterionRequirementTemplateHandler.getInstance();
private final class ChildrenManipulator extends
TreeNodeOnListWithSchedulingState<OrderElementTemplate> {
@ -121,7 +121,7 @@ public class OrderLineGroupTemplate extends OrderElementTemplate implements
}
protected static <T extends OrderLineGroupTemplate> T create(T beingBuilt,
OrderLineGroup group) {
OrderLineGroup group) {
OrderElementTemplate.create(beingBuilt, group);
List<OrderElementTemplate> result = buildChildrenTemplates(beingBuilt,
group.getChildren());
@ -165,7 +165,7 @@ public class OrderLineGroupTemplate extends OrderElementTemplate implements
private static List<OrderElementTemplate> buildChildrenTemplates(
OrderLineGroupTemplate parent, List<OrderElement> children) {
List<OrderElementTemplate> result = new ArrayList<OrderElementTemplate>();
List<OrderElementTemplate> result = new ArrayList<>();
for (OrderElement each : children) {
OrderElementTemplate template = each.createTemplate();
template.setParent(parent);
@ -174,7 +174,7 @@ public class OrderLineGroupTemplate extends OrderElementTemplate implements
return result;
}
private List<OrderElementTemplate> children = new ArrayList<OrderElementTemplate>();
private List<OrderElementTemplate> children = new ArrayList<>();
@Override
public List<OrderElementTemplate> getChildrenTemplates() {
@ -207,7 +207,7 @@ public class OrderLineGroupTemplate extends OrderElementTemplate implements
@Override
public void replace(OrderElementTemplate previousChild,
OrderElementTemplate newChild) {
OrderElementTemplate newChild) {
getManipulator().replace(previousChild, newChild);
}

View file

@ -46,23 +46,26 @@ import org.libreplan.business.orders.entities.OrderLineGroup;
public class OrderLineTemplate extends OrderElementTemplate {
@Valid
private Set<HoursGroup> hoursGroups = new HashSet<HoursGroup>();
private Set<HoursGroup> hoursGroups = new HashSet<>();
private Integer lastHoursGroupSequenceCode = 0;
private BigDecimal budget = BigDecimal.ZERO.setScale(2);
private HoursGroupOrderLineTemplateHandler hoursGroupOrderLineTemplateHandler =
HoursGroupOrderLineTemplateHandler.getInstance();
public static OrderLineTemplate create(OrderLine orderLine) {
OrderLineTemplate beingBuilt = new OrderLineTemplate();
copyHoursGroup(orderLine.getHoursGroups(), beingBuilt);
beingBuilt.setBudget(orderLine.getBudget());
return create(beingBuilt, orderLine);
}
private static void copyHoursGroup(
final Collection<HoursGroup> hoursGroups,
OrderLineTemplate orderLineTemplate) {
private static void copyHoursGroup(final Collection<HoursGroup> hoursGroups, OrderLineTemplate orderLineTemplate) {
for (HoursGroup each: hoursGroups) {
orderLineTemplate.addHoursGroup(HoursGroup.copyFrom(each,
orderLineTemplate));
orderLineTemplate.addHoursGroup(HoursGroup.copyFrom(each, orderLineTemplate));
}
}
@ -70,17 +73,16 @@ public class OrderLineTemplate extends OrderElementTemplate {
return createNew(new OrderLineTemplate());
}
private BigDecimal budget = BigDecimal.ZERO.setScale(2);
protected <T extends OrderElement> T setupElementParts(T orderElement) {
super.setupElementParts(orderElement);
setupHoursGroups((OrderLine) orderElement);
setupBudget((OrderLine) orderElement);
return orderElement;
}
private void setupHoursGroups(OrderLine orderLine) {
Set<HoursGroup> result = new HashSet<HoursGroup>();
Set<HoursGroup> result = new HashSet<>();
for (HoursGroup each: getHoursGroups()) {
result.add(HoursGroup.copyFrom(each, orderLine));
}
@ -105,12 +107,13 @@ public class OrderLineTemplate extends OrderElementTemplate {
public OrderLineGroupTemplate toContainer() {
OrderLineGroupTemplate result = OrderLineGroupTemplate.createNew();
copyTo(result);
return result;
}
@Override
public List<OrderElementTemplate> getChildren() {
return new ArrayList<OrderElementTemplate>();
return new ArrayList<>();
}
@Override
@ -123,18 +126,23 @@ public class OrderLineTemplate extends OrderElementTemplate {
if (getWorkHours() != 0) {
return false;
}
if (!getDirectCriterionRequirements().isEmpty()) {
return false;
}
if (!getAdvanceAssignmentTemplates().isEmpty()) {
return false;
}
if (!getQualityForms().isEmpty()) {
return false;
}
if (!getLabels().isEmpty()) {
return false;
}
if (!getMaterialAssignments().isEmpty()) {
return false;
}
@ -144,10 +152,12 @@ public class OrderLineTemplate extends OrderElementTemplate {
@Override
public OrderElement createElement(OrderLineGroup parent) {
OrderLine line = setupSchedulingStateType(setupVersioningInfo(parent,
OrderLine.createOrderLineWithUnfixedPercentage(getWorkHours())));
OrderLine line = setupSchedulingStateType(
setupVersioningInfo(parent, OrderLine.createOrderLineWithUnfixedPercentage(getWorkHours())));
line.initializeTemplate(this);
parent.add(line);
return setupElementParts(line);
}
@ -161,7 +171,7 @@ public class OrderLineTemplate extends OrderElementTemplate {
}
public void incrementLastHoursGroupSequenceCode() {
if(lastHoursGroupSequenceCode==null){
if (lastHoursGroupSequenceCode == null) {
lastHoursGroupSequenceCode = 0;
}
lastHoursGroupSequenceCode++;
@ -178,7 +188,7 @@ public class OrderLineTemplate extends OrderElementTemplate {
@Override
public List<HoursGroup> getHoursGroups() {
return new ArrayList<HoursGroup>(hoursGroups);
return new ArrayList<>(hoursGroups);
}
public Set<HoursGroup> myHoursGroups() {
@ -206,9 +216,6 @@ public class OrderLineTemplate extends OrderElementTemplate {
recalculateHoursGroups();
}
private HoursGroupOrderLineTemplateHandler hoursGroupOrderLineTemplateHandler = HoursGroupOrderLineTemplateHandler
.getInstance();
public void setWorkHours(Integer workHours) throws IllegalArgumentException {
hoursGroupOrderLineTemplateHandler.setWorkHours(this, workHours);
}
@ -226,8 +233,7 @@ public class OrderLineTemplate extends OrderElementTemplate {
}
public void setBudget(BigDecimal budget) {
Validate.isTrue(budget.compareTo(BigDecimal.ZERO) >= 0,
"budget cannot be negative");
Validate.isTrue(budget.compareTo(BigDecimal.ZERO) >= 0, "budget cannot be negative");
this.budget = budget.setScale(2);
}

View file

@ -36,14 +36,15 @@ import org.libreplan.business.scenarios.entities.Scenario;
*/
public class OrderTemplate extends OrderLineGroupTemplate {
private BaseCalendar calendar;
public static OrderTemplate create(Order order) {
OrderTemplate beingBuilt = new OrderTemplate();
beingBuilt.calendar = order.getCalendar();
return create(beingBuilt, order);
}
private BaseCalendar calendar;
@Override
public OrderElement createElement(OrderLineGroup parent) {
throw new UnsupportedOperationException();
@ -51,11 +52,11 @@ public class OrderTemplate extends OrderLineGroupTemplate {
public Order createOrder(Scenario currentScenario) {
Order order = Order.create();
order.setVersionForScenario(currentScenario, OrderVersion
.createInitialVersion(currentScenario));
order.setVersionForScenario(currentScenario, OrderVersion.createInitialVersion(currentScenario));
order.useSchedulingDataFor(currentScenario);
order.setCalendar(calendar);
order.initializeTemplate(this);
return setupGroupParts(setupSchedulingStateType(order));
}

View file

@ -31,7 +31,7 @@ import static org.libreplan.business.users.entities.UserRole.*;
* Profiles}
*
* @author Manuel Rego Casasnovas <rego@igalia.com>
* @author Vova Perebykivskiy <vova@libreplan-enterprise.com>
* @author Vova Perebykivskyi <vova@libreplan-enterprise.com>
*/
public enum PredefinedProfiles {

Some files were not shown because too many files have changed in this diff Show more