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.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);
}
}
@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);
}
}
@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);
}
}
@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);
}
}
@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);
}
}
@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);
}
}
@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.");
}
}
@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.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,25 +39,10 @@ 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);
}
}
@Validation
public void validate() throws Exception {
if (innerEngine == null) {
throw new IllegalStateException(
"Configuration did not include a wrapped SearchEngine.");
}
}
/**
* Complain unless ACTIVE.
@ -227,8 +211,8 @@ public class InstrumentedSearchEngineWrapper implements SearchEngine {
// Helper classes
// ----------------------------------------------------------------------
private static class SearchResponseForDocumentCount implements SearchResponse {
private static class SearchResponseForDocumentCount implements
SearchResponse {
private final int count;
public SearchResponseForDocumentCount(int count) {
@ -255,7 +239,8 @@ public class InstrumentedSearchEngineWrapper implements SearchEngine {
return Collections.emptyList();
}
private class EmptyDocumentListWithCount implements SearchResultDocumentList {
private class EmptyDocumentListWithCount implements
SearchResultDocumentList {
@Override
public Iterator<SearchResultDocument> iterator() {
return Collections.emptyIterator();

View file

@ -110,26 +110,15 @@ 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);
}
}
@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);
}
}
// ----------------------------------------------------------------------
// State management.
@ -284,7 +273,8 @@ public class SearchIndexerImpl implements SearchIndexer {
}
}
scheduler.scheduleTask(new UpdateStatementsTask(new IndexerConfigImpl(this), changes));
scheduler.scheduleTask(new UpdateStatementsTask(new IndexerConfigImpl(
this), changes));
log.debug("Scheduled updates for " + changes.size() + " statements.");
}
@ -312,7 +302,8 @@ public class SearchIndexerImpl implements SearchIndexer {
}
}
scheduler.scheduleTask(new UpdateUrisTask(new IndexerConfigImpl(this), uris));
scheduler.scheduleTask(new UpdateUrisTask(new IndexerConfigImpl(this),
uris));
log.debug("Scheduled updates for " + uris.size() + " uris.");
}
@ -338,7 +329,8 @@ public class SearchIndexerImpl implements SearchIndexer {
rebuildOnUnpause = true;
return;
}
scheduler.scheduleTask(new RebuildIndexTask(new IndexerConfigImpl(this)));
scheduler
.scheduleTask(new RebuildIndexTask(new IndexerConfigImpl(this)));
log.debug("Scheduled a full rebuild.");
}
@ -464,7 +456,8 @@ 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);
log.debug("moved task from deferred queue to task queue: "
+ task);
}
deferredQueue.clear();
}

View file

@ -17,27 +17,18 @@ public class FieldBooster implements DocumentModifier {
private final List<String> 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<String> uniqueFieldNames = new HashSet<>(fieldNames);
List<String> duplicateFieldNames = new ArrayList<>(fieldNames);
for (String fn : uniqueFieldNames) {

View file

@ -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

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.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);
}
}
@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.");
}
}
@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.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.");
}
}
@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();
}
}

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.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);
}
}
@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);
}
}
@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.");
}
}
@Override