use of org.apache.stanbol.entityhub.servicesapi.yard.YardException in project stanbol by apache.
the class ReferencedSiteImpl method getEntity.
@Override
public Entity getEntity(String id) throws SiteException {
Representation rep = null;
Boolean cachedVersion = Boolean.FALSE;
long start = System.currentTimeMillis();
if (cache != null) {
try {
rep = cache.getRepresentation(id);
if (rep == null) {
if (siteConfiguration.getCacheStrategy() == CacheStrategy.all) {
// do no remote lookups on CacheStrategy.all!!
return null;
}
} else {
cachedVersion = Boolean.TRUE;
}
} catch (YardException e) {
if (dereferencer == null) {
throw new SiteException(String.format("Unable to get Represetnation %s form Cache %s", id, siteConfiguration.getCacheId()), e);
} else {
log.warn(String.format("Unable to get Represetnation %s form Cache %s. Will dereference from remote site %s", id, siteConfiguration.getCacheId(), siteConfiguration.getAccessUri()), e);
}
}
}
if (rep == null && dereferencer != null) {
try {
rep = dereferencer.dereference(id);
} catch (IOException e) {
throw new SiteException(String.format("Unable to load Representation for entity %s form remote site %s with dereferencer %s", id, siteConfiguration.getAccessUri(), siteConfiguration.getEntityDereferencerType()), e);
}
// representation loaded from remote site and cache is available
if (rep != null && cache != null) {
// -> cache the representation
try {
start = System.currentTimeMillis();
// return the the cached version
rep = cache.store(rep);
cachedVersion = Boolean.TRUE;
log.debug(" - cached Representation {} in {} ms", id, (System.currentTimeMillis() - start));
} catch (YardException e) {
log.warn(String.format("Unable to cache Represetnation %s in Cache %s! Representation not cached!", id, siteConfiguration.getCacheId()), e);
}
}
}
if (rep != null) {
Entity entity = new EntityImpl(getId(), rep, null);
initEntityMetadata(entity, siteMetadata, singletonMap(RdfResourceEnum.isChached.getUri(), (Object) cachedVersion));
return entity;
} else {
return null;
}
}
use of org.apache.stanbol.entityhub.servicesapi.yard.YardException in project stanbol by apache.
the class CacheImpl method setAdditionalMappings.
/**
* Internally used in the initialisation to be able to parse the Yard instance
*
* @param yard the yard used to set the configured additional mappings
* @param fieldMapper the configuration
* @throws YardException on any error while accessing the yard
*/
protected void setAdditionalMappings(Yard yard, FieldMapper fieldMapper) throws YardException {
FieldMapper old = this.additionalMapper;
this.additionalMapper = fieldMapper;
try {
CacheUtils.storeAdditionalMappingsConfiguration(yard, additionalMapper);
} catch (YardException e) {
this.additionalMapper = old;
throw e;
}
}
use of org.apache.stanbol.entityhub.servicesapi.yard.YardException in project stanbol by apache.
the class SesameYard method executeSparqlFieldQuery.
/**
* Returns the SPARQL result set for a given {@link SparqlFieldQuery} that
* was executed on this yard
* @param con the repository connection to use
* @param fieldQuery the SparqlFieldQuery instance
* @param limit the maximum number of results
* @return the results of the SPARQL query in the {@link #contexts} of the
* Sesame Repository
* @throws RepositoryException on any error while using the parsed connection
* @throws QueryEvaluationException on any error while executing the query
* @throws YardException if the SPARQL query created for the parsed FieldQuery
* was illegal formatted or if the {@link #repository} does not support
* SPARQL.
*/
private TupleQueryResult executeSparqlFieldQuery(RepositoryConnection con, final SparqlFieldQuery fieldQuery, int limit, boolean select) throws RepositoryException, YardException, QueryEvaluationException {
log.debug("> execute FieldQuery: {}", fieldQuery);
String sparqlQueryString = SparqlQueryUtils.createSparqlSelectQuery(fieldQuery, select, limit, SparqlEndpointTypeEnum.Sesame);
log.debug(" - SPARQL Query: {}", sparqlQueryString);
TupleQuery sparqlOuery;
try {
sparqlOuery = con.prepareTupleQuery(QueryLanguage.SPARQL, sparqlQueryString);
} catch (MalformedQueryException e) {
log.error("Unable to pparse SPARQL Query generated for a FieldQuery");
log.error("FieldQuery: {}", fieldQuery);
log.error("SPARQL Query: {}", sparqlQueryString);
log.error("Exception ", e);
throw new YardException("Unable to parse SPARQL query generated for the parse FieldQuery", e);
} catch (UnsupportedQueryTypeException e) {
String message = "The Sesame Repository '" + repository + "'(class: " + repository.getClass().getName() + ") does not support SPARQL!";
log.error(message, e);
throw new YardException(message, e);
}
if (dataset != null) {
//respect the configured contexts
sparqlOuery.setDataset(dataset);
}
return sparqlOuery.evaluate();
}
use of org.apache.stanbol.entityhub.servicesapi.yard.YardException in project stanbol by apache.
the class ClerezzaYard method executeSparqlFieldQuery.
/**
* Returns the SPARQL result set for a given {@link SparqlFieldQuery} that
* was executed on this yard
* @param query the SparqlFieldQuery instance
* @return the results of the SPARQL query in the yard
* @throws YardException in case the generated SPARQL query could not be parsed
* or the generated Query is not an SPARQL SELECT query.
*/
private ResultSet executeSparqlFieldQuery(final SparqlFieldQuery query) throws YardException {
int limit = QueryUtils.getLimit(query, getConfig().getDefaultQueryResultNumber(), getConfig().getMaxQueryResultNumber());
SelectQuery sparqlQuery;
String sparqlQueryString = SparqlQueryUtils.createSparqlSelectQuery(query, false, limit, EndpointTypeEnum.Standard);
try {
sparqlQuery = (SelectQuery) QueryParser.getInstance().parse(sparqlQueryString);
} catch (ParseException e) {
log.error("ParseException for SPARQL Query in findRepresentation");
log.error("FieldQuery: " + query);
log.error("SPARQL Query: " + sparqlQueryString);
throw new YardException("Unable to parse SPARQL query generated for the parse FieldQuery", e);
} catch (ClassCastException e) {
log.error("ClassCastExeption because parsed SPARQL Query is not of Type " + SelectQuery.class);
log.error("FieldQuery: " + query);
log.error("SPARQL Query: " + sparqlQueryString);
throw new YardException("Unable to parse SPARQL SELECT query generated for the parse FieldQuery", e);
}
return tcManager.executeSparqlQuery(sparqlQuery, graph);
}
use of org.apache.stanbol.entityhub.servicesapi.yard.YardException in project stanbol by apache.
the class YardSite method findEntities.
@Override
public QueryResultList<Entity> findEntities(FieldQuery query) throws ManagedSiteException {
QueryResultList<Representation> results;
try {
results = getYard().findRepresentation(query);
} catch (YardException e) {
throw new ManagedSiteException(e.getMessage(), e);
}
return new QueryResultListImpl<Entity>(results.getQuery(), new AdaptingIterator<Representation, Entity>(results.iterator(), new AdaptingIterator.Adapter<Representation, Entity>() {
private final String siteId = config.getId();
@Override
public Entity adapt(Representation value, Class<Entity> type) {
Entity entity = new EntityImpl(siteId, value, null);
SiteUtils.initEntityMetadata(entity, siteMetadata, null);
return entity;
}
}, Entity.class), Entity.class);
}
Aggregations