diff --git a/ganttzk/src/test/java/org/zkoss/ganttz/timetracker/OnColumnsRowRendererTest.java b/ganttzk/src/test/java/org/zkoss/ganttz/timetracker/OnColumnsRowRendererTest.java
index 88b517bc5..4eb7b72fc 100644
--- a/ganttzk/src/test/java/org/zkoss/ganttz/timetracker/OnColumnsRowRendererTest.java
+++ b/ganttzk/src/test/java/org/zkoss/ganttz/timetracker/OnColumnsRowRendererTest.java
@@ -82,7 +82,7 @@ public class OnColumnsRowRendererTest {
private void givenDetailItems() {
detailItems = new ArrayList<>();
- start = new LocalDate(2010, 1, 1).toDateMidnight().toDateTime();
+ start = new LocalDate(2010, 1, 1).toDateTimeAtStartOfDay().toDateTime();
DateTime current = start;
Period period = Period.months(2);
diff --git a/libreplan-business/pom.xml b/libreplan-business/pom.xml
index 7ef6d1632..aebb910dc 100644
--- a/libreplan-business/pom.xml
+++ b/libreplan-business/pom.xml
@@ -137,6 +137,11 @@
org.liquibase
liquibase-maven-plugin
+
+ commons-lang
+ commons-lang
+ 2.5
+
diff --git a/libreplan-business/src/main/java/org/libreplan/business/planner/entities/DayAssignment.java b/libreplan-business/src/main/java/org/libreplan/business/planner/entities/DayAssignment.java
index 6309d99d9..d2daa5494 100644
--- a/libreplan-business/src/main/java/org/libreplan/business/planner/entities/DayAssignment.java
+++ b/libreplan-business/src/main/java/org/libreplan/business/planner/entities/DayAssignment.java
@@ -66,31 +66,28 @@ public abstract class DayAssignment extends BaseEntity {
public abstract boolean accepts(DayAssignment each);
}
- public static List filter(
- Collection extends DayAssignment> assignments,
- FilterType filter) {
+ public static List filter(Collection extends DayAssignment> assignments,
+ FilterType filter) {
if (filter == null || filter.equals(FilterType.KEEP_ALL)) {
- return new ArrayList(assignments);
+ return new ArrayList<>(assignments);
}
List result = new ArrayList();
for (DayAssignment each : assignments) {
- if (filter.accepts(each)) {
+ if ( filter.accepts(each) ) {
result.add(each);
}
}
return result;
}
- public static List getAtInterval(
- List orderedAssignments, LocalDate startInclusive,
- LocalDate endExclusive) {
+ public static List getAtInterval(List orderedAssignments, LocalDate startInclusive,
+ LocalDate endExclusive) {
int position = findFirstAfterOrEqual(orderedAssignments, startInclusive);
- List couldBeIncluded = orderedAssignments.subList(position, Math
- .max(
- orderedAssignments.size(), position));
- List result = new ArrayList();
+ List couldBeIncluded = orderedAssignments.subList(position,
+ Math.max(orderedAssignments.size(), position));
+ List result = new ArrayList<>();
for (T each : couldBeIncluded) {
- if (each.getDay().compareTo(endExclusive) >= 0) {
+ if ( each.getDay().compareTo(endExclusive) >= 0 ) {
break;
}
assert each.includedIn(startInclusive, endExclusive);
@@ -101,9 +98,9 @@ public abstract class DayAssignment extends BaseEntity {
public static List withConsolidatedValue(
Collection extends T> assignments, boolean consolidated) {
- List result = new ArrayList();
+ List result = new ArrayList<>();
for (T each : assignments) {
- if (each.isConsolidated() == consolidated) {
+ if ( each.isConsolidated() == consolidated ) {
result.add(each);
}
}
@@ -116,8 +113,7 @@ public abstract class DayAssignment extends BaseEntity {
int end = orderedAssignments.size() - 1;
while (start <= end) {
int middle = start + (end - start) / 2;
- if (orderedAssignments.get(middle).getDay().compareTo(
- startInclusive) < 0) {
+ if ( orderedAssignments.get(middle).getDay().compareTo(startInclusive) < 0 ) {
start = middle + 1;
} else {
end = middle - 1;
@@ -126,8 +122,7 @@ public abstract class DayAssignment extends BaseEntity {
return start;
}
- public static EffortDuration sum(
- Collection extends DayAssignment> assignments) {
+ public static EffortDuration sum(Collection extends DayAssignment> assignments) {
EffortDuration result = zero();
for (DayAssignment each : assignments) {
result = result.plus(each.getDuration());
@@ -144,8 +139,7 @@ public abstract class DayAssignment extends BaseEntity {
return result;
}
- public static Map> byResource(
- Collection extends T> assignments) {
+ public static Map> byResource(Collection extends T> assignments) {
Map> result = new HashMap>();
for (T assignment : assignments) {
Resource resource = assignment.getResource();
@@ -157,12 +151,11 @@ public abstract class DayAssignment extends BaseEntity {
return result;
}
- public static Map> byDay(
- Collection extends T> assignments) {
+ public static Map> byDay(Collection extends T> assignments) {
Map> result = new HashMap>();
for (T t : assignments) {
LocalDate day = t.getDay();
- if (!result.containsKey(day)) {
+ if ( !result.containsKey(day) ) {
result.put(day, new ArrayList());
}
result.get(day).add(t);
@@ -170,8 +163,7 @@ public abstract class DayAssignment extends BaseEntity {
return result;
}
- public static Set getAllResources(
- Collection extends DayAssignment> assignments) {
+ public static Set getAllResources(Collection extends DayAssignment> assignments) {
Set result = new HashSet();
for (DayAssignment dayAssignment : assignments) {
result.add(dayAssignment.getResource());
@@ -181,7 +173,7 @@ public abstract class DayAssignment extends BaseEntity {
public static List getOfType(Class klass,
Collection extends DayAssignment> dayAssignments) {
- List result = new ArrayList();
+ List result = new ArrayList<>();
for (DayAssignment each : dayAssignments) {
if (klass.isInstance(each)) {
result.add(klass.cast(each));
@@ -211,6 +203,7 @@ public abstract class DayAssignment extends BaseEntity {
return result;
}
+ @NotNull
private EffortDuration duration;
@NotNull
@@ -226,8 +219,7 @@ public abstract class DayAssignment extends BaseEntity {
}
- protected DayAssignment(LocalDate day, EffortDuration duration,
- Resource resource) {
+ protected DayAssignment(LocalDate day, EffortDuration duration, Resource resource) {
Validate.notNull(day);
Validate.notNull(duration);
Validate.notNull(resource);
@@ -236,15 +228,12 @@ public abstract class DayAssignment extends BaseEntity {
this.resource = resource;
}
- /**
- * @deprecated Use {@link #getDuration()}
- */
- @Deprecated
- public int getHours() {
+
+ /* public int getHours() {
return duration.getHours();
}
+ */
- @NotNull
public EffortDuration getDuration() {
return duration;
}
@@ -290,7 +279,7 @@ public abstract class DayAssignment extends BaseEntity {
public static List orderedByDay(
Collection dayAssignments) {
- List result = new ArrayList(dayAssignments);
+ List result = new ArrayList<>(dayAssignments);
Collections.sort(result, byDayComparator());
return result;
}
diff --git a/libreplan-business/src/main/java/org/libreplan/business/planner/entities/DerivedDayAssignment.java b/libreplan-business/src/main/java/org/libreplan/business/planner/entities/DerivedDayAssignment.java
index d35f81132..24ae2a526 100644
--- a/libreplan-business/src/main/java/org/libreplan/business/planner/entities/DerivedDayAssignment.java
+++ b/libreplan-business/src/main/java/org/libreplan/business/planner/entities/DerivedDayAssignment.java
@@ -20,8 +20,6 @@
*/
package org.libreplan.business.planner.entities;
-import static org.libreplan.business.workingday.EffortDuration.hours;
-
import org.apache.commons.lang.Validate;
import javax.validation.constraints.NotNull;
import org.joda.time.LocalDate;
@@ -40,18 +38,21 @@ import org.libreplan.business.workingday.EffortDuration;
*/
public class DerivedDayAssignment extends DayAssignment {
- @Deprecated
+/* @Deprecated
public static DerivedDayAssignment create(LocalDate day, int hours,
Resource resource, DerivedAllocation derivedAllocation) {
return create(new DerivedDayAssignment(day, hours(hours), resource,
derivedAllocation));
+ }*/
+
+ private static DerivedDayAssignment create(LocalDate day, EffortDuration hours, Resource resource,
+ DerivedDayAssignmentsContainer container) {
+ return create(new DerivedDayAssignment(day, hours, resource, container));
}
- public static DerivedDayAssignment create(LocalDate day,
- EffortDuration duration, Resource resource,
- DerivedAllocation derivedAllocation) {
- return create(new DerivedDayAssignment(day, duration, resource,
- derivedAllocation));
+ public static DerivedDayAssignment create(LocalDate day, EffortDuration duration, Resource resource,
+ DerivedAllocation derivedAllocation) {
+ return create(new DerivedDayAssignment(day, duration, resource, derivedAllocation));
}
/**
@@ -62,9 +63,10 @@ public class DerivedDayAssignment extends DayAssignment {
}
private abstract class ParentState {
- protected abstract DerivedAllocation getAllocation();
+ protected abstract DerivedAllocation getAllocation();
public abstract Scenario getScenario();
+
}
private class TransientParentState extends ParentState {
@@ -85,6 +87,7 @@ public class DerivedDayAssignment extends DayAssignment {
public Scenario getScenario() {
return null;
}
+
}
private class ContainerParentState extends ParentState {
@@ -96,11 +99,11 @@ public class DerivedDayAssignment extends DayAssignment {
protected DerivedAllocation getAllocation() {
return container.getResourceAllocation();
}
-
@Override
public Scenario getScenario() {
return container.getScenario();
}
+
}
private class DetachedState extends ParentState {
@@ -123,22 +126,19 @@ public class DerivedDayAssignment extends DayAssignment {
@OnCopy(Strategy.IGNORE)
private ParentState parentState;
- private DerivedDayAssignment(LocalDate day, EffortDuration hours,
- Resource resource) {
+ private DerivedDayAssignment(LocalDate day, EffortDuration hours, Resource resource) {
super(day, hours, resource);
Validate.isTrue(resource instanceof Worker);
}
- private DerivedDayAssignment(LocalDate day, EffortDuration hours,
- Resource resource,
- DerivedAllocation derivedAllocation) {
+ private DerivedDayAssignment(LocalDate day, EffortDuration hours, Resource resource,
+ DerivedAllocation derivedAllocation) {
this(day, hours, resource);
this.parentState = new TransientParentState(derivedAllocation);
}
- private DerivedDayAssignment(LocalDate day, EffortDuration hours,
- Resource resource,
- DerivedDayAssignmentsContainer container) {
+ private DerivedDayAssignment(LocalDate day, EffortDuration hours, Resource resource,
+ DerivedDayAssignmentsContainer container) {
this(day, hours, resource);
Validate.notNull(container);
this.container = container;
@@ -150,19 +150,11 @@ public class DerivedDayAssignment extends DayAssignment {
}
DerivedDayAssignment copyAsChildOf(DerivedDayAssignmentsContainer container) {
- return create(this.getDay(), this.getHours(), this.getResource(),
- container);
- }
-
- private static DerivedDayAssignment create(LocalDate day, int hours,
- Resource resource, DerivedDayAssignmentsContainer container) {
- return create(new DerivedDayAssignment(day,
- EffortDuration.hours(hours), resource, container));
+ return create(this.getDay(), this.getDuration(), this.getResource(), container);
}
DerivedDayAssignment copyAsChildOf(DerivedAllocation derivedAllocation) {
- return create(this.getDay(), this.getHours(), this.getResource(),
- derivedAllocation);
+ return create(this.getDay(), this.getDuration(), this.getResource(), derivedAllocation);
}
@Override
diff --git a/libreplan-business/src/main/java/org/libreplan/business/planner/entities/HoursCostCalculator.java b/libreplan-business/src/main/java/org/libreplan/business/planner/entities/HoursCostCalculator.java
index 4eef089a3..ab3720d80 100644
--- a/libreplan-business/src/main/java/org/libreplan/business/planner/entities/HoursCostCalculator.java
+++ b/libreplan-business/src/main/java/org/libreplan/business/planner/entities/HoursCostCalculator.java
@@ -34,6 +34,7 @@ import java.util.TreeMap;
import java.util.Date;
import org.joda.time.LocalDate;
+import org.joda.time.LocalTime;
import org.libreplan.business.advance.entities.AdvanceMeasurement;
import org.libreplan.business.advance.entities.DirectAdvanceAssignment;
import org.libreplan.business.planner.entities.DayAssignment.FilterType;
@@ -69,7 +70,7 @@ public class HoursCostCalculator implements ICostCalculator {
(task.getOrderElement() != null) ? task.getOrderElement().getReportGlobalAdvanceAssignment() : null;
if ( advanceAssignment == null ) {
- return new TreeMap();
+ return new TreeMap<>();
}
return calculateHoursPerDay(
@@ -110,10 +111,9 @@ public class HoursCostCalculator implements ICostCalculator {
* MAX(BCWS) equals addition of all dayAssignments.
*/
@Override
- public SortedMap getEstimatedCost(
- Task task,
- LocalDate filterStartDate,
- LocalDate filterEndDate) {
+ public SortedMap getEstimatedCost(Task task,
+ LocalDate filterStartDate,
+ LocalDate filterEndDate) {
if ( task.isSubcontracted() ) {
return getAdvanceCost(task);
@@ -130,30 +130,33 @@ public class HoursCostCalculator implements ICostCalculator {
for (DayAssignment dayAssignment : dayAssignments) {
LocalDate day = dayAssignment.getDay();
- if( ( (filterStartDate == null) || day.compareTo(filterStartDate) >= 0) &&
- ( (filterEndDate == null) || day.compareTo(filterEndDate) <= 0) ) {
+ if( ((filterStartDate == null) || day.compareTo(filterStartDate) >= 0) &&
+ ((filterEndDate == null) || day.compareTo(filterEndDate) <= 0) ) {
String currentTime = dayAssignment.getDuration().toFormattedString();
-
SimpleDateFormat format1 = new SimpleDateFormat("hh:mm");
SimpleDateFormat format2 = new SimpleDateFormat("hh");
Date date = null;
try {
- if ( isParsableWithFormat1(currentTime) )
+ if ( isParsableWithFormat1(currentTime) ) {
date = format1.parse(currentTime);
- else if ( isParsableWithFormat2(currentTime) )
+ } else if ( isParsableWithFormat2(currentTime) ) {
date = format2.parse(currentTime);
+ }
} catch (ParseException e) {
e.printStackTrace();
}
- Time time = new Time(date.getTime());
+ assert date != null;
- BigDecimal hours = new BigDecimal(time.getHours());
- additionOfAllAssignmentsMinutes += time.getMinutes();
+ LocalTime time = new LocalTime(date.getTime());
+ // Time time = new Time(date.getTime());
+
+ BigDecimal hours = new BigDecimal(time.getHourOfDay());
+ additionOfAllAssignmentsMinutes += time.getMinuteOfHour();
if ( !result.containsKey(day) ) {
result.put(day, BigDecimal.ZERO);
diff --git a/libreplan-business/src/main/java/org/libreplan/business/planner/entities/TaskElement.java b/libreplan-business/src/main/java/org/libreplan/business/planner/entities/TaskElement.java
index a30accd21..6dc146a05 100644
--- a/libreplan-business/src/main/java/org/libreplan/business/planner/entities/TaskElement.java
+++ b/libreplan-business/src/main/java/org/libreplan/business/planner/entities/TaskElement.java
@@ -71,27 +71,27 @@ public abstract class TaskElement extends BaseEntity {
private static final Log LOG = LogFactory.getLog(TaskElement.class);
public static List justTasks(Collection extends TaskElement> tasks) {
- List result = new ArrayList();
+ List result = new ArrayList<>();
for (TaskElement taskElement : tasks) {
- if (taskElement instanceof Task) {
+ if ( taskElement instanceof Task ) {
result.add((Task) taskElement);
}
}
+
return result;
}
public interface IDatesInterceptor {
- public void setStartDate(IntraDayDate previousStart,
+ void setStartDate(IntraDayDate previousStart,
IntraDayDate previousEnd, IntraDayDate newStart);
- public void setNewEnd(IntraDayDate previousEnd, IntraDayDate newEnd);
+ void setNewEnd(IntraDayDate previousEnd, IntraDayDate newEnd);
}
private static final IDatesInterceptor EMPTY_INTERCEPTOR = new IDatesInterceptor() {
@Override
- public void setStartDate(IntraDayDate previousStart,
- IntraDayDate previousEnd, IntraDayDate newStart) {
+ public void setStartDate(IntraDayDate previousStart, IntraDayDate previousEnd, IntraDayDate newStart) {
}
@Override
@@ -108,6 +108,7 @@ public abstract class TaskElement extends BaseEntity {
return o1.getStartDate().compareTo(o2.getStartDate());
}
};
+
return result;
}
@@ -128,10 +129,10 @@ public abstract class TaskElement extends BaseEntity {
*/
@SuppressWarnings("unchecked")
public LocalDate getBiggestAmongEndOrDeadline() {
- if (this.getDeadline() != null) {
- return Collections.max(asList(this.getDeadline(),
- this.getEndAsLocalDate()));
+ if ( this.getDeadline() != null ) {
+ return Collections.max(asList(this.getDeadline(), this.getEndAsLocalDate()));
}
+
return this.getEndAsLocalDate();
}
@@ -149,8 +150,7 @@ public abstract class TaskElement extends BaseEntity {
return create(taskElement);
}
- protected static T createWithoutTaskSource(
- T taskElement) {
+ protected static T createWithoutTaskSource(T taskElement) {
return create(taskElement);
}
@@ -185,7 +185,7 @@ public abstract class TaskElement extends BaseEntity {
private Boolean updatedFromTimesheets = false;
public void initializeDatesIfNeeded() {
- if (getIntraDayEndDate() == null || getIntraDayStartDate() == null) {
+ if ( getIntraDayEndDate() == null || getIntraDayStartDate() == null ) {
initializeDates();
}
}
@@ -203,9 +203,10 @@ public abstract class TaskElement extends BaseEntity {
}
public Integer getWorkHours() {
- if (taskSource == null) {
+ if ( taskSource == null ) {
return 0;
}
+
return taskSource.getTotalHours();
}
@@ -236,7 +237,7 @@ public abstract class TaskElement extends BaseEntity {
}
protected void copyParenTo(TaskElement result) {
- if (this.getParent() != null) {
+ if ( this.getParent() != null ) {
this.getParent().addTaskElement(result);
}
}
@@ -259,7 +260,7 @@ public abstract class TaskElement extends BaseEntity {
public void setName(String name) {
this.name = name;
- if (taskSource != null && taskSource.getOrderElement() != null) {
+ if ( taskSource != null && taskSource.getOrderElement() != null ) {
taskSource.getOrderElement().setName(name);
}
}
@@ -273,9 +274,10 @@ public abstract class TaskElement extends BaseEntity {
}
public OrderElement getOrderElement() {
- if (getTaskSource() == null) {
+ if ( getTaskSource() == null ) {
return null;
}
+
return getTaskSource().getOrderElement();
}
@@ -288,18 +290,16 @@ public abstract class TaskElement extends BaseEntity {
}
public Set getDependenciesWithThisDestinationAndAllParents() {
- Set result = new HashSet(
- getDependenciesWithThisDestination());
- if (parent != null) {
- result.addAll(parent
- .getDependenciesWithThisDestinationAndAllParents());
+ Set result = new HashSet(getDependenciesWithThisDestination());
+ if ( parent != null ) {
+ result.addAll(parent.getDependenciesWithThisDestinationAndAllParents());
}
+
return result;
}
public Date getStartDate() {
- return startDate != null ? startDate.getDate().toDateTimeAtStartOfDay()
- .toDate() : null;
+ return startDate != null ? startDate.getDate().toDateTimeAtStartOfDay().toDate() : null;
}
@NotNull
@@ -419,26 +419,25 @@ public abstract class TaskElement extends BaseEntity {
public void setDeadline(LocalDate deadline) {
this.deadline = deadline;
- if (taskSource != null && taskSource.getOrderElement() != null) {
+ if ( taskSource != null && taskSource.getOrderElement() != null ) {
taskSource.getOrderElement().setDeadline(
- (deadline == null)? null : deadline.toDateMidnight().toDate());
+ (deadline == null)? null : deadline.toDateTimeAtStartOfDay().toDate());
}
}
public void add(Dependency dependency) {
- if (this.equals(dependency.getOrigin())) {
+ if ( this.equals(dependency.getOrigin()) ) {
dependenciesWithThisOrigin.add(dependency);
}
- if (this.equals(dependency.getDestination())) {
+ if ( this.equals(dependency.getDestination()) ) {
dependenciesWithThisDestination.add(dependency);
}
}
private void removeDependenciesWithThisOrigin(TaskElement origin, Type type) {
- ArrayList toBeRemoved = new ArrayList();
+ ArrayList toBeRemoved = new ArrayList<>();
for (Dependency dependency : dependenciesWithThisDestination) {
- if (dependency.getOrigin().equals(origin)
- && dependency.getType().equals(type)) {
+ if ( dependency.getOrigin().equals(origin) && dependency.getType().equals(type) ) {
toBeRemoved.add(dependency);
}
}
@@ -448,8 +447,7 @@ public abstract class TaskElement extends BaseEntity {
public void removeDependencyWithDestination(TaskElement destination, Type type) {
ArrayList toBeRemoved = new ArrayList();
for (Dependency dependency : dependenciesWithThisOrigin) {
- if (dependency.getDestination().equals(destination)
- && dependency.getType().equals(type)) {
+ if ( dependency.getDestination().equals(destination) && dependency.getType().equals(type) ) {
toBeRemoved.add(dependency);
}
}
@@ -471,7 +469,7 @@ public abstract class TaskElement extends BaseEntity {
}
public void detachFromParent() {
- if (parent != null) {
+ if ( parent != null ) {
parent.remove(this);
}
}
@@ -487,22 +485,23 @@ public abstract class TaskElement extends BaseEntity {
}
private List getDependenciesWithDestination(TaskElement t) {
- ArrayList result = new ArrayList();
+ ArrayList result = new ArrayList<>();
for (Dependency dependency : dependenciesWithThisOrigin) {
- if (dependency.getDestination().equals(t)) {
+ if ( dependency.getDestination().equals(t) ) {
result.add(dependency);
}
}
+
return result;
}
private List getDependenciesWithOrigin(TaskElement t) {
- ArrayList result = new ArrayList();
+ ArrayList result = new ArrayList<>();
for (Dependency dependency : dependenciesWithThisDestination) {
- if (dependency.getOrigin().equals(t)) {
- result.add(dependency);
+ if ( dependency.getOrigin().equals(t) ) {result.add(dependency);
}
}
+
return result;
}
@@ -515,7 +514,7 @@ public abstract class TaskElement extends BaseEntity {
Set tasksToNotify = new HashSet();
for (Dependency dependency : dependenciesWithThisDestination) {
TaskElement origin = dependency.getOrigin();
- if (origin != null) {
+ if ( origin != null ) {
tasksToNotify.add(origin);
}
}
@@ -529,7 +528,7 @@ public abstract class TaskElement extends BaseEntity {
Set tasksToNotify = new HashSet();
for (Dependency dependency : dependenciesWithThisOrigin) {
TaskElement destination = dependency.getDestination();
- if (destination != null) {
+ if ( destination != null ) {
tasksToNotify.add(destination);
}
}
@@ -548,11 +547,11 @@ public abstract class TaskElement extends BaseEntity {
}
public BaseCalendar getCalendar() {
- if (calendar == null) {
+ if ( calendar == null ) {
OrderElement orderElement = getOrderElement();
- return orderElement != null ? orderElement.getOrder().getCalendar()
- : null;
+ return orderElement != null ? orderElement.getOrder().getCalendar() : null;
}
+
return calendar;
}
@@ -561,13 +560,13 @@ public abstract class TaskElement extends BaseEntity {
public abstract Set> getAllResourceAllocations();
public SortedMap getDurationsAssignedByDay() {
- SortedMap result = new TreeMap();
+ SortedMap result = new TreeMap<>();
for (ResourceAllocation> resourceAllocation : getSatisfiedResourceAllocations()) {
- for (DayAssignment each : resourceAllocation
- .getAssignments()) {
+ for (DayAssignment each : resourceAllocation.getAssignments()) {
addToResult(result, each.getDay(), each.getDuration());
}
}
+
return result;
}
@@ -577,7 +576,7 @@ public abstract class TaskElement extends BaseEntity {
}
public List getDayAssignments(DayAssignment.FilterType filter) {
- List dayAssignments = new ArrayList();
+ List dayAssignments = new ArrayList<>();
Set> resourceAllocations = getSatisfiedResourceAllocations();
for (ResourceAllocation> resourceAllocation : resourceAllocations) {
@@ -623,6 +622,7 @@ public abstract class TaskElement extends BaseEntity {
while (result.getParent() != null) {
result = result.getParent();
}
+
return result;
}
@@ -641,30 +641,33 @@ public abstract class TaskElement extends BaseEntity {
//simplified calculation has only two states:
//unassigned, when hours allocated is zero, and
//assigned otherwise
- if (getSumOfAssignedEffort().isZero()) {
+ if ( getSumOfAssignedEffort().isZero() ) {
return "unassigned";
}
+
return "assigned";
}
Set> resourceAllocations = getSatisfiedResourceAllocations();
- if (resourceAllocations.isEmpty()) {
+ if ( resourceAllocations.isEmpty() ) {
return "unassigned";
}
for (ResourceAllocation> resourceAllocation : resourceAllocations) {
final ResourcesPerDay resourcesPerDay = resourceAllocation.getResourcesPerDay();
- if (resourcesPerDay != null && resourcesPerDay.isZero()) {
+ if ( resourcesPerDay != null && resourcesPerDay.isZero() ) {
return "partially-assigned";
}
}
+
return "assigned";
}
public Boolean belongsClosedProject() {
EnumSet CLOSED = EnumSet.of(OrderStatusEnum.CANCELLED,
- OrderStatusEnum.FINISHED, OrderStatusEnum.STORED);
+ OrderStatusEnum.FINISHED,
+ OrderStatusEnum.STORED);
Order order = getOrderElement().getOrder();
- if(CLOSED.contains(order.getState())) {
+ if( CLOSED.contains(order.getState()) ) {
return true;
}
@@ -686,8 +689,7 @@ public abstract class TaskElement extends BaseEntity {
}
public BigDecimal getAdvancePercentage() {
- return (advancePercentage == null) ? BigDecimal.ZERO
- : advancePercentage;
+ return (advancePercentage == null) ? BigDecimal.ZERO : advancePercentage;
}
/**
@@ -697,10 +699,10 @@ public abstract class TaskElement extends BaseEntity {
* depending on parameter
*/
public BigDecimal getAdvancePercentage(ProgressType progressType) {
- if (progressType != null
- && progressType.equals(ProgressType.SPREAD_PROGRESS)) {
+ if ( progressType != null && progressType.equals(ProgressType.SPREAD_PROGRESS) ) {
return advancePercentage;
}
+
return BigDecimal.ZERO;
}
@@ -716,7 +718,7 @@ public abstract class TaskElement extends BaseEntity {
}
public EffortDuration getSumOfAssignedEffort() {
- if (this.getParent() == null) {
+ if ( this.getParent() == null ) {
//it's an order, we use the cached value
return sumOfAssignedEffort;
}
@@ -746,6 +748,7 @@ public abstract class TaskElement extends BaseEntity {
result.add(child);
result.addAll(child.getAllChildren());
}
+
return result;
}
@@ -753,12 +756,13 @@ public abstract class TaskElement extends BaseEntity {
public BigDecimal getTheoreticalAdvancePercentageUntilDate(Date date) {
EffortDuration totalAllocatedTime = AggregateOfDayAssignments.create(
- this.getDayAssignments(FilterType.KEEP_ALL)).getTotalTime();
+ this.getDayAssignments(FilterType.KEEP_ALL)).getTotalTime();
EffortDuration totalTheoreticalCompletedTime = this.getTheoreticalCompletedTimeUntilDate(date);
- if (totalAllocatedTime.isZero() || totalTheoreticalCompletedTime.isZero()) {
+ if ( totalAllocatedTime.isZero() || totalTheoreticalCompletedTime.isZero() ) {
return BigDecimal.ZERO;
}
Validate.isTrue(totalTheoreticalCompletedTime.getSeconds() <= totalAllocatedTime.getSeconds());
+
return totalTheoreticalCompletedTime.dividedByAndResultAsBigDecimal(totalAllocatedTime);
}
@@ -779,16 +783,18 @@ public abstract class TaskElement extends BaseEntity {
}
public BigDecimal getBudget() {
- if ((taskSource != null) && (taskSource.getOrderElement() != null)) {
+ if ( (taskSource != null) && (taskSource.getOrderElement() != null) ) {
return taskSource.getOrderElement().getBudget();
}
+
return null;
}
public BigDecimal getResourcesBudget() {
- if ((taskSource != null) && (taskSource.getOrderElement() != null)) {
+ if ( (taskSource != null) && (taskSource.getOrderElement() != null) ) {
return taskSource.getOrderElement().getResourcesBudget();
}
+
return null;
}
@@ -800,52 +806,53 @@ public abstract class TaskElement extends BaseEntity {
public TaskDeadlineViolationStatusEnum getDeadlineViolationStatus() {
LocalDate deadline = this.getDeadline();
- if (deadline == null) {
+ if ( deadline == null ) {
return TaskDeadlineViolationStatusEnum.NO_DEADLINE;
- } else if (this.getEndAsLocalDate().isAfter(deadline)) {
+ } else if ( this.getEndAsLocalDate().isAfter(deadline) ) {
return TaskDeadlineViolationStatusEnum.DEADLINE_VIOLATED;
} else {
return TaskDeadlineViolationStatusEnum.ON_SCHEDULE;
}
}
- public static IntraDayDate maxDate(
- Collection extends TaskElement> tasksToSave) {
+ public static IntraDayDate maxDate(Collection extends TaskElement> tasksToSave) {
List endDates = toEndDates(tasksToSave);
+
return endDates.isEmpty() ? null : Collections.max(endDates);
}
- private static List toEndDates(
- Collection extends TaskElement> tasksToSave) {
- List result = new ArrayList();
+ private static List toEndDates(Collection extends TaskElement> tasksToSave) {
+ List result = new ArrayList<>();
+
for (TaskElement taskElement : tasksToSave) {
IntraDayDate endDate = taskElement.getIntraDayEndDate();
- if (endDate != null) {
+ if ( endDate != null ) {
result.add(endDate);
} else {
LOG.warn("the task" + taskElement + " has null end date");
}
}
+
return result;
}
- public static IntraDayDate minDate(
- Collection extends TaskElement> tasksToSave) {
+ public static IntraDayDate minDate(Collection extends TaskElement> tasksToSave) {
List startDates = toStartDates(tasksToSave);
+
return startDates.isEmpty() ? null : Collections.min(startDates);
}
- private static List toStartDates(
- Collection extends TaskElement> tasksToSave) {
- List result = new ArrayList();
+ private static List toStartDates(Collection extends TaskElement> tasksToSave) {
+ List result = new ArrayList<>();
for (TaskElement taskElement : tasksToSave) {
IntraDayDate startDate = taskElement.getIntraDayStartDate();
- if (startDate != null) {
+ if ( startDate != null ) {
result.add(startDate);
} else {
LOG.warn("the task" + taskElement + " has null start date");
}
}
+
return result;
}
diff --git a/libreplan-business/src/main/java/org/libreplan/business/planner/limiting/entities/LimitingResourceAllocator.java b/libreplan-business/src/main/java/org/libreplan/business/planner/limiting/entities/LimitingResourceAllocator.java
index 8fade0997..db31e3976 100644
--- a/libreplan-business/src/main/java/org/libreplan/business/planner/limiting/entities/LimitingResourceAllocator.java
+++ b/libreplan-business/src/main/java/org/libreplan/business/planner/limiting/entities/LimitingResourceAllocator.java
@@ -73,8 +73,7 @@ public class LimitingResourceAllocator {
@Override
protected boolean hasNext(boolean currentDateIsLessThanEnd) {
- return currentDateIsLessThanEnd
- || currentDuration.compareTo(goal) <= 0;
+ return currentDateIsLessThanEnd || currentDuration.compareTo(goal) <= 0;
}
public void setCurrent(EffortDuration currentDuration) {
@@ -88,8 +87,7 @@ public class LimitingResourceAllocator {
}
- private final static ResourcesPerDay ONE_RESOURCE_PER_DAY = ResourcesPerDay
- .amount(new BigDecimal(1));
+ private final static ResourcesPerDay ONE_RESOURCE_PER_DAY = ResourcesPerDay.amount(new BigDecimal(1));
/**
* Returns first valid gap in queue for element
@@ -103,12 +101,10 @@ public class LimitingResourceAllocator {
* @param element element to fit into queue
* @return
*/
- public static Gap getFirstValidGap(
- LimitingResourceQueue queue, LimitingResourceQueueElement element) {
+ public static Gap getFirstValidGap(LimitingResourceQueue queue, LimitingResourceQueueElement element) {
final Resource resource = queue.getResource();
- final List elements = new LinkedList(
- queue.getLimitingResourceQueueElements());
+ final List elements = new LinkedList<>(queue.getLimitingResourceQueueElements());
final int size = elements.size();
final DateAndHour startTime = getStartTimeBecauseOfGantt(element);
@@ -119,10 +115,11 @@ public class LimitingResourceAllocator {
Gap gap = getGapInQueueAtPosition(
resource, elements, startTime, pos++);
- if (gap != null) {
- List subgaps = getFittingSubgaps(
- element, gap, resource);
- if (!subgaps.isEmpty()) {
+ if ( gap != null ) {
+
+ List subgaps = getFittingSubgaps(element, gap, resource);
+
+ if ( !subgaps.isEmpty() ) {
return subgaps.get(0);
}
}
@@ -133,42 +130,42 @@ public class LimitingResourceAllocator {
return null;
}
- private static List getFittingSubgaps(
- LimitingResourceQueueElement element,
- final Gap gap, final Resource resource) {
+ private static List getFittingSubgaps(LimitingResourceQueueElement element,
+ final Gap gap,
+ final Resource resource) {
- List result = new ArrayList();
+ List result = new ArrayList<>();
- if (isSpecific(element) && gap.canFit(element)) {
+ if ( isSpecific(element) && gap.canFit(element) ) {
result.add(gap);
- } else if (isGeneric(element)) {
- final List gaps = gap.splitIntoGapsSatisfyingCriteria(
- resource, element.getCriteria());
+ } else if ( isGeneric(element) ) {
+ final List gaps = gap.splitIntoGapsSatisfyingCriteria(resource, element.getCriteria());
for (Gap subgap : gaps) {
- if (subgap.canFit(element)) {
+
+ if ( subgap.canFit(element) ) {
result.add(subgap);
}
}
}
+
return result;
}
- public static Gap getFirstValidGapSince(
- LimitingResourceQueueElement element, LimitingResourceQueue queue,
- DateAndHour since) {
+ public static Gap getFirstValidGapSince(LimitingResourceQueueElement element,
+ LimitingResourceQueue queue,
+ DateAndHour since) {
List gaps = getValidGapsForElementSince(element, queue, since);
return (!gaps.isEmpty()) ? gaps.get(0) : null;
}
- public static List getValidGapsForElementSince(
- LimitingResourceQueueElement element, LimitingResourceQueue queue,
- DateAndHour since) {
+ public static List getValidGapsForElementSince(LimitingResourceQueueElement element,
+ LimitingResourceQueue queue,
+ DateAndHour since) {
- List result = new ArrayList();
+ List result = new ArrayList<>();
final Resource resource = queue.getResource();
- final List elements = new LinkedList(
- queue.getLimitingResourceQueueElements());
+ final List elements = new LinkedList<>(queue.getLimitingResourceQueueElements());
final int size = elements.size();
int pos = moveUntil(elements, since);
@@ -180,9 +177,8 @@ public class LimitingResourceAllocator {
// The queue cannot hold this element (queue.resource
// doesn't meet element.criteria)
- if (gap != null) {
- List subgaps = getFittingSubgaps(
- element, gap, resource);
+ if ( gap != null ) {
+ List subgaps = getFittingSubgaps(element, gap, resource);
result.addAll(subgaps);
}
}
@@ -193,7 +189,7 @@ public class LimitingResourceAllocator {
private static int moveUntil(List elements, DateAndHour until) {
int pos = 0;
- if (elements.size() > 0) {
+ if ( elements.size() > 0 ) {
// Space between until and first element start time
LimitingResourceQueueElement first = elements.get(0);
if (until.isBefore(first.getStartTime())) {
@@ -203,7 +199,8 @@ public class LimitingResourceAllocator {
for (pos = 1; pos < elements.size(); pos++) {
final LimitingResourceQueueElement each = elements.get(pos);
final DateAndHour startTime = each.getStartTime();
- if (until.isBefore(startTime) || until.isEquals(startTime)) {
+
+ if ( until.isBefore(startTime) || until.isEquals(startTime) ) {
return pos;
}
}
@@ -221,46 +218,45 @@ public class LimitingResourceAllocator {
public static DateAndHour getFirstElementTime(List dayAssignments) {
final DayAssignment start = dayAssignments.get(0);
- return new DateAndHour(start.getDay(), start.getHours());
+ return new DateAndHour(start.getDay(), start.getDuration().getHours());
}
public static DateAndHour getLastElementTime(List dayAssignments) {
final DayAssignment end = dayAssignments.get(dayAssignments.size() - 1);
- return new DateAndHour(end.getDay(), end.getHours());
+ return new DateAndHour(end.getDay(), end.getDuration().getHours());
}
- private static Gap getGapInQueueAtPosition(
- Resource resource, List elements,
- DateAndHour startTimeBecauseOfGantt, int pos) {
+ private static Gap getGapInQueueAtPosition(Resource resource,
+ List elements,
+ DateAndHour startTimeBecauseOfGantt,
+ int pos) {
final int size = elements.size();
// No elements in queue
- if (size == 0) {
+ if ( size == 0 ) {
return createLastGap(startTimeBecauseOfGantt, null, resource);
}
// Last element
- if (pos == size) {
+ if ( pos == size ) {
return createLastGap(startTimeBecauseOfGantt, elements.get(size - 1), resource);
}
LimitingResourceQueueElement next = elements.get(pos);
// First element
- if (pos == 0
- && startTimeBecauseOfGantt.getDate().isBefore(
- next.getStartDate())) {
- return Gap.create(resource,
- startTimeBecauseOfGantt, next.getStartTime());
+ if ( pos == 0 && startTimeBecauseOfGantt.getDate().isBefore(next.getStartDate()) ) {
+ return Gap.create(resource, startTimeBecauseOfGantt, next.getStartTime());
}
// In the middle of two elements
if (pos > 0) {
LimitingResourceQueueElement previous = elements.get(pos - 1);
- return Gap.create(resource, DateAndHour
- .max(previous.getEndTime(), startTimeBecauseOfGantt), next
- .getStartTime());
+ return Gap.create(resource,
+ DateAndHour.max(previous.getEndTime(),
+ startTimeBecauseOfGantt),
+ next.getStartTime());
}
return null;
@@ -270,15 +266,14 @@ public class LimitingResourceAllocator {
return new DateAndHour(new LocalDate(element.getEarliestStartDateBecauseOfGantt()), 0);
}
- private static Gap createLastGap(
- DateAndHour _startTime, LimitingResourceQueueElement lastElement,
- Resource resource) {
+ private static Gap createLastGap(DateAndHour _startTime,
+ LimitingResourceQueueElement lastElement,
+ Resource resource) {
- final DateAndHour queueEndTime = (lastElement != null) ? lastElement
- .getEndTime() : null;
+ final DateAndHour queueEndTime = (lastElement != null) ? lastElement.getEndTime() : null;
DateAndHour startTime = DateAndHour.max(_startTime, queueEndTime);
- return Gap
- .create(resource, startTime, null);
+
+ return Gap.create(resource, startTime, null);
}
/**
@@ -295,44 +290,38 @@ public class LimitingResourceAllocator {
* @param startTime
* @return
*/
- public static List generateDayAssignments(
- ResourceAllocation> resourceAllocation,
- Resource resource,
- DateAndHour startTime, DateAndHour endsAfter) {
+ public static List generateDayAssignments(ResourceAllocation> resourceAllocation,
+ Resource resource,
+ DateAndHour startTime,
+ DateAndHour endsAfter) {
- List assignments = new LinkedList();
+ List assignments = new LinkedList<>();
ResourceCalendar calendar = resource.getCalendar();
- final EffortDuration totalEffort = hours(resourceAllocation
- .getIntendedTotalHours());
+ final EffortDuration totalEffort = hours(resourceAllocation.getIntendedTotalHours());
EffortDuration effortAssigned = zero();
- UntilEndAndEffort condition = new UntilEndAndEffort(
- endsAfter.toIntraDayDate(), totalEffort);
+ UntilEndAndEffort condition = new UntilEndAndEffort(endsAfter.toIntraDayDate(), totalEffort);
for (PartialDay each : startTime.toIntraDayDate().daysUntil(condition)) {
- EffortDuration effortForDay = EffortDuration.min(
- calendar.asDurationOn(each,
- ONE_RESOURCE_PER_DAY), totalEffort);
- DayAssignment dayAssignment = createDayAssignment(
- resourceAllocation, resource, each.getDate(), effortForDay);
- effortAssigned = effortAssigned.plus(addDayAssignment(assignments,
- dayAssignment));
+ EffortDuration effortForDay = EffortDuration.min(calendar.asDurationOn(each, ONE_RESOURCE_PER_DAY),
+ totalEffort);
+ DayAssignment dayAssignment = createDayAssignment(resourceAllocation, resource, each.getDate(),
+ effortForDay);
+ effortAssigned = effortAssigned.plus(addDayAssignment(assignments, dayAssignment));
condition.setCurrent(effortAssigned);
}
- if (effortAssigned.compareTo(totalEffort) > 0) {
- stripStartAssignments(assignments,
- effortAssigned.minus(totalEffort));
+ if ( effortAssigned.compareTo(totalEffort) > 0 ) {
+ stripStartAssignments(assignments, effortAssigned.minus(totalEffort));
}
- return new ArrayList(assignments);
+ return new ArrayList<>(assignments);
}
- private static void stripStartAssignments(List assignments,
- EffortDuration durationSurplus) {
+ private static void stripStartAssignments(List assignments, EffortDuration durationSurplus) {
ListIterator listIterator = assignments.listIterator();
+
while (listIterator.hasNext() && durationSurplus.compareTo(zero()) > 0) {
DayAssignment current = listIterator.next();
- EffortDuration durationTaken = min(durationSurplus,
- current.getDuration());
+ EffortDuration durationTaken = min(durationSurplus, current.getDuration());
durationSurplus = durationSurplus.minus(durationTaken);
- if (durationTaken.compareTo(current.getDuration()) == 0) {
+ if ( durationTaken.compareTo(current.getDuration()) == 0 ) {
listIterator.remove();
} else {
listIterator.set(current.withDuration(durationTaken));
@@ -341,72 +330,70 @@ public class LimitingResourceAllocator {
}
private static List generateDayAssignmentsStartingFromEnd(ResourceAllocation> resourceAllocation,
- Resource resource,
- DateAndHour endTime) {
+ Resource resource,
+ DateAndHour endTime) {
ResourceCalendar calendar = resource.getCalendar();
- List result = new ArrayList();
+ List result = new ArrayList<>();
LocalDate date = endTime.getDate();
- EffortDuration totalIntended = hours(resourceAllocation
- .getIntendedTotalHours());
+ EffortDuration totalIntended = hours(resourceAllocation.getIntendedTotalHours());
// Generate last day assignment
PartialDay firstDay = new PartialDay(IntraDayDate.startOfDay(date),
- IntraDayDate.create(date, hours(endTime.getHour())));
- EffortDuration effortCanAllocate = min(totalIntended,
- calendar.asDurationOn(firstDay, ONE_RESOURCE_PER_DAY));
+ IntraDayDate.create(date, hours(endTime.getHour())));
+
+ EffortDuration effortCanAllocate = min(totalIntended, calendar.asDurationOn(firstDay, ONE_RESOURCE_PER_DAY));
+
if (effortCanAllocate.compareTo(zero()) > 0) {
- DayAssignment dayAssignment = createDayAssignment(
- resourceAllocation, resource, date, effortCanAllocate);
- totalIntended = totalIntended.minus(addDayAssignment(result,
- dayAssignment));
+ DayAssignment dayAssignment = createDayAssignment(resourceAllocation, resource, date, effortCanAllocate);
+ totalIntended = totalIntended.minus(addDayAssignment(result, dayAssignment));
}
// Generate rest of day assignments
- for (date = date.minusDays(1); totalIntended.compareTo(zero()) > 0; date = date
- .minusDays(1)) {
- EffortDuration duration = min(totalIntended, calendar.asDurationOn(
- PartialDay.wholeDay(date), ONE_RESOURCE_PER_DAY));
- DayAssignment dayAssigment = createDayAssignment(
- resourceAllocation, resource, date, duration);
- totalIntended = totalIntended.minus(addDayAssignment(result,
- dayAssigment));
+ for (date = date.minusDays(1); totalIntended.compareTo(zero()) > 0; date = date.minusDays(1)) {
+ EffortDuration duration = min(totalIntended,
+ calendar.asDurationOn(PartialDay.wholeDay(date),
+ ONE_RESOURCE_PER_DAY));
+
+ DayAssignment dayAssigment = createDayAssignment(resourceAllocation, resource, date, duration);
+ totalIntended = totalIntended.minus(addDayAssignment(result, dayAssigment));
}
+
return result;
}
- private static DayAssignment createDayAssignment(
- ResourceAllocation> resourceAllocation, Resource resource,
- LocalDate date, EffortDuration toAllocate) {
- if (resourceAllocation instanceof SpecificResourceAllocation) {
+ private static DayAssignment createDayAssignment(ResourceAllocation> resourceAllocation,
+ Resource resource,
+ LocalDate date,
+ EffortDuration toAllocate) {
+ if ( resourceAllocation instanceof SpecificResourceAllocation ) {
return SpecificDayAssignment.create(date, toAllocate, resource);
- } else if (resourceAllocation instanceof GenericResourceAllocation) {
+ } else if ( resourceAllocation instanceof GenericResourceAllocation ) {
return GenericDayAssignment.create(date, toAllocate, resource);
}
return null;
}
- private static EffortDuration addDayAssignment(List list,
- DayAssignment dayAssignment) {
- if (dayAssignment != null) {
+ private static EffortDuration addDayAssignment(List list, DayAssignment dayAssignment) {
+ if ( dayAssignment != null ) {
list.add(dayAssignment);
return dayAssignment.getDuration();
}
+
return zero();
}
- public static DateAndHour startTimeToAllocateStartingFromEnd(
- ResourceAllocation> resourceAllocation, Resource resource,
- Gap gap) {
+ public static DateAndHour startTimeToAllocateStartingFromEnd(ResourceAllocation> resourceAllocation,
+ Resource resource,
+ Gap gap) {
// Last element, time is end of last element (gap.starttime)
- if (gap.getEndTime() == null) {
+ if ( gap.getEndTime() == null ) {
return gap.getStartTime();
}
final List dayAssignments = LimitingResourceAllocator
- .generateDayAssignmentsStartingFromEnd(resourceAllocation,
- resource, gap.getEndTime());
+ .generateDayAssignmentsStartingFromEnd(resourceAllocation, resource, gap.getEndTime());
return LimitingResourceAllocator.getLastElementTime(dayAssignments);
}
diff --git a/libreplan-business/src/main/java/org/libreplan/business/reports/dtos/CompletedEstimatedHoursPerTaskDTO.java b/libreplan-business/src/main/java/org/libreplan/business/reports/dtos/CompletedEstimatedHoursPerTaskDTO.java
index 6cc55bf5f..90a9436af 100644
--- a/libreplan-business/src/main/java/org/libreplan/business/reports/dtos/CompletedEstimatedHoursPerTaskDTO.java
+++ b/libreplan-business/src/main/java/org/libreplan/business/reports/dtos/CompletedEstimatedHoursPerTaskDTO.java
@@ -66,9 +66,10 @@ public class CompletedEstimatedHoursPerTaskDTO {
public String getTaskName(Task task) {
String result = task.getName();
- if (result == null || result.isEmpty()) {
+ if ( result == null || result.isEmpty() ) {
result = task.getOrderElement().getName();
}
+
return result;
}
@@ -76,15 +77,16 @@ public class CompletedEstimatedHoursPerTaskDTO {
Integer result = new Integer(0);
final List dayAssignments = task.getDayAssignments(FilterType.WITHOUT_DERIVED);
- if (dayAssignments.isEmpty()) {
+ if ( dayAssignments.isEmpty() ) {
return result;
}
for (DayAssignment dayAssignment : dayAssignments) {
- if (date == null || dayAssignment.getDay().compareTo(date) <= 0) {
- result += dayAssignment.getHours();
+ if ( date == null || dayAssignment.getDay().compareTo(date) <= 0 ) {
+ result += dayAssignment.getDuration().getHours();
}
}
+
return result;
}
@@ -93,16 +95,17 @@ public class CompletedEstimatedHoursPerTaskDTO {
final List workReportLines = workReportLineDAO
.findByOrderElementAndChildren(task.getOrderElement());
- if (workReportLines.isEmpty()) {
+ if ( workReportLines.isEmpty() ) {
return result;
}
for (WorkReportLine workReportLine : workReportLines) {
final LocalDate workReportLineDate = new LocalDate(workReportLine.getDate());
- if (date == null || workReportLineDate.compareTo(date) <= 0) {
+ if ( date == null || workReportLineDate.compareTo(date) <= 0 ) {
result = EffortDuration.sum(result, workReportLine.getEffort());
}
}
+
return result;
}
diff --git a/libreplan-business/src/main/java/org/libreplan/business/reports/dtos/WorkingProgressPerTaskDTO.java b/libreplan-business/src/main/java/org/libreplan/business/reports/dtos/WorkingProgressPerTaskDTO.java
index 855607707..2d78349db 100644
--- a/libreplan-business/src/main/java/org/libreplan/business/reports/dtos/WorkingProgressPerTaskDTO.java
+++ b/libreplan-business/src/main/java/org/libreplan/business/reports/dtos/WorkingProgressPerTaskDTO.java
@@ -83,27 +83,28 @@ public class WorkingProgressPerTaskDTO {
this.realHours = calculateRealHours(task, date);
this.averageProgress = task.getOrderElement().getAdvancePercentage(date);
- this.imputedProgress = (totalPlannedHours != 0) ? new Double(
-realHours
- .toHoursAsDecimalWithScale(2).doubleValue()
- / totalPlannedHours.doubleValue())
+ this.imputedProgress = (totalPlannedHours != 0) ?
+ new Double(realHours.toHoursAsDecimalWithScale(2).doubleValue() / totalPlannedHours.doubleValue())
+ : new Double(0);
+ this.plannedProgress = (totalPlannedHours != 0) ?
+ new Double(partialPlannedHours / totalPlannedHours.doubleValue())
: new Double(0);
- this.plannedProgress = (totalPlannedHours != 0) ? new Double(partialPlannedHours / totalPlannedHours.doubleValue()) : new Double(0);
this.costDifference = calculateCostDifference(averageProgress,
- new BigDecimal(totalPlannedHours),
- realHours.toHoursAsDecimalWithScale(2));
+ new BigDecimal(totalPlannedHours),
+ realHours.toHoursAsDecimalWithScale(2));
this.planningDifference = calculatePlanningDifference(averageProgress,
- new BigDecimal(totalPlannedHours), new BigDecimal(
- partialPlannedHours));
+ new BigDecimal(totalPlannedHours),
+ new BigDecimal(partialPlannedHours));
this.ratioCostDifference = calculateRatioCostDifference(averageProgress, imputedProgress);
this.ratioPlanningDifference = calculateRatioPlanningDifference(averageProgress, plannedProgress);
}
public String getTaskName(Task task) {
String result = task.getName();
- if (result == null || result.isEmpty()) {
+ if ( result == null || result.isEmpty() ) {
result = task.getOrderElement().getName();
}
+
return result;
}
@@ -111,13 +112,13 @@ realHours
Integer result = new Integer(0);
final List dayAssignments = task.getDayAssignments(FilterType.WITHOUT_DERIVED);
- if (dayAssignments.isEmpty()) {
+ if ( dayAssignments.isEmpty() ) {
return result;
}
for (DayAssignment dayAssignment : dayAssignments) {
- if (date == null || dayAssignment.getDay().compareTo(date) <= 0) {
- result += dayAssignment.getHours();
+ if ( date == null || dayAssignment.getDay().compareTo(date) <= 0 ) {
+ result += dayAssignment.getDuration().getHours();
}
}
return result;
@@ -128,13 +129,13 @@ realHours
final List workReportLines = workReportLineDAO
.findByOrderElementAndChildren(task.getOrderElement());
- if (workReportLines.isEmpty()) {
+ if ( workReportLines.isEmpty() ) {
return result;
}
for (WorkReportLine workReportLine : workReportLines) {
final LocalDate workReportLineDate = new LocalDate(workReportLine.getDate());
- if (date == null || workReportLineDate.compareTo(date) <= 0) {
+ if ( date == null || workReportLineDate.compareTo(date) <= 0 ) {
result = EffortDuration.sum(result, workReportLine.getEffort());
}
}
@@ -206,30 +207,36 @@ realHours
}
public BigDecimal calculateCostDifference(BigDecimal averageProgress,
- BigDecimal totalPlannedHours, BigDecimal realHours) {
+ BigDecimal totalPlannedHours,
+ BigDecimal realHours) {
BigDecimal result = averageProgress;
result = result.multiply(totalPlannedHours);
+
return result.subtract(realHours);
}
public BigDecimal calculatePlanningDifference(BigDecimal averageProgress,
- BigDecimal totalPlannedHours, BigDecimal partialPlannedHours) {
+ BigDecimal totalPlannedHours,
+ BigDecimal partialPlannedHours) {
BigDecimal result = averageProgress;
result = result.multiply(totalPlannedHours);
+
return result.subtract(partialPlannedHours);
}
public BigDecimal calculateRatioCostDifference(BigDecimal averageProgress, Double imputedProgress) {
- if (imputedProgress.doubleValue() == 0) {
+ if ( imputedProgress.doubleValue() == 0 ) {
return new BigDecimal(0);
}
+
return averageProgress.divide(new BigDecimal(imputedProgress), 2, RoundingMode.HALF_UP);
}
public BigDecimal calculateRatioPlanningDifference(BigDecimal averageProgress, Double plannedProgress) {
- if (plannedProgress.doubleValue() == 0) {
+ if ( plannedProgress.doubleValue() == 0 ) {
return new BigDecimal(0);
}
+
return averageProgress.divide(new BigDecimal(plannedProgress), 2, RoundingMode.HALF_UP);
}
diff --git a/libreplan-business/src/test/java/org/libreplan/business/test/planner/entities/DayAssignmentMatchers.java b/libreplan-business/src/test/java/org/libreplan/business/test/planner/entities/DayAssignmentMatchers.java
index 97b158d18..5f047bfc9 100644
--- a/libreplan-business/src/test/java/org/libreplan/business/test/planner/entities/DayAssignmentMatchers.java
+++ b/libreplan-business/src/test/java/org/libreplan/business/test/planner/entities/DayAssignmentMatchers.java
@@ -49,9 +49,9 @@ public class DayAssignmentMatchers {
@Override
final public boolean matches(Object value) {
- if (value instanceof List) {
- List dayAssignments = new ArrayList(
- (List) value);
+ if ( value instanceof List ) {
+ List dayAssignments = new ArrayList<>((List) value);
+
return matches(dayAssignments);
}
return false;
@@ -70,48 +70,48 @@ public class DayAssignmentMatchers {
@Override
public void describeTo(Description description) {
- description.appendText("the first assignment must be at date"
- + start);
+ description.appendText("the first assignment must be at date" + start);
}
- public CombinableMatcher> consecutiveDays(
- int days) {
- return both(this).and(
- DayAssignmentMatchers.consecutiveDays(days));
+ public CombinableMatcher> consecutiveDays(int days) {
+ return both(this).and(DayAssignmentMatchers.consecutiveDays(days));
}
@Override
protected boolean matches(List assignments) {
- return !assignments.isEmpty()
- && assignments.get(0).getDay().equals(start);
+
+ return !assignments.isEmpty() && assignments.get(0).getDay().equals(start);
}
}
- public static final Matcher> haveHours(
- final int... hours) {
+ public static final Matcher> haveHours(final int... hours) {
return new BaseMatcher>() {
@Override
public boolean matches(Object value) {
- if (value instanceof List) {
+ if ( value instanceof List ) {
+
List extends DayAssignment> assignments = (List extends DayAssignment>) value;
- if (assignments.size() != hours.length) {
+
+ if ( assignments.size() != hours.length ) {
return false;
}
+
for (int i = 0; i < hours.length; i++) {
- if (hours[i] != assignments.get(i).getHours()) {
+ if ( hours[i] != assignments.get(i).getDuration().getHours() ) {
return false;
}
}
+
return true;
}
+
return false;
}
@Override
public void describeTo(Description description) {
- description.appendText("must have hours: "
- + Arrays.toString(hours));
+ description.appendText("must have hours: " + Arrays.toString(hours));
}
};
}
@@ -121,15 +121,17 @@ public class DayAssignmentMatchers {
@Override
public boolean matches(List assignments) {
- if (assignments.size() != days) {
+ if ( assignments.size() != days ) {
return false;
}
- if (days == 0) {
+ if ( days == 0 ) {
return true;
}
+
LocalDate current = assignments.get(0).getDay();
+
for (DayAssignment d : assignments) {
- if (!d.getDay().equals(current)) {
+ if ( !d.getDay().equals(current) ) {
return false;
}
current = current.plusDays(1);
@@ -139,8 +141,7 @@ public class DayAssignmentMatchers {
@Override
public void describeTo(Description description) {
- description.appendText("it must have " + days
- + " days consecutive ");
+ description.appendText("it must have " + days + " days consecutive ");
}
};
}
@@ -160,27 +161,32 @@ public class DayAssignmentMatchers {
@Override
protected boolean matches(List assignments) {
for (DayAssignment dayAssignment : assignments) {
- if (dayAssignment instanceof GenericDayAssignment) {
+
+ if ( dayAssignment instanceof GenericDayAssignment ) {
+
GenericDayAssignment generic = (GenericDayAssignment) dayAssignment;
- if (!allocation.equals(generic
- .getGenericResourceAllocation())) {
+
+ if ( !allocation.equals(generic.getGenericResourceAllocation()) ) {
return false;
}
- } else if (dayAssignment instanceof SpecificDayAssignment) {
+
+ } else if ( dayAssignment instanceof SpecificDayAssignment ) {
+
SpecificDayAssignment specific = (SpecificDayAssignment) dayAssignment;
- if (!allocation.equals(specific
- .getSpecificResourceAllocation())) {
+
+ if ( !allocation.equals(specific.getSpecificResourceAllocation()) ) {
+
return false;
}
}
}
+
return true;
}
@Override
public void describeTo(Description description) {
- description.appendText("all must belong to allocation "
- + allocation);
+ description.appendText("all must belong to allocation " + allocation);
}
};
}
diff --git a/libreplan-business/src/test/java/org/libreplan/business/test/planner/entities/DerivedAllocationGeneratorTest.java b/libreplan-business/src/test/java/org/libreplan/business/test/planner/entities/DerivedAllocationGeneratorTest.java
index eb770009c..a8ae2b72a 100644
--- a/libreplan-business/src/test/java/org/libreplan/business/test/planner/entities/DerivedAllocationGeneratorTest.java
+++ b/libreplan-business/src/test/java/org/libreplan/business/test/planner/entities/DerivedAllocationGeneratorTest.java
@@ -59,6 +59,7 @@ import org.libreplan.business.resources.entities.MachineWorkersConfigurationUnit
import org.libreplan.business.resources.entities.Resource;
import org.libreplan.business.resources.entities.Worker;
import org.libreplan.business.scenarios.bootstrap.IScenariosBootstrap;
+import org.libreplan.business.workingday.EffortDuration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -67,8 +68,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* @author Óscar González Fernández
*/
@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(locations = { BUSINESS_SPRING_CONFIG_FILE,
- BUSINESS_SPRING_CONFIG_TEST_FILE })
+@ContextConfiguration(locations = { BUSINESS_SPRING_CONFIG_FILE, BUSINESS_SPRING_CONFIG_TEST_FILE })
public class DerivedAllocationGeneratorTest {
@Autowired
@@ -95,7 +95,7 @@ public class DerivedAllocationGeneratorTest {
@SuppressWarnings("unchecked")
private void givenFinder(Worker... workers) {
IWorkerFinder result = createNiceMock(IWorkerFinder.class);
- Collection extends Criterion> argument = (Collection extends Criterion>) anyObject();
+ Collection extends Criterion> argument = anyObject();
expect(result.findWorkersMatching(argument)).andReturn(
Arrays.asList(workers)).anyTimes();
replay(result);
@@ -118,36 +118,34 @@ public class DerivedAllocationGeneratorTest {
configurationUnit = result;
}
- private Set assignmentsFor(
- MachineWorkersConfigurationUnit unit, Worker[] workers) {
- Set result = new HashSet();
+ private Set assignmentsFor(MachineWorkersConfigurationUnit unit, Worker[] workers) {
+ Set result = new HashSet<>();
for (Worker each : workers) {
MachineWorkerAssignment assignment = workerAssignment(unit,each);
result.add(assignment);
}
+
return result;
}
- private MachineWorkerAssignment workerAssignment(
- MachineWorkersConfigurationUnit unit, Worker each) {
+ private MachineWorkerAssignment workerAssignment(MachineWorkersConfigurationUnit unit, Worker each) {
MachineWorkerAssignment result = createNiceMock(MachineWorkerAssignment.class);
- expect(result.getMachineWorkersConfigurationUnit()).andReturn(unit)
- .anyTimes();
+ expect(result.getMachineWorkersConfigurationUnit()).andReturn(unit).anyTimes();
expect(result.getWorker()).andReturn(each);
- expect(result.getStartDate()).andReturn(
- asDate(new LocalDate(2000, 1, 1))).anyTimes();
+ expect(result.getStartDate()).andReturn(asDate(new LocalDate(2000, 1, 1))).anyTimes();
expect(result.getFinishDate()).andReturn(null).anyTimes();
replay(result);
+
return result;
}
private Worker workerWithAlwaysAssignedHours(int assignedHours){
Worker result = createNiceMock(Worker.class);
- expect(
- result.getAssignedDurationDiscounting(isA(Map.class),
- isA(LocalDate.class))).andReturn(hours(assignedHours))
+ expect(result.getAssignedDurationDiscounting(isA(Map.class), isA(LocalDate.class)))
+ .andReturn(hours(assignedHours))
.anyTimes();
replay(result);
+
return result;
}
@@ -156,26 +154,28 @@ public class DerivedAllocationGeneratorTest {
}
private void givenDayAssignments() {
- dayAssignments = new ArrayList();
+ dayAssignments = new ArrayList<>();
}
private void givenDayAssignments(LocalDate start, int... hours) {
- dayAssignments = new ArrayList();
+ dayAssignments = new ArrayList<>();
for (int i = 0; i < hours.length; i++) {
dayAssignments.add(createAssignment(start.plusDays(i), machine,
hours[i]));
}
}
- private DayAssignment createAssignment(LocalDate day, Machine machine,
- int hours) {
+ private DayAssignment createAssignment(LocalDate day, Machine machine, int hours) {
DayAssignment dayAssignment = createNiceMock(DayAssignment.class);
- expect(dayAssignment.getHours()).andReturn(hours).anyTimes();
+
+ // expect(dayAssignment.getHours()).andReturn(hours).anyTimes();
expect(dayAssignment.getDuration()).andReturn(hours(hours)).anyTimes();
expect(dayAssignment.getResource()).andReturn(machine).anyTimes();
expect(dayAssignment.getDay()).andReturn(day).anyTimes();
expect(dayAssignment.isAssignedTo(machine)).andReturn(true).anyTimes();
+
replay(dayAssignment);
+
return dayAssignment;
}
@@ -184,8 +184,7 @@ public class DerivedAllocationGeneratorTest {
givenFinder();
givenConfigurationUnit();
givenDayAssignments();
- DerivedAllocationGenerator.generate(derivedFrom, finder,
- configurationUnit, dayAssignments);
+ DerivedAllocationGenerator.generate(derivedFrom, finder, configurationUnit, dayAssignments);
}
@Test(expected = IllegalArgumentException.class)
@@ -193,8 +192,7 @@ public class DerivedAllocationGeneratorTest {
givenDerivedFrom();
givenConfigurationUnit();
givenDayAssignments();
- DerivedAllocationGenerator.generate(derivedFrom, finder,
- configurationUnit, dayAssignments);
+ DerivedAllocationGenerator.generate(derivedFrom, finder, configurationUnit, dayAssignments);
}
@Test(expected = IllegalArgumentException.class)
@@ -202,8 +200,7 @@ public class DerivedAllocationGeneratorTest {
givenDerivedFrom();
givenFinder();
givenDayAssignments();
- DerivedAllocationGenerator.generate(derivedFrom, finder,
- configurationUnit, dayAssignments);
+ DerivedAllocationGenerator.generate(derivedFrom, finder, configurationUnit, dayAssignments);
}
@Test(expected = IllegalArgumentException.class)
@@ -211,8 +208,7 @@ public class DerivedAllocationGeneratorTest {
givenDerivedFrom();
givenFinder();
givenConfigurationUnit();
- DerivedAllocationGenerator.generate(derivedFrom, finder,
- configurationUnit, dayAssignments);
+ DerivedAllocationGenerator.generate(derivedFrom, finder, configurationUnit, dayAssignments);
}
@Test
@@ -222,10 +218,8 @@ public class DerivedAllocationGeneratorTest {
givenConfigurationUnit(new BigDecimal(1.5), new Worker());
givenDayAssignments(new LocalDate(2009, 10, 20), 8, 8, 8, 4);
DerivedAllocation derivedAllocation = DerivedAllocationGenerator
- .generate(derivedFrom, finder, configurationUnit,
- dayAssignments);
- List assignments = derivedAllocation
- .getAssignments();
+ .generate(derivedFrom, finder, configurationUnit, dayAssignments);
+ List assignments = derivedAllocation.getAssignments();
assertThat(assignments, haveHours(12, 12, 12, 6));
}
@@ -238,14 +232,11 @@ public class DerivedAllocationGeneratorTest {
givenDayAssignments(start, 8, 8, 8, 4);
Machine otherMachine = Machine.create();
- dayAssignments
- .add(createAssignment(start.plusDays(5), otherMachine, 8));
+ dayAssignments.add(createAssignment(start.plusDays(5), otherMachine, 8));
DerivedAllocation derivedAllocation = DerivedAllocationGenerator
- .generate(derivedFrom, finder, configurationUnit,
- dayAssignments);
- List assignments = derivedAllocation
- .getAssignments();
+ .generate(derivedFrom, finder, configurationUnit, dayAssignments);
+ List assignments = derivedAllocation.getAssignments();
assertThat(assignments.size(), equalTo(4));
}
@@ -258,12 +249,9 @@ public class DerivedAllocationGeneratorTest {
givenConfigurationUnit(new BigDecimal(1.5));
givenDayAssignments(new LocalDate(2009, 10, 20), 8, 8, 8, 4);
DerivedAllocation derivedAllocation = DerivedAllocationGenerator
- .generate(derivedFrom, finder, configurationUnit,
- dayAssignments);
- List assignments = derivedAllocation
- .getAssignments();
- Map> byResource = DayAssignment
- .byResourceAndOrdered(assignments);
+ .generate(derivedFrom, finder, configurationUnit, dayAssignments);
+ List assignments = derivedAllocation.getAssignments();
+ Map> byResource = DayAssignment.byResourceAndOrdered(assignments);
assertThat(byResource.get(worker1), haveHours(7, 7, 7, 4));
assertThat(byResource.get(worker2), haveHours(5, 5, 5, 2));
}
diff --git a/libreplan-business/src/test/java/org/libreplan/business/test/planner/entities/DerivedAllocationTest.java b/libreplan-business/src/test/java/org/libreplan/business/test/planner/entities/DerivedAllocationTest.java
index 4ee0db738..33c95275f 100644
--- a/libreplan-business/src/test/java/org/libreplan/business/test/planner/entities/DerivedAllocationTest.java
+++ b/libreplan-business/src/test/java/org/libreplan/business/test/planner/entities/DerivedAllocationTest.java
@@ -50,6 +50,7 @@ import org.libreplan.business.resources.entities.Machine;
import org.libreplan.business.resources.entities.MachineWorkersConfigurationUnit;
import org.libreplan.business.resources.entities.Resource;
import org.libreplan.business.resources.entities.Worker;
+import org.libreplan.business.workingday.EffortDuration;
/**
* @author Óscar González Fernández
@@ -81,21 +82,20 @@ public class DerivedAllocationTest {
private void givenADerivedAllocation() {
givenDerivedFrom();
givenConfigurationUnit();
- derivedAllocation = DerivedAllocation.create(derivedFrom,
- configurationUnit);
+ derivedAllocation = DerivedAllocation.create(derivedFrom, configurationUnit);
}
private void givenDayAssignments(LocalDate start, Resource resource, int... hours) {
givenDayAssignments(derivedAllocation, start, resource, hours);
}
- private void givenDayAssignments(DerivedAllocation derivedAllocation,
- LocalDate start, Resource resource, int... hours) {
- dayAssignments = new ArrayList();
+ private void givenDayAssignments(DerivedAllocation derivedAllocation, LocalDate start,
+ Resource resource, int... hours) {
+ dayAssignments = new ArrayList<>();
for (int i = 0; i < hours.length; i++) {
LocalDate current = start.plusDays(i);
- DerivedDayAssignment d = DerivedDayAssignment.create(current,
- hours[i], resource, derivedAllocation);
+ DerivedDayAssignment d = DerivedDayAssignment.create(current, EffortDuration.hours(hours[i]),
+ resource, derivedAllocation);
dayAssignments.add(d);
}
}
@@ -116,8 +116,7 @@ public class DerivedAllocationTest {
private void givenGenericDerivedFrom(Resource... resources) {
derivedFrom = createNiceMock(GenericResourceAllocation.class);
GenericResourceAllocation generic = (GenericResourceAllocation) derivedFrom;
- expect(generic.getAssociatedResources()).andReturn(
- Arrays.asList(resources));
+ expect(generic.getAssociatedResources()).andReturn(Arrays.asList(resources));
replay(derivedFrom);
}
@@ -129,8 +128,7 @@ public class DerivedAllocationTest {
public void aDerivedAllocationHasAMachineWorkerConfigurationUnitAndAResourceAllocation() {
givenConfigurationUnit();
givenDerivedFrom();
- DerivedAllocation result = DerivedAllocation.create(derivedFrom,
- configurationUnit);
+ DerivedAllocation result = DerivedAllocation.create(derivedFrom, configurationUnit);
assertNotNull(result);
assertThat(result.getConfigurationUnit(), equalTo(configurationUnit));
assertEquals(result.getDerivedFrom(), derivedFrom);
@@ -166,8 +164,7 @@ public class DerivedAllocationTest {
public void aJustCreatedDerivedAllocationIsANewObject() {
givenDerivedFrom();
givenConfigurationUnit();
- DerivedAllocation result = DerivedAllocation.create(derivedFrom,
- configurationUnit);
+ DerivedAllocation result = DerivedAllocation.create(derivedFrom, configurationUnit);
assertTrue(result.isNewObject());
}
@@ -176,8 +173,7 @@ public class DerivedAllocationTest {
givenADerivedAllocation();
givenDayAssignments(new LocalDate(2008, 12, 1), worker, 8, 8, 8, 8);
derivedAllocation.resetAssignmentsTo(dayAssignments);
- assertThat(derivedAllocation.getAssignments(),
- compareValuesExceptParent(dayAssignments));
+ assertThat(derivedAllocation.getAssignments(), compareValuesExceptParent(dayAssignments));
}
private Matcher> compareValuesExceptParent(
@@ -185,46 +181,47 @@ public class DerivedAllocationTest {
return compareValuesExceptParent(Arrays.asList(derivedDayAssignments));
}
- private Matcher> compareValuesExceptParent(
- final List expected) {
+ private Matcher> compareValuesExceptParent(final List expected) {
return new BaseMatcher>() {
@Override
public boolean matches(Object object) {
- if (!(object instanceof Collection>)) {
+ if ( !(object instanceof Collection>) ) {
return false;
}
+
Collection arg = (Collection) object;
- if (arg.size() != expected.size()) {
+ if ( arg.size() != expected.size() ) {
return false;
}
+
Iterator argIterator = arg.iterator();
- Iterator expectedIterator = expected
- .iterator();
+ Iterator expectedIterator = expected.iterator();
+
while (argIterator.hasNext()) {
+
DerivedDayAssignment dayAssignment = argIterator.next();
DerivedDayAssignment expectedAssignment = expectedIterator.next();
Resource resource = dayAssignment.getResource();
- Resource expectedResource = expectedAssignment
- .getResource();
+ Resource expectedResource = expectedAssignment.getResource();
LocalDate day = dayAssignment.getDay();
LocalDate expectedDay = expectedAssignment.getDay();
- int hours = dayAssignment.getHours();
- int expectedHours = expectedAssignment
- .getHours();
- if (!resource.equals(expectedResource)
- || !day.equals(expectedDay)
- || hours != expectedHours) {
+
+ int hours = dayAssignment.getDuration().getHours();
+ int expectedHours = expectedAssignment.getDuration().getHours();
+
+ if ( !resource.equals(expectedResource) || !day.equals(expectedDay)
+ || hours != expectedHours ) {
return false;
}
}
+
return true;
}
@Override
public void describeTo(Description description) {
- description.appendText("must have the same values than "
- + expected);
+ description.appendText("must have the same values than " + expected);
}
};
}
@@ -233,19 +230,17 @@ public class DerivedAllocationTest {
public void theDerivedDayAssignmentsMustBeForTheSameMachine() {
givenADerivedAllocation();
final Machine otherMachine = Machine.create();
- givenDayAssignments(new LocalDate(2008, 12, 1), otherMachine, 8, 8,
- 8);
+ givenDayAssignments(new LocalDate(2008, 12, 1), otherMachine, 8, 8, 8);
derivedAllocation.resetAssignmentsTo(dayAssignments);
}
@Test
public void whenResettingAssignmentsTheParentIsChanged() {
givenADerivedAllocation();
- DerivedAllocation another = DerivedAllocation.create(derivedFrom,
- configurationUnit);
- givenDayAssignments(another, new LocalDate(2008, 12, 1), worker, 8, 8,
- 8);
+ DerivedAllocation another = DerivedAllocation.create(derivedFrom, configurationUnit);
+ givenDayAssignments(another, new LocalDate(2008, 12, 1), worker, 8, 8, 8);
derivedAllocation.resetAssignmentsTo(dayAssignments);
+
for (DerivedDayAssignment each : derivedAllocation.getAssignments()) {
assertTrue(each.belongsTo(derivedAllocation));
}
@@ -259,13 +254,11 @@ public class DerivedAllocationTest {
derivedAllocation.resetAssignmentsTo(dayAssignments);
final LocalDate startInterval = start.plusDays(2);
final LocalDate finishInterval = start.plusDays(4);
- DerivedDayAssignment newAssignment = DerivedDayAssignment.create(
- startInterval, 3, worker, derivedAllocation);
- derivedAllocation.resetAssignmentsTo(startInterval, finishInterval,
- Arrays.asList(newAssignment));
- assertThat(derivedAllocation.getAssignments(),
- compareValuesExceptParent(dayAssignments.get(0), dayAssignments
- .get(1), newAssignment));
+ DerivedDayAssignment newAssignment = DerivedDayAssignment.create(startInterval, EffortDuration.hours(3),
+ worker, derivedAllocation);
+ derivedAllocation.resetAssignmentsTo(startInterval, finishInterval, Arrays.asList(newAssignment));
+ assertThat(derivedAllocation.getAssignments(), compareValuesExceptParent(
+ dayAssignments.get(0), dayAssignments.get(1), newAssignment));
}
@Test
@@ -274,10 +267,9 @@ public class DerivedAllocationTest {
LocalDate start = new LocalDate(2008, 12, 1);
givenDayAssignments(start, worker, 8, 8, 8, 8);
derivedAllocation.resetAssignmentsTo(dayAssignments);
- DerivedDayAssignment newAssignment = DerivedDayAssignment.create(start
- .minusDays(1), 3, worker, derivedAllocation);
- derivedAllocation.resetAssignmentsTo(start, start.plusDays(4), Arrays
- .asList(newAssignment));
+ DerivedDayAssignment newAssignment = DerivedDayAssignment.create(
+ start.minusDays(1), EffortDuration.hours(3), worker, derivedAllocation);
+ derivedAllocation.resetAssignmentsTo(start, start.plusDays(4), Arrays.asList(newAssignment));
assertTrue(derivedAllocation.getAssignments().isEmpty());
}
@@ -291,10 +283,8 @@ public class DerivedAllocationTest {
@Test
public void asDerivedFromChangesTheDerivedFromProperty() {
givenADerivedAllocation();
- ResourceAllocation> newDerivedFrom = GenericResourceAllocation
- .create();
- DerivedAllocation modified = derivedAllocation
- .asDerivedFrom(newDerivedFrom);
+ ResourceAllocation> newDerivedFrom = GenericResourceAllocation.create();
+ DerivedAllocation modified = derivedAllocation.asDerivedFrom(newDerivedFrom);
assertEquals(newDerivedFrom, modified.getDerivedFrom());
}
diff --git a/libreplan-business/src/test/java/org/libreplan/business/test/planner/entities/GenericResourceAllocationTest.java b/libreplan-business/src/test/java/org/libreplan/business/test/planner/entities/GenericResourceAllocationTest.java
index 76185a7f6..126a66f50 100644
--- a/libreplan-business/src/test/java/org/libreplan/business/test/planner/entities/GenericResourceAllocationTest.java
+++ b/libreplan-business/src/test/java/org/libreplan/business/test/planner/entities/GenericResourceAllocationTest.java
@@ -496,7 +496,7 @@ public class GenericResourceAllocationTest {
genericResourceAllocation.forResources(Arrays.asList(worker1)).allocate(ResourcesPerDay.amount(2));
List orderedAssignmentsFor = genericResourceAllocation.getOrderedAssignmentsFor(worker1);
- assertThat(orderedAssignmentsFor.get(0).getHours(), equalTo(standardHoursPerDay * 2));
+ assertThat(orderedAssignmentsFor.get(0).getDuration().getHours(), equalTo(standardHoursPerDay * 2));
}
@Test
@@ -531,7 +531,7 @@ public class GenericResourceAllocationTest {
genericResourceAllocation.forResources(Arrays.asList(worker1)).allocate(ResourcesPerDay.amount(1));
List assigmments = genericResourceAllocation.getOrderedAssignmentsFor(worker1);
- assertThat(assigmments.get(0).getHours(), equalTo(defaultWorkableHours));
+ assertThat(assigmments.get(0).getDuration().getHours(), equalTo(defaultWorkableHours));
}
@Test
diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/limitingresources/QueueComponent.java b/libreplan-webapp/src/main/java/org/libreplan/web/limitingresources/QueueComponent.java
index 7991d19cd..1002adfae 100644
--- a/libreplan-webapp/src/main/java/org/libreplan/web/limitingresources/QueueComponent.java
+++ b/libreplan-webapp/src/main/java/org/libreplan/web/limitingresources/QueueComponent.java
@@ -64,18 +64,15 @@ import org.zkoss.zul.impl.XulElement;
* This class wraps ResourceLoad data inside an specific HTML Div component.
* @author Lorenzo Tilve Álvaro
*/
-public class QueueComponent extends XulElement implements
- AfterCompose {
+public class QueueComponent extends XulElement implements AfterCompose {
private static final int DEADLINE_MARK_HALF_WIDTH = 5;
- public static QueueComponent create(
- QueueListComponent queueListComponent,
- TimeTracker timeTracker,
- LimitingResourceQueue limitingResourceQueue) {
+ public static QueueComponent create(QueueListComponent queueListComponent,
+ TimeTracker timeTracker,
+ LimitingResourceQueue limitingResourceQueue) {
- return new QueueComponent(queueListComponent, timeTracker,
- limitingResourceQueue);
+ return new QueueComponent(queueListComponent, timeTracker, limitingResourceQueue);
}
private final QueueListComponent queueListComponent;
@@ -86,12 +83,11 @@ public class QueueComponent extends XulElement implements
private LimitingResourceQueue limitingResourceQueue;
- private List queueTasks = new ArrayList();
+ private List queueTasks = new ArrayList<>();
- private QueueComponent(
- final QueueListComponent queueListComponent,
- final TimeTracker timeTracker,
- final LimitingResourceQueue limitingResourceQueue) {
+ private QueueComponent(final QueueListComponent queueListComponent,
+ final TimeTracker timeTracker,
+ final LimitingResourceQueue limitingResourceQueue) {
this.queueListComponent = queueListComponent;
this.limitingResourceQueue = limitingResourceQueue;
@@ -106,6 +102,7 @@ public class QueueComponent extends XulElement implements
createChildren(limitingResourceQueue, timeTracker.getMapper());
}
};
+
this.timeTracker.addZoomListener(zoomChangedListener);
}
@@ -122,10 +119,8 @@ public class QueueComponent extends XulElement implements
this.limitingResourceQueue = limitingResourceQueue;
}
- private void createChildren(LimitingResourceQueue limitingResourceQueue,
- IDatesMapper mapper) {
- List queueTasks = createQueueTasks(mapper,
- limitingResourceQueue.getLimitingResourceQueueElements());
+ private void createChildren(LimitingResourceQueue limitingResourceQueue, IDatesMapper mapper) {
+ List queueTasks = createQueueTasks(mapper, limitingResourceQueue.getLimitingResourceQueueElements());
appendQueueTasks(queueTasks);
}
@@ -165,41 +160,50 @@ public class QueueComponent extends XulElement implements
removeChild(queueTask);
}
- private List createQueueTasks(IDatesMapper datesMapper,
- Set list) {
+ private List createQueueTasks(IDatesMapper datesMapper, Set list) {
- List result = new ArrayList();
+ List result = new ArrayList<>();
org.zkoss.ganttz.util.Interval interval = null;
- if (timeTracker.getFilter() != null) {
+
+ if ( timeTracker.getFilter() != null ) {
timeTracker.getFilter().resetInterval();
interval = timeTracker.getFilter().getCurrentPaginationInterval();
}
+
for (LimitingResourceQueueElement each : list) {
- if (interval != null) {
- if (each.getEndDate().toDateMidnight()
- .isAfter(interval.getStart().toDateMidnight())
- && each.getStartDate().toDateMidnight()
- .isBefore(interval.getFinish().toDateMidnight())) {
+
+ if ( interval != null ) {
+
+ if ( each.getEndDate().toDateTimeAtStartOfDay().isAfter(interval.getStart().toDateTimeAtStartOfDay()) &&
+ each.getStartDate().toDateTimeAtStartOfDay()
+ .isBefore(interval.getFinish().toDateTimeAtStartOfDay()) ) {
result.add(createQueueTask(datesMapper, each));
}
+
} else {
+
result.add(createQueueTask(datesMapper, each));
+
}
}
+
return result;
}
private static QueueTask createQueueTask(IDatesMapper datesMapper, LimitingResourceQueueElement element) {
validateQueueElement(element);
+
return createDivForElement(datesMapper, element);
}
private static OrderElement getRootOrder(Task task) {
OrderElement order = task.getOrderElement();
+
while (order.getParent() != null) {
order = order.getParent();
}
+
return order;
}
@@ -213,15 +217,19 @@ public class QueueComponent extends XulElement implements
result.append(_("Completed: {0}%", element.getAdvancePercentage().multiply(new BigDecimal(100))) + " ");
final ResourceAllocation> resourceAllocation = element.getResourceAllocation();
- if (resourceAllocation instanceof SpecificResourceAllocation) {
+
+ if ( resourceAllocation instanceof SpecificResourceAllocation ) {
+
final SpecificResourceAllocation specific = (SpecificResourceAllocation) resourceAllocation;
result.append(_("Resource: {0}", specific.getResource().getName()) + " ");
- } else if (resourceAllocation instanceof GenericResourceAllocation) {
+
+ } else if ( resourceAllocation instanceof GenericResourceAllocation ) {
+
final GenericResourceAllocation generic = (GenericResourceAllocation) resourceAllocation;
result.append(_("Criteria: {0}", Criterion.getCaptionFor(generic.getCriterions())) + " ");
+
}
- result.append(_("Allocation: [{0},{1}]", element.getStartDate()
- .toString(), element.getEndDate()));
+ result.append(_("Allocation: [{0},{1}]", element.getStartDate().toString(), element.getEndDate()));
return result.toString();
}
@@ -234,32 +242,39 @@ public class QueueComponent extends XulElement implements
*/
private static DateAndHour getAdvanceEndDate(LimitingResourceQueueElement element) {
int hoursWorked = 0;
+
final List extends DayAssignment> dayAssignments = element.getDayAssignments();
- if (element.hasDayAssignments()) {
+
+ if ( element.hasDayAssignments() ) {
+
final int estimatedWorkedHours = estimatedWorkedHours(element.getIntentedTotalHours(), element.getAdvancePercentage());
for (DayAssignment each: dayAssignments) {
- hoursWorked += each.getHours();
- if (hoursWorked >= estimatedWorkedHours) {
- int hourSlot = each.getHours() - (hoursWorked - estimatedWorkedHours);
+ hoursWorked += each.getDuration().getHours();
+
+ if ( hoursWorked >= estimatedWorkedHours ) {
+ int hourSlot = each.getDuration().getHours() - (hoursWorked - estimatedWorkedHours);
return new DateAndHour(each.getDay(), hourSlot);
}
+
}
}
- if (hoursWorked != 0) {
+
+ if ( hoursWorked != 0 ) {
DayAssignment lastDayAssignment = dayAssignments.get(dayAssignments.size() - 1);
- return new DateAndHour(lastDayAssignment.getDay(), lastDayAssignment.getHours());
+ return new DateAndHour(lastDayAssignment.getDay(), lastDayAssignment.getDuration().getHours());
}
+
return null;
}
private static int estimatedWorkedHours(Integer totalHours, BigDecimal percentageWorked) {
- return (totalHours != null && percentageWorked != null) ? percentageWorked.multiply(
- new BigDecimal(totalHours)).intValue() : 0;
+ boolean bool = totalHours != null && percentageWorked != null;
+
+ return bool ? percentageWorked.multiply(new BigDecimal(totalHours)).intValue() : 0;
}
- private static QueueTask createDivForElement(IDatesMapper datesMapper,
- LimitingResourceQueueElement queueElement) {
+ private static QueueTask createDivForElement(IDatesMapper datesMapper, LimitingResourceQueueElement queueElement) {
final Task task = queueElement.getResourceAllocation().getTask();
final OrderElement order = getRootOrder(task);
@@ -270,12 +285,14 @@ public class QueueComponent extends XulElement implements
int startPixels = getStartPixels(datesMapper, queueElement);
result.setLeft(forCSS(startPixels));
- if (startPixels < 0) {
+
+ if ( startPixels < 0 ) {
cssClass += " truncated-start ";
}
int taskWidth = getWidthPixels(datesMapper, queueElement);
- if ((startPixels + taskWidth) > datesMapper.getHorizontalSize()) {
+
+ if ( (startPixels + taskWidth) > datesMapper.getHorizontalSize() ) {
taskWidth = datesMapper.getHorizontalSize() - startPixels;
cssClass += " truncated-end ";
} else {
@@ -286,138 +303,142 @@ public class QueueComponent extends XulElement implements
LocalDate deadlineDate = task.getDeadline();
boolean isOrderDeadline = false;
- if (deadlineDate == null) {
+
+ if ( deadlineDate == null ) {
+
Date orderDate = order.getDeadline();
- if (orderDate != null) {
+
+ if ( orderDate != null ) {
+
deadlineDate = LocalDate.fromDateFields(orderDate);
isOrderDeadline = true;
+
}
}
- if (deadlineDate != null) {
+
+ if ( deadlineDate != null ) {
+
int deadlinePosition = getDeadlinePixels(datesMapper, deadlineDate);
- if (deadlinePosition < datesMapper.getHorizontalSize()) {
+
+ if ( deadlinePosition < datesMapper.getHorizontalSize() ) {
Div deadline = new Div();
- deadline.setSclass(isOrderDeadline ? "deadline order-deadline"
- : "deadline");
- deadline
- .setLeft((deadlinePosition - startPixels - DEADLINE_MARK_HALF_WIDTH)
- + "px");
+ deadline.setSclass(isOrderDeadline ? "deadline order-deadline" : "deadline");
+ deadline.setLeft((deadlinePosition - startPixels - DEADLINE_MARK_HALF_WIDTH) + "px");
result.appendChild(deadline);
- result.appendChild(generateNonWorkableShade(datesMapper,
- queueElement));
+ result.appendChild(generateNonWorkableShade(datesMapper, queueElement));
}
- if (deadlineDate.isBefore(queueElement.getEndDate())) {
+
+ if ( deadlineDate.isBefore(queueElement.getEndDate()) ) {
cssClass += " unmet-deadline ";
}
}
result.setClass(cssClass);
result.appendChild(generateCompletionShade(datesMapper, queueElement));
- Component progressBar = generateProgressBar(datesMapper, queueElement,
- task, startPixels);
- if (progressBar != null) {
+ Component progressBar = generateProgressBar(datesMapper, queueElement, task, startPixels);
+
+ if ( progressBar != null ) {
result.appendChild(progressBar);
}
+
return result;
}
private static Component generateProgressBar(IDatesMapper datesMapper,
- LimitingResourceQueueElement queueElement, Task task,
- int startPixels) {
+ LimitingResourceQueueElement queueElement,
+ Task task,
+ int startPixels) {
+
DateAndHour advancementEndDate = getAdvanceEndDate(queueElement);
- if (advancementEndDate == null) {
+
+ if ( advancementEndDate == null ) {
return null;
}
- Duration durationBetween = new Duration(queueElement.getStartTime()
- .toDateTime().getMillis(), advancementEndDate.toDateTime().getMillis());
+
+ Duration durationBetween = new Duration(queueElement.getStartTime().toDateTime().getMillis(),
+ advancementEndDate.toDateTime().getMillis());
Div progressBar = new Div();
- if (!queueElement.getStartDate().isEqual(advancementEndDate.getDate())) {
+
+ if ( !queueElement.getStartDate().isEqual(advancementEndDate.getDate()) ) {
progressBar.setWidth(datesMapper.toPixels(durationBetween) + "px");
progressBar.setSclass("queue-progress-bar");
}
+
return progressBar;
}
- private static Div generateNonWorkableShade(IDatesMapper datesMapper,
- LimitingResourceQueueElement queueElement) {
+ private static Div generateNonWorkableShade(IDatesMapper datesMapper, LimitingResourceQueueElement queueElement) {
- int workableHours = queueElement.getLimitingResourceQueue()
- .getResource().getCalendar()
+ int workableHours = queueElement
+ .getLimitingResourceQueue()
+ .getResource()
+ .getCalendar()
.getCapacityOn(PartialDay.wholeDay(queueElement.getEndDate()))
.roundToHours();
- int shadeWidth = Long.valueOf(
- (24 - workableHours)
- * DatesMapperOnInterval.MILISECONDS_PER_HOUR
- / datesMapper.getMilisecondsPerPixel()).intValue();
+ int shadeWidth = Long
+ .valueOf((24 - workableHours) * DatesMapperOnInterval.MILISECONDS_PER_HOUR
+ / datesMapper.getMilisecondsPerPixel())
+ .intValue();
- int shadeLeft = Long.valueOf(
- (workableHours - queueElement.getEndHour())
- * DatesMapperOnInterval.MILISECONDS_PER_HOUR
- / datesMapper.getMilisecondsPerPixel()).intValue()
- + shadeWidth;
- ;
+ int shadeLeft = Long
+ .valueOf((workableHours - queueElement.getEndHour()) * DatesMapperOnInterval.MILISECONDS_PER_HOUR
+ / datesMapper.getMilisecondsPerPixel()).intValue() + shadeWidth;
Div notWorkableHoursShade = new Div();
- notWorkableHoursShade
- .setTooltiptext(_("Workable capacity for this period ")
- + workableHours + _(" hours"));
+ notWorkableHoursShade.setTooltiptext(_("Workable capacity for this period ") + workableHours + _(" hours"));
notWorkableHoursShade.setContext("");
notWorkableHoursShade.setSclass("not-workable-hours");
+ notWorkableHoursShade.setStyle("left: " + shadeLeft + "px; width: " + shadeWidth + "px;");
- notWorkableHoursShade.setStyle("left: " + shadeLeft + "px; width: "
- + shadeWidth + "px;");
return notWorkableHoursShade;
}
- private static Div generateCompletionShade(IDatesMapper datesMapper,
- LimitingResourceQueueElement queueElement) {
+ private static Div generateCompletionShade(IDatesMapper datesMapper, LimitingResourceQueueElement queueElement) {
- int workableHours = queueElement.getLimitingResourceQueue()
- .getResource().getCalendar()
+ int workableHours = queueElement
+ .getLimitingResourceQueue()
+ .getResource()
+ .getCalendar()
.getCapacityOn(PartialDay.wholeDay(queueElement.getEndDate()))
.roundToHours();
- int shadeWidth = new Long((24 - workableHours)
- * DatesMapperOnInterval.MILISECONDS_PER_HOUR
- / datesMapper.getMilisecondsPerPixel()).intValue();
+ int shadeWidth = new Long((24 - workableHours) * DatesMapperOnInterval.MILISECONDS_PER_HOUR
+ / datesMapper.getMilisecondsPerPixel())
+ .intValue();
- int shadeLeft = new Long((workableHours - queueElement.getEndHour())
- * DatesMapperOnInterval.MILISECONDS_PER_HOUR
- / datesMapper.getMilisecondsPerPixel()).intValue()
- + shadeWidth;
+ int shadeLeft = new Long((workableHours - queueElement.getEndHour()) * DatesMapperOnInterval.MILISECONDS_PER_HOUR
+ / datesMapper.getMilisecondsPerPixel())
+ .intValue() + shadeWidth;
Div notWorkableHoursShade = new Div();
+
notWorkableHoursShade.setContext("");
notWorkableHoursShade.setSclass("limiting-completion");
+ notWorkableHoursShade.setStyle("left: " + shadeLeft + "px; width: " + shadeWidth + "px;");
- notWorkableHoursShade.setStyle("left: " + shadeLeft + "px; width: "
- + shadeWidth + "px;");
return notWorkableHoursShade;
}
- private static int getWidthPixels(IDatesMapper datesMapper,
- LimitingResourceQueueElement queueElement) {
+ private static int getWidthPixels(IDatesMapper datesMapper, LimitingResourceQueueElement queueElement) {
return datesMapper.toPixels(queueElement.getLengthBetween());
}
- private static int getDeadlinePixels(IDatesMapper datesMapper,
- LocalDate deadlineDate) {
+ private static int getDeadlinePixels(IDatesMapper datesMapper, LocalDate deadlineDate) {
// Deadline date is considered inclusively
- return datesMapper.toPixelsAbsolute(deadlineDate.plusDays(1)
- .toDateMidnight().getMillis());
+ return datesMapper.toPixelsAbsolute(deadlineDate.plusDays(1).toDateTimeAtStartOfDay().getMillis());
}
private static String forCSS(int pixels) {
return String.format("%dpx", pixels);
}
- private static int getStartPixels(IDatesMapper datesMapper,
- LimitingResourceQueueElement queueElement) {
- return datesMapper.toPixelsAbsolute((queueElement.getStartDate()
- .toDateMidnight().getMillis() + queueElement.getStartHour()
- * DatesMapperOnInterval.MILISECONDS_PER_HOUR));
+ private static int getStartPixels(IDatesMapper datesMapper, LimitingResourceQueueElement queueElement) {
+ return datesMapper.toPixelsAbsolute(
+ (queueElement.getStartDate().toDateTimeAtStartOfDay().getMillis()
+ + queueElement.getStartHour() * DatesMapperOnInterval.MILISECONDS_PER_HOUR)
+ );
}
public void appendQueueElements(SortedSet elements) {
@@ -435,17 +456,18 @@ public class QueueComponent extends XulElement implements
public void removeQueueElement(LimitingResourceQueueElement element) {
QueueTask queueTask = findQueueTaskByElement(element);
- if (queueTask != null) {
+ if ( queueTask != null ) {
removeQueueTask(queueTask);
}
}
private QueueTask findQueueTaskByElement(LimitingResourceQueueElement element) {
for (QueueTask each: queueTasks) {
- if (each.getLimitingResourceQueueElement().getId().equals(element.getId())) {
+ if ( each.getLimitingResourceQueueElement().getId().equals(element.getId()) ) {
return each;
}
}
+
return null;
}
@@ -462,40 +484,37 @@ public class QueueComponent extends XulElement implements
return limitingResourceQueue.getResource().getName();
}
- private static void validateQueueElement(
- LimitingResourceQueueElement queueElement) {
- if ((queueElement.getStartDate() == null)
- || (queueElement.getEndDate() == null)) {
+ private static void validateQueueElement(LimitingResourceQueueElement queueElement) {
+ if ( (queueElement.getStartDate() == null ) || ( queueElement.getEndDate() == null) ) {
throw new ValidationException(_("Invalid queue element"));
}
}
private void appendMenu(QueueTask divElement) {
- if (divElement.getPage() != null) {
- MenuBuilder menuBuilder = MenuBuilder.on(divElement
- .getPage(), divElement);
+ if ( divElement.getPage() != null ) {
+ MenuBuilder menuBuilder = MenuBuilder.on(divElement.getPage(), divElement);
- menuBuilder.item(_("Edit"), "/common/img/ico_editar.png",
- new ItemAction() {
+ menuBuilder.item(_("Edit"), "/common/img/ico_editar.png", new ItemAction() {
@Override
public void onEvent(QueueTask choosen, Event event) {
editResourceAllocation(choosen);
}
});
- menuBuilder.item(_("Unassign"), "/common/img/ico_borrar.png",
- new ItemAction() {
+
+ menuBuilder.item(_("Unassign"), "/common/img/ico_borrar.png", new ItemAction() {
@Override
public void onEvent(QueueTask choosen, Event event) {
unnasign(choosen);
}
});
- menuBuilder.item(_("Move"), "",
- new ItemAction() {
+
+ menuBuilder.item(_("Move"), "", new ItemAction() {
@Override
public void onEvent(QueueTask choosen, Event event) {
moveQueueTask(choosen);
}
});
+
divElement.setContext(menuBuilder.createWithoutSettingContext());
}
}
diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/orders/OrderCRUDController.java b/libreplan-webapp/src/main/java/org/libreplan/web/orders/OrderCRUDController.java
index f78420b4d..c8a839abf 100644
--- a/libreplan-webapp/src/main/java/org/libreplan/web/orders/OrderCRUDController.java
+++ b/libreplan-webapp/src/main/java/org/libreplan/web/orders/OrderCRUDController.java
@@ -216,21 +216,16 @@ public class OrderCRUDController extends GenericForwardComposer {
comp.setVariable("controller", this, true);
// Configuration of the order filter
- Component filterComponent = Executions.createComponents(
- "/orders/_orderFilter.zul", orderFilter,
- new HashMap());
+ Component filterComponent = Executions.createComponents("/orders/_orderFilter.zul",
+ orderFilter,
+ new HashMap());
filterComponent.setVariable("orderFilterController", this, true);
- filterStartDate = (Datebox) filterComponent
- .getFellow("filterStartDate");
- filterFinishDate = (Datebox) filterComponent
- .getFellow("filterFinishDate");
- bdFilters = (BandboxMultipleSearch) filterComponent
- .getFellow("bdFilters");
- checkIncludeOrderElements = (Checkbox) filterComponent
- .getFellow("checkIncludeOrderElements");
+ filterStartDate = (Datebox) filterComponent.getFellow("filterStartDate");
+ filterFinishDate = (Datebox) filterComponent.getFellow("filterFinishDate");
+ bdFilters = (BandboxMultipleSearch) filterComponent.getFellow("bdFilters");
+ checkIncludeOrderElements = (Checkbox) filterComponent.getFellow("checkIncludeOrderElements");
- filterProjectName = (Textbox) filterComponent
- .getFellow("filterProjectName");
+ filterProjectName = (Textbox) filterComponent.getFellow("filterProjectName");
checkCreationPermissions();
setupGlobalButtons();
@@ -238,31 +233,31 @@ public class OrderCRUDController extends GenericForwardComposer {
}
private void initializeFilter() {
- Date startDate = (Date) FilterUtils.readProjectsStartDate();
+ Date startDate = FilterUtils.readProjectsStartDate();
Date endDate = FilterUtils.readProjectsEndDate();
boolean calculateStartDate = (startDate == null);
boolean calculateEndDate = (endDate == null);
// Filter predicate needs to be calculated based on the projects dates
- if ((calculateStartDate) || (calculateEndDate)) {
+ if ( (calculateStartDate) || (calculateEndDate) ) {
User user = orderModel.getUser();
// Calculate filter based on user preferences
- if (user != null) {
- if ((startDate == null)
- && !FilterUtils.hasProjectsStartDateChanged()
- && (user.getProjectsFilterPeriodSince() != null)) {
+ if ( user != null ) {
+ if ( (startDate == null ) && !FilterUtils.hasProjectsStartDateChanged() &&
+ (user.getProjectsFilterPeriodSince() != null)) {
startDate = new LocalDate()
.minusMonths(user.getProjectsFilterPeriodSince())
- .toDateTimeAtStartOfDay().toDate();
+ .toDateTimeAtStartOfDay()
+ .toDate();
}
- if ((endDate == null)
- && !FilterUtils.hasProjectsEndDateChanged()
- && (user.getProjectsFilterPeriodTo() != null)) {
+ if ( (endDate == null ) && !FilterUtils.hasProjectsEndDateChanged() &&
+ (user.getProjectsFilterPeriodTo() != null)) {
endDate = new LocalDate()
.plusMonths(user.getProjectsFilterPeriodTo())
- .toDateMidnight().toDate();
+ .toDateTimeAtStartOfDay()
+ .toDate();
}
}
}
@@ -276,8 +271,7 @@ public class OrderCRUDController extends GenericForwardComposer {
}
private void loadLabels() {
- List sessionFilters = FilterUtils
- .readProjectsParameters();
+ List sessionFilters = FilterUtils.readProjectsParameters();
// Allow labels when list is empty
if ( sessionFilters != null ) {
bdFilters.addSelectedElements(toOrderFilterEnum(sessionFilters));
@@ -288,32 +282,30 @@ public class OrderCRUDController extends GenericForwardComposer {
// Calculate filter based on user preferences
if ( (user != null) && (user.getProjectsFilterLabel() != null) ) {
bdFilters.addSelectedElement(new FilterPair(OrderFilterEnum.Label,
- user.getProjectsFilterLabel().getFinderPattern(),
- user.getProjectsFilterLabel()));
+ user.getProjectsFilterLabel().getFinderPattern(),
+ user.getProjectsFilterLabel()));
}
}
private List toOrderFilterEnum(List filterPairs) {
- List result = new ArrayList();
+ List result = new ArrayList<>();
for (FilterPair filterPair : filterPairs) {
- TaskGroupFilterEnum type = (TaskGroupFilterEnum) filterPair
- .getType();
+ TaskGroupFilterEnum type = (TaskGroupFilterEnum) filterPair.getType();
switch (type) {
case Label:
- result.add(new FilterPair(OrderFilterEnum.Label, filterPair
- .getPattern(), filterPair.getValue()));
+ result.add(new FilterPair(OrderFilterEnum.Label, filterPair.getPattern(), filterPair.getValue()));
break;
case Criterion:
- result.add(new FilterPair(OrderFilterEnum.Criterion, filterPair
- .getPattern(), filterPair.getValue()));
+ result.add(new FilterPair(OrderFilterEnum.Criterion, filterPair.getPattern(), filterPair.getValue()));
break;
case ExternalCompany:
result.add(new FilterPair(OrderFilterEnum.ExternalCompany,
- filterPair.getPattern(), filterPair.getValue()));
+ filterPair.getPattern(),
+ filterPair.getValue())
+ );
break;
case State:
- result.add(new FilterPair(OrderFilterEnum.State, filterPair
- .getPattern(), filterPair.getValue()));
+ result.add(new FilterPair(OrderFilterEnum.State, filterPair.getPattern(), filterPair.getValue()));
break;
default:
}
@@ -322,8 +314,7 @@ public class OrderCRUDController extends GenericForwardComposer {
}
private void setupGlobalButtons() {
- Hbox perspectiveButtonsInsertionPoint = (Hbox) page
- .getFellow("perspectiveButtonsInsertionPoint");
+ Hbox perspectiveButtonsInsertionPoint = (Hbox) page.getFellow("perspectiveButtonsInsertionPoint");
saveOrderAndContinueButton.addEventListener(Events.ON_CLICK,
new EventListener() {
@@ -338,8 +329,7 @@ public class OrderCRUDController extends GenericForwardComposer {
@Override
public void onEvent(Event event) throws Exception {
try {
- Messagebox
- .show(_("Unsaved changes will be lost. Are you sure?"),
+ Messagebox.show(_("Unsaved changes will be lost. Are you sure?"),
_("Confirm exit dialog"),
Messagebox.OK | Messagebox.CANCEL,
Messagebox.QUESTION,
@@ -349,8 +339,7 @@ public class OrderCRUDController extends GenericForwardComposer {
if (evt.getName().equals(
"onOK")) {
ConfirmCloseUtil.resetConfirmClose();
- Executions
- .sendRedirect("/planner/index.zul;company_scheduling");
+ Executions.sendRedirect("/planner/index.zul;company_scheduling");
}
}
});
@@ -367,26 +356,26 @@ public class OrderCRUDController extends GenericForwardComposer {
Map editOrderElementArgs = new HashMap();
editOrderElementArgs.put("top_id", "editOrderElement");
- editOrderElementWindow = (Window) Executions.createComponents(
- "/orders/_editOrderElement.zul", parent, editOrderElementArgs);
+ editOrderElementWindow = (Window) Executions.createComponents("/orders/_editOrderElement.zul",
+ parent,
+ editOrderElementArgs);
Util.createBindingsFor(editOrderElementWindow);
Util.reloadBindings(editOrderElementWindow);
}
private void addEditWindowIfNecessary() {
- if (editWindow != null) {
+ if ( editWindow != null ) {
return;
}
listWindow.setVisible(false);
cachedOnlyOneVisible = null;
- Map editWindowArgs = new HashMap();
+ Map editWindowArgs = new HashMap<>();
editWindowArgs.put("top_id", "editWindow");
Component parent = listWindow.getParent();
- editWindow = (Window) Executions.createComponents(
- "/orders/_edition.zul", parent, editWindowArgs);
+ editWindow = (Window) Executions.createComponents("/orders/_edition.zul", parent, editWindowArgs);
Util.createBindingsFor(editWindow);
Util.reloadBindings(editWindow);
@@ -414,9 +403,10 @@ public class OrderCRUDController extends GenericForwardComposer {
private void fillSchedulingModes() {
List options = schedulingMode.getChildren();
- if (options != null && options.isEmpty()) {
+ if ( options != null && options.isEmpty() ) {
schedulingMode.appendChild(createCombo(SchedulingMode.FORWARD,
_("Forward"), _("Schedule from start to deadline")));
+
schedulingMode.appendChild(createCombo(
SchedulingMode.BACKWARDS, _("Backwards"),
_("Schedule from deadline to start")));
@@ -428,7 +418,7 @@ public class OrderCRUDController extends GenericForwardComposer {
List items = schedulingMode.getItems();
SchedulingMode currentMode = getOrder().getSchedulingMode();
for (Comboitem each : items) {
- if (each.getValue().equals(currentMode)) {
+ if ( each.getValue().equals(currentMode) ) {
schedulingMode.setSelectedItem(each);
setConstraintsFor(currentMode);
return;
@@ -473,8 +463,7 @@ public class OrderCRUDController extends GenericForwardComposer {
comp,
_("Starting date cannot be empty in forward mode"));
}
- if (orderModel
- .isAnyTaskWithConstraint(PositionConstraintType.AS_SOON_AS_POSSIBLE)) {
+ if ( orderModel.isAnyTaskWithConstraint(PositionConstraintType.AS_SOON_AS_POSSIBLE) ) {
throw new WrongValueException(comp,
_("Starting date cannot be empty because there is a task with constraint \"as soon as possible\""));
}
@@ -488,14 +477,12 @@ public class OrderCRUDController extends GenericForwardComposer {
throws WrongValueException {
if (value == null) {
if (mode == SchedulingMode.BACKWARDS) {
- throw new WrongValueException(
- comp,
- _("Deadline cannot be empty in backwards mode"));
+ throw new WrongValueException(comp, _("Deadline cannot be empty in backwards mode"));
}
- if (orderModel
- .isAnyTaskWithConstraint(PositionConstraintType.AS_LATE_AS_POSSIBLE)) {
+ if (orderModel.isAnyTaskWithConstraint(PositionConstraintType.AS_LATE_AS_POSSIBLE)) {
throw new WrongValueException(comp,
- _("Deadline cannot be empty because there is a task with constraint \"as late as possible\""));
+ _("Deadline cannot be empty because there is a task with constraint " +
+ "\"as late as possible\""));
}
}
}
@@ -509,8 +496,7 @@ public class OrderCRUDController extends GenericForwardComposer {
}
private void bindListOrderStatusSelectToOnStatusChange() {
- Listbox listOrderStatus = (Listbox) editWindow
- .getFellow("listOrderStatus");
+ Listbox listOrderStatus = (Listbox) editWindow.getFellow("listOrderStatus");
listOrderStatus.addEventListener(Events.ON_SELECT, new EventListener() {
@Override
public void onEvent(Event event) {
@@ -520,15 +506,15 @@ public class OrderCRUDController extends GenericForwardComposer {
}
public void setupOrderElementTreeController() {
- if (!confirmLastTab()) {
+ if ( !confirmLastTab() ) {
return;
}
setCurrentTab();
- if (orderElementTreeController == null) {
+ if ( orderElementTreeController == null ) {
// Create order element edit window
OrderElementController orderElementController = new OrderElementController();
- if (editOrderElementWindow == null) {
+ if ( editOrderElementWindow == null ) {
initEditOrderElementWindow();
}
try {
@@ -539,10 +525,10 @@ public class OrderCRUDController extends GenericForwardComposer {
}
// Prepare tree, attach edit window to tree
- orderElementTreeController = new OrderElementTreeController(
- orderModel, orderElementController, messagesForUser);
- TreeComponent orderElementsTree = (TreeComponent) editWindow
- .getFellow("orderElementTree");
+ orderElementTreeController = new OrderElementTreeController(orderModel,
+ orderElementController,
+ messagesForUser);
+ TreeComponent orderElementsTree = (TreeComponent) editWindow.getFellow("orderElementTree");
orderElementTreeController.setTreeComponent(orderElementsTree);
orderElementsTree.useController(orderElementTreeController);
orderElementTreeController.setReadOnly(readOnly);
@@ -572,11 +558,10 @@ public class OrderCRUDController extends GenericForwardComposer {
* Operations to do before to change the selected tab
*/
private boolean confirmLastTab() {
- if (getCurrentTab() != null) {
+ if ( getCurrentTab() != null ) {
// Confirm advances tab.
- if (getCurrentTab().getId().equals("tabAdvances")) {
- if (manageOrderElementAdvancesController != null
- && !manageOrderElementAdvancesController.save()) {
+ if ( getCurrentTab().getId().equals("tabAdvances") ) {
+ if ( manageOrderElementAdvancesController != null && !manageOrderElementAdvancesController.save() ) {
resetSelectedTab();
selectTab("tabAdvances");
return false;
@@ -594,13 +579,12 @@ public class OrderCRUDController extends GenericForwardComposer {
private AssignedHoursToOrderElementController assignedHoursController;
public void setupAssignedHoursToOrderElementController() {
- if (!confirmLastTab()) {
+ if ( !confirmLastTab() ) {
return;
}
setCurrentTab();
- Component orderElementHours = editWindow
- .getFellowIfAny("orderElementHours");
+ Component orderElementHours = editWindow.getFellowIfAny("orderElementHours");
if (assignedHoursController == null) {
assignedHoursController = (AssignedHoursToOrderElementController) orderElementHours
.getVariable("assignedHoursToOrderElementController", true);
@@ -617,14 +601,13 @@ public class OrderCRUDController extends GenericForwardComposer {
private ManageOrderElementAdvancesController manageOrderElementAdvancesController;
public void setupManageOrderElementAdvancesController() {
- if (!confirmLastTab()) {
+ if ( !confirmLastTab() ) {
return;
}
setCurrentTab();
- Component orderElementAdvances = editWindow
- .getFellowIfAny("orderElementAdvances");
- if (manageOrderElementAdvancesController == null) {
+ Component orderElementAdvances = editWindow.getFellowIfAny("orderElementAdvances");
+ if ( manageOrderElementAdvancesController == null ) {
final IOrderElementModel orderElementModel = getOrderElementModel();
manageOrderElementAdvancesController = (ManageOrderElementAdvancesController) orderElementAdvances
.getVariable("manageOrderElementAdvancesController", true);
@@ -639,14 +622,14 @@ public class OrderCRUDController extends GenericForwardComposer {
private AssignedLabelsToOrderElementController assignedLabelsController;
public void setupAssignedLabelsToOrderElementController() {
- if (!confirmLastTab()) {
+ if ( !confirmLastTab() ) {
return;
}
setCurrentTab();
- if (assignedLabelsController == null) {
- LabelsAssignmentToOrderElementComponent labelsAssignment = (LabelsAssignmentToOrderElementComponent) editWindow
- .getFellow("orderElementLabels");
+ if ( assignedLabelsController == null ) {
+ LabelsAssignmentToOrderElementComponent labelsAssignment =
+ (LabelsAssignmentToOrderElementComponent) editWindow.getFellow("orderElementLabels");
assignedLabelsController = labelsAssignment.getController();
final IOrderElementModel orderElementModel = getOrderElementModel();
@@ -657,20 +640,19 @@ public class OrderCRUDController extends GenericForwardComposer {
private AssignedCriterionRequirementToOrderElementController assignedCriterionRequirementController;
public void setupAssignedCriterionRequirementsToOrderElementController() {
- if (!confirmLastTab()) {
+ if ( !confirmLastTab() ) {
return;
}
setCurrentTab();
- if (assignedCriterionRequirementController == null) {
- Component orderElementCriterionRequirements = editWindow
- .getFellowIfAny("orderElementCriterionRequirements");
- assignedCriterionRequirementController = (AssignedCriterionRequirementToOrderElementController) orderElementCriterionRequirements
+ if ( assignedCriterionRequirementController == null ) {
+ Component orderElementCriterionRequirements = editWindow.getFellowIfAny("orderElementCriterionRequirements");
+ assignedCriterionRequirementController =
+ (AssignedCriterionRequirementToOrderElementController) orderElementCriterionRequirements
.getVariable("assignedCriterionRequirementController", true);
final IOrderElementModel orderElementModel = getOrderElementModel();
- assignedCriterionRequirementController
- .openWindow(orderElementModel);
+ assignedCriterionRequirementController.openWindow(orderElementModel);
} else {
reloadHoursGroupOrder();
}
@@ -679,19 +661,18 @@ public class OrderCRUDController extends GenericForwardComposer {
private AssignedMaterialsToOrderElementController assignedMaterialsController;
public void setupAssignedMaterialsToOrderElementController() {
- if (!confirmLastTab()) {
+ if ( !confirmLastTab() ) {
return;
}
setCurrentTab();
- if (assignedMaterialsController == null) {
- OrderElementMaterialAssignmentsComponent assignmentsComponent = (OrderElementMaterialAssignmentsComponent) editWindow
- .getFellowIfAny("orderElementMaterials");
+ if ( assignedMaterialsController == null ) {
+ OrderElementMaterialAssignmentsComponent assignmentsComponent =
+ (OrderElementMaterialAssignmentsComponent) editWindow.getFellowIfAny("orderElementMaterials");
assignedMaterialsController = assignmentsComponent.getController();
final IOrderElementModel orderElementModel = getOrderElementModel();
- assignedMaterialsController.openWindow(orderElementModel
- .getOrderElement());
+ assignedMaterialsController.openWindow(orderElementModel.getOrderElement());
}
}
@@ -706,7 +687,8 @@ public class OrderCRUDController extends GenericForwardComposer {
Component orderElementTaskQualityForms = editWindow.getFellowIfAny("orderElementTaskQualityForms");
if ( assignedTaskQualityFormController == null ) {
- assignedTaskQualityFormController = (AssignedTaskQualityFormsToOrderElementController) orderElementTaskQualityForms
+ assignedTaskQualityFormController =
+ (AssignedTaskQualityFormsToOrderElementController) orderElementTaskQualityForms
.getVariable("assignedTaskQualityFormsController", true);
final IOrderElementModel orderElementModel = getOrderElementModel();
@@ -728,8 +710,7 @@ public class OrderCRUDController extends GenericForwardComposer {
Component orderFiles = editWindow.getFellowIfAny("orderElementFiles");
if ( orderFilesController == null ){
- orderFilesController = (OrderFilesController) orderFiles
- .getVariable("orderFilesController", true);
+ orderFilesController = (OrderFilesController) orderFiles.getVariable("orderFilesController", true);
final IOrderElementModel orderElementModel = getOrderElementModel();
@@ -743,18 +724,17 @@ public class OrderCRUDController extends GenericForwardComposer {
private OrderAuthorizationController orderAuthorizationController;
public void setupOrderAuthorizationController() {
- if (!confirmLastTab()) {
+ if ( !confirmLastTab() ) {
return;
}
setCurrentTab();
- Component orderElementAuthorizations = editWindow
- .getFellowIfAny("orderElementAuthorizations");
+ Component orderElementAuthorizations = editWindow.getFellowIfAny("orderElementAuthorizations");
if (orderAuthorizationController == null) {
- orderAuthorizationController = (OrderAuthorizationController) orderElementAuthorizations
+ orderAuthorizationController =
+ (OrderAuthorizationController) orderElementAuthorizations
.getVariable("orderAuthorizationController", true);
- orderAuthorizationController
- .setMessagesForUserComponent(messagesForUser);
+ orderAuthorizationController.setMessagesForUserComponent(messagesForUser);
initOrderAuthorizations();
} else {
Util.createBindingsFor(orderElementAuthorizations);
@@ -766,19 +746,17 @@ public class OrderCRUDController extends GenericForwardComposer {
Component orderElementAuthorizations = editWindow
.getFellowIfAny("orderElementAuthorizations");
final Order order = orderModel.getOrder();
- if (order.isNewObject()) {
- orderAuthorizationController.initCreate(orderModel
- .getPlanningState());
+ if ( order.isNewObject() ) {
+ orderAuthorizationController.initCreate(orderModel.getPlanningState());
} else {
- orderAuthorizationController
- .initEdit(orderModel.getPlanningState());
+ orderAuthorizationController.initEdit(orderModel.getPlanningState());
}
Util.createBindingsFor(orderElementAuthorizations);
Util.reloadBindings(orderElementAuthorizations);
}
public List getOrders() {
- if (checkIncludeOrderElements.isChecked()) {
+ if ( checkIncludeOrderElements.isChecked() ) {
return orderModel.getOrders();
}
@@ -786,13 +764,12 @@ public class OrderCRUDController extends GenericForwardComposer {
}
private List getOrdersFiltered() {
- List labels = new ArrayList();
- List criteria = new ArrayList();
+ List labels = new ArrayList<>();
+ List criteria = new ArrayList<>();
ExternalCompany customer = null;
OrderStatusEnum state = null;
- for (FilterPair filterPair : (List) bdFilters
- .getSelectedElements()) {
+ for (FilterPair filterPair : (List) bdFilters.getSelectedElements()) {
OrderFilterEnum type = (OrderFilterEnum) filterPair.getType();
switch (type) {
case Label:
@@ -803,7 +780,7 @@ public class OrderCRUDController extends GenericForwardComposer {
criteria.add((Criterion) filterPair.getValue());
break;
case ExternalCompany:
- if (customer != null) {
+ if ( customer != null ) {
// It's impossible to have an Order associated to more than
// 1 customer
return Collections.emptyList();
@@ -811,7 +788,7 @@ public class OrderCRUDController extends GenericForwardComposer {
customer = (ExternalCompany) filterPair.getValue();
break;
case State:
- if (state != null) {
+ if ( state != null ) {
// It's impossible to have an Order associated with more
// than 1 state
return Collections.emptyList();
@@ -829,6 +806,7 @@ public class OrderCRUDController extends GenericForwardComposer {
if (cachedOnlyOneVisible == null) {
cachedOnlyOneVisible = new OnlyOneVisible(listWindow);
}
+
return cachedOnlyOneVisible;
}
@@ -848,24 +826,22 @@ public class OrderCRUDController extends GenericForwardComposer {
Tab previousTab = getCurrentTab();
save(showSaveMessage);
- if (orderModel.userCanRead(order,
- SecurityUtils.getSessionUserLoginName())) {
+ if ( orderModel.userCanRead(order, SecurityUtils.getSessionUserLoginName()) ) {
refreshOrderWindow();
// come back to the current tab after initialize all tabs.
resetSelectedTab();
selectTab(previousTab.getId());
- Events.sendEvent(new SelectEvent(Events.ON_SELECT, previousTab,
- null));
+ Events.sendEvent(new SelectEvent(Events.ON_SELECT, previousTab, null));
- if (isNewObject) {
+ if ( isNewObject ) {
this.planningControllerEntryPoints.goToOrderDetails(order);
}
} else {
try {
- Messagebox
- .show(_("You don't have read access to this project"),
- _("Information"), Messagebox.OK,
+ Messagebox.show(_("You don't have read access to this project"),
+ _("Information"),
+ Messagebox.OK,
Messagebox.INFORMATION);
goToList();
} catch (InterruptedException e) {
@@ -875,7 +851,7 @@ public class OrderCRUDController extends GenericForwardComposer {
}
private void refreshOrderWindow() {
- if (orderElementTreeController != null) {
+ if ( orderElementTreeController != null ) {
orderElementTreeController.resetCellsMarkedAsModified();
}
updateDisabilitiesOnInterface();
@@ -884,14 +860,13 @@ public class OrderCRUDController extends GenericForwardComposer {
}
private void refreshCodeTextboxesOnly() {
- if (orderElementTreeController != null) {
+ if ( orderElementTreeController != null ) {
Map orderElementCodeTextBoxes =
orderElementTreeController.getOrderElementCodeTextboxes();
for (OrderElement element : orderElementCodeTextBoxes.keySet()) {
- if (element.getId() != null) {
- orderElementCodeTextBoxes.get(element).setValue(
- element.getCode());
+ if ( element.getId() != null ) {
+ orderElementCodeTextBoxes.get(element).setValue(element.getCode());
}
}
}
@@ -902,21 +877,21 @@ public class OrderCRUDController extends GenericForwardComposer {
}
private void save(boolean showSaveMessage) {
- if (manageOrderElementAdvancesController != null) {
+ if ( manageOrderElementAdvancesController != null ) {
selectTab("tabAdvances");
- if (!manageOrderElementAdvancesController.save()) {
+ if ( !manageOrderElementAdvancesController.save() ) {
setCurrentTab();
return;
}
}
- if (assignedCriterionRequirementController != null) {
+ if ( assignedCriterionRequirementController != null ) {
selectTab("tabRequirements");
- if (!assignedCriterionRequirementController.close()) {
+ if ( !assignedCriterionRequirementController.close() ) {
setCurrentTab();
return;
}
}
- if (assignedTaskQualityFormController != null) {
+ if ( assignedTaskQualityFormController != null ) {
selectTab("tabTaskQualityForm");
if (!assignedTaskQualityFormController.confirm()) {
setCurrentTab();
@@ -925,7 +900,7 @@ public class OrderCRUDController extends GenericForwardComposer {
}
// come back to the default tab.
- if (getCurrentTab() != null) {
+ if ( getCurrentTab() != null ) {
selectTab(getCurrentTab().getId());
}
@@ -944,7 +919,7 @@ public class OrderCRUDController extends GenericForwardComposer {
private void setCurrentTab() {
Tabbox tabboxOrder = (Tabbox) editWindow.getFellowIfAny("tabboxOrder");
- if (tabboxOrder != null) {
+ if ( tabboxOrder != null ) {
selectedTab = tabboxOrder.getSelectedTab();
}
}
@@ -955,7 +930,7 @@ public class OrderCRUDController extends GenericForwardComposer {
protected void selectTab(String str) {
Tab tab = (Tab) editWindow.getFellowIfAny(str);
- if (tab != null) {
+ if ( tab != null ) {
tab.setSelected(true);
}
}
@@ -988,7 +963,7 @@ public class OrderCRUDController extends GenericForwardComposer {
}
public void up() {
- if (onUp == null) {
+ if ( onUp == null ) {
throw new IllegalStateException(
"in order to call up onUp action should have been set");
}
@@ -996,11 +971,14 @@ public class OrderCRUDController extends GenericForwardComposer {
}
public void confirmRemove(Order order) {
- if (orderModel.userCanWrite(order)) {
+ if ( orderModel.userCanWrite(order) ) {
try {
- int status = Messagebox.show(_("Confirm deleting {0}. Are you sure?", order.getName()),
- "Delete", Messagebox.OK | Messagebox.CANCEL, Messagebox.QUESTION);
- if (Messagebox.OK == status) {
+ int status = Messagebox.show(_("Confirm deleting {0}. Are you sure?",
+ order.getName()),
+ "Delete",
+ Messagebox.OK | Messagebox.CANCEL,
+ Messagebox.QUESTION);
+ if ( Messagebox.OK == status ) {
remove(order);
}
} catch (InterruptedException e) {
@@ -1010,7 +988,9 @@ public class OrderCRUDController extends GenericForwardComposer {
else {
try {
Messagebox.show(_("Not enough permissions to edit this project"),
- _("Information"), Messagebox.OK, Messagebox.INFORMATION);
+ _("Information"),
+ Messagebox.OK,
+ Messagebox.INFORMATION);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
@@ -1106,7 +1086,7 @@ public class OrderCRUDController extends GenericForwardComposer {
}
public void checkUserCanRead(Order order) {
- if (!orderModel.userCanRead(order, SecurityUtils.getSessionUserLoginName())) {
+ if ( !orderModel.userCanRead(order, SecurityUtils.getSessionUserLoginName()) ) {
try {
Messagebox.show(_("Sorry, you do not have permissions to access this project"),
_("Information"), Messagebox.OK, Messagebox.INFORMATION);
@@ -1144,14 +1124,12 @@ public class OrderCRUDController extends GenericForwardComposer {
}
private void initializeCustomerComponent() {
- bdExternalCompanies = (BandboxSearch) editWindow
- .getFellow("bdExternalCompanies");
+ bdExternalCompanies = (BandboxSearch) editWindow.getFellow("bdExternalCompanies");
bdExternalCompanies.setListboxEventListener(
Events.ON_SELECT, new EventListener() {
@Override
public void onEvent(Event event) {
- final Object object = bdExternalCompanies
- .getSelectedElement();
+ final Object object = bdExternalCompanies.getSelectedElement();
orderModel.setExternalCompany((ExternalCompany) object);
}
});
@@ -1159,8 +1137,7 @@ public class OrderCRUDController extends GenericForwardComposer {
new EventListener() {
@Override
public void onEvent(Event event) {
- final Object object = bdExternalCompanies
- .getSelectedElement();
+ final Object object = bdExternalCompanies.getSelectedElement();
orderModel.setExternalCompany((ExternalCompany) object);
bdExternalCompanies.close();
}
@@ -1171,7 +1148,7 @@ public class OrderCRUDController extends GenericForwardComposer {
}
public void setupOrderDetails() {
- if (!confirmLastTab()) {
+ if ( !confirmLastTab() ) {
return;
}
setCurrentTab();
@@ -1185,8 +1162,7 @@ public class OrderCRUDController extends GenericForwardComposer {
}
public void reloadOrderDetailsTab() {
- Tabpanel tabPanel = (Tabpanel) editWindow
- .getFellow("tabPanelGeneralData");
+ Tabpanel tabPanel = (Tabpanel) editWindow.getFellow("tabPanelGeneralData");
Util.createBindingsFor(tabPanel);
Util.reloadBindings(tabPanel);
}
@@ -1210,7 +1186,7 @@ public class OrderCRUDController extends GenericForwardComposer {
}
public ProjectDetailsController getCreationPopup() {
- if (projectDetailsController == null) {
+ if ( projectDetailsController == null ) {
projectDetailsController = new ProjectDetailsController();
}
return projectDetailsController;
@@ -1220,8 +1196,7 @@ public class OrderCRUDController extends GenericForwardComposer {
showCreateButtons(false);
}
- public void setPlanningControllerEntryPoints(
- IOrderPlanningGate planningControllerEntryPoints) {
+ public void setPlanningControllerEntryPoints(IOrderPlanningGate planningControllerEntryPoints) {
this.planningControllerEntryPoints = planningControllerEntryPoints;
}
@@ -1250,7 +1225,7 @@ public class OrderCRUDController extends GenericForwardComposer {
item.setValue(calendar);
BaseCalendar current = orderModel.getCalendar();
- if ((current != null) && calendar.getId().equals(current.getId())) {
+ if ( (current != null) && calendar.getId().equals(current.getId()) ) {
Combobox combobox = (Combobox) item.getParent();
combobox.setSelectedItem(item);
}
@@ -1269,7 +1244,7 @@ public class OrderCRUDController extends GenericForwardComposer {
public void setCodeAutogenerated(boolean codeAutogenerated) {
try {
orderModel.setCodeAutogenerated(codeAutogenerated);
- if (orderElementTreeController != null) {
+ if ( orderElementTreeController != null ) {
orderElementTreeController.disabledCodeBoxes(codeAutogenerated);
}
} catch (ConcurrentModificationException e) {
@@ -1307,8 +1282,7 @@ public class OrderCRUDController extends GenericForwardComposer {
appendDate(row, order.getInitDate());
appendDate(row, order.getDeadline());
appendCustomer(row, order.getCustomer());
- appendObject(row,
- Util.addCurrencySymbol(order.getTotalManualBudget()));
+ appendObject(row, Util.addCurrencySymbol(order.getTotalManualBudget()));
appendObject(row, order.getTotalHours());
appendObject(row, _(order.getState().toString()));
appendOperations(row, order);
@@ -1325,7 +1299,7 @@ public class OrderCRUDController extends GenericForwardComposer {
private void appendObject(final Row row, Object object) {
String text = new String("");
- if (object != null) {
+ if ( object != null ) {
text = object.toString();
}
appendLabel(row, text);
@@ -1333,7 +1307,7 @@ public class OrderCRUDController extends GenericForwardComposer {
private void appendCustomer(final Row row, ExternalCompany externalCompany) {
String customerName = new String("");
- if (externalCompany != null) {
+ if ( externalCompany != null ) {
customerName = externalCompany.getName();
}
appendLabel(row, customerName);
@@ -1346,7 +1320,7 @@ public class OrderCRUDController extends GenericForwardComposer {
private void appendDate(final Row row, Date date) {
String labelDate = new String("");
- if (date != null) {
+ if ( date != null ) {
labelDate = Util.formatDate(date);
}
appendLabel(row, labelDate);
@@ -1377,7 +1351,7 @@ public class OrderCRUDController extends GenericForwardComposer {
}
private void appendButtonDelete(final Hbox hbox, final Order order) {
- if (orderModel.userCanWrite(order)) {
+ if ( orderModel.userCanWrite(order) ) {
Button buttonDelete = new Button();
buttonDelete.setSclass("icono");
buttonDelete.setImage("/common/img/ico_borrar1.png");
@@ -1420,10 +1394,9 @@ public class OrderCRUDController extends GenericForwardComposer {
createTemplate(order);
}
});
- if (!SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_TEMPLATES)) {
+ if ( !SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_TEMPLATES) ) {
buttonDerived.setDisabled(true);
- buttonDerived
- .setTooltiptext(_("Not enough permissions to create templates"));
+ buttonDerived.setTooltiptext(_("Not enough permissions to create templates"));
}
hbox.appendChild(buttonDerived);
}
@@ -1446,11 +1419,9 @@ public class OrderCRUDController extends GenericForwardComposer {
public void validate(Component comp, Object value)
throws WrongValueException {
Date finishDate = (Date) value;
- if ( (finishDate != null)
- && (filterStartDate.getRawValue() != null)
- && (finishDate.compareTo((Date) filterStartDate.getRawValue()) < 0) ) {
- throw new WrongValueException(comp,
- _("must be after start date"));
+ if ( (finishDate != null) && (filterStartDate.getRawValue() != null) &&
+ (finishDate.compareTo((Date) filterStartDate.getRawValue()) < 0) ) {
+ throw new WrongValueException(comp, _("must be after start date"));
}
}
};
@@ -1462,11 +1433,9 @@ public class OrderCRUDController extends GenericForwardComposer {
public void validate(Component comp, Object value)
throws WrongValueException {
Date startDate = (Date) value;
- if ( (startDate != null)
- && (filterFinishDate.getRawValue() != null)
- && (startDate.compareTo((Date) filterFinishDate.getRawValue()) > 0) ) {
- throw new WrongValueException(comp,
- _("must be lower than end date"));
+ if ( (startDate != null) && (filterFinishDate.getRawValue() != null) &&
+ (startDate.compareTo((Date) filterFinishDate.getRawValue()) > 0) ) {
+ throw new WrongValueException(comp, _("must be lower than end date"));
}
}
};
@@ -1476,7 +1445,7 @@ public class OrderCRUDController extends GenericForwardComposer {
OrderPredicate predicate = createPredicate();
storeSessionVariables();
FilterUtils.writeProjectFilterChanged(true);
- if (predicate != null) {
+ if ( predicate != null ) {
// Force reload conversation state in oderModel
getOrders();
filterByPredicate(predicate);
@@ -1488,37 +1457,41 @@ public class OrderCRUDController extends GenericForwardComposer {
private void storeSessionVariables() {
FilterUtils.writeProjectsFilter(filterStartDate.getValue(),
- filterFinishDate.getValue(),
- getSelectedBandboxAsTaskGroupFilters(),
- filterProjectName.getValue());
+ filterFinishDate.getValue(),
+ getSelectedBandboxAsTaskGroupFilters(),
+ filterProjectName.getValue());
}
private List getSelectedBandboxAsTaskGroupFilters() {
- List result = new ArrayList();
- for (FilterPair filterPair : (List) bdFilters
- .getSelectedElements()) {
- OrderFilterEnum type = (OrderFilterEnum) filterPair
- .getType();
+ List result = new ArrayList<>();
+
+ for (FilterPair filterPair : (List) bdFilters.getSelectedElements()) {
+ OrderFilterEnum type = (OrderFilterEnum) filterPair.getType();
switch (type) {
case Label:
- result.add(new FilterPair(TaskGroupFilterEnum.Label, filterPair
- .getPattern(), filterPair.getValue()));
+ result.add(new FilterPair(TaskGroupFilterEnum.Label,
+ filterPair.getPattern(),
+ filterPair.getValue()));
break;
case Criterion:
result.add(new FilterPair(TaskGroupFilterEnum.Criterion,
- filterPair.getPattern(), filterPair.getValue()));
+ filterPair.getPattern(),
+ filterPair.getValue()));
break;
case ExternalCompany:
result.add(new FilterPair(TaskGroupFilterEnum.ExternalCompany,
- filterPair.getPattern(), filterPair.getValue()));
+ filterPair.getPattern(),
+ filterPair.getValue()));
break;
case State:
- result.add(new FilterPair(TaskGroupFilterEnum.State, filterPair
- .getPattern(), filterPair.getValue()));
+ result.add(new FilterPair(TaskGroupFilterEnum.State,
+ filterPair.getPattern(),
+ filterPair.getValue()));
break;
default:
- result.add(new FilterPair(OrderFilterEnum.Label, filterPair
- .getPattern(), filterPair.getValue()));
+ result.add(new FilterPair(OrderFilterEnum.Label,
+ filterPair.getPattern(),
+ filterPair.getValue()));
break;
}
}
@@ -1526,19 +1499,17 @@ public class OrderCRUDController extends GenericForwardComposer {
}
private OrderPredicate createPredicate() {
- List listFilters = (List) bdFilters
- .getSelectedElements();
+ List