use of org.adempiere.ad.trx.api.ITrxManager in project metasfresh-webui-api by metasfresh.
the class LetterRestController method complete.
@PostMapping("/{letterId}/complete")
@ApiOperation("Completes the letter and returns it's printable version (e.g. PDF)")
public ResponseEntity<byte[]> complete(@PathVariable("letterId") final String letterId) {
userSession.assertLoggedIn();
final ITrxManager trxManager = Services.get(ITrxManager.class);
final WebuiLetterChangeResult result = changeLetter(letterId, letter -> trxManager.call(() -> complete0(letter)));
//
// Remove the letter
lettersRepo.removeLetterById(letterId);
// Return the printable letter
return createPDFResponseEntry(result.getLetter().getTemporaryPDFData());
}
use of org.adempiere.ad.trx.api.ITrxManager in project metasfresh-webui-api by metasfresh.
the class WebsocketSender method getQueue.
private WebsocketEventsQueue getQueue() {
final ITrxManager trxManager = Services.get(ITrxManager.class);
final ITrx trx = trxManager.getThreadInheritedTrx(OnTrxMissingPolicy.ReturnTrxNone);
if (!trxManager.isActive(trx)) {
return autoflushQueue;
} else if (!trx.getTrxListenerManager().canRegisterOnTiming(TrxEventTiming.AFTER_COMMIT)) {
return autoflushQueue;
} else {
return trx.getProperty(WebsocketEventsQueue.class.getName(), () -> createAndBindTrxQueue(trx));
}
}
use of org.adempiere.ad.trx.api.ITrxManager in project metasfresh-webui-api by metasfresh.
the class ViewChangesCollector method getCurrentOrNull.
public static final ViewChangesCollector getCurrentOrNull() {
//
// Try get/create transaction level collector
final ITrxManager trxManager = Services.get(ITrxManager.class);
final ITrx currentTrx = trxManager.getThreadInheritedTrx(OnTrxMissingPolicy.ReturnTrxNone);
if (!trxManager.isNull(currentTrx)) {
return currentTrx.getProperty(TRXPROPERTY_Name, trx -> {
final ViewChangesCollector collector = new ViewChangesCollector();
trx.getTrxListenerManager().newEventListener(TrxEventTiming.AFTER_COMMIT).registerHandlingMethod(innerTrx -> collector.close());
return collector;
});
}
//
// Try getting thread level collector
final ViewChangesCollector threadLocalCollector = THREADLOCAL.get();
if (threadLocalCollector != null) {
return threadLocalCollector;
}
// Fallback: return null
return null;
}
use of org.adempiere.ad.trx.api.ITrxManager in project metasfresh-webui-api by metasfresh.
the class DocumentCollection method duplicateDocument.
public Document duplicateDocument(final DocumentPath fromDocumentPath) {
// NOTE: assume running out of transaction
// Clone the document in transaction.
// One of the reasons of doing this is because for some documents there are events which are triggered on each change (but on trx commit).
// If we would run out of transaction, those events would be triggered 10k times.
// e.g. copying the AD_Role. Each time a record like AD_Window_Access is created, the UserRolePermissionsEventBus.fireCacheResetEvent() is called.
final ITrxManager trxManager = Services.get(ITrxManager.class);
final DocumentPath toDocumentPath = trxManager.call(ITrx.TRXNAME_ThreadInherited, () -> duplicateDocumentInTrx(fromDocumentPath));
return getDocumentReadonly(toDocumentPath);
}
use of org.adempiere.ad.trx.api.ITrxManager in project metasfresh-webui-api by metasfresh.
the class DocumentWebsocketPublisher method forCollector.
private void forCollector(final Consumer<JSONDocumentChangedWebSocketEventCollector> consumer) {
//
// Get the collector to use
final JSONDocumentChangedWebSocketEventCollector collector;
final boolean autoflush;
final ITrxManager trxManager = Services.get(ITrxManager.class);
final ITrx trx = trxManager.getThreadInheritedTrx(OnTrxMissingPolicy.ReturnTrxNone);
final JSONDocumentChangedWebSocketEventCollector threadLocalCollector = THREAD_LOCAL_COLLECTOR.get();
if (threadLocalCollector != null) {
collector = threadLocalCollector;
autoflush = false;
} else if (trxManager.isActive(trx)) {
collector = trx.getProperty(JSONDocumentChangedWebSocketEventCollector.class.getName(), () -> createCollectorAndBind(trx, websocketSender));
autoflush = false;
} else {
collector = JSONDocumentChangedWebSocketEventCollector.newInstance();
autoflush = true;
}
//
// Call the consumer
consumer.accept(collector);
// Autoflush if needed
if (autoflush) {
sendAllAndClear(collector, websocketSender);
}
}
Aggregations