use of com.qcadoo.mes.materialFlowResources.exceptions.DocumentBuildException in project mes by qcadoo.
the class WarehouseIssueDocumentsService method build.
private CreationDocumentResponse build(final DocumentsStatus documentsStatus, final DocumentBuilder documentBuilder) {
Entity document;
try {
if (DocumentsStatus.ACCEPTED.getStrValue().equals(documentsStatus.getStrValue())) {
document = documentBuilder.setAccepted().buildWithEntityRuntimeException();
} else {
document = documentBuilder.buildWithEntityRuntimeException();
}
if (!document.isValid()) {
List<ErrorMessage> errors = Lists.newArrayList();
errors.addAll(document.getGlobalErrors());
return new CreationDocumentResponse(false, errors);
}
CreationDocumentResponse creationDocumentResponse = new CreationDocumentResponse(true);
creationDocumentResponse.setDocument(document);
return creationDocumentResponse;
} catch (DocumentBuildException e) {
return new CreationDocumentResponse(false, e.getGlobalErrors());
}
}
use of com.qcadoo.mes.materialFlowResources.exceptions.DocumentBuildException in project mes by qcadoo.
the class DetailedProductionCountingAndProgressListenersBPC method resourceIssue.
public void resourceIssue(final ViewDefinitionState view, final ComponentState state, final String[] args) {
FormComponent formComponent = (FormComponent) view.getComponentByReference(L_ORDER);
Entity order = formComponent.getEntity().getDataDefinition().get(formComponent.getEntity().getId());
GridComponent grid = (GridComponent) view.getComponentByReference(QcadooViewConstants.L_GRID);
Set<Long> ids = grid.getSelectedEntitiesIds();
List<Entity> pcqs = dataDefinitionService.get(BasicProductionCountingConstants.PLUGIN_IDENTIFIER, BasicProductionCountingConstants.MODEL_PRODUCTION_COUNTING_QUANTITY).find().add(SearchRestrictions.in("id", ids)).list().getEntities();
if (!canIssueMaterials(order, pcqs)) {
formComponent.setEntity(order);
return;
}
try {
productionCountingDocumentService.createInternalOutboundDocument(order, pcqs, false);
if (order.isValid()) {
productionCountingDocumentService.updateProductionCountingQuantity(pcqs);
productionTrackingListenerServicePFTD.updateCostsForOrder(order);
view.addMessage("productFlowThruDivision.productionCountingQuantity.success.createInternalOutboundDocument", ComponentState.MessageType.SUCCESS);
}
} catch (DocumentBuildException documentBuildException) {
boolean errorsDisplayed = true;
for (ErrorMessage error : documentBuildException.getEntity().getGlobalErrors()) {
if (error.getMessage().equalsIgnoreCase(L_ERROR_NOT_ENOUGH_RESOURCES)) {
order.addGlobalError(error.getMessage(), false, error.getVars());
} else {
errorsDisplayed = false;
order.addGlobalError(error.getMessage(), error.getVars());
}
}
if (!errorsDisplayed) {
order.addGlobalError("productFlowThruDivision.productionCountingQuantity.productionCountingQuantityError.createInternalOutboundDocument");
}
formComponent.setEntity(order);
}
}
use of com.qcadoo.mes.materialFlowResources.exceptions.DocumentBuildException in project mes by qcadoo.
the class ProductionTrackingDocumentsHelper method groupAndFilterInProducts.
public Multimap<Long, Entity> groupAndFilterInProducts(final Entity order, final List<Entity> trackingOperationProductInComponents) {
Multimap<Long, Entity> groupedRecordInProducts = ArrayListMultimap.create();
SearchCriteriaBuilder scb = getProductionCountingQuantityDD().find().add(SearchRestrictions.belongsTo(ProductionCountingQuantityFields.ORDER, order)).add(SearchRestrictions.eq(ProductionCountingQuantityFields.ROLE, ProductionCountingQuantityRole.USED.getStringValue()));
List<Entity> productionCountingQuantities = scb.list().getEntities();
for (Entity topic : trackingOperationProductInComponents) {
BigDecimal usedQuantity = topic.getDecimalField(L_USED_QUANTITY);
if (Objects.nonNull(usedQuantity) && BigDecimal.ZERO.compareTo(usedQuantity) < 0) {
Entity product = topic.getBelongsToField(TrackingOperationProductInComponentFields.PRODUCT);
Entity productionTracking = topic.getBelongsToField(TrackingOperationProductInComponentFields.PRODUCTION_TRACKING);
Entity toc = productionTracking.getBelongsToField(ProductionTrackingFields.TECHNOLOGY_OPERATION_COMPONENT);
Either<Boolean, Entity> eitherWarehouse = getWarehouseForProduct(productionCountingQuantities, toc, product);
if (eitherWarehouse.isRight()) {
Entity warehouse = eitherWarehouse.getRight();
if (Objects.isNull(warehouse)) {
DocumentBuilder documentBuilder = documentManagementService.getDocumentBuilder();
Entity emptyDocumentForErrorHandling = documentBuilder.createDocument(userService.getCurrentUserEntity());
emptyDocumentForErrorHandling.setNotValid();
emptyDocumentForErrorHandling.addGlobalError("productFlowThruDivision.productionCountingQuantity.productionCountingQuantityError.warehouseNotSet", product.getStringField(ProductFields.NUMBER));
throw new DocumentBuildException(emptyDocumentForErrorHandling, Lists.newArrayList());
}
groupedRecordInProducts.put(warehouse.getId(), topic);
}
}
}
return groupedRecordInProducts;
}
use of com.qcadoo.mes.materialFlowResources.exceptions.DocumentBuildException in project mes by qcadoo.
the class ProductionCountingDocumentService method checkForEmptyPositions.
private void checkForEmptyPositions(boolean useUsedQuantity, List<ProductionCountingQuantityHolder> entries) {
for (ProductionCountingQuantityHolder entry : entries) {
BigDecimal quantity = null;
if (useUsedQuantity) {
quantity = entry.getUsedQuantity();
} else {
quantity = entry.getPlannedQuantity().subtract(BigDecimalUtils.convertNullToZero(entry.getUsedQuantity()));
}
if (BigDecimal.ZERO.compareTo(quantity) >= 0) {
DocumentBuilder documentBuilder = documentManagementService.getDocumentBuilder();
Entity emptyDocumentForErrorHandling = documentBuilder.createDocument(userService.getCurrentUserEntity());
emptyDocumentForErrorHandling.setNotValid();
emptyDocumentForErrorHandling.addGlobalError("productFlowThruDivision.productionCountingQuantity.productionCountingQuantityError.emptyPosition", entry.getProduct().getStringField(ProductFields.NUMBER));
throw new DocumentBuildException(emptyDocumentForErrorHandling, Lists.newArrayList());
}
}
}
Aggregations