yaz-ztest: returns MARC-in-JSON for JSON format
authorAdam Dickmeiss <adam@indexdata.dk>
Mon, 9 Dec 2013 09:57:07 +0000 (10:57 +0100)
committerAdam Dickmeiss <adam@indexdata.dk>
Mon, 9 Dec 2013 09:57:07 +0000 (10:57 +0100)
ztest/read-marc.c
ztest/ztest.c
ztest/ztest.h

index b11b697..487d9ab 100644 (file)
@@ -1683,6 +1683,26 @@ char *dummy_xml_record(int num, ODR odr, const char *esn)
     return 0;
 }
 
+char *dummy_json_record(int num, ODR odr, const char *esn)
+{
+    if (!esn || !strcmp(esn, "marcinjson"))
+    {
+        char *rec = dummy_marc_record(num, odr);
+        if (rec)
+        {
+            WRBUF w = wrbuf_alloc();
+            yaz_marc_t mt = yaz_marc_create();
+            yaz_marc_xml(mt, YAZ_MARC_JSON);
+            yaz_marc_decode_wrbuf(mt, rec, -1, w);
+            rec = odr_strdup(odr, wrbuf_cstr(w));
+            yaz_marc_destroy(mt);
+            wrbuf_destroy(w);
+            return rec;
+        }
+    }
+    return 0;
+}
+
 /*
  * Local variables:
  * c-basic-offset: 4
index b7807d9..7299be0 100644 (file)
@@ -944,6 +944,21 @@ int ztest_fetch(void *handle, bend_fetch_rr *r)
             return 0;
         }
     }
+    else if (!oid_oidcmp(oid, yaz_oid_recsyn_json))
+    {
+        if ((cp = dummy_json_record(r->number, r->stream, esn)))
+        {
+            r->len = strlen(cp);
+            r->record = cp;
+            r->schema = "info:srw/schema/1/marcxml-1.1";
+        }
+        else
+        {
+            r->errcode = YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS;
+            r->surrogate_flag = 1;
+            return 0;
+        }
+    }
     else
     {
         char buf[OID_STR_MAX];
index f895df1..d829b77 100644 (file)
@@ -34,6 +34,7 @@
 Z_GenericRecord *dummy_grs_record(int num, ODR o);
 char *dummy_marc_record(int num, ODR odr);
 char *dummy_xml_record(int num, ODR odr, const char *esn);
+char *dummy_json_record(int num, ODR odr, const char *esn);
 Z_OPACRecord *dummy_opac(int num, ODR odr, const char *marc_input);
 
 /*