Merged HEAD-BUG-FIX (4.3/Cloud) to HEAD (4.3/Cloud)

60935: Merged V4.2-BUG-FIX (4.2.2) to HEAD-BUG-FIX (Cloud/4.3)
      60808: Merged V4.2.1 (4.2.1) to V4.2-BUG-FIX (4.2.2)
         60776: MNT-10529: NPE when requesting Number of Items for current Page
         'orderBy' statement analyzing has been fixed in 'AlfrescoCmisServiceImpl.getChildren()'. Leading spaces are causing additional empty string part on splitting 'orderBy' element if query-able names are separated by a comma and a space.
         Test case for 'orderBy' parameter has been added


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@62370 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis
2014-02-12 14:42:19 +00:00
parent 3477169b7c
commit 9cd5480a3e
2 changed files with 92 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2005-2013 Alfresco Software Limited. * Copyright (C) 2005-2014 Alfresco Software Limited.
* *
* This file is part of Alfresco * This file is part of Alfresco
* *
@@ -443,8 +443,12 @@ public class AlfrescoCmisServiceImpl extends AbstractCmisService implements Alfr
if (sort.length > 0) if (sort.length > 0)
{ {
Pair<QName, Boolean> sortProp = connector.getSortProperty(sort[0], sort.length > 1 ? sort[1] : null); // MNT-10529: Leading spaces result in an empty string value after the split operation. Leading spaces may occur in the 'orderBy' statement when the
sortProps.add(sortProp); // elements of statement separated by a comma and a space(s)
int index = (sort[0].isEmpty()) ? (1) : (0);
Pair<QName, Boolean> sortProp = connector.getSortProperty(sort[index], sort.length > (index + 1) ? sort[index + 1] : null);
sortProps.add(sortProp);
} }
} }
} }

View File

@@ -60,6 +60,7 @@ import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.TransactionService; import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.ApplicationContextHelper; import org.alfresco.util.ApplicationContextHelper;
import org.alfresco.util.Pair;
import org.apache.chemistry.opencmis.commons.PropertyIds; import org.apache.chemistry.opencmis.commons.PropertyIds;
import org.apache.chemistry.opencmis.commons.data.AllowableActions; import org.apache.chemistry.opencmis.commons.data.AllowableActions;
import org.apache.chemistry.opencmis.commons.data.CmisExtensionElement; import org.apache.chemistry.opencmis.commons.data.CmisExtensionElement;
@@ -1372,6 +1373,7 @@ public class CMISTest
assertTrue(repositories.size() > 0); assertTrue(repositories.size() > 0);
RepositoryInfo repo = repositories.get(0); RepositoryInfo repo = repositories.get(0);
String repositoryId = repo.getId(); String repositoryId = repo.getId();
String objectId = cmisService.create(repositoryId, properties, repositoryHelper.getCompanyHome().getId(), contentStream, VersioningState.MINOR, null, null); String objectId = cmisService.create(repositoryId, properties, repositoryHelper.getCompanyHome().getId(), contentStream, VersioningState.MINOR, null, null);
ObjectData cmidDoc = cmisService.getObject(repositoryId, objectId, null, true, IncludeRelationships.NONE, null, false, false, null); ObjectData cmidDoc = cmisService.getObject(repositoryId, objectId, null, true, IncludeRelationships.NONE, null, false, false, null);
@@ -1397,4 +1399,87 @@ public class CMISTest
} }
}); });
} }
@Test
public void testMNT10529() throws Exception
{
AuthenticationUtil.pushAuthentication();
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
try
{
final Pair<FileInfo, FileInfo> folderAndDocument = transactionService.getRetryingTransactionHelper().doInTransaction(
new RetryingTransactionCallback<Pair<FileInfo, FileInfo>>()
{
@Override
public Pair<FileInfo, FileInfo> execute() throws Throwable
{
NodeRef companyHomeNodeRef = repositoryHelper.getCompanyHome();
String folderName = GUID.generate();
FileInfo folderInfo = fileFolderService.create(companyHomeNodeRef, folderName, ContentModel.TYPE_FOLDER);
nodeService.setProperty(folderInfo.getNodeRef(), ContentModel.PROP_NAME, folderName);
assertNotNull(folderInfo);
String docName = GUID.generate();
FileInfo document = fileFolderService.create(folderInfo.getNodeRef(), docName, ContentModel.TYPE_CONTENT);
assertNotNull(document);
nodeService.setProperty(document.getNodeRef(), ContentModel.PROP_NAME, docName);
return new Pair<FileInfo, FileInfo>(folderInfo, document);
}
});
withCmisService(new CmisServiceCallback<Void>()
{
@Override
public Void execute(CmisService cmisService)
{
List<RepositoryInfo> repositories = cmisService.getRepositoryInfos(null);
assertNotNull(repositories);
assertTrue(repositories.size() > 0);
RepositoryInfo repo = repositories.iterator().next();
String repositoryId = repo.getId();
String objectIdStr = folderAndDocument.getFirst().getNodeRef().toString();
ObjectInFolderList children = cmisService.getChildren(repositoryId, objectIdStr, null, "cmis:name ASC", false, IncludeRelationships.NONE, null, false, null,
null, null);
assertChildren(folderAndDocument, children);
children = cmisService.getChildren(repositoryId, objectIdStr, null, "cmis:name ASC, cmis:creationDate ASC", false, IncludeRelationships.NONE, null, false,
null, null, null);
assertChildren(folderAndDocument, children);
children = cmisService.getChildren(repositoryId, objectIdStr, null, " cmis:name ASC", false, IncludeRelationships.NONE, null, false, null, null, null);
assertChildren(folderAndDocument, children);
children = cmisService.getChildren(repositoryId, objectIdStr, null, " cmis:name ASC, cmis:creationDate ASC ", false, IncludeRelationships.NONE, null,
false, null, null, null);
assertChildren(folderAndDocument, children);
return null;
}
private void assertChildren(final Pair<FileInfo, FileInfo> folderAndDocument, ObjectInFolderList children)
{
assertNotNull(children);
assertTrue(1 == children.getNumItems().longValue());
PropertyData<?> nameData = children.getObjects().iterator().next().getObject().getProperties().getProperties().get("cmis:name");
assertNotNull(nameData);
Object name = nameData.getValues().iterator().next();
assertEquals(folderAndDocument.getSecond().getName(), name);
}
}, CmisVersion.CMIS_1_0);
}
catch (CmisConstraintException e)
{
fail(e.toString());
}
finally
{
AuthenticationUtil.popAuthentication();
}
}
} }