<commit_before>var registry = registry || {};

(function (server, registry) {
    var log = new Log();

    var Resource = Packages.org.wso2.carbon.registry.core.Resource;

    var Collection = Packages.org.wso2.carbon.registry.core.Collection;

    var Comment = Packages.org.wso2.carbon.registry.core.Comment;

    var StaticConfiguration = Packages.org.wso2.carbon.registry.core.config.StaticConfiguration;

    var queryPath = '/_system/config/repository/components/org.wso2.carbon.registry/queries/';

    var content = function (registry, resource, paging) {
        if (resource instanceof Collection) {
            // #1 : this always sort children by name, so sorting cannot be done for the chunk
            return children(registry, resource, paging);
        }
        if (resource instanceof Comment) {
            return String(resource.getText());
        }
        try {
            var stream = resource.getContentStream();
            if (stream) {
                return new Stream(stream);
            }
        } catch (e) {
            log.error(e);
            //this is because getContentStream() throws an exception when content is empty
        }
        return String(resource.content);
    };

    var resourceSorter = function (key) {
        var nameAsc = function (l, r) {
            var lname, rname;
            if (l instanceof Collection) {
                lname = l.getName();
                lname = lname.substring(lname.lastIndexOf('/') + 1);
            } else {
                lname = l.name;
            }
            if (r instanceof Collection) {
                rname = r.getName();
                rname = rname.substring(rname.lastIndexOf('/') + 1);
            } else {
                rname = r.name;
            }
            return lname === rname ? 0 : (lname > rname ? 1 : -1);
        };
        switch (key) {
            case 'time-created-asc' :
                return function (l, r) {
                    return l.getCreatedTime().getTime() - r.getCreatedTime().getTime();
                };
            case 'time-created-des' :
                return function (l, r) {
                    return r.getCreatedTime().getTime() - l.getCreatedTime().getTime();
                };
            case 'name-asc' :
                return nameAsc;
            case 'name-des' :
                return function (l, r) {
                    return -nameAsc(l, r);
                };
            default:
                return resourceSorter('time-created-des');
        }
    };

    var children = function (registry, resource, paging) {
        var resources = resource.getChildren();
        //we have to manually sort this due to the bug in registry.getChildren() (#1 above)
        //resources.sort(resourceSorter(paging.sort));
        return resources.slice(paging.start, paging.start + paging.count);
    };

    var resource = function (registry, resource) {
        var path = String(resource.path),
            o = {
                created: {
                    author: String(resource.authorUserName),
                    time: resource.createdTime.time
                },
                content: content(registry, resource, {
                    start: 0,
                    count: 10
                }),
                id: String(resource.id),
                version: resource.versionNumber
            };
        if (resource instanceof Comment) {
            return o;
        }
        if (resource instanceof Collection) {
            o.collection = (resource instanceof Collection);<commit_msg>remove pagination at children method in registry.get<commit_after>var registry = registry || {};

(function (server, registry) {
    var log = new Log();

    var Resource = Packages.org.wso2.carbon.registry.core.Resource;

    var Collection = Packages.org.wso2.carbon.registry.core.Collection;

    var Comment = Packages.org.wso2.carbon.registry.core.Comment;

    var StaticConfiguration = Packages.org.wso2.carbon.registry.core.config.StaticConfiguration;

    var queryPath = '/_system/config/repository/components/org.wso2.carbon.registry/queries/';

    var content = function (registry, resource, paging) {
        if (resource instanceof Collection) {
            // #1 : this always sort children by name, so sorting cannot be done for the chunk
            return children(registry, resource, paging);
        }
        if (resource instanceof Comment) {
            return String(resource.getText());
        }
        try {
            var stream = resource.getContentStream();
            if (stream) {
                return new Stream(stream);
            }
        } catch (e) {
            log.error(e);
            //this is because getContentStream() throws an exception when content is empty
        }
        return String(resource.content);
    };

    var resourceSorter = function (key) {
        var nameAsc = function (l, r) {
            var lname, rname;
            if (l instanceof Collection) {
                lname = l.getName();
                lname = lname.substring(lname.lastIndexOf('/') + 1);
            } else {
                lname = l.name;
            }
            if (r instanceof Collection) {
                rname = r.getName();
                rname = rname.substring(rname.lastIndexOf('/') + 1);
            } else {
                rname = r.name;
            }
            return lname === rname ? 0 : (lname > rname ? 1 : -1);
        };
        switch (key) {
            case 'time-created-asc' :
                return function (l, r) {
                    return l.getCreatedTime().getTime() - r.getCreatedTime().getTime();
                };
            case 'time-created-des' :
                return function (l, r) {
                    return r.getCreatedTime().getTime() - l.getCreatedTime().getTime();
                };
            case 'name-asc' :
                return nameAsc;
            case 'name-des' :
                return function (l, r) {
                    return -nameAsc(l, r);
                };
            default:
                return resourceSorter('time-created-des');
        }
    };

    var children = function (registry, resource, paging) {
        var resources = resource.getChildren();
        //we have to manually sort this due to the bug in registry.getChildren() (#1 above)
        //resources.sort(resourceSorter(paging.sort));
//        return resources.slice(paging.start, paging.start + paging.count);
        return resources;
    };

    var resource = function (registry, resource) {
        var path = String(resource.path),
            o = {
                created: {
                    author: String(resource.authorUserName),
                    time: resource.createdTime.time
                },
                content: content(registry, resource, {
                    start: 0,
                    count: 10
                }),
                id: String(resource.id),
                version: resource.versionNumber
            };
        if (resource instanceof Comment) {
            return o;
        }
        if (resource instanceof Collection) {
            o.collection = (resource instanceof Collection);
{'fraction_non_alphanumeric': 0.10708836177000972, 'fraction_numerical': 0.004161464835622139, 'mean_word_length': 1.5423131170662905, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7479280', 'n_tokens_mistral': 1902, 'n_tokens_neox': 1791, 'n_words': 473}