Search in sources :

Example 16 with EntityTree

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);
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityTree(com.qcadoo.model.api.EntityTree) Date(java.util.Date) BigDecimal(java.math.BigDecimal)

Example 17 with EntityTree

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());
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityTreeNode(com.qcadoo.model.api.EntityTreeNode) EntityTree(com.qcadoo.model.api.EntityTree) Test(org.junit.Test)

Example 18 with EntityTree

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;
}
Also used : EntityTree(com.qcadoo.model.api.EntityTree)

Example 19 with 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);
}
Also used : Entity(com.qcadoo.model.api.Entity) DataDefinition(com.qcadoo.model.api.DataDefinition) EntityTree(com.qcadoo.model.api.EntityTree)

Example 20 with EntityTree

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());
        }
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityTree(com.qcadoo.model.api.EntityTree) After(org.aspectj.lang.annotation.After) RunInPhase(com.qcadoo.mes.states.annotation.RunInPhase) RunForStateTransitions(com.qcadoo.mes.states.annotation.RunForStateTransitions)

Aggregations

EntityTree (com.qcadoo.model.api.EntityTree)52 Entity (com.qcadoo.model.api.Entity)44 Test (org.junit.Test)14 DataDefinition (com.qcadoo.model.api.DataDefinition)10 FormComponent (com.qcadoo.view.api.components.FormComponent)10 BigDecimal (java.math.BigDecimal)8 Map (java.util.Map)7 EntityList (com.qcadoo.model.api.EntityList)6 List (java.util.List)6 Autowired (org.springframework.beans.factory.annotation.Autowired)6 Service (org.springframework.stereotype.Service)6 EntityTreeNode (com.qcadoo.model.api.EntityTreeNode)5 WindowComponent (com.qcadoo.view.api.components.WindowComponent)4 Set (java.util.Set)4 Sets (com.google.common.collect.Sets)3 ProductQuantitiesService (com.qcadoo.mes.technologies.ProductQuantitiesService)3 Date (java.util.Date)3 Locale (java.util.Locale)3 Lists (com.google.common.collect.Lists)2 Maps (com.google.common.collect.Maps)2