Permalink
Browse files

select type getFullText and add available

  • Loading branch information...
1 parent c5f9ada commit e14556bebf4526aaf1d5813904be695cde8f32b7 @oucs0130 oucs0130 committed Feb 18, 2011
@@ -18,6 +18,10 @@
public Available() {
}
+ public Available(String service) {
+ this.service=service;
+ }
+
public void addMesage(Message message) {
messages.add(message);
}
@@ -44,6 +44,12 @@ public void addItems(Collection<SearObject> beans) {
item.setHref(library.getURL());
item.setLabel(library.getLabel());
item.setStorage(library.getCollection());
+
+ if (null != library.getAvailableURL()) {
+ Available service = new Available("loan");
+ service.setHref(library.getAvailableURL());
+ item.addAvailableService(service);
+ }
if (null != library.getLibrary()) {
item.setDepartment(new Department(library.getLibrary()));
}
@@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.List;
+import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@@ -76,12 +77,25 @@ public JSONObject toJSON() throws JSONException {
if (null != label) {
json.put("label", label);
}
+
+ JSONArray availableList = new JSONArray();
for (Available service : availableServices) {
- json.put("available", service.toJSON());
+ availableList.put(service.toJSON());
+ }
+
+ if (availableList.length() != 0) {
+ json.put("available", availableList);
}
+
+ JSONArray unavailableList = new JSONArray();
for (UnAvailable service : unAvailableServices) {
- json.put("unavailable", service.toJSON());
+ unavailableList.put(service.toJSON());
}
+
+ if (unavailableList.length() != 0) {
+ json.put("unavailable", unavailableList);
+ }
+
if (null != storage) {
JSONObject storageData = new JSONObject();
storageData.put("content", storage);
@@ -9,7 +9,9 @@
private String label;
private String library;
private String status;
+ private String type;
private String url;
+ private String availableURL;
public SearLibrary() {}
@@ -78,6 +80,14 @@ public void setStatus(String status) {
this.status = status;
}
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
public String getURL() {
return url;
}
@@ -86,6 +96,14 @@ public void setURL(String url) {
this.url = url;
}
+ public String getAvailableURL() {
+ return availableURL;
+ }
+
+ public void setAvailableURL(String url) {
+ this.availableURL = url;
+ }
+
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append("id="+id+":");
@@ -38,9 +38,14 @@ public SFXXMLFilter() {
Collection<SearObject> myBeans = new ArrayList<SearObject>();
for (SearObject bean : beans) {
+ if (!validString(bean.getURL())) {
+ continue;
+ }
+
if (bean instanceof SearLibrary) {
- //SearLibrary library = (SearLibrary)bean;
- if (!validString(bean.getURL())) {
+ SearLibrary library = (SearLibrary)bean;
+
+ if (!"getFullTxt".equals(library.getType())) {
continue;
}
}
@@ -114,6 +119,8 @@ public void endElement(String uri, String localName, String qName)
} else if (localName.equals("target_name")) {
} else if (localName.equals("service_type")) {
+ searLibrary.setType(tempVal.toString());
+
} else if (localName.equals("parser")) {
} else if (localName.equals("parse_param")) {
} else if (localName.equals("proxy")) {
@@ -125,6 +132,7 @@ public void endElement(String uri, String localName, String qName)
} else if (localName.equals("target_url")) {
searLibrary.setURL(tempVal.toString());
+ searLibrary.setAvailableURL(tempVal.toString());
} else if (localName.equals("linktorsrc")) {
SearLink searLink = new SearLink();
@@ -1,11 +1,16 @@
package uk.ac.ox.oucs.sirlouie;
import java.util.Collection;
+import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.json.JSONObject;
+
import junit.framework.Assert;
import junit.framework.TestCase;
+import uk.ac.ox.oucs.sirlouie.daia.Document;
+import uk.ac.ox.oucs.sirlouie.daia.ResponseBean;
import uk.ac.ox.oucs.sirlouie.reply.SearObject;
import uk.ac.ox.oucs.sirlouie.sfx.SFXService;
@@ -469,6 +474,16 @@
+ "</sfx_menu>";
+ private String JSON = "{\"timestamp\":\"2011-02-18T09:42:46+00:00\","
+ + "\"schema\":\"http://ws.gbv.de/daia/\","
+ + "\"document\":[{\"id\":\"id\","
+ + "\"item\":[{\"id\":\"1000000000001224\",\"label\":\"EBSCOhost Business Source Complete\","
+ + "\"available\":[{\"service\":\"loan\","
+ + "\"href\":\"http://ezproxy.ouls.ox.ac.uk:2048/login?url=http://openurl.ebscohost.com/linksvc/linking.aspx?sid=bth&volume=92&date=2009-8&aulast=Rajbhandari&atitle=Chemical+changes+that+predispose+smoked+Cheddar+cheese+to+calcium+lactate+crystallization&spage=3616&issn=0022-0302&stitle=&genre=article&issue=8&auinit=P&aufirst=&epage=3622&title=Journal+of+dairy+science\"}],"
+ + "\"href\":\"http://ezproxy.ouls.ox.ac.uk:2048/login?url=http://openurl.ebscohost.com/linksvc/linking.aspx?sid=bth&volume=92&date=2009-8&aulast=Rajbhandari&atitle=Chemical+changes+that+predispose+smoked+Cheddar+cheese+to+calcium+lactate+crystallization&spage=3616&issn=0022-0302&stitle=&genre=article&issue=8&auinit=P&aufirst=&epage=3622&title=Journal+of+dairy+science\"}],"
+ + "\"href\":\"http://ezproxy.ouls.ox.ac.uk:2048/login?url=http://openurl.ebscohost.com/linksvc/linking.aspx?sid=bth&volume=92&date=2009-8&aulast=Rajbhandari&atitle=Chemical+changes+that+predispose+smoked+Cheddar+cheese+to+calcium+lactate+crystallization&spage=3616&issn=0022-0302&stitle=&genre=article&issue=8&auinit=P&aufirst=&epage=3622&title=Journal+of+dairy+science\"}],"
+ + "\"institution\":{\"content\":\"University of Oxford\",\"href\":\"http://www.ox.ac.uk\"},"
+ + "\"version\":\"0.5\"}";
private String errorXML = "<SEGMENTS xmlns=\"http://www.exlibrisgroup.com/xsd/jaguar/search\">"
+"<JAGROOT>"
@@ -493,7 +508,18 @@ public void testFilterSFXResponse() {
try {
Collection<SearObject> beans =
SFXService.filterResponse(SFX_XML);
- Assert.assertEquals(9, beans.size());
+
+ Assert.assertEquals(1, beans.size());
+
+ Document document = new Document("id", null);
+ document.addItems(beans);
+
+ ResponseBean responseBean = new ResponseBean();
+ responseBean.addDocument(document);
+ JSONObject json = responseBean.toJSON();
+ System.out.println(json.toString());
+
+ Assert.assertEquals(json.toString(), JSON);
} catch (Exception e) {
System.out.println("Exception caught ["+e.getLocalizedMessage()+"]");

0 comments on commit e14556b

Please sign in to comment.