Search in sources :

Example 41 with UnimplementedException

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

the class AuthorizationStorage method updateJSON.

@Override
public void updateJSON(ContextualisedStorage root, CSPRequestCredentials creds, CSPRequestCache cache, String filePath, JSONObject jsonObject, JSONObject restrictions) throws ExistException, UnimplementedException, UnderlyingStorageException {
    try {
        Map<String, Document> parts = new HashMap<String, Document>();
        Document doc = null;
        for (String section : r.getServicesRecordPathKeys()) {
            String path = r.getServicesRecordPath(section);
            String[] record_path = path.split(":", 2);
            doc = XmlJsonConversion.convertToXml(r, jsonObject, section, "PUT");
            parts.put(record_path[0], doc);
        }
        int status = 0;
        if (r.isMultipart()) {
            ReturnedMultipartDocument docm = conn.getMultipartXMLDocument(RequestMethod.PUT, r.getServicesURL() + "/" + filePath, parts, creds, cache);
            status = docm.getStatus();
        } else {
            ReturnedDocument docm = conn.getXMLDocument(RequestMethod.PUT, r.getServicesURL() + "/" + filePath, doc, creds, cache);
            status = docm.getStatus();
        }
        if (status == 404)
            throw new ExistException("Not found: " + r.getServicesURL() + "/" + filePath);
        if (status > 299 || status < 200)
            throw new UnderlyingStorageException("Bad response " + status, status, r.getServicesURL() + "/" + filePath);
    } catch (ConnectionException e) {
        throw new UnderlyingStorageException("Service layer exception", e);
    } catch (JSONException e) {
        throw new UnimplementedException("JSONException", e);
    }
}
Also used : HashMap(java.util.HashMap) JSONException(org.json.JSONException) Document(org.dom4j.Document) ReturnedMultipartDocument(org.collectionspace.chain.csp.persistence.services.connection.ReturnedMultipartDocument) ReturnedDocument(org.collectionspace.chain.csp.persistence.services.connection.ReturnedDocument) ExistException(org.collectionspace.csp.api.persistence.ExistException) UnderlyingStorageException(org.collectionspace.csp.api.persistence.UnderlyingStorageException) ReturnedMultipartDocument(org.collectionspace.chain.csp.persistence.services.connection.ReturnedMultipartDocument) ReturnedDocument(org.collectionspace.chain.csp.persistence.services.connection.ReturnedDocument) UnimplementedException(org.collectionspace.csp.api.persistence.UnimplementedException) ConnectionException(org.collectionspace.chain.csp.persistence.services.connection.ConnectionException)

Example 42 with UnimplementedException

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

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

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

use of org.collectionspace.csp.api.persistence.UnimplementedException 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)

Aggregations

UnimplementedException (org.collectionspace.csp.api.persistence.UnimplementedException)56 UnderlyingStorageException (org.collectionspace.csp.api.persistence.UnderlyingStorageException)55 ExistException (org.collectionspace.csp.api.persistence.ExistException)50 JSONException (org.json.JSONException)50 JSONObject (org.json.JSONObject)48 UIException (org.collectionspace.csp.api.ui.UIException)40 JSONArray (org.json.JSONArray)25 Record (org.collectionspace.chain.csp.schema.Record)11 ConnectionException (org.collectionspace.chain.csp.persistence.services.connection.ConnectionException)10 IOException (java.io.IOException)7 ReturnedDocument (org.collectionspace.chain.csp.persistence.services.connection.ReturnedDocument)6 FieldSet (org.collectionspace.chain.csp.schema.FieldSet)6 ConfigException (org.collectionspace.chain.csp.config.ConfigException)5 ReturnedMultipartDocument (org.collectionspace.chain.csp.persistence.services.connection.ReturnedMultipartDocument)5 Field (org.collectionspace.chain.csp.schema.Field)5 Document (org.dom4j.Document)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 Group (org.collectionspace.chain.csp.schema.Group)4 Instance (org.collectionspace.chain.csp.schema.Instance)4 Storage (org.collectionspace.csp.api.persistence.Storage)4