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();
}
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();
}
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();
}
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();
}
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;
}
Aggregations