Skip to content

Commit

Permalink
SAK-31346 adding exception catch on createEntity and use getEntity me…
Browse files Browse the repository at this point in the history
…thod if thrown (sakaiproject#2801)
  • Loading branch information
relong76 authored and bjones86 committed Jun 10, 2016
1 parent d4178d7 commit ac95f68
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,14 @@ private void createContentResource(String rootCollectionId,
ZipEntry nextElement, ZipFile zipFile) throws Exception {
String resourceId = rootCollectionId + nextElement.getName();
String resourceName = extractName(nextElement.getName());
ContentResourceEdit resourceEdit = ContentHostingService.addResource(resourceId);
ContentResourceEdit resourceEdit;
try {
resourceEdit = ContentHostingService.addResource(resourceId);
} catch (IdUsedException iue) {
// resource exists, update instead
LOG.debug("Content resource with ID " + resourceId + " exists. Editing instead.");
resourceEdit = ContentHostingService.editResource(resourceId);
}
resourceEdit.setContent(zipFile.getInputStream(nextElement));
resourceEdit.setContentType(mime.getContentType(resourceName));
ResourcePropertiesEdit props = resourceEdit.getPropertiesEdit();
Expand All @@ -397,7 +404,14 @@ private void createContentCollection(String rootCollectionId,
ZipEntry element) throws Exception {
String resourceId = rootCollectionId + element.getName();
String resourceName = extractName(element.getName());
ContentCollectionEdit collection = ContentHostingService.addCollection(resourceId);
ContentCollectionEdit collection;
try {
collection = ContentHostingService.addCollection(resourceId);
} catch (IdUsedException iue) {
// collection exists, update instead
LOG.debug("Content collection with ID " + resourceId + " exists. Editing instead.");
collection = ContentHostingService.editCollection(resourceId);
}
ResourcePropertiesEdit props = collection.getPropertiesEdit();
props.addProperty(ResourcePropertiesEdit.PROP_DISPLAY_NAME, resourceName);
ContentHostingService.commitCollection(collection);
Expand Down

0 comments on commit ac95f68

Please sign in to comment.