-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from actiontech/feat/more_detail
Feat/more detail
- Loading branch information
Showing
19 changed files
with
747 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,59 @@ | ||
package com.actiontech.sqle.action; | ||
|
||
import com.actiontech.sqle.config.SQLEAuditResult; | ||
import com.actiontech.sqle.config.SQLESQLAnalysisResult; | ||
import com.actiontech.sqle.config.SQLESettings; | ||
import com.actiontech.sqle.from.SQLEAuditResultUI; | ||
import com.actiontech.sqle.util.HttpClientUtil; | ||
import com.actiontech.sqle.util.NotifyUtil; | ||
import com.intellij.openapi.actionSystem.AnActionEvent; | ||
import com.intellij.openapi.actionSystem.CommonDataKeys; | ||
import com.intellij.openapi.application.ApplicationManager; | ||
import com.intellij.openapi.ui.DialogBuilder; | ||
import com.intellij.openapi.actionSystem.LangDataKeys; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.openapi.wm.ToolWindow; | ||
import com.intellij.openapi.wm.ToolWindowAnchor; | ||
import com.intellij.openapi.wm.ToolWindowManager; | ||
import com.intellij.openapi.wm.ToolWindowType; | ||
import com.intellij.ui.content.Content; | ||
import com.intellij.ui.content.ContentFactory; | ||
|
||
import java.util.List; | ||
|
||
public class Audit { | ||
public static void Audit(AnActionEvent e, String sql, HttpClientUtil.AuditType type) { | ||
|
||
SQLESettings settings = SQLESettings.getInstance(); | ||
|
||
|
||
HttpClientUtil client = new HttpClientUtil(settings); | ||
try { | ||
SQLEAuditResult result = client.AuditSQL(sql, type); | ||
SQLEAuditResultUI ui = new SQLEAuditResultUI(result); | ||
|
||
ApplicationManager.getApplication().invokeLater(() -> { | ||
DialogBuilder builder = new DialogBuilder(); | ||
builder.setTitle("SQLE"); | ||
builder.centerPanel(ui.getRootPanel()); | ||
builder.show(); | ||
}); | ||
|
||
String projectName = settings.getProjectName(); | ||
String dataSourceName = settings.getDataSourceName(); | ||
String schemaName = settings.getSchemaName(); | ||
|
||
List<SQLESQLAnalysisResult> analysisResult = client.GetSQLAnalysis(sql, projectName, dataSourceName, schemaName); | ||
SQLEAuditResultUI ui = new SQLEAuditResultUI(result, analysisResult); | ||
|
||
Project project = e.getData(LangDataKeys.PROJECT); | ||
ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project); | ||
|
||
String title = String.format("审核结果(评分:%s)", result.getScore()); | ||
toolWindowManager.unregisterToolWindow(title); | ||
ToolWindow toolWindow = toolWindowManager.registerToolWindow(title, true, ToolWindowAnchor.BOTTOM); | ||
createToolWindow(toolWindow, ui); | ||
} catch (Exception exception) { | ||
String errMessage = NotifyUtil.getExceptionMessage(exception); | ||
NotifyUtil.showErrorMessageDialog("Audit SQL Failed", errMessage); | ||
} | ||
} | ||
|
||
public static void createToolWindow(ToolWindow toolWindow, SQLEAuditResultUI ui) { | ||
ContentFactory contentFactory = ContentFactory.SERVICE.getInstance(); | ||
Content content = contentFactory.createContent(ui.getRootPanel(), "", false); | ||
toolWindow.getContentManager().addContent(content); | ||
|
||
toolWindow.setType(ToolWindowType.DOCKED, null); | ||
toolWindow.setAvailable(true); | ||
toolWindow.show(null); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/actiontech/sqle/config/ExplainClassicResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.actiontech.sqle.config; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
import lombok.Data; | ||
import lombok.ToString; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Data | ||
@ToString | ||
public class ExplainClassicResult { | ||
@SerializedName("rows") | ||
private List<Map<String, String>> rows; | ||
|
||
@SerializedName("head") | ||
private List<TableMetaItemHeadResV1> head; | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/actiontech/sqle/config/SQLEDataSourceNameListResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.actiontech.sqle.config; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
import lombok.Data; | ||
import lombok.ToString; | ||
|
||
@Data | ||
@ToString | ||
public class SQLEDataSourceNameListResult { | ||
@SerializedName("instance_name") | ||
private String instanceName; | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/actiontech/sqle/config/SQLEProjectNameListResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.actiontech.sqle.config; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
import lombok.Data; | ||
import lombok.ToString; | ||
|
||
@Data | ||
@ToString | ||
public class SQLEProjectNameListResult { | ||
@SerializedName("name") | ||
private String Name; | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/actiontech/sqle/config/SQLESQLAnalysisResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.actiontech.sqle.config; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
import lombok.Data; | ||
import lombok.ToString; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
@ToString | ||
public class SQLESQLAnalysisResult { | ||
@SerializedName("sql_explain") | ||
private SQLExplain sqlExplain; | ||
|
||
@SerializedName("table_meta") | ||
private List<TableMeta> tableMeta; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.actiontech.sqle.config; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
import lombok.Data; | ||
import lombok.ToString; | ||
|
||
@Data | ||
@ToString | ||
public class SQLExplain { | ||
@SerializedName("sql") | ||
private String SQL; | ||
|
||
@SerializedName("classic_result") | ||
private ExplainClassicResult classicResult; | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/actiontech/sqle/config/TableColumns.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.actiontech.sqle.config; | ||
|
||
|
||
import com.google.gson.annotations.SerializedName; | ||
import lombok.Data; | ||
import lombok.ToString; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Data | ||
@ToString | ||
public class TableColumns { | ||
@SerializedName("rows") | ||
private List<Map<String, String>> rows; | ||
|
||
@SerializedName("head") | ||
private List<TableMetaItemHeadResV1> head; | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/actiontech/sqle/config/TableIndexes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.actiontech.sqle.config; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
import lombok.Data; | ||
import lombok.ToString; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Data | ||
@ToString | ||
public class TableIndexes { | ||
@SerializedName("rows") | ||
private List<Map<String, String>> rows; | ||
|
||
@SerializedName("head") | ||
private List<TableMetaItemHeadResV1> head; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.actiontech.sqle.config; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
import lombok.Data; | ||
import lombok.ToString; | ||
|
||
@Data | ||
@ToString | ||
public class TableMeta { | ||
@SerializedName("name") | ||
private String Name; | ||
|
||
@SerializedName("schema") | ||
private String Schema; | ||
|
||
@SerializedName("columns") | ||
private TableColumns Columns; | ||
|
||
@SerializedName("indexes") | ||
private TableIndexes Indexes; | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/actiontech/sqle/config/TableMetaItemHeadResV1.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.actiontech.sqle.config; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
import lombok.Data; | ||
import lombok.ToString; | ||
|
||
@Data | ||
@ToString | ||
public class TableMetaItemHeadResV1 { | ||
@SerializedName("field_name") | ||
private String fieldName; | ||
} |
Oops, something went wrong.