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

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


        }
        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

    public Entity getMappingById(String id) throws IllegalArgumentException, EntityhubException{
        if(id == null || id.isEmpty()){
            throw new IllegalArgumentException("The parsed id MUST NOT be NULL nor empty");
        }
        Yard entityhubYard = lookupYard();
        Entity mapping = loadEntity(entityhubYard, id);
        if(mapping == null){
            return null;
        } else if(mapping != null && EntityMapping.isValid(mapping)){
            return mapping;
        } else {
View Full Code Here

    @Override
    public QueryResultList<Entity> findEntities(FieldQuery query) throws YardException{
        QueryResultList<String> references = lookupYard().findReferences(query);
        List<Entity> entities = new ArrayList<Entity>(references.size());
        for(String reference : references){
            Entity entity = lookupLocalEntity(reference);
            if(entity != null){
                entities.add(entity);
            } else {
                log.warn("Unable to create Entity for Reference {} in the Yard " +
                    "usd by the entity hub [id={}] -> ignore reference",
View Full Code Here

        if (symbolId == null || symbolId.isEmpty()) {
            // TODO: how to parse an error message
            throw new WebApplicationException(BAD_REQUEST);
        }
        Entityhub entityhub = ContextHelper.getServiceFromContext(Entityhub.class, servletContext);
        Entity entity;
        try {
            entity = entityhub.getEntity(symbolId);
        } catch (EntityhubException e) {
            throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
        }
View Full Code Here

            if (reference == null || reference.isEmpty()) {
                // TODO: how to parse an error message
                throw new WebApplicationException(BAD_REQUEST);
            }
            Entityhub entityhub = ContextHelper.getServiceFromContext(Entityhub.class, servletContext);
            Entity entity;
            try {
                entity = entityhub.lookupLocalEntity(reference, create);
            } catch (EntityhubException e) {
                throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
            }
View Full Code Here

            return Response.status(Status.BAD_REQUEST).entity("The Request does" +
                    "not provide the id of the Entity to delete (parameter 'id').")
                    .header(HttpHeaders.ACCEPT, accepted).build();
        }
        Entityhub entityhub = ContextHelper.getServiceFromContext(Entityhub.class, servletContext);
        Entity entity;
        try {
            entity = entityhub.delete(id);
        } catch (EntityhubException e) {
            return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage())
            .header(HttpHeaders.ACCEPT, accepted).build();
View Full Code Here

        //for remote Entiteis as suggested by
        // http://incubator.apache.org/stanbol/docs/trunk/entityhub/entityhubandlinkeddata.html
        Map<String,Entity> updated = new HashMap<String,Entity>();
        for(Representation representation : parsed){
            try {
                Entity entity = entityhub.store(representation);
                updated.put(entity.getId(), entity);
            }catch (EntityhubException e) {
                log.error(String.format("Exception while storing Entity %s" +
                        "in the Entityhub.",representation),e);
            }
        }
        //create the response for the Entity
        // for now directly return the added entity. one could also
        // consider returning a seeOther (303) with the get URI for the
        // created/updated entity
        if(updated.isEmpty()){
            // No (valid) data parsed
            ResponseBuilder rb = Response.status(Status.NOT_MODIFIED);
            addCORSOrigin(servletContext, rb, headers);
            return rb.build();
        } else {
            Entity entity = updated.values().iterator().next();
            if(method.equals(HttpMethod.POST)){
                ResponseBuilder rb = Response.created(uriInfo.getAbsolutePathBuilder()
                    .queryParam("id", "{entityId}")
                    .build(entity.getId()));
                addCORSOrigin(servletContext, rb, headers);
                return rb.build();
            } else {
                //return Response.noContent().build();
                //As alternative return the modified entity
View Full Code Here

                return Response.status(Status.BAD_REQUEST).entity("The mapping id (URI) is missing.\n").header(
                    HttpHeaders.ACCEPT, acceptedMediaType).build();
            }
        }
        Entityhub entityhub = ContextHelper.getServiceFromContext(Entityhub.class, servletContext);
        Entity mapping;
        try {
            mapping = entityhub.getMappingById(reference);
        } catch (EntityhubException e) {
            log.error("error while getting the mapping for {}", reference, e);
            return Response.status(Status.INTERNAL_SERVER_ERROR).build();
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.