take of NPE, add rest method to cleanup uploaded files in session

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1307830 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2012-03-31 15:35:32 +00:00
parent dbe30a337d
commit 62a08312f9
4 changed files with 65 additions and 35 deletions

View File

@ -147,7 +147,7 @@ public abstract class AbstractRestService
protected void triggerAuditEvent( String repositoryId, String filePath, String action ) protected void triggerAuditEvent( String repositoryId, String filePath, String action )
{ {
AuditEvent auditEvent = new AuditEvent(); AuditEvent auditEvent = new AuditEvent( action, repositoryId );
auditEvent.setAction( action ); auditEvent.setAction( action );
auditEvent.setRepositoryId( repositoryId ); auditEvent.setRepositoryId( repositoryId );
auditEvent.setResource( filePath ); auditEvent.setResource( filePath );

View File

@ -187,6 +187,17 @@ public class DefaultFileUploadService
return Boolean.FALSE; return Boolean.FALSE;
} }
public Boolean clearUploadedFiles()
throws ArchivaRestServiceException
{
List<FileMetadata> fileMetadatas = getSessionFileMetadatas();
for ( FileMetadata fileMetadata : fileMetadatas )
{
deleteFile( fileMetadata.getServerFileName() );
}
return Boolean.TRUE;
}
public List<FileMetadata> getSessionFileMetadatas() public List<FileMetadata> getSessionFileMetadatas()
throws ArchivaRestServiceException throws ArchivaRestServiceException
{ {

View File

@ -75,4 +75,12 @@ public interface FileUploadService
@PathParam( "artifactId" ) String artifactId, @QueryParam( "generatePom" ) boolean generatePom ) @PathParam( "artifactId" ) String artifactId, @QueryParam( "generatePom" ) boolean generatePom )
throws ArchivaRestServiceException; throws ArchivaRestServiceException;
@Path( "clearUploadedFiles" )
@GET
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
@RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD )
Boolean clearUploadedFiles()
throws ArchivaRestServiceException;
} }

View File

@ -38,7 +38,7 @@ define("archiva.artifacts-management",["jquery","i18n","order!utils","order!jque
this.artifactUploads=[]; this.artifactUploads=[];
saveArtifacts=function(){ saveArtifacts=function(){
clearUserMessages();
if(!$("#main-content #fileupload" ).valid()){ if(!$("#main-content #fileupload" ).valid()){
return; return;
} }
@ -55,6 +55,10 @@ define("archiva.artifacts-management",["jquery","i18n","order!utils","order!jque
dataType: 'json', dataType: 'json',
success: function(data) { success: function(data) {
},
error: function(data) {
var res = $.parseJSON(data.responseText);
displayRestError(res);
} }
} }
); );
@ -66,46 +70,53 @@ define("archiva.artifacts-management",["jquery","i18n","order!utils","order!jque
displayUploadArtifact=function(){ displayUploadArtifact=function(){
var mainContent=$("#main-content"); var mainContent=$("#main-content");
mainContent.html(mediumSpinnerImg()); mainContent.html(mediumSpinnerImg());
mainContent.html($("#file-upload-screen" ).html());
$.ajax("restServices/archivaServices/browseService/userRepositories", {
$.ajax("restServices/archivaUiServices/fileUploadService/clearUploadedFiles", {
type: "GET", type: "GET",
dataType: 'json', dataType: 'json',
success: function(data) { success: function(data) {
var artifactUploadViewModel=new ArtifactUploadViewModel(data); mainContent.html($("#file-upload-screen" ).html());
ko.applyBindings(artifactUploadViewModel,mainContent.find("#file-upload-main" ).get(0)); $.ajax("restServices/archivaServices/browseService/userRepositories", {
var validator = $("#main-content #fileupload" ).validate({ type: "GET",
showErrors: function(validator, errorMap, errorList) { dataType: 'json',
customShowError("#main-content #fileupload",validator,errorMap,errorMap); success: function(data) {
} var artifactUploadViewModel=new ArtifactUploadViewModel(data);
}); ko.applyBindings(artifactUploadViewModel,mainContent.find("#file-upload-main" ).get(0));
$('#fileupload').fileupload({ var validator = $("#main-content #fileupload" ).validate({
add: function (e, data) { showErrors: function(validator, errorMap, errorList) {
data.formData = { customShowError("#main-content #fileupload",validator,errorMap,errorMap);
groupId: artifactUploadViewModel.groupId(), }
artifactId: artifactUploadViewModel.artifactId(), });
version: artifactUploadViewModel.version(), $('#fileupload').fileupload({
packaging: artifactUploadViewModel.packaging() add: function (e, data) {
}; data.formData = {
$.blueimpUI.fileupload.prototype.options.add.call(this, e, data); groupId: artifactUploadViewModel.groupId(),
}, artifactId: artifactUploadViewModel.artifactId(),
submit: function (e, data) { version: artifactUploadViewModel.version(),
var $this = $(this); packaging: artifactUploadViewModel.packaging()
};
$.blueimpUI.fileupload.prototype.options.add.call(this, e, data);
},
submit: function (e, data) {
var $this = $(this);
$this.fileupload('send', data); $this.fileupload('send', data);
artifactUploadViewModel.artifactUploads.push(new ArtifactUpload(data.formData.classifier,data.formData.pomFile)); artifactUploadViewModel.artifactUploads.push(new ArtifactUpload(data.formData.classifier,data.formData.pomFile));
return false; return false;
}
}
);
$('#fileupload').bind('fileuploadsubmit', function (e, data) {
var pomFile = data.context.find('#pomFile' ).attr("checked");
var classifier = data.context.find('#classifier' ).val();
data.formData.pomFile = pomFile;
data.formData.classifier = classifier;
});
} }
}
);
$('#fileupload').bind('fileuploadsubmit', function (e, data) {
var pomFile = data.context.find('#pomFile' ).attr("checked");
var classifier = data.context.find('#classifier' ).val();
data.formData.pomFile = pomFile;
data.formData.classifier = classifier;
}); });
} }
}); });
} }
}); });