Search in sources :

Example 6 with Spec

use of org.collectionspace.chain.csp.schema.Spec in project application by collectionspace.

the class MakeXsd method generateFieldGroup.

/*
	 * This method generates an XML Schema complex type definition for "ui-type" config attributes -e.g., "groupfield/structureddate"
	 */
private String generateFieldGroup(FieldSet fieldSet, Element ele, Namespace ns, Element root) throws Exception {
    String fieldSetServicesType = fieldSet.getServicesType(false);
    Spec spec = fieldSet.getRecord().getSpec();
    // find a record that corresponds to the fieldset's service type
    Record record = spec.getRecord(fieldSetServicesType);
    if (record == null) {
        // try again, this time try a group type
        record = spec.getRecord(fieldSetServicesType);
    }
    if (record == null) {
        String msg = String.format("Could not find parent record for field '%s'.", fieldSet.toString());
        throw new Exception(msg);
    }
    String servicesType = record.getServicesType();
    // 
    // Special case for backwards compat with existing "dateGroup" table/schema in Services
    // 
    String servicesGroupType = fieldSet.getServicesGroupType(false);
    if (fieldSetServicesType.equalsIgnoreCase(servicesGroupType) == false) {
        servicesType = servicesGroupType;
    }
    if (servicesType == null) {
        servicesType = fieldSetServicesType;
    }
    boolean definedNewType = false;
    Element currentElement = ele;
    Element complexElement = currentElement;
    // 
    if (fieldSet.isAStructureDate() == true) {
        @SuppressWarnings("unused") String // for debugging puposes only
        parentRecordName = fieldSet.getRecord().getID();
        // We'll add the structured date type def to the root/outer level
        currentElement = root;
        complexElement = root.addElement(new QName("complexType", ns));
        complexElement.addAttribute("name", servicesType);
        definedNewType = true;
        Element sequenced = complexElement.addElement(new QName("sequence", ns));
        currentElement = sequenced;
    } else {
        String msg = String.format("Not a structuredDate fieldset.  Field set services type: '%s', Services type: '%s'", fieldSetServicesType, servicesType);
        sendToDebugLog(msg);
    }
    for (FieldSet subRecordFieldSet : record.getAllFieldTopLevel("")) {
        generateDataEntry(currentElement, subRecordFieldSet, ns, root, false);
    }
    if (definedNewType == true) {
        String complexElementXSD = complexElement.asXML();
        if (isValidNewType(servicesType, complexElementXSD, fieldSet.getID()) == true) {
            if (isDefinedLocally(servicesType, complexElementXSD) == false) {
                recordDefinedComplexTypes.put(servicesType, complexElementXSD);
                sendToDebugLog(String.format("The complex type '%s' is defined as: %s", servicesType, complexElementXSD));
            } else {
                // No need to define this type more than once in the current schema, so remove the element we just created.
                root.remove(complexElement);
                sendToDebugLog(String.format("The complex type '%s'  redefinition will be ingnored.  Def of: %s", servicesType, complexElementXSD));
            }
        }
    }
    return servicesType;
}
Also used : FieldSet(org.collectionspace.chain.csp.schema.FieldSet) QName(org.dom4j.QName) Element(org.dom4j.Element) Record(org.collectionspace.chain.csp.schema.Record) TenantSpec(org.collectionspace.chain.csp.persistence.services.TenantSpec) Spec(org.collectionspace.chain.csp.schema.Spec) IOException(java.io.IOException)

Example 7 with Spec

use of org.collectionspace.chain.csp.schema.Spec in project application by collectionspace.

the class TestServiceThroughWebapp method getAdminTenantId.

private static String getAdminTenantId() {
    Spec spec = tester.getSpec(jetty);
    String tenant = spec.getAdminData().getTenant();
    return tenant;
}
Also used : Spec(org.collectionspace.chain.csp.schema.Spec)

Example 8 with Spec

use of org.collectionspace.chain.csp.schema.Spec in project application by collectionspace.

the class ServicesBaseClass method getServiceManager.

private CSPManager getServiceManager() throws CSPDependencyException {
    CSPManager cspm = new CSPManagerImpl();
    cspm.register(new CoreConfig());
    cspm.register(new Spec());
    cspm.register(new ServicesStorageGenerator());
    cspm.go();
    cspm.configure(getRootSource(), new ConfigFinder(null), false);
    return cspm;
}
Also used : 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) TestConfigFinder(org.collectionspace.csp.helper.test.TestConfigFinder)

Example 9 with Spec

use of org.collectionspace.chain.csp.schema.Spec 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());
}
Also used : ConfigRoot(org.collectionspace.chain.csp.config.ConfigRoot) CSPManager(org.collectionspace.csp.api.container.CSPManager) CSPRequestCache(org.collectionspace.csp.api.core.CSPRequestCache) RequestCache(org.collectionspace.csp.helper.core.RequestCache) Record(org.collectionspace.chain.csp.schema.Record) CSPRequestCredentials(org.collectionspace.csp.api.core.CSPRequestCredentials) Spec(org.collectionspace.chain.csp.schema.Spec) StorageGenerator(org.collectionspace.csp.api.persistence.StorageGenerator)

Example 10 with Spec

use of org.collectionspace.chain.csp.schema.Spec 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");
}
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)

Aggregations

Spec (org.collectionspace.chain.csp.schema.Spec)31 ConfigRoot (org.collectionspace.chain.csp.config.ConfigRoot)12 TenantSpec (org.collectionspace.chain.csp.persistence.services.TenantSpec)10 CSPManager (org.collectionspace.csp.api.container.CSPManager)8 CSPManagerImpl (org.collectionspace.csp.container.impl.CSPManagerImpl)8 CoreConfig (org.collectionspace.chain.csp.inner.CoreConfig)7 Record (org.collectionspace.chain.csp.schema.Record)7 ConfigFinder (org.collectionspace.csp.helper.core.ConfigFinder)7 FieldSet (org.collectionspace.chain.csp.schema.FieldSet)5 WebUI (org.collectionspace.chain.csp.webui.main.WebUI)5 CSPDependencyException (org.collectionspace.csp.api.core.CSPDependencyException)5 UI (org.collectionspace.csp.api.ui.UI)4 TestConfigFinder (org.collectionspace.csp.helper.test.TestConfigFinder)4 Element (org.dom4j.Element)4 JSONObject (org.json.JSONObject)4 ServicesStorageGenerator (org.collectionspace.chain.csp.persistence.services.ServicesStorageGenerator)3 QName (org.dom4j.QName)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 StringWriter (java.io.StringWriter)2