Skip to content

Commit

Permalink
[Fix-3536][api]If user didn't have tenant,create resource directory w…
Browse files Browse the repository at this point in the history
…ill NPE (#3537)

* [Fix-3536][api]If user didn't have tenant,create resource will NPE

* [Fix-3536][api]If user didn't have tenant,create resource directory will NPE
  • Loading branch information
lgcareer committed Aug 18, 2020
1 parent a3f6123 commit 0505ebf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ public Result createDirectory(User loginUser,
return result;
}
String fullName = currentDir.equals("/") ? String.format("%s%s",currentDir,name):String.format("%s/%s",currentDir,name);

result = verifyResourceName(fullName,type,loginUser);
if (!result.getCode().equals(Status.SUCCESS.getCode())) {
return result;
}
if (pid != -1) {
Resource parentResource = resourcesMapper.selectById(pid);

Expand All @@ -118,13 +121,6 @@ public Result createDirectory(User loginUser,
}
}


if (checkResourceExists(fullName, 0, type.ordinal())) {
logger.error("resource directory {} has exist, can't recreate", fullName);
putMsg(result, Status.RESOURCE_EXIST);
return result;
}

Date now = new Date();

Resource resource = new Resource(pid,name,fullName,true,description,name,loginUser.getId(),type,0,now,now);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ public void testCreateDirecotry(){
Assert.assertEquals(Status.HDFS_NOT_STARTUP.getMsg(),result.getMsg());

//PARENT_RESOURCE_NOT_EXIST
user.setId(1);
user.setTenantId(1);
Mockito.when(userMapper.selectById(1)).thenReturn(getUser());
Mockito.when(tenantMapper.queryById(1)).thenReturn(getTenant());
PowerMockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(true);
Mockito.when(resourcesMapper.selectById(Mockito.anyInt())).thenReturn(null);
result = resourcesService.createDirectory(user,"directoryTest","directory test",ResourceType.FILE,1,"/");
Expand Down

0 comments on commit 0505ebf

Please sign in to comment.