public JSONObject viewRetrieveImg( ContextualisedStorage storage, CSPRequestCredentials creds, CSPRequestCache cache, String filePath, String view, String extra, JSONObject restrictions) throws ExistException, UnimplementedException, UnderlyingStorageException, JSONException, UnsupportedEncodingException { JSONObject out = new JSONObject(); String servicesurl = r.getServicesURL() + "/"; try { filePath = filePath + "/derivatives/" + view + "/content"; String softpath = filePath; if (r.hasSoftDeleteMethod()) { softpath = softpath(filePath); } if (r.hasHierarchyUsed("screen")) { softpath = hierarchicalpath(softpath); } if (r.isMultipart()) { ReturnUnknown doc = conn.getUnknownDocument(RequestMethod.GET, servicesurl + softpath, null, creds, cache); if ((doc.getStatus() < 200 || doc.getStatus() >= 300)) throw new UnderlyingStorageException("Does not exist ", doc.getStatus(), softpath); out.put("getByteBody", doc.getBytes()); out.put("contenttype", doc.getContentType()); } else { ReturnUnknown doc = conn.getUnknownDocument(RequestMethod.GET, servicesurl + softpath, null, creds, cache); if ((doc.getStatus() < 200 || doc.getStatus() >= 300)) throw new UnderlyingStorageException("Does not exist ", doc.getStatus(), softpath); out.put("getByteBody", doc.getBytes()); out.put("contenttype", doc.getContentType()); } } catch (ConnectionException e) { throw new UnderlyingStorageException( "Service layer exception" + e.getLocalizedMessage(), e.getStatus(), e.getUrl(), e); } return out; }
public JSONObject retrieveJSON( ContextualisedStorage root, CSPRequestCredentials creds, CSPRequestCache cache, String filePath, JSONObject restrictions) throws ExistException, UnimplementedException, UnderlyingStorageException { try { if (r.isType("report")) { Document doc = null; Map<String, Document> parts = new HashMap<String, Document>(); for (String section : r.getServicesRecordPaths()) { String path = r.getServicesRecordPath(section); String[] record_path = path.split(":", 2); doc = XmlJsonConversion.convertToXml(r, restrictions, section, "POST"); if (doc != null) { parts.put(record_path[0], doc); } } ReturnUnknown doc2 = null; if (filePath.contains("/output")) { doc2 = conn.getReportDocument(RequestMethod.GET, "reports/" + filePath, null, creds, cache); } else { doc2 = conn.getReportDocument(RequestMethod.POST, "reports/" + filePath, doc, creds, cache); } if (doc2.getStatus() > 299 || doc2.getStatus() < 200) throw new UnderlyingStorageException( "Bad response ", doc2.getStatus(), r.getServicesURL() + "/"); JSONObject out = new JSONObject(); out.put("getByteBody", doc2.getBytes()); out.put("contenttype", doc2.getContentType()); return out; } else { String[] parts = filePath.split("/"); if (parts.length >= 2) { String extra = ""; if (parts.length == 3) { extra = parts[2]; } return viewRetrieveImg(root, creds, cache, parts[0], parts[1], extra, restrictions); } else return simpleRetrieveJSON(creds, cache, filePath); } } catch (JSONException x) { throw new UnderlyingStorageException("Error building JSON", x); } catch (UnsupportedEncodingException x) { throw new UnderlyingStorageException("Error UnsupportedEncodingException JSON", x); } catch (ConnectionException e) { throw new UnderlyingStorageException( "Service layer exception" + e.getLocalizedMessage(), e.getStatus(), e.getUrl(), e); } }