Search in sources :

Example 6 with StudyDataset

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

the class DatasetDtosTest method test_study_dataset_dto.

@Test
public void test_study_dataset_dto() throws Exception {
    StudyDataset studyDataset = createStudyDataset();
    Mica.DatasetDto dto = datasetDtos.asDto(studyDataset);
    assertThat(dto.getId(), is("123"));
}
Also used : StudyDataset(org.obiba.mica.dataset.domain.StudyDataset) Test(org.junit.Test)

Example 7 with StudyDataset

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

the class DatasetDtosTest method createStudyDataset.

private StudyDataset createStudyDataset() {
    StudyDataset studyDataset = new StudyDataset();
    studyDataset.setId("123");
    return studyDataset;
}
Also used : StudyDataset(org.obiba.mica.dataset.domain.StudyDataset)

Example 8 with StudyDataset

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

the class DraftCollectedDatasetsResource method create.

@POST
@Path("/collected-datasets")
@Timed
@RequiresPermissions({ "/draft/collected-dataset:ADD" })
public Response create(Mica.DatasetDto datasetDto, @Context UriInfo uriInfo, @Nullable @QueryParam("comment") String comment) {
    Dataset dataset = dtos.fromDto(datasetDto);
    if (!(dataset instanceof StudyDataset))
        throw new IllegalArgumentException("A collected dataset is expected");
    datasetService.save((StudyDataset) dataset, comment);
    return Response.created(uriInfo.getBaseUriBuilder().segment("draft", "collected-dataset", dataset.getId()).build()).build();
}
Also used : StudyDataset(org.obiba.mica.dataset.domain.StudyDataset) Dataset(org.obiba.mica.dataset.domain.Dataset) StudyDataset(org.obiba.mica.dataset.domain.StudyDataset) Path(javax.ws.rs.Path) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed)

Example 9 with StudyDataset

use of org.obiba.mica.dataset.domain.StudyDataset 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.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.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.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 10 with StudyDataset

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

the class DatasetDtos method fromDto.

@NotNull
public Dataset fromDto(Mica.DatasetDtoOrBuilder dto) {
    Dataset dataset = dto.hasExtension(Mica.HarmonizedDatasetDto.type) ? fromDto(dto.getExtension(Mica.HarmonizedDatasetDto.type)) : dto.hasExtension(Mica.CollectedDatasetDto.type) ? fromDto(dto.getExtension(Mica.CollectedDatasetDto.type)) : new StudyDataset();
    if (dto.hasId())
        dataset.setId(dto.getId());
    dataset.setAcronym(localizedStringDtos.fromDto(dto.getAcronymList()));
    dataset.setName(localizedStringDtos.fromDto(dto.getNameList()));
    dataset.setDescription(localizedStringDtos.fromDto(dto.getDescriptionList()));
    dataset.setEntityType(dto.getEntityType());
    dataset.setPublished(dto.getPublished());
    if (dto.getAttributesCount() > 0) {
        dto.getAttributesList().forEach(attributeDto -> dataset.addAttribute(attributeDtos.fromDto(attributeDto)));
    }
    if (dto.hasContent()) {
        dataset.setModel(JSONUtils.toMap(dto.getContent()));
    }
    return dataset;
}
Also used : StudyDataset(org.obiba.mica.dataset.domain.StudyDataset) Dataset(org.obiba.mica.dataset.domain.Dataset) HarmonizationDataset(org.obiba.mica.dataset.domain.HarmonizationDataset) StudyDataset(org.obiba.mica.dataset.domain.StudyDataset) NotNull(javax.validation.constraints.NotNull)

Aggregations

StudyDataset (org.obiba.mica.dataset.domain.StudyDataset)16 StudyTable (org.obiba.mica.core.domain.StudyTable)4 IOException (java.io.IOException)3 Dataset (org.obiba.mica.dataset.domain.Dataset)3 DatasetVariable (org.obiba.mica.dataset.domain.DatasetVariable)3 DatasetUpdatedEvent (org.obiba.mica.dataset.event.DatasetUpdatedEvent)3 Timed (com.codahale.metrics.annotation.Timed)2 Strings (com.google.common.base.Strings)2 Lists (com.google.common.collect.Lists)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 NotNull (javax.validation.constraints.NotNull)2 BadRequestException (javax.ws.rs.BadRequestException)2 Path (javax.ws.rs.Path)2 DateTime (org.joda.time.DateTime)2 NoSuchVariableException (org.obiba.magma.NoSuchVariableException)2 HarmonizationDataset (org.obiba.mica.dataset.domain.HarmonizationDataset)2 StudyDatasetState (org.obiba.mica.dataset.domain.StudyDatasetState)2 DatasetDeletedEvent (org.obiba.mica.dataset.event.DatasetDeletedEvent)2