use of org.collectionspace.csp.api.core.CSPDependencyException in project application by collectionspace.
the class CSPManagerImpl method configure.
@Override
public void configure(InputSource in, EntityResolver er, boolean forXsdGeneration) throws CSPDependencyException {
RuleSetImpl rules = new RuleSetImpl();
for (Configurable config : config_csps) {
config.configure(rules);
}
if (forXsdGeneration == true) {
String msg = String.format("Config Generation: '%s' - ### Generating Service configuration from '%s'.", in.getPublicId(), in.getPublicId());
log.trace(msg);
}
try {
ConfigParser parser = new ConfigParser(rules, er);
parser.parse(in);
// Finish up all the config-related tasks
for (Configurable config : config_csps) {
config.config_finish();
}
// Run the post-config init tasks
for (Configurable config : config_csps) {
config.complete_init(this, forXsdGeneration);
}
} catch (ConfigException e) {
String msg = String.format("Config Generation: '%s' - Trouble parsing configuration files.", in.getPublicId());
// XXX
throw new CSPDependencyException(msg, e);
}
}
use of org.collectionspace.csp.api.core.CSPDependencyException in project application by collectionspace.
the class DependencyResolver method go.
public void go() throws CSPDependencyException {
// keep track of successful runs of Dependables
Set<Dependable> successList = new HashSet<Dependable>();
Set<CSPDependencyException> exceptionList = null;
boolean contineRunningJobs = true;
int count = 0;
int max = jobList.size();
while (contineRunningJobs && count < max) {
// FIXME: What's the logic here? Keep trying while all jobs haven't run successfully (i.e. count < max) and ???
// reset the list of errors/exceptions
exceptionList = new HashSet<CSPDependencyException>();
contineRunningJobs = false;
for (Dependable job : jobList) {
if (successList.contains(job) == false) {
// test to see if we already successfully ran the job
try {
job.run();
successList.add(job);
// since we ran one successfully, we'll try rerunning the ones that may have failed earlier
contineRunningJobs = true;
count++;
log.debug("Dynamic dependency task '" + task_name + "' CSP(" + job.getName() + ") loaded successfully");
} catch (CSPDependencyException x) {
log.debug("Dynamic dependency task '" + task_name + "' could NOT load CSP(" + job.getName() + ") yet: " + x.getMessage());
exceptionList.add(x);
}
}
}
}
if (count < max) {
// if we couln't run them all successfully then log the errors/exceptions and throw an exception
for (CSPDependencyException x : exceptionList) {
log.error("Unresolved CSP Exception in dependency task '" + task_name + "' " + x.getMessage());
}
throw new CSPDependencyException("Encountered multiple dependency resolution exceptions:", (CSPDependencyException[]) (exceptionList.toArray(new CSPDependencyException[0])));
}
}
use of org.collectionspace.csp.api.core.CSPDependencyException in project application by collectionspace.
the class ConfigFinder method getConfigStreamViaClassLoader.
private static InputStream getConfigStreamViaClassLoader(String configFilename) throws CSPDependencyException {
// TODO next stage will be to move default.xml into here and rename it (CSPACE-1288)
// CSPACE-2114 initial (still messy, but better than before) stage is to change
// from 3 files (2x config and default) to just one of them (default.xml hard-coded here)
ClassLoader loader;
try {
// In Eclipse all classes are still visible so we can jump across via a known class name
loader = Class.forName(classNearDefaultXml).getClassLoader();
} catch (ClassNotFoundException e) {
// In Maven we can only see stuff in target/test-classes
// so this relies on top-level pom.xml copying the file in for us
log.debug("Falling back to current thread ClassLoader");
loader = Thread.currentThread().getContextClassLoader();
}
try {
InputStream result = loader.getResourceAsStream(configFilename);
if (result != null) {
log.info("Found config for testing: " + configFilename);
URL configFileURL = loader.getResource(configFilename);
log.info(String.format("Config file URL: '%s'", configFileURL.toString()));
return result;
} else {
throw new CSPDependencyException("Failed to open config file at " + configFilename);
}
} catch (Exception e) {
return null;
}
}
use of org.collectionspace.csp.api.core.CSPDependencyException in project application by collectionspace.
the class ConfigFinder method resolveEntityAsFile.
public File resolveEntityAsFile(String publicId, String systemId) throws SAXException, IOException {
try {
File out = getDataFromEnvironmentVariableAsFile(TEST_CONFIG);
if (out != null) {
return out;
}
if (ctx != null && "-//CSPACE//ROOT".equals(publicId)) {
InputStream outStream = getDataFromAttribute("config-data");
if (outStream != null) {
log.warn(String.format("Configuration not found as a file but as a string in the environment: %s", outStream.toString()));
return null;
}
out = getDataFromAttributePathAsFile("config-path");
if (out != null) {
return out;
}
out = getDataFromNameAsFile("config-filename");
if (out != null) {
return out;
}
}
// run by mvn
if ("-//CSPACE//TESTROOT".equals(publicId)) {
out = getConfigFileViaClassLoader(systemId);
if (out != null) {
return out;
}
}
out = getDataFromJBossPathAsFile(systemId);
if (out != null) {
return out;
}
// running tests find the resource/entity here
out = getDataFromClasspathAsFile(systemId);
if (out != null) {
return out;
}
out = getConfigFileViaClassLoader(systemId);
if (out != null) {
return out;
}
throw new SAXException("No such file " + systemId);
} catch (CSPDependencyException e) {
throw new SAXException("Error parsing", e);
}
}
use of org.collectionspace.csp.api.core.CSPDependencyException in project application by collectionspace.
the class TestConfigFinder method getConfigStream.
// used to test multi tenancy
public static InputSource getConfigStream(String filename, boolean isFromBuild) throws CSPDependencyException {
InputSource result = null;
try {
InputSource out = null;
ConfigFinder cfg = new ConfigFinder(null);
if (isFromBuild == true) {
out = cfg.resolveEntity("-//CSPACE//TESTROOT", filename);
} else {
out = cfg.resolveEntity("-//CSPACE//ROOT", filename);
}
if (out != null) {
result = out;
} else {
throw new CSPDependencyException("No config file found by any method");
}
} catch (SAXException x) {
throw new CSPDependencyException("Parsing failed", x);
} catch (IOException x) {
throw new CSPDependencyException("Parsing failed", x);
}
return result;
}
Aggregations