mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 05:01:07 +00:00
Fix the check for primary key of integer (to work for null primary keys, and to be inside the try-catch); tests on that
This commit is contained in:
@ -91,20 +91,6 @@ public class DMLAuditAction extends AbstractQActionFunction<DMLAuditInput, DMLAu
|
|||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
DMLType dmlType = getDMLType(tableActionInput);
|
DMLType dmlType = getDMLType(tableActionInput);
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// currently, the table's primary key must be integer... so, log (once) and return early if not that //
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
QFieldMetaData field = table.getField(table.getPrimaryKeyField());
|
|
||||||
if(!QFieldType.INTEGER.equals(field.getType()))
|
|
||||||
{
|
|
||||||
if(!loggedUnauditableTableNames.contains(table.getName()))
|
|
||||||
{
|
|
||||||
LOG.info("Cannot audit table without integer as its primary key", logPair("tableName", table.getName()));
|
|
||||||
loggedUnauditableTableNames.add(table.getName());
|
|
||||||
}
|
|
||||||
return (output);
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
List<QRecord> recordList = CollectionUtils.nonNullList(input.getRecordList()).stream()
|
List<QRecord> recordList = CollectionUtils.nonNullList(input.getRecordList()).stream()
|
||||||
@ -119,6 +105,21 @@ public class DMLAuditAction extends AbstractQActionFunction<DMLAuditInput, DMLAu
|
|||||||
return (output);
|
return (output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// currently, the table's primary key must be integer... so, log (once) and return early if not that //
|
||||||
|
// (or, if no primary key!) //
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
QFieldMetaData field = table.getFields().get(table.getPrimaryKeyField());
|
||||||
|
if(field == null || !QFieldType.INTEGER.equals(field.getType()))
|
||||||
|
{
|
||||||
|
if(!loggedUnauditableTableNames.contains(table.getName()))
|
||||||
|
{
|
||||||
|
LOG.info("Cannot audit table without integer as its primary key", logPair("tableName", table.getName()));
|
||||||
|
loggedUnauditableTableNames.add(table.getName());
|
||||||
|
}
|
||||||
|
return (output);
|
||||||
|
}
|
||||||
|
|
||||||
String contextSuffix = getContentSuffix(input);
|
String contextSuffix = getContentSuffix(input);
|
||||||
|
|
||||||
AuditInput auditInput = new AuditInput();
|
AuditInput auditInput = new AuditInput();
|
||||||
|
@ -400,4 +400,49 @@ class DMLAuditActionTest extends BaseTest
|
|||||||
QContext.popAction();
|
QContext.popAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
@Test
|
||||||
|
void testTableWithoutIntegerPrimaryKey() throws QException
|
||||||
|
{
|
||||||
|
QInstance qInstance = QContext.getQInstance();
|
||||||
|
new AuditsMetaDataProvider().defineAll(qInstance, TestUtils.MEMORY_BACKEND_NAME, null);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// we used to throw if table had no primary key. first, assert that we do not throw in that case //
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
QContext.getQInstance().addTable(
|
||||||
|
new QTableMetaData()
|
||||||
|
.withName("nullPkey")
|
||||||
|
.withField(new QFieldMetaData("foo", QFieldType.STRING))
|
||||||
|
.withAuditRules(new QAuditRules().withAuditLevel(AuditLevel.FIELD)));
|
||||||
|
|
||||||
|
new DMLAuditAction().execute(new DMLAuditInput()
|
||||||
|
.withTableActionInput(new InsertInput("nullPkey"))
|
||||||
|
.withRecordList(List.of(new QRecord())));
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// next, make sure we don't throw (and don't record anything) if table's pkey isn't integer //
|
||||||
|
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
QContext.getQInstance().addTable(
|
||||||
|
new QTableMetaData()
|
||||||
|
.withName("stringPkey")
|
||||||
|
.withField(new QFieldMetaData("idString", QFieldType.STRING))
|
||||||
|
.withPrimaryKeyField("idString")
|
||||||
|
.withAuditRules(new QAuditRules().withAuditLevel(AuditLevel.FIELD)));
|
||||||
|
|
||||||
|
new DMLAuditAction().execute(new DMLAuditInput()
|
||||||
|
.withTableActionInput(new InsertInput("stringPkey"))
|
||||||
|
.withRecordList(List.of(new QRecord())));
|
||||||
|
|
||||||
|
//////////////////////////////////
|
||||||
|
// make sure no audits happened //
|
||||||
|
//////////////////////////////////
|
||||||
|
List<QRecord> auditList = TestUtils.queryTable("audit");
|
||||||
|
assertTrue(auditList.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user