-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#4376 WIP. StudyTableSource interface added. New property sourceURN r…
…eplaces opal project/table in dataset's study tables and variables. Requires ES index config update.
- Loading branch information
Showing
43 changed files
with
704 additions
and
714 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 0 additions & 88 deletions
88
mica-core/src/main/java/org/obiba/mica/core/domain/OpalTable.java
This file was deleted.
Oops, something went wrong.
113 changes: 113 additions & 0 deletions
113
mica-core/src/main/java/org/obiba/mica/core/domain/OpalTableSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
* Copyright (c) 2022 OBiBa. All rights reserved. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the GNU Public License v3.0. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.obiba.mica.core.domain; | ||
|
||
import com.google.common.base.Strings; | ||
import org.obiba.magma.ValueTable; | ||
import org.obiba.mica.micaConfig.service.OpalService; | ||
import org.obiba.mica.spi.dataset.StudyTableSource; | ||
import org.obiba.opal.rest.client.magma.RestDatasource; | ||
import org.obiba.opal.rest.client.magma.RestValueTable; | ||
import org.obiba.opal.web.model.Math; | ||
import org.obiba.opal.web.model.Search; | ||
|
||
import javax.validation.constraints.NotNull; | ||
|
||
/** | ||
* Connector to an Opal server, to retrieve value table and summary statistics. | ||
*/ | ||
public class OpalTableSource implements StudyTableSource { | ||
|
||
private OpalService opalService; | ||
|
||
private String opalUrl; | ||
|
||
@NotNull | ||
private String project; | ||
|
||
@NotNull | ||
private String table; | ||
|
||
public String getProject() { | ||
return project; | ||
} | ||
|
||
public void setProject(String project) { | ||
this.project = project; | ||
} | ||
|
||
public String getTable() { | ||
return table; | ||
} | ||
|
||
public void setTable(String table) { | ||
this.table = table; | ||
} | ||
|
||
@Override | ||
public ValueTable getValueTable() { | ||
return getDatasource().getValueTable(table); | ||
} | ||
|
||
@Override | ||
public Search.QueryResultDto getFacets(Search.QueryTermsDto query) { | ||
return getRestValueTable().getFacets(query); | ||
} | ||
|
||
@Override | ||
public Math.SummaryStatisticsDto getVariableSummary(String variableName) { | ||
return ((RestValueTable.RestVariableValueSource)getRestValueTable().getVariableValueSource(variableName)).getSummary(); | ||
} | ||
|
||
@Override | ||
public String getURN() { | ||
return String.format("urn:opal:%s.%s", project, table); | ||
} | ||
|
||
public static boolean isFor(String sourceURN) { | ||
return !Strings.isNullOrEmpty(sourceURN) && sourceURN.startsWith("urn:opal:"); | ||
} | ||
|
||
public static OpalTableSource newSource(String project, String table) { | ||
OpalTableSource source = new OpalTableSource(); | ||
source.setProject(project); | ||
source.setTable(table); | ||
return source; | ||
} | ||
|
||
public static OpalTableSource fromURN(String sourceURN) { | ||
if (Strings.isNullOrEmpty(sourceURN) || !sourceURN.startsWith("urn:opal:")) | ||
throw new IllegalArgumentException("Not a valid Opal table source URN: " + sourceURN); | ||
|
||
String fullName = toTableName(sourceURN); | ||
int sep = fullName.indexOf("."); | ||
String project = fullName.substring(0, sep); | ||
String table = fullName.substring(sep + 1); | ||
return OpalTableSource.newSource(project, table); | ||
} | ||
|
||
public static String toTableName(String sourceURN) { | ||
return sourceURN.replace("urn:opal:", ""); | ||
} | ||
|
||
public void init(OpalService opalService, String opalUrl) { | ||
this.opalService = opalService; | ||
this.opalUrl = opalUrl; | ||
} | ||
|
||
private RestDatasource getDatasource() { | ||
return opalService.getDatasource(opalUrl, project); | ||
} | ||
|
||
private RestValueTable getRestValueTable() { | ||
return (RestValueTable) getDatasource().getValueTable(table); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
mica-core/src/main/java/org/obiba/mica/core/service/StudyTableSourceServiceRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright (c) 2022 OBiBa. All rights reserved. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the GNU Public License v3.0. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.obiba.mica.core.service; | ||
|
||
import org.obiba.mica.core.domain.BaseStudyTable; | ||
import org.obiba.mica.core.domain.OpalTableSource; | ||
import org.obiba.mica.micaConfig.service.OpalService; | ||
import org.obiba.mica.micaConfig.service.PluginsService; | ||
import org.obiba.mica.spi.dataset.StudyTableSource; | ||
import org.obiba.mica.spi.dataset.StudyTableSourceService; | ||
import org.obiba.mica.study.domain.BaseStudy; | ||
import org.springframework.stereotype.Service; | ||
|
||
import javax.inject.Inject; | ||
import java.util.NoSuchElementException; | ||
import java.util.Optional; | ||
|
||
@Service | ||
public class StudyTableSourceServiceRegistry { | ||
|
||
@Inject | ||
private PluginsService pluginsService; | ||
|
||
@Inject | ||
private OpalService opalService; | ||
|
||
public StudyTableSource makeSource(BaseStudy study, String sourceURN) { | ||
if (OpalTableSource.isFor(sourceURN)) { | ||
OpalTableSource source = OpalTableSource.fromURN(sourceURN); | ||
source.init(opalService, study.getOpal()); | ||
return source; | ||
} | ||
Optional<StudyTableSourceService> serviceOptional = pluginsService.getStudyTableSourceServices().stream() | ||
.filter(service -> service.isFor(sourceURN)).findFirst(); | ||
if (serviceOptional.isPresent()) { | ||
// TODO add a context to the study table source | ||
return serviceOptional.get().makeSource(sourceURN); | ||
} | ||
throw new NoSuchElementException("Missing study-table-source plugin to handle source: " + sourceURN); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.