[xwiki-devs] [Contrib]A new component : XWiki Object Sort
It sorts XWiki Objects by their propeties. I already made an extension page on http://extensions.xwiki.org/xwiki/bin/view/Extension/XWiki+Object+Sort I want to have a github repository on https://github.com/xwiki-contrib<http://github.com/xwiki-contrib>for a github user https://github.com/crocket/ The project page for xwiki-contrib-objectsort is https://project.snowberry.me/projects/xwikiobjectsort/repository And the repository page is http://gitweb.snowberry.me/?p=xwikiobjectsort.git;a=summary You can clone the source code from git://snowberry.me/xwikiobjectsort.git
On 11/24/2012 10:15 AM, crocket wrote:
It sorts XWiki Objects by their propeties. I already made an extension page on http://extensions.xwiki.org/xwiki/bin/view/Extension/XWiki+Object+Sort
I want to have a github repository on https://github.com/xwiki-contrib<http://github.com/xwiki-contrib>for a github user https://github.com/crocket/
The project page for xwiki-contrib-objectsort is https://project.snowberry.me/projects/xwikiobjectsort/repository And the repository page is http://gitweb.snowberry.me/?p=xwikiobjectsort.git;a=summary
You can clone the source code from git://snowberry.me/xwikiobjectsort.git
Hello, I looked a bit at your code, and I have some observations: - While I agree that being able to sort objects is important, I'd rather see this in a patched version of the $sorttool instead of a separate component; I've checked it and we'd just have to change the way getComparable works. Doing this means that we're going to reuse a tool that we're already supposed to be using for general sorting, and we'd get as benefits the ability to specify a sort direction, and the ability to mix properties and other object metadata, like owner document or object number. - Even as it is right now, I don't like that the script service only has a getInstance method and then exposes the internal object. - I don't think that both sort and sortCopy are needed. Only the method that sorts a copy and returns it should be available. - sortCopyByProps should also be called just sort, since the type of parameters passed will be enough for the right method to be called (polymorphism). And I'm actually wondering if we need both methods or not, since sorting by just one property could be done by passing a list with just one member. WDYT? -- Sergiu Dumitriu http://purl.org/net/sergiu
- While I agree that being able to sort objects is important, I'd rather see this in a patched version of the $sorttool instead of a separate component; I've checked it and we'd just have to change the way getComparable works. Doing this means that we're going to reuse a tool that we're already supposed to be using for general sorting, and we'd get as benefits the ability to specify a sort direction, and the ability to mix properties and other object metadata, like owner document or object number.
I agree that the functionality in ObjectSort should go into $sorttool, but I have no influence over the development of XWiki, so I advertised it as a contrib project. What is getComparable by the way?
- Even as it is right now, I don't like that the script service only has a getInstance method and then exposes the internal object.
I thought that if I put just getInstance in the script service, I could reduce redundancy in the code. But I'm only a starting programmer. There are certainly better designs than mine.
- I don't think that both sort and sortCopy are needed. Only the method that sorts a copy and returns it should be available.
If only the method that sort a copy and returns it is available, there can be increased memory usage, so I introduced an in-place sort method, too. Why do you think an in-place sort method should not be available?
- sortCopyByProps should also be called just sort, since the type of parameters passed will be enough for the right method to be called (polymorphism). And I'm actually wondering if we need both methods or not, since sorting by just one property could be done by passing a list with just one member.
You're right. I thought $services.objectsort.getInstance().sortByProps($doc.getObjects("Class"), ["port", "day:asc", "hour:desc"]) was possible but $services.objectsort.getInstance().sortByProps($doc.getObjects("Class"), "port") wasn't possible because I thought String couldn't be cast to List<String>. However, $services.objectsort.getInstance().sortByProps($doc.getObjects("Class"), "port") just worked out of box. I'll remove sort and sortCopy and rename sortByProps and sortCopyByProps to sort and sortByProps, respectively.
participants (2)
-
crocket -
Sergiu Dumitriu