/**
* 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.content.targeting.api.model;
import com.liferay.content.targeting.InvalidTrackingActionException;
import com.liferay.content.targeting.model.Campaign;
import com.liferay.content.targeting.model.TrackingActionInstance;
import com.liferay.content.targeting.util.ContentTargetingContextUtil;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.lar.PortletDataContext;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.Constants;
import com.liferay.portal.kernel.util.LocaleUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.xml.Element;
import com.liferay.portal.security.permission.ResourceActionsUtil;
import java.util.Locale;
import java.util.Map;
import javax.portlet.PortletRequest;
import javax.portlet.PortletResponse;
/**
* @author Eduardo Garcia
*/
public abstract class BaseTrackingAction implements TrackingAction {
@Override
public void activate() {
if (_log.isDebugEnabled()) {
_log.debug(
"Tracking Action activate: " + getClass().getSimpleName());
}
}
@Override
public void deActivate() {
if (_log.isDebugEnabled()) {
_log.debug(
"Tracking Action deactivate: " + getClass().getSimpleName());
}
}
@Override
public void deleteData(TrackingActionInstance trackingActionInstance)
throws PortalException, SystemException {
}
@Override
public void exportData(
PortletDataContext portletDataContext, Element campaignElement,
Campaign campaign, Element trackingInstanceElement,
TrackingActionInstance trackingActionInstance)
throws Exception {
}
@Override
public String getDescription(Locale locale) {
String key = getClass().getName().concat(".description");
String description = ResourceActionsUtil.getModelResource(locale, key);
if (description.endsWith(key)) {
description = getShortDescription(locale);
}
return description;
}
@Override
public String getFormHTML(
TrackingActionInstance trackingActionInstance,
Map<String, Object> context, Map<String, String> values) {
String content = StringPool.BLANK;
try {
populateContext(trackingActionInstance, context, values);
content = ContentTargetingContextUtil.parseTemplate(
getClass(), _FORM_TEMPLATE_PATH, context);
}
catch (Exception e) {
_log.error(
"Error while processing tracking action form template " +
_FORM_TEMPLATE_PATH,
e);
}
return content;
}
@Override
public String getIcon() {
return "icon-file";
}
@Override
public String getName(Locale locale) {
return ResourceActionsUtil.getModelResource(
locale, getClass().getName());
}
@Override
public String getShortDescription(Locale locale) {
String key = getClass().getName().concat(".shortDescription");
String shortDescription = ResourceActionsUtil.getModelResource(
locale, key);
if (shortDescription.endsWith(key)) {
shortDescription = StringPool.BLANK;
}
return shortDescription;
}
@Override
public String getTrackingActionKey() {
return getClass().getSimpleName();
}
@Override
public void importData(
PortletDataContext portletDataContext, Campaign campaign,
TrackingActionInstance trackingActionInstance)
throws Exception {
}
@Override
public boolean isInstantiable() {
return true;
}
@Override
public String processTrackingAction(
PortletRequest request, PortletResponse response, String id,
Map<String, String> values) throws InvalidTrackingActionException {
return null;
}
protected String getExportImportErrorMessage(
Campaign campaign, TrackingActionInstance trackingActionInstance,
String missingReferenceClassName, String missingReferenceId,
String action) {
StringBundler sb = new StringBundler(9);
if (action.equals(Constants.EXPORT)) {
sb.append("Cannot export tracking action ");
}
else {
sb.append("Cannot import tracking action ");
}
sb.append(getName(LocaleUtil.getDefault()));
sb.append(" from campaign ");
sb.append(campaign.getName(LocaleUtil.getDefault()));
sb.append(" because it refers to a missing ");
sb.append(
ResourceActionsUtil.getModelResource(
LocaleUtil.getDefault(), missingReferenceClassName));
sb.append(" with id ");
sb.append(missingReferenceId);
sb.append(".");
return sb.toString();
}
protected void populateContext(
TrackingActionInstance trackingActionInstance,
Map<String, Object> context, Map<String, String> values) {
}
protected static final String _FORM_TEMPLATE_PATH =
"templates/ct_tracking_action.ftl";
private static Log _log = LogFactoryUtil.getLog(BaseTrackingAction.class);
}