Example usage for com.liferay.portal.kernel.transaction TransactionCommitCallbackUtil registerCallback

List of usage examples for com.liferay.portal.kernel.transaction TransactionCommitCallbackUtil registerCallback

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.transaction TransactionCommitCallbackUtil registerCallback.

Prototype

public static void registerCallback(Callable<?> callable) 

Source Link

Usage

From source file:com.liferay.adaptive.media.internal.processor.AdaptiveMediaAsyncProcessorImpl.java

License:Open Source License

@Override
public void triggerCleanUp(M model, String modelId) throws PortalException {
    if (Validator.isNotNull(modelId)) {
        _modelIds.putIfAbsent(AdaptiveMediaProcessorCommand.CLEAN_UP, new CopyOnWriteArrayList<>());

        List<String> cleanUpModelIds = _modelIds.get(AdaptiveMediaProcessorCommand.CLEAN_UP);

        if (cleanUpModelIds.contains(modelId)) {
            if (_log.isInfoEnabled()) {
                _log.info("Omitted clean up for model id " + modelId + " because it is already in progress");
            }/*from  w  ww  .j a  v  a  2s .  c o m*/

            return;
        }

        cleanUpModelIds.add(modelId);

        if (_log.isInfoEnabled()) {
            _log.info("Added clean up for model id " + modelId + " to the queue");
        }
    }

    Message message = new Message();

    message.put("className", _clazz.getName());
    message.put("model", model);
    message.put("command", AdaptiveMediaProcessorCommand.CLEAN_UP);

    if (Validator.isNotNull(modelId)) {
        message.put("modelId", modelId);
    }

    TransactionCommitCallbackUtil.registerCallback(() -> {
        _messageBus.sendMessage(AdaptiveMediaDestinationNames.ADAPTIVE_MEDIA_PROCESSOR, message);

        return null;
    });
}

From source file:com.liferay.adaptive.media.internal.processor.AdaptiveMediaAsyncProcessorImpl.java

License:Open Source License

@Override
public void triggerProcess(M model, String modelId) throws PortalException {
    if (Validator.isNotNull(modelId)) {
        _modelIds.putIfAbsent(AdaptiveMediaProcessorCommand.PROCESS, new CopyOnWriteArrayList<>());

        List<String> processModelIds = _modelIds.get(AdaptiveMediaProcessorCommand.PROCESS);

        if (processModelIds.contains(modelId)) {
            if (_log.isInfoEnabled()) {
                _log.info("Omitted process for model id " + modelId + " because it is already in progress");
            }/*from www.  j a  va2s .  c o  m*/

            return;
        }

        processModelIds.add(modelId);

        if (_log.isInfoEnabled()) {
            _log.info("Added process for model id " + modelId + " to the queue");
        }
    }

    Message message = new Message();

    message.put("className", _clazz.getName());
    message.put("model", model);
    message.put("command", AdaptiveMediaProcessorCommand.PROCESS);

    if (Validator.isNotNull(modelId)) {
        message.put("modelId", modelId);
    }

    TransactionCommitCallbackUtil.registerCallback(() -> {
        _messageBus.sendMessage(AdaptiveMediaDestinationNames.ADAPTIVE_MEDIA_PROCESSOR, message);

        return null;
    });
}

From source file:com.liferay.adaptive.media.internal.processor.AMAsyncProcessorImpl.java

License:Open Source License

@Override
public void triggerCleanUp(M model, String modelId) throws PortalException {
    if (Validator.isNotNull(modelId)) {
        _modelIds.putIfAbsent(AMProcessorCommand.CLEAN_UP, new CopyOnWriteArrayList<>());

        List<String> cleanUpModelIds = _modelIds.get(AMProcessorCommand.CLEAN_UP);

        if (cleanUpModelIds.contains(modelId)) {
            if (_log.isInfoEnabled()) {
                _log.info("Omitted clean up for model ID " + modelId + " because it is already in progress");
            }//from w  w w  . java2 s. co m

            return;
        }

        cleanUpModelIds.add(modelId);

        if (_log.isInfoEnabled()) {
            _log.info("Added clean up for model ID " + modelId + " to the queue");
        }
    }

    Message message = new Message();

    message.put("className", _clazz.getName());
    message.put("command", AMProcessorCommand.CLEAN_UP);
    message.put("model", model);

    if (Validator.isNotNull(modelId)) {
        message.put("modelId", modelId);
    }

    TransactionCommitCallbackUtil.registerCallback(() -> {
        _messageBus.sendMessage(AMDestinationNames.ADAPTIVE_MEDIA_PROCESSOR, message);

        return null;
    });
}

From source file:com.liferay.adaptive.media.internal.processor.AMAsyncProcessorImpl.java

License:Open Source License

@Override
public void triggerProcess(M model, String modelId) throws PortalException {
    if (Validator.isNotNull(modelId)) {
        _modelIds.putIfAbsent(AMProcessorCommand.PROCESS, new CopyOnWriteArrayList<>());

        List<String> processModelIds = _modelIds.get(AMProcessorCommand.PROCESS);

        if (processModelIds.contains(modelId)) {
            if (_log.isInfoEnabled()) {
                _log.info("Omitted process for model ID " + modelId + " because it is already in progress");
            }//from   w  w w  .  ja v a 2  s  . c  o m

            return;
        }

        processModelIds.add(modelId);

        if (_log.isInfoEnabled()) {
            _log.info("Added process for model ID " + modelId + " to the queue");
        }
    }

    Message message = new Message();

    message.put("className", _clazz.getName());
    message.put("command", AMProcessorCommand.PROCESS);
    message.put("model", model);

    if (Validator.isNotNull(modelId)) {
        message.put("modelId", modelId);
    }

    TransactionCommitCallbackUtil.registerCallback(() -> {
        _messageBus.sendMessage(AMDestinationNames.ADAPTIVE_MEDIA_PROCESSOR, message);

        return null;
    });
}

From source file:com.liferay.document.library.internal.repository.capabilities.LiferayProcessorCapability.java

License:Open Source License

protected void registerDLProcessorCallback(final FileEntry fileEntry, final FileVersion fileVersion) {

    TransactionCommitCallbackUtil.registerCallback(new Callable<Void>() {

        @Override//from   w ww. j a va2  s. co  m
        public Void call() throws Exception {
            DLProcessorRegistryUtil.trigger(fileEntry, fileVersion, true);

            return null;
        }

    });
}

From source file:com.liferay.document.library.internal.repository.capabilities.LiferaySyncCapability.java

License:Open Source License

protected void registerDLSyncEventCallback(final String event, final String type, final long typePK) {

    DLSyncEvent dlSyncEvent = _dlSyncEventLocalService.addDLSyncEvent(event, type, typePK);

    final long modifiedTime = dlSyncEvent.getModifiedTime();

    TransactionCommitCallbackUtil.registerCallback(new Callable<Void>() {

        @Override/*from  www  .j a va 2  s  .  com*/
        public Void call() throws Exception {
            Message message = new Message();

            Map<String, Object> values = new HashMap<>(4);

            values.put("event", event);
            values.put("modifiedTime", modifiedTime);
            values.put("type", type);
            values.put("typePK", typePK);

            message.setValues(values);

            MessageBusUtil.sendMessage(DestinationNames.DOCUMENT_LIBRARY_SYNC_EVENT_PROCESSOR, message);

            return null;
        }

    });
}

From source file:com.liferay.document.library.internal.service.DLFileRankDLAppHelperLocalServiceWrapper.java

License:Open Source License

@Override
public void getFileAsStream(long userId, FileEntry fileEntry, boolean incrementCounter) {

    super.getFileAsStream(userId, fileEntry, incrementCounter);

    if (!incrementCounter) {
        return;/*from  www . j a  v a  2 s  . c o  m*/
    }

    if (userId > 0) {
        TransactionCommitCallbackUtil.registerCallback(() -> {
            _dlFileRankLocalService.updateFileRank(fileEntry.getGroupId(), fileEntry.getCompanyId(), userId,
                    fileEntry.getFileEntryId(), new ServiceContext());

            return null;
        });
    }
}

