Skip to content
Snippets Groups Projects
Commit 9c17c4cc authored by Piotr Gawron's avatar Piotr Gawron
Browse files

old unused code removed

parent 62aba8c8
No related branches found
No related tags found
1 merge request!773Resolve "move from log4j to log4j2"
package lcsb.mapviewer.annotation.services;
import java.io.IOException;
import java.util.Map;
import org.apache.http.HttpStatus;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.hibernate.AnnotationException;
import org.springframework.stereotype.Service;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
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.XmlParser;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.MiriamRelationType;
......@@ -31,18 +27,6 @@ import lcsb.mapviewer.model.map.MiriamType;
*/
@Service
public final class MiriamConnector extends CachableInterface implements IExternalService {
/**
* String used to distinguish cached data for links.
*/
static final String LINK_DB_PREFIX = "Link: ";
/**
* String describing invalid miriam entries that will be put into db (instead of
* null).
*/
private static final String INVALID_LINK = "INVALID";
/**
* Default class logger.
*/
......@@ -68,14 +52,6 @@ public final class MiriamConnector extends CachableInterface implements IExterna
} else if (miriamData.getDataType().getUris().size() == 0) {
throw new InvalidArgumentException("Url for " + miriamData.getDataType() + " cannot be retreived.");
}
String query = LINK_DB_PREFIX + miriamData.getDataType().getUris().get(0) + "\n" + miriamData.getResource();
String result = getCacheValue(query);
if (result != null) {
if (INVALID_LINK.equals(result)) {
return null;
}
return result;
}
String id;
if (miriamData.getDataType().getNamespace().isEmpty()) {
id = miriamData.getResource();
......@@ -83,14 +59,18 @@ public final class MiriamConnector extends CachableInterface implements IExterna
id = miriamData.getDataType().getNamespace() + ":" + miriamData.getResource();
}
query = "https://identifiers.org/rest/identifiers/validate/" + id;
String page;
String query = "https://identifiers.org/rest/identifiers/validate/" + id;
try {
page = getWebPageContent(query);
String page = getWebPageContent(query);
Gson gson = new Gson();
Map<?, ?> map = gson.fromJson(page, Map.class);
return (String) map.get("url");
} catch (WrongResponseCodeIOException e) {
if (HttpStatus.SC_NOT_FOUND == e.getResponseCode()) {
return null;
} else {
throw new AnnotationException("Problem with accessing identifiers.org", e);
}
} catch (Exception e) {
throw new AnnotationException("Problem with accessing identifiers.org", e);
}
......@@ -135,36 +115,6 @@ public final class MiriamConnector extends CachableInterface implements IExterna
}
}
@Override
public String refreshCacheQuery(Object query) throws SourceNotAvailable {
String result = null;
if (query instanceof String) {
String name = (String) query;
if (name.startsWith(LINK_DB_PREFIX)) {
String tmp = name.substring(LINK_DB_PREFIX.length());
String[] rows = tmp.split("\n");
if (rows.length != 2) {
throw new InvalidArgumentException("Miriam link query is invalid: " + query);
}
MiriamType dataType = MiriamType.getTypeByUri(rows[0]);
String resource = rows[1];
result = getUrlString(new MiriamData(MiriamRelationType.BQ_BIOL_IS_DESCRIBED_BY, dataType, resource));
} else if (name.startsWith("http")) {
try {
result = getWebPageContent(name);
} catch (IOException e) {
throw new SourceNotAvailable(e);
}
} else {
throw new InvalidArgumentException("Don't know what to do with string \"" + query + "\"");
}
} else {
throw new InvalidArgumentException("Don't know what to do with class: " + query.getClass());
}
return result;
}
/**
* Checks if {@link MiriamType} is valid.
*
......
......@@ -14,7 +14,6 @@ import java.io.IOException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.hibernate.AnnotationException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
......@@ -146,30 +145,6 @@ public class MiriamConnectorTest extends AnnotationTestFunctions {
}
}
@Test
public void testRefresh2() throws Exception {
MiriamData md = TaxonomyBackend.HUMAN_TAXONOMY;
String query = MiriamConnector.LINK_DB_PREFIX + md.getDataType().getUris().get(0) + "\n" + md.getResource();
try {
String res = miriamConnector.refreshCacheQuery(query);
assertNotNull(res);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testRefresh3() throws Exception {
try {
String res = miriamConnector.refreshCacheQuery("https://www.google.pl/");
assertNotNull(res);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testGetUrlForDoi() throws Exception {
try {
......@@ -241,19 +216,6 @@ public class MiriamConnectorTest extends AnnotationTestFunctions {
}
}
@Test
public void testRefreshInvalidCacheQuery3() throws Exception {
try {
miriamConnector.refreshCacheQuery(MiriamConnector.LINK_DB_PREFIX);
fail("Exception expected");
} catch (InvalidArgumentException e) {
assertTrue(e.getMessage().contains("Miriam link query is invalid"));
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testCheckValidyOfUnknownMiriamType() throws Exception {
try {
......
delete from cache_query_table where query like 'Link:%';
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment