Skip to content

Commit

Permalink
SAK-31528 (sakaiproject#5128)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonespm authored and ottenhoff committed Dec 14, 2017
1 parent e8a6bcc commit af47ec7
Showing 1 changed file with 42 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4025,9 +4025,7 @@ public ContentResource addAttachmentResource(String name, String type, InputStre
}

// add this collection
ContentCollectionEdit edit = addCollection(collection);
edit.getPropertiesEdit().addProperty(ResourceProperties.PROP_DISPLAY_NAME, name);
commitCollection(edit);
addAndCommitAttachmentCollection(collection, name, null);

// and add the resource
return addResource(id, type, content, properties, new ArrayList(), NotificationService.NOTI_NONE);
Expand Down Expand Up @@ -4079,24 +4077,25 @@ public ContentResource addAttachmentResource(String name, String site, String to
}

String siteCollection = ATTACHMENTS_COLLECTION + siteId + Entity.SEPARATOR;

String siteTitle = site;
String siteCreator = null;

try {
Site m_site = m_siteService.getSite(site);
siteTitle = m_site.getTitle();
siteCreator = m_site.getCreatedBy().getId();
} catch (IdUnusedException e1) {
log.debug("Site {} was null, defaulting to regular title", site);
}

try
{
checkCollection(siteCollection);
}
catch (Exception e)
{
// add this collection
ContentCollectionEdit siteEdit = addCollection(siteCollection);
try
{
String siteTitle = m_siteService.getSite(site).getTitle();
siteEdit.getPropertiesEdit().addProperty(ResourceProperties.PROP_DISPLAY_NAME, siteTitle);
}
catch (Exception e1)
{
siteEdit.getPropertiesEdit().addProperty(ResourceProperties.PROP_DISPLAY_NAME, site);
}
commitCollection(siteEdit);
addAndCommitAttachmentCollection(siteCollection, siteTitle, siteCreator);
}

String toolCollection = siteCollection + toolId + Entity.SEPARATOR;
Expand All @@ -4106,10 +4105,7 @@ public ContentResource addAttachmentResource(String name, String site, String to
}
catch (Exception e)
{
// add this collection
ContentCollectionEdit toolEdit = addCollection(toolCollection);
toolEdit.getPropertiesEdit().addProperty(ResourceProperties.PROP_DISPLAY_NAME, tool);
commitCollection(toolEdit);
addAndCommitAttachmentCollection(toolCollection, tool, siteCreator);
}

// form a name based on the attachments collection, a unique folder id, and the given name
Expand All @@ -4121,10 +4117,7 @@ public ContentResource addAttachmentResource(String name, String site, String to
throw new RuntimeException(ID_LENGTH_EXCEPTION);
}

// add this collection
ContentCollectionEdit edit = addCollection(collection);
edit.getPropertiesEdit().addProperty(ResourceProperties.PROP_DISPLAY_NAME, name);
commitCollection(edit);
addAndCommitAttachmentCollection(collection, name, siteCreator);

// and add the resource
return addResource(id, type, content, properties, new ArrayList(), NotificationService.NOTI_NONE);
Expand Down Expand Up @@ -4162,15 +4155,37 @@ public ContentResourceEdit addAttachmentResource(String name) throws IdInvalidEx
// form a name based on the attachments collection, a unique folder id, and the given name
String collection = ATTACHMENTS_COLLECTION + idManager.createUuid() + Entity.SEPARATOR;
String id = collection + name;

addAndCommitAttachmentCollection(collection, name, null);

return addResource(id);

} // addAttachmentResource

/**
* addAndCommitAttachmentCollection - Helper to Add and Commit an Attachment Collection, used by many methods
* @param collection - Value of collection to create
* @param name - Name of collection
* @param createdBy - Id of user creating or null to leave unchaned
*
* @throws IdUsedException
* @throws IdInvalidException
* @throws PermissionException
* @throws InconsistentException
*/

private void addAndCommitAttachmentCollection(String collection, String name, String createdBy) throws IdUsedException, IdInvalidException, PermissionException, InconsistentException {
// add this collection
ContentCollectionEdit edit = addCollection(collection);
edit.getPropertiesEdit().addProperty(ResourceProperties.PROP_DISPLAY_NAME, name);
commitCollection(edit);

return addResource(id);

} // addAttachmentResource
//Set the created by to someone else unless null
if (createdBy != null) {
edit.getPropertiesEdit().addProperty(ResourceProperties.PROP_CREATOR, createdBy);
}

commitCollection(edit);
}

/**
* check permissions for updateResource().
Expand Down

0 comments on commit af47ec7

Please sign in to comment.