Search in sources :

Example 41 with EntityTree

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

the class TechnologyValidationService method checkIfOperationsUsesSubOperationsProds.

private boolean checkIfOperationsUsesSubOperationsProds(final StateChangeContext stateChangeContext, final FormComponent technologyForm, final Entity technology) {
    final EntityTree operationComponents = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS);
    Set<Entity> operations = checkIfConsumesSubOpsProds(operationComponents);
    if (!operations.isEmpty()) {
        StringBuilder levels = new StringBuilder();
        for (Entity operation : operations) {
            if (levels.length() != 0) {
                levels.append(", ");
            }
            levels.append(operation.getStringField(TechnologyOperationComponentFields.NODE_NUMBER));
        }
        if (operations.size() == 1) {
            if (Objects.nonNull(technologyForm)) {
                technologyForm.addMessage(L_TECHNOLOGIES_TECHNOLOGY_VALIDATE_GLOBAL_ERROR_TREE_IS_NOT_VALID, MessageType.FAILURE);
                technologyForm.addMessage(L_TECHNOLOGIES_TECHNOLOGY_VALIDATE_GLOBAL_ERROR_OPERATION_DONT_CONSUME_SUB_OPERATIONS_PRODUCTS, MessageType.FAILURE, false, levels.toString());
            } else {
                stateChangeContext.addFieldValidationError(TechnologyFields.OPERATION_COMPONENTS, L_TECHNOLOGIES_TECHNOLOGY_VALIDATE_GLOBAL_ERROR_TREE_IS_NOT_VALID);
                stateChangeContext.addMessage(L_TECHNOLOGIES_TECHNOLOGY_VALIDATE_GLOBAL_ERROR_OPERATION_DONT_CONSUME_SUB_OPERATIONS_PRODUCTS, StateMessageType.FAILURE, false, levels.toString());
            }
        } else {
            if (Objects.nonNull(technologyForm)) {
                technologyForm.addMessage(L_TECHNOLOGIES_TECHNOLOGY_VALIDATE_GLOBAL_ERROR_TREE_IS_NOT_VALID, MessageType.FAILURE);
                technologyForm.addMessage(L_TECHNOLOGIES_TECHNOLOGY_VALIDATE_GLOBAL_ERROR_OPERATION_DONT_CONSUME_SUB_OPERATIONS_PRODUCTS_PLURAL, MessageType.FAILURE, false, levels.toString());
            } else {
                stateChangeContext.addFieldValidationError(TechnologyFields.OPERATION_COMPONENTS, L_TECHNOLOGIES_TECHNOLOGY_VALIDATE_GLOBAL_ERROR_TREE_IS_NOT_VALID);
                stateChangeContext.addMessage(L_TECHNOLOGIES_TECHNOLOGY_VALIDATE_GLOBAL_ERROR_OPERATION_DONT_CONSUME_SUB_OPERATIONS_PRODUCTS_PLURAL, StateMessageType.FAILURE, false, levels.toString());
            }
        }
        return false;
    }
    return true;
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityTree(com.qcadoo.model.api.EntityTree)

Example 42 with EntityTree

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

the class TechnologyValidationService method checkIfTechnologyHasAtLeastOneComponent.

