use of com.qcadoo.mes.productionPerShift.BalanceGenerationStrategy in project mes by qcadoo.
the class GenerateBalanceListeners method generateBalance.
public void generateBalance(final ViewDefinitionState viewState, final ComponentState formState, final String[] args) {
FormComponent form = (FormComponent) formState;
Entity contextEntity = form.getPersistedEntityWithIncludedFormValues();
// We don't want to reuse contexts - in case of the user working with many browser tabs to compare a couple of results
contextEntity.setId(null);
contextEntity.setField(BalanceContextFields.BALANCES, Collections.<Entity>emptyList());
// Call validation
contextEntity = contextEntity.getDataDefinition().save(contextEntity);
if (!contextEntity.isValid()) {
form.setEntity(contextEntity);
return;
}
BalanceGenerationStrategy strategy = resolveBalanceGenerationStrategy(contextEntity);
List<Entity> balances = productionBalancePerShiftGenerator.generate(strategy);
contextEntity.setField(BalanceContextFields.BALANCES, balances);
Entity persistedContext = contextEntity.getDataDefinition().save(contextEntity);
if (persistedContext.isValid()) {
// Show 'balances' tab
WindowComponent window = (WindowComponent) viewState.getComponentByReference(QcadooViewConstants.L_WINDOW);
window.setActiveTab("balances");
}
form.setEntity(persistedContext);
}
Aggregations