Search in sources :

Example 11 with Spec

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;
}
Also used : ServicesStorageGenerator(org.collectionspace.chain.csp.persistence.services.ServicesStorageGenerator) CSPManager(org.collectionspace.csp.api.container.CSPManager) CoreConfig(org.collectionspace.chain.csp.inner.CoreConfig) CSPManagerImpl(org.collectionspace.csp.container.impl.CSPManagerImpl) TenantSpec(org.collectionspace.chain.csp.persistence.services.TenantSpec) Spec(org.collectionspace.chain.csp.schema.Spec) File(java.io.File) ConfigFinder(org.collectionspace.csp.helper.core.ConfigFinder) TestConfigFinder(org.collectionspace.csp.helper.test.TestConfigFinder)

Example 12 with Spec

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);
    }
}
Also used : JSONException(org.json.JSONException) Spec(org.collectionspace.chain.csp.schema.Spec) UnderlyingStorageException(org.collectionspace.csp.api.persistence.UnderlyingStorageException)

Example 13 with Spec

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
    }
}
Also used : JSONObject(org.json.JSONObject) Element(org.dom4j.Element) Relationship(org.collectionspace.chain.csp.schema.Relationship) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) Spec(org.collectionspace.chain.csp.schema.Spec) Document(org.dom4j.Document) ReturnedMultipartDocument(org.collectionspace.chain.csp.persistence.services.connection.ReturnedMultipartDocument) ReturnedDocument(org.collectionspace.chain.csp.persistence.services.connection.ReturnedDocument)

Example 14 with Spec

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;
}
Also used : ConfigRoot(org.collectionspace.chain.csp.config.ConfigRoot) CSPManager(org.collectionspace.csp.api.container.CSPManager) Spec(org.collectionspace.chain.csp.schema.Spec)

Example 15 with 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);
}
Also used : CSPDependencyException(org.collectionspace.csp.api.core.CSPDependencyException) ServicesConnection(org.collectionspace.chain.csp.persistence.services.connection.ServicesConnection) Spec(org.collectionspace.chain.csp.schema.Spec) ReturnedDocument(org.collectionspace.chain.csp.persistence.services.connection.ReturnedDocument)

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