[Bug #647] Improve quantities by default in resource allocation window .
FEA: ItEr60S04ValidacionEProbasFuncionaisItEr59S04
This commit is contained in:
parent
a36dc067ee
commit
7a17025aef
6 changed files with 105 additions and 4 deletions
|
|
@ -152,11 +152,11 @@ public class Criterion extends IntegrationEntity implements ICriterion {
|
|||
}
|
||||
}
|
||||
|
||||
private static String allWorkersCaption() {
|
||||
public static String allWorkersCaption() {
|
||||
return _("[generic all workers]");
|
||||
}
|
||||
|
||||
private static String allMachinesCaption() {
|
||||
public static String allMachinesCaption() {
|
||||
return _("[generic all machines]");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,8 @@ import org.hibernate.validator.Valid;
|
|||
*/
|
||||
public class Machine extends Resource {
|
||||
|
||||
private final static ResourceEnum type = ResourceEnum.MACHINE;
|
||||
|
||||
private String name;
|
||||
|
||||
private String description;
|
||||
|
|
@ -126,4 +128,8 @@ public class Machine extends Resource {
|
|||
return c.getResourceType().equals(ResourceEnum.MACHINE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceEnum getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1103,6 +1103,8 @@ public abstract class Resource extends IntegrationEntity {
|
|||
|
||||
}
|
||||
|
||||
public abstract ResourceEnum getType();
|
||||
|
||||
public boolean isVirtual() {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,6 +74,8 @@ public class Worker extends Resource {
|
|||
|
||||
}
|
||||
|
||||
private final static ResourceEnum type = ResourceEnum.WORKER;
|
||||
|
||||
private String firstName;
|
||||
|
||||
private String surname;
|
||||
|
|
@ -176,4 +178,8 @@ public class Worker extends Resource {
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceEnum getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,10 +28,11 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
import org.navalplanner.business.orders.entities.HoursGroup;
|
||||
import org.navalplanner.business.planner.entities.CalculatedValue;
|
||||
import org.navalplanner.business.planner.entities.DerivedAllocationGenerator.IWorkerFinder;
|
||||
import org.navalplanner.business.planner.entities.ResourceAllocation;
|
||||
import org.navalplanner.business.planner.entities.Task;
|
||||
import org.navalplanner.business.planner.entities.DerivedAllocationGenerator.IWorkerFinder;
|
||||
import org.navalplanner.business.planner.entities.allocationalgorithms.HoursModification;
|
||||
import org.navalplanner.business.planner.entities.allocationalgorithms.ResourcesPerDayModification;
|
||||
import org.navalplanner.business.resources.entities.Criterion;
|
||||
|
|
@ -75,7 +76,13 @@ public class AllocationRowsHandler {
|
|||
if (alreadyExistsAllocationFor(each)) {
|
||||
alreadyPresent.add(each);
|
||||
} else {
|
||||
currentRows.add(SpecificAllocationRow.forResource(each));
|
||||
SpecificAllocationRow specificAllocationRow = SpecificAllocationRow
|
||||
.forResource(each);
|
||||
Integer calculatedHours = calculateHours(specificAllocationRow);
|
||||
if (calculatedHours != null) {
|
||||
specificAllocationRow.setHoursToInput(calculatedHours);
|
||||
}
|
||||
currentRows.add(specificAllocationRow);
|
||||
formBinder.newAllocationAdded();
|
||||
}
|
||||
}
|
||||
|
|
@ -101,6 +108,11 @@ public class AllocationRowsHandler {
|
|||
.create(resourceType, criteria, resourcesMatched);
|
||||
if (hours != null) {
|
||||
genericAllocationRow.setHoursToInput(hours);
|
||||
} else {
|
||||
Integer calculatedHours = calculateHours(genericAllocationRow);
|
||||
if (calculatedHours != null) {
|
||||
genericAllocationRow.setHoursToInput(calculatedHours);
|
||||
}
|
||||
}
|
||||
if (alreadyExistsAllocationFor(resourceType, criteria)) {
|
||||
formBinder.markThereisAlreadyAssignmentWith(resourceType,
|
||||
|
|
@ -112,6 +124,77 @@ public class AllocationRowsHandler {
|
|||
}
|
||||
}
|
||||
|
||||
private Integer calculateHours(AllocationRow allocationRow) {
|
||||
if ((isAllocationByResourceType(allocationRow, ResourceEnum.WORKER))
|
||||
&& notStillExistAnotherAllocation(ResourceEnum.WORKER)) {
|
||||
return calculateHoursByCalculatedValue(ResourceEnum.WORKER);
|
||||
} else if (isAllocationByResourceType(allocationRow,
|
||||
ResourceEnum.MACHINE)
|
||||
&& notStillExistAnotherAllocation(ResourceEnum.MACHINE)) {
|
||||
return calculateHoursByCalculatedValue(ResourceEnum.MACHINE);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Integer calculateHoursByCalculatedValue(ResourceEnum resource) {
|
||||
switch (calculatedValue) {
|
||||
case NUMBER_OF_HOURS:
|
||||
break;
|
||||
case END_DATE:
|
||||
case RESOURCES_PER_DAY:
|
||||
return calculateHoursGroupByResourceType(resource);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Integer calculateHoursGroupByResourceType(ResourceEnum resource) {
|
||||
Integer hours = new Integer(0);
|
||||
for(HoursGroup hourGroup : task.getTaskSource().getHoursGroups()){
|
||||
if (hourGroup.getResourceType().equals(resource)) {
|
||||
hours += hourGroup.getWorkingHours();
|
||||
}
|
||||
}
|
||||
return hours;
|
||||
}
|
||||
|
||||
private boolean notStillExistAnotherAllocation(ResourceEnum type) {
|
||||
for (AllocationRow allocation : getCurrentRows()) {
|
||||
if (isAllocationByResourceType(allocation, type)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isAllocationByResourceType(AllocationRow allocationRow,
|
||||
ResourceEnum resourceType) {
|
||||
if (!allocationRow.isGeneric()) {
|
||||
Resource resource = ((SpecificAllocationRow) allocationRow)
|
||||
.getResource();
|
||||
return resource.getType().equals(resourceType);
|
||||
} else {
|
||||
Collection<? extends Criterion> criteria = ((GenericAllocationRow) allocationRow)
|
||||
.getCriterions();
|
||||
for (Criterion criterion : criteria) {
|
||||
if (criterion.getType().getResource().equals(resourceType)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return isGenericAllBy(((GenericAllocationRow) allocationRow),
|
||||
resourceType);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isGenericAllBy(GenericAllocationRow generic,
|
||||
ResourceEnum type) {
|
||||
String captionName = generic.getName();
|
||||
if (type.equals(ResourceEnum.WORKER)) {
|
||||
return captionName.equals(Criterion.allWorkersCaption());
|
||||
} else {
|
||||
return captionName.equals(Criterion.allMachinesCaption());
|
||||
}
|
||||
}
|
||||
|
||||
public List<AllocationRow> getCurrentRows() {
|
||||
return currentRows;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import static org.navalplanner.web.I18nHelper._;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
|
@ -144,4 +145,7 @@ public class GenericAllocationRow extends AllocationRow {
|
|||
return resources;
|
||||
}
|
||||
|
||||
public Set<Criterion> getCriterions() {
|
||||
return Collections.unmodifiableSet(criterions);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue