Search in sources :

Example 1 with DatasetVariable

use of org.obiba.mica.dataset.domain.DatasetVariable in project mica2 by obiba.

the class CollectedDatasetService method indexDatasets.

private void indexDatasets(Set<StudyDataset> publishedDatasets, List<StudyDataset> datasets, boolean mustIndexVariables) {
    datasets.forEach(dataset -> {
        try {
            eventBus.post(new DatasetUpdatedEvent(dataset));
            if (publishedDatasets.contains(dataset)) {
                prepareForIndex(dataset);
                Iterable<DatasetVariable> variables = mustIndexVariables && publishedDatasets.contains(dataset) ? wrappedGetDatasetVariables(dataset) : null;
                eventBus.post(new DatasetPublishedEvent(dataset, variables, getCurrentUsername()));
            }
        } catch (Exception e) {
            log.error(String.format("Error indexing dataset %s", dataset), e);
        }
    });
}
Also used : DatasetUpdatedEvent(org.obiba.mica.dataset.event.DatasetUpdatedEvent) DatasetVariable(org.obiba.mica.dataset.domain.DatasetVariable) DatasetPublishedEvent(org.obiba.mica.dataset.event.DatasetPublishedEvent) NoSuchVariableException(org.obiba.magma.NoSuchVariableException) NoSuchDatasetException(org.obiba.mica.dataset.NoSuchDatasetException) NoSuchEntityException(org.obiba.mica.NoSuchEntityException) NoSuchValueTableException(org.obiba.magma.NoSuchValueTableException) NoSuchStudyException(org.obiba.mica.study.NoSuchStudyException)

Example 2 with DatasetVariable

use of org.obiba.mica.dataset.domain.DatasetVariable in project mica2 by obiba.

the class CollectedDatasetService method publish.

/**
 * Apply dataset publication flag.
 *
 * @param id
 * @param published
 */
@Caching(evict = { @CacheEvict(value = "aggregations-metadata", key = "'dataset'") })
public void publish(@NotNull String id, boolean published, PublishCascadingScope cascadingScope) {
    StudyDataset dataset = findById(id);
    helper.evictCache(dataset);
    if (published) {
        checkIsPublishable(dataset);
        Iterable<DatasetVariable> variables = wrappedGetDatasetVariables(dataset);
        publishState(id);
        prepareForIndex(dataset);
        eventBus.post(new DatasetPublishedEvent(dataset, variables, getCurrentUsername(), cascadingScope));
    // helper.asyncBuildDatasetVariablesCache(dataset, variables);
    } else {
        unPublishState(id);
        eventBus.post(new DatasetUnpublishedEvent(dataset));
    }
}
Also used : DatasetUnpublishedEvent(org.obiba.mica.dataset.event.DatasetUnpublishedEvent) DatasetVariable(org.obiba.mica.dataset.domain.DatasetVariable) DatasetPublishedEvent(org.obiba.mica.dataset.event.DatasetPublishedEvent) StudyDataset(org.obiba.mica.dataset.domain.StudyDataset) Caching(org.springframework.cache.annotation.Caching)

Example 3 with DatasetVariable

use of org.obiba.mica.dataset.domain.DatasetVariable in project mica2 by obiba.

the class HarmonizedDatasetService method indexAll.

