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