Search in sources :

Example 1 with StateChangeContext

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);
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) StateChangeContext(com.qcadoo.mes.states.StateChangeContext)

Example 2 with 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());
        }
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) List(java.util.List) StateChangeContext(com.qcadoo.mes.states.StateChangeContext) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage)

Example 3 with StateChangeContext

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());
}
Also used : StateChangeContext(com.qcadoo.mes.states.StateChangeContext) StateChangeTest(com.qcadoo.mes.states.StateChangeTest) Test(org.junit.Test)

Example 4 with StateChangeContext

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;
}
Also used : StateChangeEntityDescriber(com.qcadoo.mes.states.StateChangeEntityDescriber) Entity(com.qcadoo.model.api.Entity) StateChangeContext(com.qcadoo.mes.states.StateChangeContext)

Example 5 with StateChangeContext

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);
    }
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) ViewContextHolder(com.qcadoo.mes.states.service.client.util.ViewContextHolder) StateChangeContext(com.qcadoo.mes.states.StateChangeContext)

Aggregations

StateChangeContext (com.qcadoo.mes.states.StateChangeContext)25 Entity (com.qcadoo.model.api.Entity)20 FormComponent (com.qcadoo.view.api.components.FormComponent)10 ViewContextHolder (com.qcadoo.mes.states.service.client.util.ViewContextHolder)8 Lists (com.google.common.collect.Lists)7 List (java.util.List)7 Autowired (org.springframework.beans.factory.annotation.Autowired)7 Service (org.springframework.stereotype.Service)6 TranslationService (com.qcadoo.localization.api.TranslationService)5 DataDefinition (com.qcadoo.model.api.DataDefinition)5 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)5 Collectors (java.util.stream.Collectors)5 Sets (com.google.common.collect.Sets)4 ProductFields (com.qcadoo.mes.basic.constants.ProductFields)4 ErrorMessage (com.qcadoo.model.api.validators.ErrorMessage)4 ProductFamilyElementType (com.qcadoo.mes.basic.constants.ProductFamilyElementType)3 OrderFields (com.qcadoo.mes.orders.constants.OrderFields)3 OrdersConstants (com.qcadoo.mes.orders.constants.OrdersConstants)3 StateMessageType (com.qcadoo.mes.states.messages.constants.StateMessageType)3 BigDecimal (java.math.BigDecimal)3