Commit e5aaec92 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

switching to default format of rest api (json)

parent 9da84f54
package lcsb.mapviewer.annotation.services;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import org.hibernate.AnnotationException;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import com.google.gson.Gson;
import lcsb.mapviewer.annotation.cache.CachableInterface;
import lcsb.mapviewer.annotation.cache.GeneralCacheInterface;
import lcsb.mapviewer.annotation.cache.SourceNotAvailable;
import lcsb.mapviewer.annotation.cache.WebPageDownloader;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.common.exception.InvalidXmlSchemaException;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.MiriamRelationType;
import lcsb.mapviewer.model.map.MiriamType;
......@@ -219,26 +220,20 @@ public final class MiriamConnector extends CachableInterface implements IExterna
protected String getUrlString2(MiriamData md) throws AnnotationException {
try {
String result = null;
String uri = md.getDataType().getUris().get(0) + ":" + md.getResource();
String query = "https://www.ebi.ac.uk/miriamws/main/rest/resolve/" + uri;
String page;
page = getWebPageContent(query);
Document document = getXmlDocumentFromString(page);
Node uris = document.getFirstChild();
NodeList nodes = uris.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
if (Node.ELEMENT_NODE == node.getNodeType()) {
if (getNodeAttr("deprecated", node).equals("")) {
result = node.getTextContent();
}
}
}
String queryUri = md.getDataType().getUris().get(0) + ":" + md.getResource();
String query = "https://www.ebi.ac.uk/miriamws/main/rest/resolve/" + queryUri;
String page = getWebPageContent(query);
Gson gson = new Gson();
Map<?, ?> gsonObject = new HashMap<String, Object>();
gsonObject = (Map<?, ?>) gson.fromJson(page, gsonObject.getClass());
Object uris = gsonObject.get("uri");
Map<?, ?> entry = (Map<?, ?>) ((List<?>) uris).get(0);
result = (String) entry.get("$");
return result;
} catch (IOException e) {
} catch (Exception e) {
throw new AnnotationException("Problem with accessing miriam REST API", e);
} catch (InvalidXmlSchemaException e) {
throw new AnnotationException("Problem with parsing miriam REST API response", e);
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment