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);
}
}
}
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;
}
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);
}
});
}
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);
}
}
}
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);
}
}
}
Aggregations