Merged V3.1 to HEAD

13902: Merged V2.2 to V3.1
        13900: Fixed ETHREEOH-1846: NullPointerException in ADMLuceneIndexerImpl if localized string is null
    14167: MT - fix ETHREEOH-2015
    14198: MT - fix ETHREEOH-210 and add unit tests (will also fix ALFCOM-2823 when merged forward to HEAD)


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@14204 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka
2009-05-06 11:40:13 +00:00
parent 5791792f95
commit 70d66c0f8c
4 changed files with 300 additions and 136 deletions

View File

@@ -300,6 +300,9 @@
<property name="tenantAdminService"> <property name="tenantAdminService">
<ref bean="tenantAdminService" /> <ref bean="tenantAdminService" />
</property> </property>
<property name="tenantService">
<ref bean="tenantService" />
</property>
<property name="clearBatchSize"> <property name="clearBatchSize">
<value>50</value> <value>50</value>
</property> </property>

View File

@@ -597,6 +597,9 @@ public class ADMLuceneIndexerImpl extends AbstractLuceneIndexerImpl<NodeRef> imp
for (QName propertyName : properties.keySet()) for (QName propertyName : properties.keySet())
{ {
Serializable value = properties.get(propertyName); Serializable value = properties.get(propertyName);
value = convertForMT(propertyName, value);
if (indexAllProperties) if (indexAllProperties)
{ {
indexProperty(nodeRef, propertyName, value, xdoc, false); indexProperty(nodeRef, propertyName, value, xdoc, false);
@@ -616,7 +619,7 @@ public class ADMLuceneIndexerImpl extends AbstractLuceneIndexerImpl<NodeRef> imp
Pair<Path, QName> pair = it.next(); Pair<Path, QName> pair = it.next();
// Lucene flags in order are: Stored, indexed, tokenised // Lucene flags in order are: Stored, indexed, tokenised
qNameRef = getLastRefOrNull(pair.getFirst()); qNameRef = tenantService.getName(getLastRefOrNull(pair.getFirst()));
String pathString = pair.getFirst().toString(); String pathString = pair.getFirst().toString();
if ((pathString.length() > 0) && (pathString.charAt(0) == '/')) if ((pathString.length() > 0) && (pathString.charAt(0) == '/'))
@@ -648,7 +651,7 @@ public class ADMLuceneIndexerImpl extends AbstractLuceneIndexerImpl<NodeRef> imp
qNameBuffer.append(";/"); qNameBuffer.append(";/");
} }
qNameBuffer.append(ISO9075.getXPathName(qNameRef.getQName())); qNameBuffer.append(ISO9075.getXPathName(qNameRef.getQName()));
xdoc.add(new Field("PARENT", tenantService.getName(qNameRef.getParentRef()).toString(), Field.Store.YES, Field.Index.NO_NORMS, Field.TermVector.NO)); xdoc.add(new Field("PARENT", qNameRef.getParentRef().toString(), Field.Store.YES, Field.Index.NO_NORMS, Field.TermVector.NO));
xdoc.add(new Field("ASSOCTYPEQNAME", ISO9075.getXPathName(qNameRef.getTypeQName()), Field.Store.YES, Field.Index.NO, Field.TermVector.NO)); xdoc.add(new Field("ASSOCTYPEQNAME", ISO9075.getXPathName(qNameRef.getTypeQName()), Field.Store.YES, Field.Index.NO, Field.TermVector.NO));
xdoc.add(new Field("LINKASPECT", (pair.getSecond() == null) ? "" : ISO9075.getXPathName(pair.getSecond()), Field.Store.YES, Field.Index.NO_NORMS, xdoc.add(new Field("LINKASPECT", (pair.getSecond() == null) ? "" : ISO9075.getXPathName(pair.getSecond()), Field.Store.YES, Field.Index.NO_NORMS,
Field.TermVector.NO)); Field.TermVector.NO));
@@ -746,6 +749,36 @@ public class ADMLuceneIndexerImpl extends AbstractLuceneIndexerImpl<NodeRef> imp
return docs; return docs;
} }
private Serializable convertForMT(QName propertyName, Serializable inboundValue)
{
if (! tenantService.isEnabled())
{
// no conversion
return inboundValue;
}
PropertyDefinition propertyDef = getDictionaryService().getProperty(propertyName);
if ((propertyDef != null) && ((propertyDef.getDataType().getName().equals(DataTypeDefinition.NODE_REF)) || (propertyDef.getDataType().getName().equals(DataTypeDefinition.CATEGORY))))
{
if (inboundValue instanceof Collection)
{
Collection<NodeRef> in = (Collection<NodeRef>)inboundValue;
ArrayList<NodeRef> out = new ArrayList<NodeRef>(in.size());
for (NodeRef o : in)
{
out.add(tenantService.getName(o));
}
return out;
}
else
{
return tenantService.getName((NodeRef)inboundValue);
}
}
return inboundValue;
}
/** /**
* @param indexAtomicPropertiesOnly * @param indexAtomicPropertiesOnly
* true to ignore all properties that must be indexed non-atomically * true to ignore all properties that must be indexed non-atomically
@@ -979,6 +1012,11 @@ public class ADMLuceneIndexerImpl extends AbstractLuceneIndexerImpl<NodeRef> imp
for (Locale locale : mlText.getLocales()) for (Locale locale : mlText.getLocales())
{ {
String localeString = mlText.getValue(locale); String localeString = mlText.getValue(locale);
if (localeString == null)
{
// No text for that locale
continue;
}
StringBuilder builder; StringBuilder builder;
MLAnalysisMode analysisMode; MLAnalysisMode analysisMode;
VerbatimAnalyser vba; VerbatimAnalyser vba;

View File

@@ -29,7 +29,7 @@ import java.io.PrintWriter;
import java.io.Serializable; import java.io.Serializable;
import java.io.StringWriter; import java.io.StringWriter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -63,6 +63,7 @@ import org.alfresco.service.cmr.security.AuthorityType;
import org.alfresco.service.cmr.security.OwnableService; import org.alfresco.service.cmr.security.OwnableService;
import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.cmr.security.PersonService; import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.cmr.usage.UsageService;
import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
import org.alfresco.util.ApplicationContextHelper; import org.alfresco.util.ApplicationContextHelper;
@@ -93,10 +94,12 @@ public class MultiTDemoTest extends TestCase
private CheckOutCheckInService cociService; private CheckOutCheckInService cociService;
private RepoAdminService repoAdminService; private RepoAdminService repoAdminService;
private DictionaryService dictionaryService; private DictionaryService dictionaryService;
private UsageService usageService;
public static int NUM_TENANTS = 2; public static int NUM_TENANTS = 2;
public static final String TEST_TENANT_DOMAIN = "my.test"; public static final String TEST_RUN = System.currentTimeMillis()+"";
public static final String TEST_TENANT_DOMAIN = TEST_RUN+".my.test";
public static final String TEST_TENANT_DOMAIN2 = TEST_TENANT_DOMAIN+"2"; public static final String TEST_TENANT_DOMAIN2 = TEST_TENANT_DOMAIN+"2";
public static List<String> tenants; public static List<String> tenants;
@@ -151,6 +154,7 @@ public class MultiTDemoTest extends TestCase
cociService = (CheckOutCheckInService) ctx.getBean("CheckoutCheckinService"); cociService = (CheckOutCheckInService) ctx.getBean("CheckoutCheckinService");
repoAdminService = (RepoAdminService) ctx.getBean("RepoAdminService"); repoAdminService = (RepoAdminService) ctx.getBean("RepoAdminService");
dictionaryService = (DictionaryService) ctx.getBean("DictionaryService"); dictionaryService = (DictionaryService) ctx.getBean("DictionaryService");
usageService = (UsageService) ctx.getBean("usageService");
} }
@Override @Override
@@ -160,6 +164,40 @@ public class MultiTDemoTest extends TestCase
} }
public void test_ETHREEOH_2015()
{
final String tenantDomain1 = TEST_RUN+".one.ethreeoh2015";
final String tenantDomain2 = TEST_RUN+".two.ethreeoh2015";
clearUsage(AuthenticationUtil.getAdminUserName());
createTenant(tenantDomain1);
String tenantAdminName = tenantService.getDomainUser(AuthenticationUtil.getAdminUserName(), tenantDomain1);
AuthenticationUtil.runAs(new RunAsWork<Object>()
{
public Object doWork() throws Exception
{
createUser(TEST_USER1, tenantDomain1, TEST_USER1+" "+tenantDomain1);
return null;
}
}, tenantAdminName);
createTenant(tenantDomain2);
}
private void clearUsage(String userName)
{
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); // authenticate as super-admin
// find person
NodeRef personNodeRef = personService.getPerson(userName);
// clear user usage
nodeService.setProperty(personNodeRef, ContentModel.PROP_SIZE_CURRENT, null);
usageService.deleteDeltas(personNodeRef);
}
public void testCreateTenants() throws Throwable public void testCreateTenants() throws Throwable
{ {
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); // authenticate as super-admin AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); // authenticate as super-admin
@@ -180,6 +218,20 @@ public class MultiTDemoTest extends TestCase
try try
{ {
for (final String tenantDomain : tenants) for (final String tenantDomain : tenants)
{
createTenant(tenantDomain);
}
}
catch (Throwable t)
{
StringWriter stackTrace = new StringWriter();
t.printStackTrace(new PrintWriter(stackTrace));
System.err.println(stackTrace.toString());
throw t;
}
}
private void createTenant(final String tenantDomain)
{ {
// create tenants (if not already created) // create tenants (if not already created)
AuthenticationUtil.runAs(new RunAsWork<Object>() AuthenticationUtil.runAs(new RunAsWork<Object>()
@@ -198,15 +250,6 @@ public class MultiTDemoTest extends TestCase
} }
}, AuthenticationUtil.getSystemUserName()); }, AuthenticationUtil.getSystemUserName());
} }
}
catch (Throwable t)
{
StringWriter stackTrace = new StringWriter();
t.printStackTrace(new PrintWriter(stackTrace));
System.err.println(stackTrace.toString());
throw t;
}
}
public void testCreateUsers() throws Throwable public void testCreateUsers() throws Throwable
{ {
@@ -276,8 +319,6 @@ public class MultiTDemoTest extends TestCase
assertEquals(4, personRefs.size()); // admin@tenant, guest@tenant, alice@tenant, bob@tenant assertEquals(4, personRefs.size()); // admin@tenant, guest@tenant, alice@tenant, bob@tenant
} }
return null; return null;
} }
}, tenantAdminName); }, tenantAdminName);
@@ -400,6 +441,18 @@ public class MultiTDemoTest extends TestCase
{ {
logger.info("Create demo categories"); logger.info("Create demo categories");
// super admin
AuthenticationUtil.runAs(new RunAsWork<Object>()
{
public Object doWork() throws Exception
{
logger.info("Create demo categories - super tenant");
createCategoriesImpl("");
return null;
}
}, AuthenticationUtil.getAdminUserName());
for (final String tenantDomain : tenants) for (final String tenantDomain : tenants)
{ {
String tenantAdminName = tenantService.getDomainUser(AuthenticationUtil.getAdminUserName(), tenantDomain); String tenantAdminName = tenantService.getDomainUser(AuthenticationUtil.getAdminUserName(), tenantDomain);
@@ -408,17 +461,9 @@ public class MultiTDemoTest extends TestCase
{ {
public Object doWork() throws Exception public Object doWork() throws Exception
{ {
NodeRef catRef = createCategory(SPACES_STORE, null, "CatA", "CatA-"+tenantDomain); logger.info("Create demo categories - "+tenantDomain);
createCategory(SPACES_STORE, catRef, "SubCatA", "SubCatA-"+tenantDomain); // ignore return
catRef = createCategory(SPACES_STORE, null, "CatB", "CatB-"+tenantDomain); createCategoriesImpl(tenantDomain);
createCategory(SPACES_STORE, catRef, "SubCatB", "SubCatB-"+tenantDomain); // ignore return
if (tenantDomain.equals(TEST_TENANT_DOMAIN2))
{
catRef = createCategory(SPACES_STORE, null, "CatC", "CatC-"+tenantDomain);
createCategory(SPACES_STORE, catRef, "SubCatC", "SubCatC-"+tenantDomain); // ignore return
}
return null; return null;
} }
@@ -427,6 +472,78 @@ public class MultiTDemoTest extends TestCase
} }
} }
@SuppressWarnings("unchecked")
private void createCategoriesImpl(String tenantDomain)
{
if (tenantDomain.equals(TenantService.DEFAULT_DOMAIN))
{
Collection<ChildAssociationRef> childAssocs = categoryService.getRootCategories(SPACES_STORE, ContentModel.ASPECT_GEN_CLASSIFIABLE);
for (ChildAssociationRef childAssoc : childAssocs)
{
if (nodeService.getProperty(childAssoc.getChildRef(), ContentModel.PROP_NAME).equals("CatA"))
{
return; // re-runnable, else we need to delete the created categories
}
}
}
// Find all root categories
String query = "PATH:\"/cm:generalclassifiable/*\"";
ResultSet resultSet = searchService.query(SPACES_STORE, SearchService.LANGUAGE_LUCENE, query);
int cnt = resultSet.length();
NodeRef catA = createCategory(SPACES_STORE, null, "CatA", "CatA-"+tenantDomain);
createCategory(SPACES_STORE, catA, "SubCatA", "SubCatA-"+tenantDomain); // ignore return
NodeRef catB = createCategory(SPACES_STORE, null, "CatB", "CatB-"+tenantDomain);
createCategory(SPACES_STORE, catB, "SubCatB", "SubCatB-"+tenantDomain); // ignore return
cnt = cnt + 2;
if (tenantDomain.equals(TEST_TENANT_DOMAIN2))
{
NodeRef catC = createCategory(SPACES_STORE, null, "CatC", "CatC-"+tenantDomain);
createCategory(SPACES_STORE, catC, "SubCatC", "SubCatC-"+tenantDomain); // ignore return
cnt = cnt + 1;
}
// Find all root categories
resultSet = searchService.query(SPACES_STORE, SearchService.LANGUAGE_LUCENE, query);
assertEquals(cnt, resultSet.length());
String queryMembers = "PATH:\"/cm:generalclassifiable//cm:catA/member\"";
resultSet = searchService.query(SPACES_STORE, SearchService.LANGUAGE_LUCENE, queryMembers);
assertEquals(0, resultSet.length());
NodeRef homeSpaceRef = getHomeSpaceFolderNode(AuthenticationUtil.getRunAsUser());
NodeRef contentRef = addContent(homeSpaceRef, "tqbfjotld.txt", "The quick brown fox jumps over the lazy dog (tenant " + tenantDomain + ")", MimetypeMap.MIMETYPE_TEXT_PLAIN);
assertFalse(nodeService.hasAspect(contentRef, ContentModel.ASPECT_GEN_CLASSIFIABLE));
List<NodeRef> categories = (List<NodeRef>)nodeService.getProperty(contentRef, ContentModel.PROP_CATEGORIES);
assertNull(categories);
// Classify the node (ie. assign node to a particular category in a classification)
categories = new ArrayList<NodeRef>(1);
categories.add(catA);
HashMap<QName, Serializable> catProps = new HashMap<QName, Serializable>();
catProps.put(ContentModel.PROP_CATEGORIES, (Serializable)categories);
nodeService.addAspect(contentRef, ContentModel.ASPECT_GEN_CLASSIFIABLE, catProps);
assertTrue(nodeService.hasAspect(contentRef, ContentModel.ASPECT_GEN_CLASSIFIABLE));
categories = (List<NodeRef>)nodeService.getProperty(contentRef, ContentModel.PROP_CATEGORIES);
assertEquals(1, categories.size());
// test ETHREEOH-210
queryMembers = "PATH:\"/cm:generalclassifiable//cm:CatA/member\"";
resultSet = searchService.query(SPACES_STORE, SearchService.LANGUAGE_LUCENE, queryMembers);
assertEquals(1, resultSet.length());
}
public void testCreateFolders() public void testCreateFolders()
{ {
logger.info("Create demo folders"); logger.info("Create demo folders");
@@ -499,7 +616,6 @@ public class MultiTDemoTest extends TestCase
if (tenantDomain.equals(TEST_TENANT_DOMAIN2)) if (tenantDomain.equals(TEST_TENANT_DOMAIN2))
{ {
contentRef = addContent(homeSpaceRef, tenantUserName+" quick brown fox ANO.txt", "The quick brown fox jumps over the lazy dog ANO (tenant " + tenantDomain + ")", MimetypeMap.MIMETYPE_TEXT_PLAIN); contentRef = addContent(homeSpaceRef, tenantUserName+" quick brown fox ANO.txt", "The quick brown fox jumps over the lazy dog ANO (tenant " + tenantDomain + ")", MimetypeMap.MIMETYPE_TEXT_PLAIN);
nodeService.addAspect(contentRef, ContentModel.ASPECT_VERSIONABLE, null); nodeService.addAspect(contentRef, ContentModel.ASPECT_VERSIONABLE, null);
} }
@@ -1023,13 +1139,12 @@ public class MultiTDemoTest extends TestCase
return content; return content;
} }
/*
// comment-in to run from command line
public static void main(String args[]) public static void main(String args[])
{ {
System.out.println(new Date()); System.out.println(new Date());
junit.textui.TestRunner.run(MultiTDemoTest.class); junit.textui.TestRunner.run(MultiTDemoTest.class);
System.out.println(new Date()); System.out.println(new Date());
} }
*/
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2005-2008 Alfresco Software Limited. * Copyright (C) 2005-2009 Alfresco Software Limited.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@@ -39,6 +39,7 @@ import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.repo.tenant.Tenant; import org.alfresco.repo.tenant.Tenant;
import org.alfresco.repo.tenant.TenantAdminService; import org.alfresco.repo.tenant.TenantAdminService;
import org.alfresco.repo.tenant.TenantService;
import org.alfresco.repo.transaction.TransactionServiceImpl; import org.alfresco.repo.transaction.TransactionServiceImpl;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.cmr.repository.ContentData; import org.alfresco.service.cmr.repository.ContentData;
@@ -68,6 +69,7 @@ public class UserUsageTrackingComponent
private NodeDaoService nodeDaoService; private NodeDaoService nodeDaoService;
private UsageService usageService; private UsageService usageService;
private TenantAdminService tenantAdminService; private TenantAdminService tenantAdminService;
private TenantService tenantService;
private StoreRef personStoreRef; private StoreRef personStoreRef;
@@ -112,6 +114,11 @@ public class UserUsageTrackingComponent
this.tenantAdminService = tenantAdminService; this.tenantAdminService = tenantAdminService;
} }
public void setTenantService(TenantService tenantService)
{
this.tenantService = tenantService;
}
public void setClearBatchSize(int clearBatchSize) public void setClearBatchSize(int clearBatchSize)
{ {
this.clearBatchSize = clearBatchSize; this.clearBatchSize = clearBatchSize;
@@ -332,7 +339,8 @@ public class UserUsageTrackingComponent
return true; // continue to next node (more required) return true; // continue to next node (more required)
} }
}; };
nodeDaoService.getUsersWithoutUsage(personStoreRef, userHandler);
nodeDaoService.getUsersWithoutUsage(tenantService.getName(personStoreRef), userHandler);
return null; return null;
} }
@@ -375,7 +383,7 @@ public class UserUsageTrackingComponent
for (String store : stores) for (String store : stores)
{ {
final StoreRef storeRef = new StoreRef(store); final StoreRef storeRef = tenantService.getName(new StoreRef(store));
if (logger.isTraceEnabled()) if (logger.isTraceEnabled())
{ {