Search in sources :

Example 81 with UnderlyingStorageException

use of org.collectionspace.csp.api.persistence.UnderlyingStorageException 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 82 with UnderlyingStorageException

use of org.collectionspace.csp.api.persistence.UnderlyingStorageException 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 83 with UnderlyingStorageException

use of org.collectionspace.csp.api.persistence.UnderlyingStorageException 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 84 with UnderlyingStorageException

use of org.collectionspace.csp.api.persistence.UnderlyingStorageException 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 85 with UnderlyingStorageException

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

the class VocabulariesRead method getRefObjs.

/**
 * Returns all the objects that are linked to a vocabulary item
 * @param storage
 * @param path
 * @return
 * @throws ExistException
 * @throws UnimplementedException
 * @throws UnderlyingStorageException
 * @throws JSONException
 */
@SuppressWarnings("unchecked")
private void getRefObjs(Storage storage, String path, JSONObject out, String itemsKey, boolean addPagination, JSONObject restrictions) throws JSONException {
    JSONArray items = new JSONArray();
    try {
        JSONObject refObjs = storage.retrieveJSON(path + "/refObjs", restrictions);
        if (refObjs != null) {
            if (refObjs.has("items")) {
                JSONArray ritems = refObjs.getJSONArray("items");
                for (int i = 0; i < ritems.length(); i++) {
                    JSONObject in = ritems.getJSONObject(i);
                    // JSONObject in=ritems.getJSONObject(field);
                    String rt = in.getString("sourceFieldType");
                    Record rec = this.spec.getRecordByServicesDocType(rt);
                    // as the key.
                    if (rec == null) {
                        if (in.has("summarylist")) {
                            JSONObject summaryList = in.getJSONObject("summarylist");
                            if (summaryList.has("uri")) {
                                String uri = summaryList.getString("uri");
                                if (Tools.notBlank(uri)) {
                                    String recordtypekey = uri.split("/")[0];
                                    if (Tools.notBlank(recordtypekey)) {
                                        rec = this.spec.getRecordByServicesUrl(recordtypekey);
                                    }
                                }
                            }
                        }
                    }
                    String uiname;
                    if (rec != null) {
                        uiname = rec.getWebURL();
                        if (rec.isType("authority")) {
                            // Need to add namespace for authorities
                            String refName = null;
                            if (in.has("refName")) {
                                refName = in.getString("refName");
                            } else if (in.has("summarylist")) {
                                JSONObject summList = in.getJSONObject("summarylist");
                                if (summList.has("refName")) {
                                    refName = summList.getString("refName");
                                }
                            }
                            if (refName != null) {
                                RefName.AuthorityItem item = RefName.AuthorityItem.parse(refName);
                                in.put("namespace", item.getParentShortIdentifier());
                            }
                        }
                    } else {
                        uiname = rt;
                    }
                    in.put("recordtype", uiname);
                    /*
						JSONObject entry=new JSONObject();
						entry.put("csid",in.getString("csid"));
						entry.put("recordtype",in.getString("sourceFieldType"));
						entry.put("sourceFieldName",field);
						entry.put("number",in.getString("sourceFieldName"));
						*/
                    items.put(in);
                }
            }
            out.put(itemsKey, items);
            if (addPagination && refObjs.has("pagination")) {
                out.put("pagination", refObjs.get("pagination"));
            }
        }
    } catch (JSONException ex) {
        log.debug("JSONException" + ex.getLocalizedMessage());
    // wordlessly eat the errors at the moment as they might be permission errors
    } catch (ExistException e) {
        log.debug("ExistException" + e.getLocalizedMessage());
    // wordlessly eat the errors at the moment as they might be permission errors
    } catch (UnimplementedException e) {
        log.debug("UnimplementedException" + e.getLocalizedMessage());
    // wordlessly eat the errors at the moment as they might be permission errors
    } catch (UnderlyingStorageException e) {
        log.debug("UnderlyingStorageException" + e.getLocalizedMessage());
    // wordlessly eat the errors at the moment as they might be permission errors
    }
}
Also used : JSONObject(org.json.JSONObject) RefName(org.collectionspace.services.common.api.RefName) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) Record(org.collectionspace.chain.csp.schema.Record) ExistException(org.collectionspace.csp.api.persistence.ExistException) UnderlyingStorageException(org.collectionspace.csp.api.persistence.UnderlyingStorageException) UnimplementedException(org.collectionspace.csp.api.persistence.UnimplementedException)

Aggregations

UnderlyingStorageException (org.collectionspace.csp.api.persistence.UnderlyingStorageException)108 JSONObject (org.json.JSONObject)75 JSONException (org.json.JSONException)73 ExistException (org.collectionspace.csp.api.persistence.ExistException)57 UnimplementedException (org.collectionspace.csp.api.persistence.UnimplementedException)55 UIException (org.collectionspace.csp.api.ui.UIException)40 ConnectionException (org.collectionspace.chain.csp.persistence.services.connection.ConnectionException)39 JSONArray (org.json.JSONArray)34 ReturnedDocument (org.collectionspace.chain.csp.persistence.services.connection.ReturnedDocument)30 Document (org.dom4j.Document)29 ReturnedMultipartDocument (org.collectionspace.chain.csp.persistence.services.connection.ReturnedMultipartDocument)23 FieldSet (org.collectionspace.chain.csp.schema.FieldSet)17 UnsupportedEncodingException (java.io.UnsupportedEncodingException)16 Field (org.collectionspace.chain.csp.schema.Field)14 Record (org.collectionspace.chain.csp.schema.Record)14 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)11 Node (org.dom4j.Node)10 ReturnedURL (org.collectionspace.chain.csp.persistence.services.connection.ReturnedURL)9 IOException (java.io.IOException)7