Example usage for com.liferay.portal.kernel.backgroundtask BackgroundTaskResult SUCCESS

List of usage examples for com.liferay.portal.kernel.backgroundtask BackgroundTaskResult SUCCESS

Introduction

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

Prototype

BackgroundTaskResult SUCCESS

To view the source code for com.liferay.portal.kernel.backgroundtask BackgroundTaskResult SUCCESS.

Click Source Link

Usage

From source file:com.liferay.adaptive.media.web.internal.background.task.OptimizeImagesBackgroundTaskExecutor.java

License:Open Source License

@Override
public BackgroundTaskResult execute(BackgroundTask backgroundTask) throws Exception {

    Map<String, Serializable> taskContextMap = backgroundTask.getTaskContextMap();

    String configurationEntryUuid = (String) taskContextMap
            .get(OptimizeImagesBackgroundTaskConstants.CONFIGURATION_ENTRY_UUID);
    long companyId = GetterUtil.getLong(taskContextMap.get(OptimizeImagesBackgroundTaskConstants.COMPANY_ID));

    optimizeImages(configurationEntryUuid, companyId);

    return BackgroundTaskResult.SUCCESS;
}

From source file:com.liferay.dynamic.data.mapping.background.task.DDMStructureIndexerBackgroundTaskExecutor.java

License:Open Source License

@Override
public BackgroundTaskResult execute(BackgroundTask backgroundTask) throws Exception {

    Map<String, Serializable> taskContextMap = backgroundTask.getTaskContextMap();

    Number structureIdNumber = (Number) taskContextMap.get("structureId");

    long structureId = structureIdNumber.longValue();

    DDMStructureIndexer structureIndexer = getDDMStructureIndexer(structureId);

    List<Long> ddmStructureIds = getChildrenStructureIds(structureId);

    structureIndexer.reindexDDMStructures(ddmStructureIds);

    return BackgroundTaskResult.SUCCESS;
}

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

License:Open Source License

@Override
public BackgroundTaskResult execute(BackgroundTask backgroundTask) throws PortalException {

    ExportImportConfiguration exportImportConfiguration = getExportImportConfiguration(backgroundTask);

    Map<String, Serializable> settingsMap = exportImportConfiguration.getSettingsMap();

    long userId = MapUtil.getLong(settingsMap, "userId");

    StringBundler sb = new StringBundler(4);

    sb.append(StringUtil.replace(exportImportConfiguration.getName(), CharPool.SPACE, CharPool.UNDERLINE));
    sb.append(StringPool.DASH);/*  www.  j  a v  a2s  . co  m*/
    sb.append(Time.getTimestamp());
    sb.append(".lar");

    File larFile = ExportImportLocalServiceUtil.exportLayoutsAsFile(exportImportConfiguration);

    BackgroundTaskManagerUtil.addBackgroundTaskAttachment(userId, backgroundTask.getBackgroundTaskId(),
            sb.toString(), larFile);

    return BackgroundTaskResult.SUCCESS;
}

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

License:Open Source License

@Override
public BackgroundTaskResult execute(BackgroundTask backgroundTask) throws Exception {

    ExportImportConfiguration exportImportConfiguration = getExportImportConfiguration(backgroundTask);

    List<FileEntry> attachmentsFileEntries = backgroundTask.getAttachmentsFileEntries();

    File file = null;/*from  ww w . ja  va  2  s.c om*/

    for (FileEntry attachmentsFileEntry : attachmentsFileEntries) {
        try {
            file = FileUtil.createTempFile("lar");

            FileUtil.write(file, attachmentsFileEntry.getContentStream());

            TransactionInvokerUtil.invoke(transactionConfig,
                    new LayoutImportCallable(exportImportConfiguration, file));
        } catch (IOException ioe) {
            StringBundler sb = new StringBundler(3);

            sb.append("Unable to process LAR file while executing ");
            sb.append("LayoutImportBackgroundTaskExecutor: ");

            if (!Objects.isNull(attachmentsFileEntry)
                    && Validator.isNotNull(attachmentsFileEntry.getFileName())) {

                sb.append(attachmentsFileEntry.getFileName());
            } else {
                sb.append("unknown file name");
            }

            throw new SystemException(sb.toString(), ioe);
        } catch (Throwable t) {
            if (_log.isDebugEnabled()) {
                _log.debug(t, t);
            } else if (_log.isWarnEnabled()) {
                _log.warn("Unable to import layouts: " + t.getMessage());
            }

            throw new SystemException(t);
        } finally {
            FileUtil.delete(file);
        }
    }

    return BackgroundTaskResult.SUCCESS;
}

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

License:Open Source License

@Override
public BackgroundTaskResult execute(BackgroundTask backgroundTask) throws Exception {

    ExportImportConfiguration exportImportConfiguration = getExportImportConfiguration(backgroundTask);

    Map<String, Serializable> settingsMap = exportImportConfiguration.getSettingsMap();

    long userId = MapUtil.getLong(settingsMap, "userId");
    String fileName = MapUtil.getString(settingsMap, "fileName");

    File larFile = ExportImportLocalServiceUtil.exportPortletInfoAsFile(exportImportConfiguration);

    BackgroundTaskManagerUtil.addBackgroundTaskAttachment(userId, backgroundTask.getBackgroundTaskId(),
            fileName, larFile);/*from   ww  w.j  a v a2  s .co m*/

    return BackgroundTaskResult.SUCCESS;
}

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

License:Open Source License

@Override
public BackgroundTaskResult execute(BackgroundTask backgroundTask) throws Exception {

    ExportImportConfiguration exportImportConfiguration = getExportImportConfiguration(backgroundTask);

    List<FileEntry> attachmentsFileEntries = backgroundTask.getAttachmentsFileEntries();

    File file = null;/*from  w ww  .j a v a2  s.c  om*/

    for (FileEntry attachmentsFileEntry : attachmentsFileEntries) {
        try {
            file = FileUtil.createTempFile("lar");

            FileUtil.write(file, attachmentsFileEntry.getContentStream());

            TransactionInvokerUtil.invoke(transactionConfig,
                    new PortletImportCallable(exportImportConfiguration, file));
        } catch (Throwable t) {
            if (_log.isDebugEnabled()) {
                _log.debug(t, t);
            } else if (_log.isWarnEnabled()) {
                _log.warn("Unable to import portlet: " + t.getMessage());
            }

            throw new SystemException(t);
        } finally {
            FileUtil.delete(file);
        }
    }

    return BackgroundTaskResult.SUCCESS;
}