Package org.apache.stanbol.entityhub.servicesapi.model

Examples of org.apache.stanbol.entityhub.servicesapi.model.Entity


                try {
                    // When using the Cache, directly get the representations!
                    QueryResultList<Representation> representations = cache.findRepresentation((query));
                    results = new ArrayList<Entity>(representations.size());
                    for (Representation result : representations) {
                        Entity entity = new EntityImpl(getId(), result, null);
                        results.add(entity);
                        initEntityMetadata(entity, siteMetadata,
                            singletonMap(RdfResourceEnum.isChached.getUri(), (Object) Boolean.TRUE));
                    }
                    return new QueryResultListImpl<Entity>(query, results, Entity.class);
                } catch (YardException e) {
                    if (siteConfiguration.getEntitySearcherType() == null || isOfflineMode()) {
                        throw new SiteException("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 SiteException(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 SiteException(String.format("EntitySearcher %s not available for remote site %s!",
                siteConfiguration.getEntitySearcherType(), siteConfiguration.getQueryUri()));
        }
        ensureOnline(siteConfiguration.getQueryUri(), entitySearcher.getClass());
        try {
            log.trace("Will use an entity-searcher [type :: {}][query-uri :: {}].", entitySearcher.getClass()
                    .toString(), EntitySearcher.QUERY_URI);
            entityIds = entitySearcher.findEntities(query);
        } catch (IOException e) {
            throw new SiteException(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;
        SiteException 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 (SiteException e) {
                lastError = e;
                errors++;
                log.warn(String
View Full Code Here


    }

    @Override
    public Entity getEntity(String id) throws SiteException {
        Cache cache = getCache();
        Entity entity = null;
        long start = System.currentTimeMillis();
        if (cache != null) {
            try {
                Representation rep = cache.getRepresentation(id);
                if (rep != null) {
View Full Code Here

        return lookupLocalEntity(entity,false);
    }

    @Override
    public Entity lookupLocalEntity(String entityId, boolean create) throws YardException {
        Entity entity = getEntity(entityId);
        if(entity != null){
            return entity;
        } else {
            //parsed reference was not a locally managed entity ->
            //search for an mapped Entity
            Entity entityMapping = getMappingBySource(entityId);
            if(entityMapping != null){
                entity = getEntity(EntityMapping.getTargetId(entityMapping));
                if(entity != null){
                    return entity;
                } else {
                    log.warn("Unable to find Entity for Entity Mapping "+entityMapping+"!");
                    return recoverEntity(EntityMapping.getTargetId(entityMapping));
                }
            } else if(create){
                //search if the parsed reference is known by any referenced site
                // and if YES, create a new Symbol
                Entity remoteEntity = siteManager.getEntity(entityId);
                 if(remoteEntity == null){ //id not found by any referred site
                     return null;
                 } else {
                     return importEntity(remoteEntity);
                 }
View Full Code Here

            }
        }
    }
    @Override
    public final Entity importEntity(String reference) throws IllegalStateException, IllegalArgumentException, YardException {
        Entity entity = getEntity(reference);
        if(entity == null){
            Entity entityMapping = getMappingBySource(reference);
            if(entityMapping == null){
                Entity remoteEntity = siteManager.getEntity(reference);
                if(remoteEntity == null){
                    return null;
                } else {
                    return importEntity(remoteEntity);
                }
View Full Code Here

    public final Entity getEntity(String entityId) throws IllegalArgumentException,IllegalStateException, YardException {
        if(entityId == null || entityId.isEmpty()){
            throw new IllegalArgumentException("The parsed id MUST NOT be NULL nor empty!");
        }
        Yard entityhubYard = lookupYard();
        Entity entity = loadEntity(entityhubYard, entityId);
        if(entity == null){
            return null;
        } else if (ManagedEntity.canWrap(entity)){
            return entity;
        } else {
View Full Code Here

            throw new IllegalArgumentException("The parsed Representation MUST NOT be NULL!");
        }
        Yard yard = lookupYard();
        //parse only the id of the representation, because we need the current
        //stored version of the entity!
        Entity entity = loadEntity(yard, representation.getId());
        //now we need to check if the parsed representation is the data or the
        //metadata of the Entity
        ManagedEntity updated;
        if(entity == null || representation.getId().equals(entity.getRepresentation().getId())){
            //update the data or create a new entity
            updated = ManagedEntity.init(new EntityImpl(config.getID(), representation,
                entity != null ? entity.getMetadata() : null),
                config.getDefaultManagedEntityState());
            if(entity == null){ //add creation date
                updated.setCreated(new Date());
            }
        } else {
            //update the metadata
            entity = new EntityImpl(config.getID(), entity.getRepresentation(),
                representation);
            //we need to validate the metadata
            updated = ManagedEntity.init(
                entity, config.getDefaultManagedEntityState());
        }
View Full Code Here

    public final Entity delete(String id) throws EntityhubException, IllegalArgumentException {
        if(id == null || id.isEmpty()){
            throw new IllegalArgumentException("The parsed id MUST NOT be NULL nor emtpty!");
        }
        Yard yard = lookupYard();
        Entity entity = loadEntity(yard, id);
        if(entity != null){
            log.debug("delete Entity {} as requested by the parsed id {}",entity.getId(),id);
            //we need to remove all mappings for this Entity
            deleteMappingsbyTarget(yard,entity.getId());
            deleteEntity(yard,entity);
        } else {
            log.debug("Unable to delete Entity for id {}, because no Entity for this id is" +
                "managed by the Entityhub",id);
        }
View Full Code Here

        }
        if(state == null){
            throw new IllegalStateException("The parsed state for the Entity MUST NOT ne NULL");
        }
        Yard yard = lookupYard();
        Entity entity = loadEntity(yard, id);
        if(entity != null){
            ManagedEntity managed = new ManagedEntity(entity);
            if(managed.getState() != state){
                managed.setState(state);
                storeEntity(yard, entity);
View Full Code Here

        }
        Yard entityhubYard = lookupYard();
        ValueFactory valueFactory = entityhubYard.getValueFactory();
        //Create the locally managed Entity
        Representation localRep = entityhubYard.create(constructResourceId(DEFAULT_MANAGED_ENTITY_PREFIX));
        Entity localEntity = loadEntity(entityhubYard, localRep);
        importEntity(remoteEntity, site, localEntity, valueFactory);

        //Second create and init the Mapping
        Representation entityMappingRepresentation = entityhubYard.create(
            constructResourceId(DEFAULT_MAPPING_PREFIX));
        Entity entityMappingEntity = loadEntity(entityhubYard, entityMappingRepresentation);
        establishMapping(localEntity, remoteEntity, site, entityMappingEntity);
       
        //Store the entity and the mappedEntity in the entityhubYard
        storeEntity(entityhubYard, localEntity);
        storeEntity(entityhubYard,entityMappingEntity);
View Full Code Here

        fieldQuery.setConstraint(RdfResourceEnum.mappingSource.getUri(), new ReferenceConstraint(reference));
        Yard entityhubYard = lookupYard();
        QueryResultList<Representation> resultList = entityhubYard.findRepresentation(fieldQuery);
        if(!resultList.isEmpty()){
            Iterator<Representation> resultIterator = resultList.iterator();
            Entity mapping = loadEntity(entityhubYard, resultIterator.next());
           //print warnings in case of multiple mappings
            if(resultIterator.hasNext()){
                log.warn("Multiple Mappings found for Entity {}!",reference);
                log.warn("  > {} -> returned instance",mapping.getId());
                while(resultIterator.hasNext()){
                    log.warn("  > {} -> ignored",resultIterator.next());
                }
            }
            if(!EntityMapping.isValid(mapping)){
View Full Code Here

TOP

Related Classes of org.apache.stanbol.entityhub.servicesapi.model.Entity

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.