Search in sources :

Example 21 with StateChangeContext

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

the class OrderCreationService method createTechnology.

private Either<String, Entity> createTechnology(OrderCreationRequest orderCreationRequest) {
    Entity product = getProduct(orderCreationRequest.getProductId());
    Entity parameter = parameterService.getParameter();
    Entity operation = parameter.getBelongsToField(L_DASHBOARD_OPERATION);
    Entity dashboardComponentsLocation = parameter.getBelongsToField(OrderCreationService.L_DASHBOARD_COMPONENTS_LOCATION);
    Entity dashboardProductsInputLocation = parameter.getBelongsToField(OrderCreationService.L_DASHBOARD_PRODUCTS_INPUT_LOCATION);
    Entity toc = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_TECHNOLOGY_OPERATION_COMPONENT).create();
    toc.setField(TechnologyOperationComponentFields.OPERATION, operation);
    toc.setField(TechnologyOperationComponentFields.ENTITY_TYPE, L_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, L_ALL);
    }
    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");
    }
    Entity topoc = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_OPERATION_PRODUCT_OUT_COMPONENT).create();
    topoc.setField(OperationProductOutComponentFields.PRODUCT, product);
    topoc.setField(OperationProductOutComponentFields.QUANTITY, BigDecimal.ONE);
    toc.setField(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS, Lists.newArrayList(topoc));
    List<Entity> topics = Lists.newArrayList();
    for (MaterialDto material : orderCreationRequest.getMaterials()) {
        Entity inProduct = getProduct(material.getProductId());
        Entity topic = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_OPERATION_PRODUCT_IN_COMPONENT).create();
        topic.setField(OperationProductInComponentFields.PRODUCT, inProduct);
        topic.setField(OperationProductInComponentFields.QUANTITY, material.getQuantityPerUnit());
        topics.add(topic);
    }
    toc.setField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS, topics);
    String range = parameter.getStringField(L_RANGE);
    Entity technology = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_TECHNOLOGY).create();
    technology.setField(TechnologyFields.NUMBER, technologyNameAndNumberGenerator.generateNumber(product));
    technology.setField(TechnologyFields.NAME, technologyNameAndNumberGenerator.generateName(product));
    technology.setField(TechnologyFields.PRODUCT, product);
    technology.setField(TechnologyFields.EXTERNAL_SYNCHRONIZED, true);
    technology.setField(TechnologyFields.OPERATION_COMPONENTS, Lists.newArrayList(toc));
    technology.setField(L_RANGE, range);
    technology.setField("componentsLocation", dashboardComponentsLocation);
    technology.setField("productsInputLocation", dashboardProductsInputLocation);
    technology.setField("typeOfProductionRecording", "02cumulated");
    technology = technology.getDataDefinition().save(technology);
    if (technology.isValid()) {
        final StateChangeContext technologyStateChangeContext = stateChangeContextBuilder.build(technologyStateChangeAspect.getChangeEntityDescriber(), technology, TechnologyState.ACCEPTED.getStringValue());
        technologyStateChangeAspect.changeState(technologyStateChangeContext);
        technology = technology.getDataDefinition().get(technology.getId());
        if (!technology.getStringField(TechnologyFields.STATE).equals(TechnologyStateStringValues.ACCEPTED)) {
            return Either.left(translationService.translate("basic.dashboard.orderDefinitionWizard.createTechnology.acceptError", LocaleContextHolder.getLocale()));
        }
        technology.setField(TechnologyFields.MASTER, Boolean.TRUE);
        technology.getDataDefinition().save(technology);
    } else {
        return Either.left(translationService.translate("basic.dashboard.orderDefinitionWizard.createTechnology.validationError", LocaleContextHolder.getLocale()));
    }
    return Either.right(technology);
}
Also used : Entity(com.qcadoo.model.api.Entity) MaterialDto(com.qcadoo.mes.technologies.controller.dataProvider.MaterialDto) StateChangeContext(com.qcadoo.mes.states.StateChangeContext)

Example 22 with StateChangeContext

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

the class OrderStateReasonViewListeners method continueStateChange.

