use of org.molgenis.data.annotation.core.RepositoryAnnotator in project molgenis by molgenis.
the class AnnotationJobFactory method createJob.
@RunAsSystem
public AnnotationJob createJob(AnnotationJobExecution metaData) {
dataService.add(ANNOTATION_JOB_EXECUTION, metaData);
String annotatorNames = metaData.getAnnotators();
String targetName = metaData.getTargetName();
String username = metaData.getUser();
// create an authentication to run as the user that is listed as the owner of the job
RunAsUserToken runAsAuthentication = new RunAsUserToken("Job Execution", username, null, userDetailsService.loadUserByUsername(username).getAuthorities(), null);
Repository<Entity> repository = dataService.getRepository(targetName);
List<RepositoryAnnotator> availableAnnotators = annotationService.getAllAnnotators().stream().filter(RepositoryAnnotator::annotationDataExists).collect(toList());
List<RepositoryAnnotator> requestedAnnotators = Arrays.stream(annotatorNames.split(",")).map(annotationService::getAnnotatorByName).collect(toList());
AnnotatorDependencyOrderResolver resolver = new AnnotatorDependencyOrderResolver();
List<RepositoryAnnotator> annotators = Lists.newArrayList(resolver.getAnnotatorSelectionDependencyList(availableAnnotators, requestedAnnotators, repository, entityTypeFactory));
return new AnnotationJob(crudRepositoryAnnotator, username, annotators, repository, new ProgressImpl(metaData, jobExecutionUpdater, mailSender), runAsAuthentication, new TransactionTemplate(transactionManager));
}
use of org.molgenis.data.annotation.core.RepositoryAnnotator in project molgenis by molgenis.
the class AnnotationServiceImpl method getAnnotatorsByMetaData.
@Override
public List<RepositoryAnnotator> getAnnotatorsByMetaData(EntityType metaData) {
getAllAnnotators();
List<RepositoryAnnotator> result = Lists.newArrayList();
for (RepositoryAnnotator annotator : annotators) {
if (annotator.canAnnotate(metaData).equals("true")) {
result.add(annotator);
}
}
return result;
}
use of org.molgenis.data.annotation.core.RepositoryAnnotator in project molgenis by molgenis.
the class AnnotatorUtils method createCompoundForAnnotator.
private static void createCompoundForAnnotator(EntityType entityType, AttributeFactory attributeFactory, RepositoryAnnotator annotator, List<Attribute> attributes, String compoundName) {
Attribute compound;
compound = attributeFactory.create().setName(compoundName).setLabel(annotator.getFullName()).setDataType(COMPOUND).setLabel(annotator.getSimpleName());
attributes.stream().filter(part -> entityType.getAttribute(part.getName()) == null).forEachOrdered(part -> part.setParent(compound));
entityType.addAttribute(compound);
// Only add attributes that do not already exist. We assume existing attributes are added in a previous annotation run.
// This is a potential risk if an attribute with that name already exist that was not added by the annotator.
// This risk is relatively low since annotator attributes are prefixed.
attributes = attributes.stream().filter(attribute -> entityType.getAttribute(attribute.getName()) == null).collect(toList());
entityType.addAttributes(attributes);
}
use of org.molgenis.data.annotation.core.RepositoryAnnotator in project molgenis by molgenis.
the class AnnotatorController method setMapOfAnnotators.
/**
* Sets a map of annotators, whether they can be used by the selected data set.
*
* @return mapOfAnnotators
*/
private Map<String, Map<String, Object>> setMapOfAnnotators(String dataSetName) {
Map<String, Map<String, Object>> mapOfAnnotators = new HashMap<>();
if (dataSetName != null) {
EntityType entityType = dataService.getEntityType(dataSetName);
for (RepositoryAnnotator annotator : annotationService.getAllAnnotators()) {
List<Attribute> outputAttrs = annotator.getOutputAttributes();
outputAttrs = getAtomicAttributesFromList(outputAttrs);
Map<String, Object> map = new HashMap<>();
map.put("description", annotator.getDescription());
map.put("canAnnotate", annotator.canAnnotate(entityType));
map.put("inputAttributes", createAttrsResponse(annotator.getRequiredAttributes()));
map.put("inputAttributeTypes", toMap(annotator.getRequiredAttributes()));
map.put("outputAttributes", createAttrsResponse(outputAttrs));
map.put("outputAttributeTypes", toMap(annotator.getOutputAttributes()));
String settingsEntityName = PACKAGE_SETTINGS + PACKAGE_SEPARATOR + annotator.getInfo().getCode();
map.put("showSettingsButton", permissionService.hasPermission(new EntityTypeIdentity(settingsEntityName), EntityTypePermission.WRITE));
mapOfAnnotators.put(annotator.getSimpleName(), map);
}
}
return mapOfAnnotators;
}
use of org.molgenis.data.annotation.core.RepositoryAnnotator in project molgenis by molgenis.
the class AnnotationJob method call.
@Override
public Void call(Progress progress) throws Exception {
progress.setProgressMax(annotators.size());
int i = 0;
for (RepositoryAnnotator annotator : annotators) {
progress.progress(i, getMessage(i, annotator));
try {
crudRepositoryAnnotator.annotate(annotator, repository);
successfulAnnotators.add(annotator.getSimpleName());
} catch (Exception ex) {
if (firstException == null) {
firstException = ex;
}
failedAnnotators.add(annotator.getSimpleName());
}
i++;
}
progress.progress(annotators.size(), getMessage());
try {
// TODO: Workaround to make sure that the progress bar gets loaded
Thread.sleep(1000);
} catch (InterruptedException e) {
}
if (firstException != null) {
progress.status("Failed annotators: " + StringUtils.join(failedAnnotators, ",") + ". Successful annotators: " + StringUtils.join(successfulAnnotators, ","));
throw firstException;
}
return null;
}
Aggregations