Skip to content

Commit

Permalink
Merge pull request pentaho#2741 from AliaksandrDrebenchuk/BACKLOG-5863
Browse files Browse the repository at this point in the history
BACKLOG-5863 Cannot rename files in folders
  • Loading branch information
pentaho-nbaker committed Dec 28, 2015
2 parents 25a9ef7 + 075631f commit 74d1e03
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1889,8 +1889,6 @@ public Response doRename( @PathParam( "pathId" ) String pathId, @QueryParam( "ne
try {
JcrRepositoryFileUtils.checkName( newName );

checkCorrectExtension( newName );

boolean success = fileService.doRename( pathId, newName );
if ( success ) {
return buildOkResponse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1369,41 +1369,25 @@ public void testDoRename() throws Exception {
doReturn( mockOkMsgResponse ).when( fileResource ).buildOkResponse( errMsg );

// Test 1
doReturn( true ).when( fileResource.fileService ).doRename( PATH_ID, NAME_NEW_FILE );
doReturn( true ).when( fileResource.fileService ).doRename( PATH_ID, NAME_NEW_FILE_WITHOUTH_EXTENSION );

Response testResponse = fileResource.doRename( PATH_ID, NAME_NEW_FILE );
Response testResponse = fileResource.doRename( PATH_ID, NAME_NEW_FILE_WITHOUTH_EXTENSION );
assertEquals( mockOkResponse, testResponse );

// Test 2
doReturn( false ).when( fileResource.fileService ).doRename( PATH_ID, NAME_NEW_FILE );
doReturn( false ).when( fileResource.fileService ).doRename( PATH_ID, NAME_NEW_FILE_WITHOUTH_EXTENSION );

testResponse = fileResource.doRename( PATH_ID, NAME_NEW_FILE );
testResponse = fileResource.doRename( PATH_ID, NAME_NEW_FILE_WITHOUTH_EXTENSION );
assertEquals( mockOkMsgResponse, testResponse );

verify( fileResource.fileService, times( 2 ) ).doRename( PATH_ID, NAME_NEW_FILE );
verify( fileResource.fileService, times( 2 ) ).doRename( PATH_ID, NAME_NEW_FILE_WITHOUTH_EXTENSION );
verify( fileResource, times( 1 ) ).buildOkResponse();
verify( fileResource, times( 1 ) ).buildOkResponse( errMsg );
}

@Test
public void testDoRenameWithoutExtension() throws Exception {
Response testResponse = fileResource.doRename( PATH_ID, NAME_NEW_FILE_WITHOUTH_EXTENSION );
assertEquals( Status.INTERNAL_SERVER_ERROR.getStatusCode(), testResponse.getStatus() );

verify( fileResource, times( 1 ) ).buildServerErrorResponse( anyString() );
}

@Test
public void testDoRenameIncorrectExtension() throws Exception {
Response testResponse = fileResource.doRename( PATH_ID, NAME_NEW_FILE_WRONG_EXTENSION );
assertEquals( Status.INTERNAL_SERVER_ERROR.getStatusCode(), testResponse.getStatus() );

verify( fileResource, times( 1 ) ).buildServerErrorResponse( anyString() );
}

@Test
public void testDoRenameCorrectExtension() throws Exception {
Response testResponse = fileResource.doRename( PATH_ID, NAME_NEW_FILE );
Response testResponse = fileResource.doRename( PATH_ID, NAME_NEW_FILE_WITHOUTH_EXTENSION );
assertEquals( Status.OK.getStatusCode(), testResponse.getStatus() );

verify( fileResource, times( 1 ) ).buildOkResponse( anyString() );
Expand All @@ -1412,18 +1396,18 @@ public void testDoRenameCorrectExtension() throws Exception {
@Test
public void testDoRenameError() throws Exception {
Throwable mockThrowable = mock( RuntimeException.class );
doThrow( mockThrowable ).when( fileResource.fileService ).doRename( PATH_ID, NAME_NEW_FILE );
doThrow( mockThrowable ).when( fileResource.fileService ).doRename( PATH_ID, NAME_NEW_FILE_WITHOUTH_EXTENSION );

String msg = "msg";
doReturn( msg ).when( mockThrowable ).getMessage();

Response mockResponse = mock( Response.class );
doReturn( mockResponse ).when( fileResource ).buildServerErrorResponse( msg );

Response testResponse = fileResource.doRename( PATH_ID, NAME_NEW_FILE );
Response testResponse = fileResource.doRename( PATH_ID, NAME_NEW_FILE_WITHOUTH_EXTENSION );
assertEquals( mockResponse, testResponse );

verify( fileResource.fileService, times( 1 ) ).doRename( PATH_ID, NAME_NEW_FILE );
verify( fileResource.fileService, times( 1 ) ).doRename( PATH_ID, NAME_NEW_FILE_WITHOUTH_EXTENSION );
verify( mockThrowable, times( 1 ) ).getMessage();
verify( fileResource, times( 1 ) ).buildServerErrorResponse( msg );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ define([
initialize: function () {
var me = this;

this.on("change:name", this.renamePath);

// Set default for showOverrideDialog
BrowserUtils._makeAjaxCall("GET", "text", this.buildsessionVariableUrl("showOverrideDialog"), true, function (result) {
me.set("showOverrideDialog", result.length == 0 || result === "true");
Expand All @@ -59,8 +57,7 @@ define([
this.set("path", null);
},

renamePath: function (event, name) {
var prevName = event._previousAttributes.name;
renamePath: function (prevName, name) {

// if the value was previously null or being set to null, nothing should happen
if (prevName === null || name === null) {
Expand Down Expand Up @@ -307,7 +304,9 @@ define([

this.RenameDialog.$dialog.find(".ok").bind("click", function () {
me.RenameDialog.hide();
me.model.set("name", me.$el.find("#rename-field").val());
var newName = me.$el.find("#rename-field").val();
var oldName = me.model.get("name");
me.model.renamePath( oldName,newName );
});
this.RenameDialog.$dialog.find(".cancel").bind("click", function () {
me.cancelRename.apply(me);
Expand Down Expand Up @@ -351,6 +350,18 @@ define([
init: function (path, overrideType) {

var repoPath = Encoder.encodeRepositoryPath( path );

var name = path.split("/")[path.split("/").length - 1];
if ( overrideType !== "folder") {
var dotIndex = name.lastIndexOf("\.");
if (dotIndex > -1) {
name = name.substr(0, dotIndex);
}
}

this.model.set("path", repoPath);
this.model.set("name", name);
this.view.overrideType = overrideType;

var me = this;
BrowserUtils._makeAjaxCall("GET", "json", BrowserUtils.getUrlBase() + "api/repo/files/" + FileBrowser.encodePathComponents(repoPath) + "/localeProperties", true,
Expand All @@ -361,24 +372,11 @@ define([
var obj = arr[i];
if (obj.key === "file.title") {
me.model.set("name", obj.value);
return;
}
}
}
me.view.render();
});

var name = path.split("/")[path.split("/").length - 1];
if ( overrideType !== "folder") {
var dotIndex = name.lastIndexOf("\.");
if (dotIndex > -1) {
name = name.substr(0, dotIndex);
}
}

this.model.set("path", repoPath);
this.model.set("name", name);
this.view.overrideType = overrideType;
this.view.render();
}
}

Expand Down

0 comments on commit 74d1e03

Please sign in to comment.