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();
}
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));
}
}
Aggregations