Search in sources :

Example 1 with ITrxManager

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());
}
Also used : ITrxManager(org.adempiere.ad.trx.api.ITrxManager) PostMapping(org.springframework.web.bind.annotation.PostMapping) ApiOperation(io.swagger.annotations.ApiOperation)

Example 2 with ITrxManager

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));
    }
}
Also used : ITrx(org.adempiere.ad.trx.api.ITrx) ITrxManager(org.adempiere.ad.trx.api.ITrxManager)

Example 3 with ITrxManager

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;
}
Also used : ITrx(org.adempiere.ad.trx.api.ITrx) ITrxManager(org.adempiere.ad.trx.api.ITrxManager)

Example 4 with ITrxManager

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);
}
Also used : ITrxManager(org.adempiere.ad.trx.api.ITrxManager) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath)

Example 5 with ITrxManager

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);
    }
}
Also used : ITrx(org.adempiere.ad.trx.api.ITrx) ITrxManager(org.adempiere.ad.trx.api.ITrxManager)

Aggregations

ITrxManager (org.adempiere.ad.trx.api.ITrxManager)6 ITrx (org.adempiere.ad.trx.api.ITrx)4 DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)1 ApiOperation (io.swagger.annotations.ApiOperation)1 CacheInvalidateMultiRequest (org.adempiere.ad.dao.cache.CacheInvalidateMultiRequest)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1