Search in sources :

Example 1 with RestDatasource

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;
}
Also used : RestDatasource(org.obiba.opal.rest.client.magma.RestDatasource) OpalCredential(org.obiba.mica.micaConfig.domain.OpalCredential)

Example 2 with RestDatasource

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);
}
Also used : RestDatasource(org.obiba.opal.rest.client.magma.RestDatasource) MagmaRuntimeException(org.obiba.magma.MagmaRuntimeException) Test(org.junit.Test)

Aggregations

RestDatasource (org.obiba.opal.rest.client.magma.RestDatasource)2 Test (org.junit.Test)1 MagmaRuntimeException (org.obiba.magma.MagmaRuntimeException)1 OpalCredential (org.obiba.mica.micaConfig.domain.OpalCredential)1