use of com.qcadoo.mes.states.StateChangeContext in project mes by qcadoo.
the class WarehouseIssueGenerator method generateIssue.
private void generateIssue(Entity parameter, Entity issueLocation, Entity orderDto) {
Entity newWarehouseIssue = createNewWarehouseIssue(orderDto, issueLocation);
newWarehouseIssue = getWarehouseIssueDD().save(newWarehouseIssue);
warehouseIssueService.fillProductsToIssue(newWarehouseIssue.getId(), CollectionProducts.ON_ORDER, orderDto, issueLocation);
newWarehouseIssue = getWarehouseIssueDD().get(newWarehouseIssue.getId());
if (newWarehouseIssue.getHasManyField(WarehouseIssueFields.PRODUCTS_TO_ISSUES).isEmpty()) {
getWarehouseIssueDD().delete(newWarehouseIssue.getId());
} else if (parameter.getBooleanField(ParameterFieldsPFTD.AUTOMATIC_RELEASE_AFTER_GENERATION)) {
warehouseIssueService.copyProductsToIssue(newWarehouseIssue);
newWarehouseIssue = getWarehouseIssueDD().get(newWarehouseIssue.getId());
final StateChangeContext stateChangeContext = stateChangeContextBuilder.build(warehouseIssueStateChangeAspect.getChangeEntityDescriber(), newWarehouseIssue, WarehouseIssueStringValues.IN_PROGRESS);
warehouseIssueStateChangeAspect.changeState(stateChangeContext);
}
}
use of com.qcadoo.mes.states.StateChangeContext 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());
}
}
}
use of com.qcadoo.mes.states.StateChangeContext in project mes by qcadoo.
the class StateChangeContextBuilderTest method shouldBuildStateChangeContextFromScratches.
@Test
public final void shouldBuildStateChangeContextFromScratches() {
// given
given(stateChangeDD.create()).willReturn(stateChangeEntity);
stubSearchCriteria(Lists.<Entity>newArrayList());
// when
final StateChangeContext stateChangeContext = stateChangeContextBuilder.build(describer, owner, TestState.ACCEPTED.getStringValue());
// then
assertNotNull(stateChangeContext);
assertEquals(stateChangeEntity, stateChangeContext.getStateChangeEntity());
assertEquals(owner, stateChangeContext.getOwner());
}
use of com.qcadoo.mes.states.StateChangeContext in project mes by qcadoo.
the class StateChangeSamplesClientImpl method performChange.
private Entity performChange(final StateChangeService stateChangeService, final Entity entity, final String targetState) {
final StateChangeEntityDescriber describer = stateChangeService.getChangeEntityDescriber();
final StateChangeContext stateChangeContext = stateChangeContextBuilder.build(describer, entity, targetState);
stateChangeService.changeState(stateChangeContext);
checkResults(stateChangeContext);
Entity resultEntity = null;
if (entity.getId() == null) {
resultEntity = entity.getDataDefinition().save(entity);
} else {
resultEntity = entity.getDataDefinition().get(entity.getId());
}
return resultEntity;
}
use of com.qcadoo.mes.states.StateChangeContext in project mes by qcadoo.
the class MaintenanceEventToPlannedEventListeners method continueStateChange.
public void continueStateChange(final ViewDefinitionState view, final ComponentState component, final String[] args) {
final FormComponent form = (FormComponent) component;
Entity eventStateChange = form.getPersistedEntityWithIncludedFormValues();
maintenanceEventStateChangeValidators.validate(eventStateChange.getDataDefinition(), eventStateChange);
form.setEntity(eventStateChange);
if (!eventStateChange.getErrors().isEmpty()) {
return;
}
form.performEvent(view, "save");
if (!form.isValid()) {
return;
}
final Entity stateChangeEntity = ((FormComponent) form).getEntity();
final String plannedEventType = stateChangeEntity.getStringField(MaintenanceEventStateChangeFields.PLANNED_EVENT_TYPE);
final StateChangeContext stateContext = stateChangeContextBuilder.build(maintenanceEventStateChangeAspect.getChangeEntityDescriber(), stateChangeEntity);
if (plannedEventType.isEmpty()) {
stateContext.setStatus(StateChangeStatus.FAILURE);
stateContext.addFieldMessage("cmmsMachineParts.maintenanceEventStateChange.plannedEventType.required", StateMessageType.FAILURE, MaintenanceEventStateChangeFields.PLANNED_EVENT_TYPE);
stateContext.save();
maintenanceEventStateChangeViewClient.showMessages(new ViewContextHolder(view, form), stateContext);
return;
}
String plannedEventCorrect = createPlannedEvent(stateChangeEntity, plannedEventType);
if (!StringUtils.isEmpty(plannedEventCorrect)) {
stateContext.setStatus(StateChangeStatus.IN_PROGRESS);
stateContext.addMessage("cmmsMachineParts.maintenanceEventStateChange.success.plannedEventCreated", StateMessageType.INFO, plannedEventCorrect);
maintenanceEventStateChangeAspect.changeState(stateContext);
maintenanceEventStateChangeViewClient.showMessages(new ViewContextHolder(view, form), stateContext);
} else {
stateContext.setStatus(StateChangeStatus.FAILURE);
stateContext.addMessage("cmmsMachineParts.maintenanceEventStateChange.error.plannedEventNotCreated", StateMessageType.FAILURE);
stateContext.save();
maintenanceEventStateChangeViewClient.showMessages(new ViewContextHolder(view, form), stateContext);
}
}
Aggregations