use of org.molgenis.data.annotation.core.exception.AnnotationException in project molgenis by molgenis.
the class AnnotationJobTest method testFirstAnnotatorFails.
@Test
public void testFirstAnnotatorFails() throws IOException {
when(exac.getSimpleName()).thenReturn("exac");
when(cadd.getSimpleName()).thenReturn("cadd");
AnnotationException exception = new AnnotationException(mock(AnnotationException.class));
doThrow(exception).when(crudRepositoryAnnotator).annotate(exac, repository);
try {
annotationJob.call();
fail("Should throw exception");
} catch (JobExecutionException actual) {
assertEquals(actual.getCause(), exception);
}
Mockito.verify(progress).start();
Mockito.verify(progress).setProgressMax(2);
Mockito.verify(progress).progress(0, "Annotating \"My repo\" with exac (annotator 1 of 2, started by \"fdlk\")");
Mockito.verify(progress).progress(1, "Annotating \"My repo\" with cadd (annotator 2 of 2, started by \"fdlk\")");
Mockito.verify(progress).status("Failed annotators: exac. Successful annotators: cadd");
Mockito.verify(progress).failed(exception);
}
use of org.molgenis.data.annotation.core.exception.AnnotationException 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);
}
}
use of org.molgenis.data.annotation.core.exception.AnnotationException in project molgenis by molgenis.
the class AbstractRepositoryEntityAnnotator method annotate.
@Override
@Transactional
@RunAsSystem
public Iterator<Entity> annotate(final Iterable<Entity> sourceIterable, boolean updateMode) {
Iterator<Entity> source = sourceIterable.iterator();
return new Iterator<Entity>() {
int current = 0;
int size = 0;
List<Entity> results;
Entity result;
@Override
public boolean hasNext() {
return current < size || source.hasNext();
}
@Override
public Entity next() {
Entity sourceEntity = null;
if (current >= size) {
if (source.hasNext()) {
try {
sourceEntity = source.next();
results = annotateEntity(sourceEntity, updateMode);
} catch (Exception e) {
throw new AnnotationException(sourceEntity, current + 1, getRequiredAttributes(), getSimpleName(), e);
}
size = results.size();
}
current = 0;
}
if (!results.isEmpty()) {
result = results.get(current);
} else {
result = sourceEntity;
}
++current;
return result;
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
};
}
Aggregations