[Bug #899] Show tag GENERIC_MACHINES

* Add toString() in some classes
* Show criteria name and criteria type for resource allocations of type generic

FEA : ItEr71S04BugFixing
This commit is contained in:
Diego Pino Garcia 2011-02-25 16:00:25 +01:00
parent 6833231705
commit 768cf47ee2
8 changed files with 74 additions and 19 deletions

View file

@ -119,7 +119,7 @@ public class Criterion extends IntegrationEntity implements ICriterion {
return getCaptionFor(ResourceEnum.WORKER, criteria);
}
public static String getCaptionForCriterionsFrom(
public static String getCaptionFor(
GenericResourceAllocation allocation) {
return getCaptionFor(allocation.getResourceType(),
allocation.getCriterions());
@ -138,7 +138,7 @@ public class Criterion extends IntegrationEntity implements ICriterion {
}
List<String> result = new ArrayList<String>();
for (Criterion each : criteria) {
result.add(each.getName());
result.add(each.getCompleteName());
}
return StringUtils.join(result, ",");
}
@ -395,4 +395,10 @@ public class Criterion extends IntegrationEntity implements ICriterion {
public Boolean isCodeAutogenerated() {
return getType() != null ? getType().isCodeAutogenerated() : false;
}
@Override
public String toString() {
return String.format("%s :: %s", type, name);
}
}

View file

@ -551,4 +551,9 @@ public class CriterionType extends IntegrationEntity implements
+ EntitySequence.CODE_SEPARATOR_CHILDREN + criterionCode);
}
}
public String toString() {
return name;
}
}

View file

@ -136,4 +136,10 @@ public class Machine extends Resource {
public ResourceEnum getType() {
return type;
}
@Override
public String toString() {
return String.format("MACHINE: %s", name);
}
}

View file

@ -55,6 +55,7 @@ import org.navalplanner.business.common.exceptions.ValidationException;
import org.navalplanner.business.costcategories.entities.ResourcesCostCategoryAssignment;
import org.navalplanner.business.planner.entities.AvailabilityCalculator;
import org.navalplanner.business.planner.entities.DayAssignment;
import org.navalplanner.business.planner.entities.ResourceAllocation;
import org.navalplanner.business.resources.daos.IResourceDAO;
import org.navalplanner.business.scenarios.entities.Scenario;
import org.navalplanner.business.workingday.EffortDuration;
@ -114,6 +115,10 @@ public abstract class Resource extends IntegrationEntity {
return resources;
}
public static String getCaptionFor(ResourceAllocation<?> resourceAllocation) {
return getCaptionFor(resourceAllocation.getAssociatedResources());
}
public static String getCaptionFor(List<Resource> resources) {
List<String> values = new ArrayList<String>();
for (Resource each: resources) {

View file

@ -249,7 +249,7 @@ public class LimitingResourcesController extends GenericForwardComposer {
return (resource != null) ? resource.getName() : "";
} else if (resourceAllocation instanceof GenericResourceAllocation) {
GenericResourceAllocation genericAllocation = (GenericResourceAllocation) resourceAllocation;
return Criterion.getCaptionForCriterionsFrom(genericAllocation);
return Criterion.getCaptionFor(genericAllocation);
}
return StringUtils.EMPTY;
}

View file

@ -90,7 +90,7 @@ public class GenericAllocationRow extends AllocationRow {
.byCriteria(resourceAllocation.getCriterions())
.byResourceType(type).execute());
result.setName(Criterion
.getCaptionForCriterionsFrom(resourceAllocation));
.getCaptionFor(resourceAllocation));
return result;
}

View file

