use of org.apache.stanbol.entityhub.servicesapi.site.SiteConfiguration in project stanbol by apache.
the class EntityhubImpl method establishMapping.
/**
* Creates a new {@link EntityMapping} for the parsed source and target
* {@link Entity}. This also sets the State and the expire date based on the
* configurations of the ReferencesSite of the source entity and the defaults of the
* Entityhub
* @param localEntity the locally managed entity (target for the mapping)
* @param remoteEntity the remote Entity (source for the mapping)
* @param site the referenced site managing the source Entity
* @param entityMappingRepresentation the Entity for the mapping
* @return the EntityMapping
*/
private EntityMapping establishMapping(Entity localEntity, Entity remoteEntity, Site site, Entity entityMappingEntity) {
EntityMapping entityMapping = EntityMapping.init(entityMappingEntity);
//now init the mappingState and the expireDate based on the config of the
//ReferencedSite of the source entity (considering also the defaults of the entityhub)
SiteConfiguration siteConfig = site.getConfiguration();
MappingState mappingState = siteConfig.getDefaultMappedEntityState();
if (mappingState == null) {
mappingState = config.getDefaultMappingState();
}
entityMapping.setState(mappingState);
long expireDuration = siteConfig.getDefaultExpireDuration();
if (expireDuration > 0) {
Date expireDate = new Date(System.currentTimeMillis() + expireDuration);
entityMapping.setExpires(expireDate);
}
entityMapping.setSourceId(remoteEntity.getId());
entityMapping.setTargetId(localEntity.getId());
//initialise additional metadata
entityMapping.setCreated(new Date());
return entityMapping;
}
use of org.apache.stanbol.entityhub.servicesapi.site.SiteConfiguration in project stanbol by apache.
the class ReferencedSiteRootResource method site2Representation.
/*
* Referenced Site Metadata
*/
/**
* Transforms a site to a Representation that can be serialised
* @param context
* @return
*/
private Representation site2Representation(Site site, String id) {
RdfValueFactory valueFactory = RdfValueFactory.getInstance();
RdfRepresentation rep = valueFactory.createRepresentation(id);
String namespace = NamespaceEnum.entityhub.getNamespace();
rep.add(namespace + "localMode", site.supportsLocalMode());
rep.add(namespace + "supportsSearch", site.supportsSearch());
SiteConfiguration config = site.getConfiguration();
rep.add("http://www.w3.org/2000/01/rdf-schema#label", config.getName());
rep.add("http://www.w3.org/1999/02/22-rdf-syntax-ns#type", valueFactory.createReference(namespace + "ReferencedSite"));
if (config.getDescription() != null) {
rep.add("http://www.w3.org/2000/01/rdf-schema#description", config.getDescription());
}
if (config.getAttribution() != null) {
rep.add("http://creativecommons.org/ns#attributionName", config.getAttribution());
}
if (config.getAttributionUrl() != null) {
rep.add("http://creativecommons.org/ns#attributionURL", config.getAttributionUrl());
}
//add the licenses
if (config.getLicenses() != null) {
int count = 0;
for (License license : config.getLicenses()) {
String licenseUrl;
if (license.getUrl() != null) {
licenseUrl = license.getUrl();
} else {
licenseUrl = id + (!id.endsWith("/") ? "/" : "") + LICENSE_PATH + '/' + LICENSE_NAME + (count > 0 ? count : "");
count++;
}
//if defined add the name to dc:license
if (license.getName() != null) {
rep.add("http://purl.org/dc/terms/license", licenseUrl);
}
//link to the license via cc:license
rep.add("http://creativecommons.org/ns#license", licenseUrl);
}
}
if (config.getEntityPrefixes() != null) {
for (String prefix : config.getEntityPrefixes()) {
rep.add(namespace + "entityPrefix", prefix);
}
} else {
//all entities are allowed/processed
rep.add(namespace + "entityPrefix", "*");
}
if (config instanceof ReferencedSiteConfiguration) {
ReferencedSiteConfiguration refConfig = (ReferencedSiteConfiguration) config;
if (refConfig.getCacheStrategy() != null) {
rep.add(namespace + "cacheStrategy", valueFactory.createReference(namespace + "cacheStrategy-" + refConfig.getCacheStrategy().name()));
}
//add the accessUri and queryUri
if (refConfig.getAccessUri() != null) {
rep.add(namespace + "accessUri", valueFactory.createReference(refConfig.getAccessUri()));
}
if (refConfig.getQueryUri() != null) {
rep.add(namespace + "queryUri", valueFactory.createReference(refConfig.getQueryUri()));
}
}
return rep;
}
use of org.apache.stanbol.entityhub.servicesapi.site.SiteConfiguration in project stanbol by apache.
the class EntityhubImpl method importEntity.
/**
* Imports a {@link Entity} from a {@link Site}. This Method imports
* the {@link Representation} by applying all configured mappings. It also
* sets the {@link ManagedEntityState} to the configured default value by the
* referenced site of the imported entity or the default for the Entityhub
* if the site does not define this configuration.<p>
* @param remoteEntity The entity to import
* @param site the referenced site of the entity to import
* @param localEntity the target entity for the import
* @param valueFactory the valusFactory used to create instance while importing
*/
private void importEntity(Entity remoteEntity, Site site, Entity localEntity, ValueFactory valueFactory) {
SiteConfiguration siteConfig = site.getConfiguration();
ManagedEntityState state;
state = siteConfig.getDefaultManagedEntityState();
if (state == null) {
state = config.getDefaultManagedEntityState();
}
//this wrapper allows to use an API to write metadata
ManagedEntity managedEntity = ManagedEntity.init(localEntity, state);
FieldMapper siteMapper = site.getFieldMapper();
FieldMapper mapper = this.fieldMapper.clone();
for (FieldMapping siteMapping : siteMapper.getMappings()) {
mapper.addMapping(siteMapping);
}
//TODO: As soon as MappingActivities are implemented we need to add such
// information to the EntityMapping instance!
mapper.applyMappings(remoteEntity.getRepresentation(), localEntity.getRepresentation(), valueFactory);
//set general metadata
managedEntity.setCreated(new Date());
//set the metadata required by the referenced site
managedEntity.addAttributionLink(site.getConfiguration().getAttributionUrl());
managedEntity.addAttributionText(site.getConfiguration().getAttribution(), null);
//TODO: maybe replace with the URL of the site
managedEntity.addContributorName(site.getConfiguration().getName());
}
Aggregations