Skip to content

Commit

Permalink
LRAC-14467 set experiment publishable to false on Asah when creating …
Browse files Browse the repository at this point in the history
…a new experiment over that
  • Loading branch information
marcosapmf authored and brianchandotcom committed Sep 13, 2023
1 parent 849d38d commit 42f9ee3
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 5 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,32 +15,46 @@
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.service.ServiceContext;
import com.liferay.portal.kernel.service.ServiceContextFactory;
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.exception.DuplicateSegmentsExperimentException;
import com.liferay.segments.experiment.web.internal.util.SegmentsExperimentUtil;
import com.liferay.segments.model.SegmentsExperiment;
import com.liferay.segments.model.SegmentsExperimentRel;
import com.liferay.segments.service.SegmentsEntryLocalService;
import com.liferay.segments.service.SegmentsExperienceLocalService;
import com.liferay.segments.service.SegmentsExperimentRelService;
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 @@ -55,6 +70,17 @@
public class AddSegmentsExperimentMVCActionCommand
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 @@ -98,6 +124,10 @@ private JSONObject _addSegmentsExperiment(ActionRequest actionRequest)
ServiceContext serviceContext = ServiceContextFactory.getInstance(
actionRequest);

AnalyticsConfiguration analyticsConfiguration =
_analyticsSettingsManager.getAnalyticsConfiguration(
serviceContext.getCompanyId());

long segmentsExperienceId = ParamUtil.getLong(
actionRequest, "segmentsExperienceId");
long plid = ParamUtil.getLong(actionRequest, "plid");
Expand All @@ -110,6 +140,19 @@ private JSONObject _addSegmentsExperiment(ActionRequest actionRequest)
if (segmentsExperiment.getStatus() ==
SegmentsExperimentConstants.STATUS_TERMINATED) {

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);

Expand Down Expand Up @@ -139,9 +182,8 @@ private JSONObject _addSegmentsExperiment(ActionRequest actionRequest)
return JSONUtil.put(
"segmentsExperiment",
SegmentsExperimentUtil.toSegmentsExperimentJSONObject(
_analyticsSettingsManager.getAnalyticsConfiguration(
segmentsExperiment.getCompanyId()),
themeDisplay.getLocale(), segmentsExperiment)
analyticsConfiguration, themeDisplay.getLocale(),
segmentsExperiment)
).put(
"segmentsExperimentRel",
SegmentsExperimentUtil.toSegmentsExperimentRelJSONObject(
Expand All @@ -159,12 +201,32 @@ private JSONObject _addSegmentsExperiment(ActionRequest actionRequest)
@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 SegmentsExperimentRelService _segmentsExperimentRelService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,32 @@ public static JSONObject toSegmentsExperimentRelJSONObject(
);
}

public static JSONObject toSegmentsExperimentRelJSONObject(
Locale locale, SegmentsExperimentRel segmentsExperimentRel)
throws PortalException {

if (segmentsExperimentRel == null) {
return null;
}

return JSONUtil.put(
"control", segmentsExperimentRel.isControl()
).put(
"name", segmentsExperimentRel.getName(locale)
).put(
"segmentsExperienceId",
String.valueOf(segmentsExperimentRel.getSegmentsExperienceId())
).put(
"segmentsExperimentId",
String.valueOf(segmentsExperimentRel.getSegmentsExperimentId())
).put(
"segmentsExperimentRelId",
String.valueOf(segmentsExperimentRel.getSegmentsExperimentRelId())
).put(
"split", segmentsExperimentRel.getSplit()
);
}

public static JSONObject toStatusJSONObject(Locale locale, int status) {
SegmentsExperimentConstants.Status segmentsExperimentConstantsStatus =
SegmentsExperimentConstants.Status.parse(status);
Expand Down

0 comments on commit 42f9ee3

Please sign in to comment.