From 1925708e78b845c0b5975f6e69997d7761030c12 Mon Sep 17 00:00:00 2001 From: Luis Majano Date: Tue, 18 Oct 2022 19:20:31 +0200 Subject: [PATCH 1/4] version bump --- box.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/box.json b/box.json index 177cdbf..866e6d2 100644 --- a/box.json +++ b/box.json @@ -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", From e273b70d1331e1727f3ffd3a767c7ee003185a78 Mon Sep 17 00:00:00 2001 From: Michael Born Date: Tue, 1 Nov 2022 10:16:30 -0400 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=90=9B=20FIX:=20Correct=20standalone?= =?UTF-8?q?=20build:docs=20box=20script?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The variables.exportsDir needs to exist in the docs target as well as the buildSource target. --- build/Build.cfc | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/build/Build.cfc b/build/Build.cfc index 926cce1..2ce38eb 100644 --- a/build/Build.cfc +++ b/build/Build.cfc @@ -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#"; @@ -200,6 +198,8 @@ component { version = "1.0.0", outputDir = ".tmp/apidocs" ){ + ensureExportDir( argumentCollection = arguments ); + // Create project mapping fileSystemUtil.createMapping( arguments.projectName, variables.cwd ); // Generate Docs @@ -315,4 +315,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 ); + } } From cf9323b9042d94eb46fa852d15a87780f8e1cd31 Mon Sep 17 00:00:00 2001 From: Michael Born Date: Tue, 1 Nov 2022 10:16:58 -0400 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=91=8C=20IMPROVE:=20Don't=20create=20?= =?UTF-8?q?(relative,=20useless)=20output=20dir=20on=20docs=20build?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Docbox already does this, only it gets the path right. There's no need to create it inside the build/ directory. --- build/Build.cfc | 1 - 1 file changed, 1 deletion(-) diff --git a/build/Build.cfc b/build/Build.cfc index 2ce38eb..8e6eb76 100644 --- a/build/Build.cfc +++ b/build/Build.cfc @@ -204,7 +204,6 @@ component { 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( From 46c1c5eaa3961f5c7354f2506c80cd37c631185a Mon Sep 17 00:00:00 2001 From: Luis Majano Date: Thu, 10 Nov 2022 10:23:57 +0100 Subject: [PATCH 4/4] ### Added * Refactored the ORM includes to its own function * ORM Includes is only set to `true` if `cborm` has been registered --- ModuleConfig.cfc | 55 +++++++++--------- box.json | 6 +- changelog.md | 9 +++ interceptors/Mementifier.cfc | 105 +++++++++++++++++++---------------- 4 files changed, 99 insertions(+), 76 deletions(-) diff --git a/ModuleConfig.cfc b/ModuleConfig.cfc index 5c83566..b8f781e 100644 --- a/ModuleConfig.cfc +++ b/ModuleConfig.cfc @@ -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(){ - } } diff --git a/box.json b/box.json index 866e6d2..279a255 100644 --- a/box.json +++ b/box.json @@ -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", diff --git a/changelog.md b/changelog.md index 6bfc120..5cc115d 100644 --- a/changelog.md +++ b/changelog.md @@ -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 diff --git a/interceptors/Mementifier.cfc b/interceptors/Mementifier.cfc index f912935..7826c14 100644 --- a/interceptors/Mementifier.cfc +++ b/interceptors/Mementifier.cfc @@ -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 ); @@ -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 @@ -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 *