Ignore:
Timestamp:
Nov 23, 2012, 4:55:04 PM (11 years ago)
Author:
casties
Branch:
default
Message:

fixed bug with new rectangle shapes. added limit, offset and sortBy parameters to annotator/ and annotator/search.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorSearch.java

    r32 r63  
    44package de.mpiwg.itgroup.annotations.restlet;
    55
     6import java.util.ArrayList;
    67import java.util.List;
    78
     
    1819import de.mpiwg.itgroup.annotations.Person;
    1920import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore;
     21import de.mpiwg.itgroup.annotations.restlet.utils.JSONObjectComparator;
    2022
    2123/**
     
    3436    /**
    3537     * result for JSON content-type. optional search parameters: uri, user, limit,
    36      * offset.
     38     * offset, sortBy.
    3739     *
    3840     * @param entity
     
    5052        String uri = form.getFirstValue("uri");
    5153        String user = form.getFirstValue("user");
    52         String limit = form.getFirstValue("limit");
    53         String offset = form.getFirstValue("offset");
     54        int limit = getInt(form.getFirstValue("limit"));
     55        int offset = getInt(form.getFirstValue("offset"));
     56        String sortBy = form.getFirstValue("sortBy");
    5457
    55         JSONArray results = new JSONArray();
    5658        // do search
     59        ArrayList<JSONObject> results = new ArrayList<JSONObject>();
    5760        logger.debug(String.format("searching for uri=%s user=%s", uri, user));
    5861        AnnotationStore store = getAnnotationStore();
    59         List<Annotation> annots = store.searchAnnotationByUriUser(uri, user, limit, offset);
     62        List<Annotation> annots = store.searchAnnotationByUriUser(uri, user);
    6063        for (Annotation annot : annots) {
    6164            // check permission
     
    6366            JSONObject jo = createAnnotatorJson(annot, (authUser == null));
    6467            if (jo != null) {
    65                 results.put(jo);
     68                results.add(jo);
    6669            } else {
    6770                setStatus(Status.SERVER_ERROR_INTERNAL, "JSON Error");
     
    6972            }
    7073        }
     74
     75        // sort if necessary
     76        if (sortBy != null) {
     77            JSONObjectComparator.sortAnnotations(results, sortBy);
     78        }
     79       
     80        // put in JSON list
     81        JSONArray rows = new JSONArray();
     82        int cnt = 0;
     83        for (JSONObject result : results) {
     84            cnt += 1;
     85            if (offset > 0 && cnt < offset) continue;
     86            rows.put(result);
     87            if (limit > 0 && cnt >= limit) break;
     88        }
     89
    7190        // assemble result object
    7291        JSONObject result = new JSONObject();
    7392        try {
    74             result.put("rows", results);
    75             result.put("total", results.length());
     93            result.put("rows", rows);
     94            result.put("total", rows.length());
    7695        } catch (JSONException e) {
    7796            setStatus(Status.SERVER_ERROR_INTERNAL, "JSON Error");
Note: See TracChangeset for help on using the changeset viewer.