Search in sources :

Example 11 with YardException

use of org.apache.stanbol.entityhub.servicesapi.yard.YardException in project stanbol by apache.

the class ClerezzaYard method writeLockGraph.

/**
     * @return
     * @throws YardException
     */
private Lock writeLockGraph() throws YardException {
    if (immutable) {
        throw new YardException("Unable modify data in ClerezzaYard '" + getId() + "' because the backing RDF graph '" + yardGraphUri + "' is read-only!");
    }
    final Lock writeLock;
    writeLock = graph.getLock().writeLock();
    writeLock.lock();
    return writeLock;
}
Also used : YardException(org.apache.stanbol.entityhub.servicesapi.yard.YardException) Lock(java.util.concurrent.locks.Lock)

Example 12 with YardException

use of org.apache.stanbol.entityhub.servicesapi.yard.YardException in project stanbol by apache.

the class SesameYard method store.

protected final Iterable<Representation> store(Iterable<Representation> representations, boolean allowCreate) throws IllegalArgumentException, YardException {
    RepositoryConnection con = null;
    try {
        con = repository.getConnection();
        con.begin();
        ArrayList<Representation> added = new ArrayList<Representation>();
        for (Representation representation : representations) {
            if (representation != null) {
                //reassign
                Representation stored = store(con, representation, allowCreate, false);
                //to check if the store was successful
                if (stored != null) {
                    added.add(stored);
                } else {
                    //can only be the case if allowCreate==false (update was called)
                    log.warn(String.format("Unable to update Representation %s in Yard %s because it is not present!", representation.getId(), getId()));
                }
            }
        //ignore null values in the parsed Iterable!
        }
        con.commit();
        return added;
    } catch (RepositoryException e) {
        throw new YardException("Unable to remove parsed Representations", e);
    } catch (IllegalArgumentException e) {
        try {
            //to avoid Exception logs in case store(..) throws an Exception
            //in the case allowCreate and canNotCreateIsError do not allow
            //the store operation
            con.rollback();
        } catch (RepositoryException ignore) {
        }
        throw e;
    } finally {
        if (con != null) {
            try {
                con.close();
            } catch (RepositoryException ignore) {
            }
        }
    }
}
Also used : RepositoryConnection(org.openrdf.repository.RepositoryConnection) YardException(org.apache.stanbol.entityhub.servicesapi.yard.YardException) ArrayList(java.util.ArrayList) RdfRepresentation(org.apache.stanbol.entityhub.model.sesame.RdfRepresentation) Representation(org.apache.stanbol.entityhub.servicesapi.model.Representation) RepositoryException(org.openrdf.repository.RepositoryException)

Example 13 with YardException

use of org.apache.stanbol.entityhub.servicesapi.yard.YardException in project stanbol by apache.

the class SesameYard method remove.

@Override
public final void remove(Iterable<String> ids) throws IllegalArgumentException, YardException {
    if (ids == null) {
        throw new IllegalArgumentException("The parsed Iterable over the IDs to remove MUST NOT be NULL!");
    }
    RepositoryConnection con = null;
    try {
        con = repository.getConnection();
        con.begin();
        for (String id : ids) {
            if (id != null) {
                remove(con, sesameFactory.createURI(id));
            }
        }
        con.commit();
    } catch (RepositoryException e) {
        throw new YardException("Unable to remove parsed Representations", e);
    } finally {
        if (con != null) {
            try {
                con.close();
            } catch (RepositoryException ignore) {
            }
        }
    }
}
Also used : RepositoryConnection(org.openrdf.repository.RepositoryConnection) YardException(org.apache.stanbol.entityhub.servicesapi.yard.YardException) RepositoryException(org.openrdf.repository.RepositoryException)

Example 14 with YardException

use of org.apache.stanbol.entityhub.servicesapi.yard.YardException in project stanbol by apache.

the class SesameYard method findReferences.

