Search in sources :

Example 36 with EntityTree

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

the class NormServiceTest 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 37 with EntityTree

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

the class NormServiceTest method shouldReturnAnErrorMessageIfTheQuantitiesDontMatch.

@Ignore
@Test
public void shouldReturnAnErrorMessageIfTheQuantitiesDontMatch() {
    // given
    EntityTree tree = mockEntityTreeIterator(asList(operComp1));
    given(technology.getTreeField("operationComponents")).willReturn(tree);
    given(technologyService.getProductCountForOperationComponent(operComp1)).willReturn(new BigDecimal(13.5));
    given(operComp1.getDecimalField("productionInOneCycle")).willReturn(new BigDecimal(13.51));
    Locale locale = LocaleContextHolder.getLocale();
    given(translationService.translate("technologies.technology.validate.error.invalidQuantity1", locale)).willReturn("message1");
    given(operComp1.getStringField("nodeNumber")).willReturn("1");
    given(translationService.translate("technologies.technology.validate.error.invalidQuantity2", locale)).willReturn("message2");
    // when
    List<String> messages = normService.checkOperationOutputQuantities(technology);
    // then
    assertEquals(1, messages.size());
    assertEquals("message1 1 message2", messages.get(0));
}
Also used : Locale(java.util.Locale) EntityTree(com.qcadoo.model.api.EntityTree) BigDecimal(java.math.BigDecimal) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 38 with EntityTree

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

the class FactoryStructureForEventHooks method generateFactoryStructure.

// TODO move fields' names to constants
public void generateFactoryStructure(final ViewDefinitionState view) {
    FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    Entity maintenanceEvent = form.getEntity();
    EntityTree factoryStructure = factoryStructureGenerationService.generateFactoryStructureForEntity(maintenanceEvent, "maintenanceEvent");
    maintenanceEvent.setField(MaintenanceEventFields.FACTORY_STRUCTURE, factoryStructure);
    generatedTree = factoryStructure;
    form.setEntity(maintenanceEvent);
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) EntityTree(com.qcadoo.model.api.EntityTree)

Example 39 with EntityTree

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

the class TechnologyValidationService method checkIfEveryInComponentsHasQuantities.

public boolean checkIfEveryInComponentsHasQuantities(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> operationProductInComponents = operationComponent.getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS);
        for (Entity operationProductInComponent : operationProductInComponents) {
            boolean differentProductsInDifferentSizes = operationProductInComponent.getBooleanField(OperationProductInComponentFields.DIFFERENT_PRODUCTS_IN_DIFFERENT_SIZES);
            boolean variousQuantitiesInProductsBySize = operationProductInComponent.getBooleanField(OperationProductInComponentFields.VARIOUS_QUANTITIES_IN_PRODUCTS_BY_SIZE);
            if (!differentProductsInDifferentSizes && Objects.isNull(operationProductInComponent.getDecimalField(OperationProductInComponentFields.QUANTITY))) {
                stateChangeContext.addValidationError("technologies.technology.validate.global.error.inComponentsQuantitiesNotFilled", operationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION).getStringField(OperationFields.NUMBER), operationComponent.getStringField(TechnologyOperationComponentFields.NODE_NUMBER));
                return false;
            }
            if (differentProductsInDifferentSizes && variousQuantitiesInProductsBySize) {
                boolean quantitiesOrProductsNotSet = false;
                if (operationProductInComponent.getHasManyField(OperationProductInComponentFields.PRODUCT_BY_SIZE_GROUPS).isEmpty()) {
                    quantitiesOrProductsNotSet = true;
                } else if (operationProductInComponent.getHasManyField(OperationProductInComponentFields.PRODUCT_BY_SIZE_GROUPS).stream().anyMatch(pbs -> Objects.isNull(pbs.getDecimalField(ProductBySizeGroupFields.QUANTITY)))) {
                    quantitiesOrProductsNotSet = true;
                }
                if (quantitiesOrProductsNotSet) {
                    stateChangeContext.addValidationError("technologies.technology.validate.global.error.variousQuantitiesInProductsBySizeNotFilled", 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 40 with EntityTree

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

the class TechnologyValidationService method checkTopComponentsProducesProductForTechnology.

private boolean checkTopComponentsProducesProductForTechnology(final StateChangeContext stateChangeContext, final FormComponent technologyForm, final Entity technology) {
    final Entity savedTechnology = technology.getDataDefinition().get(technology.getId());
    final Entity product = savedTechnology.getBelongsToField(TechnologyFields.PRODUCT);
    final EntityTree operationComponents = savedTechnology.getTreeField(TechnologyFields.OPERATION_COMPONENTS);
    final EntityTreeNode root = operationComponents.getRoot();
    if (Objects.nonNull(root)) {
        final EntityList operationProductOutComponents = root.getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS);
        for (Entity operationProductOutComponent : operationProductOutComponents) {
            if (product.getId().equals(operationProductOutComponent.getBelongsToField(OperationProductOutComponentFields.PRODUCT).getId())) {
                return true;
            }
        }
    }
    if (Objects.nonNull(technologyForm)) {
        technologyForm.addMessage("technologies.technology.validate.global.error.noFinalProductInTechnologyTree", MessageType.FAILURE);
    } else {
        stateChangeContext.addValidationError("technologies.technology.validate.global.error.noFinalProductInTechnologyTree");
    }
    return false;
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityTreeNode(com.qcadoo.model.api.EntityTreeNode) EntityList(com.qcadoo.model.api.EntityList) 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