public static ResourceEnum inferType(Collection<? extends Criterion> criterions) { if (criterions.isEmpty()) { return ResourceEnum.WORKER; } Criterion first = criterions.iterator().next(); return first.getType().getResource(); }
@Test @Transactional public void afterRemovingTheCriterionNoLongerExists() throws InstanceNotFoundException { givenACriterionWithAnExistentType(); criterionDAO.save(criterion); criterionDAO.remove(criterion.getId()); assertFalse(criterionDAO.exists(criterion.getId())); }
public static Set<Criterion> withAllDescendants( Collection<? extends Criterion> originalCriteria) { Set<Criterion> result = new HashSet<Criterion>(); for (Criterion each : originalCriteria) { result.add(each); result.addAll(withAllDescendants(each.getChildren())); } return result; }
@Override public int compare(Criterion o1, Criterion o2) { if (o1.getName() == null) { return 1; } if (o2.getName() == null) { return -1; } return o1.getName().toLowerCase() .compareTo(o2.getName().toLowerCase()); }
public boolean includes(Criterion other) { if (isEquivalent(other)) { return true; } for (Criterion each : this.getChildren()) { if (each.includes(other)) { return true; } } return false; }
@Override public int compare(Criterion o1, Criterion o2) { if (o1.isEquivalent(o2)) { return 0; } if (o1.includes(o2)) { return -1; } else { return 1; } }
/** * Returns a string of criterion names separated by comma * @param resourceType * @param criteria * @return */ public static String getCaptionFor(ResourceEnum resourceType, Collection<? extends Criterion> criteria) { if (criteria.isEmpty()) { return allCaptionFor(resourceType); } List<String> result = new ArrayList<String>(); for (Criterion each : criteria) { result.add(each.getCompleteName()); } return StringUtils.join(result, ","); }
@AssertTrue(message="a disabled resource has enabled subresources") public boolean isActiveConstraint() { if (!active) { for (Criterion c : children) { if (c.isActive()) { return false; } } } return true; }
@Test public void ifItsDifferentThereIsOther() { Criterion c = transactionService.runOnTransaction( new IOnTransaction<Criterion>() { @Override public Criterion execute() { return givenASavedCriterionWithAnExistentType(); } }); Criterion copy = Criterion.create(c.getName(), c.getType()); assertTrue(criterionDAO.thereIsOtherWithSameNameAndType(copy)); }
private void searchInCriterions(CriterionType type, String filter) { List<Criterion> list = getMapCriterions().get(type); if (list == null) { return; } for (Criterion criterion : list) { String name = StringUtils.deleteWhitespace(criterion.getName().toLowerCase()); if (name.contains(filter)) { addCriterion(type, criterion); if ((filter.length() < 3) && (getListMatching().size() > 9)) { return; } } } }
public static Criterion createUnvalidated(String code, String name, CriterionType type, Criterion parent, Boolean active) { Criterion criterion = create(new Criterion(), code); criterion.name = name; criterion.type = type; criterion.parent = parent; if (active != null) { criterion.active = active; } return criterion; }
@Test @Transactional public void afterSavingACriterionItExists() { givenACriterionWithAnExistentType(); criterionDAO.save(criterion); assertTrue(criterionDAO.exists(criterion.getId())); }
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(); }
private void addCriterion(CriterionType type, Criterion criterion) { String pattern = criterion.getName() + " ( " + type.getName() + " )"; getListMatching() .add( new FilterPair( TaskElementFilterEnum.Criterion, type.getResource().toLowerCase(), pattern, criterion)); }
public boolean isEquivalentOrIncludedIn(Criterion other) { if (isEquivalent(other)) { return true; } for (Criterion each : other.getChildren()) { if (isEquivalentOrIncludedIn(each)) { return true; } } return false; }
public void moveTo(Criterion newParent) { if (parent == null) { if (newParent != null) { parent = newParent; parent.getChildren().add(this); } } else { // parent != null if (!parent.equals(newParent)) { parent.getChildren().remove(this); parent = newParent; if (parent != null) { parent.getChildren().add(this); } } } }
private boolean isNew(Collection<? extends Criterion> criteria, Collection<? extends Resource> resources) { LimitingAllocationRow allocationRow = getLimitingAllocationRow(); if (allocationRow == null || allocationRow.isSpecific()) { return true; } Set<Long> allocatedResourcesIds = allocationRow.getResourcesIds(); for (Resource each: resources) { if (!allocatedResourcesIds.contains(each.getId())) { return true; } } Set<Long> allocatedCriteriaIds = allocationRow.getCriteriaIds(); for (Criterion each: criteria) { if (!allocatedCriteriaIds.contains(each.getId())) { return true; } } return false; }
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)); } }
private void reattachCriterion(Criterion criterion) { criterionDAO.reattachUnmodifiedEntity(criterion); criterion.getName(); reattachCriterionType(criterion.getType()); }
private void initializeCriterion(Criterion criterion) { criterionDAO.reattach(criterion); Hibernate.initialize(criterion.getType()); }
public static Criterion createPredefined(String name, CriterionType type) { Criterion result = create(name, type); result.predefinedCriterionInternalName = name; return result; }
public static Criterion createValidCriterion(String name, String description) { CriterionType criterionType = CriterionTypeDAOTest.createValidCriterionType(); return Criterion.withNameAndType(name, criterionType); }
private Criterion anotherCriterionWithSameNameAndType(Criterion c) { return Criterion.create(c.getName(), c.getType()); }
public boolean isEquivalent(Criterion other) { return new EqualsBuilder().append(getName(), other.getName()) .append(getType(), other.getType()).isEquals(); }
@Override public int compareTo(Criterion o) { return toString().compareToIgnoreCase(o.toString()); }