use of org.apache.stanbol.entityhub.servicesapi.yard.YardException in project stanbol by apache.
the class YardSite method getEntity.
@Override
public Entity getEntity(String id) throws ManagedSiteException {
Representation rep;
try {
rep = getYard().getRepresentation(id);
} catch (YardException e) {
throw new ManagedSiteException(e.getMessage(), e);
}
if (rep != null) {
Entity entity = new EntityImpl(config.getId(), rep, null);
SiteUtils.initEntityMetadata(entity, siteMetadata, null);
return entity;
} else {
return null;
}
}
use of org.apache.stanbol.entityhub.servicesapi.yard.YardException in project stanbol by apache.
the class YardSite method store.
/**
* Stores the parsed representations to the Yard and also applies the
* configured {@link #getFieldMapper() FieldMappings}.
* @param The representations to store
*/
@Override
public void store(final Iterable<Representation> representations) throws ManagedSiteException {
try {
Yard yard = getYard();
final ValueFactory vf = yard.getValueFactory();
yard.store(new Iterable<Representation>() {
@Override
public Iterator<Representation> iterator() {
return new Iterator<Representation>() {
Iterator<Representation> it = representations.iterator();
@Override
public boolean hasNext() {
return it.hasNext();
}
@Override
public Representation next() {
Representation next = it.next();
fieldMapper.applyMappings(next, next, vf);
return next;
}
@Override
public void remove() {
it.remove();
}
};
}
});
} catch (YardException e) {
throw new ManagedSiteException(e.getMessage(), e);
}
}
use of org.apache.stanbol.entityhub.servicesapi.yard.YardException in project stanbol by apache.
the class YardSite method store.
/**
* Stores the parsed representation to the Yard and also applies the
* configured {@link #getFieldMapper() FieldMappings}.
* @param The representation to store
*/
@Override
public void store(Representation representation) throws ManagedSiteException {
try {
Yard yard = getYard();
fieldMapper.applyMappings(representation, representation, yard.getValueFactory());
yard.store(representation);
} catch (YardException e) {
throw new ManagedSiteException(e.getMessage(), e);
}
}
use of org.apache.stanbol.entityhub.servicesapi.yard.YardException in project stanbol by apache.
the class CacheImpl method setBaseMappings.
@Override
public void setBaseMappings(FieldMapper fieldMapper) throws YardException {
if (isAvailable()) {
FieldMapper old = this.baseMapper;
this.baseMapper = fieldMapper;
try {
CacheUtils.storeBaseMappingsConfiguration(yard, baseMapper);
} catch (YardException e) {
this.baseMapper = old;
throw e;
}
}
}
use of org.apache.stanbol.entityhub.servicesapi.yard.YardException in project stanbol by apache.
the class SolrYard method find.
private QueryResultList<Representation> find(final FieldQuery parsedQuery, SELECT select) throws YardException {
//create a clone of the query, because we need to refine it because the
//query (as executed) needs to be included in the result set
FieldQuery fieldQuery = parsedQuery.clone();
log.debug("find " + fieldQuery);
long start = System.currentTimeMillis();
final Set<String> selected;
if (select == SELECT.QUERY) {
// if query set the fields to add to the result Representations
selected = new HashSet<String>(fieldQuery.getSelectedFields());
// add the score to query results!
selected.add(RdfResourceEnum.resultScore.getUri());
} else {
// otherwise add all fields
selected = null;
}
final SolrQuery query = solrQueryFactoy.parseFieldQuery(fieldQuery, select);
long queryGeneration = System.currentTimeMillis();
if (closed) {
log.warn("The SolrYard '{}' was already closed!", config.getName());
}
QueryResponse response;
try {
response = AccessController.doPrivileged(new PrivilegedExceptionAction<QueryResponse>() {
public QueryResponse run() throws IOException, SolrServerException {
StreamQueryRequest request = new StreamQueryRequest(query);
return request.process(server);
}
});
} catch (PrivilegedActionException pae) {
Exception e = pae.getException();
if (e instanceof SolrServerException) {
if ("unknown handler: /mlt".equals(e.getCause().getMessage())) {
throw new YardException("Solr is missing '<requestHandler name=\"/mlt\"" + " class=\"solr.MoreLikeThisHandler\" startup=\"lazy\" />'" + " in 'solrconfig.xml'", e);
}
throw new YardException("Error while performing Query on SolrServer: " + query.getQuery(), e);
} else if (e instanceof IOException) {
throw new YardException("Unable to access SolrServer", e);
} else {
throw RuntimeException.class.cast(e);
}
}
if (SolrQueryFactory.MLT_QUERY_TYPE.equals(query.getRequestHandler())) {
log.debug("{}", response);
}
long queryTime = System.currentTimeMillis();
// return a queryResultList
QueryResultListImpl<Representation> resultList = new QueryResultListImpl<Representation>(fieldQuery, // by adapting SolrDocuments to Representations
new AdaptingIterator<SolrDocument, Representation>(response.getResults().iterator(), // inline Adapter Implementation
new AdaptingIterator.Adapter<SolrDocument, Representation>() {
@Override
public Representation adapt(SolrDocument doc, Class<Representation> type) {
// use this method for the conversion!
return createRepresentation(doc, selected);
}
}, Representation.class), Representation.class);
long resultProcessing = System.currentTimeMillis();
log.debug(String.format(" ... done [queryGeneration=%dms|queryTime=%dms|resultProcessing=%dms|sum=%dms]", (queryGeneration - start), (queryTime - queryGeneration), (resultProcessing - queryTime), (resultProcessing - start)));
return resultList;
}
Aggregations