Skip to content

Commit

Permalink
DATAAPI-31 new annotation to enable deleted change queue detail
Browse files Browse the repository at this point in the history
  • Loading branch information
pixl8-brayden committed Sep 5, 2024
1 parent a18bc25 commit e031e00
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Additional _optional_ annotation options at the _object_ level are:
* `dataApiCategory`: For the HTML documentation. Allows sub-groups of entities. Especially useful for large APIs.
* `dataApiQueueEnabled`: Whether or not the change queue is enabled for this object
* `dataApiQueue`: Specific queue name for this object
* `dataApiQueueDeleteDetail`: Whether or not the deleted record detail is available in the change queue data for this object
* `dataApiSortOrder`: Sort order for paginated results. Default is date last modified ascending.
* `dataApiSavedFilters`: Comma-separated list of saved filters to apply to all requests to this object (e.g. only return active records)
* `dataApiIgnoreDefaultFilters`: Comma-separated list of ignore default filters to apply to all requests to this object
Expand Down
17 changes: 17 additions & 0 deletions interceptors/DataApiInterceptors.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ component extends="coldbox.system.Interceptor" {
property name="dataApiService" inject="delayedInjector:dataApiService";
property name="dataApiQueueService" inject="delayedInjector:dataApiQueueService";
property name="dataApiConfigurationService" inject="delayedInjector:dataApiConfigurationService";
property name="presideObjectService" inject="delayedInjector:presideObjectService";
property name="interceptorService" inject="coldbox:InterceptorService";

variables._applicationLoaded = false;
Expand Down Expand Up @@ -116,6 +117,22 @@ component extends="coldbox.system.Interceptor" {

if( isEmptyString( interceptData.id ?: "" ) ){
interceptData.deletedIds = dataApiQueueService.getDeletedRecordIds( argumentCollection = interceptData );

if ( ArrayLen( interceptData.deletedIds ) && dataApiConfigurationService.isObjectQueueDeleteDetailEnabled( objectName=interceptData.objectName ) ) {
var deletedQuery = presideObjectService.selectData(
objectName = interceptData.objectName
, filter = { id=interceptData.deletedIds }
, selectFields = dataApiConfigurationService.getSelectFields( entity=dataApiConfigurationService.getObjectEntity( objectName=interceptData.objectName ) )
);

if ( deletedQuery.recordcount ) {
interceptData.deletedRecords = {};

for ( var row in deletedQuery ) {
interceptData.deletedRecords[ row.id ] = row;
}
}
}
}
}

Expand Down
15 changes: 15 additions & 0 deletions services/DataApiConfigurationService.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,21 @@ component {
} );
}

public boolean function isObjectQueueDeleteDetailEnabled( required string objectName, string namespace=_getDataApiNamespace() ) {
var args = arguments;
var cacheKey = "isObjectQueueDeleteDetailEnabled-#arguments.objectName#-#arguments.namespace#";

return _simpleLocalCache( cacheKey, function(){
if ( !isObjectQueueEnabled( args.objectName, args.namespace ) ) {
return false;
}

var queueDeleteDetailEnabled = $getPresideObjectService().getObjectAttribute( args.objectName, "dataApiQueueDeleteDetail#_getNamespaceWithSeparator( args.namespace )#" );

return _isTrue( queueDeleteDetailEnabled );
} );
}

public struct function getDefaultQueueConfig() {
return {
name = ""
Expand Down
17 changes: 12 additions & 5 deletions services/DataApiQueueService.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ component {
, recordId = record.record_id
, queueId = record.id
, timestamp = _unixTimestamp( record.dateCreated )
, record = IsJson( record.data ) ? DeserializeJson( record.data ) : {}
} );
break;
case "update":
Expand Down Expand Up @@ -243,10 +244,11 @@ component {
}

public void function queueDelete(
string objectName = ""
, string id = ""
, any filter = {}
, array deletedIds = []
string objectName = ""
, string id = ""
, any filter = {}
, array deletedIds = []
, struct deletedRecords = {}
) {
if( !Len( filter.id ?: "" ) && !Len( filter[ "#objectName#.id" ] ?: "" ) && arrayLen( deletedIds ) ) {
filter = { id = deletedIds };
Expand All @@ -257,7 +259,11 @@ component {
value = ListToArray( value );
}
for( var id in value ) {
queueDelete( arguments.objectName, id );
queueDelete(
objectName = arguments.objectName
, id = id
, deletedRecords = arguments.deletedRecords
);
}
return;
}
Expand All @@ -283,6 +289,7 @@ component {
, namespace = namespace
, queue_name = queueSettings.name
, operation = "delete"
, data = StructKeyExists( arguments.deletedRecords, arguments.id ) ? SerializeJSON( arguments.deletedRecords[ arguments.id ] ) : ""
} );
}

Expand Down

0 comments on commit e031e00

Please sign in to comment.