Search in sources :

Example 11 with DatasetVariable

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

the class PublishedCollectedDatasetVariableResource method getContingencyVariables.

private Pair<DatasetVariable, DatasetVariable> getContingencyVariables(String crossVariable) {
    if (Strings.isNullOrEmpty(crossVariable))
        throw new BadRequestException("Cross variable name is required for the contingency table");
    DatasetVariable var = getDatasetVariable(datasetId, variableName, DatasetVariable.Type.Collected, null);
    DatasetVariable crossVar = getDatasetVariable(datasetId, crossVariable, DatasetVariable.Type.Collected, null);
    return Pair.create(var, crossVar);
}
Also used : DatasetVariable(org.obiba.mica.dataset.domain.DatasetVariable) BadRequestException(javax.ws.rs.BadRequestException)

Example 12 with DatasetVariable

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

the class PublishedDataschemaDatasetVariableResource 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 value = new CsvContingencyWriter(variables.getFirst(), variables.getSecond()).write(getDatasetVariableContingenciesDto(variables.getFirst(), variables.getSecond()));
    return Response.ok(value.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) 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 13 with DatasetVariable

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

the class PublishedDataschemaDatasetVariableResource method getContingencyVariables.

private Pair<DatasetVariable, DatasetVariable> getContingencyVariables(String crossVariable) {
    if (Strings.isNullOrEmpty(crossVariable))
        throw new BadRequestException("Cross variable name is required for the contingency table");
    DatasetVariable var = getDatasetVariable(datasetId, variableName, DatasetVariable.Type.Dataschema, null);
    DatasetVariable crossVar = getDatasetVariable(datasetId, crossVariable, DatasetVariable.Type.Dataschema, null);
    return Pair.create(var, crossVar);
}
Also used : DatasetVariable(org.obiba.mica.dataset.domain.DatasetVariable) BadRequestException(javax.ws.rs.BadRequestException)

Example 14 with DatasetVariable

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

the class PublishedHarmonizedDatasetVariableResource 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) 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 15 with DatasetVariable

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

the class PublishedHarmonizedDatasetVariableResource method getContingencyVariables.

private Pair<DatasetVariable, DatasetVariable> getContingencyVariables(String crossVariable) {
    if (Strings.isNullOrEmpty(crossVariable))
        throw new BadRequestException("Cross variable name is required for the contingency table");
    DatasetVariable var = getDatasetVariable(datasetId, variableName, DatasetVariable.Type.Harmonized, studyId, project, table, tableType);
    DatasetVariable crossVar = getDatasetVariable(datasetId, crossVariable, DatasetVariable.Type.Harmonized, studyId, project, table, tableType);
    return Pair.create(var, crossVar);
}
Also used : DatasetVariable(org.obiba.mica.dataset.domain.DatasetVariable) BadRequestException(javax.ws.rs.BadRequestException)

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