Search in sources :

Example 46 with UIException

use of org.collectionspace.csp.api.ui.UIException in project application by collectionspace.

the class RelateRead method relate_get.

private void relate_get(Storage storage, UIRequest request, String path) throws UIException {
    try {
        JSONObject relation = convertPayload(storage, storage.retrieveJSON("/relations/" + searchPath + "/" + path, new JSONObject()), path);
        request.sendJSONResponse(relation);
    } catch (ExistException e) {
        throw new UIException("JSON Not found ", e);
    } catch (UnimplementedException e) {
        throw new UIException("Unimplemented", e);
    } catch (UnderlyingStorageException x) {
        UIException uiexception = new UIException(x.getMessage(), x.getStatus(), x.getUrl(), x);
        request.sendJSONResponse(uiexception.getJSON());
    } catch (JSONException e) {
        throw new UIException("Could not build JSON ", e);
    }
}
Also used : JSONObject(org.json.JSONObject) UIException(org.collectionspace.csp.api.ui.UIException) JSONException(org.json.JSONException) ExistException(org.collectionspace.csp.api.persistence.ExistException) UnderlyingStorageException(org.collectionspace.csp.api.persistence.UnderlyingStorageException) UnimplementedException(org.collectionspace.csp.api.persistence.UnimplementedException)

Example 47 with UIException

use of org.collectionspace.csp.api.ui.UIException in project application by collectionspace.

the class WebUI method serviceRequest.

@Override
public void serviceRequest(UIRequest ui) throws UIException, UnauthorizedException {
    CSPRequestCache cache = new RequestCache();
    String[] path = ui.getPrincipalPath();
    Request r = new Request(xxx_storage, cache, ui);
    String test = ui.getRequestedOperation().toString();
    log.debug("ServiceRequest path: " + StringUtils.join(path, "/"));
    log.debug(test);
    try {
        if (tries.get(ui.getRequestedOperation()).call(path, r))
            return;
    } catch (UIException e) {
        throw e;
    } catch (UnauthorizedException ue) {
        throw ue;
    } catch (Exception e) {
        log.error("Error in WebUI.serviceRequest", e);
        log.error(String.format("Request body= %s", ui.getBody()));
        throw new UIException("Error in read", e);
    }
    throw new UIException("path not used");
}
Also used : CSPRequestCache(org.collectionspace.csp.api.core.CSPRequestCache) RequestCache(org.collectionspace.csp.helper.core.RequestCache) UIRequest(org.collectionspace.csp.api.ui.UIRequest) UnauthorizedException(org.collectionspace.csp.api.persistence.UnauthorizedException) UIException(org.collectionspace.csp.api.ui.UIException) CSPRequestCache(org.collectionspace.csp.api.core.CSPRequestCache) UIException(org.collectionspace.csp.api.ui.UIException) CSPDependencyException(org.collectionspace.csp.api.core.CSPDependencyException) UnauthorizedException(org.collectionspace.csp.api.persistence.UnauthorizedException)

Example 48 with UIException

use of org.collectionspace.csp.api.ui.UIException in project application by collectionspace.

the class ServicesStorageGenerator method initializeAuthorities.

