Example usage for com.liferay.portal.kernel.backgroundtask BackgroundTaskConstants STATUS_SUCCESSFUL

List of usage examples for com.liferay.portal.kernel.backgroundtask BackgroundTaskConstants STATUS_SUCCESSFUL

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.backgroundtask BackgroundTaskConstants STATUS_SUCCESSFUL.

Prototype

int STATUS_SUCCESSFUL

To view the source code for com.liferay.portal.kernel.backgroundtask BackgroundTaskConstants STATUS_SUCCESSFUL.

Click Source Link

Usage

From source file:com.liferay.exportimport.internal.background.task.BaseStagingBackgroundTaskExecutor.java

License:Open Source License

protected BackgroundTaskResult processMissingReferences(long backgroundTaskId,
        MissingReferences missingReferences) {

    BackgroundTaskResult backgroundTaskResult = new BackgroundTaskResult(
            BackgroundTaskConstants.STATUS_SUCCESSFUL);

    if (missingReferences == null) {
        return backgroundTaskResult;
    }//from   w  w w.j ava2  s  .c  o m

    Map<String, MissingReference> weakMissingReferences = missingReferences.getWeakMissingReferences();

    if (MapUtil.isNotEmpty(weakMissingReferences)) {
        BackgroundTask backgroundTask = BackgroundTaskManagerUtil.fetchBackgroundTask(backgroundTaskId);

        JSONArray jsonArray = StagingUtil.getWarningMessagesJSONArray(getLocale(backgroundTask),
                weakMissingReferences);

        backgroundTaskResult.setStatusMessage(jsonArray.toString());
    }

    return backgroundTaskResult;
}

From source file:com.liferay.exportimport.internal.lifecycle.NotificationExportImportLifecycleListener.java

License:Open Source License

@Override
public void onProcessSucceeded(ExportImportLifecycleEvent exportImportLifecycleEvent) throws Exception {

    sendNotification(BackgroundTaskConstants.STATUS_SUCCESSFUL);
}

From source file:com.liferay.exportimport.internal.notifications.ExportImportUserNotificationHandler.java

License:Open Source License

@Override
protected String getBody(UserNotificationEvent userNotificationEvent, ServiceContext serviceContext)
        throws Exception {

    Locale locale = _portal.getLocale(serviceContext.getRequest());

    ResourceBundle resourceBundle = _resourceBundleLoader.loadResourceBundle(locale);

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject(userNotificationEvent.getPayload());

    ExportImportConfiguration exportImportConfiguration = null;

    try {//from   w ww  .j  a  va  2  s  .  c o  m
        exportImportConfiguration = _exportImportConfigurationLocalService
                .getExportImportConfiguration(jsonObject.getLong("exportImportConfigurationId"));
    } catch (PortalException pe) {
        if (_log.isDebugEnabled()) {
            _log.debug(pe, pe);
        }

        return LanguageUtil.get(resourceBundle, "the-process-referenced-by-this-notification-does-not-exist");
    }

    String message = "x-"
            + ExportImportConfigurationConstants.getTypeLabel(exportImportConfiguration.getType());

    int status = jsonObject.getInt("status");

    if (status == BackgroundTaskConstants.STATUS_SUCCESSFUL) {
        message += "-process-finished-successfully";
    } else if (status == BackgroundTaskConstants.STATUS_FAILED) {
        message += "-process-failed";
    } else {
        return "Unable to process notification: " + HtmlUtil.escape(jsonObject.toString());
    }

    long backgroundTaskId = jsonObject.getLong("backgroundTaskId");

    BackgroundTaskDisplay backgroundTaskDisplay = _backgroundTaskDisplayFactory
            .getBackgroundTaskDisplay(backgroundTaskId);

    String processName = backgroundTaskDisplay.getDisplayName(serviceContext.getRequest());

    return LanguageUtil.format(resourceBundle, message, processName);
}

From source file:com.liferay.exportimport.lifecycle.NotificationExportImportLifecycleListener.java

License:Open Source License

@Override
protected void onProcessSucceeded(List<Serializable> attributes) throws Exception {

    sendNotification(BackgroundTaskConstants.STATUS_SUCCESSFUL);
}

From source file:com.liferay.server.admin.web.internal.portlet.action.EditServerMVCActionCommand.java

License:Open Source License

protected void reindex(final ActionRequest actionRequest) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    Map<String, Serializable> taskContextMap = new HashMap<>();

    String className = ParamUtil.getString(actionRequest, "className");

    if (!ParamUtil.getBoolean(actionRequest, "blocking")) {
        _indexWriterHelper.reindex(themeDisplay.getUserId(), "reindex",
                _portalInstancesLocalService.getCompanyIds(), className, taskContextMap);

        return;/*from   www . j  ava  2  s. c  o m*/
    }

    final String jobName = "reindex-".concat(_portalUUID.generate());

    final CountDownLatch countDownLatch = new CountDownLatch(1);

    MessageListener messageListener = new MessageListener() {

        @Override
        public void receive(Message message) throws MessageListenerException {

            int status = message.getInteger("status");

            if ((status != BackgroundTaskConstants.STATUS_CANCELLED)
                    && (status != BackgroundTaskConstants.STATUS_FAILED)
                    && (status != BackgroundTaskConstants.STATUS_SUCCESSFUL)) {

                return;
            }

            if (!jobName.equals(message.getString("name"))) {
                return;
            }

            PortletSession portletSession = actionRequest.getPortletSession();

            long lastAccessedTime = portletSession.getLastAccessedTime();
            int maxInactiveInterval = portletSession.getMaxInactiveInterval();

            int extendedMaxInactiveIntervalTime = (int) (System.currentTimeMillis() - lastAccessedTime
                    + maxInactiveInterval);

            portletSession.setMaxInactiveInterval(extendedMaxInactiveIntervalTime);

            countDownLatch.countDown();
        }

    };

    _messageBus.registerMessageListener(DestinationNames.BACKGROUND_TASK_STATUS, messageListener);

    try {
        _indexWriterHelper.reindex(themeDisplay.getUserId(), jobName,
                _portalInstancesLocalService.getCompanyIds(), className, taskContextMap);

        countDownLatch.await(ParamUtil.getLong(actionRequest, "timeout", Time.HOUR), TimeUnit.MILLISECONDS);
    } finally {
        _messageBus.unregisterMessageListener(DestinationNames.BACKGROUND_TASK_STATUS, messageListener);
    }
}