use of org.collectionspace.chain.csp.config.ConfigRoot in project application by collectionspace.
the class NullResolver method serveSingle.
/**
* Return a single request from the cspace-ui servlet context
* @param tenant
* @param sub
* @param sc
* @throws UIException
* @throws IOException
*/
private void serveSingle(String tenant, CompositeWebUIRequestPart sub, ServletContext sc) throws UIException, IOException {
// Setup our request object
UI web = tenantCSPM.get(tenant).getUI("web");
WebUI webui = (WebUI) web;
UIMapping[] allmappings = webui.getAllMappings();
ConfigRoot root = tenantCSPM.get(tenant).getConfigRoot();
Spec spec = (Spec) root.getRoot(Spec.SPEC_ROOT);
// this doesn't seem to work yet
Boolean doMetaConfig = true;
String[] pathbits = sub.getPrincipalPath();
String pathinfo = StringUtils.join(pathbits, "/");
String path = pathinfo;
Map<String, Object> validmap = doMapping(pathinfo, allmappings, spec);
if (null != validmap) {
path = (String) validmap.get("File");
if (((UIMapping) validmap.get("map")).hasMetaConfig() && doMetaConfig) {
InputStream is = getFixedContent(sc, path, tenant);
StringWriter writer = new StringWriter();
IOUtils.copy(is, writer, "UTF-8");
String theString = writer.toString();
/*
SAXReader reader = new SAXReader();
reader.setEntityResolver(new NullResolver());
Document xmlfile = null;
ByteArrayOutputStream dump = new ByteArrayOutputStream();
xmlfile = reader.read(new TeeInputStream(is, dump));
// log.info(dump.toString("UTF-8"));
// log.info(xmlfile.asXML());<tr></tr<.>
TODO I want this to work... it just doesn't yet as I haven\'t had time to work on it
this is all about replace items in the title etc of the universal files so they become more specific
*/
for (String metafield : ((UIMapping) validmap.get("map")).getAllMetaConfigs()) {
String rtext = ((UIMapping) validmap.get("map")).getMetaConfig(metafield).parseValue((Record) validmap.get("record"), (Instance) validmap.get("instance"));
// try as json
String regex = "\"" + metafield + "\": \"[^\"]*\"";
String replacement = "\"" + metafield + "\": \"" + rtext + "\"";
theString = theString.replaceFirst(regex, replacement);
// try as xml
String regex2 = "<" + metafield + ">[^<]*</" + metafield + ">";
String replacement2 = "<" + metafield + ">" + rtext + "</" + metafield + ">";
theString = theString.replaceFirst(regex2, replacement2);
}
InputStream is2 = new ByteArrayInputStream(theString.getBytes("UTF-8"));
serveExternalContent(sub, sc, is2, path);
is.close();
return;
}
}
if (pathbits[1].equals("bundle")) {
if (serverCreateMergedExternalContent(sub, sc, pathinfo, tenant)) {
return;
}
}
if (serverFixedExternalContent(sub, sc)) {
return;
}
}
use of org.collectionspace.chain.csp.config.ConfigRoot in project application by collectionspace.
the class NullResolver method serveSingle.
/**
* abstraction for returning a single item.
* probably could be simplified with other serveSingle function
* @param tenant
* @param servlet_request
* @param servlet_response
* @param pathinfo
* @param pathbits
* @param sc
* @throws IOException
* @throws BadRequestException
* @throws UnsupportedEncodingException
*/
private void serveSingle(String tenant, HttpServletRequest servlet_request, HttpServletResponse servlet_response, String pathinfo, String[] pathbits, ServletContext sc) throws IOException, BadRequestException, UnsupportedEncodingException {
// should we redirect this url or just do the normal stuff
// Setup our request object
UI web = tenantCSPM.get(tenant).getUI("web");
WebUI webui = (WebUI) web;
UIMapping[] allmappings = webui.getAllMappings();
ConfigRoot root = tenantCSPM.get(tenant).getConfigRoot();
Spec spec = (Spec) root.getRoot(Spec.SPEC_ROOT);
// this doesn't seem to work yet
Boolean doMetaConfig = true;
String path = pathinfo;
Map<String, Object> validmap = doMapping(pathinfo, allmappings, spec);
if (null != validmap) {
path = (String) validmap.get("File");
if (((UIMapping) validmap.get("map")).hasMetaConfig() && doMetaConfig) {
InputStream is = getFixedContent(sc, path, tenant);
StringWriter writer = new StringWriter();
IOUtils.copy(is, writer, "UTF-8");
String theString = writer.toString();
/*
SAXReader reader = new SAXReader();
reader.setEntityResolver(new NullResolver());
Document xmlfile = null;
ByteArrayOutputStream dump = new ByteArrayOutputStream();
xmlfile = reader.read(new TeeInputStream(is, dump));
// log.info(dump.toString("UTF-8"));
// log.info(xmlfile.asXML());<tr></tr<.>
TODO I want this to work... it just doesn't yet as I haven\'t had time to work on it
this is all about replace items in the title etc of the universal files so they become more specific
*/
for (String metafield : ((UIMapping) validmap.get("map")).getAllMetaConfigs()) {
String rtext = ((UIMapping) validmap.get("map")).getMetaConfig(metafield).parseValue((Record) validmap.get("record"), (Instance) validmap.get("instance"));
// try as json
String regex = "\"" + metafield + "\": \"[^\"]*\"";
String replacement = "\"" + metafield + "\": \"" + rtext + "\"";
theString = theString.replaceFirst(regex, replacement);
// try as xml
String regex2 = "<" + metafield + ">[^<]*</" + metafield + ">";
String replacement2 = "<" + metafield + ">" + rtext + "</" + metafield + ">";
theString = theString.replaceFirst(regex2, replacement2);
}
InputStream is2 = new ByteArrayInputStream(theString.getBytes("UTF-8"));
serveContent(servlet_response, is2);
is.close();
return;
}
}
if (pathbits[1].equals("bundle")) {
if (serverCreateMergedExternalContent(servlet_request, servlet_response, sc, pathinfo, tenant)) {
return;
}
}
if (serverFixedExternalContent(servlet_request, servlet_response, sc, path, tenant)) {
return;
}
}
use of org.collectionspace.chain.csp.config.ConfigRoot in project application by collectionspace.
the class ServicesBaseClass method makeServicesStorage.
protected Storage makeServicesStorage() throws CSPDependencyException {
CSPManager cspm = getServiceManager();
ConfigRoot root = cspm.getConfigRoot();
Spec spec = (Spec) root.getRoot(Spec.SPEC_ROOT);
assertNotNull(spec);
// XXX this is spec specific testing that will break when we rename the object in the UI
Record r_obj = spec.getRecord("collection-object");
assertNotNull(r_obj);
assertEquals("collection-object", r_obj.getID());
assertEquals("cataloging", r_obj.getWebURL());
StorageGenerator gen = cspm.getStorage("service");
CSPRequestCredentials creds = gen.createCredentials();
creds.setCredential(ServicesStorageGenerator.CRED_USERID, spec.getAdminData().getAuthUser());
creds.setCredential(ServicesStorageGenerator.CRED_PASSWORD, spec.getAdminData().getAuthPass());
return gen.getStorage(creds, new RequestCache());
}
use of org.collectionspace.chain.csp.config.ConfigRoot in project application by collectionspace.
the class TestService method testXMLJSONConversion.
@Test
public void testXMLJSONConversion() 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);
testXMLJSON(spec, "location", "location.xml", "location.json");
testXMLJSON(spec, "concept", "concept.xml", "concept.json");
testXMLJSON(spec, "place", "placeXMLJSON.xml", "placeJSON.json");
testXMLJSON(spec, "citation", "citation.xml", "citation.json");
testXMLJSON(spec, "work", "work.xml", "work.json");
testXMLJSON(spec, "collection-object", "objectsXMLJSON.xml", "objectsJSON.json");
testXMLJSON(spec, "acquisition", "acquisitionXMLJSON.xml", "acquisitionJSON.json");
testXMLJSON(spec, "intake", "intake.xml", "intake.json");
testXMLJSON(spec, "loanin", "loanin.xml", "loanin.json");
testXMLJSON(spec, "loanout", "loanout.xml", "loanout.json");
testXMLJSON(spec, "valuationcontrol", "valuationcontrol.xml", "valuationcontrol.json");
testXMLJSON(spec, "movement", "movement.xml", "movement.json");
testXMLJSON(spec, "objectexit", "objectexit.xml", "objectexit.json");
testXMLJSON(spec, "group", "group.xml", "group.json");
testXMLJSON(spec, "media", "media.xml", "mediaJSON.json");
testXMLJSON(spec, "conditioncheck", "conditioncheck.xml", "conditioncheck.json");
testXMLJSON(spec, "conservation", "conservation.xml", "conservation.json");
testXMLJSON(spec, "exhibition", "exhibition.xml", "exhibition.json");
testXMLJSON(spec, "role", "role.xml", "role.json");
testXMLJSON(spec, "permrole", "rolepermissions.xml", "rolepermissions.json");
testXMLJSON(spec, "userrole", "accountrole.xml", "accountrole.json");
// testXMLJSON(spec,
// "permission","permissionXMLJSON.xml","permissionsJSON.json");
// testXMLJSON(spec,
// "organization","orgauthref.xml","permissionsJSON.json");
}
use of org.collectionspace.chain.csp.config.ConfigRoot 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