com.liferay.batch.engine.internal.BatchEngineImportTaskExecutorImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com.liferay.batch.engine.service
Show all versions of com.liferay.batch.engine.service
Liferay Batch Engine Service
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.batch.engine.internal;
import com.liferay.batch.engine.BatchEngineImportTaskExecutor;
import com.liferay.batch.engine.BatchEngineTaskContentType;
import com.liferay.batch.engine.BatchEngineTaskExecuteStatus;
import com.liferay.batch.engine.BatchEngineTaskOperation;
import com.liferay.batch.engine.configuration.BatchEngineTaskConfiguration;
import com.liferay.batch.engine.internal.item.BatchEngineTaskItemDelegateExecutor;
import com.liferay.batch.engine.internal.item.BatchEngineTaskItemDelegateExecutorFactory;
import com.liferay.batch.engine.internal.reader.BatchEngineImportTaskItemReader;
import com.liferay.batch.engine.internal.reader.BatchEngineImportTaskItemReaderFactory;
import com.liferay.batch.engine.internal.reader.BatchEngineImportTaskItemReaderUtil;
import com.liferay.batch.engine.internal.task.progress.BatchEngineTaskProgress;
import com.liferay.batch.engine.internal.task.progress.BatchEngineTaskProgressFactory;
import com.liferay.batch.engine.model.BatchEngineImportTask;
import com.liferay.batch.engine.service.BatchEngineImportTaskLocalService;
import com.liferay.petra.string.StringPool;
import com.liferay.portal.configuration.metatype.bnd.util.ConfigurableUtil;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.service.CompanyLocalService;
import com.liferay.portal.kernel.service.UserLocalService;
import com.liferay.portal.kernel.transaction.Propagation;
import com.liferay.portal.kernel.transaction.TransactionConfig;
import com.liferay.portal.kernel.transaction.TransactionInvokerUtil;
import com.liferay.portal.kernel.util.GetterUtil;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.osgi.framework.BundleContext;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
/**
* @author Ivica Cardic
*/
@Component(
configurationPid = "com.liferay.batch.engine.configuration.BatchEngineTaskConfiguration",
service = BatchEngineImportTaskExecutor.class
)
public class BatchEngineImportTaskExecutorImpl
implements BatchEngineImportTaskExecutor {
@Override
public void execute(BatchEngineImportTask batchEngineImportTask) {
try {
batchEngineImportTask.setExecuteStatus(
BatchEngineTaskExecuteStatus.STARTED.toString());
batchEngineImportTask.setStartTime(new Date());
BatchEngineTaskProgress batchEngineTaskProgress =
_batchEngineTaskProgressFactory.create(
BatchEngineTaskContentType.valueOf(
batchEngineImportTask.getContentType()));
batchEngineImportTask.setTotalItemsCount(
batchEngineTaskProgress.getTotalItemsCount(
_batchEngineImportTaskLocalService.openContentInputStream(
batchEngineImportTask.getBatchEngineImportTaskId())));
_batchEngineImportTaskLocalService.updateBatchEngineImportTask(
batchEngineImportTask);
BatchEngineTaskExecutorUtil.execute(
() -> _importItems(batchEngineImportTask),
_userLocalService.getUser(batchEngineImportTask.getUserId()));
_updateBatchEngineImportTask(
BatchEngineTaskExecuteStatus.COMPLETED, batchEngineImportTask,
null);
}
catch (Throwable throwable) {
_log.error(
"Unable to update batch engine import task " +
batchEngineImportTask,
throwable);
_updateBatchEngineImportTask(
BatchEngineTaskExecuteStatus.FAILED, batchEngineImportTask,
throwable.getMessage());
}
}
@Activate
protected void activate(
BundleContext bundleContext, Map properties) {
BatchEngineTaskConfiguration batchEngineTaskConfiguration =
ConfigurableUtil.createConfigurable(
BatchEngineTaskConfiguration.class, properties);
_batchEngineImportTaskItemReaderFactory =
new BatchEngineImportTaskItemReaderFactory(
GetterUtil.getString(
batchEngineTaskConfiguration.csvFileColumnDelimiter(),
StringPool.COMMA));
_batchEngineTaskProgressFactory = new BatchEngineTaskProgressFactory();
_batchEngineTaskItemDelegateExecutorFactory =
new BatchEngineTaskItemDelegateExecutorFactory(
_batchEngineTaskMethodRegistry, null, null, null);
}
private void _commitItems(
BatchEngineImportTask batchEngineImportTask,
BatchEngineTaskItemDelegateExecutor
batchEngineTaskItemDelegateExecutor,
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy