示例#1
0
    private static String createTooltiptext(LimitingResourceQueueElement element) {
        final Task task = element.getResourceAllocation().getTask();
        final OrderElement order = getRootOrder(task);

        StringBuilder result = new StringBuilder();
        result.append(_("Project: {0}", order.getName())).append(" ");
        result.append(_("Task: {0}", task.getName())).append(" ");
        result.append(_("Completed: {0}%", element.getAdvancePercentage().multiply(new BigDecimal(100)))).append(" ");

        final ResourceAllocation<?> resourceAllocation = element.getResourceAllocation();

        if ( resourceAllocation instanceof SpecificResourceAllocation ) {

            final SpecificResourceAllocation specific = (SpecificResourceAllocation) resourceAllocation;
            result.append(_("Resource: {0}", specific.getResource().getName())).append(" ");

        } else if ( resourceAllocation instanceof GenericResourceAllocation ) {

            final GenericResourceAllocation generic = (GenericResourceAllocation) resourceAllocation;

            /* TODO resolve deprecated */
            result.append(_("Criteria: {0}", Criterion.getCaptionFor(generic.getCriterions()))).append(" ");

        }
        result.append(_("Allocation: [{0},{1}]", element.getStartDate().toString(), element.getEndDate()));

        return result.toString();
    }
    public static GenericAllocationRow create(CalculatedValue calculatedValue,
            ResourceEnum resourceType,
            Collection<? extends Criterion> criterions,
            Collection<? extends Resource> resources) {

        GenericAllocationRow result = new GenericAllocationRow(calculatedValue);
        Validate.isTrue(!resources.isEmpty());
        Validate.notNull(criterions);
        initializeDefault(result, resourceType);
        result.criterions = new HashSet<Criterion>(criterions);
        result.resources = new ArrayList<Resource>(resources);
        result.setName(Criterion.getCaptionFor(resourceType, criterions));
        return result;
    }
    public static GenericAllocationRow from(
            GenericResourceAllocation resourceAllocation,
            IResourcesSearcher searchModel) {
        GenericAllocationRow result = initializeDefault(
                new GenericAllocationRow(resourceAllocation),
                resourceAllocation.getResourceType());

        ResourceType type = resourceAllocation.isLimiting() ?
                ResourceType.LIMITING_RESOURCE :
                ResourceType.NON_LIMITING_RESOURCE;

        result.criterions = resourceAllocation.getCriterions();
        result.resources = new ArrayList<Resource>(searchModel
                .searchBy(resourceAllocation.getResourceType())
                .byCriteria(resourceAllocation.getCriterions())
                .byResourceType(type).execute());
        result.setName(Criterion
                .getCaptionFor(resourceAllocation));
        return result;
    }
    @Override
    @Transactional(readOnly = true)
    public void addGeneric(ResourceEnum resourceType,
            Collection<? extends Criterion> criteria,
            Collection<? extends Resource> resources) {

        if (resources.isEmpty()) {
            getMessagesForUser()
                    .showMessage(Level.ERROR,
                            _("there are no resources for required criteria: {0}. " +
                                    "So the generic allocation can't be added",
                            Criterion.getCaptionFor(resourceType, criteria)));
        }

        if (resources.size() >= 1) {
            if (planningState != null) {
                planningState.reassociateResourcesWithSession();
            }
            addGenericResourceAllocation(resourceType, criteria,
                    reloadResources(resources));
        }
    }