From d752989003a5f6c06fb025c165bdf643e79cac34 Mon Sep 17 00:00:00 2001 From: Jim Blake Date: Sun, 29 May 2016 16:12:11 -0400 Subject: [PATCH] VIVO-1247, remove duplicate code used with ConfigurationBeanLoader. Now that the @Property annotation includes cardinality parameters, we can remove a lot of duplicate code. --- .../webapp/application/ApplicationImpl.java | 103 +++--------------- .../InstrumentedSearchEngineWrapper.java | 71 +++++------- .../webapp/searchindex/SearchIndexerImpl.java | 61 +++++------ .../documentBuilding/FieldBooster.java | 13 +-- .../indexing/SelectQueryUriFinder.java | 6 +- .../sparql/ContentTripleSourceSPARQL.java | 29 +---- .../impl/tdb/ContentTripleSourceTDB.java | 22 +--- .../virtuoso/ContentTripleSourceVirtuoso.java | 48 +------- 8 files changed, 86 insertions(+), 267 deletions(-) diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/application/ApplicationImpl.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/application/ApplicationImpl.java index 36e230466..1f840ae37 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/application/ApplicationImpl.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/application/ApplicationImpl.java @@ -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.triplesource.impl.BasicCombinedTripleSource; 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. @@ -69,15 +68,9 @@ public class ApplicationImpl implements Application { 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) { - if (searchEngine == null) { - searchEngine = se; - } else { - throw new IllegalStateException( - "Configuration includes multiple SearchEngine instances: " - + searchEngine + ", and " + se); - } + searchEngine = se; } @Override @@ -85,15 +78,9 @@ public class ApplicationImpl implements Application { 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) { - if (searchIndexer == null) { - searchIndexer = si; - } else { - throw new IllegalStateException( - "Configuration includes multiple SearchIndexer instances: " - + searchIndexer + ", and " + si); - } + searchIndexer = si; } @Override @@ -101,15 +88,9 @@ public class ApplicationImpl implements Application { 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) { - if (imageProcessor == null) { - imageProcessor = ip; - } else { - throw new IllegalStateException( - "Configuration includes multiple ImageProcessor instances: " - + imageProcessor + ", and " + ip); - } + imageProcessor = ip; } @Override @@ -117,15 +98,9 @@ public class ApplicationImpl implements Application { 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) { - if (fileStorage == null) { - fileStorage = fs; - } else { - throw new IllegalStateException( - "Configuration includes multiple FileStorage instances: " - + fileStorage + ", and " + fs); - } + fileStorage = fs; } @Override @@ -133,15 +108,9 @@ public class ApplicationImpl implements Application { 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) { - if (contentTripleSource == null) { - contentTripleSource = source; - } else { - throw new IllegalStateException( - "Configuration includes multiple instances of ContentTripleSource: " - + contentTripleSource + ", and " + source); - } + contentTripleSource = source; } @Override @@ -149,15 +118,9 @@ public class ApplicationImpl implements Application { 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) { - if (configurationTripleSource == null) { - configurationTripleSource = source; - } else { - throw new IllegalStateException( - "Configuration includes multiple instances of ConfigurationTripleSource: " - + configurationTripleSource + ", and " + source); - } + configurationTripleSource = source; } @Override @@ -165,47 +128,9 @@ public class ApplicationImpl implements Application { 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) { - if (tboxReasonerModule == null) { - 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."); - } + tboxReasonerModule = module; } @Override diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/searchengine/InstrumentedSearchEngineWrapper.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/searchengine/InstrumentedSearchEngineWrapper.java index 72228d940..d4ea2382e 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/searchengine/InstrumentedSearchEngineWrapper.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/searchengine/InstrumentedSearchEngineWrapper.java @@ -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.SearchResultDocumentList; 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 @@ -40,26 +39,11 @@ public class InstrumentedSearchEngineWrapper implements SearchEngine { 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) { - if (innerEngine == null) { - innerEngine = inner; - } else { - throw new IllegalStateException( - "Configuration includes multiple SearchEngine instancess: " - + innerEngine + ", and " + inner); - } + innerEngine = inner; } - @Validation - public void validate() throws Exception { - if (innerEngine == null) { - throw new IllegalStateException( - "Configuration did not include a wrapped SearchEngine."); - } - } - - /** * Complain unless ACTIVE. */ @@ -222,13 +206,13 @@ public class InstrumentedSearchEngineWrapper implements SearchEngine { return count; } } - + // ---------------------------------------------------------------------- // Helper classes // ---------------------------------------------------------------------- - - private static class SearchResponseForDocumentCount implements SearchResponse { + private static class SearchResponseForDocumentCount implements + SearchResponse { private final int count; public SearchResponseForDocumentCount(int count) { @@ -254,28 +238,29 @@ public class InstrumentedSearchEngineWrapper implements SearchEngine { public List getFacetFields() { return Collections.emptyList(); } - - private class EmptyDocumentListWithCount implements SearchResultDocumentList { - @Override - public Iterator iterator() { - return Collections.emptyIterator(); - } - - @Override - public int size() { - return 0; - } - - @Override - public long getNumFound() { - return count; - } - - @Override - public SearchResultDocument get(int i) { - throw new ArrayIndexOutOfBoundsException(i); - } + + private class EmptyDocumentListWithCount implements + SearchResultDocumentList { + @Override + public Iterator iterator() { + return Collections.emptyIterator(); + } + + @Override + public int size() { + return 0; + } + + @Override + public long getNumFound() { + return count; + } + + @Override + public SearchResultDocument get(int i) { + throw new ArrayIndexOutOfBoundsException(i); + } } } - + } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/searchindex/SearchIndexerImpl.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/searchindex/SearchIndexerImpl.java index e9a6a9a81..2b63123bc 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/searchindex/SearchIndexerImpl.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/searchindex/SearchIndexerImpl.java @@ -99,7 +99,7 @@ public class SearchIndexerImpl implements SearchIndexer { private Set uriFinders; private WebappDaoFactory wadf; - private boolean rebuildOnUnpause = false; + private boolean rebuildOnUnpause = false; private volatile int paused = 0; @@ -110,25 +110,14 @@ public class SearchIndexerImpl implements SearchIndexer { // 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) { - if (threadPoolSize == null) { - threadPoolSize = Integer.parseInt(size); - } else { - throw new IllegalStateException( - "Configuration includes multiple values for threadPoolSize: " - + threadPoolSize + ", and " + size); - } + threadPoolSize = Integer.parseInt(size); } @Validation public void validate() throws Exception { - if (threadPoolSize == null) { - throw new IllegalStateException( - "Configuration did not include a value for threadPoolSize."); - } else { - this.pool = new WorkerThreadPool(threadPoolSize); - } + 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) { scheduleUpdatesForUris(pendingUris); pendingUris = new ArrayList<>(); @@ -278,13 +267,14 @@ public class SearchIndexerImpl implements SearchIndexer { if (changes == null || changes.isEmpty()) { return; } - if (paused > 0) { + if (paused > 0) { if (addToPendingStatements(changes)) { 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."); } @@ -306,13 +296,14 @@ public class SearchIndexerImpl implements SearchIndexer { if (uris == null || uris.isEmpty()) { return; } - if (paused > 0) { + if (paused > 0) { if (pendingUris.addAll(uris)) { 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."); } @@ -332,13 +323,14 @@ public class SearchIndexerImpl implements SearchIndexer { return; } fireEvent(REBUILD_REQUESTED); - if (paused > 0) { + if (paused > 0) { // Make sure that we are rebuilding when we unpause // and don't bother noting any other changes until unpaused - rebuildOnUnpause = true; - return; - } - scheduler.scheduleTask(new RebuildIndexTask(new IndexerConfigImpl(this))); + rebuildOnUnpause = true; + return; + } + scheduler + .scheduleTask(new RebuildIndexTask(new IndexerConfigImpl(this))); log.debug("Scheduled a full rebuild."); } @@ -447,13 +439,13 @@ public class SearchIndexerImpl implements SearchIndexer { } public synchronized void scheduleTask(Task task) { - if (!started) { - deferredQueue.add(task); - log.debug("added task to deferred queue: " + task); - } else { + if (!started) { + deferredQueue.add(task); + log.debug("added task to deferred queue: " + task); + } else { taskQueue.scheduleTask(task); log.debug("added task to task queue: " + task); - } + } } public synchronized void start() { @@ -463,8 +455,9 @@ public class SearchIndexerImpl implements SearchIndexer { private void processDeferredTasks() { for (Task task : deferredQueue) { - taskQueue.scheduleTask(task); - log.debug("moved task from deferred queue to task queue: " + task); + taskQueue.scheduleTask(task); + log.debug("moved task from deferred queue to task queue: " + + task); } deferredQueue.clear(); } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/searchindex/documentBuilding/FieldBooster.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/searchindex/documentBuilding/FieldBooster.java index 5a86e1f65..7a3f0dad9 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/searchindex/documentBuilding/FieldBooster.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/searchindex/documentBuilding/FieldBooster.java @@ -17,27 +17,18 @@ public class FieldBooster implements DocumentModifier { private final List fieldNames = new ArrayList<>(); 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) { 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) { this.boost = boost; } @Validation 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 uniqueFieldNames = new HashSet<>(fieldNames); List duplicateFieldNames = new ArrayList<>(fieldNames); for (String fn : uniqueFieldNames) { diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/searchindex/indexing/SelectQueryUriFinder.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/searchindex/indexing/SelectQueryUriFinder.java index a0e50797a..efaf41964 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/searchindex/indexing/SelectQueryUriFinder.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/searchindex/indexing/SelectQueryUriFinder.java @@ -74,7 +74,7 @@ public class SelectQueryUriFinder implements IndexingUriFinder, 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) { queries.add(query); } @@ -89,10 +89,6 @@ public class SelectQueryUriFinder implements IndexingUriFinder, if (label == null) { label = this.getClass().getSimpleName() + ":" + this.hashCode(); } - if (queries.isEmpty()) { - throw new IllegalStateException( - "Configuration contains no queries for " + label); - } } @Override diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/triplesource/impl/sparql/ContentTripleSourceSPARQL.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/triplesource/impl/sparql/ContentTripleSourceSPARQL.java index cc19fac1e..044492036 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/triplesource/impl/sparql/ContentTripleSourceSPARQL.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/triplesource/impl/sparql/ContentTripleSourceSPARQL.java @@ -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.sparql.RDFServiceSparql; 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; /** @@ -41,34 +40,14 @@ public class ContentTripleSourceSPARQL extends ContentTripleSource { private Dataset dataset; 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) { - if (endpointURI == null) { - endpointURI = eUri; - } else { - throw new IllegalStateException( - "Configuration includes multiple instances of EndpointURI: " - + endpointURI + ", and " + eUri); - } + endpointURI = 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) { - if (updateEndpointURI == null) { - 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."); - } + updateEndpointURI = ueUri; } @Override diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/triplesource/impl/tdb/ContentTripleSourceTDB.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/triplesource/impl/tdb/ContentTripleSourceTDB.java index 4591559b0..595633252 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/triplesource/impl/tdb/ContentTripleSourceTDB.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/triplesource/impl/tdb/ContentTripleSourceTDB.java @@ -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.servlet.setup.JenaDataSourceSetupBase; 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; /** @@ -49,23 +48,9 @@ public class ContentTripleSourceTDB extends ContentTripleSource { private Dataset dataset; 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) { - if (tdbPath == null) { - 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."); - } + tdbPath = path; } @Override @@ -106,7 +91,8 @@ public class ContentTripleSourceTDB extends ContentTripleSource { } private void checkForFirstTimeStartup() { - if (this.dataset.getNamedModel(ModelNames.TBOX_ASSERTIONS).getGraph().isEmpty()) { + if (this.dataset.getNamedModel(ModelNames.TBOX_ASSERTIONS).getGraph() + .isEmpty()) { JenaDataSourceSetupBase.thisIsFirstStartup(); } } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/triplesource/impl/virtuoso/ContentTripleSourceVirtuoso.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/triplesource/impl/virtuoso/ContentTripleSourceVirtuoso.java index 441279fb3..5cb4c0ce0 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/triplesource/impl/virtuoso/ContentTripleSourceVirtuoso.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/triplesource/impl/virtuoso/ContentTripleSourceVirtuoso.java @@ -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.triplesource.impl.sparql.ContentTripleSourceSPARQL; 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; /** @@ -19,54 +18,19 @@ public class ContentTripleSourceVirtuoso extends ContentTripleSourceSPARQL { private String username; 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) { - if (baseUri == null) { - baseUri = uri; - } else { - throw new IllegalStateException( - "Configuration includes multiple instances of BaseURI: " - + baseUri + ", and " + uri); - } + baseUri = 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) { - if (username == null) { - username = user; - } else { - throw new IllegalStateException( - "Configuration includes multiple instances of Username: " - + username + ", and " + user); - } + username = 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) { - if (password == null) { - 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."); - } + password = pass; } @Override