Skip to content

Commit

Permalink
LRAC-14467 set experiment publishable to false on Asah and delete it …
Browse files Browse the repository at this point in the history
…on DXP when publishing an experience
  • Loading branch information
marcosapmf authored and brianchandotcom committed Sep 13, 2023
1 parent 39ef61a commit 23d884c
Showing 1 changed file with 89 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
* SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
*/

package com.liferay.segments.experiment.web.internal.portlet.action;
package com.liferay.segments.asah.connector.internal.portlet.action;

import com.liferay.analytics.settings.configuration.AnalyticsConfiguration;
import com.liferay.analytics.settings.rest.manager.AnalyticsSettingsManager;
import com.liferay.portal.kernel.json.JSONObject;
import com.liferay.portal.kernel.json.JSONUtil;
Expand All @@ -14,26 +15,41 @@
import com.liferay.portal.kernel.portlet.JSONPortletResponseUtil;
import com.liferay.portal.kernel.portlet.bridges.mvc.BaseMVCActionCommand;
import com.liferay.portal.kernel.portlet.bridges.mvc.MVCActionCommand;
import com.liferay.portal.kernel.service.CompanyLocalService;
import com.liferay.portal.kernel.service.GroupLocalService;
import com.liferay.portal.kernel.service.LayoutLocalService;
import com.liferay.portal.kernel.theme.ThemeDisplay;
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.Http;
import com.liferay.portal.kernel.util.LocaleUtil;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.Portal;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.segments.asah.connector.internal.client.AsahFaroBackendClient;
import com.liferay.segments.asah.connector.internal.client.AsahFaroBackendClientImpl;
import com.liferay.segments.asah.connector.internal.client.model.Experiment;
import com.liferay.segments.asah.connector.internal.client.model.util.ExperimentUtil;
import com.liferay.segments.asah.connector.internal.util.SegmentsExperimentUtil;
import com.liferay.segments.constants.SegmentsExperimentConstants;
import com.liferay.segments.constants.SegmentsPortletKeys;
import com.liferay.segments.experiment.web.internal.util.SegmentsExperimentUtil;
import com.liferay.segments.model.SegmentsExperiment;
import com.liferay.segments.service.SegmentsEntryLocalService;
import com.liferay.segments.service.SegmentsExperienceLocalService;
import com.liferay.segments.service.SegmentsExperimentService;

import java.util.Map;
import java.util.concurrent.Callable;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;

import javax.servlet.http.HttpServletResponse;

import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Reference;

/**
Expand All @@ -49,6 +65,17 @@
public class EditSegmentsExperimentStatusMVCActionCommand
extends BaseMVCActionCommand {

@Activate
protected void activate(Map<String, Object> properties) {
_asahFaroBackendClient = new AsahFaroBackendClientImpl(
_analyticsSettingsManager, _http);
}

@Deactivate
protected void deactivate() {
_asahFaroBackendClient = null;
}

@Override
protected void doProcessAction(
ActionRequest actionRequest, ActionResponse actionResponse)
Expand Down Expand Up @@ -97,18 +124,53 @@ private JSONObject _editSegmentsExperimentStatus(
(ThemeDisplay)actionRequest.getAttribute(
WebKeys.THEME_DISPLAY);

long winnerSegmentsExperienceId = ParamUtil.getLong(
actionRequest, "winnerSegmentsExperienceId", -1);

SegmentsExperiment segmentsExperiment =
_segmentsExperimentService.updateSegmentsExperimentStatus(
ParamUtil.getLong(
actionRequest, "segmentsExperimentId"),
ParamUtil.getLong(
actionRequest, "winnerSegmentsExperienceId", -1),
winnerSegmentsExperienceId,
ParamUtil.getInteger(actionRequest, "status"));

return SegmentsExperimentUtil.toSegmentsExperimentJSONObject(
AnalyticsConfiguration analyticsConfiguration =
_analyticsSettingsManager.getAnalyticsConfiguration(
themeDisplay.getCompanyId()),
themeDisplay.getLocale(), segmentsExperiment);
themeDisplay.getCompanyId());

if (((segmentsExperiment.getStatus() ==
SegmentsExperimentConstants.STATUS_COMPLETED) ||
(segmentsExperiment.getStatus() ==
SegmentsExperimentConstants.STATUS_TERMINATED)) &&
(winnerSegmentsExperienceId != -1) &&
(winnerSegmentsExperienceId ==
segmentsExperiment.getWinnerSegmentsExperienceId())) {

Experiment experiment = ExperimentUtil.toExperiment(
_companyLocalService,
analyticsConfiguration.liferayAnalyticsDataSourceId(),
_groupLocalService, _layoutLocalService,
LocaleUtil.getSiteDefault(), _portal,
_segmentsEntryLocalService,
_segmentsExperienceLocalService, segmentsExperiment);

experiment.setPublishable(false);

_asahFaroBackendClient.updateExperiment(
segmentsExperiment.getCompanyId(), experiment);

segmentsExperiment.setStatus(
SegmentsExperimentConstants.STATUS_DELETED_ON_DXP_ONLY);

_segmentsExperimentService.deleteSegmentsExperiment(
segmentsExperiment, false);

segmentsExperiment = null;
}

return SegmentsExperimentUtil.toSegmentsExperimentJSONObject(
analyticsConfiguration, themeDisplay.getLocale(),
segmentsExperiment);
});
}

Expand All @@ -122,12 +184,32 @@ private JSONObject _editSegmentsExperimentStatus(
@Reference
private AnalyticsSettingsManager _analyticsSettingsManager;

private AsahFaroBackendClient _asahFaroBackendClient;

@Reference
private CompanyLocalService _companyLocalService;

@Reference
private GroupLocalService _groupLocalService;

@Reference
private Http _http;

@Reference
private Language _language;

@Reference
private LayoutLocalService _layoutLocalService;

@Reference
private Portal _portal;

@Reference
private SegmentsEntryLocalService _segmentsEntryLocalService;

@Reference
private SegmentsExperienceLocalService _segmentsExperienceLocalService;

@Reference
private SegmentsExperimentService _segmentsExperimentService;

Expand Down

0 comments on commit 23d884c

Please sign in to comment.