Search in sources :

Example 1 with StateEnum

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;
}
Also used : StateEnum(com.qcadoo.mes.states.StateEnum) StateTransitionNotAlloweException(com.qcadoo.mes.states.exception.StateTransitionNotAlloweException)

Example 2 with StateEnum

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);
            }
        }
    }
}
Also used : MaterialFlowConstants(com.qcadoo.mes.materialFlow.constants.MaterialFlowConstants) LoggerFactory(org.slf4j.LoggerFactory) com.qcadoo.mes.productionCounting.constants(com.qcadoo.mes.productionCounting.constants) Autowired(org.springframework.beans.factory.annotation.Autowired) DocumentManagementService(com.qcadoo.mes.materialFlowResources.service.DocumentManagementService) UnitConversionService(com.qcadoo.model.api.units.UnitConversionService) SearchResult(com.qcadoo.model.api.search.SearchResult) StringUtils(org.apache.commons.lang3.StringUtils) BigDecimal(java.math.BigDecimal) ProductionCountingDocumentService(com.qcadoo.mes.productFlowThruDivision.service.ProductionCountingDocumentService) TransactionAspectSupport(org.springframework.transaction.interceptor.TransactionAspectSupport) RealProductionCostService(com.qcadoo.mes.productFlowThruDivision.realProductionCost.RealProductionCostService) SearchRestrictions(com.qcadoo.model.api.search.SearchRestrictions) OrderMaterialsCostDataGenerator(com.qcadoo.mes.costNormsForMaterials.orderRawMaterialCosts.OrderMaterialsCostDataGenerator) DataDefinition(com.qcadoo.model.api.DataDefinition) Collectors(java.util.stream.Collectors) DocumentBuilder(com.qcadoo.mes.materialFlowResources.service.DocumentBuilder) com.qcadoo.mes.productFlowThruDivision.constants(com.qcadoo.mes.productFlowThruDivision.constants) StateEnum(com.qcadoo.mes.states.StateEnum) Entity(com.qcadoo.model.api.Entity) ParameterService(com.qcadoo.mes.basic.ParameterService) ProductionCountingQuantityTypeOfMaterial(com.qcadoo.mes.basicProductionCounting.constants.ProductionCountingQuantityTypeOfMaterial) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) ProductionTrackingDocumentsHelper(com.qcadoo.mes.productionCounting.utils.ProductionTrackingDocumentsHelper) OrderFieldsCNFM(com.qcadoo.mes.costNormsForMaterials.constants.OrderFieldsCNFM) DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) java.util(java.util) MultiHashMap(org.apache.commons.collections.MultiHashMap) DocumentStateChangeService(com.qcadoo.mes.materialFlowResources.service.DocumentStateChangeService) OrderFields(com.qcadoo.mes.orders.constants.OrderFields) com.qcadoo.mes.materialFlowResources.constants(com.qcadoo.mes.materialFlowResources.constants) Multimap(com.google.common.collect.Multimap) StateMessageType(com.qcadoo.mes.states.messages.constants.StateMessageType) ProductionCountingQuantityFields(com.qcadoo.mes.basicProductionCounting.constants.ProductionCountingQuantityFields) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) BasicProductionCountingConstants(com.qcadoo.mes.basicProductionCounting.constants.BasicProductionCountingConstants) Lists(com.google.common.collect.Lists) PossibleUnitConversions(com.qcadoo.model.api.units.PossibleUnitConversions) ResourceManagementService(com.qcadoo.mes.materialFlowResources.service.ResourceManagementService) Service(org.springframework.stereotype.Service) StateChangeContext(com.qcadoo.mes.states.StateChangeContext) Logger(org.slf4j.Logger) OrderState(com.qcadoo.mes.orders.states.constants.OrderState) UnitConversionItemFieldsB(com.qcadoo.mes.basic.constants.UnitConversionItemFieldsB) Maps(com.google.common.collect.Maps) SearchQueryBuilder(com.qcadoo.model.api.search.SearchQueryBuilder) MultiMap(org.apache.commons.collections.MultiMap) ProductionCountingQuantityRole(com.qcadoo.mes.basicProductionCounting.constants.ProductionCountingQuantityRole) Either(com.qcadoo.commons.functional.Either) ProductFields(com.qcadoo.mes.basic.constants.ProductFields) Preconditions(com.google.common.base.Preconditions) OrderMaterialAvailability(com.qcadoo.mes.productFlowThruDivision.OrderMaterialAvailability) ProductionTrackingStateStringValues(com.qcadoo.mes.productionCounting.states.constants.ProductionTrackingStateStringValues) Transactional(org.springframework.transaction.annotation.Transactional) Entity(com.qcadoo.model.api.Entity) StateEnum(com.qcadoo.mes.states.StateEnum)

Example 3 with StateEnum

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

Example 4 with StateEnum

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);
}
Also used : Entity(com.qcadoo.model.api.Entity) StateEnum(com.qcadoo.mes.states.StateEnum) StateTransitionNotAlloweException(com.qcadoo.mes.states.exception.StateTransitionNotAlloweException) StateChangeContextImpl(com.qcadoo.mes.states.StateChangeContextImpl) DataDefinition(com.qcadoo.model.api.DataDefinition) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with StateEnum

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();
}
Also used : StateChangeEntityDescriber(com.qcadoo.mes.states.StateChangeEntityDescriber) Entity(com.qcadoo.model.api.Entity) StateEnum(com.qcadoo.mes.states.StateEnum) StateTransitionNotAlloweException(com.qcadoo.mes.states.exception.StateTransitionNotAlloweException) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

StateEnum (com.qcadoo.mes.states.StateEnum)5 StateTransitionNotAlloweException (com.qcadoo.mes.states.exception.StateTransitionNotAlloweException)3 Entity (com.qcadoo.model.api.Entity)3 Transactional (org.springframework.transaction.annotation.Transactional)3 DataDefinition (com.qcadoo.model.api.DataDefinition)2 Preconditions (com.google.common.base.Preconditions)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Multimap (com.google.common.collect.Multimap)1 Either (com.qcadoo.commons.functional.Either)1 ParameterService (com.qcadoo.mes.basic.ParameterService)1 ProductFields (com.qcadoo.mes.basic.constants.ProductFields)1 UnitConversionItemFieldsB (com.qcadoo.mes.basic.constants.UnitConversionItemFieldsB)1 BasicProductionCountingConstants (com.qcadoo.mes.basicProductionCounting.constants.BasicProductionCountingConstants)1 ProductionCountingQuantityFields (com.qcadoo.mes.basicProductionCounting.constants.ProductionCountingQuantityFields)1 ProductionCountingQuantityRole (com.qcadoo.mes.basicProductionCounting.constants.ProductionCountingQuantityRole)1 ProductionCountingQuantityTypeOfMaterial (com.qcadoo.mes.basicProductionCounting.constants.ProductionCountingQuantityTypeOfMaterial)1 OrderFieldsCNFM (com.qcadoo.mes.costNormsForMaterials.constants.OrderFieldsCNFM)1 OrderMaterialsCostDataGenerator (com.qcadoo.mes.costNormsForMaterials.orderRawMaterialCosts.OrderMaterialsCostDataGenerator)1 MaterialFlowConstants (com.qcadoo.mes.materialFlow.constants.MaterialFlowConstants)1