public void continueStateChange(final ViewDefinitionState view, final ComponentState component, final String[] args) {
    final FormComponent form = (FormComponent) component;
    form.performEvent(view, "save");
    if (!form.isValid()) {
        return;
    }
    final Entity stateChangeEntity = ((FormComponent) form).getEntity();
    final StateChangeContext stateContext = stateChangeContextBuilder.build(orderStateChangeService.getChangeEntityDescriber(), stateChangeEntity);
    stateContext.setStatus(StateChangeStatus.IN_PROGRESS);
    orderStateChangeService.changeState(stateContext);
    orderStateChangeViewClient.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 23 with StateChangeContext

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

the class WarehouseIssueStateService method checkIfAnyNotIssuedPositionsExists.

public boolean checkIfAnyNotIssuedPositionsExists(final StateChangeContext stateChangeContext) {
    Entity warehouseIssue = stateChangeContext.getOwner();
    List<Entity> issues = warehouseIssue.getHasManyField(WarehouseIssueFields.ISSUES);
    if (!issues.stream().filter(e -> !e.getBooleanField(IssueFields.ISSUED)).collect(Collectors.toList()).isEmpty()) {
        stateChangeContext.addValidationError("productFlowThruDivision.issue.state.complete.error.existsNotIssuedPositions");
        return true;
    }
    return false;
}
Also used : DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) ReservationsServiceForProductsToIssue(com.qcadoo.mes.productFlowThruDivision.reservation.ReservationsServiceForProductsToIssue) MultiHashMap(org.apache.commons.collections.MultiHashMap) MaterialFlowConstants(com.qcadoo.mes.materialFlow.constants.MaterialFlowConstants) Date(java.util.Date) IssueFields(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.constans.IssueFields) Autowired(org.springframework.beans.factory.annotation.Autowired) CreationDocumentResponse(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.CreationDocumentResponse) OrdersConstants(com.qcadoo.mes.orders.constants.OrdersConstants) Lists(com.google.common.collect.Lists) WarehouseIssueService(com.qcadoo.mes.productFlowThruDivision.service.WarehouseIssueService) Service(org.springframework.stereotype.Service) Map(java.util.Map) WarehouseIssueFields(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.constans.WarehouseIssueFields) LocationFields(com.qcadoo.mes.materialFlow.constants.LocationFields) StateChangeContext(com.qcadoo.mes.states.StateChangeContext) WarehouseIssueParameterService(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.WarehouseIssueParameterService) IssueValidators(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.validators.IssueValidators) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) DataDefinition(com.qcadoo.model.api.DataDefinition) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) MultiMap(org.apache.commons.collections.MultiMap) List(java.util.List) Entity(com.qcadoo.model.api.Entity) UpdateIssuesLocationsQuantityStatusHolder(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.UpdateIssuesLocationsQuantityStatusHolder) StateChangeStatus(com.qcadoo.mes.states.constants.StateChangeStatus) Entity(com.qcadoo.model.api.Entity)

Example 24 with StateChangeContext

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

the class TechnologyValidationService method checkIfEveryInComponentsHasQuantities.

public boolean checkIfEveryInComponentsHasQuantities(final StateChangeContext stateChangeContext) {
    Entity technology = stateChangeContext.getOwner();
    final Entity savedTechnology = technology.getDataDefinition().get(technology.getId());
    final EntityTree operationComponents = savedTechnology.getTreeField(TechnologyFields.OPERATION_COMPONENTS);
    for (Entity operationComponent : operationComponents) {
        List<Entity> operationProductInComponents = operationComponent.getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS);
        for (Entity operationProductInComponent : operationProductInComponents) {
            boolean differentProductsInDifferentSizes = operationProductInComponent.getBooleanField(OperationProductInComponentFields.DIFFERENT_PRODUCTS_IN_DIFFERENT_SIZES);
            boolean variousQuantitiesInProductsBySize = operationProductInComponent.getBooleanField(OperationProductInComponentFields.VARIOUS_QUANTITIES_IN_PRODUCTS_BY_SIZE);
            if (!differentProductsInDifferentSizes && Objects.isNull(operationProductInComponent.getDecimalField(OperationProductInComponentFields.QUANTITY))) {
                stateChangeContext.addValidationError("technologies.technology.validate.global.error.inComponentsQuantitiesNotFilled", operationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION).getStringField(OperationFields.NUMBER), operationComponent.getStringField(TechnologyOperationComponentFields.NODE_NUMBER));
                return false;
            }
            if (differentProductsInDifferentSizes && variousQuantitiesInProductsBySize) {
                boolean quantitiesOrProductsNotSet = false;
                if (operationProductInComponent.getHasManyField(OperationProductInComponentFields.PRODUCT_BY_SIZE_GROUPS).isEmpty()) {
                    quantitiesOrProductsNotSet = true;
                } else if (operationProductInComponent.getHasManyField(OperationProductInComponentFields.PRODUCT_BY_SIZE_GROUPS).stream().anyMatch(pbs -> Objects.isNull(pbs.getDecimalField(ProductBySizeGroupFields.QUANTITY)))) {
                    quantitiesOrProductsNotSet = true;
                }
                if (quantitiesOrProductsNotSet) {
                    stateChangeContext.addValidationError("technologies.technology.validate.global.error.variousQuantitiesInProductsBySizeNotFilled", operationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION).getStringField(OperationFields.NUMBER), operationComponent.getStringField(TechnologyOperationComponentFields.NODE_NUMBER));
                    return false;
                }
            }
        }
    }
    return true;
}
Also used : TechnologyTreeValidationService(com.qcadoo.mes.technologies.tree.TechnologyTreeValidationService) MessageType(com.qcadoo.view.api.ComponentState.MessageType) PRODUCT(com.qcadoo.mes.technologies.constants.TechnologyFields.PRODUCT) ProductFamilyElementType(com.qcadoo.mes.basic.constants.ProductFamilyElementType) Autowired(org.springframework.beans.factory.annotation.Autowired) ProductStructureTreeService(com.qcadoo.mes.technologies.tree.ProductStructureTreeService) TechnologyService(com.qcadoo.mes.technologies.TechnologyService) StateMessageType(com.qcadoo.mes.states.messages.constants.StateMessageType) HashSet(java.util.HashSet) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) BigDecimal(java.math.BigDecimal) Lists(com.google.common.collect.Lists) Locale(java.util.Locale) Service(org.springframework.stereotype.Service) FormComponent(com.qcadoo.view.api.components.FormComponent) Map(java.util.Map) ProductQuantitiesService(com.qcadoo.mes.technologies.ProductQuantitiesService) OPERATION_COMPONENTS(com.qcadoo.mes.technologies.constants.TechnologyFields.OPERATION_COMPONENTS) StateChangeContext(com.qcadoo.mes.states.StateChangeContext) UNIT(com.qcadoo.mes.basic.constants.ProductFields.UNIT) Set(java.util.Set) TranslationService(com.qcadoo.localization.api.TranslationService) DataDefinition(com.qcadoo.model.api.DataDefinition) EntityTree(com.qcadoo.model.api.EntityTree) Sets(com.google.common.collect.Sets) EntityList(com.qcadoo.model.api.EntityList) Objects(java.util.Objects) com.qcadoo.mes.technologies.constants(com.qcadoo.mes.technologies.constants) Entity(com.qcadoo.model.api.Entity) List(java.util.List) ProductFields(com.qcadoo.mes.basic.constants.ProductFields) EntityTreeNode(com.qcadoo.model.api.EntityTreeNode) Entity(com.qcadoo.model.api.Entity) EntityTree(com.qcadoo.model.api.EntityTree)

