Search in sources :

Example 1 with EntityRuntimeException

use of com.qcadoo.model.api.exception.EntityRuntimeException in project mes by qcadoo.

the class AnomalyProductionTrackingDetailsListeners method clearQuantitiesInRR.

private void clearQuantitiesInRR(ViewDefinitionState view) {
    AwesomeDynamicListComponent anomalyProductionTrackingEntriesADL = (AwesomeDynamicListComponent) view.getComponentByReference("anomalyProductionTrackingEntries");
    List<Entity> entities = anomalyProductionTrackingEntriesADL.getEntities();
    for (Entity entity : entities) {
        Entity trackingOperationProductInComponent = entity.getBelongsToField("trackingOperationProductInComponent");
        trackingOperationProductInComponent.setField(TrackingOperationProductInComponentFields.USED_QUANTITY, BigDecimal.ZERO);
        trackingOperationProductInComponent.setField(TrackingOperationProductInComponentFields.GIVEN_QUANTITY, BigDecimal.ZERO);
        trackingOperationProductInComponent = trackingOperationProductInComponent.getDataDefinition().save(trackingOperationProductInComponent);
        if (!trackingOperationProductInComponent.isValid()) {
            throw new EntityRuntimeException(trackingOperationProductInComponent);
        }
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) AwesomeDynamicListComponent(com.qcadoo.view.api.components.AwesomeDynamicListComponent) EntityRuntimeException(com.qcadoo.model.api.exception.EntityRuntimeException)

Example 2 with EntityRuntimeException

use of com.qcadoo.model.api.exception.EntityRuntimeException in project mes by qcadoo.

the class StateExecutorService method changeState.

public <M extends StateService> Entity changeState(final Class<M> serviceMarker, Entity entity, final String userName, final String targetState) {
    List<M> services = lookupChangeStateServices(serviceMarker);
    StateChangeEntityDescriber describer = services.stream().findFirst().get().getChangeEntityDescriber();
    String sourceState = entity.getStringField(describer.getOwnerStateFieldName());
    Entity stateChangeEntity = buildStateChangeEntity(describer, entity, userName, sourceState, targetState);
    try {
        stateChangeEntity = saveStateChangeContext(entity, stateChangeEntity, describer, sourceState, targetState, StateChangeStatus.IN_PROGRESS);
        List<Entity> stateChanges = Lists.newArrayList();
        stateChanges.addAll(entity.getHasManyField(describer.getOwnerStateChangesFieldName()));
        stateChanges.add(stateChangeEntity);
        entity.setField(describer.getOwnerStateChangesFieldName(), stateChanges);
        entity = performChangeState(services, entity, stateChangeEntity, describer);
        if (entity.isValid()) {
            copyMessages(entity);
            saveStateChangeEntity(stateChangeEntity, StateChangeStatus.SUCCESSFUL);
            message("states.messages.change.successful", ComponentState.MessageType.SUCCESS);
            LOG.info(String.format("Change state successful. Entity name : %S id : %d. Target state : %S", entity.getDataDefinition().getName(), entity.getId(), stateChangeEntity.getStringField(describer.getTargetStateFieldName())));
        } else {
            saveStateChangeEntity(stateChangeEntity, StateChangeStatus.FAILURE);
            entity = rollbackStateChange(entity, sourceState);
            message("states.messages.change.failure", ComponentState.MessageType.FAILURE);
            LOG.info(String.format("Change state failure. Entity name : %S id : %d. Target state : %S", entity.getDataDefinition().getName(), entity.getId(), stateChangeEntity.getStringField(describer.getTargetStateFieldName())));
        }
    } catch (EntityRuntimeException entityException) {
        copyMessages(entityException.getEntity(), entity);
        entity = rollbackStateChange(entity, sourceState);
        saveStateChangeEntity(stateChangeEntity, StateChangeStatus.FAILURE);
        message("states.messages.change.failure", ComponentState.MessageType.FAILURE);
        return entity;
    } catch (AnotherChangeInProgressException e) {
        entity = rollbackStateChange(entity, sourceState);
        saveStateChangeEntity(stateChangeEntity, StateChangeStatus.FAILURE);
        message("states.messages.change.failure", ComponentState.MessageType.FAILURE);
        message("states.messages.change.failure.anotherChangeInProgress", ComponentState.MessageType.FAILURE);
        LOG.info(String.format("Another state change in progress. Entity name : %S id : %d. Target state : %S", entity.getDataDefinition().getName(), entity.getId(), targetState));
    } catch (StateTransitionNotAlloweException e) {
        entity = rollbackStateChange(entity, sourceState);
        saveStateChangeEntity(stateChangeEntity, StateChangeStatus.FAILURE);
        message("states.messages.change.failure", ComponentState.MessageType.FAILURE);
        message("states.messages.change.failure.transitionNotAllowed", ComponentState.MessageType.FAILURE);
        LOG.info(String.format("State change - transition not allowed. Entity name : %S id : %d. Target state : %S", entity.getDataDefinition().getName(), entity.getId(), targetState));
    } catch (Exception exception) {
        entity = rollbackStateChange(entity, sourceState);
        saveStateChangeEntity(stateChangeEntity, StateChangeStatus.FAILURE);
        message("states.messages.change.failure", ComponentState.MessageType.FAILURE);
        message("states.messages.change.failure.internalServerError", ComponentState.MessageType.FAILURE);
        LOG.info(String.format("State change exception. Entity name : %S id : %d. Target state : %S", entity.getDataDefinition().getName(), entity.getId(), targetState));
        LOG.warn("Can't perform state change", exception);
    }
    return entity;
}
Also used : StateChangeEntityDescriber(com.qcadoo.mes.states.StateChangeEntityDescriber) Entity(com.qcadoo.model.api.Entity) AnotherChangeInProgressException(com.qcadoo.mes.states.exception.AnotherChangeInProgressException) StateTransitionNotAlloweException(com.qcadoo.mes.states.exception.StateTransitionNotAlloweException) AnotherChangeInProgressException(com.qcadoo.mes.states.exception.AnotherChangeInProgressException) EntityRuntimeException(com.qcadoo.model.api.exception.EntityRuntimeException) StateTransitionNotAlloweException(com.qcadoo.mes.states.exception.StateTransitionNotAlloweException) EntityRuntimeException(com.qcadoo.model.api.exception.EntityRuntimeException)

Example 3 with EntityRuntimeException

use of com.qcadoo.model.api.exception.EntityRuntimeException in project mes by qcadoo.

the class TechnologiesListListeners method trySetAsDefault.

@Transactional
public void trySetAsDefault(ViewDefinitionState view) {
    GridComponent grid = (GridComponent) view.getComponentByReference(QcadooViewConstants.L_GRID);
    Set<Long> selectedEntities = grid.getSelectedEntitiesIds();
    selectedEntities.forEach(techId -> {
        Entity technology = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_TECHNOLOGY).get(techId);
        technology.setField(TechnologyFields.MASTER, Boolean.TRUE);
        technology = technology.getDataDefinition().save(technology);
        if (!technology.isValid()) {
            throw new EntityRuntimeException(technology);
        }
    });
}
Also used : Entity(com.qcadoo.model.api.Entity) GridComponent(com.qcadoo.view.api.components.GridComponent) EntityRuntimeException(com.qcadoo.model.api.exception.EntityRuntimeException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with EntityRuntimeException

use of com.qcadoo.model.api.exception.EntityRuntimeException in project mes by qcadoo.

the class ProductsBySizeController method tryCreateMOPositions.

@Transactional
public void tryCreateMOPositions(Entity mo, List<Entity> helperEntries, List<ProductBySizePosition> positions) {
    for (ProductBySizePosition position : positions) {
        Entity product = helperEntries.stream().filter(e -> e.getId().equals(position.getId())).findAny().get().getBelongsToField("product");
        Entity moProduct = dataDefinitionService.get(MasterOrdersConstants.PLUGIN_IDENTIFIER, MasterOrdersConstants.MODEL_MASTER_ORDER_PRODUCT).create();
        moProduct.setField(MasterOrderProductFields.MASTER_ORDER, mo);
        moProduct.setField(MasterOrderProductFields.PRODUCT, product);
        moProduct.setField(MasterOrderProductFields.TECHNOLOGY, technologyServiceO.getDefaultTechnology(moProduct.getBelongsToField(MasterOrderProductFields.PRODUCT)));
        moProduct.setField(MasterOrderProductFields.MASTER_ORDER_QUANTITY, position.getValue());
        moProduct = moProduct.getDataDefinition().save(moProduct);
        if (!moProduct.isValid()) {
            throw new EntityRuntimeException(moProduct);
        }
    }
}
Also used : SizeFields(com.qcadoo.mes.basic.constants.SizeFields) LocaleContextHolder(org.springframework.context.i18n.LocaleContextHolder) ProductsBySizeHelperFields(com.qcadoo.mes.masterOrders.constants.ProductsBySizeHelperFields) DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) SalesPlanProductFields(com.qcadoo.mes.masterOrders.constants.SalesPlanProductFields) MediaType(org.springframework.http.MediaType) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Controller(org.springframework.stereotype.Controller) TranslationService(com.qcadoo.localization.api.TranslationService) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) MasterOrdersConstants(com.qcadoo.mes.masterOrders.constants.MasterOrdersConstants) RequestBody(org.springframework.web.bind.annotation.RequestBody) TechnologyServiceO(com.qcadoo.mes.orders.TechnologyServiceO) List(java.util.List) Entity(com.qcadoo.model.api.Entity) MasterOrderProductFields(com.qcadoo.mes.masterOrders.constants.MasterOrderProductFields) ProductFields(com.qcadoo.mes.basic.constants.ProductFields) EntityRuntimeException(com.qcadoo.model.api.exception.EntityRuntimeException) Transactional(org.springframework.transaction.annotation.Transactional) Entity(com.qcadoo.model.api.Entity) EntityRuntimeException(com.qcadoo.model.api.exception.EntityRuntimeException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with EntityRuntimeException

use of com.qcadoo.model.api.exception.EntityRuntimeException in project mes by qcadoo.

the class CompanyDefaultProductsListeners method tryCreatePositions.

@Transactional
public void tryCreatePositions(GridComponent grid, Long companyId) {
    for (Long productId : grid.getSelectedEntitiesIds()) {
        Entity defaultProductCompany = getCompanyProductDD().find().add(SearchRestrictions.belongsTo(L_PRODUCT, BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT, productId)).setMaxResults(1).uniqueResult();
        Entity productCompany = null;
        if (Objects.nonNull(defaultProductCompany)) {
            if (defaultProductCompany.getBelongsToField(L_COMPANY).getId().equals(companyId)) {
                productCompany = defaultProductCompany;
            } else if (defaultProductCompany.getBooleanField(L_IS_DEFAULT)) {
                throw new EntityRuntimeException(defaultProductCompany);
            } else {
                productCompany = getCompanyProductDD().create();
            }
        } else {
            productCompany = getCompanyProductDD().create();
        }
        productCompany.setField(L_COMPANY, companyId);
        productCompany.setField(L_PRODUCT, productId);
        productCompany.setField(L_IS_DEFAULT, Boolean.TRUE);
        productCompany = productCompany.getDataDefinition().save(productCompany);
        if (!productCompany.isValid()) {
            throw new EntityRuntimeException(productCompany);
        }
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityRuntimeException(com.qcadoo.model.api.exception.EntityRuntimeException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

EntityRuntimeException (com.qcadoo.model.api.exception.EntityRuntimeException)11 Entity (com.qcadoo.model.api.Entity)10 Transactional (org.springframework.transaction.annotation.Transactional)5 TranslationService (com.qcadoo.localization.api.TranslationService)2 ProductFields (com.qcadoo.mes.basic.constants.ProductFields)2 SizeFields (com.qcadoo.mes.basic.constants.SizeFields)2 MasterOrderProductFields (com.qcadoo.mes.masterOrders.constants.MasterOrderProductFields)2 MasterOrdersConstants (com.qcadoo.mes.masterOrders.constants.MasterOrdersConstants)2 ProductsBySizeHelperFields (com.qcadoo.mes.masterOrders.constants.ProductsBySizeHelperFields)2 SalesPlanProductFields (com.qcadoo.mes.masterOrders.constants.SalesPlanProductFields)2 TechnologyServiceO (com.qcadoo.mes.orders.TechnologyServiceO)2 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)2 GridComponent (com.qcadoo.view.api.components.GridComponent)2 List (java.util.List)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 LocaleContextHolder (org.springframework.context.i18n.LocaleContextHolder)2 MediaType (org.springframework.http.MediaType)2 Controller (org.springframework.stereotype.Controller)2 RequestBody (org.springframework.web.bind.annotation.RequestBody)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2