Fix to Site Profile dashlet to handle missing "isPublic" flag.

Refactor of upload webscript to fix issue with missing document reference and reduce code paths.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@10118 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Kevin Roast
2008-07-30 11:38:03 +00:00
parent abc20e4b06
commit 9392bbf502

View File

@@ -1,23 +1,25 @@
var filename = null; function main()
var content = null;
var mimetype = null;
var siteId = null;
var containerId = null;
var thumbnailNames = null;
// Upload specific
var uploadDirectory = null;
var title = "";
var overwrite = true; // If a filename clashes for a versionable file
// Update specific
var updateNodeRef = null;
var majorVersion = false;
var description = "";
// Parse file attributes
for each (field in formdata.fields)
{ {
var filename = null;
var content = null;
var mimetype = null;
var siteId = null;
var containerId = null;
var thumbnailNames = null;
// Upload specific
var uploadDirectory = null;
var title = "";
var overwrite = true; // If a filename clashes for a versionable file
// Update specific
var updateNodeRef = null;
var majorVersion = false;
var description = "";
// Parse file attributes
for each (field in formdata.fields)
{
switch (String(field.name).toLowerCase()) switch (String(field.name).toLowerCase())
{ {
case "filedata": case "filedata":
@@ -79,26 +81,26 @@ for each (field in formdata.fields)
thumbnailNames = field.value; thumbnailNames = field.value;
break; break;
} }
} }
// Ensure mandatory file attributes have been located // Ensure mandatory file attributes have been located
if (siteId === null || containerId === null || filename === null || content === null) if (siteId === null || containerId === null || filename === null || content === null)
{ {
status.code = 400; status.code = 400;
status.message = "Required parameters are missing"; status.message = "Required parameters are missing";
//status.redirect = false; status.redirect = true;
} return;
else }
{
var site = siteService.getSite(siteId); var site = siteService.getSite(siteId);
if (site === null) if (site === null)
{ {
status.code = 404; status.code = 404;
status.message = "Site (" + siteId + ") not found."; status.message = "Site (" + siteId + ") not found.";
status.redirect = true; status.redirect = true;
return;
} }
else
{
// Upload mode, since uploadDirectory was used // Upload mode, since uploadDirectory was used
var container = site.getContainer(containerId); var container = site.getContainer(containerId);
if (container === null) if (container === null)
@@ -123,8 +125,10 @@ else
status.code = 404; status.code = 404;
status.message = "Cannot upload document since updateNodeRef '" + updateNodeRef + "' points to a locked document, supply a nodeRef to its working copy instead."; status.message = "Cannot upload document since updateNodeRef '" + updateNodeRef + "' points to a locked document, supply a nodeRef to its working copy instead.";
status.redirect = true; status.redirect = true;
return;
} }
else if (!workingCopy.hasAspect("cm:workingcopy"))
if (!workingCopy.hasAspect("cm:workingcopy"))
{ {
// It's not a working copy, do a check out to get the working copy // It's not a working copy, do a check out to get the working copy
workingCopy = workingCopy.checkout(); workingCopy = workingCopy.checkout();
@@ -147,10 +151,10 @@ else
status.code = 404; status.code = 404;
status.message = "Cannot upload file since uploadDirectory '" + uploadDirectory + "' does not exist."; status.message = "Cannot upload file since uploadDirectory '" + uploadDirectory + "' does not exist.";
status.redirect = true; status.redirect = true;
return;
} }
var existingFile = container.childByNamePath(uploadDirectory + filename); var existingFile = container.childByNamePath(uploadDirectory + filename);
var overwritten = false;
if (existingFile !== null) if (existingFile !== null)
{ {
// File already exists, decide what to do // File already exists, decide what to do
@@ -159,8 +163,7 @@ else
// Upload component was configured to overwrite files if name clashes // Upload component was configured to overwrite files if name clashes
existingFile.properties.content.write(content); existingFile.properties.content.write(content);
model.document = existingFile; model.document = existingFile;
// Stop creation of new file below return;
overwritten = true;
} }
else else
{ {
@@ -178,8 +181,6 @@ else
} }
// save the new file (original or renamed file) as long as an overwrite hasn't been performed // save the new file (original or renamed file) as long as an overwrite hasn't been performed
if (!overwritten)
{
var newFile = destNode.createFile(filename); var newFile = destNode.createFile(filename);
newFile.properties.contentType = contentType; newFile.properties.contentType = contentType;
newFile.properties.content.write(content); newFile.properties.content.write(content);
@@ -190,8 +191,8 @@ else
newFile.properties.description = description; newFile.properties.description = description;
// Make file versionable (todo: check that this is ok depending on version store development) // Make file versionable (todo: check that this is ok depending on version store development)
newFile.addAspect("cm:versionable"); newFile.addAspect("cm:versionable");
// Save new file
newFile.save(); newFile.save();
// Create thumbnail? // Create thumbnail?
if (thumbnailNames != null) if (thumbnailNames != null)
{ {
@@ -207,12 +208,13 @@ else
} }
model.document = newFile; model.document = newFile;
} }
}
else else
{ {
status.code = 404; status.code = 404;
status.message = "Illegal arguments: updateNodeRef OR uploadDirectory must be provided (not both)"; status.message = "Illegal arguments: updateNodeRef OR uploadDirectory must be provided (not both)";
status.redirect = true; status.redirect = true;
} return;
} }
} }
main();