Search in sources :

Example 6 with BaseStudyTable

use of org.obiba.mica.core.domain.BaseStudyTable in project mica2 by obiba.

the class RQLCriteriaOpalConverter method parseField.

private RQLFieldReferences parseField(String path) {
    DatasetVariable.IdResolver resolver = DatasetVariable.IdResolver.from(path);
    if (resolver.getType() == null || DatasetVariable.Type.Collected.equals(resolver.getType())) {
        StudyDataset ds = collectedDatasetService.findById(resolver.getDatasetId());
        BaseStudyTable studyTable = ds.getStudyTable();
        BaseStudy study = studyService.findStudy(studyTable.getStudyId());
        return new RQLFieldReferences(path, ds, studyTable, study, getDatasetVariableInternal(Indexer.PUBLISHED_VARIABLE_INDEX, Indexer.VARIABLE_TYPE, path));
    } else if (DatasetVariable.Type.Dataschema.equals(resolver.getType())) {
        HarmonizationDataset ds = harmonizedDatasetService.findById(resolver.getDatasetId());
        BaseStudy study = studyService.findStudy(ds.getHarmonizationTable().getStudyId());
        return new RQLFieldReferences(path, ds, ds.getBaseStudyTables(), study, getDatasetVariableInternal(Indexer.PUBLISHED_VARIABLE_INDEX, Indexer.VARIABLE_TYPE, path));
    } else if (DatasetVariable.Type.Harmonized.equals(resolver.getType())) {
        HarmonizationDataset ds = harmonizedDatasetService.findById(resolver.getDatasetId());
        Optional<BaseStudyTable> studyTable = ds.getBaseStudyTables().stream().filter(st -> st.getStudyId().equals(resolver.getStudyId()) && st.getProject().equals(resolver.getProject()) && st.getTable().equals(resolver.getTable())).findFirst();
        if (!studyTable.isPresent())
            throw new IllegalArgumentException("Not a valid variable: " + path);
        BaseStudy study = studyService.findStudy(studyTable.get().getStudyId());
        return new RQLFieldReferences(path, ds, studyTable.get(), study, getDatasetVariableInternal(Indexer.PUBLISHED_HVARIABLE_INDEX, Indexer.HARMONIZED_VARIABLE_TYPE, path));
    }
    throw new IllegalArgumentException("Not a valid variable: " + path);
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) BaseStudyTable(org.obiba.mica.core.domain.BaseStudyTable) NoSuchVariableException(org.obiba.magma.NoSuchVariableException) Indexer(org.obiba.mica.spi.search.Indexer) ValueType(org.obiba.magma.ValueType) Scope(org.springframework.context.annotation.Scope) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) Lists(com.google.common.collect.Lists) StudyDataset(org.obiba.mica.dataset.domain.StudyDataset) Searcher(org.obiba.mica.spi.search.Searcher) HarmonizationStudy(org.obiba.mica.study.domain.HarmonizationStudy) TextType(org.obiba.magma.type.TextType) DatasetVariable(org.obiba.mica.dataset.domain.DatasetVariable) BaseStudy(org.obiba.mica.study.domain.BaseStudy) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DateTime(org.joda.time.DateTime) VariableNature(org.obiba.magma.support.VariableNature) CollectedDatasetService(org.obiba.mica.dataset.service.CollectedDatasetService) StudyService(org.obiba.mica.study.service.StudyService) RQLParser(net.jazdw.rql.parser.RQLParser) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) HarmonizedDatasetService(org.obiba.mica.dataset.service.HarmonizedDatasetService) Component(org.springframework.stereotype.Component) List(java.util.List) ASTNode(net.jazdw.rql.parser.ASTNode) HarmonizationDataset(org.obiba.mica.dataset.domain.HarmonizationDataset) Optional(java.util.Optional) Joiner(com.google.common.base.Joiner) InputStream(java.io.InputStream) DatasetVariable(org.obiba.mica.dataset.domain.DatasetVariable) BaseStudyTable(org.obiba.mica.core.domain.BaseStudyTable) BaseStudy(org.obiba.mica.study.domain.BaseStudy) StudyDataset(org.obiba.mica.dataset.domain.StudyDataset) HarmonizationDataset(org.obiba.mica.dataset.domain.HarmonizationDataset)

Example 7 with BaseStudyTable

use of org.obiba.mica.core.domain.BaseStudyTable in project mica2 by obiba.

the class DraftHarmonizedDatasetResource method getFacets.

@POST
@Path("/facets")
public List<Search.QueryResultDto> getFacets(Search.QueryTermsDto query) {
    checkPermission("/draft/harmonized-dataset", "VIEW");
    ImmutableList.Builder<Search.QueryResultDto> builder = ImmutableList.builder();
    HarmonizationDataset dataset = getDataset();
    for (BaseStudyTable table : dataset.getBaseStudyTables()) {
        builder.add(datasetService.getFacets(query, table));
    }
    return builder.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) BaseStudyTable(org.obiba.mica.core.domain.BaseStudyTable) HarmonizationDataset(org.obiba.mica.dataset.domain.HarmonizationDataset)

Aggregations

BaseStudyTable (org.obiba.mica.core.domain.BaseStudyTable)7 HarmonizationDataset (org.obiba.mica.dataset.domain.HarmonizationDataset)7 IOException (java.io.IOException)5 NoSuchValueTableException (org.obiba.magma.NoSuchValueTableException)4 NoSuchVariableException (org.obiba.magma.NoSuchVariableException)4 Timed (com.codahale.metrics.annotation.Timed)3 ImmutableList (com.google.common.collect.ImmutableList)3 Future (java.util.concurrent.Future)3 Mica (org.obiba.mica.web.model.Mica)3 StudyDataset (org.obiba.mica.dataset.domain.StudyDataset)2 Math (org.obiba.opal.web.model.Math)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Joiner (com.google.common.base.Joiner)1 Strings (com.google.common.base.Strings)1 Lists (com.google.common.collect.Lists)1 InputStream (java.io.InputStream)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1