Search in sources :

Example 56 with ExistException

use of org.collectionspace.csp.api.persistence.ExistException in project application by collectionspace.

the class VocabulariesRead method getInstance.

private JSONObject getInstance(Storage storage, JSONObject restriction) throws UIException {
    JSONObject out = new JSONObject();
    try {
        String refPath = n.getRecord().getID() + "/" + n.getTitleRef() + "/";
        if (getInfoMode == GET_FULL_INFO || getInfoMode == GET_BASIC_INFO) {
            JSONObject fields = storage.retrieveJSON(refPath, restriction);
            if (fields.has("csid")) {
                String csid = fields.getString("csid");
                out.put("fields", fields);
                out.put("csid", csid);
            }
        }
    } catch (ExistException e) {
        UIException uiexception = new UIException(e.getMessage(), e);
        return uiexception.getJSON();
    } catch (UnimplementedException e) {
        UIException uiexception = new UIException(e.getMessage(), e);
        return uiexception.getJSON();
    } catch (UnderlyingStorageException x) {
        UIException uiexception = new UIException(x.getMessage(), x.getStatus(), x.getUrl(), x);
        return uiexception.getJSON();
    } catch (JSONException e) {
        throw new UIException("Could not create JSON" + e, e);
    }
    return out;
}
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 57 with ExistException

use of org.collectionspace.csp.api.persistence.ExistException in project application by collectionspace.

the class VocabulariesWorkflowTransition method store_transition.

private void store_transition(Storage storage, UIRequest request, String path, String transition) throws UIException {
    try {
        String url = n.getRecord().getID() + "/" + n.getTitleRef() + "/" + path;
        storage.transitionWorkflowJSON(url, transition);
    } catch (ExistException e) {
        throw new UIException("JSON Not found " + e, 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());
    }
}
Also used : 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 58 with ExistException

use of org.collectionspace.csp.api.persistence.ExistException in project application by collectionspace.

the class ReturnedURL method setResponse.

@Override
public boolean setResponse(HttpMethod method, int status) throws Exception {
    // it's ok to release the parent connection since we consume the entire response stream here
    boolean result = true;
    String possiblemessg = method.getResponseBodyAsString();
    Header location = method.getResponseHeader("Location");
    this.status = status;
    if (status == HttpStatus.SC_CONFLICT) {
        throw new ExistException("Record exists already. Can't create a duplicate: " + possiblemessg != null ? possiblemessg : "Unknown reason.", status);
    }
    if (location == null) {
        if (possiblemessg != "") {
            throw new ConnectionException(possiblemessg, status, "");
        }
        throw new ConnectionException("Missing location header " + method.getResponseBodyAsString(), status, "");
    }
    url = location.getValue();
    return result;
}
Also used : Header(org.apache.commons.httpclient.Header) ExistException(org.collectionspace.csp.api.persistence.ExistException)

Example 59 with ExistException

use of org.collectionspace.csp.api.persistence.ExistException in project application by collectionspace.

the class UserDetailsDelete method store_delete.

private void store_delete(Storage storage, UIRequest request, String path) throws UIException {
    try {
        // Deleting a user needs to clear the userperms cache for safety.
        ResponseCache.clearCache(ResponseCache.USER_PERMS_CACHE);
        storage.deleteJSON(base + "/" + path);
    } catch (ExistException e) {
        throw new UIException("JSON Not found " + e, 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());
    }
}
Also used : 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 60 with ExistException

use of org.collectionspace.csp.api.persistence.ExistException in project application by collectionspace.

the class UserDetailsReset method reset_password.

/* check token and if matches csid then reset password 
	 * */
