/**
* 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.portal.search.internal.background.task;
import com.liferay.portal.kernel.backgroundtask.BackgroundTask;
import com.liferay.portal.kernel.backgroundtask.BackgroundTaskConstants;
import com.liferay.portal.kernel.backgroundtask.BackgroundTaskResult;
import com.liferay.portal.kernel.backgroundtask.BaseBackgroundTaskExecutor;
import com.liferay.portal.kernel.backgroundtask.display.BackgroundTaskDisplay;
import com.liferay.portal.kernel.search.background.task.ReindexBackgroundTaskConstants;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.search.internal.background.task.display.ReindexBackgroundTaskDisplay;
import java.io.Serializable;
import java.util.Map;
/**
* @author Andrew Betts
*/
public abstract class ReindexBackgroundTaskExecutor
extends BaseBackgroundTaskExecutor {
public ReindexBackgroundTaskExecutor() {
setBackgroundTaskStatusMessageTranslator(
new ReindexBackgroundTaskStatusMessageTranslator());
setIsolationLevel(BackgroundTaskConstants.ISOLATION_LEVEL_COMPANY);
}
@Override
public BackgroundTaskResult execute(BackgroundTask backgroundTask)
throws Exception {
Map<String, Serializable> taskContextMap =
backgroundTask.getTaskContextMap();
String className = (String)taskContextMap.get(
ReindexBackgroundTaskConstants.CLASS_NAME);
long[] companyIds = GetterUtil.getLongValues(
taskContextMap.get(ReindexBackgroundTaskConstants.COMPANY_IDS));
reindex(className, companyIds);
return BackgroundTaskResult.SUCCESS;
}
@Override
public BackgroundTaskDisplay getBackgroundTaskDisplay(
BackgroundTask backgroundTask) {
return new ReindexBackgroundTaskDisplay(backgroundTask);
}
protected abstract void reindex(String className, long[] companyIds)
throws Exception;
}