use of com.qcadoo.model.api.EntityTree in project mes by qcadoo.
the class TechnologyTreeNumberingHooks method rebuildTreeNumbering.
public void rebuildTreeNumbering(final ViewDefinitionState view) {
FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
Long technologyId = form.getEntityId();
if (technologyId == null) {
return;
}
Entity technology = getTechnologyById(technologyId);
if (!isDraftTechnology(technology)) {
return;
}
EntityTree technologyTree = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS);
if (technologyTree == null || technologyTree.getRoot() == null) {
return;
}
debug("Fire tree node number generator for tecnology with id = " + technologyId);
treeNumberingService.generateTreeNumbers(technologyTree);
}
use of com.qcadoo.model.api.EntityTree in project mes by qcadoo.
the class TechnologyOperationComponentHooks method setOperationOutProduct.
private void setOperationOutProduct(final Entity technologyOperationComponent) {
if (Objects.nonNull(technologyOperationComponent.getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS)) && technologyOperationComponent.getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS).isEmpty()) {
Entity technology = technologyOperationComponent.getBelongsToField(TechnologyOperationComponentFields.TECHNOLOGY);
EntityTree tree = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS);
Entity operationProductOutComponent = getOperationProductOutComponentDD().create();
operationProductOutComponent.setField(OperationProductOutComponentFields.QUANTITY, 1);
if (Objects.isNull(tree) || tree.isEmpty()) {
operationProductOutComponent.setField(OperationProductOutComponentFields.PRODUCT, technology.getBelongsToField(TechnologyFields.PRODUCT));
technologyOperationComponent.setField(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS, Collections.singletonList(operationProductOutComponent));
} else {
Entity operation = technologyOperationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION);
if (Objects.nonNull(operation)) {
Entity product = operation.getBelongsToField(OperationFields.PRODUCT);
if (Objects.nonNull(product)) {
operationProductOutComponent.setField(OperationProductOutComponentFields.PRODUCT, product);
technologyOperationComponent.setField(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS, Collections.singletonList(operationProductOutComponent));
}
}
}
}
}
use of com.qcadoo.model.api.EntityTree in project mes by qcadoo.
the class TechnologiesTechnologyDetailsPdfView method addContent.
@Override
protected final String addContent(final Document document, final Map<String, Object> model, final Locale locale, final PdfWriter writer) throws DocumentException, IOException {
checkState(model.get("id") != null, "Unable to generate report for unsaved technology! (missing id)");
String documentTitle = translationService.translate("technologies.technologiesTechnologyDetails.report.title", locale);
String documentAuthor = translationService.translate("qcadooReport.commons.generatedBy.label", locale);
pdfHelper.addDocumentHeader(document, "", documentTitle, documentAuthor, new Date());
DataDefinition technologyDD = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_TECHNOLOGY);
Entity technology = technologyDD.get(valueOf(model.get("id").toString()));
Entity product = technology.getBelongsToField(TechnologyFields.PRODUCT);
PdfPTable panelTable = pdfHelper.createPanelTable(3);
pdfHelper.addTableCellAsOneColumnTable(panelTable, translationService.translate(TECHNOLOGIES_TECHNOLOGIES_TECHNOLOGY_DETAILS_REPORT_PANEL_TECHNOLOGY + TechnologyFields.NAME, locale), technology.getStringField(TechnologyFields.NAME));
pdfHelper.addTableCellAsOneColumnTable(panelTable, translationService.translate(TECHNOLOGIES_TECHNOLOGIES_TECHNOLOGY_DETAILS_REPORT_PANEL_TECHNOLOGY + TechnologyFields.NUMBER, locale), technology.getStringField(TechnologyFields.NUMBER));
panelTable.addCell(createImageCell(product));
pdfHelper.addTableCellAsOneColumnTable(panelTable, translationService.translate(TECHNOLOGIES_TECHNOLOGIES_TECHNOLOGY_DETAILS_REPORT_PANEL_TECHNOLOGY + TechnologyFields.PRODUCT, locale), product.getStringField(ProductFields.NAME));
pdfHelper.addTableCellAsOneColumnTable(panelTable, translationService.translate("technologies.technologiesTechnologyDetails.report.panel.technology.default", locale), technology.getBooleanField(TechnologyFields.MASTER) ? translationService.translate("qcadooView.true", locale) : translationService.translate("qcadooView.false", locale));
if (StringUtils.isEmpty(technology.getStringField(ProductFields.DESCRIPTION))) {
panelTable.addCell(StringUtils.EMPTY);
} else {
pdfHelper.addTableCellAsOneColumnTable(panelTable, translationService.translate(TECHNOLOGIES_TECHNOLOGIES_TECHNOLOGY_DETAILS_REPORT_PANEL_TECHNOLOGY + TechnologyFields.DESCRIPTION, locale), technology.getStringField(ProductFields.DESCRIPTION));
}
panelTable.addCell(StringUtils.EMPTY);
panelTable.setSpacingAfter(20);
panelTable.setSpacingBefore(20);
document.add(panelTable);
List<String> technologyDetailsTableHeader = new ArrayList<>();
technologyDetailsTableHeader.add(translationService.translate("technologies.technologiesTechnologyDetails.report.columnHeader.level", locale));
technologyDetailsTableHeader.add(translationService.translate("technologies.technologiesTechnologyDetails.report.columnHeader.name", locale));
technologyDetailsTableHeader.add(translationService.translate("technologies.technologiesTechnologyDetails.report.columnHeader.direction", locale));
technologyDetailsTableHeader.add(translationService.translate("technologies.technologiesTechnologyDetails.report.columnHeader.technologyInputProductTypeName", locale));
technologyDetailsTableHeader.add(translationService.translate("technologies.technologiesTechnologyDetails.report.columnHeader.productNumber", locale));
technologyDetailsTableHeader.add(translationService.translate("technologies.technologiesTechnologyDetails.report.columnHeader.productName", locale));
technologyDetailsTableHeader.add(translationService.translate("technologies.technologiesTechnologyDetails.report.columnHeader.quantity", locale));
technologyDetailsTableHeader.add(translationService.translate("technologies.technologiesTechnologyDetails.report.columnHeader.unit", locale));
Map<String, HeaderAlignment> alignments = Maps.newHashMap();
alignments.put(translationService.translate("technologies.technologiesTechnologyDetails.report.columnHeader.level", locale), HeaderAlignment.LEFT);
alignments.put(translationService.translate("technologies.technologiesTechnologyDetails.report.columnHeader.name", locale), HeaderAlignment.LEFT);
alignments.put(translationService.translate("technologies.technologiesTechnologyDetails.report.columnHeader.direction", locale), HeaderAlignment.LEFT);
alignments.put(translationService.translate("technologies.technologiesTechnologyDetails.report.columnHeader.technologyInputProductTypeName", locale), HeaderAlignment.LEFT);
alignments.put(translationService.translate("technologies.technologiesTechnologyDetails.report.columnHeader.productNumber", locale), HeaderAlignment.LEFT);
alignments.put(translationService.translate("technologies.technologiesTechnologyDetails.report.columnHeader.productName", locale), HeaderAlignment.LEFT);
alignments.put(translationService.translate("technologies.technologiesTechnologyDetails.report.columnHeader.quantity", locale), HeaderAlignment.RIGHT);
alignments.put(translationService.translate("technologies.technologiesTechnologyDetails.report.columnHeader.unit", locale), HeaderAlignment.LEFT);
PdfPTable table = pdfHelper.createTableWithHeader(8, technologyDetailsTableHeader, false, alignments);
EntityTree technologyTree = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS);
treeNumberingService.generateTreeNumbers(technologyTree);
List<Entity> technologyOperationComponents = entityTreeUtilsService.getSortedEntities(technologyTree);
for (Entity technologyOperationComponent : technologyOperationComponents) {
String nodeNumber = technologyOperationComponent.getStringField(TechnologyOperationComponentFields.NODE_NUMBER);
String operationName = technologyOperationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION).getStringField(OperationFields.NAME);
List<Entity> operationProductComponents = newArrayList();
operationProductComponents.addAll(technologyOperationComponent.getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS));
operationProductComponents.addAll(technologyOperationComponent.getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS));
addProducts(locale, table, nodeNumber, operationName, operationProductComponents);
}
document.add(table);
return translationService.translate("technologies.technologiesTechnologyDetails.report.fileName", locale);
}
use of com.qcadoo.model.api.EntityTree in project mes by qcadoo.
the class TechnologyValidationService method checkIfEveryOperationHasInComponents.
public void checkIfEveryOperationHasInComponents(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) {
boolean isValid = true;
List<Entity> operationProductInComponents = operationComponent.getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS);
if (operationProductInComponents.isEmpty()) {
isValid = false;
} else {
for (Entity operationProductInComponent : operationProductInComponents) {
boolean differentProductsInDifferentSizes = operationProductInComponent.getBooleanField(OperationProductInComponentFields.DIFFERENT_PRODUCTS_IN_DIFFERENT_SIZES);
if (differentProductsInDifferentSizes) {
List<Entity> productBySizeGroups = operationProductInComponent.getHasManyField(OperationProductInComponentFields.PRODUCT_BY_SIZE_GROUPS);
isValid = isValid && !productBySizeGroups.isEmpty();
} else {
Entity product = operationProductInComponent.getBelongsToField(OperationProductInComponentFields.PRODUCT);
isValid = isValid && Objects.nonNull(product);
}
}
}
if (!isValid) {
stateChangeContext.addValidationError("technologies.technology.validate.global.error.noInputComponents", operationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION).getStringField(OperationFields.NUMBER), operationComponent.getStringField(TechnologyOperationComponentFields.NODE_NUMBER));
return;
}
}
}
use of com.qcadoo.model.api.EntityTree in project mes by qcadoo.
the class TechnologyValidationService method checkDifferentProductsInDifferentSizes.
public boolean checkDifferentProductsInDifferentSizes(final StateChangeContext stateChangeContext) {
Entity technology = stateChangeContext.getOwner();
final Entity savedTechnology = technology.getDataDefinition().get(technology.getId());
final Entity product = savedTechnology.getBelongsToField(TechnologyFields.PRODUCT);
if (ProductFamilyElementType.PARTICULAR_PRODUCT.getStringValue().equals(product.getField(ProductFields.ENTITY_TYPE))) {
final EntityTree operationComponents = savedTechnology.getTreeField(TechnologyFields.OPERATION_COMPONENTS);
for (Entity operationComponent : operationComponents) {
final List<Entity> operationProductInComponents = operationComponent.getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS);
for (Entity operationProductInComponent : operationProductInComponents) {
boolean differentProductsInDifferentSizes = operationProductInComponent.getBooleanField(OperationProductInComponentFields.DIFFERENT_PRODUCTS_IN_DIFFERENT_SIZES);
if (differentProductsInDifferentSizes) {
stateChangeContext.addValidationError("technologies.technology.validate.global.error.differentProductsInDifferentSizes");
return false;
}
}
}
}
return true;
}
Aggregations