diff --git a/source/java/org/alfresco/opencmis/AlfrescoCmisServiceImpl.java b/source/java/org/alfresco/opencmis/AlfrescoCmisServiceImpl.java index b745a8c871..7004c89516 100644 --- a/source/java/org/alfresco/opencmis/AlfrescoCmisServiceImpl.java +++ b/source/java/org/alfresco/opencmis/AlfrescoCmisServiceImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2013 Alfresco Software Limited. + * Copyright (C) 2005-2014 Alfresco Software Limited. * * This file is part of Alfresco * @@ -443,8 +443,12 @@ public class AlfrescoCmisServiceImpl extends AbstractCmisService implements Alfr if (sort.length > 0) { - Pair sortProp = connector.getSortProperty(sort[0], sort.length > 1 ? sort[1] : null); - sortProps.add(sortProp); + // MNT-10529: Leading spaces result in an empty string value after the split operation. Leading spaces may occur in the 'orderBy' statement when the + // elements of statement separated by a comma and a space(s) + int index = (sort[0].isEmpty()) ? (1) : (0); + + Pair sortProp = connector.getSortProperty(sort[index], sort.length > (index + 1) ? sort[index + 1] : null); + sortProps.add(sortProp); } } } diff --git a/source/test-java/org/alfresco/opencmis/CMISTest.java b/source/test-java/org/alfresco/opencmis/CMISTest.java index b1cb2e4555..025d8e1b5e 100644 --- a/source/test-java/org/alfresco/opencmis/CMISTest.java +++ b/source/test-java/org/alfresco/opencmis/CMISTest.java @@ -60,6 +60,7 @@ import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; import org.alfresco.service.transaction.TransactionService; import org.alfresco.util.ApplicationContextHelper; +import org.alfresco.util.Pair; import org.apache.chemistry.opencmis.commons.PropertyIds; import org.apache.chemistry.opencmis.commons.data.AllowableActions; import org.apache.chemistry.opencmis.commons.data.CmisExtensionElement; @@ -1372,6 +1373,7 @@ public class CMISTest assertTrue(repositories.size() > 0); RepositoryInfo repo = repositories.get(0); String repositoryId = repo.getId(); + 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); @@ -1397,4 +1399,87 @@ public class CMISTest } }); } + + @Test + public void testMNT10529() throws Exception + { + AuthenticationUtil.pushAuthentication(); + AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); + + try + { + final Pair folderAndDocument = transactionService.getRetryingTransactionHelper().doInTransaction( + new RetryingTransactionCallback>() + { + @Override + public Pair 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(folderInfo, document); + } + }); + + withCmisService(new CmisServiceCallback() + { + @Override + public Void execute(CmisService cmisService) + { + List 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 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(); + } + } }