use of com.qcadoo.model.api.validators.ErrorMessage 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.model.api.validators.ErrorMessage in project mes by qcadoo.
the class OrderStatesListenerServicePFTD method createTransferDocumentsForUnusedMaterials.
private Either<String, Void> createTransferDocumentsForUnusedMaterials(final Entity locationFrom, final Entity locationTo, final Map<Entity, BigDecimal> products, final Entity order) {
DocumentBuilder document = documentManagementService.getDocumentBuilder().transfer(locationFrom, locationTo);
if (products.isEmpty()) {
return Either.right(null);
}
for (Map.Entry<Entity, BigDecimal> entry : products.entrySet()) {
Entity product = entry.getKey();
BigDecimal quantity = entry.getValue();
if (quantity.compareTo(BigDecimal.ZERO) > 0) {
BigDecimal givenQuantity = quantity;
String givenUnit = product.getStringField(ProductFields.ADDITIONAL_UNIT);
BigDecimal conversion = BigDecimal.ONE;
if (!StringUtils.isEmpty(givenUnit)) {
PossibleUnitConversions unitConversions = unitConversionService.getPossibleConversions(product.getStringField(ProductFields.UNIT), searchCriteriaBuilder -> searchCriteriaBuilder.add(SearchRestrictions.belongsTo(UnitConversionItemFieldsB.PRODUCT, product)));
if (unitConversions.isDefinedFor(givenUnit)) {
givenQuantity = unitConversions.convertTo(quantity, givenUnit);
conversion = unitConversions.asUnitToConversionMap().get(givenUnit);
}
} else {
givenUnit = product.getStringField(ProductFields.UNIT);
}
Entity position = document.createPosition(product, quantity, givenQuantity, givenUnit, conversion, null, null, null, null, null);
document.addPosition(position);
}
}
Entity acceptedDocument = acceptTransferDocument(document, order);
if (!acceptedDocument.isValid()) {
for (ErrorMessage error : acceptedDocument.getGlobalErrors()) {
order.addGlobalError(error.getMessage(), error.getVars());
}
order.addGlobalError(L_ACCEPT_INBOUND_DOCUMENT_ERROR);
return Either.left(L_ACCEPT_INBOUND_DOCUMENT_ERROR);
}
return Either.right(null);
}
use of com.qcadoo.model.api.validators.ErrorMessage 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.model.api.validators.ErrorMessage in project mes by qcadoo.
the class AnomalyProductionTrackingDetailsListeners method perform.
@Transactional(propagation = Propagation.REQUIRES_NEW)
private boolean perform(ViewDefinitionState view) {
boolean valid = validate(view);
if (valid) {
createAnomalies(view);
clearQuantitiesInRR(view);
view.addMessage("productionCounting.anomalyProductionTrackingDetails.reasonsCreated", ComponentState.MessageType.SUCCESS);
CheckBoxComponent generated = (CheckBoxComponent) view.getComponentByReference("generated");
generated.setChecked(true);
return true;
} else {
view.addMessage(new ErrorMessage("productionCounting.anomalyReasonDetails.reasonIsRequired", false));
return false;
}
}
use of com.qcadoo.model.api.validators.ErrorMessage in project mes by qcadoo.
the class ProductionTrackingListenerService method closeOrder.
private void closeOrder(final Entity productionTracking) {
final Entity order = productionTracking.getBelongsToField(ORDER);
Entity orderFromDB = order.getDataDefinition().get(order.getId());
if (!orderClosingHelper.orderShouldBeClosed(productionTracking)) {
return;
}
if (order.getStringField(STATE).equals(COMPLETED.getStringValue())) {
productionTracking.addGlobalMessage("productionCounting.order.orderIsAlreadyClosed", false, false);
return;
}
final StateChangeContext orderStateChangeContext = stateChangeContextBuilder.build(orderStateChangeAspect.getChangeEntityDescriber(), orderFromDB, OrderState.COMPLETED.getStringValue());
orderStateChangeAspect.changeState(orderStateChangeContext);
orderFromDB = order.getDataDefinition().get(orderStateChangeContext.getOwner().getId());
if (orderFromDB.getStringField(STATE).equals(COMPLETED.getStringValue())) {
productionTracking.addGlobalMessage("productionCounting.order.orderClosed", false, false);
} else if (StateChangeStatus.PAUSED.equals(orderStateChangeContext.getStatus())) {
productionTracking.addGlobalMessage("productionCounting.order.orderWillBeClosedAfterExtSync", false, false);
} else {
productionTracking.addGlobalError("productionCounting.order.orderCannotBeClosed", false);
List<ErrorMessage> errors = Lists.newArrayList();
if (!orderFromDB.getErrors().isEmpty()) {
errors.addAll(order.getErrors().values());
}
if (!orderFromDB.getGlobalErrors().isEmpty()) {
errors.addAll(order.getGlobalErrors());
}
if (!orderStateChangeContext.getAllMessages().isEmpty()) {
for (Entity entity : orderStateChangeContext.getAllMessages()) {
errors.add(new ErrorMessage(getKey(entity), getArgs(entity)));
}
}
if (!errors.isEmpty()) {
StringBuilder errorMessages = new StringBuilder();
for (ErrorMessage errorMessage : errors) {
String translatedErrorMessage = translationService.translate(errorMessage.getMessage(), LocaleContextHolder.getLocale(), errorMessage.getVars());
errorMessages.append(translatedErrorMessage);
errorMessages.append(", ");
}
productionTracking.addGlobalError("orders.order.orderStates.error", errorMessages.toString());
}
}
}
Aggregations