Search in sources :

Example 1 with RepositoryAnnotator

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));
}
Also used : Entity(org.molgenis.data.Entity) ProgressImpl(org.molgenis.jobs.ProgressImpl) RunAsUserToken(org.springframework.security.access.intercept.RunAsUserToken) RepositoryAnnotator(org.molgenis.data.annotation.core.RepositoryAnnotator) CrudRepositoryAnnotator(org.molgenis.data.annotation.web.CrudRepositoryAnnotator) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) AnnotatorDependencyOrderResolver(org.molgenis.data.annotation.core.utils.AnnotatorDependencyOrderResolver) RunAsSystem(org.molgenis.security.core.runas.RunAsSystem)

Example 2 with RepositoryAnnotator

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;
}
Also used : RepositoryAnnotator(org.molgenis.data.annotation.core.RepositoryAnnotator)

Example 3 with RepositoryAnnotator

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);
}
Also used : AttributeFactory(org.molgenis.data.meta.model.AttributeFactory) RepositoryAnnotator(org.molgenis.data.annotation.core.RepositoryAnnotator) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) Attribute(org.molgenis.data.meta.model.Attribute) EntityType(org.molgenis.data.meta.model.EntityType) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) VcfAttributes(org.molgenis.data.vcf.model.VcfAttributes) COMPOUND(org.molgenis.data.meta.AttributeType.COMPOUND) Map(java.util.Map) MolgenisDataException(org.molgenis.data.MolgenisDataException) Collections(java.util.Collections) Attribute(org.molgenis.data.meta.model.Attribute)

Example 4 with RepositoryAnnotator

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;
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) HashMap(java.util.HashMap) RepositoryAnnotator(org.molgenis.data.annotation.core.RepositoryAnnotator) Attribute(org.molgenis.data.meta.model.Attribute) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with RepositoryAnnotator

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;
}
Also used : CrudRepositoryAnnotator(org.molgenis.data.annotation.web.CrudRepositoryAnnotator) RepositoryAnnotator(org.molgenis.data.annotation.core.RepositoryAnnotator)

Aggregations

RepositoryAnnotator (org.molgenis.data.annotation.core.RepositoryAnnotator)5 HashMap (java.util.HashMap)2 Map (java.util.Map)2 CrudRepositoryAnnotator (org.molgenis.data.annotation.web.CrudRepositoryAnnotator)2 Attribute (org.molgenis.data.meta.model.Attribute)2 EntityType (org.molgenis.data.meta.model.EntityType)2 Collections (java.util.Collections)1 List (java.util.List)1 Collectors.toList (java.util.stream.Collectors.toList)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Entity (org.molgenis.data.Entity)1 MolgenisDataException (org.molgenis.data.MolgenisDataException)1 AnnotatorDependencyOrderResolver (org.molgenis.data.annotation.core.utils.AnnotatorDependencyOrderResolver)1 COMPOUND (org.molgenis.data.meta.AttributeType.COMPOUND)1 AttributeFactory (org.molgenis.data.meta.model.AttributeFactory)1 EntityTypeIdentity (org.molgenis.data.security.EntityTypeIdentity)1 VcfAttributes (org.molgenis.data.vcf.model.VcfAttributes)1 ProgressImpl (org.molgenis.jobs.ProgressImpl)1 RunAsSystem (org.molgenis.security.core.runas.RunAsSystem)1 RunAsUserToken (org.springframework.security.access.intercept.RunAsUserToken)1