use of com.qcadoo.mes.states.StateChangeContext in project mes by qcadoo.
the class StateChangeContextBuilderTest method shouldBuildStateChangeContextBasedOnStateChangeEntity.
@Test
public final void shouldBuildStateChangeContextBasedOnStateChangeEntity() {
// given
stubSearchCriteria(Lists.<Entity>newArrayList());
// when
final StateChangeContext stateChangeContext = stateChangeContextBuilder.build(describer, stateChangeEntity);
// 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 AbstractStateChangeViewClient method changeState.
@Override
public final void changeState(final ViewContextHolder viewContext, final String targetState, final Entity entity) {
try {
LOG.info(String.format("Change state. Entity name : %S id : %d. Target state : %S", entity.getDataDefinition().getName(), entity.getId(), targetState));
StateChangeContext stateChangeContext = stateChangeContextBuilder.build(getStateChangeService().getChangeEntityDescriber(), entity, targetState);
getStateChangeService().changeState(stateChangeContext);
viewClientUtil.refreshComponent(viewContext);
showMessages(viewContext, stateChangeContext);
stateChangeContext = null;
} catch (AnotherChangeInProgressException e) {
viewContext.getMessagesConsumer().addMessage("states.messages.change.failure.anotherChangeInProgress", MessageType.FAILURE);
LOG.info(String.format("Another state change in progress. Entity name : %S id : %d. Target state : %S", entity.getDataDefinition().getName(), entity.getId(), targetState));
} catch (StateTransitionNotAlloweException e) {
viewContext.getMessagesConsumer().addMessage("states.messages.change.failure.transitionNotAllowed", MessageType.FAILURE);
LOG.info(String.format("State change - transition not allowed. Entity name : %S id : %d. Target state : %S", entity.getDataDefinition().getName(), entity.getId(), targetState));
} catch (Exception e) {
throw new StateChangeException(e);
}
}
use of com.qcadoo.mes.states.StateChangeContext in project mes by qcadoo.
the class StateChangeSamplesClientImpl method resumeStateChange.
@Override
public void resumeStateChange(final Entity entity, final Entity stateChangeEntity) {
entity.getDataDefinition().save(entity);
final StateChangeService stateChangeService = stateChangeServiceResolver.get(entity.getDataDefinition());
if (stateChangeService != null) {
final StateChangeEntityDescriber describer = stateChangeService.getChangeEntityDescriber();
final StateChangeContext stateChangeContext = stateChangeContextBuilder.build(describer, stateChangeEntity);
stateChangeContext.setStatus(StateChangeStatus.IN_PROGRESS);
stateChangeService.changeState(stateChangeContext);
checkResults(stateChangeContext);
}
}
use of com.qcadoo.mes.states.StateChangeContext in project mes by qcadoo.
the class MaintenanceEventToPlannedEventListeners method cancelStateChange.
public void cancelStateChange(final ViewDefinitionState view, final ComponentState form, final String[] args) {
final Entity stateChangeEntity = ((FormComponent) form).getEntity();
final StateChangeContext stateContext = stateChangeContextBuilder.build(maintenanceEventStateChangeAspect.getChangeEntityDescriber(), stateChangeEntity);
stateContext.setStatus(StateChangeStatus.CANCELED);
stateContext.save();
maintenanceEventStateChangeViewClient.showMessages(new ViewContextHolder(view, form), stateContext);
}
use of com.qcadoo.mes.states.StateChangeContext in project mes by qcadoo.
the class DashboardKanbanController method updateOrderState.
@ResponseBody
@RequestMapping(value = "/updateOrderState/{orderId}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public OrderResponse updateOrderState(@PathVariable final Long orderId) {
Entity order = getOrderDD().get(orderId);
String targetState = OrderState.IN_PROGRESS.getStringValue();
if (OrderState.IN_PROGRESS.getStringValue().equals(order.getStringField(OrderFields.STATE))) {
targetState = OrderState.COMPLETED.getStringValue();
}
StateChangeContext orderStateChangeContext = stateChangeContextBuilder.build(orderStateChangeAspect.getChangeEntityDescriber(), order, targetState);
orderStateChangeAspect.changeState(orderStateChangeContext);
OrderResponse orderResponse = new OrderResponse(dashboardKanbanDataProvider.getOrder(orderId));
List<ErrorMessage> errors = Lists.newArrayList();
if (!orderStateChangeContext.getAllMessages().isEmpty()) {
for (Entity entity : orderStateChangeContext.getAllMessages()) {
errors.add(new ErrorMessage(MessagesUtil.getKey(entity), MessagesUtil.getArgs(entity)));
}
}
if (!errors.isEmpty()) {
String errorMessages = errors.stream().map(errorMessage -> translationService.translate(errorMessage.getMessage(), LocaleContextHolder.getLocale(), errorMessage.getVars())).collect(Collectors.joining(", "));
orderResponse.setMessage(translationService.translate("orders.order.orderStates.error", LocaleContextHolder.getLocale(), errorMessages));
}
return orderResponse;
}
Aggregations