public void indexAll(boolean mustIndexVariables) {
    Set<HarmonizationDataset> publishedDatasets = Sets.newHashSet(findAllPublishedDatasets());
    findAllDatasets().forEach(dataset -> {
        try {
            eventBus.post(new DatasetUpdatedEvent(dataset));
            if (publishedDatasets.contains(dataset)) {
                Map<String, List<DatasetVariable>> harmonizationVariables = mustIndexVariables && publishedDatasets.contains(dataset) ? populateHarmonizedVariablesMap(dataset) : null;
                Iterable<DatasetVariable> datasetVariables = mustIndexVariables && publishedDatasets.contains(dataset) ? wrappedGetDatasetVariables(dataset) : null;
                eventBus.post(new DatasetPublishedEvent(dataset, datasetVariables, harmonizationVariables, getCurrentUsername()));
            }
        } catch (Exception e) {
            log.error(String.format("Error indexing dataset %s", dataset), e);
        }
    });
    eventBus.post(new HarmonizationDatasetIndexedEvent());
}
Also used : HarmonizationDatasetIndexedEvent(org.obiba.mica.dataset.event.HarmonizationDatasetIndexedEvent) DatasetUpdatedEvent(org.obiba.mica.dataset.event.DatasetUpdatedEvent) DatasetVariable(org.obiba.mica.dataset.domain.DatasetVariable) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) DatasetPublishedEvent(org.obiba.mica.dataset.event.DatasetPublishedEvent) NoSuchVariableException(org.obiba.magma.NoSuchVariableException) NoSuchDatasetException(org.obiba.mica.dataset.NoSuchDatasetException) NoSuchEntityException(org.obiba.mica.NoSuchEntityException) NoSuchValueTableException(org.obiba.magma.NoSuchValueTableException) MagmaRuntimeException(org.obiba.magma.MagmaRuntimeException) NoSuchStudyException(org.obiba.mica.study.NoSuchStudyException) ExecutionException(java.util.concurrent.ExecutionException) HarmonizationDataset(org.obiba.mica.dataset.domain.HarmonizationDataset)

Example 4 with DatasetVariable

use of org.obiba.mica.dataset.domain.DatasetVariable in project mica2 by obiba.

the class PublishedCollectedDatasetVariableResource method getContingencyCsv.

@GET
@Path("/contingency/_export")
@Produces("text/csv")
@Timed
public Response getContingencyCsv(@QueryParam("by") String crossVariable) throws IOException {
    Pair<DatasetVariable, DatasetVariable> variables = getContingencyVariables(crossVariable);
    ByteArrayOutputStream res = new CsvContingencyWriter(variables.getFirst(), variables.getSecond()).write(getContingencyDto(variables.getFirst(), variables.getSecond()));
    return Response.ok(res.toByteArray()).header("Content-Disposition", String.format("attachment; filename=\"contingency-table-%s-%s.csv\"", variableName, crossVariable)).build();
}
Also used : DatasetVariable(org.obiba.mica.dataset.domain.DatasetVariable) CsvContingencyWriter(org.obiba.mica.dataset.search.rest.harmonization.CsvContingencyWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Example 5 with DatasetVariable

use of org.obiba.mica.dataset.domain.DatasetVariable in project mica2 by obiba.

the class PublishedCollectedDatasetVariableResource method getContingencyExcel.

@GET
@Path("/contingency/_export")
@Produces("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
@Timed
public Response getContingencyExcel(@QueryParam("by") String crossVariable) throws IOException {
    Pair<DatasetVariable, DatasetVariable> variables = getContingencyVariables(crossVariable);
    ByteArrayOutputStream res = new ExcelContingencyWriter(variables.getFirst(), variables.getSecond()).write(getContingencyDto(variables.getFirst(), variables.getSecond()));
    return Response.ok(res.toByteArray()).header("Content-Disposition", String.format("attachment; filename=\"contingency-table-%s-%s.xlsx\"", variableName, crossVariable)).build();
}
Also used : DatasetVariable(org.obiba.mica.dataset.domain.DatasetVariable) ExcelContingencyWriter(org.obiba.mica.dataset.search.rest.harmonization.ExcelContingencyWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Aggregations

DatasetVariable (org.obiba.mica.dataset.domain.DatasetVariable)17 Timed (com.codahale.metrics.annotation.Timed)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 GET (javax.ws.rs.GET)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 List (java.util.List)4 BadRequestException (javax.ws.rs.BadRequestException)3 NoSuchValueTableException (org.obiba.magma.NoSuchValueTableException)3 NoSuchVariableException (org.obiba.magma.NoSuchVariableException)3 NoSuchEntityException (org.obiba.mica.NoSuchEntityException)3 StudyTable (org.obiba.mica.core.domain.StudyTable)3 StudyDataset (org.obiba.mica.dataset.domain.StudyDataset)3 DatasetPublishedEvent (org.obiba.mica.dataset.event.DatasetPublishedEvent)3 Strings (com.google.common.base.Strings)2 Lists (com.google.common.collect.Lists)2 Collectors (java.util.stream.Collectors)2 Collectors.toList (java.util.stream.Collectors.toList)2 Inject (javax.inject.Inject)2 NotNull (javax.validation.constraints.NotNull)2