Search in sources :

Example 1 with DatasetPublishedEvent

use of org.obiba.mica.dataset.event.DatasetPublishedEvent 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 2 with DatasetPublishedEvent

use of org.obiba.mica.dataset.event.DatasetPublishedEvent in project mica2 by obiba.

the class HarmonizedDatasetService method indexHarmonizedVariables.

private void indexHarmonizedVariables(HarmonizationDataset dataset) {
    if (!dataset.getBaseStudyTables().isEmpty()) {
        dataset.getBaseStudyTables().forEach(studyTable -> {
            Future<Iterable<DatasetVariable>> future = helper.asyncGetDatasetVariables(() -> getDatasetVariables(dataset, studyTable));
            try {
                Iterable<DatasetVariable> harmonizationVariables = future.get();
                eventBus.post(new DatasetPublishedEvent(dataset, null, harmonizationVariables, getCurrentUsername()));
            } catch (InterruptedException e) {
                if (e.getCause() instanceof MagmaRuntimeException) {
                    throw new DatasourceNotAvailableException(e.getCause());
                }
                throw Throwables.propagate(e.getCause());
            } catch (ExecutionException e) {
                throw Throwables.propagate(e);
            }
        });
    }
}
Also used : DatasetVariable(org.obiba.mica.dataset.domain.DatasetVariable) DatasetPublishedEvent(org.obiba.mica.dataset.event.DatasetPublishedEvent) ExecutionException(java.util.concurrent.ExecutionException)

Example 3 with DatasetPublishedEvent

use of org.obiba.mica.dataset.event.DatasetPublishedEvent in project mica2 by obiba.

the class HarmonizedDatasetService method indexByIds.

public void indexByIds(List<String> ids, boolean mustIndexVariables) {
    List<String> includeIds = ids.isEmpty() ? findAllIds() : ids;
    List<HarmonizationDataset> datasets = findAllDatasets(includeIds);
    HashSet<HarmonizationDataset> publishedDatasets = Sets.newHashSet(findPublishedDatasets(includeIds));
    datasets.forEach(dataset -> {
        try {
            eventBus.post(new DatasetUpdatedEvent(dataset));
            if (publishedDatasets.contains(dataset)) {
                if (mustIndexVariables && publishedDatasets.contains(dataset)) {
                    eventBus.post(new DatasetPublishedEvent(dataset, wrappedGetDatasetVariables(dataset), null, getCurrentUsername()));
                    indexHarmonizedVariables(dataset);
                }
            }
        } catch (Exception e) {
            log.error(String.format("Error indexing dataset %s", dataset), e);
        }
    });
}
Also used : DatasetUpdatedEvent(org.obiba.mica.dataset.event.DatasetUpdatedEvent) DatasetPublishedEvent(org.obiba.mica.dataset.event.DatasetPublishedEvent) NoSuchDatasetException(org.obiba.mica.dataset.NoSuchDatasetException) NoSuchEntityException(org.obiba.mica.NoSuchEntityException) MissingCommentException(org.obiba.mica.core.service.MissingCommentException) NoSuchStudyException(org.obiba.mica.study.NoSuchStudyException) ExecutionException(java.util.concurrent.ExecutionException) HarmonizationDataset(org.obiba.mica.dataset.domain.HarmonizationDataset)

Example 4 with DatasetPublishedEvent

use of org.obiba.mica.dataset.event.DatasetPublishedEvent in project mica2 by obiba.

the class HarmonizedDatasetService 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) {
    HarmonizationDataset dataset = findById(id);
    helper.evictCache(dataset);
    if (published) {
        checkIsPublishable(dataset);
        publishState(id);
        eventBus.post(new DatasetPublishedEvent(dataset, wrappedGetDatasetVariables(dataset), null, getCurrentUsername(), cascadingScope));
        indexHarmonizedVariables(dataset);
    } else {
        unPublishState(id);
        eventBus.post(new DatasetUnpublishedEvent(dataset));
    }
}
Also used : DatasetUnpublishedEvent(org.obiba.mica.dataset.event.DatasetUnpublishedEvent) DatasetPublishedEvent(org.obiba.mica.dataset.event.DatasetPublishedEvent) HarmonizationDataset(org.obiba.mica.dataset.domain.HarmonizationDataset) Caching(org.springframework.cache.annotation.Caching)

Example 5 with DatasetPublishedEvent

use of org.obiba.mica.dataset.event.DatasetPublishedEvent 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)

Aggregations

DatasetPublishedEvent (org.obiba.mica.dataset.event.DatasetPublishedEvent)7 DatasetVariable (org.obiba.mica.dataset.domain.DatasetVariable)4 DatasetUpdatedEvent (org.obiba.mica.dataset.event.DatasetUpdatedEvent)4 ExecutionException (java.util.concurrent.ExecutionException)3 NoSuchEntityException (org.obiba.mica.NoSuchEntityException)3 NoSuchDatasetException (org.obiba.mica.dataset.NoSuchDatasetException)3 HarmonizationDataset (org.obiba.mica.dataset.domain.HarmonizationDataset)3 NoSuchStudyException (org.obiba.mica.study.NoSuchStudyException)3 NoSuchValueTableException (org.obiba.magma.NoSuchValueTableException)2 NoSuchVariableException (org.obiba.magma.NoSuchVariableException)2 MissingCommentException (org.obiba.mica.core.service.MissingCommentException)2 StudyDataset (org.obiba.mica.dataset.domain.StudyDataset)2 DatasetUnpublishedEvent (org.obiba.mica.dataset.event.DatasetUnpublishedEvent)2 Caching (org.springframework.cache.annotation.Caching)2 List (java.util.List)1 Collectors.toList (java.util.stream.Collectors.toList)1 MagmaRuntimeException (org.obiba.magma.MagmaRuntimeException)1 EntityState (org.obiba.mica.core.domain.EntityState)1 HarmonizationDatasetIndexedEvent (org.obiba.mica.dataset.event.HarmonizationDatasetIndexedEvent)1