Skip to content

Instantly share code, notes, and snippets.

@cfvonner
Last active April 28, 2017 20:46
Show Gist options
  • Save cfvonner/79ea929af09d812cd73c8dc8b2052145 to your computer and use it in GitHub Desktop.
Save cfvonner/79ea929af09d812cd73c8dc8b2052145 to your computer and use it in GitHub Desktop.
component displayname="Base Service" accessors="true" output="false" {
property beanFactory;
public function init() {
return this;
}
private function populate ( any bean, struct properties, any beanFactory ) {
writeLog( text="#GetMetaData( this ).name#-->#getFunctionCalledName()#() arguments: #SerializeJSON( arguments )#", file="GISReports.local.dev", type="information" );
if ( isSimpleValue( bean ) ) {
if ( beanFactory.containsBean( bean ) ) bean = beanFactory.getBean( bean );
else bean = beanFactory.construct( bean );
}
//TODO: add a test for whether property exists in the bean before trying to push the data in
for ( var property in properties ) {
if ( !isNull( properties[ property ] ) &&
( ( isSimpleValue( properties[ property ] ) && Len( properties[ property ] ) ) ||
!isSimpleValue( properties[ property ] ) ) ) {
var args = { };
args[ property ] = properties[ property ];
evaluate( 'bean.set#property#( argumentCollection = args )' );
}
}
return bean;
}
private array function populateBeans( required string beanName, required any recordSet ) {
var beanArray = [];
if ( ( isQuery( recordSet) && recordSet.RecordCount ) ||
( isArray( recordSet ) && recordSet.len() ) ) {
for ( var record in recordSet ) {
/*writeLog( text="#GetMetaData( this ).name#-->#getFunctionCalledName()#() for loop: #SerializeJSON( record )#",
file="GISReports.local.dev", type="information" );*/
var bean = populate( beanName, record );
beanArray.append( bean );
}
}
return beanArray;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment