@Get public Representation get() { ResponsePojo rp = new ResponsePojo(); Date startTime = new Date(); cookieLookup = RESTTools.cookieLookup(cookie); // If JSON is != null, check that it is valid JSON boolean isValidJson = true; if (json != null) { try { JSON.parse(json); } catch (Exception e) { rp.setResponse( new ResponseObject( "Parsing JSON", false, "The value passed via the json parameter could not be" + " parsed as valid JSON.")); isValidJson = false; } } if (isValidJson) { if (cookieLookup == null) { // User is not logged in rp.setResponse( new ResponseObject( "Cookie Lookup", false, "Cookie session expired or never existed, please login first")); } else { // UserId which will serve as the OwnerId for transactions below that require it personId = cookieLookup; if (action.equals("saveJson")) { rp = this.shareController.saveJson(personId, id, type, title, description, json); } else if (action.equals("addBinaryGET")) { rp = new ResponsePojo( new ResponseObject( "addBinary", false, "Can only add binary in POST (do not use GET)")); } else if (action.equals("addBinaryPOST")) { rp = this.shareController.addBinary( personId, "binary", title, description, this.getRequest().getEntity().getMediaType().toString(), binaryData); } else if (action.equals("updateBinaryGET")) { rp = new ResponsePojo( new ResponseObject( "updateBinary", false, "Can only update binary in POST (do not use GET)")); } else if (action.equals("updateBinaryPOST")) { rp = this.shareController.updateBinary( personId, id, "binary", title, description, this.getRequest().getEntity().getMediaType().toString(), binaryData); } else if (action.equals("addRef")) { // Not currently supported // rp = this.shareController.addRef(personId, type, documentId, title, description); rp.setResponse(new ResponseObject("Cookie Lookup", false, "Not currently supported")); } else if (action.equals("updateRef")) { // Not currently supported // rp = this.shareController.updateRef(personId, id, type, documentId, title, // description); rp.setResponse(new ResponseObject("Cookie Lookup", false, "Not currently supported")); } else if (action.equals("removeShare")) { rp = this.shareController.removeShare(personId, shareId); } else if (action.equals("endorseShare")) { rp = this.shareController.endorseShare(personId, communityId, shareId, isEndorsed); } else if (action.equals("addCommunity")) { rp = this.shareController.addCommunity(personId, shareId, communityId, comment); } else if (action.equals("removeCommunity")) { rp = this.shareController.removeCommunity(personId, shareId, communityId); } else if (action.equals("getShare")) { rp = this.shareController.getShare(personId, shareId, returnContent); SharePojo share = (SharePojo) rp.getData(); if (null != share) { boolean bBinary = share.getType().equals("binary"); if (bBinary && returnContent) { try { ByteArrayOutputRepresentation rep = new ByteArrayOutputRepresentation(MediaType.valueOf(share.getMediaType())); rep.setOutputBytes(share.getBinaryData()); return rep; } catch (Exception ex) { rp = new ResponsePojo( new ResponseObject("get Share", false, "error converting bytes to output")); } } else if (!bBinary && jsonOnly) { try { BasicDBObject dbo = (BasicDBObject) com.mongodb.util.JSON.parse(share.getShare()); rp.setData(dbo, null); } catch (Exception e) { // Try a list instead BasicDBList dbo = (BasicDBList) com.mongodb.util.JSON.parse(share.getShare()); rp.setData(dbo, (BasePojoApiMap<BasicDBList>) null); } } } // (else error) } else if (action.equals("searchShares")) { rp = this.shareController.searchShares( personId, searchby, id, type, skip, limit, ignoreAdmin, returnContent); } } } Date endTime = new Date(); rp.getResponse().setTime(endTime.getTime() - startTime.getTime()); return new StringRepresentation(rp.toApi(), MediaType.APPLICATION_JSON); }