on 05-12-2004 10:59 AM
Hi
I'm using the KM API to retrieve resources from the repository. Default I receive the resources in descending date order. Is there a way to change the sort order of the document, for instance to retrieve them in alphabetical ascending order?
I haven't found any method for this. I know there is a reorder method for collections that can be used in combination with a sort algorithm to solve my problem. But it seems that there should be an easier way to solve the problem as it is possible to choose sorting in the repository iviews, maybe this functionality is not a part of the public KM API's?
Brgds// -Fred
Hi,
I'm using ResourceList:
<i>
ResourceList rList = new ResourceList();
...
aCollection = (ICollection) aResourceFactory.getResource(aRid, rContext);
if (aCollection != null) {
rList.add(aCollection.getChildren());
}
// in the rList there is a list of IResources...
DateComparator comp = new DateComparator();
rList.sort(comp);
// now the rList is sorted by date...
...
</i>
you have to implement your own comparator (in some cases), for example by our defined DATE property:
<i>import java.util.*;
import com.sapportals.wcm.repository.*;
public class DateComparator implements Comparator {
PropertyName propertyDate;
DateComparator() {
try {
propertyDate =
new PropertyName("http://sapportals.com/xmlns/cm/zapa", "Datum");
} catch (ResourceException e) {
e.printStackTrace();
}
}
public int compare(Object element1, Object element2) {
IResource res1 = (IResource) element1;
IResource res2 = (IResource) element2;
try {
IProperty datum1 = res1.getProperty(this.propertyDate);
IProperty datum2 = res2.getProperty(this.propertyDate);
if (datum1 != null
&& datum2 != null
&& datum1.getDateValue() != null
&& datum2.getDateValue() != null) {
if (datum1.getDateValue().before(datum2.getDateValue()))
return 1;
if (datum1.getDateValue().after(datum2.getDateValue()))
return -1;
return 0;
} else {
return -1;
}
} catch (NotSupportedException e) {
e.printStackTrace();
} catch (AccessDeniedException e) {
e.printStackTrace();
} catch (ResourceException e) {
e.printStackTrace();
}
return 0;
}
}</i>
Hope it helps,
Romano
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
KM supports unordered and ordered collections. Usually, collections are unordered; and the ordering in getChildren() is implementation-dependant (it may even be random). So in general, a client will need to do the ordering on it's own.
An ordered collection will always preserve it's ordering; but the actual ordering is not based on a specific algorithm but simply on the reorder operations and positions settings clients apply.
Hope this helps,
Julian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Julian for your answer. Unfortunately I am not really clear of what you are saying.
Do you mean that I can make the repository ordered and and specify to sort the resources alphabetically on the name in the client manually, and then call the getChildren() method and receive the children in alphabetically order (based on name)?
When I sort the documents in a repository ascending on the date this is not preserved the next time I go back to the repository, the folder is back on the name ascending sorting. Is there a way to set this, and can this be used in getChildren()? Or did I get you completely wrong which means that I have to implement my own sort algorithm?
Brgds// -Fred
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.