ItEr36S11CUCreacionUnidadesPlanificacionItEr35S12: There is no longer a default generic allocation initially. It must be added.
This commit is contained in:
parent
60cc1fd5d0
commit
5e749a2fbb
7 changed files with 56 additions and 90 deletions
|
|
@ -86,6 +86,13 @@ public class GenericResourceAllocation extends
|
|||
task));
|
||||
}
|
||||
|
||||
public static GenericResourceAllocation create(Task task,
|
||||
Collection<? extends Criterion> criterions) {
|
||||
GenericResourceAllocation result = new GenericResourceAllocation(task);
|
||||
result.criterions = new HashSet<Criterion>(criterions);
|
||||
return create(result);
|
||||
}
|
||||
|
||||
private GenericResourceAllocation(Task task) {
|
||||
super(task);
|
||||
this.criterions = task.getCriterions();
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ import org.navalplanner.business.planner.entities.ResourceAllocation;
|
|||
import org.navalplanner.business.planner.entities.ResourcesPerDay;
|
||||
import org.navalplanner.business.planner.entities.Task;
|
||||
import org.navalplanner.business.planner.entities.allocationalgorithms.AllocationBeingModified;
|
||||
import org.navalplanner.business.resources.entities.Resource;
|
||||
|
||||
/**
|
||||
* The information that must be introduced to create a
|
||||
|
|
@ -65,7 +64,7 @@ public abstract class AllocationDTO {
|
|||
private ResourcesPerDay resourcesPerDay;
|
||||
|
||||
public abstract AllocationBeingModified toAllocationBeingModified(
|
||||
Task task, List<Resource> resourcesMatchingCriterions);
|
||||
Task task);
|
||||
|
||||
public boolean isCreating() {
|
||||
return origin == null;
|
||||
|
|
|
|||
|
|
@ -224,14 +224,6 @@ class FormBinder {
|
|||
applyButton.setDisabled(false);
|
||||
}
|
||||
|
||||
public void markGenericAllocationMustBeNoZeroOrMoreAllocations(
|
||||
AllocationDTO allocation) {
|
||||
Decimalbox decimalbox = resourcesPerDayInputsByAllocationDTO
|
||||
.get(allocation);
|
||||
throw new WrongValueException(decimalbox,
|
||||
_("it must be no zero or must add more allocations"));
|
||||
}
|
||||
|
||||
public void markAssignedHoursMustBePositive() {
|
||||
throw new WrongValueException(assignedHoursComponent,
|
||||
_("it must be greater than zero"));
|
||||
|
|
@ -242,14 +234,6 @@ class FormBinder {
|
|||
_("at least one no empty allocation is needed"));
|
||||
}
|
||||
|
||||
public void markNoWorkersMatchedByCriterion(GenericAllocationDTO generic) {
|
||||
Decimalbox decimalbox = resourcesPerDayInputsByAllocationDTO
|
||||
.get(generic);
|
||||
throw new WrongValueException(
|
||||
decimalbox,
|
||||
_("there are no workers for required criteria. So the generic allocation can't be done"));
|
||||
}
|
||||
|
||||
public void setAllocationsList(Listbox allocationsList) {
|
||||
this.allocationsList = allocationsList;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,13 +25,17 @@ import static org.navalplanner.web.I18nHelper._;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.navalplanner.business.planner.entities.GenericResourceAllocation;
|
||||
import org.navalplanner.business.planner.entities.ResourceAllocation;
|
||||
import org.navalplanner.business.planner.entities.ResourcesPerDay;
|
||||
import org.navalplanner.business.planner.entities.Task;
|
||||
import org.navalplanner.business.planner.entities.allocationalgorithms.AllocationBeingModified;
|
||||
import org.navalplanner.business.resources.entities.Criterion;
|
||||
import org.navalplanner.business.resources.entities.Resource;
|
||||
import org.navalplanner.web.resourceload.ResourceLoadModel;
|
||||
|
||||
/**
|
||||
* The information required for creating a {@link GenericResourceAllocation}
|
||||
|
|
@ -39,21 +43,38 @@ import org.navalplanner.business.resources.entities.Resource;
|
|||
*/
|
||||
public class GenericAllocationDTO extends AllocationDTO {
|
||||
|
||||
public static GenericAllocationDTO createDefault() {
|
||||
private static GenericAllocationDTO createDefault() {
|
||||
GenericAllocationDTO result = new GenericAllocationDTO();
|
||||
result.setName(_("Generic"));
|
||||
result.setResourcesPerDay(ResourcesPerDay.amount(0));
|
||||
return result;
|
||||
}
|
||||
|
||||
public static GenericAllocationDTO create(Set<Criterion> criterions,
|
||||
Collection<? extends Resource> resources) {
|
||||
Validate.isTrue(!resources.isEmpty());
|
||||
Validate.notNull(criterions);
|
||||
GenericAllocationDTO result = createDefault();
|
||||
result.criterions = criterions;
|
||||
result.resources = new ArrayList<Resource>(resources);
|
||||
result.setName(ResourceLoadModel.getName(criterions));
|
||||
return result;
|
||||
}
|
||||
|
||||
public static GenericAllocationDTO from(
|
||||
GenericResourceAllocation resourceAllocation) {
|
||||
GenericAllocationDTO result = createDefault();
|
||||
result.setResourcesPerDay(resourceAllocation.getResourcesPerDay());
|
||||
result.setOrigin(resourceAllocation);
|
||||
result.criterions = resourceAllocation.getCriterions();
|
||||
result.resources = resourceAllocation.getAssociatedResources();
|
||||
result.setName(ResourceLoadModel.getName(result.criterions));
|
||||
return result;
|
||||
}
|
||||
|
||||
private Set<Criterion> criterions;
|
||||
private List<Resource> resources;
|
||||
|
||||
@Override
|
||||
public boolean isGeneric() {
|
||||
return true;
|
||||
|
|
@ -71,9 +92,10 @@ public class GenericAllocationDTO extends AllocationDTO {
|
|||
}
|
||||
|
||||
@Override
|
||||
public AllocationBeingModified toAllocationBeingModified(Task task,
|
||||
List<Resource> resources) {
|
||||
return AllocationBeingModified.create(GenericResourceAllocation
|
||||
.create(task), getResourcesPerDay(), resources);
|
||||
public AllocationBeingModified toAllocationBeingModified(Task task) {
|
||||
GenericResourceAllocation genericResourceAllocation = GenericResourceAllocation
|
||||
.create(task, criterions);
|
||||
return AllocationBeingModified.create(genericResourceAllocation,
|
||||
getResourcesPerDay(), this.resources);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
package org.navalplanner.web.planner.allocation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
|
|
@ -88,12 +89,21 @@ public class ResourceAllocationModel implements IResourceAllocationModel {
|
|||
@Transactional(readOnly = true)
|
||||
public void addSpecific(Collection<? extends Resource> resources) {
|
||||
planningState.reassociateResourcesWithSession(resourceDAO);
|
||||
for (Resource each : reloadResources(resources)) {
|
||||
resourceAllocationsBeingEdited
|
||||
.addSpecificResourceAllocationFor(each);
|
||||
}
|
||||
}
|
||||
|
||||
private List<Resource> reloadResources(
|
||||
Collection<? extends Resource> resources) {
|
||||
List<Resource> result = new ArrayList<Resource>();
|
||||
for (Resource each : resources) {
|
||||
Resource reloaded = resourceDAO.findExistingEntity(each.getId());
|
||||
reattachResource(reloaded);
|
||||
resourceAllocationsBeingEdited
|
||||
.addSpecificResourceAllocationFor(reloaded);
|
||||
result.add(reloaded);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -143,10 +153,6 @@ public class ResourceAllocationModel implements IResourceAllocationModel {
|
|||
previousLength);
|
||||
}
|
||||
|
||||
private List<Resource> getResourcesMatchingCriterions() {
|
||||
return resourceDAO.getAllByCriterions(getCriterions());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public ResourceAllocationsBeingEdited initAllocationsFor(Task task,
|
||||
|
|
@ -161,11 +167,10 @@ public class ResourceAllocationModel implements IResourceAllocationModel {
|
|||
loadCriterionsOfGenericAllocations();
|
||||
reattachHoursGroup(this.task.getHoursGroup());
|
||||
reattachCriterions(this.task.getHoursGroup().getValidCriterions());
|
||||
List<AllocationDTO> currentAllocations = addDefaultGenericIfNeeded(AllocationDTO.toDTOs(this.task
|
||||
.getResourceAllocations()));
|
||||
List<AllocationDTO> currentAllocations = AllocationDTO.toDTOs(this.task
|
||||
.getResourceAllocations());
|
||||
resourceAllocationsBeingEdited = ResourceAllocationsBeingEdited
|
||||
.create(task, currentAllocations, resourceDAO,
|
||||
reattachResources(getResourcesMatchingCriterions()));
|
||||
.create(task, currentAllocations, resourceDAO);
|
||||
return resourceAllocationsBeingEdited;
|
||||
}
|
||||
|
||||
|
|
@ -212,14 +217,6 @@ public class ResourceAllocationModel implements IResourceAllocationModel {
|
|||
criterionType.getName();
|
||||
}
|
||||
|
||||
private List<Resource> reattachResources(
|
||||
List<Resource> resourcesMatchingCriterions) {
|
||||
for (Resource resource : resourcesMatchingCriterions) {
|
||||
reattachResource(resource);
|
||||
}
|
||||
return resourcesMatchingCriterions;
|
||||
}
|
||||
|
||||
private void reattachResource(Resource resource) {
|
||||
resourceDAO.reattach(resource);
|
||||
reattachCriterionSatisfactions(resource.getCriterionSatisfactions());
|
||||
|
|
@ -239,16 +236,6 @@ public class ResourceAllocationModel implements IResourceAllocationModel {
|
|||
}
|
||||
}
|
||||
|
||||
private List<AllocationDTO> addDefaultGenericIfNeeded(
|
||||
List<AllocationDTO> dtos) {
|
||||
List<GenericAllocationDTO> currentGeneric = AllocationDTO
|
||||
.getGeneric(dtos);
|
||||
if (currentGeneric.isEmpty()) {
|
||||
dtos.add(0, GenericAllocationDTO.createDefault());
|
||||
}
|
||||
return dtos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AggregatedHoursGroup> getHoursAggregatedByCriterions() {
|
||||
return task.getAggregatedByCriterions();
|
||||
|
|
|
|||
|
|
@ -66,10 +66,8 @@ public class ResourceAllocationsBeingEdited {
|
|||
}
|
||||
|
||||
public static ResourceAllocationsBeingEdited create(Task task,
|
||||
List<AllocationDTO> initialAllocations, IResourceDAO resourceDAO,
|
||||
List<Resource> resourcesBeingEdited) {
|
||||
return new ResourceAllocationsBeingEdited(task, initialAllocations,
|
||||
resourcesBeingEdited);
|
||||
List<AllocationDTO> initialAllocations, IResourceDAO resourceDAO) {
|
||||
return new ResourceAllocationsBeingEdited(task, initialAllocations);
|
||||
}
|
||||
|
||||
private final List<AllocationDTO> currentAllocations;
|
||||
|
|
@ -84,12 +82,9 @@ public class ResourceAllocationsBeingEdited {
|
|||
|
||||
private Integer daysDuration;
|
||||
|
||||
private final List<Resource> resourcesMatchingCriterions;
|
||||
|
||||
private ResourceAllocationsBeingEdited(Task task,
|
||||
List<AllocationDTO> initialAllocations, List<Resource> resourcesMatchingCriterions) {
|
||||
List<AllocationDTO> initialAllocations) {
|
||||
this.task = task;
|
||||
this.resourcesMatchingCriterions = resourcesMatchingCriterions;
|
||||
this.currentAllocations = new ArrayList<AllocationDTO>(
|
||||
initialAllocations);
|
||||
this.calculatedValue = task.getCalculatedValue();
|
||||
|
|
@ -154,16 +149,8 @@ public class ResourceAllocationsBeingEdited {
|
|||
}
|
||||
|
||||
public void checkInvalidValues() {
|
||||
if (thereIsNoEmptyGenericResourceAllocation()
|
||||
&& noWorkersForCriterion()) {
|
||||
formBinder.markNoWorkersMatchedByCriterion(getGenericAllocation());
|
||||
}
|
||||
if (thereIsJustOneEmptyGenericResourceAllocation()) {
|
||||
formBinder
|
||||
.markGenericAllocationMustBeNoZeroOrMoreAllocations(getGenericAllocation());
|
||||
}
|
||||
if (formBinder.getCalculatedValue() != CalculatedValue.NUMBER_OF_HOURS
|
||||
&& formBinder.getAssignedHours() == 0) {
|
||||
&& formBinder.getAssignedHours() <= 0) {
|
||||
formBinder.markAssignedHoursMustBePositive();
|
||||
}
|
||||
if (!thereIsLeastOneNoEmptyAllocation()) {
|
||||
|
|
@ -171,19 +158,6 @@ public class ResourceAllocationsBeingEdited {
|
|||
}
|
||||
}
|
||||
|
||||
private boolean noWorkersForCriterion() {
|
||||
return resourcesMatchingCriterions.isEmpty();
|
||||
}
|
||||
|
||||
private boolean thereIsNoEmptyGenericResourceAllocation() {
|
||||
return !getGenericAllocation().isEmptyResourcesPerDay();
|
||||
}
|
||||
|
||||
private GenericAllocationDTO getGenericAllocation() {
|
||||
return (GenericAllocationDTO) currentAllocations
|
||||
.get(0);
|
||||
}
|
||||
|
||||
private boolean thereIsLeastOneNoEmptyAllocation() {
|
||||
for (AllocationDTO allocationDTO : currentAllocations) {
|
||||
if (!allocationDTO.isEmptyResourcesPerDay()) {
|
||||
|
|
@ -193,12 +167,6 @@ public class ResourceAllocationsBeingEdited {
|
|||
return false;
|
||||
}
|
||||
|
||||
private boolean thereIsJustOneEmptyGenericResourceAllocation() {
|
||||
return currentAllocations.size() == 1
|
||||
&& getGenericAllocation().isGeneric()
|
||||
&& getGenericAllocation().isEmptyResourcesPerDay();
|
||||
}
|
||||
|
||||
public AllocationResult doAllocation() {
|
||||
checkInvalidValues();
|
||||
Map<AllocationBeingModified, ResourceAllocation<?>> fromDetachedToAttached = getAllocationsWithRelationshipsToOriginal();
|
||||
|
|
@ -247,7 +215,7 @@ public class ResourceAllocationsBeingEdited {
|
|||
|
||||
private AllocationBeingModified instantiate(
|
||||
AllocationDTO key) {
|
||||
return key.toAllocationBeingModified(task, resourcesMatchingCriterions);
|
||||
return key.toAllocationBeingModified(task);
|
||||
}
|
||||
|
||||
private Integer from(Date startDate, LocalDate end) {
|
||||
|
|
|
|||
|
|
@ -99,8 +99,7 @@ public class SpecificAllocationDTO extends AllocationDTO {
|
|||
private Resource resource;
|
||||
|
||||
@Override
|
||||
public AllocationBeingModified toAllocationBeingModified(Task task,
|
||||
List<Resource> resources) {
|
||||
public AllocationBeingModified toAllocationBeingModified(Task task) {
|
||||
SpecificResourceAllocation specific = SpecificResourceAllocation
|
||||
.create(task);
|
||||
specific.setResource(resource);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue