VIVO-1247, remove duplicate code used with ConfigurationBeanLoader.

Now that the @Property annotation includes cardinality parameters, we can remove a lot of duplicate code.
This commit is contained in:
Jim Blake 2016-05-29 16:12:11 -04:00
parent efbc3e3da4
commit d752989003
8 changed files with 86 additions and 267 deletions

View file

@ -25,7 +25,6 @@ import edu.cornell.mannlib.vitro.webapp.startup.ComponentStartupStatusImpl;
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus; import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
import edu.cornell.mannlib.vitro.webapp.triplesource.impl.BasicCombinedTripleSource; import edu.cornell.mannlib.vitro.webapp.triplesource.impl.BasicCombinedTripleSource;
import edu.cornell.mannlib.vitro.webapp.utils.configuration.Property; import edu.cornell.mannlib.vitro.webapp.utils.configuration.Property;
import edu.cornell.mannlib.vitro.webapp.utils.configuration.Validation;
/** /**
* The basic implementation of the Application interface. * The basic implementation of the Application interface.
@ -69,15 +68,9 @@ public class ApplicationImpl implements Application {
return searchEngine; return searchEngine;
} }
@Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#hasSearchEngine") @Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#hasSearchEngine", minOccurs = 1, maxOccurs = 1)
public void setSearchEngine(SearchEngine se) { public void setSearchEngine(SearchEngine se) {
if (searchEngine == null) { searchEngine = se;
searchEngine = se;
} else {
throw new IllegalStateException(
"Configuration includes multiple SearchEngine instances: "
+ searchEngine + ", and " + se);
}
} }
@Override @Override
@ -85,15 +78,9 @@ public class ApplicationImpl implements Application {
return searchIndexer; return searchIndexer;
} }
@Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#hasSearchIndexer") @Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#hasSearchIndexer", minOccurs = 1, maxOccurs = 1)
public void setSearchIndexer(SearchIndexer si) { public void setSearchIndexer(SearchIndexer si) {
if (searchIndexer == null) { searchIndexer = si;
searchIndexer = si;
} else {
throw new IllegalStateException(
"Configuration includes multiple SearchIndexer instances: "
+ searchIndexer + ", and " + si);
}
} }
@Override @Override
@ -101,15 +88,9 @@ public class ApplicationImpl implements Application {
return imageProcessor; return imageProcessor;
} }
@Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#hasImageProcessor") @Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#hasImageProcessor", minOccurs = 1, maxOccurs = 1)
public void setImageProcessor(ImageProcessor ip) { public void setImageProcessor(ImageProcessor ip) {
if (imageProcessor == null) { imageProcessor = ip;
imageProcessor = ip;
} else {
throw new IllegalStateException(
"Configuration includes multiple ImageProcessor instances: "
+ imageProcessor + ", and " + ip);
}
} }
@Override @Override
@ -117,15 +98,9 @@ public class ApplicationImpl implements Application {
return fileStorage; return fileStorage;
} }
@Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#hasFileStorage") @Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#hasFileStorage", minOccurs = 1, maxOccurs = 1)
public void setFileStorage(FileStorage fs) { public void setFileStorage(FileStorage fs) {
if (fileStorage == null) { fileStorage = fs;
fileStorage = fs;
} else {
throw new IllegalStateException(
"Configuration includes multiple FileStorage instances: "
+ fileStorage + ", and " + fs);
}
} }
@Override @Override
@ -133,15 +108,9 @@ public class ApplicationImpl implements Application {
return contentTripleSource; return contentTripleSource;
} }
@Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#hasContentTripleSource") @Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#hasContentTripleSource", minOccurs = 1, maxOccurs = 1)
public void setContentTripleSource(ContentTripleSource source) { public void setContentTripleSource(ContentTripleSource source) {
if (contentTripleSource == null) { contentTripleSource = source;
contentTripleSource = source;
} else {
throw new IllegalStateException(
"Configuration includes multiple instances of ContentTripleSource: "
+ contentTripleSource + ", and " + source);
}
} }
@Override @Override
@ -149,15 +118,9 @@ public class ApplicationImpl implements Application {
return configurationTripleSource; return configurationTripleSource;
} }
@Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#hasConfigurationTripleSource") @Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#hasConfigurationTripleSource", minOccurs = 1, maxOccurs = 1)
public void setConfigurationTripleSource(ConfigurationTripleSource source) { public void setConfigurationTripleSource(ConfigurationTripleSource source) {
if (configurationTripleSource == null) { configurationTripleSource = source;
configurationTripleSource = source;
} else {
throw new IllegalStateException(
"Configuration includes multiple instances of ConfigurationTripleSource: "
+ configurationTripleSource + ", and " + source);
}
} }
@Override @Override
@ -165,47 +128,9 @@ public class ApplicationImpl implements Application {
return tboxReasonerModule; return tboxReasonerModule;
} }
@Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#hasTBoxReasonerModule") @Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#hasTBoxReasonerModule", minOccurs = 1, maxOccurs = 1)
public void setTBoxReasonerModule(TBoxReasonerModule module) { public void setTBoxReasonerModule(TBoxReasonerModule module) {
if (tboxReasonerModule == null) { tboxReasonerModule = module;
tboxReasonerModule = module;
} else {
throw new IllegalStateException(
"Configuration includes multiple instances of TBoxReasonerModule: "
+ tboxReasonerModule + ", and " + module);
}
}
@Validation
public void validate() throws Exception {
if (searchEngine == null) {
throw new IllegalStateException(
"Configuration did not include a SearchEngine.");
}
if (searchIndexer == null) {
throw new IllegalStateException(
"Configuration did not include a SearchIndexer.");
}
if (imageProcessor == null) {
throw new IllegalStateException(
"Configuration did not include an ImageProcessor.");
}
if (fileStorage == null) {
throw new IllegalStateException(
"Configuration did not include a FileStorage.");
}
if (contentTripleSource == null) {
throw new IllegalStateException(
"Configuration did not include a ContentTripleSource.");
}
if (configurationTripleSource == null) {
throw new IllegalStateException(
"Configuration did not include a ConfigurationTripleSource.");
}
if (tboxReasonerModule == null) {
throw new IllegalStateException(
"Configuration did not include a TBoxReasonerModule.");
}
} }
@Override @Override

View file

@ -26,7 +26,6 @@ import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResponse;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResultDocument; import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResultDocument;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResultDocumentList; import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResultDocumentList;
import edu.cornell.mannlib.vitro.webapp.utils.configuration.Property; import edu.cornell.mannlib.vitro.webapp.utils.configuration.Property;
import edu.cornell.mannlib.vitro.webapp.utils.configuration.Validation;
/** /**
* Manages the life-cycle of the SearchEngine. Adds logging, controlled by * Manages the life-cycle of the SearchEngine. Adds logging, controlled by
@ -40,26 +39,11 @@ public class InstrumentedSearchEngineWrapper implements SearchEngine {
private volatile LifecycleState lifecycleState = NEW; private volatile LifecycleState lifecycleState = NEW;
@Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#wraps") @Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#wraps", minOccurs = 1, maxOccurs = 1)
public void setInnerEngine(SearchEngine inner) { public void setInnerEngine(SearchEngine inner) {
if (innerEngine == null) { innerEngine = inner;
innerEngine = inner;
} else {
throw new IllegalStateException(
"Configuration includes multiple SearchEngine instancess: "
+ innerEngine + ", and " + inner);
}
} }
@Validation
public void validate() throws Exception {
if (innerEngine == null) {
throw new IllegalStateException(
"Configuration did not include a wrapped SearchEngine.");
}
}
/** /**
* Complain unless ACTIVE. * Complain unless ACTIVE.
*/ */
@ -222,13 +206,13 @@ public class InstrumentedSearchEngineWrapper implements SearchEngine {
return count; return count;
} }
} }
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Helper classes // Helper classes
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
private static class SearchResponseForDocumentCount implements
private static class SearchResponseForDocumentCount implements SearchResponse { SearchResponse {
private final int count; private final int count;
public SearchResponseForDocumentCount(int count) { public SearchResponseForDocumentCount(int count) {
@ -254,28 +238,29 @@ public class InstrumentedSearchEngineWrapper implements SearchEngine {
public List<SearchFacetField> getFacetFields() { public List<SearchFacetField> getFacetFields() {
return Collections.emptyList(); return Collections.emptyList();
} }
private class EmptyDocumentListWithCount implements SearchResultDocumentList { private class EmptyDocumentListWithCount implements
@Override SearchResultDocumentList {
public Iterator<SearchResultDocument> iterator() { @Override
return Collections.emptyIterator(); public Iterator<SearchResultDocument> iterator() {
} return Collections.emptyIterator();
}
@Override
public int size() { @Override
return 0; public int size() {
} return 0;
}
@Override
public long getNumFound() { @Override
return count; public long getNumFound() {
} return count;
}
@Override
public SearchResultDocument get(int i) { @Override
throw new ArrayIndexOutOfBoundsException(i); public SearchResultDocument get(int i) {
} throw new ArrayIndexOutOfBoundsException(i);
}
} }
} }
} }

View file

@ -99,7 +99,7 @@ public class SearchIndexerImpl implements SearchIndexer {
private Set<IndexingUriFinder> uriFinders; private Set<IndexingUriFinder> uriFinders;
private WebappDaoFactory wadf; private WebappDaoFactory wadf;
private boolean rebuildOnUnpause = false; private boolean rebuildOnUnpause = false;
private volatile int paused = 0; private volatile int paused = 0;
@ -110,25 +110,14 @@ public class SearchIndexerImpl implements SearchIndexer {
// ConfigurationBeanLoader methods. // ConfigurationBeanLoader methods.
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#threadPoolSize") @Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#threadPoolSize", minOccurs = 1, maxOccurs = 1)
public void setThreadPoolSize(String size) { public void setThreadPoolSize(String size) {
if (threadPoolSize == null) { threadPoolSize = Integer.parseInt(size);
threadPoolSize = Integer.parseInt(size);
} else {
throw new IllegalStateException(
"Configuration includes multiple values for threadPoolSize: "
+ threadPoolSize + ", and " + size);
}
} }
@Validation @Validation
public void validate() throws Exception { public void validate() throws Exception {
if (threadPoolSize == null) { this.pool = new WorkerThreadPool(threadPoolSize);
throw new IllegalStateException(
"Configuration did not include a value for threadPoolSize.");
} else {
this.pool = new WorkerThreadPool(threadPoolSize);
}
} }
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@ -241,7 +230,7 @@ public class SearchIndexerImpl implements SearchIndexer {
} }
} }
private synchronized void schedulePendingUris() { private synchronized void schedulePendingUris() {
if (paused == 0 && pendingUris.size() > 0) { if (paused == 0 && pendingUris.size() > 0) {
scheduleUpdatesForUris(pendingUris); scheduleUpdatesForUris(pendingUris);
pendingUris = new ArrayList<>(); pendingUris = new ArrayList<>();
@ -278,13 +267,14 @@ public class SearchIndexerImpl implements SearchIndexer {
if (changes == null || changes.isEmpty()) { if (changes == null || changes.isEmpty()) {
return; return;
} }
if (paused > 0) { if (paused > 0) {
if (addToPendingStatements(changes)) { if (addToPendingStatements(changes)) {
return; return;
} }
} }
scheduler.scheduleTask(new UpdateStatementsTask(new IndexerConfigImpl(this), changes)); scheduler.scheduleTask(new UpdateStatementsTask(new IndexerConfigImpl(
this), changes));
log.debug("Scheduled updates for " + changes.size() + " statements."); log.debug("Scheduled updates for " + changes.size() + " statements.");
} }
@ -306,13 +296,14 @@ public class SearchIndexerImpl implements SearchIndexer {
if (uris == null || uris.isEmpty()) { if (uris == null || uris.isEmpty()) {
return; return;
} }
if (paused > 0) { if (paused > 0) {
if (pendingUris.addAll(uris)) { if (pendingUris.addAll(uris)) {
return; return;
} }
} }
scheduler.scheduleTask(new UpdateUrisTask(new IndexerConfigImpl(this), uris)); scheduler.scheduleTask(new UpdateUrisTask(new IndexerConfigImpl(this),
uris));
log.debug("Scheduled updates for " + uris.size() + " uris."); log.debug("Scheduled updates for " + uris.size() + " uris.");
} }
@ -332,13 +323,14 @@ public class SearchIndexerImpl implements SearchIndexer {
return; return;
} }
fireEvent(REBUILD_REQUESTED); fireEvent(REBUILD_REQUESTED);
if (paused > 0) { if (paused > 0) {
// Make sure that we are rebuilding when we unpause // Make sure that we are rebuilding when we unpause
// and don't bother noting any other changes until unpaused // and don't bother noting any other changes until unpaused
rebuildOnUnpause = true; rebuildOnUnpause = true;
return; return;
} }
scheduler.scheduleTask(new RebuildIndexTask(new IndexerConfigImpl(this))); scheduler
.scheduleTask(new RebuildIndexTask(new IndexerConfigImpl(this)));
log.debug("Scheduled a full rebuild."); log.debug("Scheduled a full rebuild.");
} }
@ -447,13 +439,13 @@ public class SearchIndexerImpl implements SearchIndexer {
} }
public synchronized void scheduleTask(Task task) { public synchronized void scheduleTask(Task task) {
if (!started) { if (!started) {
deferredQueue.add(task); deferredQueue.add(task);
log.debug("added task to deferred queue: " + task); log.debug("added task to deferred queue: " + task);
} else { } else {
taskQueue.scheduleTask(task); taskQueue.scheduleTask(task);
log.debug("added task to task queue: " + task); log.debug("added task to task queue: " + task);
} }
} }
public synchronized void start() { public synchronized void start() {
@ -463,8 +455,9 @@ public class SearchIndexerImpl implements SearchIndexer {
private void processDeferredTasks() { private void processDeferredTasks() {
for (Task task : deferredQueue) { for (Task task : deferredQueue) {
taskQueue.scheduleTask(task); taskQueue.scheduleTask(task);
log.debug("moved task from deferred queue to task queue: " + task); log.debug("moved task from deferred queue to task queue: "
+ task);
} }
deferredQueue.clear(); deferredQueue.clear();
} }

View file

@ -17,27 +17,18 @@ public class FieldBooster implements DocumentModifier {
private final List<String> fieldNames = new ArrayList<>(); private final List<String> fieldNames = new ArrayList<>();
private volatile Float boost; private volatile Float boost;
@Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#hasTargetField") @Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#hasTargetField", minOccurs = 1)
public void addTargetField(String fieldName) { public void addTargetField(String fieldName) {
fieldNames.add(fieldName); fieldNames.add(fieldName);
} }
@Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#hasBoost") @Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#hasBoost", minOccurs = 1)
public void setBoost(float boost) { public void setBoost(float boost) {
this.boost = boost; this.boost = boost;
} }
@Validation @Validation
public void validate() { public void validate() {
if (boost == null) {
throw new IllegalStateException(
"Configuration did not include a boost value.");
}
if (fieldNames.isEmpty()) {
throw new IllegalStateException(
"Configuration did not include a target field.");
}
Set<String> uniqueFieldNames = new HashSet<>(fieldNames); Set<String> uniqueFieldNames = new HashSet<>(fieldNames);
List<String> duplicateFieldNames = new ArrayList<>(fieldNames); List<String> duplicateFieldNames = new ArrayList<>(fieldNames);
for (String fn : uniqueFieldNames) { for (String fn : uniqueFieldNames) {

View file

@ -74,7 +74,7 @@ public class SelectQueryUriFinder implements IndexingUriFinder,
label = l; label = l;
} }
@Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#hasSelectQuery") @Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#hasSelectQuery", minOccurs = 1)
public void addQuery(String query) { public void addQuery(String query) {
queries.add(query); queries.add(query);
} }
@ -89,10 +89,6 @@ public class SelectQueryUriFinder implements IndexingUriFinder,
if (label == null) { if (label == null) {
label = this.getClass().getSimpleName() + ":" + this.hashCode(); label = this.getClass().getSimpleName() + ":" + this.hashCode();
} }
if (queries.isEmpty()) {
throw new IllegalStateException(
"Configuration contains no queries for " + label);
}
} }
@Override @Override

View file

@ -19,7 +19,6 @@ import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceFactorySingle;
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.logging.LoggingRDFServiceFactory; import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.logging.LoggingRDFServiceFactory;
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.sparql.RDFServiceSparql; import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.sparql.RDFServiceSparql;
import edu.cornell.mannlib.vitro.webapp.utils.configuration.Property; import edu.cornell.mannlib.vitro.webapp.utils.configuration.Property;
import edu.cornell.mannlib.vitro.webapp.utils.configuration.Validation;
import edu.cornell.mannlib.vitro.webapp.utils.logging.ToString; import edu.cornell.mannlib.vitro.webapp.utils.logging.ToString;
/** /**
@ -41,34 +40,14 @@ public class ContentTripleSourceSPARQL extends ContentTripleSource {
private Dataset dataset; private Dataset dataset;
private ModelMaker modelMaker; private ModelMaker modelMaker;
@Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#hasEndpointURI") @Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#hasEndpointURI", minOccurs = 1, maxOccurs = 1)
public void setEndpointURI(String eUri) { public void setEndpointURI(String eUri) {
if (endpointURI == null) { endpointURI = eUri;
endpointURI = eUri;
} else {
throw new IllegalStateException(
"Configuration includes multiple instances of EndpointURI: "
+ endpointURI + ", and " + eUri);
}
} }
@Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#hasUpdateEndpointURI") @Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#hasUpdateEndpointURI", maxOccurs = 1)
public void setUpdateEndpointURI(String ueUri) { public void setUpdateEndpointURI(String ueUri) {
if (updateEndpointURI == null) { updateEndpointURI = ueUri;
updateEndpointURI = ueUri;
} else {
throw new IllegalStateException(
"Configuration includes multiple instances of UpdateEndpointURI: "
+ updateEndpointURI + ", and " + ueUri);
}
}
@Validation
public void validate() throws Exception {
if (endpointURI == null) {
throw new IllegalStateException(
"Configuration did not include an EndpointURI.");
}
} }
@Override @Override

View file

@ -24,7 +24,6 @@ import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.tdb.RDFServiceTDB;
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.logging.LoggingRDFServiceFactory; import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.logging.LoggingRDFServiceFactory;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase; import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase;
import edu.cornell.mannlib.vitro.webapp.utils.configuration.Property; import edu.cornell.mannlib.vitro.webapp.utils.configuration.Property;
import edu.cornell.mannlib.vitro.webapp.utils.configuration.Validation;
import edu.cornell.mannlib.vitro.webapp.utils.logging.ToString; import edu.cornell.mannlib.vitro.webapp.utils.logging.ToString;
/** /**
@ -49,23 +48,9 @@ public class ContentTripleSourceTDB extends ContentTripleSource {
private Dataset dataset; private Dataset dataset;
private ModelMaker modelMaker; private ModelMaker modelMaker;
@Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#hasTdbDirectory") @Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#hasTdbDirectory", minOccurs = 1, maxOccurs = 1)
public void setTdbPath(String path) { public void setTdbPath(String path) {
if (tdbPath == null) { tdbPath = path;
tdbPath = path;
} else {
throw new IllegalStateException(
"Configuration includes multiple instances of TdbDirectory: "
+ tdbPath + ", and " + path);
}
}
@Validation
public void validate() throws Exception {
if (tdbPath == null) {
throw new IllegalStateException(
"Configuration did not include a TdbDirectory.");
}
} }
@Override @Override
@ -106,7 +91,8 @@ public class ContentTripleSourceTDB extends ContentTripleSource {
} }
private void checkForFirstTimeStartup() { private void checkForFirstTimeStartup() {
if (this.dataset.getNamedModel(ModelNames.TBOX_ASSERTIONS).getGraph().isEmpty()) { if (this.dataset.getNamedModel(ModelNames.TBOX_ASSERTIONS).getGraph()
.isEmpty()) {
JenaDataSourceSetupBase.thisIsFirstStartup(); JenaDataSourceSetupBase.thisIsFirstStartup();
} }
} }

View file

@ -7,7 +7,6 @@ import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.virtuoso.RDFServiceVirtuoso; import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.virtuoso.RDFServiceVirtuoso;
import edu.cornell.mannlib.vitro.webapp.triplesource.impl.sparql.ContentTripleSourceSPARQL; import edu.cornell.mannlib.vitro.webapp.triplesource.impl.sparql.ContentTripleSourceSPARQL;
import edu.cornell.mannlib.vitro.webapp.utils.configuration.Property; import edu.cornell.mannlib.vitro.webapp.utils.configuration.Property;
import edu.cornell.mannlib.vitro.webapp.utils.configuration.Validation;
import edu.cornell.mannlib.vitro.webapp.utils.logging.ToString; import edu.cornell.mannlib.vitro.webapp.utils.logging.ToString;
/** /**
@ -19,54 +18,19 @@ public class ContentTripleSourceVirtuoso extends ContentTripleSourceSPARQL {
private String username; private String username;
private String password; private String password;
@Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#hasBaseURI") @Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#hasBaseURI", minOccurs = 1, maxOccurs = 1)
public void setBaseUri(String uri) { public void setBaseUri(String uri) {
if (baseUri == null) { baseUri = uri;
baseUri = uri;
} else {
throw new IllegalStateException(
"Configuration includes multiple instances of BaseURI: "
+ baseUri + ", and " + uri);
}
} }
@Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#hasUsername") @Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#hasUsername", minOccurs = 1, maxOccurs = 1)
public void setUsername(String user) { public void setUsername(String user) {
if (username == null) { username = user;
username = user;
} else {
throw new IllegalStateException(
"Configuration includes multiple instances of Username: "
+ username + ", and " + user);
}
} }
@Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#hasPassword") @Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#hasPassword", minOccurs = 1, maxOccurs = 1)
public void setPassword(String pass) { public void setPassword(String pass) {
if (password == null) { password = pass;
password = pass;
} else {
throw new IllegalStateException(
"Configuration includes multiple instances of Password: "
+ password + ", and " + pass);
}
}
@Override
@Validation
public void validate() throws Exception {
if (baseUri == null) {
throw new IllegalStateException(
"Configuration did not include a BaseURI.");
}
if (username == null) {
throw new IllegalStateException(
"Configuration did not include a Username.");
}
if (password == null) {
throw new IllegalStateException(
"Configuration did not include a Password.");
}
} }
@Override @Override