Package org.apache.stanbol.entityhub.servicesapi.site

Examples of org.apache.stanbol.entityhub.servicesapi.site.ReferencedSiteException


                        initEntityMetadata(entity,true);
                    }
                    return new QueryResultListImpl<Entity>(query, results, Entity.class);
                } catch (YardException e) {
                    if(siteConfiguration.getEntitySearcherType()==null || isOfflineMode()){
                        throw new ReferencedSiteException("Unable to execute query on Cache "+siteConfiguration.getCacheId(),e);
                    } else {
                        log.warn(String.format("Error while performing query on Cache %s! Try to use remote site %s as fallback!",
                            siteConfiguration.getCacheId(),siteConfiguration.getQueryUri()),e);
                    }
                }
            } else {
                if(siteConfiguration.getEntitySearcherType()==null || isOfflineMode()){
                    throw new ReferencedSiteException(String.format("Unable to execute query on Cache %s because it is currently not active",
                        siteConfiguration.getCacheId()));
                } else {
                    log.warn(String.format("Cache %s currently not active will query remote Site %s as fallback",
                        siteConfiguration.getCacheId(),siteConfiguration.getQueryUri()));
                }
            }
        }
        QueryResultList<String> entityIds;
        if(entitySearcher == null) {
            throw new ReferencedSiteException(
                String.format("EntitySearcher %s not available for remote site %s!",siteConfiguration.getEntitySearcherType(),
                    siteConfiguration.getQueryUri()));
        }
        ensureOnline(siteConfiguration.getQueryUri(),entitySearcher.getClass());
        try {
            entityIds = entitySearcher.findEntities(query);
        } catch (IOException e) {
            throw new ReferencedSiteException(String.format("Unable to execute query on remote site %s with entitySearcher %s!",
                    siteConfiguration.getQueryUri(),siteConfiguration.getEntitySearcherType()), e);
        }
        int numResults = entityIds.size();
        List<Entity> entities = new ArrayList<Entity>(numResults);
        int errors = 0;
        ReferencedSiteException lastError = null;
        for(String id : entityIds){
            Entity entity;
            try {
                entity = getEntity(id);
                if(entity == null){
                    log.warn("Unable to create Entity for ID that was selected by an FieldQuery (id="+id+")");
                }
                entities.add(entity);
                //use the position in the list as resultSocre
                entity.getRepresentation().set(RdfResourceEnum.resultScore.getUri(), Float.valueOf((float)numResults));
            } catch (ReferencedSiteException e) {
                lastError = e;
                errors++;
                log.warn(String.format("Unable to get Representation for Entity %s. -> %d Error%s for %d Entities in QueryResult (Reason:%s)",
                        id,errors,errors>1?"s":"",entityIds.size(),e.getMessage()));
            }
            //decrease numResults because it is used as resultScore for entities
            numResults--;
        }
        if(lastError != null){
            if(entities.isEmpty()){
                throw new ReferencedSiteException("Unable to get anly Representations for Entities selected by the parsed Query (Root-Cause is the last Exception trown)",lastError);
            } else {
                log.warn(String.format("Unable to get %d/%d Represetnations for selected Entities.",errors,entityIds.size()));
                log.warn("Stack trace of the last Exception:",lastError);
            }
        }
View Full Code Here


            if(cache != null){
                try {
                    return cache.find(query);
                } catch (YardException e) {
                    if(siteConfiguration.getEntitySearcherType()==null || isOfflineMode()){
                        throw new ReferencedSiteException("Unable to execute query on Cache "+siteConfiguration.getCacheId(),e);
                    } else {
                        log.warn(String.format("Error while performing query on Cache %s! Try to use remote site %s as fallback!",
                            siteConfiguration.getCacheId(),siteConfiguration.getQueryUri()),e);
                    }
                }
            } else {
                if(siteConfiguration.getEntitySearcherType()==null || isOfflineMode()){
                    throw new ReferencedSiteException(String.format("Unable to execute query because Cache %s is currently not active",
                        siteConfiguration.getCacheId()));
                } else {
                    log.warn(String.format("Cache %s currently not active will query remote Site %s as fallback",
                        siteConfiguration.getCacheId(),siteConfiguration.getQueryUri()));
                }
            }
        }
        if(entitySearcher == null){
            throw new ReferencedSiteException(
                String.format("EntitySearcher %s not available for remote site %s!",siteConfiguration.getEntitySearcherType(),
                    siteConfiguration.getQueryUri()));
        }
        ensureOnline(siteConfiguration.getQueryUri(), entitySearcher.getClass());
        try {
            return entitySearcher.find(query);
        } catch (IOException e) {
            throw new ReferencedSiteException("Unable execute Query on remote site "+
                siteConfiguration.getQueryUri(),e);
        }
    }
