Search in sources :

Example 6 with ConfigRoot

use of org.collectionspace.chain.csp.config.ConfigRoot 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 7 with ConfigRoot

use of org.collectionspace.chain.csp.config.ConfigRoot 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 8 with ConfigRoot

use of org.collectionspace.chain.csp.config.ConfigRoot in project application by collectionspace.

the class TenantServlet method setCacheAge.

protected void setCacheAge(String tenant, String mimetype, String path, HttpServletResponse servlet_response) {
    ConfigRoot root = tenantCSPM.get(tenant).getConfigRoot();
    Spec spec = (Spec) root.getRoot(Spec.SPEC_ROOT);
    AdminData adminData = spec.getAdminData();
    // The default value
    int cacheAge = 0;
    if (MIME_HTML.equals(mimetype)) {
        cacheAge = adminData.getUiStaticHTMLResourcesCacheAge();
    } else if (MIME_CSS.equals(mimetype)) {
        cacheAge = adminData.getUiStaticCSSResourcesCacheAge();
    } else if (MIME_JSON.equals(mimetype)) {
        cacheAge = adminData.getUiStaticJSResourcesCacheAge();
    } else if (MIME_PLAIN.equals(mimetype) || mimetype == null) {
        // try to refine from extension
        if (path.endsWith(SUFFIX_PROPS)) {
            cacheAge = adminData.getUiStaticPropertiesResourcesCacheAge();
        } else if (path.endsWith(SUFFIX_JSON)) {
            cacheAge = adminData.getUiStaticJSResourcesCacheAge();
        }
    } else if (mimetype != null) {
        if (mimetype.startsWith(MIME_IMAGE) || mimetype.startsWith(MIME_AUDIO) || mimetype.startsWith(MIME_VIDIO)) {
            cacheAge = adminData.getUiStaticMediaResourcesCacheAge();
        }
    }
    if (cacheAge > 0) {
        // Create a cache header per the timeout requested (usu. by the individual request handler)
        servlet_response.addHeader("Cache-Control", "max-age=" + Integer.toString(cacheAge));
    }
}
Also used : AdminData(org.collectionspace.chain.csp.schema.AdminData) ConfigRoot(org.collectionspace.chain.csp.config.ConfigRoot) Spec(org.collectionspace.chain.csp.schema.Spec)

Example 9 with ConfigRoot

use of org.collectionspace.chain.csp.config.ConfigRoot in project application by collectionspace.

the class TenantServlet method serviceWTenant.

/**
 * If you know the tenant id then
 * Check for global issues and if not run set up and then test if this is a init request, a composite request or a single request and
 * do the right thing
 * @param tenantid
 * @param pathparts
 * @param initcheck
 * @param servlet_request
 * @param servlet_response
 * @throws ServletException
 * @throws IOException
 * @throws BadRequestException
 * @throws UnauthorizedException
 */
