Search in sources :

Example 1 with EntityState

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

the class Mica310Upgrade method republishStudiesWithInvalidContent.

private void republishStudiesWithInvalidContent() {
    List<Study> publishedStudies = individualStudyService.findAllPublishedStudies();
    for (Study publishedStudy : publishedStudies) {
        publishedStudy = transformToValidStudy(publishedStudy);
        setDefaultWeightForStudyPopulations(publishedStudy);
        EntityState studyState = individualStudyService.getEntityState(publishedStudy.getId());
        if (studyState.getRevisionsAhead() == 0) {
            individualStudyService.save(publishedStudy);
            individualStudyService.publish(publishedStudy.getId(), true);
        } else {
            Study draftStudy = individualStudyService.findStudy(publishedStudy.getId());
            draftStudy = transformToValidStudy(draftStudy);
            individualStudyService.save(publishedStudy);
            individualStudyService.publish(publishedStudy.getId(), true);
            setDefaultWeightForStudyPopulations(draftStudy);
            individualStudyService.save(draftStudy);
        }
    }
    List<String> publishedStudiesIds = publishedStudies.stream().map(AbstractGitPersistable::getId).collect(toList());
    individualStudyService.findAllDraftStudies().stream().filter(unknownStateStudy -> !publishedStudiesIds.contains(unknownStateStudy.getId())).filter(this::canGetCommitInfoOnStudyRepository).filter(this::containsInvalidData).map(this::transformToValidStudy).forEach(individualStudyService::save);
    removeTaxonomyTaxonomyFromMongo();
}
Also used : BaseStudy(org.obiba.mica.study.domain.BaseStudy) Study(org.obiba.mica.study.domain.Study) EntityState(org.obiba.mica.core.domain.EntityState)

Example 2 with EntityState

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

the class DatasetStateUpgrade method migrateDataset.

private <T extends AbstractGitPersistableService, T1 extends EntityStateRepository> void migrateDataset(Dataset dataset, T datasetService, T1 stateRepository, Supplier<EntityState> supplier) {
    EntityState state = datasetService.findEntityState(dataset, supplier);
    state.incrementRevisionsAhead();
    stateRepository.save(state);
    eventBus.post(new DatasetUpdatedEvent(dataset));
    gitService.save(dataset, "System upgrade");
    if (state.isPublished()) {
        datasetService.publishState(dataset.getId());
        eventBus.post(new DatasetPublishedEvent(dataset, null, null));
    }
}
Also used : DatasetUpdatedEvent(org.obiba.mica.dataset.event.DatasetUpdatedEvent) EntityState(org.obiba.mica.core.domain.EntityState) DatasetPublishedEvent(org.obiba.mica.dataset.event.DatasetPublishedEvent)

Aggregations

EntityState (org.obiba.mica.core.domain.EntityState)2 DatasetPublishedEvent (org.obiba.mica.dataset.event.DatasetPublishedEvent)1 DatasetUpdatedEvent (org.obiba.mica.dataset.event.DatasetUpdatedEvent)1 BaseStudy (org.obiba.mica.study.domain.BaseStudy)1 Study (org.obiba.mica.study.domain.Study)1