Merged DEV to HEAD

52232: Introduce filter to select only enabled tenants (ALF-19172)
   52233: Missed file for rev 52232 (ALF-19172)
   52246: MT: Make lowercasing of tenant domain a little more explicit
   52247: MT: Clean up imports, redundant non-Javadoc and add @Override


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@52288 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2013-07-09 13:56:14 +00:00
parent b687de2f80
commit 5c06b15604
12 changed files with 839 additions and 745 deletions

View File

@@ -105,11 +105,12 @@ public abstract class AbstractTenantAdminDAOImpl implements TenantAdminDAO
private TenantEntity getTenantImpl(String tenantDomain)
{
tenantDomain = tenantDomain.toLowerCase();
Pair<String, TenantEntity> entityPair = tenantEntityCache.getByKey(tenantDomain);
if (entityPair == null)
{
// try lower-case to make sure
entityPair = tenantEntityCache.getByKey(tenantDomain.toLowerCase());
entityPair = tenantEntityCache.getByKey(tenantDomain);
if (entityPair == null)
{
return null;
@@ -119,9 +120,16 @@ public abstract class AbstractTenantAdminDAOImpl implements TenantAdminDAO
}
@Override
public List<TenantEntity> listTenants()
public List<TenantEntity> listTenants(boolean enabledOnly)
{
return getTenantEntities();
if (enabledOnly)
{
return getTenantEntities(Boolean.TRUE);
}
else
{
return getTenantEntities(null);
}
}
@Override
@@ -241,7 +249,10 @@ public abstract class AbstractTenantAdminDAOImpl implements TenantAdminDAO
protected abstract TenantEntity createTenantEntity(TenantEntity tenantEntity);
protected abstract TenantEntity getTenantEntity(String tenantDomain);
protected abstract List<TenantEntity> getTenantEntities();
/**
* @param enabled Enabled or disabled tenants or <tt>null</tt> for no filter
*/
protected abstract List<TenantEntity> getTenantEntities(Boolean enabled);
protected abstract int updateTenantEntity(TenantEntity tenantEntity);
protected abstract int deleteTenantEntity(String tenantDomain);
}

View File

@@ -42,7 +42,7 @@ public interface TenantAdminDAO
/**
* List tenants
*/
List<TenantEntity> listTenants();
List<TenantEntity> listTenants(boolean enabledOnly);
/**
* Get tenant for update

View File

@@ -119,13 +119,13 @@ public class TenantAdminDAOTest extends TestCase
return txnHelper.doInTransaction(callback, true);
}
private List<TenantEntity> listTenants() throws Exception
private List<TenantEntity> listTenants(final boolean enabledOnly) throws Exception
{
RetryingTransactionCallback<List<TenantEntity>> callback = new RetryingTransactionCallback<List<TenantEntity>>()
{
public List<TenantEntity> execute() throws Throwable
{
return tenantAdminDAO.listTenants();
return tenantAdminDAO.listTenants(enabledOnly);
}
};
return txnHelper.doInTransaction(callback, true);
@@ -229,7 +229,8 @@ public class TenantAdminDAOTest extends TestCase
final String tenantDomainPrefix = getName() + "-" + System.currentTimeMillis();
final int cnt = 5;
int beforeCnt = listTenants().size();
int beforeCnt = listTenants(false).size();
int enabledCnt = listTenants(true).size();
for (int i = 1; i <= cnt; i++)
{
@@ -240,7 +241,8 @@ public class TenantAdminDAOTest extends TestCase
tenantEntity = createTenant(tenantDomain, false);
assertNotNull(tenantEntity);
assertEquals(i+beforeCnt, listTenants().size());
assertEquals(i+beforeCnt, listTenants(false).size());
assertEquals("Tenant enabled/disabled count incorrect.", enabledCnt, listTenants(true).size());
tenantEntity = getTenant(tenantDomain);
assertNotNull(tenantEntity);
@@ -254,7 +256,7 @@ public class TenantAdminDAOTest extends TestCase
deleteTenant(tenantDomain);
assertEquals(i-1+beforeCnt, listTenants().size());
assertEquals(i-1+beforeCnt, listTenants(false).size());
tenantEntity = getTenant(tenantDomain);
assertNull(tenantEntity);

View File

@@ -0,0 +1,80 @@
/*
* Copyright (C) 2005-2013 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco 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 3 of the License, or
* (at your option) any later version.
*
* Alfresco 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.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.domain.tenant;
/**
* Entity for <b>alf_tenant</b> queries.
*
* @author Derek Hulley
* @since 4.2
*/
public class TenantQueryEntity
{
private String tenantDomain;
private String tenantName;
private Boolean enabled;
@Override
public String toString()
{
StringBuilder sb = new StringBuilder(512);
sb.append("TenantQueryEntity")
.append("[ tenantDomain=").append(tenantDomain)
.append(", tenantName=").append(tenantName)
.append(", enabled=").append(enabled)
.append("]");
return sb.toString();
}
/** Framework usage only */
@SuppressWarnings("unused")
private String getTenantDomain()
{
return tenantDomain;
}
public void setTenantDomain(String tenantDomain)
{
this.tenantDomain = tenantDomain;
}
/** Framework usage only */
@SuppressWarnings("unused")
private String getTenantName()
{
return tenantName;
}
public void setTenantName(String tenantName)
{
this.tenantName = tenantName;
}
/** Framework usage only */
@SuppressWarnings("unused")
private Boolean getEnabled()
{
return enabled;
}
public void setEnabled(Boolean enabled)
{
this.enabled = enabled;
}
}

View File

@@ -24,6 +24,7 @@ import java.util.Map;
import org.alfresco.repo.domain.tenant.AbstractTenantAdminDAOImpl;
import org.alfresco.repo.domain.tenant.TenantEntity;
import org.alfresco.repo.domain.tenant.TenantQueryEntity;
import org.mybatis.spring.SqlSessionTemplate;
/**
@@ -67,9 +68,11 @@ public class TenantAdminDAOImpl extends AbstractTenantAdminDAOImpl
@SuppressWarnings("unchecked")
@Override
protected List<TenantEntity> getTenantEntities()
protected List<TenantEntity> getTenantEntities(Boolean enabled)
{
return (List<TenantEntity>)template.selectList(SELECT_TENANTS);
TenantQueryEntity entity = new TenantQueryEntity();
entity.setEnabled(enabled);
return (List<TenantEntity>)template.selectList(SELECT_TENANTS, entity);
}
@Override

File diff suppressed because it is too large Load Diff

View File

@@ -145,7 +145,7 @@ public class ModuleComponentHelperTest extends BaseAlfrescoTestCase
int tenantCount = 0;
if (tenantDeployerService.isEnabled())
{
tenantCount = tenantDeployerService.getAllTenants().size();
tenantCount = tenantDeployerService.getTenants(true).size();
}
// Check
assertEquals(

View File

@@ -27,10 +27,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.repo.admin.registry.RegistryKey;
import org.alfresco.repo.admin.registry.RegistryService;
import org.alfresco.repo.tenant.TenantAdminService;
import org.alfresco.service.ServiceRegistry;
@@ -46,7 +44,6 @@ import org.springframework.context.ApplicationContextAware;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.extensions.surf.util.I18NUtil;
/**
* This component controls the execution of
@@ -118,10 +115,7 @@ public class ModuleServiceImpl implements ApplicationContextAware, ModuleService
this.moduleComponentHelper.setApplyToTenants(applyToTenants);
}
/* (non-Javadoc)
* @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
*/
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
{
this.resolver = applicationContext;

View File

@@ -113,7 +113,7 @@ public abstract class AbstractTenantRoutingContentStore extends AbstractRoutingC
if ((currentUser == null) || (tenantService.getBaseNameUser(currentUser).equals(AuthenticationUtil.getSystemUserName())))
{
// return enabled stores across all tenants, if running as system/null user, for example, ContentStoreCleaner scheduled job
List<TenantEntity> tenants = tenantAdminDAO.listTenants();
List<TenantEntity> tenants = tenantAdminDAO.listTenants(false);
for (TenantEntity tenant : tenants)
{
if (tenant.getEnabled())

View File

@@ -850,7 +850,7 @@ public class MultiTAdminServiceImpl implements TenantAdminService, ApplicationCo
@Deprecated
public List<Tenant> getTenants(boolean enabledOnly)
{
List<TenantEntity> tenantEntities = tenantAdminDAO.listTenants();
List<TenantEntity> tenantEntities = tenantAdminDAO.listTenants(enabledOnly);
List<Tenant> tenants = new ArrayList<Tenant>(tenantEntities.size());
for (TenantEntity tenantEntity : tenantEntities)
{