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;
}
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));
}
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);
}
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;
}
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;
}
Aggregations