Search in sources :

Example 11 with EntityRuntimeException

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

the class AnomalyProductionTrackingDetailsListeners method createAnomaly.

private void createAnomaly(final Entity entity) {
    Entity anomaly = dataDefinitionService.get(ProductionCountingConstants.PLUGIN_IDENTIFIER, ProductionCountingConstants.MODEL_ANOMALY).create();
    Entity productionTracking = entity.getBelongsToField("trackingOperationProductInComponent").getBelongsToField(TrackingOperationProductInComponentFields.PRODUCTION_TRACKING);
    Entity product = entity.getBelongsToField("trackingOperationProductInComponent").getBelongsToField(TrackingOperationProductInComponentFields.PRODUCT);
    anomaly.setField(AnomalyFields.NUMBER, numberGeneratorService.generateNumber(ProductionCountingConstants.PLUGIN_IDENTIFIER, ProductionCountingConstants.MODEL_ANOMALY));
    anomaly.setField(AnomalyFields.PRODUCTION_TRACKING, productionTracking);
    anomaly.setField(AnomalyFields.PRODUCT, product);
    anomaly.setField(AnomalyFields.USED_QUANTITY, entity.getDecimalField("usedQuantity"));
    anomaly.setField(AnomalyFields.STATE, "01draft");
    anomaly.setField(AnomalyFields.ISSUED, false);
    Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER);
    if (Objects.isNull(order.getBelongsToField("root"))) {
        anomaly.setField(AnomalyFields.MASTER_PRODUCT, order.getBelongsToField(OrderFields.PRODUCT));
    } else {
        anomaly.setField(AnomalyFields.MASTER_PRODUCT, order.getBelongsToField("root").getBelongsToField(OrderFields.PRODUCT));
    }
    List<Entity> reasons = Lists.newArrayList();
    List<Entity> anomalyContainers = entity.getHasManyField("anomalyReasons");
    anomalyContainers.forEach(ac -> {
        reasons.add(ac.getBelongsToField("anomalyReason"));
    });
    anomaly.setField(AnomalyFields.ANAOMALY_REASONS, reasons);
    anomaly.setField(AnomalyFields.LOCATION, findLocation(productionTracking, product));
    anomaly = anomaly.getDataDefinition().save(anomaly);
    if (!anomaly.isValid()) {
        throw new EntityRuntimeException(anomaly);
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityRuntimeException(com.qcadoo.model.api.exception.EntityRuntimeException)

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