Search in sources :

Example 6 with CSPManager

use of org.collectionspace.csp.api.container.CSPManager in project application by collectionspace.

the class ServiceConfigGeneration method getServiceManager.

private CSPManager getServiceManager(File configFile) throws Exception {
    CSPManager result = null;
    CSPManager cspm = new CSPManagerImpl();
    cspm.register(new CoreConfig());
    cspm.register(new Spec());
    cspm.register(new ServicesStorageGenerator());
    // Do more initialization of our CSPManagerImpl instance (i.e., cspm)
    cspm.go();
    File configBase = configFile.getParentFile();
    // Saves a copy of the base config directory
    cspm.setConfigBase(configBase);
    cspm.configure(getSource(configFile), new ConfigFinder(null, configBase), true);
    this.setConfigBase(configBase);
    this.setConfigFile(configFile);
    result = cspm;
    return result;
}
Also used : ServicesStorageGenerator(org.collectionspace.chain.csp.persistence.services.ServicesStorageGenerator) CSPManager(org.collectionspace.csp.api.container.CSPManager) CoreConfig(org.collectionspace.chain.csp.inner.CoreConfig) CSPManagerImpl(org.collectionspace.csp.container.impl.CSPManagerImpl) TenantSpec(org.collectionspace.chain.csp.persistence.services.TenantSpec) Spec(org.collectionspace.chain.csp.schema.Spec) File(java.io.File) ConfigFinder(org.collectionspace.csp.helper.core.ConfigFinder) TestConfigFinder(org.collectionspace.csp.helper.test.TestConfigFinder)

Example 7 with CSPManager

use of org.collectionspace.csp.api.container.CSPManager in project application by collectionspace.

the class TestSchema method testSchema.

@Test
public void testSchema() {
    CSPManager cspm = new CSPManagerImpl();
    cspm.register(new CoreConfig());
    cspm.register(new Spec());
    try {
        cspm.go();
        // finds "src/main/resources/default.xml" when running tests
        InputSource configsource = getSource("config.xml");
        // pieces together the set of config/settings files for parsing
        cspm.configure(configsource, new ConfigFinder(null), false);
    } catch (CSPDependencyException e) {
        log.error("CSPManagerImpl failed");
        log.error(e.getLocalizedMessage());
    }
    ConfigRoot root = cspm.getConfigRoot();
    Spec spec = (Spec) root.getRoot(Spec.SPEC_ROOT);
    assertNotNull(spec);
    // spec.dump()
    Record r_obj = spec.getRecord("collection-object");
    if (log.isTraceEnabled()) {
        try {
            String recordDump = r_obj.dumpFields();
            log.trace(recordDump);
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            log.trace("JSONException encountered trying to log debugging information", e);
        }
    }
    assertNotNull(r_obj);
    assertEquals("collection-object", r_obj.getID());
    assertEquals("cataloging", r_obj.getWebURL());
    StringBuffer dumpBuffer = new StringBuffer(1000);
    r_obj.dump(dumpBuffer);
    System.out.println(dumpBuffer.toString());
    // log.info(spec.dump());
    JSONObject out = new JSONObject();
    Boolean ignore = false;
    String t = "";
    for (Record r : spec.getAllRecords()) {
        // log.info(r.getID());
        if (r.getID().equals("termlist")) {
            ignore = true;
        }
        if (!ignore) {
            try {
                t = spec.getRecord(r.getID()).dumpFields();
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        // log.info(t.toString());
        }
    }
/* RECORD/field -> FIELD(type) */
/*
		rules.addRule("record",new String[]{"field"},"field",new SectionGenerator() {
			public void step(Section milestone,Map<String, String> data) {
				milestone.addValue("field.type",milestone.getParent().getValue("/record/type"));
			}
		},new Target(){
			public Object populate(Object parent, ReadOnlySection milestone) {
				Field f=new Field();
				f.type=(String)milestone.getValue("field.type");
				((Record)parent).fields.add(f);
				return f;
			}
		});
			
		// MAIN/persistence/service -> URL(url)
		rules.addRule("main",new String[]{"persistence","service"},"url",new SectionGenerator() {
			public void step(Section milestone,Map<String, String> data) {
				milestone.addValue("service.url",data.get("/service/url"));
			}
		},null);
		*/
}
Also used : InputSource(org.xml.sax.InputSource) ConfigRoot(org.collectionspace.chain.csp.config.ConfigRoot) CSPManager(org.collectionspace.csp.api.container.CSPManager) CoreConfig(org.collectionspace.chain.csp.inner.CoreConfig) JSONException(org.json.JSONException) CSPManagerImpl(org.collectionspace.csp.container.impl.CSPManagerImpl) ConfigFinder(org.collectionspace.csp.helper.core.ConfigFinder) TestConfigFinder(org.collectionspace.csp.helper.test.TestConfigFinder) JSONObject(org.json.JSONObject) CSPDependencyException(org.collectionspace.csp.api.core.CSPDependencyException) Test(org.junit.Test)

Example 8 with CSPManager

use of org.collectionspace.csp.api.container.CSPManager in project application by collectionspace.

the class ServicesBaseClass method getDefaultSpec.

private Spec getDefaultSpec() throws CSPDependencyException {
    CSPManager cspm = getServiceManager();
    ConfigRoot root = cspm.getConfigRoot();
    Spec spec = (Spec) root.getRoot(Spec.SPEC_ROOT);
    return spec;
}
Also used : ConfigRoot(org.collectionspace.chain.csp.config.ConfigRoot) CSPManager(org.collectionspace.csp.api.container.CSPManager) Spec(org.collectionspace.chain.csp.schema.Spec)

Example 9 with CSPManager

use of org.collectionspace.csp.api.container.CSPManager in project application by collectionspace.

the class TestService method testJSONXMLConversion.

/**
 * I wouldn't call this a robust multipart test - needs more work but works
 * fine for single part multipart xml
 *
 * @throws Exception
 */
@Test
public void testJSONXMLConversion() throws Exception {
    CSPManager cspm = new CSPManagerImpl();
    cspm.register(new CoreConfig());
    cspm.register(new Spec());
    cspm.register(new ServicesStorageGenerator());
    cspm.go();
    // argh - test break when config changes *sob*
    cspm.configure(getRootSource(), new ConfigFinder(null), false);
    ConfigRoot root = cspm.getConfigRoot();
    Spec spec = (Spec) root.getRoot(Spec.SPEC_ROOT);
    testJSONXML(spec, "location", "location.xml", "location.json");
    testJSONXML(spec, "concept", "concept.xml", "concept.json");
    testJSONXML(spec, "citation", "citation.xml", "citation.json");
    testJSONXML(spec, "place", "placeXMLJSON.xml", "placeJSON.json");
    testJSONXML(spec, "work", "work.xml", "work.json");
    // CSPACE-6135: In CollectionObject, the computedCurrentLocation field is services-readonly,
    // so the JSON->XML->JSON conversion produces JSON that does not match the initial JSON
    // (computedCurrentLocation is omitted from the XML, so it does not appear in the JSON
    // converted back from the XML). In this case, we need to supply a third parameter to
    // specify the expected round-trip JSON. objectsReturnedJSON.json is identical to
    // objectsJSON.json, except computedCurrentLocation has been removed.
    testJSONXML(spec, "collection-object", "objectsXMLJSON.xml", "objectsJSON.json", "objectsReturnedJSON.json");
    testJSONXML(spec, "acquisition", "acquisitionXMLJSON.xml", "acquisitionJSON.json");
    testJSONXML(spec, "media", "media.xml", "mediaJSON.json");
    testJSONXML(spec, "loanin", "loanin.xml", "loanin.json");
    testJSONXML(spec, "loanout", "loanout.xml", "loanout.json");
    testJSONXML(spec, "intake", "intake.xml", "intake.json");
    testJSONXML(spec, "movement", "movement.xml", "movement.json");
    testJSONXML(spec, "valuationcontrol", "valuationcontrol.xml", "valuationcontrol.json");
    testJSONXML(spec, "objectexit", "objectexit.xml", "objectexit.json");
    testJSONXML(spec, "group", "group.xml", "group.json");
    testJSONXML(spec, "conditioncheck", "conditioncheck.xml", "conditioncheck.json");
    testJSONXML(spec, "conservation", "conservation.xml", "conservation.json");
    testJSONXML(spec, "exhibition", "exhibition.xml", "exhibition.json");
    testJSONXML(spec, "role", "role.xml", "role.json");
// testJSONXML(spec,"permrole","rolepermissions.xml","rolepermissions.json");
// testJSONXML(spec, "userrole","accountrole.xml","accountrole.json");
// testJSONXML(spec,
// "permission","permissionXMLJSON.xml","permissionsJSON.json");
}
Also used : ConfigRoot(org.collectionspace.chain.csp.config.ConfigRoot) CSPManager(org.collectionspace.csp.api.container.CSPManager) CoreConfig(org.collectionspace.chain.csp.inner.CoreConfig) CSPManagerImpl(org.collectionspace.csp.container.impl.CSPManagerImpl) Spec(org.collectionspace.chain.csp.schema.Spec) ConfigFinder(org.collectionspace.csp.helper.core.ConfigFinder) Test(org.junit.Test)

Example 10 with CSPManager

use of org.collectionspace.csp.api.container.CSPManager 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)

Aggregations

CSPManager (org.collectionspace.csp.api.container.CSPManager)11 Spec (org.collectionspace.chain.csp.schema.Spec)8 CoreConfig (org.collectionspace.chain.csp.inner.CoreConfig)7 CSPManagerImpl (org.collectionspace.csp.container.impl.CSPManagerImpl)7 ConfigFinder (org.collectionspace.csp.helper.core.ConfigFinder)7 ConfigRoot (org.collectionspace.chain.csp.config.ConfigRoot)6 TestConfigFinder (org.collectionspace.csp.helper.test.TestConfigFinder)5 CSPDependencyException (org.collectionspace.csp.api.core.CSPDependencyException)3 Test (org.junit.Test)3 ServicesStorageGenerator (org.collectionspace.chain.csp.persistence.services.ServicesStorageGenerator)2 TenantSpec (org.collectionspace.chain.csp.persistence.services.TenantSpec)2 File (java.io.File)1 Record (org.collectionspace.chain.csp.schema.Record)1 CSPRequestCache (org.collectionspace.csp.api.core.CSPRequestCache)1 CSPRequestCredentials (org.collectionspace.csp.api.core.CSPRequestCredentials)1 StorageGenerator (org.collectionspace.csp.api.persistence.StorageGenerator)1 RequestCache (org.collectionspace.csp.helper.core.RequestCache)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1 InputSource (org.xml.sax.InputSource)1