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;
}
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;
}
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;
}
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!");
}
}
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);
}
Aggregations