use of org.molgenis.data.annotation.core.exception.UiAnnotationException in project molgenis by molgenis.
the class CrudRepositoryAnnotator method annotate.
private void annotate(RepositoryAnnotator annotator, Repository<Entity> repository, DatabaseAction action) {
if (!repository.getCapabilities().contains(WRITABLE)) {
throw new UnsupportedOperationException("Currently only writable repositories can be annotated");
}
try {
EntityType entityType = dataService.getMeta().getEntityType(repository.getName());
if (annotator instanceof EffectCreatingAnnotator) {
targetMetaData = ((EffectCreatingAnnotator) annotator).getTargetEntityType(entityType);
if (!dataService.hasRepository(targetMetaData.getId())) {
// add new entities to new repo
Repository externalRepository = dataService.getMeta().createRepository(targetMetaData);
permissionSystemService.giveUserWriteMetaPermissions(targetMetaData);
runAsSystem(() -> dataService.getMeta().updateEntityType(externalRepository.getEntityType()));
iterateOverEntitiesAndAnnotate(repository, annotator, DatabaseAction.ADD);
} else {
throw new UnsupportedOperationException("This entity has already been annotated with " + annotator.getSimpleName());
}
} else {
runAsSystem(() -> dataService.getMeta().updateEntityType(addAnnotatorMetaDataToRepositories(entityType, attributeFactory, annotator)));
iterateOverEntitiesAndAnnotate(dataService.getRepository(repository.getName()), annotator, action);
}
} catch (AnnotationException ae) {
deleteResultEntity(annotator, targetMetaData);
throw new UiAnnotationException(ae);
} catch (Exception e) {
deleteResultEntity(annotator, targetMetaData);
throw new RuntimeException(e);
}
}
Aggregations