Skip to content

Commit

Permalink
WCM-567 Retry on CME
Browse files Browse the repository at this point in the history
See LPS-56505
  • Loading branch information
Eduardo Garcia committed Mar 21, 2016
1 parent 6d2f519 commit 26c7b34
Showing 1 changed file with 97 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@

import com.liferay.content.targeting.api.model.UserSegmentSimulator;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.ArrayUtil;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.util.PortalUtil;
import com.liferay.portlet.PortalPreferences;
import com.liferay.portlet.PortletPreferencesFactoryUtil;

import java.util.ArrayList;
import java.util.ConcurrentModificationException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
Expand All @@ -44,19 +47,34 @@ public void addUserSegmentId(

long userId = PortalUtil.getUserId(request);

PortalPreferences preferences = getPortalPreferences(userId);
while (true) {
try {
PortalPreferences preferences = getPortalPreferences(userId);

String[] simulatedUserSegmentIds = preferences.getValues(
"content-targeting", "simulatedUserSegmentIds",
new String[0]);

String[] simulatedUserSegmentIds = preferences.getValues(
"content-targeting", "simulatedUserSegmentIds", new String[0]);
simulatedUserSegmentIds = ArrayUtil.append(
simulatedUserSegmentIds, String.valueOf(userSegmentId));

simulatedUserSegmentIds = ArrayUtil.append(
simulatedUserSegmentIds, String.valueOf(userSegmentId));
preferences.setValues(
"content-targeting", "simulatedUserSegmentIds",
simulatedUserSegmentIds);
preferences.setValue(
"content-targeting", "simulation", String.valueOf(true));

preferences.setValues(
"content-targeting", "simulatedUserSegmentIds",
simulatedUserSegmentIds);
preferences.setValue(
"content-targeting", "simulation", String.valueOf(true));
break;
}
catch (ConcurrentModificationException cme) {
continue;
}
catch (Exception e) {
_log.error(e, e);

break;
}
}
}

@Override
Expand Down Expand Up @@ -85,12 +103,26 @@ public void removeAllUserSegmentIds(

long userId = PortalUtil.getUserId(request);

PortalPreferences preferences = getPortalPreferences(userId);
while (true) {
try {
PortalPreferences preferences = getPortalPreferences(userId);

preferences.setValues(
"content-targeting", "simulatedUserSegmentIds", null);
preferences.setValue(
"content-targeting", "simulation", String.valueOf(false));

preferences.setValues(
"content-targeting", "simulatedUserSegmentIds", null);
preferences.setValue(
"content-targeting", "simulation", String.valueOf(false));
break;
}
catch (ConcurrentModificationException cme) {
continue;
}
catch (Exception e) {
_log.error(e, e);

break;
}
}
}

@Override
Expand All @@ -100,21 +132,37 @@ public void removeUserSegmentId(

long userId = PortalUtil.getUserId(request);

PortalPreferences preferences = getPortalPreferences(userId);
while (true) {
try {
PortalPreferences preferences = getPortalPreferences(userId);

String[] simulatedUserSegmentIds = preferences.getValues(
"content-targeting", "simulatedUserSegmentIds",
new String[0]);

String[] simulatedUserSegmentIds = preferences.getValues(
"content-targeting", "simulatedUserSegmentIds", new String[0]);
simulatedUserSegmentIds = ArrayUtil.remove(
simulatedUserSegmentIds, String.valueOf(userSegmentId));

simulatedUserSegmentIds = ArrayUtil.remove(
simulatedUserSegmentIds, String.valueOf(userSegmentId));
preferences.setValues(
"content-targeting", "simulatedUserSegmentIds",
simulatedUserSegmentIds);

preferences.setValues(
"content-targeting", "simulatedUserSegmentIds",
simulatedUserSegmentIds);
if (simulatedUserSegmentIds.length == 0) {
preferences.setValue(
"content-targeting", "simulation",
String.valueOf(false));
}

if (simulatedUserSegmentIds.length == 0) {
preferences.setValue(
"content-targeting", "simulation", String.valueOf(false));
break;
}
catch (ConcurrentModificationException cme) {
continue;
}
catch (Exception e) {
_log.error(e, e);

break;
}
}
}

Expand All @@ -125,13 +173,27 @@ public void setUserSegmentIds(

long userId = PortalUtil.getUserId(request);

PortalPreferences preferences = getPortalPreferences(userId);
while (true) {
try {
PortalPreferences preferences = getPortalPreferences(userId);

preferences.setValues(
"content-targeting", "simulatedUserSegmentIds",
ArrayUtil.toStringArray(userSegmentIds));
preferences.setValue(
"content-targeting", "simulation", String.valueOf(true));
preferences.setValues(
"content-targeting", "simulatedUserSegmentIds",
ArrayUtil.toStringArray(userSegmentIds));
preferences.setValue(
"content-targeting", "simulation", String.valueOf(true));

break;
}
catch (ConcurrentModificationException cme) {
continue;
}
catch (Exception e) {
_log.error(e, e);

break;
}
}
}

protected long[] getLongArray(String[] array) {
Expand Down Expand Up @@ -164,4 +226,7 @@ protected PortalPreferences getPortalPreferences(long userId) {
return null;
}

private static Log _log = LogFactoryUtil.getLog(
PortalPreferencesUserSegmentSimulator.class);

}

0 comments on commit 26c7b34

Please sign in to comment.