private void initializeAuthorities(CSPManager cspManager, Spec spec) {
    AdminData ad = spec.getAdminData();
    String adminUsername = ad.getAuthUser();
    String adminPass = ad.getAuthPass();
    // request.getSession().setValue(UISession.USERID,ad.getAuthUser());
    // request.getSession().setValue(UISession.PASSWORD,ad.getAuthPass());
    CSPRequestCredentials creds = this.createCredentials();
    creds.setCredential(CRED_USERID, spec.getAdminData().getAuthUser());
    creds.setCredential(CRED_PASSWORD, spec.getAdminData().getAuthPass());
    WebReset webReset = new WebReset(false, false);
    webReset.configure((WebUI) cspManager.getUI(""), spec);
    try {
        webReset.run(getStorage(creds, new RequestCache()), null, new String[0], false);
    } catch (UIException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : AdminData(org.collectionspace.chain.csp.schema.AdminData) WebReset(org.collectionspace.chain.csp.webui.misc.WebReset) CSPRequestCache(org.collectionspace.csp.api.core.CSPRequestCache) RequestCache(org.collectionspace.csp.helper.core.RequestCache) UIException(org.collectionspace.csp.api.ui.UIException) CSPRequestCredentials(org.collectionspace.csp.api.core.CSPRequestCredentials)

Example 49 with UIException

use of org.collectionspace.csp.api.ui.UIException in project application by collectionspace.

the class AuthoritiesVocabulariesInitialize method initializeVocab.

private void initializeVocab(Storage storage, UIRequest request, String path) throws UIException {
    try {
        if (fInstance == null) {
            // For now simply loop through all the instances one after the other.
            for (Instance instance : r.getAllInstances()) {
                log.info(instance.getID());
                // does instance exist?
                if (createIfMissingAuthority(storage, null, this.r, instance) == -1) {
                    log.warn(String.format("The currently authenticated user does not have sufficient permission to determine if the '%s' authority/term-list is properly initialized.", instance.getID()));
                }
                resetvocabdata(storage, request, instance);
            }
        } else {
            log.info(fInstance.getID());
            resetvocabdata(storage, request, this.fInstance);
        }
    } catch (JSONException e) {
        throw new UIException("Cannot generate JSON", e);
    } catch (ExistException e) {
        throw new UIException("Exist exception", e);
    } catch (UnimplementedException e) {
        throw new UIException("Unimplemented exception", e);
    } catch (UnderlyingStorageException x) {
        UIException uiexception = new UIException(x.getMessage(), x.getStatus(), x.getUrl(), x);
        request.sendJSONResponse(uiexception.getJSON());
    }
}
Also used : Instance(org.collectionspace.chain.csp.schema.Instance) JSONException(org.json.JSONException) UIException(org.collectionspace.csp.api.ui.UIException) ExistException(org.collectionspace.csp.api.persistence.ExistException) UnderlyingStorageException(org.collectionspace.csp.api.persistence.UnderlyingStorageException) UnimplementedException(org.collectionspace.csp.api.persistence.UnimplementedException)

Example 50 with UIException

use of org.collectionspace.csp.api.ui.UIException in project application by collectionspace.

the class AuthoritiesVocabulariesInitialize method resetvocabdata.

private void resetvocabdata(Storage storage, UIRequest request, Instance instance) throws UIException, ExistException, UnimplementedException, UnderlyingStorageException, JSONException {
    StringBuffer tty = new StringBuffer();
    tty.append("Initializing Vocab " + instance.getID() + '\n');
    // Where do we get the list from?
    // from Spec
    Option[] allOpts = instance.getAllOptions();
    // but first check: do we have a path?
    Set<String> args = request.getAllRequestArgument();
    if (args.contains("datapath")) {
        tty.append("Using Datapath \n");
        // remove all opts from instance as we have a path
        if (allOpts != null && allOpts.length > 0) {
            tty.append("Removing all opts from instance as we have a path\n");
            for (Option opt : allOpts) {
                String name = opt.getName();
                String shortIdentifier = opt.getID();
                String sample = opt.getSample();
                Boolean dfault = opt.isDefault();
                instance.deleteOption(shortIdentifier, name, sample, dfault);
            }
        }
        // add from path
        String value = request.getRequestArgument("datapath");
        // log.info("getting data from path: "+value);
        try {
            tty.append("Getting data from path: " + value + '\n');
            String names = getResource(value);
            for (String line : names.split("\n")) {
                line = line.trim();
                String[] bits = line.split("\\|");
                if (bits.length > 1) {
                    instance.addOption(bits[0], bits[1], null, false);
                } else {
                    instance.addOption(null, line, null, false);
                }
            }
        } catch (IOException e) {
            throw new UIException("IOException", e);
        }
        allOpts = instance.getAllOptions();
    }
    fillVocab(storage, r, instance, tty, allOpts, this.append);
    if (this.modifyResponse == true) {
        TTYOutputter ttyOut = request.getTTYOutputter();
        ttyOut.line(tty.toString());
    }
}
Also used : UIException(org.collectionspace.csp.api.ui.UIException) Option(org.collectionspace.chain.csp.schema.Option) TTYOutputter(org.collectionspace.csp.api.ui.TTYOutputter) IOException(java.io.IOException)

Aggregations

UIException (org.collectionspace.csp.api.ui.UIException)72 JSONObject (org.json.JSONObject)51 JSONException (org.json.JSONException)50 ExistException (org.collectionspace.csp.api.persistence.ExistException)39 UnderlyingStorageException (org.collectionspace.csp.api.persistence.UnderlyingStorageException)39 UnimplementedException (org.collectionspace.csp.api.persistence.UnimplementedException)39 JSONArray (org.json.JSONArray)19 IOException (java.io.IOException)10 Record (org.collectionspace.chain.csp.schema.Record)7 Instance (org.collectionspace.chain.csp.schema.Instance)6 ConfigException (org.collectionspace.chain.csp.config.ConfigException)5 Field (org.collectionspace.chain.csp.schema.Field)4 FieldSet (org.collectionspace.chain.csp.schema.FieldSet)4 UIRequest (org.collectionspace.csp.api.ui.UIRequest)4 MessageDigest (java.security.MessageDigest)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 ConnectionException (org.collectionspace.chain.csp.persistence.services.connection.ConnectionException)3 AdminData (org.collectionspace.chain.csp.schema.AdminData)3 Structure (org.collectionspace.chain.csp.schema.Structure)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2