Search in sources :

Example 51 with UIException

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

the class AuthoritiesVocabulariesSearchList method run.

@Override
public void run(Object in, String[] tail) throws UIException {
    if (tail.length > 0) {
        throw new UIException("Illegal search specified. Tail: " + r.getWebURL() + "/" + StringUtils.join(tail, "/"));
    }
    Request q = (Request) in;
    UIRequest uir = q.getUIRequest();
    if (search) {
        searchtype(q.getStorage(), uir, uir.getRequestArgument(SEARCH_QUERY_PARAM), uir.getRequestArgument(PAGE_SIZE_PARAM), uir.getRequestArgument(PAGE_NUM_PARAM));
    } else {
        searchtype(q.getStorage(), uir, null, uir.getRequestArgument(PAGE_SIZE_PARAM), uir.getRequestArgument(PAGE_NUM_PARAM));
    }
}
Also used : UIRequest(org.collectionspace.csp.api.ui.UIRequest) Request(org.collectionspace.chain.csp.webui.main.Request) UIException(org.collectionspace.csp.api.ui.UIException) UIRequest(org.collectionspace.csp.api.ui.UIRequest)

Example 52 with UIException

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

the class AuthoritiesVocabulariesSearchList method searchtype.

public void searchtype(Storage storage, UIRequest ui, String param, String pageSize, String pageNum) throws UIException {
    try {
        JSONObject restrictedkey = GenericSearch.setRestricted(ui, param, pageNum, pageSize, search, this.r);
        JSONObject restriction = restrictedkey.getJSONObject("restriction");
        String resultstring = restrictedkey.getString("key");
        if (ui.getBody() == null || StringUtils.isBlank(ui.getBody())) {
            search_or_list(storage, ui, restriction, resultstring);
        } else {
            // advanced search
            advancedSearch(storage, ui, restriction, resultstring, ui.getJSONBody());
        }
    } 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);
        ui.sendJSONResponse(uiexception.getJSON());
    }
}
Also used : JSONObject(org.json.JSONObject) 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 53 with UIException

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

the class VocabulariesCreateUpdate method store_set.

private void store_set(Storage storage, UIRequest request, String path) throws UIException {
    try {
        JSONObject data = request.getJSONBody();
        String redirectpath = "";
        // is this an instance or an item?
        if (this.r == null && this.n != null) {
            FieldSet displayNameFS = n.getRecord().getDisplayNameField();
            String displayNameFieldName = (displayNameFS != null) ? displayNameFS.getID() : null;
            boolean quickie = false;
            String quickieDisplayName = null;
            if (create) {
                quickie = (data.has("_view") && data.getString("_view").equals("autocomplete"));
                // Check to see if displayName field needs remapping from UI
                if (quickie && !"displayName".equals(displayNameFieldName)) {
                    // Need to map the field for displayName, and put it into a proper structure
                    JSONObject fields = data.getJSONObject("fields");
                    quickieDisplayName = fields.getString("displayName");
                    if (quickieDisplayName != null) {
                        // displayNames are nested now, so must have a field parent
                        FieldSet parentTermGroup = (FieldSet) displayNameFS.getParent();
                        JSONArray parentTermInfoArray = new JSONArray();
                        JSONObject termInfo = new JSONObject();
                        termInfo.put(displayNameFieldName, quickieDisplayName);
                        parentTermInfoArray.put(termInfo);
                        fields.put(parentTermGroup.getID(), parentTermInfoArray);
                        fields.remove("displayName");
                    }
                }
            }
            path = createItem(storage, request, path, data);
            data = reader.getJSON(storage, path);
            String refid = data.getJSONObject("fields").getString("refid");
            data.put("urn", refid);
            data.getJSONObject("fields").put("urn", refid);
            data.put("csid", data.getJSONObject("fields").getString("csid"));
            if (quickie) {
                JSONObject newdata = new JSONObject();
                newdata.put("urn", refid);
                newdata.put("displayName", quickieDisplayName);
                data = newdata;
            }
            redirectpath = n.getWebURL();
        }
        if (this.r != null && this.n == null) {
            path = createInstance(storage, request, path, data);
            redirectpath = data.getJSONObject("fields").getString("shortIdentifier");
        }
        request.sendJSONResponse(data);
        request.setOperationPerformed(create ? Operation.CREATE : Operation.UPDATE);
        if (create)
            request.setSecondaryRedirectPath(new String[] { redirectpath, path });
    // request.setSecondaryRedirectPath(new String[]{n.getWebURL(),path});
    } 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);
        request.sendJSONResponse(uiexception.getJSON());
    }
}
Also used : FieldSet(org.collectionspace.chain.csp.schema.FieldSet) 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)

Example 54 with UIException

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

the class VocabulariesDelete method store_delete.

private void store_delete(Storage storage, UIRequest request, String path) throws UIException {
    try {
        String url = n.getRecord().getID() + "/" + n.getTitleRef() + "/" + path;
        JSONObject test = storage.retrieveJSON(url + "/refObjs", new JSONObject());
        if (test.has("items") && (test.getJSONArray("items").length() > 0)) {
            UIException uiexception = new UIException("This Vocabulary Item has Procedures associated with it");
            request.sendJSONResponse(uiexception.getJSON());
            return;
        }
        storage.deleteJSON(url);
    } catch (ExistException e) {
        throw new UIException("JSON Not found " + e, e);
    } catch (JSONException e) {
        throw new UIException("JSON Not found (malformed refObjs payload) " + 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 : 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 55 with UIException

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

the class VocabulariesRead method getJSON.

private JSONObject getJSON(Storage storage, String csid, 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 + csid, restriction);
            // add in equivalent hierarchy if relevant
            csid = fields.getString("csid");
            fields = getHierarchy(storage, fields);
            // fields.put("csid",csid);
            // JSONObject relations=createRelations(storage,csid);
            out.put("fields", fields);
            out.put("csid", csid);
            out.put("namespace", n.getWebURL());
        }
        if (getInfoMode == GET_FULL_INFO) {
            out.put("relations", new JSONArray());
        // out.put("relations",relations);
        }
        if (getInfoMode == GET_FULL_INFO) {
            JSONObject tusd = this.termsused.getTermsUsed(storage, refPath + csid, new JSONObject());
            out.put("termsUsed", tusd.getJSONArray("results"));
        }
        if (getInfoMode == GET_TERMS_USED_INFO) {
            JSONObject tusd = this.termsused.getTermsUsed(storage, refPath + csid, restriction);
            out.put("termsUsed", tusd);
        }
        if (getInfoMode == GET_FULL_INFO) {
            getRefObjs(storage, refPath + csid, out, "refobjs", false, restriction);
        } else if (getInfoMode == GET_REF_OBJS_INFO) {
            getRefObjs(storage, refPath + csid, out, "items", true, restriction);
        }
    } 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) JSONArray(org.json.JSONArray) 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)

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