Skip to content

Commit

Permalink
Criada biblioteca e migrada as design rules desenvolvidas para ela.
Browse files Browse the repository at this point in the history
  • Loading branch information
Anderson Bestteti Santos committed Nov 5, 2018
1 parent 913381f commit 48d5f7c
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 132 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,137 +33,14 @@ function checkFKColumns(index){
checkFKColumns(index);]]>
</script>
</scr>
<scr id="55EE956C-2003-7051-CCA6-C69D87B4D91A" name="FK without index" object="Table" engine="Oracle Nashorn" type="Error" var="table" library="" method="null" purpose="validation" >
<scr id="273541C2-9F46-A972-510C-146B117AE338" name="TJRS - Index with invalid name" object="Table" engine="Oracle Nashorn" type="Error" var="table" library="TJRS lib" method="indexWithInvalidName" purpose="validation" >
<script>
<![CDATA[// This Design rule aims to spot foreign key constraints which
// have no index to support it.
// Variable used to return custom message
var ruleMessage;
// Variables used to return the type of the ruler Error
// or Warning and red/blue color will be used for result
// if another custom type is returned (Problem in the rule below)
// then result is colored in yellow.
var errType;
function foreignKeyWithOuIndex(pTable) {
// Stores the list of table's keys,
// and then iterate over it.
indexes = pTable.getKeys();
// Stores the result of this custom
// design rule.
result = true;
// Helps to control message text composition.
newIndexCount = 0;
// The error message template.
ruleMessage = "There is no index for constraint(s):";
// Return an index reference for a given table and
// column set
function getIndex(tab,cols){
keys = tab.getKeys();
for (var i = 0; i < keys.length; i++) {
indexTmp = keys[i];
if(!(indexTmp.isPK() || indexTmp.isUnique()) && !indexTmp.isFK() && indexTmp.isIndexForColumns(cols)){
return indexTmp
}
}
return null;
}
for (var i = 0; i < indexes.length; i++) {
index = indexes[i];
if (index.isFK()){
columns = index.getColumns();
if (columns.length>0){
newIndex = getIndex(pTable,columns);
if (newIndex==null){
separator = (++newIndexCount > 1) ? "; " : " ";
ruleMessage += separator + index.getName();
errType = "Error";
result = false;
}
}
}
}
return result;
}
// invoke the function
foreignKeyWithOuIndex(table);]]>
<![CDATA[]]>
</script>
</scr>
<scr id="FAFC5BB0-8509-5709-123D-3C245059FAEA" name="Index with invalid name" object="Table" engine="Oracle Nashorn" type="Error" var="table" library="" method="null" purpose="validation" >
<scr id="4091D7C0-AD54-B648-024F-FDD7E7B7D401" name="TJRS - FK without index X" object="Table" engine="Oracle Nashorn" type="Error" var="table" library="TJRS lib" method="FKWithOutIndex" purpose="validation" >
<script>
<![CDATA[// This Design rule aims to spot indexes, which as not compliance
// with name formation rule.
// Variable used to return custom message
var ruleMessage;
// Variables used to return the type of the ruler Error
// or Warning and red/blue color will be used for result
// if another custom type is returned (Problem in the rule below)
// then result is colored in yellow.
var errType;
function pkWithInvalidName(pTable) {
// Stores the list of table's keys,
// and then iterate over it.
indexes = pTable.getKeys();
// Stores the result of this custom
// design rule.
result = true;
// Validade the index name, through a ReGex, based on the following
// document:
// https://www.tjrs.gov.br/sistemas/redmine/projects/dc34vcqwe4/wiki/Padr%C3%A3o_de_Nome_de_Objetos_de_Banco_de_Dados
// Parameter
// pIndexName: a index name
// Returns
// boolean
function isValidIndexName(pIndexName) {
// Regular expression to match an index name
// For more information, acess: https://regex101.com/r/aA8hI6/1
//
// Rationale: ^IDX\_.+\_\d{2}$
// ^ asserts position at start of a line
// IDX matches the characters IDX literally (case sensitive)
// \_ matches the character _ literally (case sensitive)
// .+ matches any character (except for line terminators)
// + Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed (greedy)
// \_ matches the character _ literally (case sensitive)
// \d{2} matches a digit (equal to [0-9])
// {2} Quantifier — Matches exactly 2 times
// $ asserts position at the end of a line
regexp = /^IDX\_.+\_\d{2}$/i;
return regexp.test(pIndexName);
}
for (var i = 0; i < indexes.length; i++) {
index = indexes[i];
if (!index.isPK()){
if (!isValidIndexName(index.getName())) {
ruleMessage = "The index " + index.getName();
ruleMessage += " has an invalid name. It must be IDX_"
ruleMessage += pTable.getName() + "_NN, where NN is a two digits number.";
errType = "Error";
return false;
}
}
}
return result;
}
// invoke the function
pkWithInvalidName(table);]]>
<![CDATA[]]>
</script>
</scr>
</custom__validation_scripts>
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,138 @@ return true
end]]>
</script>
</lib>
<lib id="79C2ED6C-9A18-434F-F0FE-838F87B60814" name="TJRS lib" engine="Oracle Nashorn" methods="versaoBiblioteca" >
<lib id="79C2ED6C-9A18-434F-F0FE-838F87B60814" name="TJRS lib" engine="Oracle Nashorn" methods="versaoBiblioteca,indexWithInvalidName,FKWithOutIndex" >
<script>
<![CDATA[var versao = "1.0.01.11.2018";
var titulo = "TJRS - Versão da biblioteca";
<![CDATA[// Variable used to return custom message
var ruleMessage;
// Variables used to return the type of the ruler Error
// or Warning and red/blue color will be used for result
// if another custom type is returned (Problem in the rule below)
// then result is colored in yellow.
var errType;
/*============================================================================*/
javax.swing.JOptionPane
function versaoBiblioteca() {
var versao = "1.0.01.11.2018";
var titulo = "TJRS - Versão da biblioteca";
javax.swing.JOptionPane
.showMessageDialog
(null,
versao,
titulo,
javax.swing.JOptionPane.INFORMATION_MESSAGE
); ]]>
);
}
/*============================================================================*/
// This Design rule aims to spot indexes, which as not compliance
// with name formation rule.
function indexWithInvalidName(table) {
// Validade the index name, through a ReGex, based on the following
// document:
// https://www.tjrs.gov.br/sistemas/redmine/projects/dc34vcqwe4/wiki/Padr%C3%A3o_de_Nome_de_Objetos_de_Banco_de_Dados
// Parameter
// pIndexName: a index name
// Returns
// boolean
function isValidIndexName(pIndexName) {
// Regular expression to match an index name
// For more information, acess: https://regex101.com/r/aA8hI6/1
//
// Rationale: ^IDX\_.+\_\d{2}$
// ^ asserts position at start of a line
// IDX matches the characters IDX literally (case sensitive)
// \_ matches the character _ literally (case sensitive)
// .+ matches any character (except for line terminators)
// + Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed (greedy)
// \_ matches the character _ literally (case sensitive)
// \d{2} matches a digit (equal to [0-9])
// {2} Quantifier — Matches exactly 2 times
// $ asserts position at the end of a line
regexp = /^IDX\_.+\_\d{2}$/i;
return regexp.test(pIndexName);
}
// Stores the result of this custom
// design rule.
result = true;
// Stores the list of table's keys,
// and then iterate over it.
indexes = table.getKeys();
for (var i = 0; i < indexes.length; i++) {
index = indexes[i];
if (!index.isPK()){
if (!isValidIndexName(index.getName())) {
ruleMessage = "The index " + index.getName();
ruleMessage += " has an invalid name. It must be IDX_"
ruleMessage += table.getName() + "_NN, where NN is a two digits number.";
errType = "Error";
return false;
}
}
}
return result;
}
/*============================================================================*/
// This Design rule aims to spot foreign key constraints which
// have no index to support it.
function FKWithOutIndex(table) {
// Stores the list of table's keys,
// and then iterate over it.
indexes = table.getKeys();
// Stores the result of this custom
// design rule.
result = true;
// Helps to control message text composition.
newIndexCount = 0;
// The error message template.
ruleMessage = "There is no index for constraint(s):";
// Return an index reference for a given table and
// column set
function getIndex(tab,cols){
keys = tab.getKeys();
for (var i = 0; i < keys.length; i++) {
indexTmp = keys[i];
if(!(indexTmp.isPK() || indexTmp.isUnique()) && !indexTmp.isFK() && indexTmp.isIndexForColumns(cols)){
return indexTmp
}
}
return null;
}
for (var i = 0; i < indexes.length; i++) {
index = indexes[i];
if (index.isFK()){
columns = index.getColumns();
if (columns.length>0){
newIndex = getIndex(table,columns);
if (newIndex==null){
separator = (++newIndexCount > 1) ? "; " : " ";
ruleMessage += separator + index.getName();
errType = "Error";
result = false;
}
}
}
}
return result;
}]]>
</script>
</lib>
</custom_libraries>

0 comments on commit 48d5f7c

Please sign in to comment.