[HepData-svn] r1853 - trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Mon Mar 30 17:18:28 BST 2015


Author: whalley
Date: Mon Mar 30 17:18:28 2015
New Revision: 1853

Log:
more fixes and addtions

Modified:
   trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/JsonFormatter.java

Modified: trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/JsonFormatter.java
==============================================================================
--- trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/JsonFormatter.java	Mon Mar 30 12:40:49 2015	(r1852)
+++ trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/JsonFormatter.java	Mon Mar 30 17:18:28 2015	(r1853)
@@ -23,9 +23,13 @@
         String s4="    ";
         if(p == null) return null;
         s.append("{\n");
- 
+        
+// _headerXML contains all the bibliographic type stuff at the beginning
+  
         s.append(_headerXML(p));
 
+// here we deal with the extra resource are description/line files
+
         String[] descs = { "description1" , "description2" , "description3" , "description4" };
         String[] links = { "link1" , "link2" , "link3" , "link4" };
         String[] ids = new String[3];
@@ -60,6 +64,9 @@
             }
         }
 
+
+// next the insert.html file in the resource area
+
         for (int j=0; j<ids.length; j++){
             String insertfile = "/home/hepdata/resource/" +ids[j] + "/insert.html";
             File testinsert = new File(insertfile);
@@ -68,21 +75,25 @@
                 s.append(s4+"\"inserthtml\": \"/resource/"+ids[j]+"/insert.html\"\n");
             }
         }
+
+// and now the datasets
      
         for (Dataset ds : p.getDatasets()){
-            if(ds.getId() == 1) { 
-                s.append(s4+"\"datasets\": [\n");
-            }
-            s.append(_metadataXML(ds));
-            if(ds.getId() == p.getDatasets().size()) { 
-                s.append(s4+"}]\n");
+            if(ds.getId() == 1) {  s.append(s4+"\"datasets\": [\n"); } // first dataset, start the array
+
+            s.append(_metadataXML(ds));  // dataset information in _metadataXML
+
+            if(ds.getId() == p.getDatasets().size()) {
+                s.append(s4+"}]\n");     // last dataset  (end the array)
             } else {
-                s.append(s4+"},\n");
+                s.append(s4+"},\n");     // intermediate datasets (comma separates objects)
             } 
         }
  
+// finally finish off (at present does nothing!
         s.append(_footerXML());
  
+// then  write it all out.
         s.append("}\n");
         return s.toString();
     }
@@ -98,9 +109,53 @@
         String s4="    ";
         StringBuffer s = new StringBuffer();
         s.append(s4+"\"inspireid\": \""+p.getInspireId()+"\",\n");
+        if(p.getSpiresId()!=null) { s.append(s4+"\"spires\": \""+p.getSpiresId()+"\",\n"); }
         if(p.getArchive()!=null) { s.append(s4+"\"archive\": \""+p.getArchive().replaceAll("ARXIV","arXiv")+"\",\n"); }
+        if(p.getRedId()!=null) { s.append(s4+"\"durham\": \""+p.getRedId()+"\",\n"); }
+        if(p.getCdsId()!=null) { s.append(s4+"\"cds\": \""+p.getCdsId()+"\",\n"); }
         s.append(s4+"\"dateupdated\": \""+p.getDateUpdated()+"\",\n");
+        if(p.getTitle()!=null) { s.append(s4+"\"title\": \""+p.getTitle()+"\",\n"); }
+        if(p.getAuthors().size()>0){
+            int count=0;
+            s.append(s4+"\"authors\": [\n");
+            for (String author : p.getAuthors()){
+                count++;
+                s.append(s4+s4+"{\"author\": \""+author+"\"}");
+                if(count < p.getAuthors().size()) {s.append(",");}
+                s.append("\n");
+            }
+            s.append(s4+"],\n");
+        }
+        if(p.getReferences().size()>0){
+            int count=0;
+            s.append(s4+"\"references\": [\n");
+            for (Reference r : p.getReferences()){
+                count++;
+                s.append(s4+s4+"{\"description\": \""+r.getDescription()+"\", ");
+                s.append("\"date\": \""+r.getDate()+"\", ");
+                s.append("\"type\": \""+r.getType()+"\"}");
+                if(count < p.getReferences().size()) {s.append(",");}
+                s.append("\n");
+            }
+            s.append(s4+"],\n");
+        }
+        if(p.getModifications().size()>0){
+            int count=0;
+            s.append(s4+"\"modifications\": [\n");
+            for (Modification m : p.getModifications()){
+                count++;
+                s.append(s4+s4+"{\"action\": \""+m.getAction()+"\", ");
+                s.append("\"modifier\": \""+m.getModifier()+"\", ");
+                s.append("\"date\": \""+m.getComment()+"\"}");
+                if(count < p.getModifications().size()) {s.append(",");}
+                s.append("\n");
+            }
+            s.append(s4+"],\n");
+        }
+
+
         s.append(s4+"\"collaboration\": \""+p.getInformalName()+"\",\n");
+        s.append(s4+"\"experiment\": \""+p.getExperimentName()+"\",\n");
         for (String comment : p.getComments()){ 
              s.append("    \"comment\": \""+comment+"\",\n");
         }
@@ -149,7 +204,7 @@
             s.append(s4+s4+s4+"\"bins\": [\n");
              for (Bin bin : xax.getBins()){
                 s.append(s4+s4+s4+s4+"{\"id\": \""+bin.getId()+"\", ");
-                if(bin.getDescription() != null ) { s.append("\"description\": \""+bin.getDescription()+"\", \n"); }
+                if(bin.getDescription() != null ) { s.append("\"description\": \""+bin.getDescription()+"\", "); }
                 s.append("\"relation\": \""+bin.getRelation()+"\", ");
                 s.append("\"focus\": \""+bin.getFocus()+"\", ");
                 s.append("\"high\": \""+bin.getHighValue()+"\", ");
@@ -192,7 +247,8 @@
                         s.append("{\"plus\": \""+error.getPlus()+"\", ");
                         s.append("\"minus\": \""+error.getMinus()+"\", ");
                         s.append("\"norm\": \""+error.getNormType()+"\", ");
-                        s.append("\"type\": \""+error.getSourceType()+"\"}");
+                        s.append("\"type\": \""+error.getSourceType()+"\", ");
+                        s.append("\"comment\": \""+error.getComment()+"\"}");
                         if(error.getId() < point.getErrors().size()) {
                             s.append(",\n");
                         } else {


More information about the HepData-svn mailing list