it.uniroma2.art.semanticturkey.changetracking.sail.config.ChangeTrackerFactory Maven / Gradle / Ivy
package it.uniroma2.art.semanticturkey.changetracking.sail.config;
import java.util.Optional;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.sail.Sail;
import org.eclipse.rdf4j.sail.config.DelegatingSailImplConfig;
import org.eclipse.rdf4j.sail.config.SailConfigException;
import org.eclipse.rdf4j.sail.config.SailFactory;
import org.eclipse.rdf4j.sail.config.SailImplConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import it.uniroma2.art.semanticturkey.changetracking.sail.ChangeTracker;
/**
* Factory for {@link ChangeTracker}.
*
* @author Manuel Fiorelli
*/
public class ChangeTrackerFactory implements SailFactory {
private static final Logger logger = LoggerFactory.getLogger(ChangeTrackerFactory.class);
public static final String SAIL_TYPE = "http://semanticturkey.uniroma2.it/sail/changetracker";
@Override
public String getSailType() {
return SAIL_TYPE;
}
@Override
public SailImplConfig getConfig() {
return new ChangeTrackerConfig(null);
}
@Override
public Sail getSail(SailImplConfig config) throws SailConfigException {
if (!SAIL_TYPE.equals(config.getType())) {
throw new SailConfigException("Invalid Sail type: " + config.getType());
}
ChangeTrackerConfig config2 = (ChangeTrackerConfig) config;
String serverURL = config2.getServerURL();
String metadataRepoId = config2.getSupportRepositoryID();
String metadataNS = config2.getMetadataNS();
IRI metadataGraph = config2.getHistoryGraph();
Set includeGraph = config2.getIncludeGraph();
Set excludeGraph = config2.getExcludeGraph();
boolean historyEnabled = config2.isHistoryEnabled();
boolean validationEnabled = config2.isValidationEnabled();
boolean blacklistEnabled = config2.isBlacklistingEnabled();
boolean undoEnabled = config2.isUndoEnabled();
Optional interactiveNotifications = config2.isInteractiveNotifications();
IRI validationGraph = config2.getValidationGraph();
IRI blacklistGraph = config2.getBlacklistGraph();
SailImplConfig config3 = config;
if (!interactiveNotifications.isPresent()) {
while (config3 instanceof DelegatingSailImplConfig) {
config3 = ((DelegatingSailImplConfig) config3).getDelegate();
String type = config3.getType();
// only the last one is really necessary as we are going to no longer support older GDB versions
if (StringUtils.equalsAny(type, "graphdb:FreeSail", "owlim:Sail", "graphdb:Sail")) {
interactiveNotifications = ChangeTracker.OPTIONAL_FALSE;
break;
} else if (StringUtils.equalsAny(type, "openrdf:MemoryStore", "openrdf:NativeStore")) {
interactiveNotifications = ChangeTracker.OPTIONAL_TRUE;
break;
}
}
}
return new ChangeTracker(serverURL, metadataRepoId, metadataNS, metadataGraph, includeGraph,
excludeGraph, historyEnabled, validationEnabled, undoEnabled, interactiveNotifications, validationGraph,
blacklistEnabled, blacklistGraph);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy