Skip to content

Commit

Permalink
Feature - APP+API + Mejora - EDA - Permitir gestión de múltiples rela…
Browse files Browse the repository at this point in the history
…ciones entre tablas SDA#53 (#140)
  • Loading branch information
jortilles authored May 29, 2024
1 parent 8770b8a commit 447aad5
Show file tree
Hide file tree
Showing 56 changed files with 4,134 additions and 1,751 deletions.
54 changes: 22 additions & 32 deletions eda/eda_api/lib/module/dashboard/dashboard.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -657,11 +657,10 @@ export class DashboardController {
uniquesForbiddenTables = [];
}

if( req.user._id == '135792467811111111111112'){
console.log('ANONYMOUS USER QUERY....NO PERMISSIONS APPLY HERE.....');
uniquesForbiddenTables = [];

}
/* SDA CUSTOM*/ if( req.user._id == '135792467811111111111112'){
/* SDA CUSTOM*/ console.log('ANONYMOUS USER QUERY....NO PERMISSIONS APPLY HERE.....');
/* SDA CUSTOM*/ uniquesForbiddenTables = [];
/* SDA CUSTOM*/ }



Expand Down Expand Up @@ -713,13 +712,16 @@ export class DashboardController {

/** por compatibilidad. Si no tengo el tipo de columna en el filtro lo añado */
if(myQuery.filters){
myQuery.filters.forEach(f => {
if(!f.filter_column_type){
for (const filter of myQuery.filters) {
if (!filter.filter_column_type) {
const filterTable = dataModelObject.ds.model.tables.find((t) => t.table_name == filter.filter_table.split('.')[0]);

f.filter_column_type = dataModelObject.ds.model.tables.filter( t=> t.table_name == f.filter_table)[0]
.columns.filter(c=> c.column_name == f.filter_column )[0].column_type;
if (filterTable) {
const filterColumn = filterTable.columns.find((c) => c.column_name == filter.filter_column);
filter.filter_column_type = filterColumn?.column_type || 'text';
}
}
});
}
}

const query = await connection.getQueryBuilded(
Expand Down Expand Up @@ -860,9 +862,8 @@ export class DashboardController {
*/
static async execSqlQuery(req: Request, res: Response, next: NextFunction) {
try {
const connection = await ManagerConnectionService.getConnection(
req.body.model_id
)
console.log('execSqlQuery');
const connection = await ManagerConnectionService.getConnection(req.body.model_id);
const dataModel = await connection.getDataSource(req.body.model_id)

/**Security check */
Expand All @@ -889,11 +890,11 @@ export class DashboardController {
// el admin ve todo
uniquesForbiddenTables = [];
}
if( req.user._id == '135792467811111111111112'){
console.log('ANONYMOUS USER QUERY....NO PERMISSIONS APPLY HERE.....');
uniquesForbiddenTables = [];
/* SDA CUSTOM */ if( req.user._id == '135792467811111111111112'){
/* SDA CUSTOM */ console.log('ANONYMOUS USER QUERY....NO PERMISSIONS APPLY HERE.....');
/* SDA CUSTOM */ uniquesForbiddenTables = [];
/* SDA CUSTOM */ }

}
let notAllowedQuery = false
uniquesForbiddenTables.forEach(table => {
if (req.body.query.SQLexpression.indexOf(table) >= 0) {
Expand All @@ -912,23 +913,12 @@ export class DashboardController {

/**If query is in format select foo from a, b queryBuilder returns null */
if (!query) {
return next(
new HttpException(
500,
'Queries in format "select x from A, B" are not suported'
)
)
return next(new HttpException(500,'Queries in format "select x from A, B" are not suported'));
}

console.log(
'\x1b[32m%s\x1b[0m',
`QUERY for user ${req.user.name}, with ID: ${req.user._id
}, at: ${formatDate(new Date())} `
)
console.log('\x1b[32m%s\x1b[0m', `QUERY for user ${req.user.name}, with ID: ${req.user._id}, at: ${formatDate(new Date())} `);
console.log(query)
console.log(
'\n-------------------------------------------------------------------------------\n'
)
console.log('\n-------------------------------------------------------------------------------\n');

/**cached query */
let cacheEnabled =
Expand Down Expand Up @@ -1042,7 +1032,7 @@ export class DashboardController {
if (
isNaN(val) || val.toString().indexOf('-') >= 0 || val.toString().indexOf('/') >= 0 ||
val.toString().indexOf('|') >= 0 || val.toString().indexOf(':') >= 0 || val.toString().indexOf('T') >= 0 ||
val.toString().indexOf('Z') >= 0 || val.toString().indexOf('Z') >= 0) {
val.toString().indexOf('Z') >= 0 || val.toString().indexOf('Z') >= 0 || val.toString().replace(/['"]+/g, '').length == 0 ) {
isNotNumeric = true;
}
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion eda/eda_api/lib/module/datasource/datasource.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export class DataSourceController {
const names = JSON.parse(JSON.stringify(ds));
for (let i = 0, n = names.length; i < n; i += 1) {
const e = names[i];
output.push({ _id: e._id, model_name: e.ds.metadata.model_name });
output.push({ _id: e._id, model_name: e.ds.metadata.model_name });
}
output.sort((a,b) => (upperCase(a.model_name) > upperCase(b.model_name)) ? 1 :
((upperCase(b.model_name) > upperCase(a.model_name)) ? -1 : 0));
Expand Down
23 changes: 14 additions & 9 deletions eda/eda_api/lib/module/updateModel/updateModel.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,40 +62,40 @@ export class updateModel {
let columns = rows;
// seleccionamos Relaciones
await connection.query(`
SELECT distinct source_table, source_column, target_table, target_column
SELECT distinct source_table, source_column, target_table, target_column, label , 0 as direccion
FROM sda_def_relationships
union
SELECT target_table as source_table, target_column as source_column ,
source_table as target_table , source_column as target_column
source_table as target_table , source_column as target_column, label as label , 1 as direccion
FROM sda_def_relationships
union
SELECT source_table , source_column ,
master_table , master_id as target_column
master_table , master_id as target_column, 'xx-bridge|xx-bridge' , 2 as direccion
FROM sda_def_enumerations
where bridge_table is null or bridge_table = ''
union
SELECT master_table , master_id ,
source_table , source_column
source_table , source_column , 'xx-bridge|xx-bridge' , 2 as direccion
FROM sda_def_enumerations
where bridge_table is null or bridge_table = ''
union
SELECT source_table , source_bridge as source_column ,
bridge_table , source_bridge
bridge_table , source_bridge, 'xx-bridge|xx-bridge' , 2 as direccion
FROM sda_def_enumerations
where bridge_table != ''
union
SELECT bridge_table , source_bridge,
source_table , source_bridge as source_column
source_table , source_bridge as source_column , 'xx-bridge|xx-bridge' , 2 as direccion
FROM sda_def_enumerations
where bridge_table != ''
union
SELECT bridge_table , target_bridge,
master_table , master_id
master_table , master_id , 'xx-bridge|xx-bridge' , 2 as direccion
FROM sda_def_enumerations
where bridge_table != ''
union
SELECT master_table , master_id,
bridge_table , target_bridge
bridge_table , target_bridge , 'xx-bridge|xx-bridge' , 2 as direccion
FROM sda_def_enumerations
where bridge_table != '' `).then(async rows => {
let relations = rows;
Expand Down Expand Up @@ -509,7 +509,12 @@ export class updateModel {
"source_column": [relations[i].source_column],
"target_table": relations[i].target_table,
"target_column": [relations[i].target_column],
"visible": true
"visible": true,
"bridge": relations[i].label=="xx-bridge|xx-bridge"?true:false,
"display_name": {
"default": relations[i].direccion === 0 ? relations[i].label.split('|')[0] : relations[i].label.split('|')[1] ,
"localized": []
},
}
destRelations.push(rr);

Expand Down
Loading

0 comments on commit 447aad5

Please sign in to comment.