Example 25 with StateChangeContext

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

the class TechnologyValidationService method checkIfWasteProductsIsRightMarked.

public boolean checkIfWasteProductsIsRightMarked(final StateChangeContext stateChangeContext) {
    Entity technology = stateChangeContext.getOwner();
    final Entity savedTechnology = technology.getDataDefinition().get(technology.getId());
    final EntityTree operationComponents = savedTechnology.getTreeField(TechnologyFields.OPERATION_COMPONENTS);
    for (Entity operationComponent : operationComponents) {
        List<Entity> operationProductOutComponents = operationComponent.getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS);
        long notWasteCount = operationProductOutComponents.stream().filter(opoc -> !opoc.getBooleanField(OperationProductOutComponentFields.WASTE)).count();
        if (notWasteCount > 1 || notWasteCount == 0) {
            stateChangeContext.addValidationError("technologies.technology.validate.global.error.noProductsWithWasteFlagNotMarked", operationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION).getStringField(OperationFields.NUMBER), operationComponent.getStringField(TechnologyOperationComponentFields.NODE_NUMBER));
            return false;
        }
    }
    return true;
}
Also used : TechnologyTreeValidationService(com.qcadoo.mes.technologies.tree.TechnologyTreeValidationService) MessageType(com.qcadoo.view.api.ComponentState.MessageType) PRODUCT(com.qcadoo.mes.technologies.constants.TechnologyFields.PRODUCT) ProductFamilyElementType(com.qcadoo.mes.basic.constants.ProductFamilyElementType) Autowired(org.springframework.beans.factory.annotation.Autowired) ProductStructureTreeService(com.qcadoo.mes.technologies.tree.ProductStructureTreeService) TechnologyService(com.qcadoo.mes.technologies.TechnologyService) StateMessageType(com.qcadoo.mes.states.messages.constants.StateMessageType) HashSet(java.util.HashSet) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) BigDecimal(java.math.BigDecimal) Lists(com.google.common.collect.Lists) Locale(java.util.Locale) Service(org.springframework.stereotype.Service) FormComponent(com.qcadoo.view.api.components.FormComponent) Map(java.util.Map) ProductQuantitiesService(com.qcadoo.mes.technologies.ProductQuantitiesService) OPERATION_COMPONENTS(com.qcadoo.mes.technologies.constants.TechnologyFields.OPERATION_COMPONENTS) StateChangeContext(com.qcadoo.mes.states.StateChangeContext) UNIT(com.qcadoo.mes.basic.constants.ProductFields.UNIT) Set(java.util.Set) TranslationService(com.qcadoo.localization.api.TranslationService) DataDefinition(com.qcadoo.model.api.DataDefinition) EntityTree(com.qcadoo.model.api.EntityTree) Sets(com.google.common.collect.Sets) EntityList(com.qcadoo.model.api.EntityList) Objects(java.util.Objects) com.qcadoo.mes.technologies.constants(com.qcadoo.mes.technologies.constants) Entity(com.qcadoo.model.api.Entity) List(java.util.List) ProductFields(com.qcadoo.mes.basic.constants.ProductFields) EntityTreeNode(com.qcadoo.model.api.EntityTreeNode) Entity(com.qcadoo.model.api.Entity) EntityTree(com.qcadoo.model.api.EntityTree)

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