use of com.qcadoo.model.api.EntityTree in project mes by qcadoo.
the class ProductStructureTreeService method generateProductStructureTree.
public EntityTree generateProductStructureTree(final ViewDefinitionState view, final Entity technology) {
Entity product = technology.getBelongsToField(TechnologyFields.PRODUCT);
Entity operation = findOperationForProductAndTechnology(product, technology);
Entity technologyFromDB = technology.getDataDefinition().get(technology.getId());
EntityTree tree = technologyFromDB.getTreeField(TechnologyFields.PRODUCT_STRUCTURE_TREE);
if (Objects.nonNull(tree.getRoot())) {
Date productStructureCreateDate = tree.getRoot().getDateField(ProductStructureTreeNodeFields.CREATE_DATE);
List<Entity> treeEntities = tree.find().list().getEntities();
Entity technologyStateChange = getLastTechnologyStateChange(technologyFromDB);
if (productStructureCreateDate.before(technologyStateChange.getDateField(TechnologyStateChangeFields.DATE_AND_TIME)) || checkSubTechnologiesSubstitution(treeEntities) || checkIfSubTechnologiesChanged(operation, productStructureCreateDate)) {
deleteProductStructureTree(treeEntities);
} else {
return tree;
}
}
Entity root = getProductStructureTreeNodeDD().create();
BigDecimal quantity = findQuantityOfProductInOperation(null, product, operation);
Entity technologyGroup = technology.getBelongsToField(TechnologyFields.TECHNOLOGY_GROUP);
BigDecimal standardPerformance = technologyService.getStandardPerformance(technology).orElse(null);
root.setField(ProductStructureTreeNodeFields.TECHNOLOGY, technology);
root.setField(ProductStructureTreeNodeFields.MAIN_TECHNOLOGY, technology);
root.setField(ProductStructureTreeNodeFields.PRODUCT, product);
root.setField(ProductStructureTreeNodeFields.OPERATION, operation);
root.setField(ProductStructureTreeNodeFields.QUANTITY, quantity);
root.setField(ProductStructureTreeNodeFields.DIVISION, operation.getBelongsToField(TechnologyOperationComponentFields.DIVISION));
root.setField(ProductStructureTreeNodeFields.TECHNOLOGY_GROUP, technologyGroup);
root.setField(ProductStructureTreeNodeFields.STANDARD_PERFORMANCE, standardPerformance);
List<Entity> productStructureList = Lists.newArrayList();
root = addChild(productStructureList, root, null, L_FINAL_PRODUCT);
generateTreeForSubProducts(operation, technology, productStructureList, root, view, technology);
technologyFromDB = technology.getDataDefinition().get(technology.getId());
return technologyFromDB.getTreeField(TechnologyFields.PRODUCT_STRUCTURE_TREE);
}
use of com.qcadoo.model.api.EntityTree in project mes by qcadoo.
the class TechnologyTreeBuildServiceImplTest method shouldBuildTree.
@Test
public final void shouldBuildTree() {
// given
TocHolder customTreeRoot = mockCustomTreeRepresentation();
// when
EntityTree tree = treeBuildService.build(customTreeRoot, new TestTreeAdapter());
// then
EntityTreeNode root = tree.getRoot();
assertNotNull(root);
Entity toc1 = extractEntity(root);
verify(toc1).setField(TechnologyOperationComponentFields.OPERATION, toc1op);
verify(toc1).setField(Mockito.eq(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS), toc1opicCaptor.capture());
Collection<Entity> toc1opics = toc1opicCaptor.getValue();
assertEquals(1, toc1opics.size());
Entity toc1opic = toc1opics.iterator().next();
verify(toc1opic).setField(OperationProductInComponentFields.QUANTITY, BigDecimal.ONE);
verify(toc1opic).setField(OperationProductInComponentFields.PRODUCT, toc1opic1prod);
verify(toc1).setField(Mockito.eq(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS), toc1opocCaptor.capture());
Collection<Entity> toc1opocs = toc1opocCaptor.getValue();
assertEquals(1, toc1opocs.size());
Entity toc1opoc = toc1opocs.iterator().next();
verify(toc1opoc).setField(OperationProductInComponentFields.QUANTITY, BigDecimal.ONE);
verify(toc1opoc).setField(OperationProductInComponentFields.PRODUCT, toc1opoc1prod);
verify(toc1).setField(Mockito.eq(TechnologyOperationComponentFields.CHILDREN), toc1childrenCaptor.capture());
Collection<Entity> toc1children = toc1childrenCaptor.getValue();
assertEquals(1, toc1children.size());
Entity toc2 = toc1children.iterator().next();
verify(toc2).setField(TechnologyOperationComponentFields.OPERATION, toc2op);
verify(toc2).setField(Mockito.eq(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS), toc2opicCaptor.capture());
Collection<Entity> toc2opics = toc2opicCaptor.getValue();
assertEquals(1, toc2opics.size());
Entity toc2opic = toc2opics.iterator().next();
verify(toc2opic).setField(OperationProductInComponentFields.QUANTITY, BigDecimal.ONE);
verify(toc2opic).setField(OperationProductInComponentFields.PRODUCT, toc2opic1prod);
verify(toc2).setField(Mockito.eq(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS), toc2opocCaptor.capture());
Collection<Entity> toc2opocs = toc2opocCaptor.getValue();
assertEquals(1, toc2opocs.size());
Entity toc2opoc = toc2opocs.iterator().next();
verify(toc2opoc).setField(OperationProductInComponentFields.QUANTITY, BigDecimal.ONE);
verify(toc2opoc).setField(OperationProductInComponentFields.PRODUCT, toc2opoc1prod);
verify(toc2).setField(Mockito.eq(TechnologyOperationComponentFields.CHILDREN), toc2childrenCaptor.capture());
Collection<Entity> toc2children = toc2childrenCaptor.getValue();
assertTrue(toc2children.isEmpty());
}
use of com.qcadoo.model.api.EntityTree in project mes by qcadoo.
the class ProductQuantitiesServiceImplTest method mockEntityTreeIterator.
private static EntityTree mockEntityTreeIterator(List<Entity> list) {
EntityTree entityTree = mock(EntityTree.class);
when(entityTree.iterator()).thenReturn(list.iterator());
return entityTree;
}
use of com.qcadoo.model.api.EntityTree in project mes by qcadoo.
the class TechnologiesTechnologyDetailsXlsView method addOrderSeries.
private void addOrderSeries(final Map<String, Object> model, final HSSFSheet sheet, final Locale locale) {
checkState(model.get("id") != null, "Unable to generate report for unsaved technology! (missing id)");
DataDefinition technologyDD = dataDefinitionService.get(PLUGIN_IDENTIFIER, MODEL_TECHNOLOGY);
Entity technology = technologyDD.get(valueOf(model.get("id").toString()));
EntityTree technologyTree = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS);
treeNumberingService.generateTreeNumbers(technologyTree);
List<Entity> technologyOperationsList = entityTreeUtilsService.getSortedEntities(technologyTree);
int rowNum = 1;
for (Entity technologyOperation : technologyOperationsList) {
String nodeNumber = technologyOperation.getStringField(TechnologyOperationComponentFields.NODE_NUMBER);
String operationName = technologyOperation.getBelongsToField(TechnologyOperationComponentFields.OPERATION).getStringField(OperationFields.NAME);
List<Entity> operationProductComponents = Lists.newLinkedList();
operationProductComponents.addAll(technologyOperation.getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS));
operationProductComponents.addAll(technologyOperation.getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS));
rowNum = addProducts(sheet, locale, rowNum, nodeNumber, operationName, operationProductComponents);
}
sheet.autoSizeColumn((short) 0);
sheet.autoSizeColumn((short) 1);
sheet.autoSizeColumn((short) 2);
sheet.autoSizeColumn((short) 3);
sheet.autoSizeColumn((short) 4);
sheet.autoSizeColumn((short) 5);
sheet.autoSizeColumn((short) 6);
sheet.autoSizeColumn((short) 7);
}
use of com.qcadoo.model.api.EntityTree in project mes by qcadoo.
the class TechnologyProductStructureDeletingAspect method postHookOnDraft.
@RunInPhase(TechnologyStateChangePhase.LAST)
@RunForStateTransitions({ @RunForStateTransition(targetState = TechnologyStateStringValues.DRAFT) })
@After(PHASE_EXECUTION_POINTCUT)
public void postHookOnDraft(final StateChangeContext stateChangeContext, final int phase) {
Entity technology = stateChangeContext.getOwner();
Entity technologyFromDB = technology.getDataDefinition().get(technology.getId());
EntityTree tree = technologyFromDB.getTreeField(TechnologyFields.PRODUCT_STRUCTURE_TREE);
if (tree.getRoot() != null) {
List<Entity> treeEntities = tree.find().list().getEntities();
for (Entity entity : treeEntities) {
entity.getDataDefinition().delete(entity.getId());
}
}
}
Aggregations