Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/main/java/com/inovia/magnifier/reports/Report.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,10 @@ public int compare(RuleReport r1, RuleReport r2) {
for(String column : rr.getColumns()) {
html = html + "<th>" + column + "</th>";
}

if(rr.getRule().hasSuggestions()) {
html = html
+ " <th>suggestions</th>";
}
html = html
+ " </tr>"
+ " </thead>";
Expand All @@ -182,6 +185,12 @@ public int compare(RuleReport r1, RuleReport r2) {
html = html
+ "<td>" + data + "</td>";
}

if(rr.getRule().hasSuggestions()) {
html = html
+ " <td>" + (e.getDetails() != null ? e.getDetails() : "") + "</td>";
}

html = html
+ "</tr>";
}
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/com/inovia/magnifier/reports/ReportEntry.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
package com.inovia.magnifier.reports;

import com.inovia.magnifier.rule.RuleResult;

/**
* it is the result of the execution of a rule on a single database entity.
* for example: performing rule "TableHasPrimaryKey" on table "User" is summarized in a report entry
*/
public class ReportEntry {
private String[] dataToDisplay;
private Boolean isSuccess;
private String details;

public ReportEntry(String[] dataToDisplay, Boolean isSuccess) {
public ReportEntry(String[] dataToDisplay, RuleResult result) {
this.dataToDisplay = dataToDisplay.clone();
this.isSuccess = isSuccess;
this.isSuccess = result.isSuccess();
this.details = result.getDetails();
}

public Boolean isSuccess() {
return isSuccess;
return this.isSuccess;
}

public String getDetails() {
return this.details;
}

public String[] getDataToDisplay() {
Expand Down
19 changes: 11 additions & 8 deletions src/main/java/com/inovia/magnifier/rule/ForeignKeyName.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,31 @@ public class ForeignKeyName implements Rule {

public ForeignKeyName() { }

public Boolean hasSuggestions() { return true; }

public RuleReport run(Database database) {
RuleReport ruleReport = new RuleReport(this, SUGGESTION, DEBT);

for(Table t : database.getTables()) {
for(ForeignKey fk : t.getForeignKeys()) {
Boolean isSuccess = assertion(fk);
RuleResult result = assertion(fk);
String[] dataToDisplay = {t.getSchemaName(), t.getName(), fk.getColumnName(), fk.getForeignSchemaName(), fk.getForeignTableName(), fk.getForeignColumnName()};
ruleReport.addEntry(new ReportEntry(dataToDisplay, isSuccess));
ruleReport.addEntry(new ReportEntry(dataToDisplay, result));
}
}

return ruleReport;
}

private Boolean assertion(ForeignKey fk) {
if(fk.getColumnName().equals(fk.getForeignTableName() + "_" + fk.getForeignColumnName())) {
return true;
} else if(fk.getColumnName().endsWith("_" + fk.getForeignTableName() + "_" + fk.getForeignColumnName())) {
return true;
private RuleResult assertion(ForeignKey fk) {
if(fk.getColumnName().equals(fk.getForeignTableName() + "_" + fk.getForeignColumnName())
|| fk.getColumnName().endsWith("_" + fk.getForeignTableName() + "_" + fk.getForeignColumnName())) {
return new RuleResult(true, "");
}

String message = fk.getForeignTableName() + "_" + fk.getForeignColumnName();

return false;
return new RuleResult(false, message);
}

public String[] getRuleReportFormat() {
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/com/inovia/magnifier/rule/FunctionHasComment.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,31 @@ public class FunctionHasComment implements Rule {
public static final String[] FORMAT = {"schema", "function"};

public FunctionHasComment() { }

public Boolean hasSuggestions() { return false; }

public RuleReport run(Database database) {
RuleReport ruleReport = new RuleReport(this, SUGGESTION, DEBT);

for(Function f : database.getFunctions()) {
Boolean isSuccess = assertion(f, database.getComments());
RuleResult result = assertion(f, database.getComments());
String[] dataToDisplay = {f.getSchemaName(), f.getName()};
ruleReport.addEntry(new ReportEntry(dataToDisplay, isSuccess));
ruleReport.addEntry(new ReportEntry(dataToDisplay, result));
}

return ruleReport;
}

private Boolean assertion(Function function, List<Comment> comments) {
private RuleResult assertion(Function function, List<Comment> comments) {
for(Comment c : comments) {
if(c.getEntityType().equals(Comment.FUNCTION_TYPE)
&& c.getSchemaName().equals(function.getSchemaName())
&& c.getEntityName().equals(function.getName())) {
return true;
return new RuleResult(true, null);
}
}

return false;
return new RuleResult(false, null);
}

public String[] getRuleReportFormat() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,27 @@ public class FunctionParameterName implements Rule {

public FunctionParameterName() { }

public Boolean hasSuggestions() { return false; }

public RuleReport run(Database database) {
RuleReport ruleReport = new RuleReport(this, SUGGESTION, DEBT);

for(Function f : database.getFunctions()) {
for(FunctionParameter p : f.getParameters()) {
Boolean isSuccess = assertion(p);
RuleResult result = assertion(p);
String[] dataToDisplay = {f.getSchemaName(), f.getName(), p.getName() == null ? "<noname>" : p.getName(), p.getMode()};
ruleReport.addEntry(new ReportEntry(dataToDisplay, isSuccess));
ruleReport.addEntry(new ReportEntry(dataToDisplay, result));
}
}

return ruleReport;
}

private Boolean assertion(FunctionParameter p) {
return p.getName() != null
&& !p.getName().isEmpty()
&& p.getName().endsWith("_" + p.getMode().toLowerCase());
private RuleResult assertion(FunctionParameter p) {
Boolean isSuccess = p.getName() != null
&& !p.getName().isEmpty()
&& p.getName().endsWith("_" + p.getMode().toLowerCase());
return new RuleResult(isSuccess, null);
}

public String[] getRuleReportFormat() {
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/com/inovia/magnifier/rule/IndexName.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,29 @@ public class IndexName implements Rule {

public IndexName() { }

public Boolean hasSuggestions() { return false; }

public RuleReport run(Database database) {
RuleReport ruleReport = new RuleReport(this, SUGGESTION, DEBT);

for(Index i : database.getIndexes()) {
Boolean isSuccess = assertion(i);
RuleResult result = assertion(i);
String[] dataToDisplay = {i.getSchemaName(), i.getTableName(), i.getName()};
ruleReport.addEntry(new ReportEntry(dataToDisplay, isSuccess));
ruleReport.addEntry(new ReportEntry(dataToDisplay, result));
}

return ruleReport;
}

private Boolean assertion(Index i) {
private RuleResult assertion(Index i) {
if(i.getName().endsWith("_idx")) {
// Inovia convention
return true;
return new RuleResult(true, "");
} else if(i.getName().endsWith("_pkey") || i.getName().endsWith("_key")) {
// Postgres Convention
return true;
return new RuleResult(true, "");
}
return false;
return new RuleResult(false, "");
}

public String[] getRuleReportFormat() {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/inovia/magnifier/rule/Rule.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public interface Rule {
* @return a report about the execution of the rule on the database
*/
public RuleReport run(Database database);
public Boolean hasSuggestions();
public String[] getRuleReportFormat();
public String getName();
}
19 changes: 19 additions & 0 deletions src/main/java/com/inovia/magnifier/rule/RuleResult.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.inovia.magnifier.rule;

public class RuleResult {
private Boolean isSuccess;
private String details;

public RuleResult(Boolean isSuccess, String details) {
this.isSuccess = isSuccess;
this.details = details;
}

public Boolean isSuccess() {
return this.isSuccess;
}

public String getDetails() {
return this.details;
}
}
12 changes: 7 additions & 5 deletions src/main/java/com/inovia/magnifier/rule/TableHasComment.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,28 @@ public class TableHasComment implements Rule {

public TableHasComment() { }

public Boolean hasSuggestions() { return false; }

public RuleReport run(Database database) {
RuleReport ruleReport = new RuleReport(this, SUGGESTION, DEBT);

for(Table t : database.getTables()) {
Boolean isSuccess = assertion(t, database.getComments());
RuleResult result = assertion(t, database.getComments());
String[] dataToDisplay = {t.getSchemaName(), t.getName()};
ruleReport.addEntry(new ReportEntry(dataToDisplay, isSuccess));
ruleReport.addEntry(new ReportEntry(dataToDisplay, result));
}

return ruleReport;
}

private Boolean assertion(Table table, List<Comment> comments) {
private RuleResult assertion(Table table, List<Comment> comments) {
for(Comment c : comments) {
if(c.getEntityType().equals("table") && c.getSchemaName().equals(table.getSchemaName()) && c.getEntityName().equals(table.getName())) {
return true;
return new RuleResult(true, null);
}
}

return false;
return new RuleResult(false, null);
}

public String[] getRuleReportFormat() {
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/com/inovia/magnifier/rule/TableHasPrimaryKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,22 @@ public class TableHasPrimaryKey implements Rule {

public TableHasPrimaryKey() { }

public Boolean hasSuggestions() { return false; }

public RuleReport run(Database database) {
RuleReport ruleReport = new RuleReport(this, SUGGESTION, DEBT);

for(Table t : database.getTables()) {
Boolean isSuccess = assertion(t);
RuleResult result = assertion(t);
String[] dataToDisplay = {t.getSchemaName(), t.getName()};
ruleReport.addEntry(new ReportEntry(dataToDisplay, isSuccess));
ruleReport.addEntry(new ReportEntry(dataToDisplay, result));
}

return ruleReport;
}

private Boolean assertion(Table table) {
return table.hasPrimaryKey();
private RuleResult assertion(Table table) {
return new RuleResult(table.hasPrimaryKey(), null);
}

public String[] getRuleReportFormat() {
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/com/inovia/magnifier/rule/TriggerHasComment.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,28 @@ public class TriggerHasComment implements Rule {

public TriggerHasComment() { }

public Boolean hasSuggestions() { return false; }

public RuleReport run(Database database) {
RuleReport ruleReport = new RuleReport(this, SUGGESTION, DEBT);

for(Trigger t : database.getTriggers()) {
Boolean isSuccess = assertion(t, database.getComments());
RuleResult result = assertion(t, database.getComments());
String[] dataToDisplay = {t.getSchemaName(), t.getName()};
ruleReport.addEntry(new ReportEntry(dataToDisplay, isSuccess));
ruleReport.addEntry(new ReportEntry(dataToDisplay, result));
}

return ruleReport;
}

private Boolean assertion(Trigger trigger, List<Comment> comments) {
private RuleResult assertion(Trigger trigger, List<Comment> comments) {
for(Comment c : comments) {
if(c.getEntityType().equals("trigger") && c.getSchemaName().equals(trigger.getSchemaName()) && c.getEntityName().equals(trigger.getName())) {
return true;
return new RuleResult(true, null);
}
}

return false;
return new RuleResult(false, null);
}

public String[] getRuleReportFormat() {
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/com/inovia/magnifier/rule/TriggerName.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,24 @@ public class TriggerName implements Rule {

public TriggerName() { }

public Boolean hasSuggestions() { return false; }

public RuleReport run(Database database) {
RuleReport ruleReport = new RuleReport(this, SUGGESTION, DEBT);

for(Trigger t : database.getTriggers()) {
Boolean isSuccess = assertion(t);
RuleResult result = assertion(t);
String[] dataToDisplay = {t.getSchemaName(), t.getTableName(), t.getName(), t.getTiming(), t.getAction()};
ruleReport.addEntry(new ReportEntry(dataToDisplay, isSuccess));
ruleReport.addEntry(new ReportEntry(dataToDisplay, result));
}

return ruleReport;
}

private Boolean assertion(Trigger t) {
return t.getName().equalsIgnoreCase("on_" + t.getTiming() + "_" + t.getAction() + "_" + t.getTableName());
private RuleResult assertion(Trigger t) {
Boolean isSuccess = t.getName().equalsIgnoreCase("on_" + t.getTiming() + "_" + t.getAction() + "_" + t.getTableName());

return new RuleResult(isSuccess, null);
}

public String[] getRuleReportFormat() {
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/com/inovia/magnifier/rule/ViewHasComment.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,28 @@ public class ViewHasComment implements Rule {

public ViewHasComment() { }

public Boolean hasSuggestions() { return false; }

public RuleReport run(Database database) {
RuleReport ruleReport = new RuleReport(this, SUGGESTION, DEBT);

for(View v : database.getViews()) {
Boolean isSuccess = assertion(v, database.getComments());
RuleResult result = assertion(v, database.getComments());
String[] dataToDisplay = {v.getSchemaName(), v.getName()};
ruleReport.addEntry(new ReportEntry(dataToDisplay, isSuccess));
ruleReport.addEntry(new ReportEntry(dataToDisplay, result));
}

return ruleReport;
}

private Boolean assertion(View view, List<Comment> comments) {
private RuleResult assertion(View view, List<Comment> comments) {
for(Comment c : comments) {
if(c.getSchemaName().equals(view.getSchemaName()) && c.getEntityName().equals(view.getName())) {
return true;
return new RuleResult(true, null);
}
}

return false;
return new RuleResult(false, null);
}

public String[] getRuleReportFormat() {
Expand Down
Loading