mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-15 15:02:20 +00:00
Merged HEAD (5.1) to 5.1.N (5.1.1)
120229 rdina: ACE-4836 Modifications on the FileInfoPropsComparator class so that it takes into account the IS_FOLDER attribute, which is not among the properties. Added FileInfoComparatotTest class. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.1.N/root@120378 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -36,6 +36,8 @@ public class FileInfoPropsComparator implements Comparator<FileInfo>
|
|||||||
|
|
||||||
private Collator collator;
|
private Collator collator;
|
||||||
|
|
||||||
|
public static final String IS_FOLDER = "IS_FOLDER";
|
||||||
|
|
||||||
public FileInfoPropsComparator(List<Pair<QName, Boolean>> sortProps)
|
public FileInfoPropsComparator(List<Pair<QName, Boolean>> sortProps)
|
||||||
{
|
{
|
||||||
this.sortProps = sortProps;
|
this.sortProps = sortProps;
|
||||||
@@ -72,6 +74,12 @@ public class FileInfoPropsComparator implements Comparator<FileInfo>
|
|||||||
pv1 = node1.getProperties().get(sortPropQName);
|
pv1 = node1.getProperties().get(sortPropQName);
|
||||||
pv2 = node2.getProperties().get(sortPropQName);
|
pv2 = node2.getProperties().get(sortPropQName);
|
||||||
|
|
||||||
|
if (sortPropQName.getLocalName().equals(IS_FOLDER))
|
||||||
|
{
|
||||||
|
pv1 = node1.isFolder();
|
||||||
|
pv2 = node2.isFolder();
|
||||||
|
}
|
||||||
|
|
||||||
if (pv1 == null)
|
if (pv1 == null)
|
||||||
{
|
{
|
||||||
if (pv2 == null && sortProps.size() > 1)
|
if (pv2 == null && sortProps.size() > 1)
|
||||||
|
@@ -23,6 +23,7 @@ import junit.framework.JUnit4TestAdapter;
|
|||||||
import junit.framework.Test;
|
import junit.framework.Test;
|
||||||
import junit.framework.TestSuite;
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
|
import org.alfresco.repo.virtual.bundle.FileInfoPropsComparatorTest;
|
||||||
import org.alfresco.repo.virtual.bundle.VirtualCheckOutCheckInServiceExtensionTest;
|
import org.alfresco.repo.virtual.bundle.VirtualCheckOutCheckInServiceExtensionTest;
|
||||||
import org.alfresco.repo.virtual.bundle.VirtualFileFolderServiceExtensionTest;
|
import org.alfresco.repo.virtual.bundle.VirtualFileFolderServiceExtensionTest;
|
||||||
import org.alfresco.repo.virtual.bundle.VirtualLockableAspectInterceptorExtensionTest;
|
import org.alfresco.repo.virtual.bundle.VirtualLockableAspectInterceptorExtensionTest;
|
||||||
@@ -66,6 +67,7 @@ public class VirtualizationIntegrationTestSuite extends TestSuite implements Vir
|
|||||||
suite.addTest(new JUnit4TestAdapter(VirtualStoreImplTest.class));
|
suite.addTest(new JUnit4TestAdapter(VirtualStoreImplTest.class));
|
||||||
suite.addTest(new JUnit4TestAdapter(NodeRefPathExpressionTest.class));
|
suite.addTest(new JUnit4TestAdapter(NodeRefPathExpressionTest.class));
|
||||||
suite.addTest(new JUnit4TestAdapter(TemplateFilingRuleTest.class));
|
suite.addTest(new JUnit4TestAdapter(TemplateFilingRuleTest.class));
|
||||||
|
suite.addTest(new JUnit4TestAdapter(FileInfoPropsComparatorTest.class));
|
||||||
|
|
||||||
return suite;
|
return suite;
|
||||||
|
|
||||||
|
@@ -0,0 +1,188 @@
|
|||||||
|
|
||||||
|
package org.alfresco.repo.virtual.bundle;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.alfresco.model.ContentModel;
|
||||||
|
import org.alfresco.repo.virtual.VirtualizationIntegrationTest;
|
||||||
|
import org.alfresco.service.cmr.model.FileInfo;
|
||||||
|
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
import org.alfresco.service.namespace.NamespaceService;
|
||||||
|
import org.alfresco.service.namespace.QName;
|
||||||
|
import org.alfresco.util.Pair;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class FileInfoPropsComparatorTest extends VirtualizationIntegrationTest
|
||||||
|
{
|
||||||
|
|
||||||
|
private static Log logger = LogFactory.getLog(FileInfoPropsComparatorTest.class);
|
||||||
|
|
||||||
|
private void compare(List<FileInfo> fileInfoList, QName property)
|
||||||
|
{
|
||||||
|
|
||||||
|
List<Pair<QName, Boolean>> sortProps = new ArrayList<>();
|
||||||
|
sortProps.add(new Pair<QName, Boolean>(QName.createQName("IS_FOLDER"),
|
||||||
|
false));
|
||||||
|
sortProps.add(new Pair<QName, Boolean>(property,
|
||||||
|
false));
|
||||||
|
|
||||||
|
FileInfoPropsComparator comparator = new FileInfoPropsComparator(sortProps);
|
||||||
|
|
||||||
|
// compare 1 file and 1 folder, descending order, folder is first
|
||||||
|
assertEquals(-1,
|
||||||
|
comparator.compare(fileInfoList.get(0),
|
||||||
|
fileInfoList.get(1)));
|
||||||
|
assertEquals(1,
|
||||||
|
comparator.compare(fileInfoList.get(1),
|
||||||
|
fileInfoList.get(0)));
|
||||||
|
|
||||||
|
// compare 1 file and 1 folder, ascending order, folder is first
|
||||||
|
List<Pair<QName, Boolean>> localSortProps = sortProps;
|
||||||
|
localSortProps.get(0).setSecond(true);
|
||||||
|
comparator = new FileInfoPropsComparator(localSortProps);
|
||||||
|
assertEquals(1,
|
||||||
|
comparator.compare(fileInfoList.get(0),
|
||||||
|
fileInfoList.get(1)));
|
||||||
|
assertEquals(-1,
|
||||||
|
comparator.compare(fileInfoList.get(1),
|
||||||
|
fileInfoList.get(0)));
|
||||||
|
|
||||||
|
// compare 2 files, use date mofified
|
||||||
|
assertEquals(1,
|
||||||
|
comparator.compare(fileInfoList.get(1),
|
||||||
|
fileInfoList.get(2)));
|
||||||
|
assertEquals(-1,
|
||||||
|
comparator.compare(fileInfoList.get(2),
|
||||||
|
fileInfoList.get(1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCompare()
|
||||||
|
{
|
||||||
|
createFolder(testRootFolder.getNodeRef(),
|
||||||
|
"FOLDER").getChildRef();
|
||||||
|
NodeRef virtualFolder = createVirtualizedFolder(testRootFolder.getNodeRef(),
|
||||||
|
VIRTUAL_FOLDER_2_NAME,
|
||||||
|
TEST_TEMPLATE_6_JSON_SYS_PATH);
|
||||||
|
NodeRef nodeRef1 = nodeService.getChildByName(virtualFolder,
|
||||||
|
ContentModel.ASSOC_CONTAINS,
|
||||||
|
"Node1");
|
||||||
|
|
||||||
|
QName assocQName1 = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI,
|
||||||
|
QName.createValidLocalName("testfile1.txt"));
|
||||||
|
|
||||||
|
QName assocQName2 = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI,
|
||||||
|
QName.createValidLocalName("testfile2.txt"));
|
||||||
|
|
||||||
|
ChildAssociationRef assoc2 = nodeService.createNode(virtualFolder,
|
||||||
|
ContentModel.ASSOC_CONTAINS,
|
||||||
|
assocQName1,
|
||||||
|
ContentModel.TYPE_CONTENT,
|
||||||
|
null);
|
||||||
|
NodeRef nodeRef2 = assoc2.getChildRef();
|
||||||
|
|
||||||
|
ChildAssociationRef assoc3 = nodeService.createNode(virtualFolder,
|
||||||
|
ContentModel.ASSOC_CONTAINS,
|
||||||
|
assocQName2,
|
||||||
|
ContentModel.TYPE_CONTENT,
|
||||||
|
null);
|
||||||
|
NodeRef nodeRef3 = assoc3.getChildRef();
|
||||||
|
|
||||||
|
List<NodeRef> nodeRefList = new ArrayList<NodeRef>();
|
||||||
|
nodeRefList.add(nodeRef1);
|
||||||
|
nodeRefList.add(nodeRef2);
|
||||||
|
nodeRefList.add(nodeRef3);
|
||||||
|
|
||||||
|
List<FileInfo> fileInfoList = fileAndFolderService.toFileInfoList(nodeRefList);
|
||||||
|
|
||||||
|
this.compare(fileInfoList,
|
||||||
|
ContentModel.PROP_MODIFIED);
|
||||||
|
this.compare(fileInfoList,
|
||||||
|
ContentModel.PROP_CREATED);
|
||||||
|
|
||||||
|
nodeService.setProperty(nodeRef2,
|
||||||
|
ContentModel.PROP_TITLE,
|
||||||
|
"title2");
|
||||||
|
nodeService.setProperty(nodeRef3,
|
||||||
|
ContentModel.PROP_TITLE,
|
||||||
|
"title3");
|
||||||
|
fileInfoList = fileAndFolderService.toFileInfoList(nodeRefList);
|
||||||
|
this.compare(fileInfoList,
|
||||||
|
ContentModel.PROP_TITLE);
|
||||||
|
|
||||||
|
nodeService.setProperty(nodeRef2,
|
||||||
|
ContentModel.PROP_DESCRIPTION,
|
||||||
|
"descr2");
|
||||||
|
nodeService.setProperty(nodeRef3,
|
||||||
|
ContentModel.PROP_DESCRIPTION,
|
||||||
|
"descr3");
|
||||||
|
fileInfoList = fileAndFolderService.toFileInfoList(nodeRefList);
|
||||||
|
this.compare(fileInfoList,
|
||||||
|
ContentModel.PROP_DESCRIPTION);
|
||||||
|
|
||||||
|
nodeService.setProperty(nodeRef2,
|
||||||
|
ContentModel.PROP_DESCRIPTION,
|
||||||
|
"descr2");
|
||||||
|
nodeService.setProperty(nodeRef3,
|
||||||
|
ContentModel.PROP_DESCRIPTION,
|
||||||
|
"descr2");
|
||||||
|
nodeService.setProperty(nodeRef2,
|
||||||
|
ContentModel.PROP_TITLE,
|
||||||
|
"title");
|
||||||
|
nodeService.setProperty(nodeRef3,
|
||||||
|
ContentModel.PROP_TITLE,
|
||||||
|
"title1");
|
||||||
|
List<Pair<QName, Boolean>> sortProps = new ArrayList<>();
|
||||||
|
sortProps.add(new Pair<QName, Boolean>(QName.createQName("IS_FOLDER"),
|
||||||
|
false));
|
||||||
|
sortProps.add(new Pair<QName, Boolean>(ContentModel.PROP_DESCRIPTION,
|
||||||
|
false));
|
||||||
|
sortProps.add(new Pair<QName, Boolean>(ContentModel.PROP_TITLE,
|
||||||
|
false));
|
||||||
|
fileInfoList = fileAndFolderService.toFileInfoList(nodeRefList);
|
||||||
|
FileInfoPropsComparator comparator = new FileInfoPropsComparator(sortProps);
|
||||||
|
assertEquals(1,
|
||||||
|
comparator.compare(fileInfoList.get(1),
|
||||||
|
fileInfoList.get(2)));
|
||||||
|
|
||||||
|
nodeService.setProperty(nodeRef2,
|
||||||
|
ContentModel.PROP_CREATED,
|
||||||
|
new Date(8099,
|
||||||
|
11,
|
||||||
|
31));
|
||||||
|
nodeService.setProperty(nodeRef3,
|
||||||
|
ContentModel.PROP_CREATED,
|
||||||
|
new Date(0,
|
||||||
|
0,
|
||||||
|
0));
|
||||||
|
fileInfoList = fileAndFolderService.toFileInfoList(nodeRefList);
|
||||||
|
sortProps.remove((sortProps.size() - 1));
|
||||||
|
sortProps.add(new Pair<QName, Boolean>(ContentModel.PROP_CREATED,
|
||||||
|
false));
|
||||||
|
comparator = new FileInfoPropsComparator(sortProps);
|
||||||
|
assertEquals(1,
|
||||||
|
comparator.compare(fileInfoList.get(1),
|
||||||
|
fileInfoList.get(2)));
|
||||||
|
|
||||||
|
nodeService.setProperty(nodeRef2,
|
||||||
|
ContentModel.PROP_TITLE,
|
||||||
|
"");
|
||||||
|
nodeService.setProperty(nodeRef3,
|
||||||
|
ContentModel.PROP_TITLE,
|
||||||
|
" ");
|
||||||
|
fileInfoList = fileAndFolderService.toFileInfoList(nodeRefList);
|
||||||
|
sortProps.remove((sortProps.size() - 1));
|
||||||
|
sortProps.add(new Pair<QName, Boolean>(ContentModel.PROP_TITLE,
|
||||||
|
false));
|
||||||
|
comparator = new FileInfoPropsComparator(sortProps);
|
||||||
|
assertEquals(1,
|
||||||
|
comparator.compare(fileInfoList.get(1),
|
||||||
|
fileInfoList.get(2)));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user