Browse Source

Adapting partial code(file name start with R) to the sonar cloud rule (#2243)

pull/3/MERGE
gabry.wu 5 years ago committed by gaojun2048
parent
commit
e1771de45a
  1. 8
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ResourcesController.java
  2. 25
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ResourcesService.java
  3. 2
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/PropertyUtils.java
  4. 12
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ResourceMapperTest.java
  5. 4
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ResourceUserMapperTest.java
  6. 8
      dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/future/ResponseFuture.java
  7. 2
      dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/utils/RemoveZKNode.java

8
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ResourcesController.java

@ -144,7 +144,7 @@ public class ResourcesController extends BaseController{
@RequestParam(value ="type") ResourceType type
){
try{
logger.info("query resource list, login user:{}, resource type:{}", loginUser.getUserName(), type.toString());
logger.info("query resource list, login user:{}, resource type:{}", loginUser.getUserName(), type);
Map<String, Object> result = resourceService.queryResourceList(loginUser, type);
return returnDataList(result);
}catch (Exception e){
@ -180,7 +180,7 @@ public class ResourcesController extends BaseController{
){
try{
logger.info("query resource list, login user:{}, resource type:{}, search value:{}",
loginUser.getUserName(), type.toString(), searchVal);
loginUser.getUserName(), type, searchVal);
Map<String, Object> result = checkPageParams(pageNo, pageSize);
if(result.get(Constants.STATUS) != Status.SUCCESS){
return returnDataListPaging(result);
@ -426,8 +426,6 @@ public class ResourcesController extends BaseController{
@RequestParam(value = "resourceId") int resourceId) {
logger.info("login user {}, create udf function, type: {}, funcName: {},argTypes: {} ,database: {},desc: {},resourceId: {}",
loginUser.getUserName(),type, funcName, argTypes,database,description, resourceId);
Result result = new Result();
try {
return udfFuncService.createUdfFunction(loginUser,funcName,className,argTypes,database,description,type,resourceId);
} catch (Exception e) {
@ -563,7 +561,7 @@ public class ResourcesController extends BaseController{
public Result queryResourceList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("type") UdfType type){
try{
logger.info("query datasource list, user:{}, type:{}", loginUser.getUserName(), type.toString());
logger.info("query datasource list, user:{}, type:{}", loginUser.getUserName(), type);
Map<String, Object> result = udfFuncService.queryResourceList(loginUser,type.ordinal());
return returnDataList(result);
}catch (Exception e){

25
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ResourcesService.java

@ -24,10 +24,7 @@ import org.apache.dolphinscheduler.api.utils.PageInfo;
import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.common.Constants;
import org.apache.dolphinscheduler.common.enums.ResourceType;
import org.apache.dolphinscheduler.common.utils.FileUtils;
import org.apache.dolphinscheduler.common.utils.HadoopUtils;
import org.apache.dolphinscheduler.common.utils.PropertyUtils;
import org.apache.dolphinscheduler.common.utils.StringUtils;
import org.apache.dolphinscheduler.common.utils.*;
import org.apache.dolphinscheduler.dao.entity.Resource;
import org.apache.dolphinscheduler.dao.entity.Tenant;
import org.apache.dolphinscheduler.dao.entity.UdfFunc;
@ -141,7 +138,7 @@ public class ResourcesService extends BaseService {
putMsg(result, Status.SUCCESS);
Map<Object, Object> dataMap = new BeanMap(resource);
Map<String, Object> resultMap = new HashMap<String, Object>();
Map<String, Object> resultMap = new HashMap<>();
for (Map.Entry<Object, Object> entry: dataMap.entrySet()) {
if (!"class".equalsIgnoreCase(entry.getKey().toString())) {
resultMap.put(entry.getKey().toString(), entry.getValue());
@ -171,12 +168,8 @@ public class ResourcesService extends BaseService {
* @return true if resource exists
*/
private boolean checkResourceExists(String alias, int userId, int type ){
List<Resource> resources = resourcesMapper.queryResourceList(alias, userId, type);
if (resources != null && resources.size() > 0) {
return true;
}
return false;
return CollectionUtils.isNotEmpty(resources);
}
@ -237,7 +230,7 @@ public class ResourcesService extends BaseService {
//get the file suffix
String originResourceName = resource.getAlias();
String suffix = originResourceName.substring(originResourceName.lastIndexOf("."));
String suffix = originResourceName.substring(originResourceName.lastIndexOf('.'));
//if the name without suffix then add it ,else use the origin name
String nameWithSuffix = name;
@ -746,8 +739,7 @@ public class ResourcesService extends BaseService {
logger.info("resource hdfs path is {} ", hdfsFileName);
HadoopUtils.getInstance().copyHdfsToLocal(hdfsFileName, localFileName, false, true);
org.springframework.core.io.Resource file = org.apache.dolphinscheduler.api.utils.FileUtils.file2Resource(localFileName);
return file;
return org.apache.dolphinscheduler.api.utils.FileUtils.file2Resource(localFileName);
}
@ -766,7 +758,7 @@ public class ResourcesService extends BaseService {
}
List<Resource> resourceList = resourcesMapper.queryResourceExceptUserId(userId);
List<Object> list ;
if (resourceList != null && resourceList.size() > 0) {
if (CollectionUtils.isNotEmpty(resourceList)) {
Set<Resource> resourceSet = new HashSet<>(resourceList);
List<Resource> authedResourceList = resourcesMapper.queryAuthorizedResourceList(userId);
@ -801,7 +793,7 @@ public class ResourcesService extends BaseService {
List<UdfFunc> udfFuncList = udfFunctionMapper.queryUdfFuncExceptUserId(userId);
List<UdfFunc> resultList = new ArrayList<>();
Set<UdfFunc> udfFuncSet = null;
if (udfFuncList != null && udfFuncList.size() > 0) {
if (CollectionUtils.isNotEmpty(udfFuncList)) {
udfFuncSet = new HashSet<>(udfFuncList);
List<UdfFunc> authedUDFFuncList = udfFunctionMapper.queryAuthedUdfFunc(userId);
@ -897,10 +889,9 @@ public class ResourcesService extends BaseService {
*/
private void getAuthorizedResourceList(Set<?> resourceSet, List<?> authedResourceList) {
Set<?> authedResourceSet = null;
if (authedResourceList != null && authedResourceList.size() > 0) {
if (CollectionUtils.isNotEmpty(authedResourceList)) {
authedResourceSet = new HashSet<>(authedResourceList);
resourceSet.removeAll(authedResourceSet);
}
}

2
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/PropertyUtils.java

@ -71,7 +71,7 @@ public class PropertyUtils {
*
* @return judge whether resource upload startup
*/
public static Boolean getResUploadStartupState(){
public static boolean getResUploadStartupState(){
String resUploadStartupType = PropertyUtils.getString(Constants.RES_UPLOAD_STARTUP_TYPE);
ResUploadType resUploadType = ResUploadType.valueOf(resUploadStartupType);
return resUploadType == ResUploadType.HDFS || resUploadType == ResUploadType.S3;

12
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ResourceMapperTest.java

@ -138,7 +138,7 @@ public class ResourceMapperTest {
resource.setCreateTime(new Date());
//update
int update = resourceMapper.updateById(resource);
Assert.assertEquals(update, 1);
Assert.assertEquals(1, update);
resourceMapper.deleteById(resource.getId());
}
@ -149,7 +149,7 @@ public class ResourceMapperTest {
public void testDelete(){
Resource resourceMap = insertOne();
int delete = resourceMapper.deleteById(resourceMap.getId());
Assert.assertEquals(delete, 1);
Assert.assertEquals(1, delete);
}
/**
@ -236,8 +236,8 @@ public class ResourceMapperTest {
resourceUserMapper.deleteById(resourcesUser.getId());
resourceMapper.deleteById(resource.getId());
Assert.assertEquals(resources.size(), 0);
Assert.assertNotEquals(resources1.size(), 0);
Assert.assertEquals(0, resources.size());
Assert.assertNotEquals(0, resources1.size());
}
@ -251,7 +251,7 @@ public class ResourceMapperTest {
List<Resource> resources = resourceMapper.queryAuthorizedResourceList(resource.getUserId());
resourceMapper.deleteById(resource.getId());
Assert.assertEquals(resources.size(), 0);
Assert.assertEquals(0, resources.size());
}
/**
@ -293,7 +293,7 @@ public class ResourceMapperTest {
);
Assert.assertEquals(resource1, "ut tenant code for resource");
Assert.assertEquals("ut tenant code for resource", resource1);
resourceMapper.deleteById(resource.getId());
}

4
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ResourceUserMapperTest.java

@ -62,7 +62,7 @@ public class ResourceUserMapperTest {
queue.setCreateTime(new Date());
//update
int update = resourceUserMapper.updateById(queue);
Assert.assertEquals(update, 1);
Assert.assertEquals(1, update);
resourceUserMapper.deleteById(queue.getId());
}
@ -73,7 +73,7 @@ public class ResourceUserMapperTest {
public void testDelete(){
ResourcesUser queue = insertOne();
int delete = resourceUserMapper.deleteById(queue.getId());
Assert.assertEquals(delete, 1);
Assert.assertEquals(1, delete);
}
/**

8
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/future/ResponseFuture.java

@ -32,9 +32,9 @@ import java.util.concurrent.*;
*/
public class ResponseFuture {
private final static Logger LOGGER = LoggerFactory.getLogger(ResponseFuture.class);
private static final Logger LOGGER = LoggerFactory.getLogger(ResponseFuture.class);
private final static ConcurrentHashMap<Long,ResponseFuture> FUTURE_TABLE = new ConcurrentHashMap<>(256);
private static final ConcurrentHashMap<Long,ResponseFuture> FUTURE_TABLE = new ConcurrentHashMap<>(256);
/**
* request unique identification
@ -63,11 +63,11 @@ public class ResponseFuture {
/**
* response command
*/
private volatile Command responseCommand;
private Command responseCommand;
private volatile boolean sendOk = true;
private volatile Throwable cause;
private Throwable cause;
public ResponseFuture(long opaque, long timeoutMillis, InvokeCallback invokeCallback, ReleaseSemaphore releaseSemaphore) {
this.opaque = opaque;

2
dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/utils/RemoveZKNode.java

@ -28,7 +28,7 @@ import org.springframework.context.annotation.ComponentScan;
@ComponentScan("org.apache.dolphinscheduler")
public class RemoveZKNode implements CommandLineRunner {
private static Integer ARGS_LENGTH = 1;
private static final Integer ARGS_LENGTH = 1;
private static final Logger logger = LoggerFactory.getLogger(RemoveZKNode.class);

Loading…
Cancel
Save