...
 
Commits (9)
......@@ -81,7 +81,7 @@
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jcl</artifactId>
<version>${log4j-jcl-version}</version>
</dependency>
<dependency>
......@@ -144,8 +144,8 @@
<artifactId>txw2</artifactId>
</exclusion>
<exclusion>
<groupId>org.jvnet.staxex</groupId>
<artifactId>stax-ex</artifactId>
<groupId>org.jvnet.staxex</groupId>
<artifactId>stax-ex</artifactId>
</exclusion>
</exclusions>
</dependency>
......@@ -247,11 +247,35 @@
</exclusions>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>${commons-codec.version}</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>${commons-codec.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.maven/maven-artifact -->
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>3.6.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-validator/commons-validator -->
<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
<version>${commons-validator.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
<exclusion>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- mockito used for testing -->
<dependency>
......@@ -268,5 +292,10 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -124,6 +124,12 @@ public abstract class CachableInterface {
}
}
protected final void removeCacheValue(String key) {
if (cache != null) {
cache.removeByQuery(key, getCacheType());
}
}
/**
* @return the cacheType
* @see #cacheType
......
......@@ -333,4 +333,12 @@ public class Drug implements Serializable, TargettingStructure {
}
}
public void addBrandNames(List<String> brandNames) {
this.brandNames.addAll(brandNames);
}
public void addSynonyms(List<String> synonyms) {
this.synonyms.addAll(synonyms);
}
}
\ No newline at end of file
package lcsb.mapviewer.annotation.services;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import lcsb.mapviewer.annotation.cache.GeneralCacheInterface;
import lcsb.mapviewer.annotation.cache.SourceNotAvailable;
import lcsb.mapviewer.annotation.data.Drug;
import lcsb.mapviewer.annotation.data.Target;
import lcsb.mapviewer.annotation.services.annotators.AnnotatorException;
import lcsb.mapviewer.annotation.services.annotators.HgncAnnotator;
import lcsb.mapviewer.annotation.services.dapi.DapiConnectionException;
import lcsb.mapviewer.annotation.services.dapi.DapiConnector;
import lcsb.mapviewer.annotation.services.dapi.dto.*;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.MiriamType;
@Service
public class DrugBankParser extends DrugAnnotation implements IExternalService {
/**
* Prefix used for storing data about drug with name key value.
*/
static final String DRUG_NAME_PREFIX = "drug:";
public static final String DAPI_DATABASE_NAME = "DrugBank";
private static Logger logger = LogManager.getLogger();
private DapiConnector dapiConnector;
private HgncAnnotator hgncAnnotator;
private ChemicalEntityDtoConverter chemicalEntityDtoConverter;
ObjectMapper objectMapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,
false);
@Autowired
public DrugBankParser(DapiConnector dapiConnector, ChemicalEntityDtoConverter chemicalEntityDtoConverter,
HgncAnnotator hgncAnnotator) {
super(DrugBankParser.class);
this.dapiConnector = dapiConnector;
this.chemicalEntityDtoConverter = chemicalEntityDtoConverter;
this.hgncAnnotator = hgncAnnotator;
}
@Override
public Drug findDrug(String drugName) throws DrugSearchException {
try {
String url = dapiConnector.getLatestReleaseUrl(DAPI_DATABASE_NAME);
String content = dapiConnector
.getAuthenticatedContent(
url + "/drugs/?columns=sourceIdentifier&name=" + URLEncoder.encode(drugName, "UTF-8"));
ListChemicalEntityDto result = objectMapper.readValue(content, ListChemicalEntityDto.class);
List<Drug> drugs = fetchDrugs(result);
if (drugs.size() == 0) {
content = dapiConnector
.getAuthenticatedContent(
url + "/drugs/?columns=sourceIdentifier&synonym=" + URLEncoder.encode(drugName, "UTF-8"));
result = objectMapper.readValue(content, ListChemicalEntityDto.class);
drugs = fetchDrugs(result);
} else if (drugs.size() > 1) {
logger.warn("Found more than one drug by name: " + drugName);
}
if (drugs.size() > 0) {
return drugs.get(0);
}
return null;
} catch (DapiConnectionException | IOException e) {
throw new DrugSearchException("Problem with fetching drugbank data", e);
}
}
private List<Drug> fetchDrugs(ListChemicalEntityDto list) throws DapiConnectionException {
List<Drug> result = new ArrayList<>();
for (ChemicalEntityDto entity : list.getContent()) {
Drug drug = getByIdentifier(MiriamType.getMiriamDataFromPrefixIdentifier(entity.getSourceIdentifier()));
if (drug == null) {
logger.warn("Invalid drug identifier: " + entity.getSourceIdentifier());
} else {
result.add(drug);
}
}
return result;
}
private Drug getByIdentifier(MiriamData identifier) throws DapiConnectionException {
String url = dapiConnector.getLatestReleaseUrl(DAPI_DATABASE_NAME);
String content = dapiConnector.getAuthenticatedContent(url + "/drugs/" + identifier.getResource());
try {
ChemicalEntityDto result = objectMapper.readValue(content, ChemicalEntityDto.class);
return chemicalEntityDtoConverter.dtoToDrug(result);
} catch (IOException e) {
throw new DapiConnectionException("Problem with accessing dapi");
}
}
@Override
public List<Drug> getDrugListByTarget(MiriamData target, Collection<MiriamData> organisms)
throws DrugSearchException {
if (target == null) {
return new ArrayList<>();
}
List<MiriamData> targets = new ArrayList<>();
if (target.getDataType().equals(MiriamType.HGNC_SYMBOL)) {
try {
targets.addAll(hgncAnnotator.hgncToUniprot(target));
} catch (AnnotatorException e) {
logger.warn("Problem with converting to uniprot identifier", e);
targets.add(target);
}
} else if (target.getDataType().equals(MiriamType.UNIPROT)) {
targets.add(target);
} else {
throw new InvalidArgumentException(
"Only those identifiers are accepted: " + MiriamType.HGNC_SYMBOL + "," + MiriamType.UNIPROT);
}
try {
String url = dapiConnector.getLatestReleaseUrl(DAPI_DATABASE_NAME);
Map<MiriamData, Drug> result = new HashMap<>();
for (MiriamData t : targets) {
String content = dapiConnector
.getAuthenticatedContent(
url + "/drugs/?size=1000&columns=sourceIdentifier&target_identifier="
+ URLEncoder.encode(t.getPrefixedIdentifier(), "UTF-8"));
ListChemicalEntityDto dto = objectMapper.readValue(content, ListChemicalEntityDto.class);
List<Drug> drugs = fetchDrugs(dto);
for (Drug drug : drugs) {
for (Target drugTarget : drug.getTargets()) {
if (organisms.size() == 0 || organisms.contains(drugTarget.getOrganism())) {
result.put(drug.getSources().get(0), drug);
}
}
}
}
return new ArrayList<>(result.values());
} catch (DapiConnectionException | IOException e) {
throw new DrugSearchException("Problem with accessing DAPI", e);
}
}
@Override
public String refreshCacheQuery(Object query) throws SourceNotAvailable {
String result = null;
try {
if (query instanceof String) {
String name = (String) query;
if (name.startsWith(DRUG_NAME_PREFIX)) {
name = name.substring(DRUG_NAME_PREFIX.length());
result = getDrugSerializer().objectToString(findDrug(name));
} else {
result = super.refreshCacheQuery(query);
}
} else {
result = super.refreshCacheQuery(query);
}
} catch (DrugSearchException e) {
throw new SourceNotAvailable(e);
}
return result;
}
@Override
public ExternalServiceStatus getServiceStatus() {
ExternalServiceStatus status = new ExternalServiceStatus("DrugBank", MiriamType.DRUGBANK.getDbHomepage());
GeneralCacheInterface cacheCopy = getCache();
this.setCache(null);
try {
Drug drug = findDrug("Amantadine");
status.setStatus(ExternalServiceStatusType.OK);
if (drug == null) {
status.setStatus(ExternalServiceStatusType.CHANGED);
}
} catch (Exception e) {
logger.error("DrugBank (DAPI) is down", e);
status.setStatus(ExternalServiceStatusType.DOWN);
}
this.setCache(cacheCopy);
return status;
}
}
......@@ -5,7 +5,6 @@ import org.apache.logging.log4j.Marker;
import lcsb.mapviewer.model.LogMarker;
import lcsb.mapviewer.model.ProjectLogEntryType;
import lcsb.mapviewer.model.map.BioEntity;
import lcsb.mapviewer.modelutils.map.ElementUtils;
/**
* Defines annotation problem with element when there are no annotations for the
......
......@@ -8,7 +8,6 @@ import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.model.LogMarker;
import lcsb.mapviewer.model.ProjectLogEntryType;
import lcsb.mapviewer.model.map.*;
import lcsb.mapviewer.modelutils.map.ElementUtils;
/**
* Defines problem with element annotation when there are some required
......
......@@ -36,7 +36,7 @@ public class EnsemblAnnotator extends ElementAnnotator implements IExternalServi
/**
* Version of the rest API that is supported by this annotator.
*/
static final String SUPPORTED_VERSION = "11.1";
static final String SUPPORTED_VERSION = "11.2";
/**
* Url address of ensembl restful service.
......
package lcsb.mapviewer.annotation.services.dapi;
public class DapiConnectionException extends Exception {
/**
*
*/
private static final long serialVersionUID = 1L;
public DapiConnectionException(String string) {
super(string);
}
public DapiConnectionException(String string, Exception e) {
super(string, e);
}
}
package lcsb.mapviewer.annotation.services.dapi;
public interface DapiConnector {
void login() throws DapiConnectionException;
String getLatestReleaseAvailable(String databaseName) throws DapiConnectionException;
String getLatestReleaseUrl(String databaseName) throws DapiConnectionException;
String getAuthenticatedContent(String string) throws DapiConnectionException;
}
package lcsb.mapviewer.annotation.services.dapi;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.*;
import java.util.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.springframework.stereotype.Service;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.JsonArray;
import com.google.gson.JsonParser;
import lcsb.mapviewer.annotation.cache.CachableInterface;
import lcsb.mapviewer.annotation.services.dapi.dto.ListReleaseDto;
import lcsb.mapviewer.annotation.services.dapi.dto.ReleaseDto;
import lcsb.mapviewer.model.user.ConfigurationElementType;
import lcsb.mapviewer.persist.dao.ConfigurationDao;
@Service
public class DapiConnectorImpl extends CachableInterface implements DapiConnector {
@SuppressWarnings("unused")
private static Logger logger = LogManager.getLogger();
private static final String DAPI_DOMAIN = "dapi.lcsb.uni.lu";
private static final String DAPI_BASE_URL = "http://" + DAPI_DOMAIN + "/api/";
private ConfigurationDao configurationDao;
ObjectMapper objectMapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,
false);
static {
CookieManager cookieManager = new CookieManager();
CookieHandler.setDefault(cookieManager);
}
public DapiConnectorImpl(ConfigurationDao configurationDao) {
super(DapiConnectorImpl.class);
this.configurationDao = configurationDao;
}
@Override
public String getLatestReleaseAvailable(String databaseName) throws DapiConnectionException {
try {
String content = getAuthenticatedContent(DAPI_BASE_URL + "database/" + databaseName + "/releases/?size=1000",
false);
Set<String> releases = new HashSet<>();
ListReleaseDto result = objectMapper.readValue(content, ListReleaseDto.class);
for (ReleaseDto release : result.getContent()) {
releases.add(release.getName());
}
String userDataContent = getAuthenticatedContent(
DAPI_BASE_URL + "users/" + configurationDao.getValueByType(ConfigurationElementType.DAPI_LOGIN), false);
JsonArray array = new JsonParser()
.parse(userDataContent)
.getAsJsonObject()
.get("acceptedReleaseLicenses")
.getAsJsonArray();
Set<String> acceptedReleases = new HashSet<>();
for (int i = 0; i < array.size(); i++) {
String release = array.get(i).getAsJsonObject().get("release").getAsJsonObject().get("name").getAsString();
if (releases.contains(release)) {
acceptedReleases.add(release);
}
}
return getLatestVersion(acceptedReleases);
} catch (IOException e) {
throw new DapiConnectionException("Problem with accessing dapi data", e);
}
}
String getLatestVersion(Collection<String> acceptedReleases) {
List<DefaultArtifactVersion> versions = new ArrayList<>();
for (String string : acceptedReleases) {
versions.add(new DefaultArtifactVersion(string));
}
Collections.sort(versions);
return versions.get(versions.size() - 1).toString();
}
private String getAuthenticatedContent(String string, boolean fromCache) throws DapiConnectionException {
if (!isAuthenticated()) {
login();
}
try {
if (!fromCache) {
super.removeCacheValue(string);
}
return getWebPageContent(string);
} catch (IOException e) {
throw new DapiConnectionException("Problem with accessing dapi data", e);
}
}
@Override
public String getLatestReleaseUrl(String databaseName) throws DapiConnectionException {
return DAPI_BASE_URL + "database/" + databaseName + "/releases/" + getLatestReleaseAvailable(databaseName) + "/";
}
@Override
public String getAuthenticatedContent(String string) throws DapiConnectionException {
return getAuthenticatedContent(string, true);
}
private boolean isAuthenticated() {
boolean authenticated = false;
CookieManager cookieManager = (CookieManager) CookieHandler.getDefault();
for (HttpCookie cookie : cookieManager.getCookieStore().getCookies()) {
if (Objects.equals(cookie.getDomain(), DAPI_DOMAIN) && !cookie.hasExpired()
&& Objects.equals(cookie.getName(), "JSESSIONID")) {
authenticated = true;
}
}
return authenticated;
}
@Override
public void login() throws DapiConnectionException {
try {
String login = configurationDao.getValueByType(ConfigurationElementType.DAPI_LOGIN);
String password = configurationDao.getValueByType(ConfigurationElementType.DAPI_PASSWORD);
login(login, password);
} catch (IOException e) {
CookieManager cookieManager = (CookieManager) CookieHandler.getDefault();
cookieManager.getCookieStore().removeAll();
throw new DapiConnectionException("Problem with connection to DAPI server", e);
}
}
void login(String login, String password)
throws MalformedURLException, IOException, ProtocolException, DapiConnectionException {
String data = "login=" + login + "&password=" + password;
URL url = new URL(DAPI_BASE_URL + "doLogin");
HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
urlConn.addRequestProperty("User-Agent", "minerva-framework");
urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
urlConn.setRequestMethod("POST");
urlConn.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(urlConn.getOutputStream());
wr.writeBytes(data);
wr.close();
urlConn.connect();
int code = urlConn.getResponseCode();
if (code != HttpURLConnection.HTTP_OK) {
throw new DapiConnectionException("Problem with connection to dapi. Login returned status code: " + code);
}
}
}
package lcsb.mapviewer.annotation.services.dapi.dto;
import java.util.ArrayList;
import java.util.List;
public class ChemicalEntityDto {
private String sourceIdentifier;
private String name;
private String description;
private Boolean approved;
private List<ChemicalTargetDto> targets = new ArrayList<>();
private List<String> brandNames = new ArrayList<>();
private List<String> synonyms = new ArrayList<>();
public String getSourceIdentifier() {
return sourceIdentifier;
}
public void setSourceIdentifier(String sourceIdentifier) {
this.sourceIdentifier = sourceIdentifier;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<ChemicalTargetDto> getTargets() {
return targets;
}
public void setTargets(List<ChemicalTargetDto> targets) {
this.targets = targets;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public List<String> getBrandNames() {
return brandNames;
}
public void setBrandNames(List<String> brandNames) {
this.brandNames = brandNames;
}
public List<String> getSynonyms() {
return synonyms;
}
public void setSynonyms(List<String> synonyms) {
this.synonyms = synonyms;
}
public Boolean getApproved() {
return approved;
}
public void setApproved(Boolean approved) {
this.approved = approved;
}
}
package lcsb.mapviewer.annotation.services.dapi.dto;
import org.springframework.stereotype.Service;
import lcsb.mapviewer.annotation.data.Drug;
import lcsb.mapviewer.model.map.MiriamType;
@Service
public class ChemicalEntityDtoConverter {
private ChemicalTargetDtoConverter chemicalTargetDtoConverter;
public ChemicalEntityDtoConverter(ChemicalTargetDtoConverter chemicalTargetDtoConverter) {
this.chemicalTargetDtoConverter = chemicalTargetDtoConverter;
}
public Drug dtoToDrug(ChemicalEntityDto dto) {
Drug result = new Drug();
result.addSource(MiriamType.getMiriamDataFromPrefixIdentifier(dto.getSourceIdentifier()));
result.setName(dto.getName());
if (dto.getDescription() != null && !dto.getDescription().isEmpty()) {
result.setDescription(dto.getDescription());
}
result.addBrandNames(dto.getBrandNames());
result.addSynonyms(dto.getSynonyms());
result.setApproved(dto.getApproved());
for (ChemicalTargetDto target : dto.getTargets()) {
result.addTarget(chemicalTargetDtoConverter.dtoToTarget(target));
}
return result;
}
}
package lcsb.mapviewer.annotation.services.dapi.dto;
import java.util.ArrayList;
import java.util.List;
public class ChemicalTargetDto {
private String name;
private String sourceIdentifier;
private String organism;
private List<String> identifiers = new ArrayList<>();
private List<String> references = new ArrayList<>();
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<String> getIdentifiers() {
return identifiers;
}
public void setIdentifiers(List<String> identifiers) {
this.identifiers = identifiers;
}
public String getSourceIdentifier() {
return sourceIdentifier;
}
public void setSourceIdentifier(String sourceIdentifier) {
this.sourceIdentifier = sourceIdentifier;
}
public String getOrganism() {
return organism;
}
public void setOrganism(String organism) {
this.organism = organism;
}
public List<String> getReferences() {
return references;
}
public void setReferences(List<String> references) {
this.references = references;
}
}
package lcsb.mapviewer.annotation.services.dapi.dto;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;
import lcsb.mapviewer.annotation.data.Target;
import lcsb.mapviewer.annotation.services.annotators.UniprotAnnotator;
import lcsb.mapviewer.annotation.services.annotators.UniprotSearchException;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.MiriamType;
@Service
public class ChemicalTargetDtoConverter {
private static Logger logger = LogManager.getLogger();
private UniprotAnnotator uniprotAnnotator;
public ChemicalTargetDtoConverter(UniprotAnnotator uniprotAnnotator) {
this.uniprotAnnotator = uniprotAnnotator;
}
public Target dtoToTarget(ChemicalTargetDto dto) {
Target result = new Target();
result.setName(dto.getName());
result.setSource(MiriamType.getMiriamDataFromPrefixIdentifier(dto.getSourceIdentifier()));
result.setOrganism(MiriamType.getMiriamDataFromPrefixIdentifier(dto.getOrganism()));
for (String identifier : dto.getIdentifiers()) {
MiriamData md = MiriamType.getMiriamDataFromPrefixIdentifier(identifier);
if (md.getDataType().equals(MiriamType.UNIPROT)) {
try {
MiriamData hgnc = uniprotAnnotator.uniProtToHgnc(md);
if (hgnc == null) {
logger.warn("Cannot find hgnc symbol for uniprot: " + md);
} else {
md = hgnc;
}
} catch (UniprotSearchException e) {
logger.warn("Problem with translating uniprot id: " + md, e);
}
}
result.addGene(md);
}
for (String identifier : dto.getReferences()) {
MiriamData md = MiriamType.getMiriamDataFromPrefixIdentifier(identifier);
result.addReference(md);
}
return result;
}
}
package lcsb.mapviewer.annotation.services.dapi.dto;
import java.util.ArrayList;
import java.util.List;
public class ListChemicalEntityDto {
private List<ChemicalEntityDto> content = new ArrayList<>();
public List<ChemicalEntityDto> getContent() {
return content;
}
public void setContent(List<ChemicalEntityDto> content) {
this.content = content;
}
}
package lcsb.mapviewer.annotation.services.dapi.dto;
import java.util.ArrayList;
import java.util.List;
public class ListReleaseDto {
private List<ReleaseDto> content = new ArrayList<>();
public List<ReleaseDto> getContent() {
return content;
}
public void setContent(List<ReleaseDto> content) {
this.content = content;
}
}
package lcsb.mapviewer.annotation.services.dapi.dto;
public class ReleaseDto {
private int id;
private String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
......@@ -39,22 +39,38 @@ import lcsb.mapviewer.persist.dao.cache.CacheTypeDao;
@RunWith(SpringJUnit4ClassRunner.class)
public abstract class AnnotationTestFunctions extends AbstractTransactionalJUnit4SpringContextTests {
private Logger logger = LogManager.getLogger();
private static Map<String, Model> models = new HashMap<String, Model>();
@Rule
public UnitTestFailedWatcher unitTestFailedWatcher = new UnitTestFailedWatcher();
@Autowired
protected PermanentDatabaseLevelCacheInterface cache;
@Autowired
protected CacheTypeDao cacheTypeDao;
@Autowired
protected DbUtils dbUtils;
private Logger logger = LogManager.getLogger(AnnotationTestFunctions.class);
private MinervaLoggerAppender appender;
private String dapiLogin;
private String dapiPassword;
@Before
public final void _setUp() throws Exception {
MinervaLoggerAppender.unregisterLogEventStorage(appender);
appender = MinervaLoggerAppender.createAppender(false);
dapiLogin = System.getenv("DAPI_TEST_LOGIN");
dapiPassword = System.getenv("DAPI_TEST_PASSWORD");
}
protected boolean isDapiConfigurationAvailable() {
return dapiLogin != null && dapiPassword != null;
}
@After
......@@ -254,4 +270,12 @@ public abstract class AnnotationTestFunctions extends AbstractTransactionalJUnit
throw exception;
}
public String getDapiLogin() {
return dapiLogin;
}
public String getDapiPassword() {
return dapiPassword;
}
}
......@@ -4,10 +4,13 @@ import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.*;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.w3c.dom.Node;
import lcsb.mapviewer.annotation.AnnotationTestFunctions;
......@@ -17,6 +20,9 @@ import lcsb.mapviewer.persist.dao.cache.CacheTypeDao;
public class CachableInterfaceTest extends AnnotationTestFunctions {
Logger logger = LogManager.getLogger(CachableInterfaceTest.class);
@Autowired
private List<CachableInterface> interfaces;
@Before
public void setUp() throws Exception {
}
......@@ -25,6 +31,13 @@ public class CachableInterfaceTest extends AnnotationTestFunctions {
public void tearDown() throws Exception {
}
@Test
public void testImplementationCacheExists() throws Exception {
for (CachableInterface cachableInterface : interfaces) {
assertNotNull(cachableInterface.getCacheType());
}
}
@Test
public void testGetWebPage() throws Exception {
CachableInterfaceMock ci = new CachableInterfaceMock(CachableInterface.class);
......
......@@ -5,16 +5,19 @@ import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
import lcsb.mapviewer.annotation.services.annotators.AllAnnotatorTests;
import lcsb.mapviewer.annotation.services.dapi.AllDapiTests;
import lcsb.mapviewer.annotation.services.genome.AllGenomeTests;
@RunWith(Suite.class)
@SuiteClasses({ AllAnnotatorTests.class,
AllDapiTests.class,
AllGenomeTests.class,
ChEMBLParserTest.class,
ChemicalParserTest.class,
ChemicalSearchExceptionTest.class,
DrugAnnotationTest.class,
DrugbankHTMLParserTest.class,
DrugbankParserTest.class,
DrugbankParserErrorHandlingTest.class,
ExternalServiceStatusTest.class,
ExternalServiceStatusTypeTest.class,
ImproperAnnotationsTest.class,
......
......@@ -2,23 +2,21 @@ package lcsb.mapviewer.annotation.services;
import static org.junit.Assert.assertEquals;
import java.util.Collection;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ActiveProfiles;
import lcsb.mapviewer.annotation.AnnotationTestFunctions;
import lcsb.mapviewer.annotation.data.Drug;
import lcsb.mapviewer.model.map.MiriamData;
@ActiveProfiles("drugBankTestProfile")
public class DrugAnnotationTest extends AnnotationTestFunctions {
Logger logger = LogManager.getLogger(DrugAnnotationTest.class);
Logger logger = LogManager.getLogger();
@Autowired
private DrugbankHTMLParser drugBankHTMLParser;
private DrugBankParser drugBankParser;
@Before
public void setUp() throws Exception {
......@@ -30,25 +28,12 @@ public class DrugAnnotationTest extends AnnotationTestFunctions {
@Test
public void testXmlSerialization() throws Exception {
DrugAnnotation drugAnnotation = new DrugAnnotation(DrugAnnotation.class) {
@Override
public Drug findDrug(String name) {
// TODO Auto-generated method stub
return null;
}
@Override
public List<Drug> getDrugListByTarget(MiriamData target, Collection<MiriamData> organisms) {
// TODO Auto-generated method stub
return null;
}
};
Drug drug = drugBankHTMLParser.findDrug("aspirin");
Drug drug = drugBankParser.findDrug("Aspirin");
String xml = drugAnnotation.getDrugSerializer().objectToString(drug);
String xml = drugBankParser.getDrugSerializer().objectToString(drug);
Drug drug2 = drugAnnotation.getDrugSerializer().xmlToObject(getNodeFromXmlString(xml));
Drug drug2 = drugBankParser.getDrugSerializer().xmlToObject(getNodeFromXmlString(xml));
assertEquals(drug.getTargets().size(), drug2.getTargets().size());
assertEquals(drug.getTargets().get(0).getGenes().size(), drug2.getTargets().get(0).getGenes().size());
......
package lcsb.mapviewer.annotation.services;
import static org.junit.Assert.assertEquals;
import static org.junit.Assume.assumeTrue;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ActiveProfiles;
import lcsb.mapviewer.annotation.AnnotationTestFunctions;
import lcsb.mapviewer.annotation.cache.GeneralCacheInterface;
import lcsb.mapviewer.annotation.cache.SourceNotAvailable;
@ActiveProfiles("dapiDownTestProfile")
public class DrugbankParserErrorHandlingTest extends AnnotationTestFunctions {
Logger logger = LogManager.getLogger();
@Autowired
private DrugBankParser drugBankParser;
@Before
public void setUp() {
assumeTrue("DAPI credentials are not provided", isDapiConfigurationAvailable());
}
@Test(expected = SourceNotAvailable.class)
public void testRefreshCacheQueryWhenDbNotAvailable() throws Exception {
GeneralCacheInterface cache = drugBankParser.getCache();
try {
drugBankParser.setCache(null);
drugBankParser.refreshCacheQuery(DrugBankParser.DRUG_NAME_PREFIX + "aspirin");
} finally {
drugBankParser.setCache(cache);
}
}
@Test
public void testSimulateDownStatus() throws Exception {
assertEquals(ExternalServiceStatusType.DOWN, drugBankParser.getServiceStatus().getStatus());
}
}
......@@ -24,16 +24,10 @@ import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.MiriamType;
public class MeSHParserTest extends AnnotationTestFunctions {
Logger logger = LogManager.getLogger(MeSHParserTest.class);
Logger logger = LogManager.getLogger();
@Autowired
MeSHParser meshParser;
@Autowired
private PermanentDatabaseLevelCacheInterface permanentDatabaseLevelCache;
@Autowired
private GeneralCacheInterface cache;
private MeSHParser meshParser;
@Test
public void testGetMesh() throws Exception {
......
......@@ -13,7 +13,8 @@ import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import lcsb.mapviewer.annotation.AnnotationTestFunctions;
import lcsb.mapviewer.annotation.cache.*;
import lcsb.mapviewer.annotation.cache.GeneralCacheInterface;
import lcsb.mapviewer.annotation.cache.SourceNotAvailable;
import lcsb.mapviewer.annotation.data.MiRNA;
import lcsb.mapviewer.annotation.data.Target;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
......@@ -23,13 +24,10 @@ import lcsb.mapviewer.model.map.MiriamType;
import lcsb.mapviewer.model.map.model.Model;
public class MiRNAParserTest extends AnnotationTestFunctions {
Logger logger = LogManager.getLogger(MiRNAParserTest.class);
Logger logger = LogManager.getLogger();
@Autowired
MiRNAParser miRNAParser;
@Autowired
private PermanentDatabaseLevelCacheInterface permanentDatabaseLevelCache;
private MiRNAParser miRNAParser;
@Before
public void setUp() throws Exception {
......
package lcsb.mapviewer.annotation.services.dapi;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({ DapiConnectorTest.class,
DapiConnectorImplTest.class })
public class AllDapiTests {
}
package lcsb.mapviewer.annotation.services.dapi;
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
import org.junit.Test;
public class DapiConnectorImplTest {
@Test
public void test() throws DapiConnectionException {
DapiConnectorImpl connector = new DapiConnectorImpl(null);
String version = connector.getLatestVersion(Arrays.asList("2.2", "3.3", "11.2", "10"));
assertEquals("11.2", version);
}
}
package lcsb.mapviewer.annotation.services.dapi;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;
import org.apache.commons.validator.routines.UrlValidator;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.Rollback;
import lcsb.mapviewer.annotation.AnnotationTestFunctions;
import lcsb.mapviewer.annotation.services.DrugBankParser;
import lcsb.mapviewer.model.user.ConfigurationElementType;
import lcsb.mapviewer.model.user.ConfigurationOption;
import lcsb.mapviewer.persist.dao.ConfigurationDao;
@Rollback(true)
public class DapiConnectorTest extends AnnotationTestFunctions {
@Autowired
DapiConnector dapiConnector;
@Autowired
ConfigurationDao configurationDao;
@Before
public void setUp() {
assumeTrue("DAPI credentials are not provided", isDapiConfigurationAvailable());
ConfigurationOption option = configurationDao.getByType(ConfigurationElementType.DAPI_LOGIN);
if (option == null) {
option = new ConfigurationOption();
option.setType(ConfigurationElementType.DAPI_LOGIN);
configurationDao.add(option);
}
option.setValue(getDapiLogin());
configurationDao.update(option);
option = configurationDao.getByType(ConfigurationElementType.DAPI_PASSWORD);
if (option == null) {
option = new ConfigurationOption();
option.setType(ConfigurationElementType.DAPI_PASSWORD);
configurationDao.add(option);
}
option.setValue(getDapiPassword());
configurationDao.update(option);
}
@Test
public void testLogin() throws DapiConnectionException {
dapiConnector.login();
}
@Test
public void testGetLatestReleaseAvailable() throws DapiConnectionException {
String version = dapiConnector.getLatestReleaseAvailable(DrugBankParser.DAPI_DATABASE_NAME);
assertNotNull(version);
}
@Test
public void testGetLatestReleaseUrl() throws DapiConnectionException {
String url = dapiConnector.getLatestReleaseUrl(DrugBankParser.DAPI_DATABASE_NAME);
assertTrue(UrlValidator.getInstance().isValid(url));
}
}
package lcsb.mapviewer.annotation.services.dapi;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.*;
@Profile("drugBankTestProfile")
@Configuration
public class DrugBankDapiConfiguration {
@Autowired
DapiConnector dapiConnector;
private String dapiLogin;
private String dapiPassword;
public DrugBankDapiConfiguration() {
dapiLogin = System.getenv("DAPI_TEST_LOGIN");
dapiPassword = System.getenv("DAPI_TEST_PASSWORD");
}
@Bean
@Primary
public DapiConnector dapiConnector() throws DapiConnectionException {
DapiConnectorImpl mock = (DapiConnectorImpl) Mockito.spy(dapiConnector);
Mockito.doReturn("http://dapi.lcsb.uni.lu/api/database/DrugBank/releases/5.1/").when(mock)
.getLatestReleaseUrl("DrugBank");
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock arg0) throws Throwable {
mock.login(dapiLogin, dapiPassword);
return null;
}
}).when(mock).login();
return mock;
}
}
package lcsb.mapviewer.annotation.services.dapi;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;
import org.mockito.Mockito;
import org.springframework.context.annotation.*;
@Profile("dapiDownTestProfile")
@Configuration
public class DrugBankDapiInavailableConfiguration {
@Bean
@Primary
public DapiConnector dapiConnector() throws DapiConnectionException {
DapiConnector mock = Mockito.mock(DapiConnector.class);
when(mock.getAuthenticatedContent(anyString()))
.thenThrow(new DapiConnectionException("Simulated connection problem"));
Mockito.doThrow(new DapiConnectionException("Simulated connection problem")).when(mock).login();
return mock;
}
}
package lcsb.mapviewer.converter.model.celldesigner;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.geom.Dimension2D;
import java.awt.geom.Point2D;
......
package lcsb.mapviewer.converter.model.celldesigner.structure.fields;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.geom.Dimension2D;
import java.awt.geom.Point2D;
......
package lcsb.mapviewer.converter.model.celldesigner.compartment;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
......@@ -122,6 +121,7 @@ public class CompartmentParserTests extends CellDesignerTestFunctions {
public void testOldCellDesignerCompartment() throws Exception {
Model model = getModelForFile("testFiles/compartment/old_compartment.xml");
Compartment c = model.getElementByElementId("ca1");
assertNotNull(c);
assertEquals(1, model.getElements().size());
}
......
......@@ -2,11 +2,10 @@ package lcsb.mapviewer.converter.model.celldesigner.reaction;
import static org.junit.Assert.*;
import java.awt.*;
import java.awt.Color;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.util.*;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
......@@ -28,6 +27,7 @@ public class ReactionParserTests extends CellDesignerTestFunctions {
ReactionXmlParser parser;
CellDesignerElementCollection elements;
@SuppressWarnings("unused")
private Logger logger = LogManager.getLogger();
@Before
......
......@@ -22,8 +22,6 @@ import lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser;
import lcsb.mapviewer.model.map.Drawable;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.model.ModelComparator;
import lcsb.mapviewer.model.map.reaction.AbstractNode;
import lcsb.mapviewer.model.map.reaction.Reaction;
import lcsb.mapviewer.model.map.species.Species;
@RunWith(Parameterized.class)
......
package lcsb.mapviewer.converter.model.sbml;
import java.io.IOException;
import java.util.*;
import org.apache.logging.log4j.LogManager;
......@@ -10,9 +9,7 @@ import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import lcsb.mapviewer.commands.CommandExecutionException;
import lcsb.mapviewer.commands.layout.ApplySimpleLayoutModelCommand;
import lcsb.mapviewer.converter.ConverterParams;
import lcsb.mapviewer.converter.ZIndexPopulator;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.model.ModelFullIndexed;
......
......@@ -9,7 +9,6 @@ import java.nio.file.*;
import java.util.ArrayList;
import java.util.Collection;
import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.Test;
......@@ -65,7 +64,7 @@ public class GenericSbmlToXmlParserTest extends SbmlTestFunctions {
String xml = converter.model2String(model);
InputStream stream = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8));
Model model2 = converter.createModel(new ConverterParams().inputStream(stream).sizeAutoAdjust(false));
model.setName(null);
......
......@@ -297,4 +297,17 @@ public class MiriamData implements Comparable<MiriamData>, Serializable {
public void setAnnotator(Class<?> annotator) {
this.annotator = annotator;
}
/**
* Returns identifier in the new identifiers.org format.
*
* @return
*/
public String getPrefixedIdentifier() {
String prefix = "null";
if (getDataType() != null && getDataType().getNamespace() != null) {
prefix = getDataType().getNamespace();
}
return prefix + ":" + getResource();
}
}
......@@ -981,6 +981,24 @@ public enum MiriamType {
throw new InvalidArgumentException("Unknown miriam type: " + type + " (id: " + id + ")");
}
public static MiriamData getMiriamDataFromPrefixIdentifier(String generalIdentifier) {
if (generalIdentifier == null) {
return null;
}
int index = generalIdentifier.indexOf(":");
if (index < 0) {
throw new InvalidArgumentException("Identifier doesn't contain type");
}
String type = generalIdentifier.substring(0, index);
String id = generalIdentifier.substring(index + 1);
for (MiriamType mt : MiriamType.values()) {
if (mt.getNamespace().equalsIgnoreCase(type)) {
return new MiriamData(MiriamRelationType.BQ_BIOL_IS_DESCRIBED_BY, mt, id);
}
}
throw new InvalidArgumentException("Unknown miriam type: " + type + " (id: " + id + ")");
}
/**
* Creates {@link MiriamData} from miriam uri.
*
......
......@@ -16,6 +16,7 @@ import lcsb.mapviewer.common.comparator.*;
*/
public class LayerTextComparator extends Comparator<LayerText> {
@SuppressWarnings("unused")
private Logger logger = LogManager.getLogger();
/**
......
......@@ -10,7 +10,6 @@ import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.model.map.species.field.StructuralState;
/**
* Class that represents complex in the model. Complex elements contain
......
......@@ -352,6 +352,12 @@ public enum ConfigurationElementType {
MAX_NUMBER_OF_MAP_LEVELS("Max number of map zoom levels", "10", ConfigurationElementEditType.INTEGER, false,
ConfigurationElementTypeGroup.POINT_AND_CLICK),
DAPI_LOGIN("Login to Data-API system", "", ConfigurationElementEditType.STRING, false,
ConfigurationElementTypeGroup.DAPI),
DAPI_PASSWORD("Login to Data-API system", "", ConfigurationElementEditType.PASSWORD, false,
ConfigurationElementTypeGroup.DAPI),
;
/**
......
......@@ -9,6 +9,7 @@ public enum ConfigurationElementTypeGroup {
SERVER_CONFIGURATION("Server configuration"),
LDAP_CONFIGURATION("LDAP configuration"),
SEARCH_VISIBLE_PARAMETERS("Search panel options"),
DAPI("Data-API configuration"),
;
private String commonName;
......
......@@ -14,7 +14,6 @@ import org.xml.sax.SAXException;
import lcsb.mapviewer.common.XmlParser;
import lcsb.mapviewer.common.exception.InvalidStateException;
import lcsb.mapviewer.common.exception.InvalidXmlSchemaException;
import lcsb.mapviewer.common.geometry.LineTransformation;
import lcsb.mapviewer.converter.ConverterException;
import lcsb.mapviewer.converter.model.celldesigner.geometry.helper.PolylineDataFactory;
import lcsb.mapviewer.model.graphics.PolylineData;
......
......@@ -6,7 +6,6 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.model.LogMarker;
import lcsb.mapviewer.model.ProjectLogEntryType;
......