protected void serviceWTenant(String tenantid, List<String> pathparts, String initcheck, HttpServletRequest servlet_request, HttpServletResponse servlet_response) throws ServletException, IOException, BadRequestException, UnauthorizedException {
    if (locked_down != null) {
        // this ended up with a status 200 hmmmm not great so changed it to return a 400... hopefully that wont break anythign else
        servlet_response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Servlet is locked down in a hard fail because of fatal error: " + locked_down);
        // servlet_response.getWriter().append("Servlet is locked down in a hard fail because of fatal error: "+locked_down);
        return;
    }
    if (initcheck.equals("init")) {
        tenantCSPM.put(tenantid, new CSPManagerImpl());
        tenantInit.put(tenantid, false);
        setup(tenantid);
        ConfigFinder cfg = new ConfigFinder(getServletContext());
        try {
            InputSource cfg_stream = cfg.resolveEntity("-//CSPACE//ROOT", "cspace-config-" + tenantid + ".xml");
            String test = IOUtils.toString(cfg_stream.getByteStream());
            // servlet_response.sendError(HttpServletResponse.SC_BAD_REQUEST, "cspace-config re-loaded"+test);
            servlet_response.getWriter().append("cspace-config re-loaded" + test);
        } catch (SAXException e) {
            // TODO Auto-generated catch block
            servlet_response.sendError(HttpServletResponse.SC_BAD_REQUEST, "cspace-config re-loadedfailed");
        }
        return;
    }
    if (!tenantInit.containsKey(tenantid) || !tenantInit.get(tenantid)) {
        setup(tenantid);
    }
    if (locked_down != null) {
        // this ended up with a status 200 hmmmm not great so changed it to return a 400... hopefully that wont break anythign else
        servlet_response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Servlet is locked down in a hard fail because of fatal error: " + locked_down);
        // servlet_response.getWriter().append("Servlet is locked down in a hard fail because of fatal error: "+locked_down);
        return;
    }
    if (perhapsServeFixedContent(servlet_request, servlet_response)) {
        return;
    }
    // Setup our request object
    UI web = tenantCSPM.get(tenantid).getUI("web");
    if (!tenantUmbrella.containsKey(tenantid)) {
        synchronized (getClass()) {
            if (!tenantUmbrella.containsKey(tenantid)) {
                tenantUmbrella.put(tenantid, new WebUIUmbrella((WebUI) web));
            }
        }
    }
    try {
        ConfigRoot root = tenantCSPM.get(tenantid).getConfigRoot();
        Spec spec = (Spec) root.getRoot(Spec.SPEC_ROOT);
        WebUIRequest req = new WebUIRequest(tenantUmbrella.get(tenantid), servlet_request, servlet_response, spec.getAdminData().getCookieLife(), pathparts);
        if (is_composite(req)) {
            serve_composite(web, req);
        } else {
            web.serviceRequest(req);
            req.solidify(true);
        }
    } catch (UIException e) {
        throw new BadRequestException("UIException", e);
    }
}
Also used : InputSource(org.xml.sax.InputSource) ConfigRoot(org.collectionspace.chain.csp.config.ConfigRoot) CSPManagerImpl(org.collectionspace.csp.container.impl.CSPManagerImpl) ConfigFinder(org.collectionspace.csp.helper.core.ConfigFinder) SAXException(org.xml.sax.SAXException) WebUI(org.collectionspace.chain.csp.webui.main.WebUI) WebUI(org.collectionspace.chain.csp.webui.main.WebUI) UI(org.collectionspace.csp.api.ui.UI) UIException(org.collectionspace.csp.api.ui.UIException) Spec(org.collectionspace.chain.csp.schema.Spec)

Example 10 with ConfigRoot

use of org.collectionspace.chain.csp.config.ConfigRoot in project application by collectionspace.

the class NullResolver method serviceUIWTenant.

/**
 * UI specific logic to work out the file needed from the server based on the url
 * fromthe cspace-ui servlet context
 * @param tenant
 * @param servlet_request
 * @param servlet_response
 * @throws BadRequestException
 * @throws ConnectionException
 * @throws DocumentException
 * @throws IOException
 */
