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