Browse Source

Adapting partial code(file name start with E) to the sonar cloud rule (#1999)

* Adapting partial code(file name start with E) to the sonar cloud rule

* remove isEmpty invoke

* resolve conflicts
gabry.wu 5 years ago
parent
commit
6a8cef08e4

+ 2 - 2
dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/manager/EnterpriseWeChatManager.java

@@ -42,8 +42,8 @@ public class EnterpriseWeChatManager {
     public Map<String,Object> send(Alert alert, String token){
         Map<String,Object> retMap = new HashMap<>();
         retMap.put(Constants.STATUS, false);
-        String agentId = EnterpriseWeChatUtils.enterpriseWeChatAgentId;
-        String users = EnterpriseWeChatUtils.enterpriseWeChatUsers;
+        String agentId = EnterpriseWeChatUtils.ENTERPRISE_WE_CHAT_AGENT_ID;
+        String users = EnterpriseWeChatUtils.ENTERPRISE_WE_CHAT_USERS;
         List<String> userList = Arrays.asList(users.split(","));
         logger.info("send message {}",alert);
         String msg = EnterpriseWeChatUtils.makeUserSendMsg(userList, agentId,EnterpriseWeChatUtils.markdownByAlert(alert));

+ 19 - 19
dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/EnterpriseWeChatUtils.java

@@ -43,24 +43,24 @@ public class EnterpriseWeChatUtils {
 
     public static final Logger logger = LoggerFactory.getLogger(EnterpriseWeChatUtils.class);
 
-    private static final String enterpriseWeChatCorpId = PropertyUtils.getString(Constants.ENTERPRISE_WECHAT_CORP_ID);
+    private static final String ENTERPRISE_WE_CHAT_CORP_ID = PropertyUtils.getString(Constants.ENTERPRISE_WECHAT_CORP_ID);
 
-    private static final String enterpriseWeChatSecret = PropertyUtils.getString(Constants.ENTERPRISE_WECHAT_SECRET);
+    private static final String ENTERPRISE_WE_CHAT_SECRET = PropertyUtils.getString(Constants.ENTERPRISE_WECHAT_SECRET);
 
-    private static final String enterpriseWeChatTokenUrl = PropertyUtils.getString(Constants.ENTERPRISE_WECHAT_TOKEN_URL);
-    private static String enterpriseWeChatTokenUrlReplace = enterpriseWeChatTokenUrl
-            .replaceAll("\\$corpId", enterpriseWeChatCorpId)
-            .replaceAll("\\$secret", enterpriseWeChatSecret);
+    private static final String ENTERPRISE_WE_CHAT_TOKEN_URL = PropertyUtils.getString(Constants.ENTERPRISE_WECHAT_TOKEN_URL);
+    private static final String ENTERPRISE_WE_CHAT_TOKEN_URL_REPLACE = ENTERPRISE_WE_CHAT_TOKEN_URL
+            .replaceAll("\\$corpId", ENTERPRISE_WE_CHAT_CORP_ID)
+            .replaceAll("\\$secret", ENTERPRISE_WE_CHAT_SECRET);
 
-    private static final String enterpriseWeChatPushUrl = PropertyUtils.getString(Constants.ENTERPRISE_WECHAT_PUSH_URL);
+    private static final String ENTERPRISE_WE_CHAT_PUSH_URL = PropertyUtils.getString(Constants.ENTERPRISE_WECHAT_PUSH_URL);
 
-    private static final String enterpriseWeChatTeamSendMsg = PropertyUtils.getString(Constants.ENTERPRISE_WECHAT_TEAM_SEND_MSG);
+    private static final String ENTERPRISE_WE_CHAT_TEAM_SEND_MSG = PropertyUtils.getString(Constants.ENTERPRISE_WECHAT_TEAM_SEND_MSG);
 
-    private static final String enterpriseWeChatUserSendMsg = PropertyUtils.getString(Constants.ENTERPRISE_WECHAT_USER_SEND_MSG);
+    private static final String ENTERPRISE_WE_CHAT_USER_SEND_MSG = PropertyUtils.getString(Constants.ENTERPRISE_WECHAT_USER_SEND_MSG);
 
-    public static final String enterpriseWeChatAgentId = PropertyUtils.getString(Constants.ENTERPRISE_WECHAT_AGENT_ID);
+    public static final String ENTERPRISE_WE_CHAT_AGENT_ID = PropertyUtils.getString(Constants.ENTERPRISE_WECHAT_AGENT_ID);
 
-    public static final String enterpriseWeChatUsers = PropertyUtils.getString(Constants.ENTERPRISE_WECHAT_USERS);
+    public static final String ENTERPRISE_WE_CHAT_USERS = PropertyUtils.getString(Constants.ENTERPRISE_WECHAT_USERS);
 
     /**
      * get Enterprise WeChat is enable
@@ -87,7 +87,7 @@ public class EnterpriseWeChatUtils {
 
         CloseableHttpClient httpClient = HttpClients.createDefault();
         try {
-            HttpGet httpGet = new HttpGet(enterpriseWeChatTokenUrlReplace);
+            HttpGet httpGet = new HttpGet(ENTERPRISE_WE_CHAT_TOKEN_URL_REPLACE);
             CloseableHttpResponse response = httpClient.execute(httpGet);
             try {
                 HttpEntity entity = response.getEntity();
@@ -114,7 +114,7 @@ public class EnterpriseWeChatUtils {
      * @return Enterprise WeChat send message
      */
     public static String makeTeamSendMsg(String toParty, String agentId, String msg) {
-        return enterpriseWeChatTeamSendMsg.replaceAll("\\$toParty", toParty)
+        return ENTERPRISE_WE_CHAT_TEAM_SEND_MSG.replaceAll("\\$toParty", toParty)
                 .replaceAll("\\$agentId", agentId)
                 .replaceAll("\\$msg", msg);
     }
@@ -128,7 +128,7 @@ public class EnterpriseWeChatUtils {
      */
     public static String makeTeamSendMsg(Collection<String> toParty, String agentId, String msg) {
         String listParty = FuncUtils.mkString(toParty, "|");
-        return enterpriseWeChatTeamSendMsg.replaceAll("\\$toParty", listParty)
+        return ENTERPRISE_WE_CHAT_TEAM_SEND_MSG.replaceAll("\\$toParty", listParty)
                 .replaceAll("\\$agentId", agentId)
                 .replaceAll("\\$msg", msg);
     }
@@ -141,7 +141,7 @@ public class EnterpriseWeChatUtils {
      * @return Enterprise WeChat send message
      */
     public static String makeUserSendMsg(String toUser, String agentId, String msg) {
-        return enterpriseWeChatUserSendMsg.replaceAll("\\$toUser", toUser)
+        return ENTERPRISE_WE_CHAT_USER_SEND_MSG.replaceAll("\\$toUser", toUser)
                 .replaceAll("\\$agentId", agentId)
                 .replaceAll("\\$msg", msg);
     }
@@ -155,7 +155,7 @@ public class EnterpriseWeChatUtils {
      */
     public static String makeUserSendMsg(Collection<String> toUser, String agentId, String msg) {
         String listUser = FuncUtils.mkString(toUser, "|");
-        return enterpriseWeChatUserSendMsg.replaceAll("\\$toUser", listUser)
+        return ENTERPRISE_WE_CHAT_USER_SEND_MSG.replaceAll("\\$toUser", listUser)
                 .replaceAll("\\$agentId", agentId)
                 .replaceAll("\\$msg", msg);
     }
@@ -169,7 +169,7 @@ public class EnterpriseWeChatUtils {
      * @throws IOException the IOException
      */
     public static String sendEnterpriseWeChat(String charset, String data, String token) throws IOException {
-        String enterpriseWeChatPushUrlReplace = enterpriseWeChatPushUrl.replaceAll("\\$token", token);
+        String enterpriseWeChatPushUrlReplace = ENTERPRISE_WE_CHAT_PUSH_URL.replaceAll("\\$token", token);
 
         CloseableHttpClient httpClient = HttpClients.createDefault();
         try {
@@ -184,8 +184,8 @@ public class EnterpriseWeChatUtils {
             } finally {
                 response.close();
             }
-            logger.info("Enterprise WeChat send [{}], param:{}, resp:{}", 
-                enterpriseWeChatPushUrl, data, resp);
+            logger.info("Enterprise WeChat send [{}], param:{}, resp:{}",
+                    ENTERPRISE_WE_CHAT_PUSH_URL, data, resp);
             return resp;
         } finally {
             httpClient.close();

+ 4 - 4
dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/utils/EnterpriseWeChatUtilsTest.java

@@ -53,7 +53,7 @@ public class EnterpriseWeChatUtilsTest {
             String resp = EnterpriseWeChatUtils.sendEnterpriseWeChat("utf-8", msg, token);
 
             String errmsg = JSON.parseObject(resp).getString("errmsg");
-            Assert.assertEquals(errmsg, "ok");
+            Assert.assertEquals("ok",errmsg);
         } catch (IOException e) {
             e.printStackTrace();
         }
@@ -68,7 +68,7 @@ public class EnterpriseWeChatUtilsTest {
             String resp = EnterpriseWeChatUtils.sendEnterpriseWeChat("utf-8", msg, token);
 
             String errmsg = JSON.parseObject(resp).getString("errmsg");
-            Assert.assertEquals(errmsg, "ok");
+            Assert.assertEquals("ok",errmsg);
         } catch (IOException e) {
             e.printStackTrace();
         }
@@ -95,7 +95,7 @@ public class EnterpriseWeChatUtilsTest {
             String resp = EnterpriseWeChatUtils.sendEnterpriseWeChat("utf-8", msg, token);
 
             String errmsg = JSON.parseObject(resp).getString("errmsg");
-            Assert.assertEquals(errmsg, "ok");
+            Assert.assertEquals("ok",errmsg);
         } catch (IOException e) {
             e.printStackTrace();
         }
@@ -110,7 +110,7 @@ public class EnterpriseWeChatUtilsTest {
             String resp = EnterpriseWeChatUtils.sendEnterpriseWeChat("utf-8", msg, token);
 
             String errmsg = JSON.parseObject(resp).getString("errmsg");
-            Assert.assertEquals(errmsg, "ok");
+            Assert.assertEquals("ok",errmsg);
         } catch (IOException e) {
             e.printStackTrace();
         }

+ 1 - 1
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ExecutorController.java

@@ -149,7 +149,7 @@ public class ExecutorController extends BaseController {
     ) {
         try {
             logger.info("execute command, login user: {}, project:{}, process instance id:{}, execute type:{}",
-                    loginUser.getUserName(), projectName, processInstanceId, executeType.toString());
+                    loginUser.getUserName(), projectName, processInstanceId, executeType);
             Map<String, Object> result = execService.execute(loginUser, projectName, processInstanceId, executeType);
             return returnDataList(result);
         } catch (Exception e) {

+ 6 - 9
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ExecutorService.java

@@ -259,10 +259,7 @@ public class ExecutorService extends BaseService{
         // checkTenantExists();
         Tenant tenant = processService.getTenantForProcess(processDefinition.getTenantId(),
                 processDefinition.getUserId());
-        if(tenant == null){
-            return false;
-        }
-        return true;
+        return tenant != null;
     }
 
     /**
@@ -298,6 +295,7 @@ public class ExecutorService extends BaseService{
                 if (executionStatus.typeIsPause()|| executionStatus.typeIsCancel()) {
                     checkResult = true;
                 }
+                break;
             default:
                 break;
         }
@@ -369,7 +367,7 @@ public class ExecutorService extends BaseService{
      * @return check result code
      */
     public Map<String, Object> startCheckByProcessDefinedId(int processDefineId) {
-        Map<String, Object> result = new HashMap<String, Object>();
+        Map<String, Object> result = new HashMap<>();
 
         if (processDefineId == 0){
             logger.error("process definition id is null");
@@ -378,10 +376,9 @@ public class ExecutorService extends BaseService{
         List<Integer> ids = new ArrayList<>();
         processService.recurseFindSubProcessId(processDefineId, ids);
         Integer[] idArray = ids.toArray(new Integer[ids.size()]);
-        if (ids.size() > 0){
-            List<ProcessDefinition> processDefinitionList;
-            processDefinitionList = processDefinitionMapper.queryDefinitionListByIdList(idArray);
-            if (processDefinitionList != null && processDefinitionList.size() > 0){
+        if (!ids.isEmpty()){
+            List<ProcessDefinition> processDefinitionList = processDefinitionMapper.queryDefinitionListByIdList(idArray);
+            if (processDefinitionList != null){
                 for (ProcessDefinition processDefinition : processDefinitionList){
                     /**
                      * if there is no online process, exit directly

+ 2 - 2
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ErrorCommandMapperTest.java

@@ -67,7 +67,7 @@ public class ErrorCommandMapperTest {
         //update
         errorCommand.setUpdateTime(new Date());
         int update = errorCommandMapper.updateById(errorCommand);
-        Assert.assertEquals(update, 1);
+        Assert.assertEquals(1,update);
         errorCommandMapper.deleteById(errorCommand.getId());
     }
 
@@ -79,7 +79,7 @@ public class ErrorCommandMapperTest {
 
         ErrorCommand errorCommand = insertOne();
         int delete = errorCommandMapper.deleteById(errorCommand.getId());
-        Assert.assertEquals(delete, 1);
+        Assert.assertEquals(1,delete);
     }
 
     /**