Skip to content

Commit

Permalink
SAK-41055: Drop Box > IndexOutOfBoundsException when uploading to top…
Browse files Browse the repository at this point in the history
…-level folder with email notification
  • Loading branch information
wdn5e-virginia-edu authored and bjones86 committed Dec 14, 2018
1 parent 17fc899 commit af06a2e
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,8 @@ db.text.new.dnd = New items have been added to the Drop Box for "{0}" in the "{1

db.text.location = Location: site "{0}" > Drop Box {1} > {2}
db.text.prefs = This automatic notification message was sent by {0} ({1}) from the Drop Box in the {2} site. You can modify how you receive notifications at Home > Preferences.

db.subj.upd.dnd.toplevel = [ {0} - Top-level Drop Box items changed ]
db.subj.new.dnd.toplevel = [ {0} - New top-level Drop Box items ]
db.text.upd.dnd.toplevel = Several items have been updated in the top-level Drop Box in the "{0}" site at {1} ({2})
db.text.new.dnd.toplevel = New items have been added to the top-level Drop Box in the "{0}" site at {1} ({2})
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.List;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;

import org.sakaiproject.util.SiteEmailNotification;
import org.sakaiproject.util.api.FormattedText;
Expand Down Expand Up @@ -146,7 +147,51 @@ protected String getSubject(Event event)
String[] args = {title, folderName};
if (this.isDropboxFolder())
{
return rb.getFormattedMessage((contentHostingService.EVENT_RESOURCE_AVAILABLE.equals(function) ? "db.subj.new.dnd" : "db.subj.upd-dnd"), args);
String dropboxId = contentHostingService.getIndividualDropboxId(ref.getId());
boolean toplevel = false;
if (dropboxId == null || "".equals(dropboxId))
{
toplevel = true;
}
else
{
try
{
contentHostingService.getProperties(dropboxId);
// checking for valid INDIVIDUAL dropboxId. results not needed.
}
catch (PermissionException e)
{
log.warn("PermissionException trying to get title for individual dropbox: {}", dropboxId);
}
catch (IdUnusedException e)
{
String[] parts = dropboxId.split(Entity.SEPARATOR);
if (parts.length == 4)
{
toplevel = true;
}
else
{
log.warn("IdUnusedException trying to get title for individual dropbox: {}", dropboxId);
}
}
}
if (toplevel)
{
// toplevel templates here don't use final array item args[1] == folderName
return rb.getFormattedMessage(
(ContentHostingService.EVENT_RESOURCE_AVAILABLE.equals(function)
? "db.subj.new.dnd.toplevel"
: "db.subj.upd.dnd.toplevel"), (Object[]) args);
}
else
{
return rb.getFormattedMessage(
(ContentHostingService.EVENT_RESOURCE_AVAILABLE.equals(function)
? "db.subj.new.dnd"
: "db.subj.upd.dnd"), (Object[]) args);
}
}
else return "[ " + title + " - "
+ ((contentHostingService.EVENT_RESOURCE_AVAILABLE.equals(function))||(contentHostingService.EVENT_RESOURCE_ADD.equals(function)) ? rb.getString("newDnD") : rb.getString("chan")) + " "
Expand Down Expand Up @@ -226,8 +271,14 @@ protected List getRecipients(Event event)
String parts[] = resourceRef.split("/");
if(parts.length >= 4)
{
String dropboxOwnerId = parts[4];
if(modifiedBy != null && modifiedBy.equals(dropboxOwnerId))
String dropboxOwnerId = "";
if (parts.length >= 5)
{
dropboxOwnerId = parts[4];
}
if (StringUtils.isBlank(dropboxOwnerId) // notify on change made in common top-level dropbox
|| StringUtils.equals(modifiedBy, dropboxOwnerId)) // notify on change made by member/student in individual
// dropbox
{
// notify instructor(s)
StringBuilder buf = new StringBuilder();
Expand All @@ -245,7 +296,7 @@ protected List getRecipients(Event event)

refineToSiteMembers(recipients, site);
}
else
else // notify on change made by owner/instructor in individual dropbox
{
// notify student
try
Expand Down Expand Up @@ -525,37 +576,40 @@ private void addMessageTextResources(StringBuilder buf, String title, Reference
}
buf.append(blankLine);

for (int i=0;i<this.fileList.size();i++)
if (this.fileList != null)
{
ref2 = entityManager.newReference((String)this.getFileList().get(i));
url = ref2.getUrl();
props = ref2.getProperties();
resourceName = props.getPropertyFormatted(ResourceProperties.PROP_DISPLAY_NAME);

// add location
String path = constructPath(ref2.getReference());
buf.append(rb.getString("locsit") + " \"" + title + "\" > " + rb.getString("reso") + " " + path + " > ");
if ( doHtml )
{
buf.append("<a href=\"");
buf.append(url);
buf.append("\">");
buf.append(resourceName);
buf.append("</a>");
}
else
for (int i=0;i<this.fileList.size();i++)
{
buf.append(resourceName);
}
ref2 = entityManager.newReference((String)this.getFileList().get(i));
url = ref2.getUrl();
props = ref2.getProperties();
resourceName = props.getPropertyFormatted(ResourceProperties.PROP_DISPLAY_NAME);

// add location
String path = constructPath(ref2.getReference());
buf.append(rb.getString("locsit") + " \"" + title + "\" > " + rb.getString("reso") + " " + path + " > ");
if ( doHtml )
{
buf.append("<a href=\"");
buf.append(url);
buf.append("\">");
buf.append(resourceName);
buf.append("</a>");
}
else
{
buf.append(resourceName);
}

buf.append(blankLine);
buf.append(blankLine);

// add a reference to the resource for non-HTML
if ( ! doHtml )
{
buf.append("\n" + rb.getString("resour") + " " + resourceName);
buf.append(" " + url);
buf.append("\n\n"); // End on a blank line
// add a reference to the resource for non-HTML
if ( ! doHtml )
{
buf.append("\n" + rb.getString("resour") + " " + resourceName);
buf.append(" " + url);
buf.append("\n\n"); // End on a blank line
}
}
}

Expand Down Expand Up @@ -587,19 +641,35 @@ private void addMessageTextDropbox(StringBuilder buf, String siteTitle, Referenc
String newLine = "\n";

String dropboxId = contentHostingService.getIndividualDropboxId(ref.getId());
String dropboxTitle = null;
try
{
ResourceProperties dbProps = contentHostingService.getProperties(dropboxId);
dropboxTitle = dbProps.getPropertyFormatted(ResourceProperties.PROP_DISPLAY_NAME);
}
catch (PermissionException e)
String dropboxTitle = "";
boolean toplevel = false;
if (StringUtils.isBlank(dropboxId))
{
log.warn("PermissionException trying to get title for individual dropbox: {}", dropboxId);
}
catch (IdUnusedException e)
toplevel = true;
}
else
{
log.warn("IdUnusedException trying to get title for individual dropbox: {}", dropboxId);
try
{
ResourceProperties dbProps = contentHostingService.getProperties(dropboxId);
dropboxTitle = dbProps.getPropertyFormatted(ResourceProperties.PROP_DISPLAY_NAME);
}
catch (PermissionException e)
{
log.warn("PermissionException trying to get title for individual dropbox: {}", dropboxId);
}
catch (IdUnusedException e)
{
String[] parts = dropboxId.split(Entity.SEPARATOR);
if (parts.length == 4)
{
toplevel = true;
}
else
{
log.warn("IdUnusedException trying to get title for individual dropbox: {}", dropboxId);
}
}
}

if ( doHtml )
Expand All @@ -624,43 +694,58 @@ private void addMessageTextDropbox(StringBuilder buf, String siteTitle, Referenc
}
if (contentHostingService.EVENT_RESOURCE_AVAILABLE.equals(function))
{
buf.append(rb.getFormattedMessage("db.text.new.dnd", new String[]{dropboxTitle, siteTitle, portalName, portalUrl}));
if (toplevel)
{
buf.append(rb.getFormattedMessage("db.text.new.dnd.toplevel", new Object[] {siteTitle, portalName, portalUrl}));
}
else
{
buf.append(rb.getFormattedMessage("db.text.new.dnd", new Object[] {dropboxTitle, siteTitle, portalName, portalUrl}));
}
}
else
{
buf.append(rb.getFormattedMessage("db.text.upd.dnd", new String[]{dropboxTitle, siteTitle, portalName, portalUrl}));
if (toplevel)
{
buf.append(rb.getFormattedMessage("db.text.upd.dnd.toplevel", new Object[] {siteTitle, portalName, portalUrl}));
}
else
{
buf.append(rb.getFormattedMessage("db.text.upd.dnd", new Object[] {dropboxTitle, siteTitle, portalName, portalUrl}));
}
}
buf.append(blankLine);

//FOR
for (int i=0;i<this.fileList.size();i++)
if (this.fileList != null)
{
ref2 = entityManager.newReference((String)this.getFileList().get(i));
url = ref2.getUrl();
props = ref2.getProperties();
resourceName = props.getPropertyFormatted(ResourceProperties.PROP_DISPLAY_NAME);
for (int i=0;i<this.fileList.size();i++)
{
ref2 = entityManager.newReference((String)this.getFileList().get(i));
url = ref2.getUrl();
props = ref2.getProperties();
resourceName = props.getPropertyFormatted(ResourceProperties.PROP_DISPLAY_NAME);

// add location
String path = constructPath(ref2.getReference());
String item = resourceName;
// add location
String path = constructPath(ref2.getReference());
String item = resourceName;

if(doHtml)
{
item = "<a href=\"" + url + "\">" + item + "</a>";
}
buf.append(rb.getFormattedMessage("db.text.location", new String[]{siteTitle, path, item}));
if(doHtml)
{
item = "<a href=\"" + url + "\">" + item + "</a>";
}
buf.append(rb.getFormattedMessage("db.text.location", new String[]{siteTitle, path, item}));

buf.append(blankLine);
buf.append(blankLine);

// add a reference to the resource for non-HTML
if ( ! doHtml )
{
buf.append("\n" + rb.getString("resour") + " " + resourceName);
buf.append(" " + url);
buf.append("\n\n"); // End on a blank line
// add a reference to the resource for non-HTML
if ( ! doHtml )
{
buf.append("\n" + rb.getString("resour") + " " + resourceName);
buf.append(" " + url);
buf.append("\n\n"); // End on a blank line
}
}
}
//END FOR

// Add the tag
if (doHtml)
Expand Down

0 comments on commit af06a2e

Please sign in to comment.