protected void serviceUIWTenant(String tenant, HttpServletRequest servlet_request, HttpServletResponse servlet_response) throws BadRequestException, ConnectionException, DocumentException, IOException {
    String pathinfo = servlet_request.getPathInfo();
    String[] pathbits = pathinfo.substring(1).split("/");
    String urlredirect = "/collectionspace/ui/" + tenant + "/html/index.html";
    // clean up bad links - hopefully these links are never found any more...
    if (pathinfo.equals("/html") || pathinfo.equals("/html/")) {
        servlet_response.sendRedirect(urlredirect);
    } else if (pathinfo.equals("/" + tenant) || pathinfo.equals("/" + tenant + "/html") || pathinfo.equals("/" + tenant + "/")) {
        servlet_response.sendRedirect(urlredirect);
    } else if (pathinfo.equals("/" + tenant + "/index.html") || pathinfo.equals("/" + tenant + "/html/")) {
        servlet_response.sendRedirect(urlredirect);
    } else if (pathinfo.equals("/" + tenant + "/html") || pathinfo.equals("/" + tenant + "/html/")) {
        servlet_response.sendRedirect(urlredirect);
    }
    ServletContext sc = null;
    sc = getServletContext().getContext("/cspace-ui");
    if (sc == null) {
        servlet_response.sendError(HttpServletResponse.SC_BAD_REQUEST, "missing servlet context cspace-ui");
    }
    // work out what to do with the item based on it's type
    if (pathbits[0].equals("css") || pathbits[0].equals("js") || pathbits[0].equals("lib") || pathbits[0].equals("images")) {
        String tenantposs = getTenantByCookie(servlet_request);
        if (serverFixedExternalContent(servlet_request, servlet_response, sc, pathinfo, tenantposs)) {
            return;
        }
    }
    if (pathbits[0].equals("bundle")) {
        String tenantposs = getTenantByCookie(servlet_request);
        if (serverCreateMergedExternalContent(servlet_request, servlet_response, sc, pathinfo, tenantposs)) {
            return;
        }
    }
    if (pathbits[0].equals("config") || pathbits[1].equals("config")) {
    // tenant = getTenantByCookie(servlet_request);
    }
    if (!tenantInit.containsKey(tenant) || !tenantInit.get(tenant)) {
        setup(tenant);
    }
    /**
     * Support composite requests in ui calls as well as app direct calls
     */
    if (is_composite(pathinfo)) {
        List<String> p = new ArrayList<String>();
        for (String part : servlet_request.getPathInfo().split("/")) {
            if ("".equals(part))
                continue;
            p.add(part);
        }
        p.remove(0);
        ConfigRoot root = tenantCSPM.get(tenant).getConfigRoot();
        Spec spec = (Spec) root.getRoot(Spec.SPEC_ROOT);
        WebUIRequest req;
        UI web = tenantCSPM.get(tenant).getUI("web");
        if (!tenantUmbrella.containsKey(tenant)) {
            synchronized (getClass()) {
                if (!tenantUmbrella.containsKey(tenant)) {
                    tenantUmbrella.put(tenant, new WebUIUmbrella((WebUI) web));
                }
            }
        }
        try {
            req = new WebUIRequest(tenantUmbrella.get(tenant), servlet_request, servlet_response, spec.getAdminData().getCookieLife(), p);
            serveComposite(tenant, req, sc);
        } catch (UIException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } else {
        serveSingle(tenant, servlet_request, servlet_response, pathinfo, pathbits, sc);
    }
}
Also used : WebUI(org.collectionspace.chain.csp.webui.main.WebUI) ConfigRoot(org.collectionspace.chain.csp.config.ConfigRoot) WebUI(org.collectionspace.chain.csp.webui.main.WebUI) UI(org.collectionspace.csp.api.ui.UI) ArrayList(java.util.ArrayList) ServletContext(javax.servlet.ServletContext) UIException(org.collectionspace.csp.api.ui.UIException) Spec(org.collectionspace.chain.csp.schema.Spec)

Aggregations

ConfigRoot (org.collectionspace.chain.csp.config.ConfigRoot)13 Spec (org.collectionspace.chain.csp.schema.Spec)12 CSPManager (org.collectionspace.csp.api.container.CSPManager)6 CSPManagerImpl (org.collectionspace.csp.container.impl.CSPManagerImpl)5 ConfigFinder (org.collectionspace.csp.helper.core.ConfigFinder)5 CoreConfig (org.collectionspace.chain.csp.inner.CoreConfig)4 WebUI (org.collectionspace.chain.csp.webui.main.WebUI)4 UI (org.collectionspace.csp.api.ui.UI)4 JSONObject (org.json.JSONObject)3 Test (org.junit.Test)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 StringWriter (java.io.StringWriter)2 TeeInputStream (org.apache.commons.io.input.TeeInputStream)2 TenantSpec (org.collectionspace.chain.csp.persistence.services.TenantSpec)2 UIMapping (org.collectionspace.chain.csp.webui.external.UIMapping)2 CSPDependencyException (org.collectionspace.csp.api.core.CSPDependencyException)2 UIException (org.collectionspace.csp.api.ui.UIException)2 TestConfigFinder (org.collectionspace.csp.helper.test.TestConfigFinder)2 InputSource (org.xml.sax.InputSource)2