use of com.qcadoo.model.api.EntityTreeNode in project mes by qcadoo.
the class TechnologyOperationComponentHooks method copyReferencedTechnology.
private void copyReferencedTechnology(final DataDefinition technologyOperationComponentDD, final Entity technologyOperationComponent) {
if (Objects.isNull(technologyOperationComponent.getField(TechnologyOperationComponentFields.REFERENCE_TECHNOLOGY))) {
return;
}
Entity technology = technologyOperationComponent.getBelongsToField(TechnologyOperationComponentFields.TECHNOLOGY);
Entity referencedTechnology = technologyOperationComponent.getBelongsToField(TechnologyOperationComponentFields.REFERENCE_TECHNOLOGY);
Set<Long> technologies = Sets.newHashSet();
technologies.add(technology.getId());
boolean isCyclic = checkForCyclicReferences(technologies, referencedTechnology);
if (isCyclic) {
technologyOperationComponent.addError(technologyOperationComponentDD.getField(TechnologyOperationComponentFields.REFERENCE_TECHNOLOGY), "technologies.technologyReferenceTechnologyComponent.error.cyclicDependency");
return;
}
EntityTreeNode root = referencedTechnology.getTreeField(TechnologyFields.OPERATION_COMPONENTS).getRoot();
if (Objects.isNull(root)) {
technologyOperationComponent.addError(technologyOperationComponentDD.getField(TechnologyOperationComponentFields.REFERENCE_TECHNOLOGY), "technologies.technologyReferenceTechnologyComponent.error.operationComponentsEmpty");
return;
}
Entity copiedRoot = copyReferencedTechnologyOperations(root, technologyOperationComponent.getBelongsToField(TechnologyOperationComponentFields.TECHNOLOGY));
for (Entry<String, Object> entry : copiedRoot.getFields().entrySet()) {
if (!(entry.getKey().equals("id") || entry.getKey().equals(TechnologyOperationComponentFields.PARENT))) {
technologyOperationComponent.setField(entry.getKey(), entry.getValue());
}
}
technologyOperationComponent.setField(TechnologyOperationComponentFields.REFERENCE_TECHNOLOGY, null);
}
use of com.qcadoo.model.api.EntityTreeNode in project mes by qcadoo.
the class TechnologyTreeValidationServiceImpl method collectChildrenProducingManyParentInputs.
private void collectChildrenProducingManyParentInputs(final Map<String, Set<String>> parentToChildrenMap, final EntityTreeNode parentOperation) {
final Set<Long> parentInProductIds = getProductIdsFromOperationComponent(parentOperation, TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS);
for (EntityTreeNode subOperation : parentOperation.getChildren()) {
final Set<Long> childOutProductIds = getProductIdsFromOperationComponent(subOperation, TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS);
if (hasMoreThanOneCommonProduct(parentInProductIds, childOutProductIds)) {
appendNodeNumbersToMap(parentToChildrenMap, parentOperation, subOperation);
}
collectChildrenProducingManyParentInputs(parentToChildrenMap, subOperation);
}
}
use of com.qcadoo.model.api.EntityTreeNode in project mes by qcadoo.
the class TechnologyTreeValidationServiceImpl method checkConsumingManyProductsFromOneSubOp.
@Override
public final Map<String, Set<String>> checkConsumingManyProductsFromOneSubOp(final EntityTree technologyTree) {
final Map<String, Set<String>> parentToChildrenMap = Maps.newHashMap();
if (Objects.nonNull(technologyTree) && !technologyTree.isEmpty()) {
final EntityTreeNode rootNode = technologyTree.getRoot();
collectChildrenProducingManyParentInputs(parentToChildrenMap, rootNode);
}
return parentToChildrenMap;
}
use of com.qcadoo.model.api.EntityTreeNode in project qcadoo by qcadoo.
the class EntityTreeUtilsServiceTest method shouldReturnListOfNodesInTheSameOrderAsTheyAppearOnTheTree.
@Test
public final void shouldReturnListOfNodesInTheSameOrderAsTheyAppearOnTheTree() throws Exception {
// given
EntityTreeNode l1b1a11 = mockEntityTreeNode(null, 1, "1.B.1.A.11");
EntityTreeNode l1b1a10 = mockEntityTreeNode(Lists.newArrayList(l1b1a11), 1, "1.B.1.A.10");
EntityTreeNode l1b1a9 = mockEntityTreeNode(Lists.newArrayList(l1b1a10), 1, "1.B.1.A.9");
EntityTreeNode l1b1a8 = mockEntityTreeNode(Lists.newArrayList(l1b1a9), 1, "1.B.1.A.8");
EntityTreeNode l1b1a7 = mockEntityTreeNode(Lists.newArrayList(l1b1a8), 1, "1.B.1.A.7");
EntityTreeNode l1b1a6 = mockEntityTreeNode(Lists.newArrayList(l1b1a7), 1, "1.B.1.A.6");
EntityTreeNode l1b1a5 = mockEntityTreeNode(Lists.newArrayList(l1b1a6), 1, "1.B.1.A.5");
EntityTreeNode l1b1a4 = mockEntityTreeNode(Lists.newArrayList(l1b1a5), 1, "1.B.1.A.4");
EntityTreeNode l1b1a3 = mockEntityTreeNode(Lists.newArrayList(l1b1a4), 1, "1.B.1.A.3");
EntityTreeNode l1b1a2 = mockEntityTreeNode(Lists.newArrayList(l1b1a3), 1, "1.B.1.A.2");
EntityTreeNode l1b1a1 = mockEntityTreeNode(Lists.newArrayList(l1b1a2), 1, "1.B.1.A.1");
EntityTreeNode l1b1b1 = mockEntityTreeNode(null, 2, "1.B.1.B.1");
EntityTreeNode l1a1 = mockEntityTreeNode(null, 1, "1.A.1");
EntityTreeNode l1b1 = mockEntityTreeNode(Lists.newLinkedList(Lists.newArrayList(l1b1b1, l1b1a1)), 2, "1.B.1");
EntityTreeNode root = mockEntityTreeNode(Lists.newLinkedList(Lists.newArrayList(l1a1, l1b1)), 1, "1");
given(tree.getRoot()).willReturn(root);
given(tree.isEmpty()).willReturn(false);
// when
List<Entity> nodesList = entityTreeUtils.getSortedEntities(tree);
// then
Assert.assertEquals(15, nodesList.size());
Assert.assertEquals("1", nodesList.get(0).getField("nodeNumber"));
Assert.assertEquals("1.A.1", nodesList.get(1).getField("nodeNumber"));
Assert.assertEquals("1.B.1", nodesList.get(2).getField("nodeNumber"));
Assert.assertEquals("1.B.1.A.1", nodesList.get(3).getField("nodeNumber"));
Assert.assertEquals("1.B.1.A.2", nodesList.get(4).getField("nodeNumber"));
Assert.assertEquals("1.B.1.A.3", nodesList.get(5).getField("nodeNumber"));
Assert.assertEquals("1.B.1.A.4", nodesList.get(6).getField("nodeNumber"));
Assert.assertEquals("1.B.1.A.5", nodesList.get(7).getField("nodeNumber"));
Assert.assertEquals("1.B.1.A.6", nodesList.get(8).getField("nodeNumber"));
Assert.assertEquals("1.B.1.A.7", nodesList.get(9).getField("nodeNumber"));
Assert.assertEquals("1.B.1.A.8", nodesList.get(10).getField("nodeNumber"));
Assert.assertEquals("1.B.1.A.9", nodesList.get(11).getField("nodeNumber"));
Assert.assertEquals("1.B.1.A.10", nodesList.get(12).getField("nodeNumber"));
Assert.assertEquals("1.B.1.A.11", nodesList.get(13).getField("nodeNumber"));
Assert.assertEquals("1.B.1.B.1", nodesList.get(14).getField("nodeNumber"));
}
use of com.qcadoo.model.api.EntityTreeNode in project qcadoo by qcadoo.
the class EntityTreeUtilsServiceTest method mockEntityTreeNode.
private EntityTreeNode mockEntityTreeNode(final List<EntityTreeNode> children, final int priority, final String nodeNumber) {
EntityTreeNode node = mock(EntityTreeNode.class);
given(node.getField(PRIORITY)).willReturn(priority);
given(node.getChildren()).willReturn(children == null ? new ArrayList<EntityTreeNode>() : children);
given(node.getStringField("nodeNumber")).willReturn(nodeNumber);
given(node.getField("nodeNumber")).willReturn(nodeNumber);
return node;
}
Aggregations