Extend record response with more info.
authorAdam Dickmeiss <adam@indexdata.dk>
Mon, 31 Aug 2009 12:39:35 +0000 (14:39 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Mon, 31 Aug 2009 12:39:35 +0000 (14:39 +0200)
The record command now has activeclients (as in show), nextrecid
(if such record exist), prevrecid (if such record exist). This allows
navigation on single records and check for whether the system is idle
(activeclients == 0). Bug #3012.

src/http_command.c
src/logic.c
src/pazpar2.h
test/test_http_23.res
test/test_http_6.res

index 340e7c0..ff35fdd 100644 (file)
@@ -550,7 +550,7 @@ static void cmd_record(struct http_channel *c)
     struct http_response *rs = c->response;
     struct http_request *rq = c->request;
     struct http_session *s = locate_session(rq, rs);
-    struct record_cluster *rec;
+    struct record_cluster *rec, *prev_r, *next_r;
     struct record *r;
     struct conf_service *service = global_parameters.server->service;
     const char *idstr = http_argbyname(rq, "id");
@@ -565,7 +565,7 @@ static void cmd_record(struct http_channel *c)
         return;
     }
     wrbuf_rewind(c->wrbuf);
-    if (!(rec = show_single(s->psession, idstr)))
+    if (!(rec = show_single(s->psession, idstr, &prev_r, &next_r)))
     {
         if (session_set_watch(s->psession, SESSION_WATCH_RECORD,
                               cmd_record_ready, c, c) != 0)
@@ -618,6 +618,20 @@ static void cmd_record(struct http_channel *c)
         wrbuf_puts(c->wrbuf, "<recid>");
         wrbuf_xmlputs(c->wrbuf, rec->recid);
         wrbuf_puts(c->wrbuf, "</recid>\n");
+        if (prev_r)
+        {
+            wrbuf_puts(c->wrbuf, "<prevrecid>");
+            wrbuf_xmlputs(c->wrbuf, prev_r->recid);
+            wrbuf_puts(c->wrbuf, "</prevrecid>\n");
+        }
+        if (next_r)
+        {
+            wrbuf_puts(c->wrbuf, "<nextrecid>");
+            wrbuf_xmlputs(c->wrbuf, next_r->recid);
+            wrbuf_puts(c->wrbuf, "</nextrecid>\n");
+        }
+        wrbuf_printf(c->wrbuf, "<activeclients>%d</activeclients>\n", 
+                     session_active_clients(s->psession));
         write_metadata(c->wrbuf, service, rec->metadata, 1);
         for (r = rec->records; r; r = r->next)
             write_subrecord(r, c->wrbuf, service, 1);
index 02a133d..f565706 100644 (file)
@@ -765,14 +765,24 @@ void report_nmem_stats(void)
 }
 #endif
 
-struct record_cluster *show_single(struct session *s, const char *id)
+struct record_cluster *show_single(struct session *s, const char *id,
+                                   struct record_cluster **prev_r,
+                                   struct record_cluster **next_r)
 {
     struct record_cluster *r;
 
     reclist_rewind(s->reclist);
+    *prev_r = 0;
+    *next_r = 0;
     while ((r = reclist_read_record(s->reclist)))
+    {
         if (!strcmp(r->recid, id))
+        {
+            *next_r = reclist_read_record(s->reclist);
             return r;
+        }
+        *prev_r = r;
+    }
     return 0;
 }
 
index 243745c..2a1f65c 100644 (file)
@@ -172,7 +172,9 @@ enum pazpar2_error_code search(struct session *s, char *query,
                                char *filter, const char **addinfo);
 struct record_cluster **show(struct session *s, struct reclist_sortparms *sp, int start,
         int *num, int *total, int *sumhits, NMEM nmem_show);
-struct record_cluster *show_single(struct session *s, const char *id);
+struct record_cluster *show_single(struct session *s, const char *id,
+                                   struct record_cluster **prev_r,
+                                   struct record_cluster **next_r);
 struct termlist_score **termlist(struct session *s, const char *name, int *num);
 int session_set_watch(struct session *s, int what, session_watchfun fun, void *data, struct http_channel *c);
 int session_active_clients(struct session *s);
index 6701271..348843c 100644 (file)
@@ -1,5 +1,7 @@
 <record>
 <recid>title how to program a computer author jack collins medium book</recid>
+<nextrecid>title computer processing of dynamic images from an anger scintillation camera author medium book</nextrecid>
+<activeclients>0</activeclients>
 
 <md-title>How to program a computer</md-title>
 <md-author>Jack Collins</md-author>
index 6701271..cd94513 100644 (file)
@@ -1,5 +1,7 @@
 <record>
 <recid>title how to program a computer author jack collins medium book</recid>
+<nextrecid>title the use of passwords for controlled access to computer resources author wood helen m medium book</nextrecid>
+<activeclients>0</activeclients>
 
 <md-title>How to program a computer</md-title>
 <md-author>Jack Collins</md-author>