use of org.obiba.opal.rest.client.magma.RestDatasource in project mica2 by obiba.
the class OpalService method getDatasource.
/**
* Get the datasource from the provided Opal server url.
*
* @param opalUrl if null, default Opal server url will be used.
* @param project
* @return
*/
public synchronized RestDatasource getDatasource(@Nullable String opalUrl, String project) {
final String projectUrl = getOpalProjectUrl(opalUrl, project);
opalUrl = Strings.isNullOrEmpty(opalUrl) ? getDefaultOpal() : opalUrl;
OpalCredential opalCredential = getOpalCredential(opalUrl);
if (cachedDatasources.containsKey(projectUrl)) {
Pair<OpalCredential, RestDatasource> p = cachedDatasources.get(projectUrl);
if (p.getKey().equals(opalCredential)) {
log.debug("Using cached rest datasource to " + projectUrl);
return p.getValue();
}
log.debug("Opal credential changed, evicting rest datasource for " + projectUrl);
// opal credential changed
cachedDatasources.remove(projectUrl);
}
RestDatasource datasource = createRestDatasource(opalCredential, projectUrl, opalUrl, project);
Initialisables.initialise(datasource);
cachedDatasources.put(projectUrl, Pair.create(opalCredential, datasource));
log.debug("Initialized rest datasource for " + projectUrl);
return datasource;
}
use of org.obiba.opal.rest.client.magma.RestDatasource in project mica2 by obiba.
the class CollectedDatasetServiceTest method testDatasourceConnectionErrorIsIgnoredForDraft.
@Test
public void testDatasourceConnectionErrorIsIgnoredForDraft() {
RestDatasource r = mock(RestDatasource.class);
when(r.getValueTable(anyString())).thenThrow(new MagmaRuntimeException());
when(opalService.getDatasource(anyString(), anyString())).thenReturn(r);
when(individualStudyService.findDraft(anyString())).thenReturn(study);
when(studyDatasetStateRepository.findOne(anyString())).thenReturn(state);
collectedDatasetService.save(dataset);
}
Aggregations