public boolean checkIfTechnologyHasAtLeastOneComponent(final StateChangeContext stateChangeContext) {
    Entity technology = stateChangeContext.getOwner();
    final Entity savedTechnology = technology.getDataDefinition().get(technology.getId());
    final EntityTree operationComponents = savedTechnology.getTreeField(TechnologyFields.OPERATION_COMPONENTS);
    if (!operationComponents.isEmpty()) {
        return true;
    }
    stateChangeContext.addValidationError("technologies.technology.validate.global.error.emptyTechnologyTree");
    return false;
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityTree(com.qcadoo.model.api.EntityTree)

Example 43 with EntityTree

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

the class TechnologyValidationService method checkIfWasteProductsIsRightMarked.

public boolean checkIfWasteProductsIsRightMarked(final StateChangeContext stateChangeContext) {
    Entity technology = stateChangeContext.getOwner();
    final Entity savedTechnology = technology.getDataDefinition().get(technology.getId());
    final EntityTree operationComponents = savedTechnology.getTreeField(TechnologyFields.OPERATION_COMPONENTS);
    for (Entity operationComponent : operationComponents) {
        List<Entity> operationProductOutComponents = operationComponent.getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS);
        long notWasteCount = operationProductOutComponents.stream().filter(opoc -> !opoc.getBooleanField(OperationProductOutComponentFields.WASTE)).count();
        if (notWasteCount > 1 || notWasteCount == 0) {
            stateChangeContext.addValidationError("technologies.technology.validate.global.error.noProductsWithWasteFlagNotMarked", operationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION).getStringField(OperationFields.NUMBER), operationComponent.getStringField(TechnologyOperationComponentFields.NODE_NUMBER));
            return false;
        }
    }
    return true;
}
Also used : TechnologyTreeValidationService(com.qcadoo.mes.technologies.tree.TechnologyTreeValidationService) MessageType(com.qcadoo.view.api.ComponentState.MessageType) PRODUCT(com.qcadoo.mes.technologies.constants.TechnologyFields.PRODUCT) ProductFamilyElementType(com.qcadoo.mes.basic.constants.ProductFamilyElementType) Autowired(org.springframework.beans.factory.annotation.Autowired) ProductStructureTreeService(com.qcadoo.mes.technologies.tree.ProductStructureTreeService) TechnologyService(com.qcadoo.mes.technologies.TechnologyService) StateMessageType(com.qcadoo.mes.states.messages.constants.StateMessageType) HashSet(java.util.HashSet) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) BigDecimal(java.math.BigDecimal) Lists(com.google.common.collect.Lists) Locale(java.util.Locale) Service(org.springframework.stereotype.Service) FormComponent(com.qcadoo.view.api.components.FormComponent) Map(java.util.Map) ProductQuantitiesService(com.qcadoo.mes.technologies.ProductQuantitiesService) OPERATION_COMPONENTS(com.qcadoo.mes.technologies.constants.TechnologyFields.OPERATION_COMPONENTS) StateChangeContext(com.qcadoo.mes.states.StateChangeContext) UNIT(com.qcadoo.mes.basic.constants.ProductFields.UNIT) Set(java.util.Set) TranslationService(com.qcadoo.localization.api.TranslationService) DataDefinition(com.qcadoo.model.api.DataDefinition) EntityTree(com.qcadoo.model.api.EntityTree) Sets(com.google.common.collect.Sets) EntityList(com.qcadoo.model.api.EntityList) Objects(java.util.Objects) com.qcadoo.mes.technologies.constants(com.qcadoo.mes.technologies.constants) Entity(com.qcadoo.model.api.Entity) List(java.util.List) ProductFields(com.qcadoo.mes.basic.constants.ProductFields) EntityTreeNode(com.qcadoo.model.api.EntityTreeNode) Entity(com.qcadoo.model.api.Entity) EntityTree(com.qcadoo.model.api.EntityTree)

Example 44 with EntityTree

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

the class TechnologyDetailsListeners method generateProductStructure.

public void generateProductStructure(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    FormComponent technologyForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    FormComponent productStructureForm = (FormComponent) view.getComponentByReference(L_PRODUCT_STRUCTURE_FORM);
    Entity technology = technologyForm.getEntity();
    Entity productTechnology = technology.copy();
    EntityTree generatedTree = productStructureTreeService.generateProductStructureTree(view, technology);
    productTechnology.setField(PRODUCT_STRUCTURE_TREE, generatedTree);
    productStructureForm.setEntity(productTechnology);
    WindowComponent window = (WindowComponent) view.getComponentByReference(QcadooViewConstants.L_WINDOW);
    window.setActiveTab(L_PRODUCT_STRUCTURE);
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) WindowComponent(com.qcadoo.view.api.components.WindowComponent) EntityTree(com.qcadoo.model.api.EntityTree)

Example 45 with EntityTree

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

the class TechnologyTreeValidators method checkConsumingTheSameProductFromManySubOperations.

public boolean checkConsumingTheSameProductFromManySubOperations(final DataDefinition technologyDD, final Entity technology, final boolean autoCloseMessage) {
    Entity techFromDB = technologyDD.get(technology.getId());
    EntityTree tree = techFromDB.getTreeField(TechnologyFields.OPERATION_COMPONENTS);
    Map<String, Set<Entity>> nodesMap = technologyTreeValidationService.checkConsumingTheSameProductFromManySubOperations(tree);
    for (Entry<String, Set<Entity>> entry : nodesMap.entrySet()) {
        String parentNodeNumber = entry.getKey();
        for (Entity product : entry.getValue()) {
            String productName = product.getStringField(ProductFields.NAME);
            String productNumber = product.getStringField(ProductFields.NUMBER);
            technology.addGlobalError("technologies.technology.validate.global.error.subOperationsProduceTheSameProductThatIsConsumed", autoCloseMessage, parentNodeNumber, productName, productNumber);
        }
    }
    return nodesMap.isEmpty();
}
Also used : Entity(com.qcadoo.model.api.Entity) Set(java.util.Set) EntityTree(com.qcadoo.model.api.EntityTree)

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