use of org.collectionspace.csp.api.core.CSPDependencyException in project application by collectionspace.
the class WebUI 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");
configure_finish(spec);
for (WebMethod m : all_methods) m.configure(this, spec);
String name = (String) ctx.getConfigRoot().getRoot(CSPContext.XXX_SERVICE_NAME);
xxx_storage = ctx.getStorage(name);
}
use of org.collectionspace.csp.api.core.CSPDependencyException in project application by collectionspace.
the class ConfigFinder method resolveEntity.
/*
* Try to resolve/find and load a resource/entity/file. Uses a variety of method and locations to resolve the resource/entity/file
* (non-Javadoc)
* @see org.xml.sax.EntityResolver#resolveEntity(java.lang.String, java.lang.String)
*/
@Override
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
try {
InputStream out = null;
// If there is a conf base directory, look for it there first
File configBase = this.getConfigBase();
if (configBase != null && configBase.exists()) {
String fileEntityName = configBase.getAbsolutePath() + "/" + systemId;
log.debug(String.format("Looking to resolve publicId:%s systemId:%s in '%s'.", publicId, systemId, fileEntityName));
File fileEntity = new File(fileEntityName);
if (fileEntity.exists() == true) {
log.debug(String.format("Resolved '%s'.\r\n", fileEntityName));
out = new FileInputStream(fileEntity);
InputSource result = new InputSource(out);
result.setPublicId(fileEntity.getPath());
return result;
}
}
// Look for it in the env vars
String envVarName = TEST_CONFIG;
out = getDataFromEnvironmentVariable(envVarName);
if (out != null) {
InputSource result = new InputSource(out);
result.setPublicId(System.getenv(envVarName));
return result;
}
// Look for it as a servlet container attribute
if (ctx != null && "-//CSPACE//ROOT".equals(publicId)) {
String attributeName = "config-data";
out = getDataFromAttribute(attributeName);
if (out != null) {
InputSource result = new InputSource(out);
result.setPublicId((String) ctx.getAttribute(attributeName));
return result;
}
String attributePath = "config-path";
out = getDataFromAttributePath(attributePath);
if (out != null) {
InputSource result = new InputSource(out);
result.setPublicId((String) ctx.getAttribute(attributePath));
return result;
}
String attributeFilename = "config-filename";
out = getDataFromName(attributeFilename);
if (out != null) {
InputSource result = new InputSource(out);
result.setPublicId((String) ctx.getAttribute(attributeFilename));
return result;
}
}
// use config from tomcat-main/src/main/resources if this is a test run by Maven
if ("-//CSPACE//TESTROOT".equals(publicId)) {
out = getConfigStreamViaClassLoader(systemId);
if (out != null) {
InputSource result = new InputSource(out);
result.setPublicId(systemId);
return result;
}
}
out = getDataFromJBossPath(systemId);
if (out != null) {
InputSource result = new InputSource(out);
result.setPublicId(systemId);
return result;
}
// running tests find the resource/entity here
out = getDataFromClasspath(systemId);
if (out != null) {
InputSource result = new InputSource(out);
result.setPublicId(systemId);
return result;
}
out = getConfigStreamViaClassLoader(systemId);
if (out != null) {
InputSource result = new InputSource(out);
result.setPublicId(systemId);
return result;
}
// otherwise, throw an exception
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 ConfigFinder method getConfigFileViaClassLoader.
private static File getConfigFileViaClassLoader(String configFilename) throws CSPDependencyException {
File result = null;
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 {
URL fileURL = loader.getResource(configFilename);
if (fileURL != null) {
log.debug("Found config for testing: " + configFilename);
log.debug(String.format("Config file URL: '%s'", fileURL.toString()));
String filename = fileURL.getFile();
log.debug(String.format("URL file: '%s'", filename));
File file = new File(filename);
if (file.exists() == true) {
result = file;
} else {
log.error(String.format("App config file '%s' from URL '%s' does not exist.", filename, fileURL));
}
} else {
throw new CSPDependencyException("Failed to open config file at " + configFilename);
}
} catch (Exception e) {
log.error(String.format("Could not load config file '%s'", configFilename), e);
}
return result;
}
use of org.collectionspace.csp.api.core.CSPDependencyException in project application by collectionspace.
the class ServicesStorageGenerator method real_init.
private void real_init(CSPManager cspManager, Spec spec, boolean forXsdGeneration) throws CSPDependencyException {
try {
ServicesConnection conn = new ServicesConnection(base_url, ims_url);
for (Record r : spec.getAllRecords()) {
if (r.isType("blob") || r.isType("report") || r.isType("batch"))
addChild(r.getID(), new BlobStorage(spec.getRecord(r.getID()), conn));
else if (r.isType("userdata"))
addChild(r.getID(), new UserStorage(spec.getRecord(r.getID()), conn));
else if (r.isType("record") || r.isType("searchall"))
addChild(r.getID(), new RecordStorage(spec.getRecord(r.getID()), conn));
else if (r.isType("authority"))
addChild(r.getID(), new ConfiguredVocabStorage(spec.getRecord(r.getID()), conn));
else if (r.isType("authorizationdata"))
addChild(r.getID(), new AuthorizationStorage(spec.getRecord(r.getID()), conn));
}
addChild("direct", new DirectRedirector(spec));
addChild("id", new ServicesIDGenerator(conn, spec));
addChild("relations", new ServicesRelationStorage(conn, spec));
//
if (forXsdGeneration == false) {
initializeAuthorities(cspManager, spec);
}
} catch (Exception e) {
e.printStackTrace();
// XXX wrong type
throw new CSPDependencyException("Could not set target", e);
}
}
use of org.collectionspace.csp.api.core.CSPDependencyException 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);
*/
}
Aggregations