bAdminOrModOfAllCommunities = false;
}
}//TESTED
if (!bAdminOrModOfAllCommunities) {
rp.setResponse(new ResponseObject("Update Share",false,"Unable to update share: you are not owner or admin"));
return rp;
}
}
}//end if not owner
// Check: am I trying to update a reference or json?
if (null == share.getDocumentLocation()) {
rp.setResponse(new ResponseObject("Update Share",false,"Unable to update share: this is not a reference share"));
return rp;
}
if (!bAdminOrModOfAllCommunities) { // quick check whether I'm admin on-request - if so can endorse
bAdminOrModOfAllCommunities = RESTTools.adminLookup(ownerIdStr, false);
}//TESTED
// Remove endorsements unless I'm admin (if I'm not admin I must be owner...)
if (!bAdminOrModOfAllCommunities) { // Now need to check if I'm admin/mod/content publisher for each community..
if (null == share.getEndorsed()) { // fill this with all allowed communities
share.setEndorsed(new HashSet<ObjectId>());
share.getEndorsed().add(share.getOwner().get_id()); // (will be added later)
for (ShareCommunityPojo comm: share.getCommunities()) {
if (SocialUtils.isOwnerOrModeratorOrContentPublisher(comm.get_id().toString(), ownerIdStr)) {
share.getEndorsed().add(comm.get_id());
}
}
}//TESTED
else {
for (ShareCommunityPojo comm: share.getCommunities()) {
// (leave it as is except remove anything that I can't endorse)
if (!SocialUtils.isOwnerOrModeratorOrContentPublisher(comm.get_id().toString(), ownerIdStr)) {
share.getEndorsed().remove(comm.get_id());
}
}
}//TESTED
}//TESTED
else {
if (null == share.getEndorsed()) { // fill this with all communities
share.setEndorsed(new HashSet<ObjectId>());
share.getEndorsed().add(share.getOwner().get_id());
for (ShareCommunityPojo comm: share.getCommunities()) {
share.getEndorsed().add(comm.get_id());
}
}
//(else just leave with the same set of endorsements as before)
}//TESTED
share.setType(type);
share.setTitle(title);
share.setDescription(description);
share.setModified(new Date());
// Create DocumentLocationPojo and add to the share
DocumentLocationPojo documentLocation = new DocumentLocationPojo();
setRefLocation(location, documentLocation);
share.setDocumentLocation(documentLocation);
if (null == documentLocation.getDatabase()) { // (local file)
// Check, need to be admin:
if (!RESTTools.adminLookup(ownerIdStr, false)) {
rp.setResponse(new ResponseObject("Share", false, "Permission denied: you need to be admin to update a local file ref"));
return rp;
}
if ((null != type) && (type.equalsIgnoreCase("binary") || type.startsWith("binary:"))) {
String[] binaryType = type.split(":", 2);
if (binaryType.length > 1) {
share.setMediaType(binaryType[1]);
share.setType("binary");
}
else {
share.setMediaType(MimeUtils.getMimeType(FilenameUtils.getExtension(idStr)));
}
}
documentLocation.setCollection(idStr); // collection==file, database==id==null
}//TESTED
else {
documentLocation.set_id(new ObjectId(idStr));
}
// Get ShareOwnerPojo object
PersonPojo owner = getPerson(new ObjectId(ownerIdStr));
share.setOwner(getOwner(owner));
// Set Personal Community
share.setCommunities(getPersonalCommunity(owner));
// Serialize the ID and Dates in the object to MongoDB format
// Save the document to the share collection
DbManager.getSocial().getShare().update(query, share.toDb());
rp.setResponse(new ResponseObject("Share", true, "Share updated successfully."));
}
else
{
rp.setResponse(new ResponseObject("Share", false, "Unable to update share: only the owner of the share or admin can update it."));
return rp;
}
}
catch (Exception e)
{
//logger.error("Exception Message: " + e.getMessage(), e);
rp.setResponse(new ResponseObject("Share", false, "Unable to update share: " + e.getMessage()));
}
return rp;
}