View Full Code Here

            if(cache != null){
                try {
                    return cache.findReferences(query);
                } catch (YardException e) {
                    if(siteConfiguration.getEntitySearcherType()==null || isOfflineMode()){
                        throw new ReferencedSiteException("Unable to execute query on Cache "+siteConfiguration.getCacheId(),e);
                    } else {
                        log.warn(String.format("Error while performing query on Cache %s! Try to use remote site %s as fallback!",
                            siteConfiguration.getCacheId(),siteConfiguration.getQueryUri()),e);
                    }
                }
            } else {
                if(siteConfiguration.getEntitySearcherType()==null  || isOfflineMode()){
                    throw new ReferencedSiteException(
                        String.format("Unable to execute query on Cache %s because it is currently not active",
                            siteConfiguration.getCacheId()));
                } else {
                    log.warn(String.format("Cache %s currently not active will query remote Site %s as fallback",
                        siteConfiguration.getCacheId(),siteConfiguration.getQueryUri()));
                }
            }
        }
        if(entitySearcher == null){
            throw new ReferencedSiteException(
                String.format("EntitySearcher %s not available for remote site %s!",siteConfiguration.getEntitySearcherType(),
                    siteConfiguration.getQueryUri()));
        }
        ensureOnline(siteConfiguration.getQueryUri(), entitySearcher.getClass());
        try {
            return entitySearcher.findEntities(query);
        } catch (IOException e) {
            throw new ReferencedSiteException("Unable execute Query on remote site "+
                siteConfiguration.getQueryUri(),e);
        }
    }
View Full Code Here

        }
    }
    @Override
    public InputStream getContent(String id, String contentType) throws ReferencedSiteException {
        if(siteConfiguration.getEntityDereferencerType() == null){
            throw new ReferencedSiteException(
                String.format("Unable to get Content for Entity %s because No dereferencer configured for ReferencedSite %s",
                    id,getId()));
        }
        if(dereferencer == null){
            throw new ReferencedSiteException(
                String.format("Dereferencer %s for remote site %s is not available",siteConfiguration.getEntityDereferencerType(),
                siteConfiguration.getAccessUri()));
        }
        ensureOnline(siteConfiguration.getAccessUri(), dereferencer.getClass());
        try {
            return dereferencer.dereference(id, contentType);
        } catch (IOException e) {
            throw new ReferencedSiteException(
                String.format("Unable to load content for Entity %s and mediaType %s from remote site %s by using dereferencer %s",
                    id,contentType,siteConfiguration.getAccessUri(),siteConfiguration.getEntityDereferencerType()),e);
        }
    }
View Full Code Here

                } else if(siteConfiguration.getCacheStrategy() == CacheStrategy.all){
                    return null; //do no remote lokkups on CacheStrategy.all!!
                }
            } catch (YardException e) {
                if (siteConfiguration.getEntityDereferencerType() == null || isOfflineMode()) {
                    throw new ReferencedSiteException(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);
                }
            }
        } else {
            if (siteConfiguration.getEntityDereferencerType() == null || isOfflineMode()) {
                throw new ReferencedSiteException(String.format("Unable to get Represetnation %s because configured Cache %s is currently not available",
                        id, siteConfiguration.getCacheId()));
            } else {
                log.warn(String.format("Cache %s is currently not available. Will use remote site %s to load Representation %s",
                        siteConfiguration.getCacheId(), siteConfiguration.getEntityDereferencerType(), id));
            }
        }
        if (entity == null) { // no cache or not found in cache
            if(dereferencer == null){
                throw new ReferencedSiteException(String.format("Entity Dereferencer %s for accessing remote site %s is not available",
                    siteConfiguration.getEntityDereferencerType(),siteConfiguration.getAccessUri()));
            }
            ensureOnline(siteConfiguration.getAccessUri(), dereferencer.getClass());
            Representation rep = null;
            try {
                rep = dereferencer.dereference(id);
            } catch (IOException e) {
                throw new ReferencedSiteException(
                    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){
View Full Code Here

     * @throws ReferencedSiteException in case {@link #isOfflineMode()} returns
     * <code>true</code>
     */
    private void ensureOnline(String uri, Class<?> clazz) throws ReferencedSiteException {
        if(isOfflineMode()){
            throw new ReferencedSiteException(String.format(
                "Unable to access remote Service %s by using %s because Stanbol runs in OfflineMode",
                uri,clazz.getSimpleName()));
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.stanbol.entityhub.servicesapi.site.ReferencedSiteException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.