@Override public void close() throws IOException { flush(); } };
@Override public ElmoFinder<T> withDisplayName (final @Nonnull String displayName) { final ElmoFinder<T> clone = (ElmoFinder<T>) clone(); clone.displayName = displayName; return clone; }
/******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Nonnull @Override public Finder<Taxon> findTaxa() { return new ElmoTaxonomyFinder<Taxon>(Taxon.class); }
/******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Nonnull @Override public Finder<Taxon> findSubTaxa() { try { log.debug("findSubTaxa() - {}", getDisplayName()); final List<Taxon> result = new ArrayList<Taxon>(); for (final Concept skosConcept : as(Concept.class).getSkosNarrowers()) { final QName id = skosConcept.getQName(); final InternalElmoTaxon concept = ((ElmoTaxonomy)taxonomy).conceptFactory.find(id); concept.setBindings(repository, taxonomy); result.add(concept); } return new ElmoFinder<Taxon>(result); } catch (NotFoundException e) { throw new RuntimeException(e); } }
@Override @Nonnull public Taxonomy build() { final QName qName = new QName(id.stringValue()); final InternalElmoTaxonomy taxonomy = taxonomyFactory.create(qName); taxonomy.setBindings((Repository)repository); taxonomy.init(this); // taxonomy.getLookup().lookup(DcResource.class).setDcDescription("THE DESCRIPTION"); Taxonomy taxonomy2 = taxonomy; for (final Initializer<Taxonomy> initializer : getInitializers()) { taxonomy2 = initializer.initialize(taxonomy2); } return taxonomy2; } };
@Override @Nonnull public Taxon build() { log.debug("createTaxon().build({})", this); final QName qName = new QName(id.stringValue()); final InternalElmoTaxon taxon = conceptFactory.create(qName); taxon.setBindings(repository, ElmoTaxonomy.this); taxon.init(this, ElmoTaxonomy.this); Taxon taxon2 = taxon; for (final Initializer<Taxon> initializer : getInitializers()) { taxon2 = initializer.initialize(taxon2); } return taxon2; } };
new ArrayList<Taxon>(getAnonymousSynonym().findSynonyms().results()); if (as(Entity.class).getQName().equals(i.next().as(Entity.class).getQName())) return new ElmoFinder<Taxon>(synonyms); return new ElmoFinder<Taxon>(Collections.<Taxon>emptyList());
@Override @Nonnull public Finder<Taxon> findSynonyms() { try // FIXME: workaround because the @rdf annotation of this.synonym doesn't work { final SesameManager em = (SesameManager)ElmoManagerThreadLocal.get(); final ResourceManager<Resource> rm = em.getResourceManager(); final RepositoryResult<Statement> triples = em.getConnection().getStatements(null, new URIImpl(ElmoTaxonomyVocabulary.URI_SCIENTIFIC_NAME_ID), rm.createResource(getLookup().lookup(Entity.class).getQName())); final List<Taxon> synonyms = new ArrayList<Taxon>(); while (triples.hasNext()) { final URI uri = (URI)triples.next().getSubject(); synonyms.add(((InternalElmoTaxonomy)taxonomy)._findConcept(uri.stringValue())); } return new ElmoFinder<Taxon>(synonyms); } catch (NotFoundException e) { throw new RuntimeException(e); } catch (RepositoryException e) { throw new RuntimeException(e); } }
setDisplayNames(as(Entity.class), displayable); final Concept skosConcept = as(Concept.class); skosConcept.getSkosInSchemes().add(taxonomy.as(ConceptScheme.class)); addStatement(ElmoTaxonomyVocabulary.URI_SCIENTIFIC_NAME, scientificName); // FIXME: workaround because the @rdf annotation doesn't work addStatement(ElmoTaxonomyVocabulary.URI_SPECIFIC_EPITHET, specificEpithet); // FIXME: workaround because the @rdf annotation doesn't work addStatement(ElmoTaxonomyVocabulary.URI_SCIENTIFIC_NAME_ID, scientificNameId); // FIXME: workaround because the @rdf annotation of this.scientificNameId doesn't work addStatement(ElmoTaxonomyVocabulary.URI_TAXON_RANK, rankAsString); // FIXME: workaround because the @rdf annotation of this.rank doesn't work
/******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Nonnull @Override public Taxon getTopTaxon() { log.debug("getTopConcept() - @{}", Integer.toHexString(System.identityHashCode(this))); final Set<Concept> topConcepts = as(ConceptScheme.class).getSkosHasTopConcepts(); final InternalElmoTaxon concept = (InternalElmoTaxon)topConcepts.iterator().next(); concept.setBindings(repository, this); // return concept; return Wrapper.wrap(concept); // FIXME: shouldn't be wrapped by the Proxy? }
/******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Override @Nonnull public <T> T as (final @Nonnull Class<T> clazz) { if (Exporter.class.equals(clazz)) { return clazz.cast(new ElmoExporter(repository)); } if (Identifiable.class.equals(clazz)) { final Id id = new Id(entity.getQName().getNamespaceURI() + entity.getQName().getLocalPart()); return clazz.cast(new DefaultIdentifiable(id)); } return super.as(clazz); }
public Taxon initialize (final @Nonnull Taxon taxon) { getLookup().lookup(Concept.class).getSkosNarrowers().add(taxon.getLookup().lookup(Concept.class)); // as(Concept.class).getSkosNarrowers().add(taxon.as(Concept.class)); FIXME return taxon; } });
/******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ public void export (final @Nonnull File file) throws IOException { log.info("Exporting repository to {}", file); final String fileName = file.getName().toLowerCase(); export(new FileOutputStream(file), fileName); }
/******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Nonnull @Override public Taxon.Builder createTopTaxon() { return createTaxon().withInitializer(new Initializer<Taxon>() { @Override @Nonnull public Taxon initialize (final @Nonnull Taxon taxon) { getLookup().lookup(ConceptScheme.class).getSkosHasTopConcepts().add(taxon.getLookup().lookup(Concept.class)); // as(ConceptScheme.class).getSkosHasTopConcepts().add(taxon.as(Concept.class)); return taxon; } }); }
/******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ public <T> T as (final @Nonnull Class<T> clazz) { if (Importer.class.equals(clazz)) { return clazz.cast(new ElmoImporter()); } throw new AsException(clazz); }
/******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Override public synchronized Taxon findOrCreateAnonymousTaxon (final @Nonnull String id) { log.debug("findOrCreateAnonymousTaxon({})", id); final QName qName = new QName(id); InternalElmoTaxon taxon = null; // FIXME anonymousTaxonFactory.find(qName); // InternalElmoAnonymousTaxon taxon = null; // FIXME anonymousTaxonFactory.find(qName); if (taxon == null) { taxon = conceptFactory.create(qName); // taxon = anonymousTaxonFactory.create(qName); taxon.setBindings(repository, this); // taxon.getLookup().lookup(Concept.class).getSkosInSchemes().add(getLookup().lookup(ConceptScheme.class)); // FIXME: use as() } return taxon; }
@Override @Nonnull public Taxon initialize (final @Nonnull Taxon taxon) { getLookup().lookup(ConceptScheme.class).getSkosHasTopConcepts().add(taxon.getLookup().lookup(Concept.class)); // as(ConceptScheme.class).getSkosHasTopConcepts().add(taxon.as(Concept.class)); return taxon; } });
private static void setDisplayNames (final @Nonnull Entity entity, final @Nonnull LocalizedDisplayable displayable) { final SortedMap<String, Locale> sortedMap = new TreeMap<String, Locale>(); for (final Entry<Locale, String> entry : displayable.getDisplayNames().entrySet()) { if (!entry.getValue().equals("")) { sortedMap.put(languageCode(entry.getKey()), entry.getKey()); } } for (final Entry<String, Locale> entry : sortedMap.entrySet()) { final Locale locale = entry.getValue(); RDFUtils.setDisplayName(entity, displayable.getDisplayName(locale), locale); } }
/******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Override public Taxonomy findTaxonomyByName (final @Nonnull String name, final @Nonnull Object repository) throws NotFoundException { log.debug("findTaxonomyByName({}, {})", name, repository); // FIXME: handle the repository! final ElmoQuery query = em.createQuery(QUERY_TAXONOMY_BY_NAME).setParameter("name", name); final Entity entity = (Entity)query.getSingleResult(); final InternalElmoTaxonomy taxonomy = taxonomyFactory.find(entity.getQName()); // final ElmoTaxonomy taxonomy = (ElmoTaxonomy)query.getSingleResult(); taxonomy.setBindings((Repository)repository); return Wrapper.wrap(taxonomy); }
private void addStatement (final @Nonnull String uri, final @Nonnull String string) { final SesameManager em = (SesameManager)ElmoManagerThreadLocal.get(); final ResourceManager<Resource> rm = em.getResourceManager(); try { em.getConnection().add(rm.createResource(getLookup().lookup(Entity.class).getQName()), new URIImpl(uri), em.getLiteralManager().getLiteral(string)); } catch (RepositoryException e) { throw new RuntimeException(e); } }