Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
lmajano committed Nov 10, 2022
2 parents f85a086 + 46c1c5e commit 5c8f4d9
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 81 deletions.
55 changes: 29 additions & 26 deletions ModuleConfig.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,64 @@
component {

// Module Properties
this.title = "mementifier";
this.author = "Ortus Solutions, Corp";
this.description = "Assist with extracting memento from objects";
this.title = "mementifier";
this.author = "Ortus Solutions, Corp";
this.description = "Assist with extracting state from objects";
// Model Namespace
this.modelNamespace = "mementifier";
this.modelNamespace = "mementifier";
// CF Mapping
this.cfmapping = "mementifier";
this.cfmapping = "mementifier";
// Auto-map models
this.autoMapModels = true;
// Module Dependencies
this.dependencies = [];
this.autoMapModels = true;

/**
* Configure
*/
function configure(){

// module settings - stored in modules.name.settings
settings = {
// Turn on to use the ISO8601 date/time formatting on all processed date/time properites, else use the masks
iso8601Format = false,
iso8601Format : false,
// The default date mask to use for date properties
dateMask = "yyyy-MM-dd",
dateMask : "yyyy-MM-dd",
// The default time mask to use for date properties
timeMask = "HH:mm:ss",
timeMask : "HH:mm:ss",
// Enable orm auto default includes: If true and an object doesn't have any `memento` struct defined
// this module will create it with all properties and relationships it can find for the target entity
// leveraging the cborm module.
ormAutoIncludes = true,
ormAutoIncludes : true,
// The default value for getters which return null
nullDefaultValue = '',
// Don't check for getters before invoking them
trustedGetters = false,
nullDefaultValue : "",
// Don't check for getters before invoking them
trustedGetters : false,
// If not empty, convert all date/times to the specific timezone
convertToTimezone = ""
convertToTimezone : ""
};

// Custom Declared Interceptors
interceptors = [
{ class="mementifier.interceptors.Mementifier" }
];
interceptors = [ { class : "mementifier.interceptors.Mementifier" } ];
}

/**
* Fired when the module is registered and activated.
*/
function onLoad(){
* Listen to application and modules loaded
*/
function afterAspectsLoad(){
// Verify if the `cborm` module is installed and in use, else skip orm auto includes
if ( !controller.getModuleService().isModuleRegistered( "cborm" ) ) {
settings.ormAutoIncludes = false;
}
}

/**
* Fired when the module is registered and activated.
*/
function onLoad(){
}

/**
* Fired when the module is unregistered and unloaded
*/
* Fired when the module is unregistered and unloaded
*/
function onUnload(){

}

}
8 changes: 4 additions & 4 deletions box.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name":"Mementifier : The State Maker!",
"version":"3.0.1",
"version":"3.1.0",
"location":"https://downloads.ortussolutions.com/ortussolutions/coldbox-modules/mementifier/@build.version@/mementifier-@build.version@.zip",
"author":"Ortus Solutions, Corp",
"homepage":"https://github.com/coldbox-modules/mementifier",
Expand Down Expand Up @@ -42,9 +42,9 @@
"build:module":"task run taskFile=build/Build.cfc :projectName=`package show slug` :version=`package show version`",
"build:docs":"task run taskFile=build/Build.cfc target=docs :projectName=`package show slug` :version=`package show version`",
"release":"recipe build/release.boxr",
"format":"cfformat run interceptors/,models/,test-harness/tests/**/*.cfc ./.cfformat.json --overwrite",
"format:watch":"cfformat watch interceptors/,models/,test-harness/tests/**/*.cfc ./.cfformat.json",
"format:check":"cfformat check interceptors/,models/,test-harness/tests/**/*.cfc ./.cfformat.json",
"format":"cfformat run interceptors/,models/,ModuleConfig.cfc,test-harness/tests/**/*.cfc ./.cfformat.json --overwrite",
"format:watch":"cfformat watch interceptors/,models/,ModuleConfig.cfc,test-harness/tests/**/*.cfc ./.cfformat.json",
"format:check":"cfformat check interceptors/,models/,ModuleConfig.cfc,test-harness/tests/**/*.cfc ./.cfformat.json",
"cfpm":"echo '\".engine/adobe2021/WEB-INF/cfusion/bin/cfpm.sh\"' | run",
"cfpm:install":"echo '\".engine/adobe2021/WEB-INF/cfusion/bin/cfpm.sh\" install ${1}' | run",
"install:2021":"run-script cfpm:install zip,debugger,orm,mysql,postgresql,sqlserver,feed,chart",
Expand Down
21 changes: 17 additions & 4 deletions build/Build.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,7 @@ component {
)
.toConsole();

// Prepare exports directory
variables.exportsDir = variables.artifactsDir & "/#projectName#/#arguments.version#";
directoryCreate( variables.exportsDir, true, true );
ensureExportDir( argumentCollection = arguments );

// Project Build Dir
variables.projectBuildDir = variables.buildDir & "/#projectName#";
Expand Down Expand Up @@ -200,11 +198,12 @@ component {
version = "1.0.0",
outputDir = ".tmp/apidocs"
){
ensureExportDir( argumentCollection = arguments );

// Create project mapping
fileSystemUtil.createMapping( arguments.projectName, variables.cwd );
// Generate Docs
print.greenLine( "Generating API Docs, please wait..." ).toConsole();
directoryCreate( arguments.outputDir, true, true );

command( "docbox generate" )
.params(
Expand Down Expand Up @@ -315,4 +314,18 @@ component {
return ( createObject( "java", "java.lang.System" ).getProperty( "cfml.cli.exitCode" ) ?: 0 );
}

/**
* Ensure the export directory exists at artifacts/NAME/VERSION/
*/
private function ensureExportDir(
required projectName,
version = "1.0.0"
){
if ( structKeyExists( variables, "exportsDir" ) && directoryExists( variables.exportsDir ) ){
return;
}
// Prepare exports directory
variables.exportsDir = variables.artifactsDir & "/#projectName#/#arguments.version#";
directoryCreate( variables.exportsDir, true, true );
}
}
9 changes: 9 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

----

## [3.1.0] => 2022-NOV-10

### Added

* Refactored the ORM includes to its own function
* ORM Includes is only set to `true` if `cborm` has been registered

----

## [3.0.1] => 2022-OCT-18

### Fixed
Expand Down
105 changes: 58 additions & 47 deletions interceptors/Mementifier.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ component {
}

// Inject helper methods
arguments.entity.$injectMixin( "$buildOrmIncludes", variables.$buildOrmIncludes );
arguments.entity.$injectMixin( "$buildNestedMementoList", variables.$buildNestedMementoList );
arguments.entity.$injectMixin( "$buildNestedMementoStruct", variables.$buildNestedMementoStruct );
arguments.entity.$injectMixin( "$getDeepProperties", variables.$getDeepProperties );
Expand Down Expand Up @@ -178,53 +179,7 @@ component {

// Is orm auto inflate on and no memento defined? Build the default includes using this entity and Hibernate
if ( thisMemento.ormAutoIncludes && !arrayLen( thisMemento.defaultIncludes ) ) {
var thisName = isNull( variables.entityName ) ? "" : variables.entityName;
if ( !len( thisName ) ) {
var md = getMetadata( this );
thisName = ( md.keyExists( "entityName" ) ? md.entityName : listLast( md.name, "." ) );
}

var ORMService = new cborm.models.BaseORMService();

var entityMd = ORMService.getEntityMetadata( this );
var types = entityMd.getPropertyTypes();
var typeMap = arrayReduce(
entityMd.getPropertyNames(),
function( mdTypes, propertyName, index ){
arguments.mdTypes[ arguments.propertyName ] = types[ index ].getClass().getName();
return arguments.mdTypes;
},
{}
);

thisMemento.defaultIncludes = typeMap
.keyArray()
.filter( function( propertyName ){
switch ( listLast( typeMap[ arguments.propertyName ], "." ) ) {
case "BagType":
case "OneToManyType":
case "ManyToManyType":
case "ManyToOneType":
case "OneToOneType":
case "BinaryType": {
return false;
}
default: {
return true;
}
}
} );

// Append primary keys
if ( entityMd.hasIdentifierProperty() ) {
arrayAppend( thisMemento.defaultIncludes, entityMd.getIdentifierPropertyName() );
} else if ( entityMd.getIdentifierType().isComponentType() ) {
arrayAppend(
thisMemento.defaultIncludes,
listToArray( arrayToList( entityMd.getIdentifierType().getPropertyNames() ) ),
true
);
}
thisMemento.defaultIncludes = $buildOrmIncludes();
}

// Do we have a * for auto includes of all properties in the object
Expand Down Expand Up @@ -452,6 +407,62 @@ component {
return result;
}

/**
* This function builds automatic ORM entity includes
*
* @return The array of default includes for the ORM entity where this function is injected into
*/
array function $buildOrmIncludes(){
var thisName = isNull( variables.entityName ) ? "" : variables.entityName;
if ( !len( thisName ) ) {
var md = getMetadata( this );
thisName = ( md.keyExists( "entityName" ) ? md.entityName : listLast( md.name, "." ) );
}

var ORMService = new cborm.models.BaseORMService();
var entityMd = ORMService.getEntityMetadata( this );
var types = entityMd.getPropertyTypes();
var typeMap = arrayReduce(
entityMd.getPropertyNames(),
function( mdTypes, propertyName, index ){
arguments.mdTypes[ arguments.propertyName ] = types[ index ].getClass().getName();
return arguments.mdTypes;
},
{}
);

var defaultIncludes = typeMap
.keyArray()
.filter( function( propertyName ){
switch ( listLast( typeMap[ arguments.propertyName ], "." ) ) {
case "BagType":
case "OneToManyType":
case "ManyToManyType":
case "ManyToOneType":
case "OneToOneType":
case "BinaryType": {
return false;
}
default: {
return true;
}
}
} );

// Append primary keys
if ( entityMd.hasIdentifierProperty() ) {
arrayAppend( defaultIncludes, entityMd.getIdentifierPropertyName() );
} else if ( entityMd.getIdentifierType().isComponentType() ) {
arrayAppend(
defaultIncludes,
listToArray( arrayToList( entityMd.getIdentifierType().getPropertyNames() ) ),
true
);
}

return defaultIncludes;
}

/**
* Build a new memento include/exclude list using the target list and a property root
*
Expand Down

0 comments on commit 5c8f4d9

Please sign in to comment.