@Override
public QueryResultList<String> findReferences(FieldQuery parsedQuery) throws YardException, IllegalArgumentException {
    if (parsedQuery == null) {
        throw new IllegalArgumentException("The parsed query MUST NOT be NULL!");
    }
    final SparqlFieldQuery query = SparqlFieldQueryFactory.getSparqlFieldQuery(parsedQuery);
    RepositoryConnection con = null;
    TupleQueryResult results = null;
    try {
        con = repository.getConnection();
        con.begin();
        //execute the query
        int limit = QueryUtils.getLimit(query, getConfig().getDefaultQueryResultNumber(), getConfig().getMaxQueryResultNumber());
        results = executeSparqlFieldQuery(con, query, limit, false);
        //parse the results
        List<String> ids = limit > 0 ? new ArrayList<String>(limit) : new ArrayList<String>();
        while (results.hasNext()) {
            BindingSet result = results.next();
            Value value = result.getValue(query.getRootVariableName());
            if (value instanceof Resource) {
                ids.add(value.stringValue());
            }
        }
        con.commit();
        return new QueryResultListImpl<String>(query, ids, String.class);
    } catch (RepositoryException e) {
        throw new YardException("Unable to execute findReferences query", e);
    } catch (QueryEvaluationException e) {
        throw new YardException("Unable to execute findReferences query", e);
    } finally {
        if (results != null) {
            //close the result if present
            try {
                results.close();
            } catch (QueryEvaluationException ignore) {
            /* ignore */
            }
        }
        if (con != null) {
            try {
                con.close();
            } catch (RepositoryException ignore) {
            /* ignore */
            }
        }
    }
}
Also used : RepositoryConnection(org.openrdf.repository.RepositoryConnection) BindingSet(org.openrdf.query.BindingSet) Resource(org.openrdf.model.Resource) RepositoryException(org.openrdf.repository.RepositoryException) YardException(org.apache.stanbol.entityhub.servicesapi.yard.YardException) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) SparqlFieldQuery(org.apache.stanbol.entityhub.query.sparql.SparqlFieldQuery) Value(org.openrdf.model.Value) QueryResultListImpl(org.apache.stanbol.entityhub.core.query.QueryResultListImpl) TupleQueryResult(org.openrdf.query.TupleQueryResult)

Example 15 with YardException

use of org.apache.stanbol.entityhub.servicesapi.yard.YardException in project stanbol by apache.

the class SesameYard method isRepresentation.

@Override
public boolean isRepresentation(String id) throws YardException {
    if (id == null) {
        throw new IllegalArgumentException("The parsed id MUST NOT be NULL!");
    }
    if (id.isEmpty()) {
        throw new IllegalArgumentException("The parsed id MUST NOT be EMPTY!");
    }
    RepositoryConnection con = null;
    try {
        con = repository.getConnection();
        con.begin();
        boolean state = isRepresentation(con, sesameFactory.createURI(id));
        con.commit();
        return state;
    } catch (RepositoryException e) {
        throw new YardException("Unable to check for Representation " + id, e);
    } finally {
        if (con != null) {
            try {
                con.close();
            } catch (RepositoryException ignore) {
            }
        }
    }
}
Also used : RepositoryConnection(org.openrdf.repository.RepositoryConnection) YardException(org.apache.stanbol.entityhub.servicesapi.yard.YardException) RepositoryException(org.openrdf.repository.RepositoryException)

Aggregations

YardException (org.apache.stanbol.entityhub.servicesapi.yard.YardException)31 Representation (org.apache.stanbol.entityhub.servicesapi.model.Representation)15 RepositoryConnection (org.openrdf.repository.RepositoryConnection)10 RepositoryException (org.openrdf.repository.RepositoryException)10 IOException (java.io.IOException)9 SolrServerException (org.apache.solr.client.solrj.SolrServerException)6 PrivilegedActionException (java.security.PrivilegedActionException)5 ArrayList (java.util.ArrayList)5 QueryResultListImpl (org.apache.stanbol.entityhub.core.query.QueryResultListImpl)5 RdfRepresentation (org.apache.stanbol.entityhub.model.sesame.RdfRepresentation)5 EntityImpl (org.apache.stanbol.entityhub.core.model.EntityImpl)4 Entity (org.apache.stanbol.entityhub.servicesapi.model.Entity)4 ManagedSiteException (org.apache.stanbol.entityhub.servicesapi.site.ManagedSiteException)4 HashSet (java.util.HashSet)3 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)3 SolrDocument (org.apache.solr.common.SolrDocument)3 SolrInputDocument (org.apache.solr.common.SolrInputDocument)3 SparqlFieldQuery (org.apache.stanbol.entityhub.query.sparql.SparqlFieldQuery)3 FieldMapper (org.apache.stanbol.entityhub.servicesapi.mapping.FieldMapper)3 FieldQuery (org.apache.stanbol.entityhub.servicesapi.query.FieldQuery)3