use of org.apache.stanbol.entityhub.servicesapi.model.Representation in project stanbol by apache.
the class TrackingDereferencerBase method dereference.
@Override
public final boolean dereference(IRI uri, Graph graph, Lock writeLock, DereferenceContext dc) throws DereferenceException {
T service = getService();
if (service == null) {
throw new DereferenceException(uri, serviceClass.getClass().getSimpleName() + "service is currently not available");
}
EntityhubDereferenceContext derefContext = (EntityhubDereferenceContext) dc;
Representation rep;
try {
rep = getRepresentation(service, uri.getUnicodeString(), derefContext.isOfflineMode());
} catch (EntityhubException e) {
throw new DereferenceException(uri, e);
}
//we need the languages as strings
final Set<String> langs = derefContext.getLanguages();
final FieldMapper fieldMapper = derefContext.getFieldMapper();
final Program<Object> ldpathProgram = derefContext.getProgram();
if (rep != null) {
if (fieldMapper == null && ldpathProgram == null && (langs == null || langs.isEmpty())) {
copyAll(uri, rep, graph, writeLock);
} else {
//we need to apply some filters while dereferencing
if (fieldMapper != null || (langs != null && !langs.isEmpty())) {
//this considers speficied fields and included languages
copyMapped(uri, rep, fieldMapper, langs, graph, writeLock);
}
if (ldpathProgram != null) {
//this executes LDPath statements
copyLdPath(uri, getRdfBackend(service), ldpathProgram, langs, graph, writeLock);
}
}
return true;
} else {
return false;
}
}
use of org.apache.stanbol.entityhub.servicesapi.model.Representation in project stanbol by apache.
the class CacheImpl method applyCacheMappings.
/**
* Applies the mappings defined by the {@link #baseMapper} and the {@link #additionalMapper}
* to the parsed Representation.
*
* @param yard The yard (local reference to avoid syncronization)
* @param representation The representation to map
* @return the mapped representation
*/
private Representation applyCacheMappings(Yard yard, Representation representation) {
long start = System.currentTimeMillis();
Representation mapped = null;
ValueFactory valueFactory = getValueFactory();
if (baseMapper != null) {
mapped = yard.getValueFactory().createRepresentation(representation.getId());
baseMapper.applyMappings(representation, mapped, valueFactory);
}
if (additionalMapper != null) {
if (mapped == null) {
mapped = yard.getValueFactory().createRepresentation(representation.getId());
}
additionalMapper.applyMappings(representation, mapped, valueFactory);
}
log.info(" -- applied mappings in " + (System.currentTimeMillis() - start) + "ms");
return mapped != null ? mapped : representation;
}
use of org.apache.stanbol.entityhub.servicesapi.model.Representation in project stanbol by apache.
the class CacheUtils method storeBaseMappingsConfiguration.
/**
* Stores the baseMappings to the {@link Yard}. This may cause unexpected
* behaviour for subsequest calls of the stored configuration does not
* correspond with the actual data stored within the cache.<p>
* Typically this is only used at the start or end of the creation of a
* full Cache ({@link CacheStrategy#all}) of an referenced site (entity source).<p>
* Note also that if the {@link #baseMapper} is <code>null</code> this
* method removes any existing configuration from the yard.
* @throws YardException an any error while storing the config to the yard.
* @throws IllegalArgumentException if <code>null</code> is parsed as {@link Yard}.
*/
public static void storeBaseMappingsConfiguration(Yard yard, FieldMapper baseMapper) throws YardException, IllegalArgumentException {
if (yard == null) {
throw new IllegalArgumentException("The parsed Yard MUST NOT be NULL!");
}
if (baseMapper == null) {
yard.remove(Cache.BASE_CONFIGURATION_URI);
} else {
Representation config = yard.getValueFactory().createRepresentation(Cache.BASE_CONFIGURATION_URI);
writeFieldConfig(config, baseMapper);
yard.store(config);
}
}
use of org.apache.stanbol.entityhub.servicesapi.model.Representation in project stanbol by apache.
the class CacheUtils method loadBaseMappings.
/**
* Loads the base mappings form the parsed Yard
* @param yard The yard
* @param nsPrefixService if present '{prefix}:{localname}' configurations are
* @return The baseMappings
* @throws YardException on any Error while getting the Representation holding
* the Configuration from the Yard.
* @throws CacheInitialisationException if the configuration is found but not
* valid.
* @throws IllegalArgumentException if <code>null</code> is parsed as {@link Yard}
*/
public static FieldMapper loadBaseMappings(Yard yard, NamespacePrefixService nsPrefixService) throws YardException, CacheInitialisationException {
if (yard == null) {
throw new IllegalArgumentException("The parsed Yard MUST NOT be NULL!");
}
Representation baseConfig = yard.getRepresentation(Cache.BASE_CONFIGURATION_URI);
if (baseConfig != null) {
FieldMapper mapper = readFieldConfig(yard, baseConfig, nsPrefixService);
if (mapper == null) {
String msg = "Invalid Base Configuration: Unable to parse FieldMappings from Field " + Cache.FIELD_MAPPING_CONFIG_FIELD;
log.error(msg);
if (log.isErrorEnabled()) {
log.error(ModelUtils.getRepresentationInfo(baseConfig));
}
throw new CacheInitialisationException(msg);
} else {
return mapper;
}
} else {
return null;
//throw new CacheInitialisationException("Base Configuration not present");
}
}
use of org.apache.stanbol.entityhub.servicesapi.model.Representation in project stanbol by apache.
the class RepresentationTest method testEmptyFieldGetFirstDataType.
@Test(expected = IllegalArgumentException.class)
public void testEmptyFieldGetFirstDataType() {
Representation rep = createRepresentation(null);
rep.getFirst("", Integer.class);
}
Aggregations