Search in sources :

Example 91 with EntityList

use of com.qcadoo.model.api.EntityList in project mes by qcadoo.

the class TechnologyValidationService method checkCycleForSubProducts.

private boolean checkCycleForSubProducts(final StateChangeContext stateChangeContext, final Entity operation, final Set<Long> usedTechnologies) {
    if (Objects.isNull(operation)) {
        return true;
    }
    EntityList productInComponents = operation.getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS);
    for (Entity productInComp : productInComponents) {
        Set<Long> copyUsedTechnologies = new HashSet<>(usedTechnologies);
        Entity product = productInComp.getBelongsToField(OperationProductInComponentFields.PRODUCT);
        Entity subOperation = productStructureTreeService.findOperationForProductWithinChildren(product, operation);
        Entity subTechnology = productStructureTreeService.findTechnologyForProduct(product);
        subTechnology = useChangingTechnologyInCheckingCycle(stateChangeContext, product, subTechnology);
        if (Objects.nonNull(subTechnology)) {
            if (copyUsedTechnologies.contains(subTechnology.getId())) {
                stateChangeContext.addValidationError("technologies.technologyDetails.window.productStructure.productStructureForm.duplicateProductForTechnology", product.getStringField(ProductFields.NUMBER) + " " + product.getStringField(ProductFields.NAME));
                return false;
            } else {
                if (Objects.isNull(subOperation)) {
                    Entity operationForTechnology = productStructureTreeService.findOperationForProductAndTechnology(product, subTechnology);
                    copyUsedTechnologies.add(subTechnology.getId());
                    boolean hasNotCycle = checkCycleForSubProducts(stateChangeContext, operationForTechnology, copyUsedTechnologies);
                    if (!hasNotCycle) {
                        return false;
                    }
                } else {
                    boolean hasNotCycle = checkCycleForSubProducts(stateChangeContext, subOperation, copyUsedTechnologies);
                    if (!hasNotCycle) {
                        return false;
                    }
                }
            }
        } else if (Objects.nonNull(subOperation)) {
            boolean hasNotCycle = checkCycleForSubProducts(stateChangeContext, subOperation, copyUsedTechnologies);
            if (!hasNotCycle) {
                return false;
            }
        }
    }
    return true;
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityList(com.qcadoo.model.api.EntityList) HashSet(java.util.HashSet)

Example 92 with EntityList

use of com.qcadoo.model.api.EntityList in project mes by qcadoo.

the class ProductStructureTreeService method addChildTOC.

