Search in sources :

Example 1 with Site

use of org.apache.stanbol.entityhub.servicesapi.site.Site in project stanbol by apache.

the class ReferencedSiteSearcher method lookup.

@Override
public Collection<? extends Representation> lookup(String field, Set<String> includeFields, List<String> search, String... languages) throws IllegalStateException {
    // build the query and than return the result
    Site site = getSearchService();
    if (site == null) {
        throw new IllegalStateException("ReferencedSite " + siteId + " is currently not available");
    }
    FieldQuery query = EntitySearcherUtils.createFieldQuery(site.getQueryFactory(), field, includeFields, search, languages);
    if (limit != null) {
        query.setLimit(limit);
    }
    QueryResultList<Representation> results;
    try {
        results = site.find(query);
    } catch (SiteException e) {
        throw new IllegalStateException("Exception while searchign for " + search + '@' + Arrays.toString(languages) + "in the ReferencedSite " + site.getId(), e);
    }
    return results.results();
}
Also used : Site(org.apache.stanbol.entityhub.servicesapi.site.Site) FieldQuery(org.apache.stanbol.entityhub.servicesapi.query.FieldQuery) Representation(org.apache.stanbol.entityhub.servicesapi.model.Representation) SiteException(org.apache.stanbol.entityhub.servicesapi.site.SiteException)

Example 2 with Site

use of org.apache.stanbol.entityhub.servicesapi.site.Site in project stanbol by apache.

the class ReferencedSiteRootResource method getLicenseInfo.

@GET
@Path(value = ReferencedSiteRootResource.LICENSE_PATH + "/{name}")
public Response getLicenseInfo(@PathParam(value = "site") String siteId, @Context HttpHeaders headers, @Context UriInfo uriInfo, @PathParam(value = "name") String name) {
    Site site = getSite(siteId);
    MediaType acceptedMediaType = getAcceptableMediaType(headers, MediaType.APPLICATION_JSON_TYPE);
    if (name == null || name.isEmpty()) {
    // return all
    } else if (name.startsWith(LICENSE_NAME)) {
        try {
            String numberString = name.substring(LICENSE_NAME.length());
            if (numberString.isEmpty()) {
                numberString = "0";
            }
            // license0 is the first one
            int count = -1;
            if (site.getConfiguration().getLicenses() != null) {
                for (License license : site.getConfiguration().getLicenses()) {
                    if (license.getUrl() == null) {
                        count++;
                    }
                    if (Integer.toString(count).equals(numberString)) {
                        ResponseBuilder rb = Response.ok(license2Representation(uriInfo.getAbsolutePath().toString(), license));
                        rb.header(HttpHeaders.CONTENT_TYPE, acceptedMediaType + "; charset=utf-8");
                        // addCORSOrigin(servletContext, rb, headers);
                        return rb.build();
                    }
                }
            }
        } catch (NumberFormatException e) {
            return Response.status(Status.NOT_FOUND).entity("No License found.\n").header(HttpHeaders.ACCEPT, acceptedMediaType).build();
        }
    }
    return Response.status(Response.Status.NOT_FOUND).build();
}
Also used : ManagedSite(org.apache.stanbol.entityhub.servicesapi.site.ManagedSite) Site(org.apache.stanbol.entityhub.servicesapi.site.Site) License(org.apache.stanbol.entityhub.servicesapi.site.License) MediaType(javax.ws.rs.core.MediaType) MediaTypeUtil.getAcceptableMediaType(org.apache.stanbol.commons.web.base.utils.MediaTypeUtil.getAcceptableMediaType) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Path(javax.ws.rs.Path) EntityhubLDPath(org.apache.stanbol.entityhub.ldpath.EntityhubLDPath) GET(javax.ws.rs.GET)

Example 3 with Site

use of org.apache.stanbol.entityhub.servicesapi.site.Site in project stanbol by apache.

the class ReferencedSiteRootResource method handleCorsPreflightEntity.

@OPTIONS
@Path("/entity")
public Response handleCorsPreflightEntity(@PathParam(value = "site") String siteId, @Context HttpHeaders headers) {
    Site site = getSite(siteId);
    ResponseBuilder res = Response.ok();
    if (site instanceof ManagedSite) {
    // enableCORS(servletContext, res, headers, OPTIONS,GET,POST,PUT,DELETE);
    } else {
    // enableCORS(servletContext, res, headers,OPTIONS,GET);
    }
    return res.build();
}
Also used : ManagedSite(org.apache.stanbol.entityhub.servicesapi.site.ManagedSite) Site(org.apache.stanbol.entityhub.servicesapi.site.Site) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) ManagedSite(org.apache.stanbol.entityhub.servicesapi.site.ManagedSite) Path(javax.ws.rs.Path) EntityhubLDPath(org.apache.stanbol.entityhub.ldpath.EntityhubLDPath) OPTIONS(javax.ws.rs.OPTIONS)

Example 4 with Site

use of org.apache.stanbol.entityhub.servicesapi.site.Site in project stanbol by apache.

the class ReferencedSiteRootResource method deleteEntity.

@DELETE
@Path("entity/")
public Response deleteEntity(@PathParam(value = "site") String siteId, @QueryParam(value = "id") String id, @Context HttpHeaders headers) {
    MediaType accepted = getAcceptableMediaType(headers, JerseyUtils.ENTITY_SUPPORTED_MEDIA_TYPES, MediaType.APPLICATION_JSON_TYPE);
    ManagedSite managedSite;
    Site site = getSite(siteId);
    if (site instanceof ManagedSite) {
        managedSite = (ManagedSite) site;
    } else {
        ResponseBuilder builder = Response.status(Status.FORBIDDEN).entity(String.format("The Site '%s' is not managed and does not support " + "create/update nor delete operations", site.getId())).header(HttpHeaders.ACCEPT, accepted);
        // addCORSOrigin(servletContext, builder, headers);
        return builder.build();
    }
    if (id == null || id.isEmpty()) {
        ResponseBuilder builder = Response.status(Status.BAD_REQUEST).entity("The Request does" + "not provide the id of the Entity to delete (parameter 'id').").header(HttpHeaders.ACCEPT, accepted);
        // addCORSOrigin(servletContext, builder, headers);
        return builder.build();
    }
    ResponseBuilder builder;
    try {
        if ("*".equals(id)) {
            managedSite.deleteAll();
            builder = Response.ok();
        } else {
            Entity entity = managedSite.getEntity(id);
            if (entity != null) {
                // delete the entity
                managedSite.delete(id);
                // return the deleted data
                final MediaType acceptedMediaType = getAcceptableMediaType(headers, new HashSet<String>(JerseyUtils.ENTITY_SUPPORTED_MEDIA_TYPES), MediaType.APPLICATION_JSON_TYPE);
                builder = Response.ok(entity).header(HttpHeaders.CONTENT_TYPE, acceptedMediaType + "; charset=utf-8");
            } else {
                builder = Response.status(Status.NOT_FOUND).entity("No Entity with the parsed Id '" + id + "' is present on the ManagedSite '" + managedSite.getId() + "'!").header(HttpHeaders.ACCEPT, accepted);
            }
        }
    } catch (SiteException e) {
        String message = "Exception while deleting '" + id + "' from ManagedSite '" + managedSite.getId() + "'!";
        log.error(message, e);
        builder = Response.status(Status.INTERNAL_SERVER_ERROR).entity(message + ' ' + e.getClass().getSimpleName() + ": " + e.getMessage()).header(HttpHeaders.ACCEPT, accepted);
    }
    // addCORSOrigin(servletContext, builder, headers);
    return builder.build();
}
Also used : ManagedSite(org.apache.stanbol.entityhub.servicesapi.site.ManagedSite) Site(org.apache.stanbol.entityhub.servicesapi.site.Site) Entity(org.apache.stanbol.entityhub.servicesapi.model.Entity) MediaType(javax.ws.rs.core.MediaType) MediaTypeUtil.getAcceptableMediaType(org.apache.stanbol.commons.web.base.utils.MediaTypeUtil.getAcceptableMediaType) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) SiteException(org.apache.stanbol.entityhub.servicesapi.site.SiteException) ManagedSiteException(org.apache.stanbol.entityhub.servicesapi.site.ManagedSiteException) ManagedSite(org.apache.stanbol.entityhub.servicesapi.site.ManagedSite) Path(javax.ws.rs.Path) EntityhubLDPath(org.apache.stanbol.entityhub.ldpath.EntityhubLDPath) DELETE(javax.ws.rs.DELETE)

Example 5 with Site

use of org.apache.stanbol.entityhub.servicesapi.site.Site in project stanbol by apache.

the class EntityhubImpl method importEntity.

/**
 * Imports the Entity
 * @param remoteEntity the Entity to import
 * @return the Entity created and stored within the Entityhub
 * @throws YardException
 */
protected Entity importEntity(Entity remoteEntity) throws YardException {
    if (remoteEntity == null) {
        return null;
    }
    Site site = siteManager.getSite(remoteEntity.getSite());
    if (site == null) {
        log.warn("Unable to import Entity {} because the ReferencedSite {} is currently not active -> return null", remoteEntity.getId(), remoteEntity.getSite());
        return null;
    }
    ValueFactory valueFactory = entityhubYard.getValueFactory();
    // Create the locally managed Entity
    Representation localRep = entityhubYard.create(constructResourceId(DEFAULT_MANAGED_ENTITY_PREFIX));
    Entity localEntity = loadEntity(localRep);
    importEntity(remoteEntity, site, localEntity, valueFactory);
    // Second create and init the Mapping
    Representation entityMappingRepresentation = entityhubYard.create(constructResourceId(DEFAULT_MAPPING_PREFIX));
    Entity entityMappingEntity = loadEntity(entityMappingRepresentation);
    establishMapping(localEntity, remoteEntity, site, entityMappingEntity);
    // Store the entity and the mappedEntity in the entityhubYard
    storeEntity(localEntity);
    storeEntity(entityMappingEntity);
    return localEntity;
}
Also used : Site(org.apache.stanbol.entityhub.servicesapi.site.Site) Entity(org.apache.stanbol.entityhub.servicesapi.model.Entity) Representation(org.apache.stanbol.entityhub.servicesapi.model.Representation) ValueFactory(org.apache.stanbol.entityhub.servicesapi.model.ValueFactory)

Aggregations

Site (org.apache.stanbol.entityhub.servicesapi.site.Site)20 SiteException (org.apache.stanbol.entityhub.servicesapi.site.SiteException)12 Entity (org.apache.stanbol.entityhub.servicesapi.model.Entity)9 HashSet (java.util.HashSet)8 FieldQuery (org.apache.stanbol.entityhub.servicesapi.query.FieldQuery)6 Path (javax.ws.rs.Path)5 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)5 EntityhubLDPath (org.apache.stanbol.entityhub.ldpath.EntityhubLDPath)5 Representation (org.apache.stanbol.entityhub.servicesapi.model.Representation)5 ManagedSite (org.apache.stanbol.entityhub.servicesapi.site.ManagedSite)5 MediaType (javax.ws.rs.core.MediaType)4 MediaTypeUtil.getAcceptableMediaType (org.apache.stanbol.commons.web.base.utils.MediaTypeUtil.getAcceptableMediaType)4 IRI (org.apache.clerezza.commons.rdf.IRI)3 QueryResultListImpl (org.apache.stanbol.entityhub.core.query.QueryResultListImpl)3 ArrayList (java.util.ArrayList)2 GET (javax.ws.rs.GET)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 Graph (org.apache.clerezza.commons.rdf.Graph)2 Viewable (org.apache.stanbol.commons.web.viewable.Viewable)2 EngineException (org.apache.stanbol.enhancer.servicesapi.EngineException)2