Search in sources :

Example 11 with CSPDependencyException

use of org.collectionspace.csp.api.core.CSPDependencyException in project application by collectionspace.

the class ServicesStorageGenerator method complete_init.

@Override
public void complete_init(CSPManager cspManager, boolean forXsdGeneration) throws CSPDependencyException {
    Spec spec = (Spec) ctx.getConfigRoot().getRoot(Spec.SPEC_ROOT);
    if (spec == null) {
        throw new CSPDependencyException("Could not load spec");
    }
    real_init(cspManager, spec, forXsdGeneration);
}
Also used : CSPDependencyException(org.collectionspace.csp.api.core.CSPDependencyException) Spec(org.collectionspace.chain.csp.schema.Spec)

Example 12 with CSPDependencyException

use of org.collectionspace.csp.api.core.CSPDependencyException in project application by collectionspace.

the class ServicesStorageGenerator method configure.

@Override
public void configure(RuleSet rules) throws CSPDependencyException {
    /* MAIN/persistence/service -> SERVICE */
    rules.addRule(SECTIONED, new String[] { "persistence", "service" }, SECTION_PREFIX + "service", null, new RuleTarget() {

        @Override
        public Object populate(Object parent, ReadOnlySection milestone) {
            ((ConfigRoot) parent).setRoot(SERVICE_ROOT, ServicesStorageGenerator.this);
            base_url = (String) milestone.getValue("/url");
            // XXX should be path-selectable
            ((ConfigRoot) parent).setRoot(CSPContext.XXX_SERVICE_NAME, "service");
            ims_url = (String) milestone.getValue("/ims-url");
            tenantSpec = new TenantSpec(milestone);
            return ServicesStorageGenerator.this;
        }
    });
    rules.addRule(SECTION_PREFIX + "service", new String[] { "remoteclients", "remoteclient" }, SECTION_PREFIX + "remoteclient", null, new RuleTarget() {

        @Override
        public Object populate(Object parent, ReadOnlySection milestone) throws Exception {
            String name = (String) milestone.getValue("/name");
            String url = (String) milestone.getValue("/url");
            String username = (String) milestone.getValue("/user");
            String password = (String) milestone.getValue("/password");
            String sslString = (String) milestone.getValue("/ssl");
            boolean ssl = false;
            if (sslString != null && sslString.equalsIgnoreCase(Boolean.toString(true))) {
                ssl = true;
            }
            String authString = (String) milestone.getValue("/auth");
            boolean auth = false;
            if (authString != null && authString.equalsIgnoreCase(Boolean.toString(true))) {
                auth = true;
            }
            String tenantId = (String) milestone.getValue("/tenantId");
            String tenantName = (String) milestone.getValue("/tenantName");
            RemoteClient remoteClient = tenantSpec.new RemoteClient(name, url, username, password, ssl, auth, tenantId, tenantName);
            tenantSpec.addRemoteClient(remoteClient);
            return this;
        }
    });
    rules.addRule(SECTION_PREFIX + "service", new String[] { "repository", "dateformats", "pattern" }, SECTION_PREFIX + "dateformat", null, new RuleTarget() {

        @Override
        public Object populate(Object parent, ReadOnlySection milestone) {
            String format = (String) milestone.getValue("");
            tenantSpec.addFormat(format);
            return this;
        }
    });
    rules.addRule(SECTION_PREFIX + "service", new String[] { "repository", "languages", "language" }, SECTION_PREFIX + "language", null, new RuleTarget() {

        @Override
        public Object populate(Object parent, ReadOnlySection milestone) {
            String lang = (String) milestone.getValue("");
            tenantSpec.addLanguage(lang);
            return this;
        }
    });
}
Also used : RuleTarget(org.collectionspace.chain.csp.config.RuleTarget) RemoteClient(org.collectionspace.chain.csp.persistence.services.TenantSpec.RemoteClient) ReadOnlySection(org.collectionspace.chain.csp.config.ReadOnlySection) UIException(org.collectionspace.csp.api.ui.UIException) CSPDependencyException(org.collectionspace.csp.api.core.CSPDependencyException)

Example 13 with CSPDependencyException

use of org.collectionspace.csp.api.core.CSPDependencyException in project application by collectionspace.

the class TenantServlet method load_config.

