Search in sources :

Example 1 with UnknownEntityException

use of org.molgenis.data.UnknownEntityException in project molgenis by molgenis.

the class TagWizardController method viewTagWizard.

/**
 * Displays on tag wizard button press
 *
 * @param target The target entity name
 * @param model  the model
 * @return name of the tag wizard view
 */
@GetMapping
public String viewTagWizard(@RequestParam(required = false, value = "selectedTarget") String target, Model model) {
    List<String> entityTypeIds = dataService.findAll(ENTITY_TYPE_META_DATA, EntityType.class).map(EntityType::getId).collect(toList());
    if (StringUtils.isEmpty(target)) {
        Optional<String> findFirst = entityTypeIds.stream().findFirst();
        if (findFirst.isPresent()) {
            target = findFirst.get();
        }
    }
    if (StringUtils.isEmpty(target)) {
        throw new UnknownEntityException("There are no entities available!");
    }
    List<Ontology> ontologies = ontologyService.getOntologies();
    EntityType emd = dataService.getEntityType(target);
    List<Attribute> attributes = newArrayList(emd.getAttributes());
    Map<String, Multimap<Relation, OntologyTerm>> taggedAttributes = attributes.stream().collect(toMap((Attribute::getName), (x -> ontologyTagService.getTagsForAttribute(emd, x))));
    model.addAttribute("entity", emd);
    model.addAttribute("entityTypeIds", entityTypeIds);
    model.addAttribute("attributes", attributes);
    model.addAttribute("ontologies", ontologies);
    model.addAttribute("taggedAttributes", taggedAttributes);
    model.addAttribute("relations", Relation.values());
    return VIEW_TAG_WIZARD;
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Multimap(com.google.common.collect.Multimap) Ontology(org.molgenis.ontology.core.model.Ontology) Attribute(org.molgenis.data.meta.model.Attribute) UnknownEntityException(org.molgenis.data.UnknownEntityException)

Example 2 with UnknownEntityException

use of org.molgenis.data.UnknownEntityException in project molgenis by molgenis.

the class UntypedTagService method getTagsForPackage.

@Override
@RunAsSystem
public Iterable<SemanticTag<Package, LabeledResource, LabeledResource>> getTagsForPackage(Package p) {
    Entity packageEntity = dataService.findOne(PACKAGE, new QueryImpl<>().eq(PackageMetadata.ID, p.getId()));
    if (packageEntity == null) {
        throw new UnknownEntityException("Unknown package [" + p.getId() + "]");
    }
    List<SemanticTag<Package, LabeledResource, LabeledResource>> tags = Lists.newArrayList();
    for (Entity tagEntity : packageEntity.getEntities(PackageMetadata.TAGS)) {
        tags.add(SemanticTag.asTag(p, tagEntity));
    }
    return tags;
}
Also used : Entity(org.molgenis.data.Entity) QueryImpl(org.molgenis.data.support.QueryImpl) UnknownEntityException(org.molgenis.data.UnknownEntityException) SemanticTag(org.molgenis.data.semantic.SemanticTag) RunAsSystem(org.molgenis.security.core.runas.RunAsSystem)

Example 3 with UnknownEntityException

use of org.molgenis.data.UnknownEntityException in project molgenis by molgenis.

the class OntologyTagServiceImpl method getTagsForPackage.

@Override
public Iterable<SemanticTag<Package, OntologyTerm, Ontology>> getTagsForPackage(Package package_) {
    Entity packageEntity = dataService.findOneById(PACKAGE, package_.getId());
    if (packageEntity == null) {
        throw new UnknownEntityException("Unknown package [" + package_.getId() + "]");
    }
    List<SemanticTag<Package, OntologyTerm, Ontology>> tags = Lists.newArrayList();
    for (Entity tagEntity : packageEntity.getEntities(PackageMetadata.TAGS)) {
        tags.add(asTag(package_, tagEntity));
    }
    return tags;
}
Also used : Entity(org.molgenis.data.Entity) UnknownEntityException(org.molgenis.data.UnknownEntityException) SemanticTag(org.molgenis.data.semantic.SemanticTag)

Example 4 with UnknownEntityException

use of org.molgenis.data.UnknownEntityException in project molgenis by molgenis.

the class OntologyScriptInitializerImpl method initialize.

@Override
@RunAsSystem
public void initialize() {
    Resource resource = new ClassPathResource("roc-curve.R");
    if (resource.exists()) {
        long count = dataService.count(SCRIPT, new QueryImpl<>().eq(ScriptMetaData.NAME, ROC_CURVE_SCRIPT_NAME));
        if (count == 0) {
            Entity scriptType = dataService.findOne(ScriptTypeMetaData.SCRIPT_TYPE, new QueryImpl<>().eq(ScriptTypeMetaData.NAME, "R"));
            if (scriptType == null)
                throw new UnknownEntityException("ScriptType R does not exist!");
            String scriptContent;
            try {
                scriptContent = FileCopyUtils.copyToString(new InputStreamReader(resource.getInputStream(), "UTF-8"));
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
            if (dataService.count(SCRIPT_PARAMETER, new QueryImpl<>().eq(ScriptParameterMetaData.NAME, ROC_CURVE_SCRIPT_PARAMETER)) == 0) {
                dataService.add(SCRIPT_PARAMETER, scriptParameterFactory.create().setName(ROC_CURVE_SCRIPT_PARAMETER));
            }
            Entity scriptParameterEntity = dataService.findOne(SCRIPT_PARAMETER, new QueryImpl<>().eq(ScriptParameterMetaData.NAME, ROC_CURVE_SCRIPT_PARAMETER));
            Script script = scriptFactory.create();
            script.setName(ROC_CURVE_SCRIPT_NAME);
            script.setGenerateToken(true);
            script.set(ScriptMetaData.TYPE, scriptType);
            script.setResultFileExtension("png");
            script.setContent(scriptContent);
            script.set(ScriptMetaData.PARAMETERS, Arrays.asList(scriptParameterEntity));
            dataService.add(SCRIPT, script);
            LOG.info("Script entity \"roc\" has been added to the database!");
        } else {
            LOG.info("Script entity \"roc\" already exists in the database!");
        }
    } else {
        LOG.info("R script \"roc-curve.R\" does not exist on classpath!");
    }
}
Also used : Entity(org.molgenis.data.Entity) QueryImpl(org.molgenis.data.support.QueryImpl) InputStreamReader(java.io.InputStreamReader) UnknownEntityException(org.molgenis.data.UnknownEntityException) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) ClassPathResource(org.springframework.core.io.ClassPathResource) RunAsSystem(org.molgenis.security.core.runas.RunAsSystem)

Example 5 with UnknownEntityException

use of org.molgenis.data.UnknownEntityException in project molgenis by molgenis.

the class EntityMappingRepositoryImpl method toEntityMapping.

private EntityMapping toEntityMapping(Entity entityMappingEntity) {
    String identifier = entityMappingEntity.getString(EntityMappingMetaData.IDENTIFIER);
    EntityType targetEntityType;
    try {
        targetEntityType = dataService.getEntityType(entityMappingEntity.getString(EntityMappingMetaData.TARGET_ENTITY_TYPE));
    } catch (UnknownEntityException uee) {
        LOG.error(uee.getMessage());
        targetEntityType = null;
    }
    EntityType sourceEntityType;
    try {
        sourceEntityType = dataService.getEntityType(entityMappingEntity.getString(EntityMappingMetaData.SOURCE_ENTITY_TYPE));
    } catch (UnknownEntityException uee) {
        LOG.error(uee.getMessage());
        sourceEntityType = null;
    }
    List<Entity> attributeMappingEntities = Lists.newArrayList(entityMappingEntity.getEntities(EntityMappingMetaData.ATTRIBUTE_MAPPINGS));
    List<AttributeMapping> attributeMappings = attributeMappingRepository.getAttributeMappings(attributeMappingEntities, sourceEntityType, targetEntityType);
    return new EntityMapping(identifier, sourceEntityType, targetEntityType, attributeMappings);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityMapping(org.molgenis.semanticmapper.mapping.model.EntityMapping) DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) UnknownEntityException(org.molgenis.data.UnknownEntityException) AttributeMapping(org.molgenis.semanticmapper.mapping.model.AttributeMapping)

Aggregations

UnknownEntityException (org.molgenis.data.UnknownEntityException)9 Entity (org.molgenis.data.Entity)6 EntityType (org.molgenis.data.meta.model.EntityType)3 SemanticTag (org.molgenis.data.semantic.SemanticTag)3 RunAsSystem (org.molgenis.security.core.runas.RunAsSystem)3 QueryImpl (org.molgenis.data.support.QueryImpl)2 ImmutableList (com.google.common.collect.ImmutableList)1 Multimap (com.google.common.collect.Multimap)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 UncheckedIOException (java.io.UncheckedIOException)1 Attribute (org.molgenis.data.meta.model.Attribute)1 Package (org.molgenis.data.meta.model.Package)1 DynamicEntity (org.molgenis.data.support.DynamicEntity)1 Ontology (org.molgenis.ontology.core.model.Ontology)1 AttributeMapping (org.molgenis.semanticmapper.mapping.model.AttributeMapping)1 EntityMapping (org.molgenis.semanticmapper.mapping.model.EntityMapping)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1 Resource (org.springframework.core.io.Resource)1