private void addChildTOC(final List<Entity> tree, final Entity child, final Entity parent, final Entity product, final String type) {
    child.setField(TechnologyOperationComponentFields.PARENT, parent);
    child.setField(TechnologyOperationComponentFields.PRIORITY, 1);
    child.setField(TechnologyOperationComponentFields.TYPE_FROM_STRUCTURE_TREE, type);
    child.setField(TechnologyOperationComponentFields.PRODUCT_FROM_STRUCTURE_TREE, product);
    if (Objects.nonNull(parent)) {
        List<Entity> children = Lists.newArrayList();
        EntityList tocChildren = parent.getHasManyField(TechnologyOperationComponentFields.CHILDREN);
        if (!tocChildren.isEmpty()) {
            children = Lists.newArrayList(tocChildren);
        }
        if (tocChildren.stream().noneMatch(e -> e.getId().equals(child.getId()))) {
            children.add(child);
        }
        parent.setField(TechnologyOperationComponentFields.CHILDREN, children);
    }
    tree.add(child);
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityList(com.qcadoo.model.api.EntityList)

Example 93 with EntityList

use of com.qcadoo.model.api.EntityList in project mes by qcadoo.

the class ProductStructureTreeService method generateTreeForSubProducts.

private void generateTreeForSubProducts(final Entity operation, final Entity technology, final List<Entity> tree, final Entity parent, final ViewDefinitionState view, final Entity mainTechnology) {
    EntityList operationProductInComponents = operation.getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS);
    for (Entity operationProductInComponent : operationProductInComponents) {
        Entity child = getProductStructureTreeNodeDD().create();
        Entity technologyInputProductType = operationProductInComponent.getBelongsToField(OperationProductInComponentFields.TECHNOLOGY_INPUT_PRODUCT_TYPE);
        Entity product = operationProductInComponent.getBelongsToField(OperationProductInComponentFields.PRODUCT);
        String unit = operationProductInComponent.getStringField(OperationProductInComponentFields.GIVEN_UNIT);
        Entity subOperation = findOperationForProductWithinChildren(product, operation);
        BigDecimal quantity = findQuantityOfProductInOperation(technologyInputProductType, product, operation);
        Entity subTechnology = findTechnologyForProduct(product);
        if (Objects.nonNull(subTechnology)) {
            if (Objects.isNull(subOperation)) {
                Entity operationForTechnology = findOperationForProductAndTechnology(product, subTechnology);
                Entity technologyGroup = subTechnology.getBelongsToField(TechnologyFields.TECHNOLOGY_GROUP);
                BigDecimal standardPerformance = technologyService.getStandardPerformance(subTechnology).orElse(null);
                child.setField(ProductStructureTreeNodeFields.TECHNOLOGY, subTechnology);
                child.setField(ProductStructureTreeNodeFields.MAIN_TECHNOLOGY, mainTechnology);
                child.setField(ProductStructureTreeNodeFields.OPERATION, operationForTechnology);
                child.setField(ProductStructureTreeNodeFields.PRODUCT, product);
                child.setField(ProductStructureTreeNodeFields.QUANTITY, quantity);
                child.setField(ProductStructureTreeNodeFields.DIVISION, operationForTechnology.getBelongsToField(TechnologyOperationComponentFields.DIVISION));
                child.setField(ProductStructureTreeNodeFields.TECHNOLOGY_GROUP, technologyGroup);
                child.setField(ProductStructureTreeNodeFields.STANDARD_PERFORMANCE, standardPerformance);
                child = addChild(tree, child, parent, L_COMPONENT);
                generateTreeForSubProducts(operationForTechnology, subTechnology, tree, child, view, mainTechnology);
            } else {
                child.setField(ProductStructureTreeNodeFields.TECHNOLOGY, technology);
                child.setField(ProductStructureTreeNodeFields.MAIN_TECHNOLOGY, mainTechnology);
                child.setField(ProductStructureTreeNodeFields.PRODUCT, product);
                child.setField(ProductStructureTreeNodeFields.QUANTITY, quantity);
                child.setField(ProductStructureTreeNodeFields.OPERATION, subOperation);
                child.setField(ProductStructureTreeNodeFields.DIVISION, subOperation.getBelongsToField(TechnologyOperationComponentFields.DIVISION));
                child = addChild(tree, child, parent, L_INTERMEDIATE);
                if (Objects.nonNull(view)) {
                    FormComponent productStructureForm = (FormComponent) view.getComponentByReference("productStructureForm");
                    if (Objects.nonNull(productStructureForm)) {
                        productStructureForm.addMessage("technologies.technologyDetails.window.productStructure.productStructureForm.technologyAndOperationExists", MessageType.INFO, false, product.getStringField(ProductFields.NUMBER) + " " + product.getStringField(ProductFields.NAME));
                    }
                }
                generateTreeForSubProducts(subOperation, technology, tree, child, view, mainTechnology);
            }
        } else {
            Entity technologyGroup = technology.getBelongsToField(TechnologyFields.TECHNOLOGY_GROUP);
            BigDecimal standardPerformance = technologyService.getStandardPerformance(technology).orElse(null);
            child.setField(ProductStructureTreeNodeFields.TECHNOLOGY, technology);
            child.setField(ProductStructureTreeNodeFields.MAIN_TECHNOLOGY, mainTechnology);
            child.setField(ProductStructureTreeNodeFields.PRODUCT, product);
            child.setField(ProductStructureTreeNodeFields.QUANTITY, quantity);
            child.setField(ProductStructureTreeNodeFields.TECHNOLOGY_GROUP, technologyGroup);
            child.setField(ProductStructureTreeNodeFields.STANDARD_PERFORMANCE, standardPerformance);
            child.setField(ProductStructureTreeNodeFields.UNIT, unit);
            if (Objects.nonNull(subOperation)) {
                child.setField(ProductStructureTreeNodeFields.OPERATION, subOperation);
                child.setField(ProductStructureTreeNodeFields.DIVISION, subOperation.getBelongsToField(TechnologyOperationComponentFields.DIVISION));
                child = addChild(tree, child, parent, L_INTERMEDIATE);
                generateTreeForSubProducts(subOperation, technology, tree, child, view, mainTechnology);
            } else {
                boolean differentProductsInDifferentSizes = operationProductInComponent.getBooleanField(OperationProductInComponentFields.DIFFERENT_PRODUCTS_IN_DIFFERENT_SIZES);
                boolean variousQuantitiesInProductsBySize = operationProductInComponent.getBooleanField(OperationProductInComponentFields.VARIOUS_QUANTITIES_IN_PRODUCTS_BY_SIZE);
                child.setField(ProductStructureTreeNodeFields.TECHNOLOGY_INPUT_PRODUCT_TYPE, technologyInputProductType);
                child.setField(ProductStructureTreeNodeFields.DIFFERENT_PRODUCTS_IN_DIFFERENT_SIZES, differentProductsInDifferentSizes);
                child.setField(ProductStructureTreeNodeFields.VARIOUS_QUANTITIES_IN_PRODUCTS_BY_SIZE, variousQuantitiesInProductsBySize);
                child.setField(ProductStructureTreeNodeFields.OPERATION, operation);
                child.setField(ProductStructureTreeNodeFields.DIVISION, operation.getBelongsToField(TechnologyOperationComponentFields.DIVISION));
                child = addChild(tree, child, parent, L_MATERIAL);
                if (differentProductsInDifferentSizes) {
                    generateTreeForProductBySizeGroups(operationProductInComponent, operation, variousQuantitiesInProductsBySize, technology, tree, child, view, mainTechnology);
                }
            }
        }
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) FormComponent(com.qcadoo.view.api.components.FormComponent) EntityList(com.qcadoo.model.api.EntityList) BigDecimal(java.math.BigDecimal)

Example 94 with EntityList

use of com.qcadoo.model.api.EntityList in project mes by qcadoo.

the class ProductQuantitiesServiceImplTest method mockEntityListIterator.

private static EntityList mockEntityListIterator(List<Entity> list) {
    EntityList entityList = mock(EntityList.class);
    when(entityList.iterator()).thenReturn(list.iterator());
    return entityList;
}
Also used : EntityList(com.qcadoo.model.api.EntityList)

Example 95 with EntityList

use of com.qcadoo.model.api.EntityList in project mes by qcadoo.

the class ProductionLinesServiceImplTest method init.

@Before
public void init() {
    MockitoAnnotations.initMocks(this);
    productionLinesServiceImpl = new ProductionLinesServiceImpl();
    EntityList workstationComps = mockEntityListIterator(asList(workComp1, workComp2));
    given(productionLine.getHasManyField("workstationTypeComponents")).willReturn(workstationComps);
    given(workComp1.getBelongsToField("workstationType")).willReturn(work1);
    given(workComp2.getBelongsToField("workstationType")).willReturn(work2);
    given(work1.getId()).willReturn(1L);
    given(work2.getId()).willReturn(2L);
    given(work3.getId()).willReturn(3L);
    given(opComp1.getBelongsToField("operation")).willReturn(operation);
    given(workComp1.getField("quantity")).willReturn(123);
    given(workComp2.getField("quantity")).willReturn(234);
}
Also used : EntityList(com.qcadoo.model.api.EntityList) Before(org.junit.Before)

Aggregations

EntityList (com.qcadoo.model.api.EntityList)103 Entity (com.qcadoo.model.api.Entity)52 Test (org.junit.Test)27 DataDefinition (com.qcadoo.model.api.DataDefinition)16 SearchCriteriaBuilder (com.qcadoo.model.api.search.SearchCriteriaBuilder)16 Before (org.junit.Before)11 UserFieldsMF (com.qcadoo.mes.materialFlow.constants.UserFieldsMF)10 UserLocationFields (com.qcadoo.mes.materialFlow.constants.UserLocationFields)10 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)10 SearchRestrictions (com.qcadoo.model.api.search.SearchRestrictions)10 SecurityService (com.qcadoo.security.api.SecurityService)10 QcadooSecurityConstants (com.qcadoo.security.constants.QcadooSecurityConstants)10 Objects (java.util.Objects)10 Set (java.util.Set)10 Collectors (java.util.stream.Collectors)10 Autowired (org.springframework.beans.factory.annotation.Autowired)10 Service (org.springframework.stereotype.Service)10 FilterValueHolder (com.qcadoo.view.api.components.lookup.FilterValueHolder)9 BigDecimal (java.math.BigDecimal)9 StateChangeTest (com.qcadoo.mes.states.StateChangeTest)5