@ -26,7 +26,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.navalplanner.business.planner.entities.GenericResourceAllocation;
import org.navalplanner.business.planner.entities.ResourceAllocation;
@ -35,6 +34,7 @@ import org.navalplanner.business.planner.entities.Task;
import org.navalplanner.business.resources.entities.Criterion;
import org.navalplanner.business.resources.entities.Resource;
import org.navalplanner.business.resources.entities.ResourceEnum;
import org.navalplanner.business.resources.entities.Worker;
import org.navalplanner.web.common.components.NewAllocationSelector.AllocationType;
/**
@ -127,8 +127,19 @@ public class LimitingAllocationRow {
}
public AllocationType getAllocationType() {
return (resourceAllocation instanceof SpecificResourceAllocation) ? AllocationType.SPECIFIC
: AllocationType.GENERIC_WORKERS;
if (resourceAllocation instanceof SpecificResourceAllocation) {
return AllocationType.SPECIFIC;
} else if (isWorker()) {
return AllocationType.GENERIC_WORKERS;
}
return AllocationType.GENERIC_MACHINES;
}
public boolean isWorker() {
if (resources != null && !resources.isEmpty()) {
return ((Resource) resources.iterator().next()) instanceof Worker;
}
return false;
}
public String getAllocationTypeStr() {
@ -137,24 +148,17 @@ public class LimitingAllocationRow {
public String getAllocation() {
final AllocationType type = getAllocationType();
if (AllocationType.GENERIC_WORKERS.equals(type)) {
final GenericResourceAllocation generic = (GenericResourceAllocation) resourceAllocation;
return Criterion.getCaptionForCriterionsFrom(generic);
if (AllocationType.GENERIC_WORKERS.equals(type)
|| AllocationType.GENERIC_MACHINES.equals(type)) {
return Criterion
.getCaptionFor((GenericResourceAllocation) resourceAllocation);
}
if (AllocationType.SPECIFIC.equals(type)) {
return formatResources(resourceAllocation.getAssociatedResources());
return Resource.getCaptionFor(resourceAllocation);
}
return "";
}
private String formatResources(List<Resource> resources) {
List<String> resourcesNames = new ArrayList<String>();
for (Resource each: resources) {
resourcesNames.add(each.getName());
}
return StringUtils.join(resourcesNames, ",");
}
public int getHours() {
return hours;
}

View file

@ -29,6 +29,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Set;
import org.hibernate.Hibernate;
import org.navalplanner.business.common.IAdHocTransactionService;
import org.navalplanner.business.common.IOnTransaction;
import org.navalplanner.business.orders.daos.IHoursGroupDAO;
@ -37,6 +38,7 @@ import org.navalplanner.business.orders.entities.HoursGroup;
import org.navalplanner.business.orders.entities.TaskSource;
import org.navalplanner.business.planner.daos.ITaskElementDAO;
import org.navalplanner.business.planner.daos.ITaskSourceDAO;
import org.navalplanner.business.planner.entities.GenericResourceAllocation;
import org.navalplanner.business.planner.entities.ResourceAllocation;
import org.navalplanner.business.planner.entities.Task;
import org.navalplanner.business.planner.entities.TaskElement;
@ -96,14 +98,40 @@ public class LimitingResourceAllocationModel implements ILimitingResourceAllocat
private LimitingResourceAllocationController limitingResourceAllocationController;
@Override
@Transactional(readOnly=true)
public void init(IContextWithPlannerTask<TaskElement> context, Task task,
PlanningState planningState) {
this.context = context;
this.task = task;
this.planningState = planningState;
initializeCriteria(task);
limitingAllocationRows = LimitingAllocationRow.toRows(task);
}
private void initializeCriteria(Task task) {
for (ResourceAllocation<?> each: task.getLimitingResourceAllocations()) {
if (isGeneric(each)) {
initializeCriteria((GenericResourceAllocation) each);
}
}
}
private boolean isGeneric(ResourceAllocation<?> resourceAllocation) {
return resourceAllocation instanceof GenericResourceAllocation;
}
private void initializeCriteria(GenericResourceAllocation generic) {
for (Criterion each : generic.getCriterions()) {
initializeCriterion(each);
}
}
private void initializeCriterion(Criterion criterion) {
criterionDAO.reattach(criterion);
Hibernate.initialize(criterion.getType());
}
@Override
@Transactional(readOnly=true)
public Integer getOrderHours() {
@ -118,6 +146,7 @@ public class LimitingResourceAllocationModel implements ILimitingResourceAllocat
public void addGeneric(ResourceEnum resourceType,
Collection<? extends Criterion> criteria,
Collection<? extends Resource> resources) {
if (resources.isEmpty()) {
getMessagesForUser()
.showMessage(Level.ERROR,