/** * 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.exportimport.internal.background.task; import com.liferay.portal.kernel.backgroundtask.BackgroundTaskStatus; import com.liferay.portal.kernel.messaging.Message; import com.liferay.portal.kernel.util.Constants; import com.liferay.portal.kernel.util.GetterUtil; import com.liferay.portal.kernel.util.LongWrapper; import com.liferay.portal.kernel.util.Validator; import java.util.HashMap; /** * @author Daniel Kocsis */ public class PortletStagingBackgroundTaskStatusMessageTranslator extends DefaultExportImportBackgroundTaskStatusMessageTranslator { protected long getAllModelAdditionCountersTotal( BackgroundTaskStatus backgroundTaskStatus) { long allModelAdditionCountersTotal = GetterUtil.getLong( backgroundTaskStatus.getAttribute("allModelAdditionCountersTotal")); long currentModelAdditionCountersTotal = GetterUtil.getLong( backgroundTaskStatus.getAttribute( "currentModelAdditionCountersTotal")); return allModelAdditionCountersTotal + currentModelAdditionCountersTotal; } @Override protected synchronized void translatePortletMessage( BackgroundTaskStatus backgroundTaskStatus, Message message) { String phase = GetterUtil.getString( backgroundTaskStatus.getAttribute("phase")); if (Validator.isNull(phase)) { clearBackgroundTaskStatus(backgroundTaskStatus); phase = Constants.EXPORT; } else { phase = Constants.IMPORT; } backgroundTaskStatus.setAttribute("phase", phase); if (phase.equals(Constants.EXPORT)) { long portletModelAdditionCountersTotal = GetterUtil.getLong( message.get("portletModelAdditionCountersTotal")); backgroundTaskStatus.setAttribute( "allModelAdditionCountersTotal", portletModelAdditionCountersTotal); } else { backgroundTaskStatus.setAttribute( "allModelAdditionCountersTotal", getAllModelAdditionCountersTotal(backgroundTaskStatus)); backgroundTaskStatus.setAttribute( "allPortletModelAdditionCounters", new HashMap<String, LongWrapper>()); backgroundTaskStatus.setAttribute( "currentPortletModelAdditionCounters", new HashMap<String, LongWrapper>()); } super.translatePortletMessage(backgroundTaskStatus, message); } }