use of com.qcadoo.mes.states.StateEnum in project mes by qcadoo.
the class StateExecutorService method saveStateChangeContext.
private Entity saveStateChangeContext(final Entity entity, Entity stateChangeEntity, final StateChangeEntityDescriber describer, final String _sourceState, final String _targetState, final StateChangeStatus status) {
final StateEnum sourceState = describer.parseStateEnum(_sourceState);
final StateEnum targetState = describer.parseStateEnum(_targetState);
if (Objects.nonNull(sourceState) && !sourceState.canChangeTo(targetState)) {
throw new StateTransitionNotAlloweException(sourceState, targetState);
}
checkForUnfinishedStateChange(describer, entity);
stateChangeEntity = saveStateChangeEntity(stateChangeEntity, status);
return stateChangeEntity;
}
use of com.qcadoo.mes.states.StateEnum in project mes by qcadoo.
the class OrderStatesListenerServicePFTD method checkMaterialAvailability.
public void checkMaterialAvailability(StateChangeContext stateChangeContext) {
Entity order = stateChangeContext.getOwner();
StateEnum targetState = stateChangeContext.getStateEnumValue(stateChangeContext.getDescriber().getTargetStateFieldName());
Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY);
String momentOfValidation = parameterService.getParameter().getStringField(ParameterFieldsPFTD.MOMENT_OF_VALIDATION);
String message = "productFlowThruDivision.order.state.accept.error.missingComponents";
String messageShort = "productFlowThruDivision.order.state.accept.error.missingComponentsShort";
if (MomentOfValidation.ORDER_STARTING.getStrValue().equals(momentOfValidation)) {
message = "productFlowThruDivision.order.state.inProgress.error.missingComponents";
messageShort = "productFlowThruDivision.order.state.inProgress.error.missingComponentsShort";
}
if (order.getField(OrderFieldsPFTD.IGNORE_MISSING_COMPONENTS) != null && !order.getBooleanField(OrderFieldsPFTD.IGNORE_MISSING_COMPONENTS) && technology != null && (OrderState.ACCEPTED == targetState && MomentOfValidation.ORDER_ACCEPTANCE.getStrValue().equals(momentOfValidation) || OrderState.IN_PROGRESS == targetState && MomentOfValidation.ORDER_STARTING.getStrValue().equals(momentOfValidation))) {
List<Entity> entries = orderMaterialAvailability.generateMaterialAvailabilityForOrder(order);
List<Entity> notAvailableProducts = entries.stream().filter(en -> !AvailabilityOfMaterialAvailability.FULL.getStrValue().equals(en.getStringField(MaterialAvailabilityFields.AVAILABILITY))).map(entity -> entity.getBelongsToField(MaterialAvailabilityFields.PRODUCT)).collect(Collectors.toList());
if (!notAvailableProducts.isEmpty()) {
String missingProductNames = StringUtils.join(notAvailableProducts.stream().map(product -> product.getStringField(ProductFields.NAME)).collect(Collectors.toList()), ", ");
if (missingProductNames.length() < 255) {
stateChangeContext.addMessage(message, StateMessageType.FAILURE, false, missingProductNames);
} else {
stateChangeContext.addMessage(messageShort, StateMessageType.FAILURE, false);
}
}
}
}
use of com.qcadoo.mes.states.StateEnum in project mes by qcadoo.
the class StateExecutorService method canChangeState.
private <M extends StateService> boolean canChangeState(final StateChangeEntityDescriber describer, final Entity owner, final String targetStateString) {
final StateEnum sourceState = describer.parseStateEnum(owner.getStringField(describer.getOwnerStateFieldName()));
final StateEnum targetState = describer.parseStateEnum(targetStateString);
// TODO wrzucamy błąd do encji?
if (Objects.nonNull(sourceState) && !sourceState.canChangeTo(targetState)) {
return false;
}
return true;
}
use of com.qcadoo.mes.states.StateEnum in project mes by qcadoo.
the class StateChangeContextBuilderImpl method build.
@Override
@Transactional
public StateChangeContext build(final StateChangeEntityDescriber describer, final Entity owner, final String targetStateString) {
final Entity persistedOwner = owner.getDataDefinition().save(owner);
final DataDefinition stateChangeDataDefinition = describer.getDataDefinition();
final StateEnum sourceState = describer.parseStateEnum(owner.getStringField(describer.getOwnerStateFieldName()));
final StateEnum targetState = describer.parseStateEnum(targetStateString);
if (sourceState != null && !sourceState.canChangeTo(targetState)) {
throw new StateTransitionNotAlloweException(sourceState, targetState);
}
final Entity stateChangeEntity = stateChangeEntityBuilder.build(describer, persistedOwner, targetState);
checkForUnfinishedStateChange(describer, persistedOwner);
return new StateChangeContextImpl(stateChangeDataDefinition.save(stateChangeEntity), describer, messageService);
}
use of com.qcadoo.mes.states.StateEnum in project mes by qcadoo.
the class AbstractStateChangeAspect method performChangeEntityState.
@Transactional
protected void performChangeEntityState(final StateChangeContext stateChangeContext) {
final StateChangeEntityDescriber describer = stateChangeContext.getDescriber();
if (!StateChangePhaseUtil.canRun(stateChangeContext)) {
if (!stateChangeContext.isOwnerValid()) {
stateChangeContext.setStatus(StateChangeStatus.FAILURE);
stateChangeContext.setField(describer.getDateTimeFieldName(), new Date());
LOGGER.info(String.format("State change : failure. Entity name : %S id : %d.", stateChangeContext.getOwner().getDataDefinition().getName(), stateChangeContext.getOwner().getId()));
}
return;
}
final Entity owner = stateChangeContext.getOwner();
final StateEnum sourceState = stateChangeContext.getStateEnumValue(describer.getSourceStateFieldName());
final StateEnum targetState = stateChangeContext.getStateEnumValue(describer.getTargetStateFieldName());
if (sourceState != null && !sourceState.canChangeTo(targetState)) {
throw new StateTransitionNotAlloweException(sourceState, targetState);
}
boolean ownerIsValid = stateChangeContext.isOwnerValid();
if (ownerIsValid) {
owner.setField(describer.getOwnerStateFieldName(), targetState.getStringValue());
ownerIsValid = owner.getDataDefinition().save(owner).isValid();
}
if (ownerIsValid) {
stateChangeContext.setStatus(SUCCESSFUL);
LOGGER.info(String.format("State change : successful. Entity name : %S id : %d. Target state : %S", owner.getDataDefinition().getName(), owner.getId(), targetState));
} else {
LOGGER.info(String.format("State change : failure. Entity name : %S id : %d. Target state : %S", owner.getDataDefinition().getName(), owner.getId(), targetState));
ValidationMessageHelper.copyErrorsFromEntity(stateChangeContext, owner);
stateChangeContext.setStatus(StateChangeStatus.FAILURE);
}
stateChangeContext.setField(describer.getDateTimeFieldName(), new Date());
stateChangeContext.save();
}
Aggregations