/**
 * retrieve the correct config file based on the tenantId
 * @param ctx
 * @param tenantId
 * @throws CSPDependencyException
 */
protected void load_config(ServletContext ctx, String tenantId) throws CSPDependencyException {
    try {
        ConfigFinder cfg = new ConfigFinder(ctx);
        InputSource cfg_stream = cfg.resolveEntity("-//CSPACE//ROOT", "cspace-config-" + tenantId + ".xml");
        if (cfg_stream == null) {
            locked_down = "Cannot find cspace config xml file";
        } else {
            tenantCSPM.get(tenantId).configure(cfg_stream, cfg, false);
        }
    } catch (UnsupportedEncodingException e) {
        throw new CSPDependencyException("Config has bad character encoding", e);
    } catch (IOException e) {
        throw new CSPDependencyException("Cannot load config", e);
    } catch (SAXException e) {
        throw new CSPDependencyException("Cannot parse config file", e);
    }
}
Also used : InputSource(org.xml.sax.InputSource) CSPDependencyException(org.collectionspace.csp.api.core.CSPDependencyException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) ConfigFinder(org.collectionspace.csp.helper.core.ConfigFinder) SAXException(org.xml.sax.SAXException)

Example 14 with CSPDependencyException

use of org.collectionspace.csp.api.core.CSPDependencyException in project application by collectionspace.

the class TestData method getSpec.

public final Spec getSpec(ServletTester tester) {
    if (this.spec == null) {
        CSPManager cspm = new CSPManagerImpl();
        cspm.register(new CoreConfig());
        cspm.register(new Spec());
        try {
            cspm.go();
            tester.getAttribute("config-filename");
            String filename = (String) tester.getAttribute("config-filename");
            cspm.configure(getSource(filename), new ConfigFinder(null), false);
        } catch (CSPDependencyException e) {
            log.info("CSPManagerImpl failed");
            log.info(tester.getAttribute("config-filename").toString());
            log.info(e.getLocalizedMessage());
        }
        ConfigRoot root = cspm.getConfigRoot();
        Spec spec = (Spec) root.getRoot(Spec.SPEC_ROOT);
        this.spec = spec;
    }
    return this.spec;
}
Also used : ConfigRoot(org.collectionspace.chain.csp.config.ConfigRoot) CSPManager(org.collectionspace.csp.api.container.CSPManager) CoreConfig(org.collectionspace.chain.csp.inner.CoreConfig) CSPDependencyException(org.collectionspace.csp.api.core.CSPDependencyException) CSPManagerImpl(org.collectionspace.csp.container.impl.CSPManagerImpl) Spec(org.collectionspace.chain.csp.schema.Spec) ConfigFinder(org.collectionspace.csp.helper.core.ConfigFinder) TestConfigFinder(org.collectionspace.csp.helper.test.TestConfigFinder)

Example 15 with CSPDependencyException

use of org.collectionspace.csp.api.core.CSPDependencyException in project application by collectionspace.

the class TestServices method getServiceManager.

private CSPManager getServiceManager(String filename) {
    CSPManager cspm = new CSPManagerImpl();
    cspm.register(new CoreConfig());
    cspm.register(new Spec());
    cspm.register(new ServicesStorageGenerator());
    try {
        cspm.go();
        cspm.configure(getSource(filename), new ConfigFinder(null), false);
    } catch (CSPDependencyException e) {
        log.error("CSPManagerImpl failed");
        log.error(e.getLocalizedMessage());
    }
    return cspm;
}
Also used : ServicesStorageGenerator(org.collectionspace.chain.csp.persistence.services.ServicesStorageGenerator) CSPManager(org.collectionspace.csp.api.container.CSPManager) CoreConfig(org.collectionspace.chain.csp.inner.CoreConfig) CSPDependencyException(org.collectionspace.csp.api.core.CSPDependencyException) CSPManagerImpl(org.collectionspace.csp.container.impl.CSPManagerImpl) TenantSpec(org.collectionspace.chain.csp.persistence.services.TenantSpec) Spec(org.collectionspace.chain.csp.schema.Spec) ConfigFinder(org.collectionspace.csp.helper.core.ConfigFinder) TestConfigFinder(org.collectionspace.csp.helper.test.TestConfigFinder)

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