use of org.collectionspace.chain.csp.schema.Spec in project application by collectionspace.
the class ServiceConfigGeneration method getServiceManager.
private CSPManager getServiceManager(File configFile) throws Exception {
CSPManager result = null;
CSPManager cspm = new CSPManagerImpl();
cspm.register(new CoreConfig());
cspm.register(new Spec());
cspm.register(new ServicesStorageGenerator());
// Do more initialization of our CSPManagerImpl instance (i.e., cspm)
cspm.go();
File configBase = configFile.getParentFile();
// Saves a copy of the base config directory
cspm.setConfigBase(configBase);
cspm.configure(getSource(configFile), new ConfigFinder(null, configBase), true);
this.setConfigBase(configBase);
this.setConfigFile(configFile);
result = cspm;
return result;
}
use of org.collectionspace.chain.csp.schema.Spec in project application by collectionspace.
the class AuthorizationStorage method retrieveJSON.
@Override
public JSONObject retrieveJSON(ContextualisedStorage root, CSPRequestCredentials creds, CSPRequestCache cache, String filePath, JSONObject restrictions) throws ExistException, UnimplementedException, UnderlyingStorageException {
try {
String[] parts = filePath.split("/");
if (parts.length > 2) {
Spec s = r.getSpec();
// {csid}/userrole/{csid}
if (s.hasRecordByWebUrl(parts[1])) {
String path = s.getRecordByWebUrl(parts[1]).getServicesURL();
int len = parts.length - 1;
for (int i = 0; i < len; i++) {
path = path.replace("*", parts[i]);
i++;
}
filePath = path + "/" + parts[len];
return simpleRetrieveJSONFullPath(creds, cache, filePath, s.getRecordByWebUrl(parts[1]).getRecord());
} else {
// {csid}/refobj/bob
String extra = "";
if (parts.length == 3) {
extra = parts[2];
}
return viewRetrieveJSON(root, creds, cache, parts[0], parts[1], extra, restrictions);
}
} else {
return simpleRetrieveJSON(creds, cache, filePath);
}
} catch (JSONException x) {
throw new UnderlyingStorageException("Error building JSON", x);
}
}
use of org.collectionspace.chain.csp.schema.Spec in project application by collectionspace.
the class GenericStorage method handleHierarchyPayloadSend.
public void handleHierarchyPayloadSend(Record thisr, Map<String, Document> body, JSONObject jsonObject, String thiscsid) throws JSONException, ExistException, UnderlyingStorageException {
if (thisr.hasHierarchyUsed("screen")) {
Spec spec = this.r.getSpec();
ArrayList<Element> alleles = new ArrayList<Element>();
for (Relationship rel : r.getSpec().getAllRelations()) {
Relationship newrel = rel;
Boolean inverse = false;
if (rel.hasInverse()) {
newrel = thisr.getSpec().getRelation(rel.getInverse());
inverse = true;
}
// does this relationship apply to this record
if (rel.hasSourceType(r.getID())) {
// does this record have the data in the json
if (jsonObject.has(rel.getID())) {
String metaTypeField = rel.getMetaTypeField();
if (rel.getObject().equals("1")) {
if (jsonObject.has(rel.getID()) && !jsonObject.get(rel.getID()).equals("")) {
// Look for a metatype
String metaType = "";
if (!StringUtils.isEmpty(metaTypeField) && jsonObject.has(metaTypeField)) {
metaType = jsonObject.getString(metaTypeField);
}
Element bit = createRelationship(newrel, jsonObject.get(rel.getID()), thiscsid, r.getServicesURL(), metaType, inverse, spec);
if (bit != null) {
alleles.add(bit);
}
}
} else if (rel.getObject().equals("n")) {
// if()
JSONArray temp = jsonObject.getJSONArray(rel.getID());
for (int i = 0; i < temp.length(); i++) {
String relFieldName = rel.getChildName();
JSONObject relItem = temp.getJSONObject(i);
if (relItem.has(relFieldName) && !relItem.getString(relFieldName).equals("")) {
String uri = relItem.getString(relFieldName);
// Look for a metatype
String metaType = "";
if (!StringUtils.isEmpty(metaTypeField) && relItem.has(metaTypeField)) {
metaType = relItem.getString(metaTypeField);
}
Element bit = createRelationship(newrel, uri, thiscsid, r.getServicesURL(), metaType, inverse, spec);
if (bit != null) {
alleles.add(bit);
}
}
}
}
}
}
}
// add relationships section
if (!alleles.isEmpty()) {
Element[] array = alleles.toArray(new Element[0]);
Document out = XmlJsonConversion.getXMLRelationship(array);
body.put("relations-common-list", out);
// log.info(out.asXML());
} else {
Document out = XmlJsonConversion.getXMLRelationship(null);
body.put("relations-common-list", out);
// log.info(out.asXML());
}
// probably should put empty array in if no data
}
}
use of org.collectionspace.chain.csp.schema.Spec 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;
}
use of org.collectionspace.chain.csp.schema.Spec in project application by collectionspace.
the class ServicesBaseClass method setup.
protected void setup() throws ConnectionException {
Spec spec = null;
String ims_base = "";
try {
base = getBaseUrl();
ims_base = getIMSBaseUrl();
spec = getDefaultSpec();
} catch (CSPDependencyException e) {
assertNotNull("Base service url invalid in config file", base);
}
// XXX still yuck but centralised now
log.info("ServicesBaseClass setting up connection using base URL:" + base);
conn = new ServicesConnection(base, ims_base);
creds = new ServicesRequestCredentials();
creds.setCredential(ServicesStorageGenerator.CRED_USERID, spec.getAdminData().getAuthUser());
creds.setCredential(ServicesStorageGenerator.CRED_PASSWORD, spec.getAdminData().getAuthPass());
ReturnedDocument out = conn.getXMLDocument(RequestMethod.GET, "accounts/0/accountperms", null, creds, cache);
Assume.assumeTrue(out.getStatus() == 200);
}
Aggregations