Search in sources :

Example 6 with StateChangeContext

use of com.qcadoo.mes.states.StateChangeContext in project mes by qcadoo.

the class PlannedEventReasonViewListeners method cancelStateChange.

public void cancelStateChange(final ViewDefinitionState view, final ComponentState form, final String[] args) {
    final Entity stateChangeEntity = ((FormComponent) form).getEntity();
    stateChangeEntity.setField(PlannedEventStateChangeFields.COMMENT_REQUIRED, false);
    final StateChangeContext stateContext = stateChangeContextBuilder.build(plannedEventStateChangeAspect.getChangeEntityDescriber(), stateChangeEntity);
    stateContext.setStatus(StateChangeStatus.CANCELED);
    stateContext.save();
    plannedEventStateChangeViewClient.showMessages(new ViewContextHolder(view, form), stateContext);
}
Also used : Entity(com.qcadoo.model.api.Entity) FormComponent(com.qcadoo.view.api.components.FormComponent) ViewContextHolder(com.qcadoo.mes.states.service.client.util.ViewContextHolder) StateChangeContext(com.qcadoo.mes.states.StateChangeContext)

Example 7 with StateChangeContext

use of com.qcadoo.mes.states.StateChangeContext in project mes by qcadoo.

the class PlannedEventReasonViewListeners method continueStateChange.

public void continueStateChange(final ViewDefinitionState view, final ComponentState component, final String[] args) {
    final FormComponent form = (FormComponent) component;
    Entity eventStateChange = form.getPersistedEntityWithIncludedFormValues();
    plannedEventStateChangeValidators.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 StateChangeContext stateContext = stateChangeContextBuilder.build(plannedEventStateChangeAspect.getChangeEntityDescriber(), stateChangeEntity);
    stateContext.setStatus(StateChangeStatus.IN_PROGRESS);
    plannedEventStateChangeAspect.changeState(stateContext);
    plannedEventStateChangeViewClient.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)

Example 8 with StateChangeContext

use of com.qcadoo.mes.states.StateChangeContext in project mes by qcadoo.

the class MaintenanceEventReasonViewListeners 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 StateChangeContext stateContext = stateChangeContextBuilder.build(maintenanceEventStateChangeAspect.getChangeEntityDescriber(), stateChangeEntity);
    stateContext.setStatus(StateChangeStatus.IN_PROGRESS);
    maintenanceEventStateChangeAspect.changeState(stateContext);
    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)

Example 9 with StateChangeContext

use of com.qcadoo.mes.states.StateChangeContext in project mes by qcadoo.

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

Example 10 with StateChangeContext

use of com.qcadoo.mes.states.StateChangeContext in project mes by qcadoo.

the class AfterReviewEventsService method createAfterReviewEvents.

public void createAfterReviewEvents(final StateChangeContext stateChangeContext) {
    Entity plannedEvent = stateChangeContext.getOwner();
    if (!PlannedEventType.REVIEW.equals(PlannedEventType.from(plannedEvent))) {
        return;
    }
    List<Entity> incorrectActions = plannedEvent.getHasManyField(PlannedEventFields.ACTIONS).stream().filter(action -> action.getStringField(ActionForPlannedEventFields.STATE).equals(ActionForPlannedEventState.INCORRECT.getStringValue())).collect(Collectors.toList());
    List<String> createdActions = Lists.newArrayList();
    for (Entity action : incorrectActions) {
        createdActions.add(createAfterReviewEventForIncorrectAction(action, plannedEvent));
    }
    if (!createdActions.isEmpty()) {
        stateChangeContext.addMessage("cmmsMachineParts.plannedEvent.afterReviewEventsCreated", StateMessageType.INFO, true, createdActions.stream().collect(Collectors.joining(", ")));
    }
}
Also used : LocaleContextHolder(org.springframework.context.i18n.LocaleContextHolder) DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) StateChangeContext(com.qcadoo.mes.states.StateChangeContext) PlannedEventBasedOn(com.qcadoo.mes.cmmsMachineParts.constants.PlannedEventBasedOn) Autowired(org.springframework.beans.factory.annotation.Autowired) TranslationService(com.qcadoo.localization.api.TranslationService) CmmsMachinePartsConstants(com.qcadoo.mes.cmmsMachineParts.constants.CmmsMachinePartsConstants) Collectors(java.util.stream.Collectors) ActionForPlannedEventState(com.qcadoo.mes.cmmsMachineParts.constants.ActionForPlannedEventState) PlannedEventType(com.qcadoo.mes.cmmsMachineParts.constants.PlannedEventType) StateMessageType(com.qcadoo.mes.states.messages.constants.StateMessageType) PlannedEventFields(com.qcadoo.mes.cmmsMachineParts.constants.PlannedEventFields) List(java.util.List) Entity(com.qcadoo.model.api.Entity) Lists(com.google.common.collect.Lists) NumberGeneratorService(com.qcadoo.view.api.utils.NumberGeneratorService) Service(org.springframework.stereotype.Service) ActionForPlannedEventFields(com.qcadoo.mes.cmmsMachineParts.constants.ActionForPlannedEventFields) Entity(com.qcadoo.model.api.Entity)

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