Search in sources :

Example 1 with ViewContextHolder

use of com.qcadoo.mes.states.service.client.util.ViewContextHolder in project mes by qcadoo.

the class ChangeTechnologyParametersListeners method createCustomizedTechnologies.

@Transactional
private void createCustomizedTechnologies(ViewDefinitionState view, ComponentState state, Set<Long> ids, Entity entity, Entity finalGroup, BigDecimal finalStandardPerformance) {
    boolean updateOperationTimeNorms = entity.getBooleanField(L_UPDATE_OPERATION_TIME_NORMS);
    ids.forEach(techId -> {
        Entity technology = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_TECHNOLOGY).get(techId);
        technology.setField(TechnologyFields.MASTER, Boolean.FALSE);
        technology = technology.getDataDefinition().save(technology);
        if (technology.isValid()) {
            Entity copyTechnology = technology.getDataDefinition().copy(technology.getId()).get(0);
            Entity product = technology.getBelongsToField(TechnologyFields.PRODUCT);
            copyTechnology.setField(TechnologyFields.NUMBER, technologyNameAndNumberGenerator.generateNumber(product));
            copyTechnology.setField(TechnologyFields.NAME, technologyNameAndNumberGenerator.generateName(product));
            if (entity.getBooleanField(L_CHANGE_GROUP)) {
                copyTechnology.setField(TechnologyFields.TECHNOLOGY_GROUP, finalGroup);
            }
            if (entity.getBooleanField(L_CHANGE_PERFORMANCE_NORM)) {
                technologyService.getMasterTechnologyProductionLine(copyTechnology).ifPresent(e -> {
                    e.setField(TechnologyProductionLineFields.STANDARD_PERFORMANCE, finalStandardPerformance);
                    e.getDataDefinition().save(e);
                });
            }
            copyTechnology = copyTechnology.getDataDefinition().save(copyTechnology);
            Entity copyTechnologyDb = copyTechnology.getDataDefinition().get(copyTechnology.getId());
            if (updateOperationTimeNorms) {
                List<Entity> tocs = copyTechnologyDb.getHasManyField(TechnologyFields.OPERATION_COMPONENTS);
                tocs.forEach(toc -> {
                    Entity operation = toc.getBelongsToField(TechnologyOperationComponentFields.OPERATION);
                    for (String fieldName : FIELDS_OPERATION) {
                        toc.setField(fieldName, operation.getField(fieldName));
                    }
                    if (operation.getField(NEXT_OPERATION_AFTER_PRODUCED_TYPE) == null) {
                        toc.setField(NEXT_OPERATION_AFTER_PRODUCED_TYPE, "01all");
                    }
                    if (operation.getField(PRODUCTION_IN_ONE_CYCLE) == null) {
                        toc.setField(PRODUCTION_IN_ONE_CYCLE, "1");
                    }
                    if (operation.getField(NEXT_OPERATION_AFTER_PRODUCED_QUANTITY) == null) {
                        toc.setField(NEXT_OPERATION_AFTER_PRODUCED_QUANTITY, "0");
                    }
                    copyOperationWorkstationTimes(toc, operation);
                    toc.getDataDefinition().save(toc);
                });
            }
            technologyStateChangeViewClient.changeState(new ViewContextHolder(view, state), TechnologyStateStringValues.OUTDATED, technology);
            Entity savedTech = copyTechnologyDb.getDataDefinition().get(copyTechnologyDb.getId());
            if (savedTech.isValid()) {
                technologyStateChangeViewClient.changeState(new ViewContextHolder(view, state), TechnologyStateStringValues.ACCEPTED, savedTech);
                Entity tech = savedTech.getDataDefinition().get(savedTech.getId());
                tech.setField(TechnologyFields.MASTER, Boolean.TRUE);
                tech.getDataDefinition().save(tech);
            } else {
                throw new IllegalStateException("There was a problem creating the technology");
            }
        } else {
            throw new IllegalStateException("There was a problem creating the technology");
        }
    });
}
Also used : Entity(com.qcadoo.model.api.Entity) ViewContextHolder(com.qcadoo.mes.states.service.client.util.ViewContextHolder) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with ViewContextHolder

use of com.qcadoo.mes.states.service.client.util.ViewContextHolder in project mes by qcadoo.

the class ModifyTechnologyListeners method customizeTechnology.

@Transactional
private void customizeTechnology(final ViewDefinitionState view, final ComponentState state, Entity technology, List<Entity> entries, Entity mt, ModifyTechnologyResult modifyTechnologyResult) {
    technology.setField(TechnologyFields.MASTER, Boolean.FALSE);
    technology = technology.getDataDefinition().save(technology);
    if (technology.isValid()) {
        Entity copyTechnology = technology.getDataDefinition().copy(technology.getId()).get(0);
        Entity product = technology.getBelongsToField(TechnologyFields.PRODUCT);
        copyTechnology.setField(TechnologyFields.NUMBER, technologyNameAndNumberGenerator.generateNumber(product));
        copyTechnology.setField(TechnologyFields.NAME, technologyNameAndNumberGenerator.generateName(product));
        copyTechnology = copyTechnology.getDataDefinition().save(copyTechnology);
        for (Entity entry : entries) {
            modifyOperation(mt, copyTechnology, entry);
        }
        copyTechnology = copyTechnology.getDataDefinition().get(copyTechnology.getId());
        technologyStateChangeViewClient.changeState(new ViewContextHolder(view, state), TechnologyStateStringValues.ACCEPTED, copyTechnology);
        Entity tech = copyTechnology.getDataDefinition().get(copyTechnology.getId());
        tech.setField(TechnologyFields.MASTER, Boolean.TRUE);
        tech.getDataDefinition().save(tech);
        modifyTechnologyResult.addCreatedTechnology(tech.getStringField(TechnologyFields.NUMBER));
    } else {
        throw new IllegalStateException("There was a problem creating the technology");
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) ViewContextHolder(com.qcadoo.mes.states.service.client.util.ViewContextHolder) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with ViewContextHolder

use of com.qcadoo.mes.states.service.client.util.ViewContextHolder 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)

Example 4 with ViewContextHolder

use of com.qcadoo.mes.states.service.client.util.ViewContextHolder 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 5 with ViewContextHolder

use of com.qcadoo.mes.states.service.client.util.ViewContextHolder 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)

Aggregations

ViewContextHolder (com.qcadoo.mes.states.service.client.util.ViewContextHolder)13 Entity (com.qcadoo.model.api.Entity)12 FormComponent (com.qcadoo.view.api.components.FormComponent)10 StateChangeContext (com.qcadoo.mes.states.StateChangeContext)8 Transactional (org.springframework.transaction.annotation.Transactional)2 GridComponent (com.qcadoo.view.api.components.GridComponent)1