use of com.qcadoo.mes.productionPerShift.domain.PpsMessage in project mes by qcadoo.
the class ProductionPerShiftListeners method generateProgressForDays.
public void generateProgressForDays(final ViewDefinitionState view, final ComponentState componentState, final String[] args) {
if (!automaticPpsParametersService.isAutomaticPlanForShiftOn()) {
view.addMessage(new ErrorMessage("productionPerShift.automaticAlgorithm.error.ppsOff", false));
return;
}
FormComponent productionPerShiftForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
AwesomeDynamicListComponent progressForDaysComponent = (AwesomeDynamicListComponent) view.getComponentByReference("progressForDays");
Entity productionPerShift = productionPerShiftForm.getPersistedEntityWithIncludedFormValues();
ProgressForDaysContainer progressForDaysContainer = new ProgressForDaysContainer();
try {
automaticPpsExecutorService.generateProgressForDays(progressForDaysContainer, productionPerShift);
} catch (Exception ex) {
for (ErrorMessage errorMessage : progressForDaysContainer.getErrors()) {
view.addMessage(errorMessage.getMessage(), ComponentState.MessageType.FAILURE, false, errorMessage.getVars());
}
if (progressForDaysContainer.getErrors().isEmpty()) {
LOG.error("PPS generation error ", ex);
throw new IllegalStateException();
}
return;
}
List<Entity> progressForDays = progressForDaysContainer.getProgressForDays();
Entity order = productionPerShift.getBelongsToField(ProductionPerShiftFields.ORDER);
Entity product = order.getBelongsToField(OrderFields.PRODUCT);
if (progressForDaysContainer.isCalculationError()) {
productionPerShift.getGlobalErrors().forEach(error -> view.addMessage(error.getMessage(), ComponentState.MessageType.FAILURE, false, error.getVars()));
} else if (progressForDaysContainer.isPartCalculation()) {
productionPerShiftForm.setEntity(productionPerShift);
String unit = null;
if (product != null) {
unit = product.getStringField(ProductFields.UNIT);
}
progressForDaysComponent.setFieldValue(progressForDays);
fillUnit(progressForDaysComponent, unit);
for (PpsMessage message : progressForDaysContainer.getMessages()) {
view.addMessage(message.getMessage(), message.getType(), false, message.getVars());
}
updateProgressForDays(view, componentState, args);
} else {
Date orderFinishDate = ppsTimeHelper.calculateOrderFinishDate(order, progressForDays);
productionPerShift.setField(ProductionPerShiftFields.ORDER_FINISH_DATE, orderFinishDate);
productionPerShiftForm.setEntity(productionPerShift);
String unit = null;
if (product != null) {
unit = product.getStringField(ProductFields.UNIT);
}
progressForDaysComponent.setFieldValue(progressForDays);
fillUnit(progressForDaysComponent, unit);
updateProgressForDays(view, componentState, args);
}
}
Aggregations