From source file:com.liferay.dynamic.data.mapping.service.impl.DDMStructureLocalServiceImpl.java

License:Open Source License

protected void syncStructureTemplatesFields(final DDMStructure structure) {
    TransactionCommitCallbackUtil.registerCallback(new Callable<Void>() {

        @Override/*w  ww  .j  av a 2 s.  co m*/
        public Void call() throws Exception {
            DDMFormTemplateSynchonizer ddmFormTemplateSynchonizer = new DDMFormTemplateSynchonizer(
                    structure.getDDMForm(), ddmFormJSONDeserializer, ddmFormJSONSerializer,
                    ddmTemplateLocalService);

            List<DDMTemplate> templates = getStructureTemplates(structure,
                    DDMTemplateConstants.TEMPLATE_TYPE_FORM);

            ddmFormTemplateSynchonizer.setDDMFormTemplates(templates);

            ddmFormTemplateSynchonizer.synchronize();

            return null;
        }

    });
}

From source file:com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.java

License:Open Source License

protected void setArticlesExpirationDate(JournalArticle article) {
    if (ExportImportThreadLocal.isImportInProcess()) {
        return;/*from   w w w .  j a  v  a  2s.c o  m*/
    }

    if (!article.isApproved() || (article.getExpirationDate() == null)) {
        return;
    }

    final List<JournalArticle> articles = journalArticlePersistence.findByG_A(article.getGroupId(),
            article.getArticleId());

    final Date expirationDate = article.getExpirationDate();

    TransactionCommitCallbackUtil.registerCallback(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            for (JournalArticle curArticle : articles) {
                curArticle.setExpirationDate(expirationDate);

                journalArticleLocalService.updateJournalArticle(curArticle);
            }

            return null;
        }

    });
}

From source file:de.hofuniversity.iisys.liferay.workflows.LoggingWorkflowEngine.java

License:Open Source License

@Override
public ExecutionContext executeTimerWorkflowInstance(long kaleoTimerInstanceTokenId,
        ServiceContext serviceContext, Map<String, Serializable> workflowContext) throws WorkflowException {

    try {// ww w .  j  a v a  2 s  .  co  m
        fLogger.println("WorkflowEngine.executeTimerWorkflowInstance");
        fLogger.println("\tkaleoTimerInstanceTokenId: " + kaleoTimerInstanceTokenId);
        fLogger.println("\tserviceContext:");
        logServiceContext(serviceContext, "\t\t");
        fLogger.println("\tworkflowContext:");
        logMap(workflowContext, "\t\t");

        KaleoTimerInstanceToken kaleoTimerInstanceToken = kaleoTimerInstanceTokenLocalService
                .getKaleoTimerInstanceToken(kaleoTimerInstanceTokenId);

        KaleoInstanceToken kaleoInstanceToken = kaleoTimerInstanceToken.getKaleoInstanceToken();

        final ExecutionContext executionContext = new ExecutionContext(kaleoInstanceToken,
                kaleoTimerInstanceToken, workflowContext, serviceContext);

        KaleoTaskInstanceToken kaleoTaskInstanceToken = kaleoTimerInstanceToken.getKaleoTaskInstanceToken();

        executionContext.setKaleoTaskInstanceToken(kaleoTaskInstanceToken);

        final KaleoNode currentKaleoNode = kaleoInstanceToken.getCurrentKaleoNode();

        NodeExecutor nodeExecutor = _nodeExecutorFactory.getNodeExecutor(currentKaleoNode.getType());

        nodeExecutor.executeTimer(currentKaleoNode, executionContext);

        TransactionCommitCallbackUtil.registerCallback(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                _kaleoSignaler.signalExecute(currentKaleoNode, executionContext);

                return null;
            }

        });

        fLogger.println("\tRETURN executionContext:");
        logExecContext(executionContext, "\t\t");
        fLogger.flush();

        return executionContext;
    } catch (Exception e) {
        throw new WorkflowException(e);
    }
}