private void reset_password(Storage storage, UIRequest request, Request in) throws UIException {
    // mock login else service layer gets upset
    // XXX ARGH
    AdminData ad = spec.getAdminData();
    request.getSession().setValue(UISession.USERID, ad.getAuthUser());
    request.getSession().setValue(UISession.PASSWORD, ad.getAuthPass());
    in.reset();
    JSONObject outputJSON = new JSONObject();
    if (testSuccess(in.getStorage())) {
        JSONObject data = null;
        data = request.getJSONBody();
        String token;
        try {
            token = data.getString("token");
            String password = data.getString("password");
            String email = data.getString("email");
            JSONObject userdetails = getcsID(storage, email);
            if (!userdetails.getBoolean("isError")) {
                String csid = userdetails.getString("csid");
                if (testToken(csid, token)) {
                    /* update userdetails */
                    String path = csid;
                    JSONObject fields = userdetails.getJSONObject("fields");
                    try {
                        JSONObject changedata = new JSONObject();
                        JSONObject updatefields = fields;
                        updatefields.put("password", password);
                        changedata.put("fields", updatefields);
                        changedata.put("csid", csid);
                        sendJSON(storage, path, changedata);
                        outputJSON.put("isError", false);
                        JSONObject messages = new JSONObject();
                        messages.put("message", "Your Password has been succesfully changed, Please login");
                        messages.put("severity", "info");
                        JSONArray arr = new JSONArray();
                        arr.put(messages);
                        outputJSON.put("messages", arr);
                    } catch (JSONException x) {
                        throw new UIException("Failed to parse json: ", x);
                    } catch (ExistException x) {
                        throw new UIException("Existence exception: ", x);
                    } catch (UnimplementedException x) {
                        throw new UIException("Unimplemented exception: ", x);
                    } catch (UnderlyingStorageException x) {
                        UIException uiexception = new UIException(x.getMessage(), x.getStatus(), x.getUrl(), x);
                        outputJSON = uiexception.getJSON();
                    }
                } else {
                    outputJSON.put("isError", false);
                    JSONObject messages = new JSONObject();
                    messages.put("message", "Token was not valid");
                    messages.put("severity", "error");
                    JSONArray arr = new JSONArray();
                    arr.put(messages);
                    outputJSON.put("messages", arr);
                }
            } else {
                outputJSON = userdetails;
            }
            request.getSession().setValue(UISession.USERID, "");
            request.getSession().setValue(UISession.PASSWORD, "");
            in.reset();
        } catch (JSONException x) {
            throw new UIException("Failed to parse json: ", x);
        }
    } else {
        try {
            outputJSON.put("isError", false);
            JSONObject messages = new JSONObject();
            messages.put("message", "The admin details in cspace-config.xml failed");
            messages.put("severity", "error");
            JSONArray arr = new JSONArray();
            arr.put(messages);
            outputJSON.put("messages", arr);
        } catch (JSONException x) {
            throw new UIException("Failed to parse json: ", x);
        }
    }
    /* should we automagically log them in or let them do that?, 
		 * I think we should let them login, it has the advantage 
		 * that they find out straight away if they can't remember the new password  */
    request.sendJSONResponse(outputJSON);
    request.setOperationPerformed(Operation.CREATE);
}
Also used : AdminData(org.collectionspace.chain.csp.schema.AdminData) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) 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)

Aggregations

ExistException (org.collectionspace.csp.api.persistence.ExistException)64 UnderlyingStorageException (org.collectionspace.csp.api.persistence.UnderlyingStorageException)57 UnimplementedException (org.collectionspace.csp.api.persistence.UnimplementedException)50 JSONObject (org.json.JSONObject)50 JSONException (org.json.JSONException)49 UIException (org.collectionspace.csp.api.ui.UIException)40 JSONArray (org.json.JSONArray)23 IOException (java.io.IOException)10 ConnectionException (org.collectionspace.chain.csp.persistence.services.connection.ConnectionException)10 Record (org.collectionspace.chain.csp.schema.Record)9 ReturnedDocument (org.collectionspace.chain.csp.persistence.services.connection.ReturnedDocument)8 ReturnedMultipartDocument (org.collectionspace.chain.csp.persistence.services.connection.ReturnedMultipartDocument)8 Document (org.dom4j.Document)7 ConfigException (org.collectionspace.chain.csp.config.ConfigException)5 FieldSet (org.collectionspace.chain.csp.schema.FieldSet)5 File (java.io.File)4 Field (org.collectionspace.chain.csp.schema.Field)4 Instance (org.collectionspace.chain.csp.schema.Instance)4 Storage (org.collectionspace.csp.api.persistence.Storage)4 RefName (org.collectionspace.services.common.api.RefName)4