Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Component with its own class name as service type] LPS-206371 Refactor CurrentAccountEntryManagerStore, WorkflowMetricsSLADefinitionTransformer and FeatureFlagBatchEngineUnitProcessor #1411

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@

import javax.servlet.http.HttpSession;

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

/**
* @author Drew Brokke
*/
@Component(service = CurrentAccountEntryManagerStore.class)
public class CurrentAccountEntryManagerStore {
public abstract class BaseCurrentAccountEntryManagerStore {

public AccountEntry getAccountEntryFromHttpSession(long groupId) {
HttpSession httpSession = PortalSessionThreadLocal.getHttpSession();
Expand All @@ -41,7 +39,7 @@ public AccountEntry getAccountEntryFromHttpSession(long groupId) {
long currentAccountEntryId = GetterUtil.getLong(
httpSession.getAttribute(_getKey(groupId)));

return _accountEntryLocalService.fetchAccountEntry(
return accountEntryLocalService.fetchAccountEntry(
currentAccountEntryId);
}

Expand All @@ -50,23 +48,23 @@ public AccountEntry getAccountEntryFromPortalPreferences(

com.liferay.portal.kernel.model.PortalPreferences
modelPortalPreferences =
_portalPreferencesLocalService.fetchPortalPreferences(
portalPreferencesLocalService.fetchPortalPreferences(
userId, PortletKeys.PREFS_OWNER_TYPE_USER);

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

PortalPreferences portalPreferences =
_portalPreferenceValueLocalService.getPortalPreferences(
portalPreferenceValueLocalService.getPortalPreferences(
modelPortalPreferences, false);

long accountEntryId = GetterUtil.getLong(
portalPreferences.getValue(
AccountEntry.class.getName(), _getKey(groupId)));

if (accountEntryId > 0) {
return _accountEntryLocalService.fetchAccountEntry(accountEntryId);
return accountEntryLocalService.fetchAccountEntry(accountEntryId);
}

return null;
Expand Down Expand Up @@ -114,17 +112,30 @@ public void saveInPortalPreferences(
portalPreferences.setValue(
AccountEntry.class.getName(), key, String.valueOf(accountEntryId));

_portalPreferencesLocalService.updatePreferences(
portalPreferencesLocalService.updatePreferences(
userId, PortletKeys.PREFS_OWNER_TYPE_USER, portalPreferences);
}

public void setCurrentAccountEntry(
public void setCurrentAccountEntryManagerStore(
long accountEntryId, long groupId, long userId) {

saveInHttpSession(accountEntryId, groupId);
saveInPortalPreferences(accountEntryId, groupId, userId);
}

@Reference
protected AccountEntryLocalService accountEntryLocalService;

@Reference
protected PortalPreferencesLocalService portalPreferencesLocalService;

@Reference
protected PortalPreferenceValueLocalService
portalPreferenceValueLocalService;

@Reference
protected PortletPreferencesFactory portletPreferencesFactory;

private String _getKey(long groupId) {
return AccountWebKeys.CURRENT_ACCOUNT_ENTRY_ID + groupId;
}
Expand All @@ -134,8 +145,7 @@ private PortalPreferences _getPortalPreferences(long userId) {
// LPS-156201

try {
return _portletPreferencesFactory.getPortalPreferences(
userId, true);
return portletPreferencesFactory.getPortalPreferences(userId, true);
}
catch (Exception exception) {
if (_log.isDebugEnabled()) {
Expand All @@ -147,19 +157,6 @@ private PortalPreferences _getPortalPreferences(long userId) {
}

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

@Reference
private AccountEntryLocalService _accountEntryLocalService;

@Reference
private PortalPreferencesLocalService _portalPreferencesLocalService;

@Reference
private PortalPreferenceValueLocalService
_portalPreferenceValueLocalService;

@Reference
private PortletPreferencesFactory _portletPreferencesFactory;
BaseCurrentAccountEntryManagerStore.class);

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
*/
@Component(service = CurrentAccountEntryManager.class)
public class CurrentAccountEntryManagerImpl
extends BaseCurrentAccountEntryManagerStore
implements CurrentAccountEntryManager {

@Override
Expand All @@ -63,23 +64,18 @@ public AccountEntry getCurrentAccountEntry(long groupId, long userId)
PermissionChecker permissionChecker = _permissionCheckerFactory.create(
user);

AccountEntry accountEntry =
_currentAccountEntryManagerStore.getAccountEntryFromHttpSession(
groupId);
AccountEntry accountEntry = getAccountEntryFromHttpSession(groupId);

String[] allowedTypes = _getAllowedTypes(groupId);

if (_isValid(accountEntry, allowedTypes, permissionChecker)) {
return accountEntry;
}

accountEntry =
_currentAccountEntryManagerStore.
getAccountEntryFromPortalPreferences(groupId, userId);
accountEntry = getAccountEntryFromPortalPreferences(groupId, userId);

if (_isValid(accountEntry, allowedTypes, permissionChecker)) {
_currentAccountEntryManagerStore.saveInHttpSession(
accountEntry.getAccountEntryId(), groupId);
saveInHttpSession(accountEntry.getAccountEntryId(), groupId);

return accountEntry;
}
Expand Down Expand Up @@ -117,8 +113,7 @@ public void setCurrentAccountEntry(
"type: " + accountEntry.getType());
}

_currentAccountEntryManagerStore.setCurrentAccountEntry(
accountEntryId, groupId, userId);
setCurrentAccountEntryManagerStore(accountEntryId, groupId, userId);
}
catch (PortalException portalException) {
if (_log.isWarnEnabled()) {
Expand Down Expand Up @@ -198,9 +193,6 @@ private boolean _isValid(
private volatile ModelResourcePermission<AccountEntry>
_accountEntryModelResourcePermission;

@Reference
private CurrentAccountEntryManagerStore _currentAccountEntryManagerStore;

@Reference
private PermissionCheckerFactory _permissionCheckerFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package com.liferay.account.internal.security.permission.contributor;

import com.liferay.account.constants.AccountRoleConstants;
import com.liferay.account.internal.manager.CurrentAccountEntryManagerStore;
import com.liferay.account.internal.manager.BaseCurrentAccountEntryManagerStore;
import com.liferay.account.model.AccountEntry;
import com.liferay.account.model.AccountRole;
import com.liferay.account.service.AccountEntryUserRelLocalService;
Expand All @@ -32,7 +32,8 @@
* @author Pei-Jung Lan
*/
@Component(service = RoleContributor.class)
public class AccountRoleContributor implements RoleContributor {
public class AccountRoleContributor
extends BaseCurrentAccountEntryManagerStore implements RoleContributor {

@Override
public void contribute(RoleCollection roleCollection) {
Expand All @@ -53,9 +54,8 @@ public void contribute(RoleCollection roleCollection) {
if (!Objects.equals(
AccountEntry.class.getName(), group.getClassName())) {

AccountEntry currentAccountEntry =
_currentAccountEntryManagerStore.getCurrentAccountEntry(
roleCollection.getGroupId(), user.getUserId());
AccountEntry currentAccountEntry = getCurrentAccountEntry(
roleCollection.getGroupId(), user.getUserId());

if ((currentAccountEntry != null) &&
(currentAccountEntry.getAccountEntryId() > 0)) {
Expand Down Expand Up @@ -103,9 +103,6 @@ private void _addRoleId(RoleCollection roleCollection, String roleName)
@Reference
private AccountRoleLocalService _accountRoleLocalService;

@Reference
private CurrentAccountEntryManagerStore _currentAccountEntryManagerStore;

@Reference
private GroupLocalService _groupLocalService;

Expand Down
Loading