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;
}
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;
}
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;
}
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());
}
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");
}
Aggregations