Search in sources :

Example 16 with CSPDependencyException

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);
    }
}
Also used : CSPDependencyException(org.collectionspace.csp.api.core.CSPDependencyException) ConfigParser(org.collectionspace.chain.csp.config.impl.parser.ConfigParser) ConfigException(org.collectionspace.chain.csp.config.ConfigException) Configurable(org.collectionspace.chain.csp.config.Configurable) RuleSetImpl(org.collectionspace.chain.csp.config.impl.main.RuleSetImpl)

Example 17 with CSPDependencyException

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])));
    }
}
Also used : CSPDependencyException(org.collectionspace.csp.api.core.CSPDependencyException) HashSet(java.util.HashSet)

Example 18 with CSPDependencyException

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;
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) CSPDependencyException(org.collectionspace.csp.api.core.CSPDependencyException) URL(java.net.URL) IOException(java.io.IOException) CSPDependencyException(org.collectionspace.csp.api.core.CSPDependencyException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException)

Example 19 with CSPDependencyException

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);
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) CSPDependencyException(org.collectionspace.csp.api.core.CSPDependencyException) File(java.io.File) SAXException(org.xml.sax.SAXException)

Example 20 with CSPDependencyException

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;
}
Also used : InputSource(org.xml.sax.InputSource) CSPDependencyException(org.collectionspace.csp.api.core.CSPDependencyException) IOException(java.io.IOException) ConfigFinder(org.collectionspace.csp.helper.core.ConfigFinder) SAXException(org.xml.sax.SAXException)

Aggregations

CSPDependencyException (org.collectionspace.csp.api.core.CSPDependencyException)21 IOException (java.io.IOException)7 SAXException (org.xml.sax.SAXException)7 ConfigFinder (org.collectionspace.csp.helper.core.ConfigFinder)6 Spec (org.collectionspace.chain.csp.schema.Spec)5 JSONException (org.json.JSONException)5 File (java.io.File)4 ExistException (org.collectionspace.csp.api.persistence.ExistException)4 Storage (org.collectionspace.csp.api.persistence.Storage)4 UnderlyingStorageException (org.collectionspace.csp.api.persistence.UnderlyingStorageException)4 UnimplementedException (org.collectionspace.csp.api.persistence.UnimplementedException)4 JSONObject (org.json.JSONObject)4 InputSource (org.xml.sax.InputSource)4 FileInputStream (java.io.FileInputStream)3 InputStream (java.io.InputStream)3 CoreConfig (org.collectionspace.chain.csp.inner.CoreConfig)3 CSPManager (org.collectionspace.csp.api.container.CSPManager)3 CSPManagerImpl (org.collectionspace.csp.container.impl.CSPManagerImpl)3 TestConfigFinder (org.collectionspace.csp.helper.test.TestConfigFinder)3 FileNotFoundException (java.io.FileNotFoundException)2