server/boot/load-model.js
function(seriesCallback) {
      var subscriptions = [];
      if (apicCfg && apicCfg.plans && apicCfg.applications) {
        //add the configured plans
        var idx = 0;
        for (var k in apicCfg.applications) {
          var theApp = apicCfg.applications[k];
          //An application can subscribe only one plan in a given product. Since
          //we have only one product defined for local data, the subscription of
          //an app should be a string instead of array!
          if (theApp && (!theApp.subscription || typeof theApp.subscription !== 'string')) {
            logger.warn('The app "%s" does not subscribe a plan?', k);
          } else if (typeof theApp === 'object') {
            subscriptions[idx] = {
              'snapshot-id': uid,
              organization: defaultOrg,
              'developer-organization': defaultOrg,
              catalog: defaultCatalog,
              id: 'defaultSubsID-' + k + '-static-product',
              application: {
                id: 'defaultAppID-' + k,
                title: 'defaultAppTitle-' + idx,
                'oauth-redirection-uri': (theApp['oauth-redirection-uri'] || 'https://localhost'),
                'app-credentials': [ {
                  'client-id': k,
                  'client-secret': (theApp['client-secret'] || 'dummy') } ] },
              'plan-registration': {
                id: ('static-product:1.0.0:' + theApp.subscription) } };
          }
          idx++;
        }
      } else {
        //the default subscription
        subscriptions[0] = {
          'snapshot-id': uid,
          organization: defaultOrg,
          'developer-organization': defaultOrg,
          catalog: defaultCatalog,
          id: 'defaultSubsID',
          application: {
            id: 'defaultAppID',
            title: 'defaultAppTitle',
            'oauth-redirection-uri': 'https://localhost',
            'app-credentials': [ {
              'client-id': 'default',
              'client-secret': 'CRexOpCRkV1UtjNvRZCVOczkUrNmGyHzhkGKJXiDswo=' } ] },
          'plan-registration': {
            id: 'ALLPLANS' } };
      }

      async.forEach(
        subscriptions,
        function(subscription, subsCallback) {
          var modelname = 'subscription';
          app.models[modelname].create(
            subscription,
            function(err, mymodel) {
              if (err) {
                logger.error(err);
                subsCallback(err);
                return;
              }
              logger.debug('%s created: %j', modelname, mymodel);
              subsCallback();
            });
        });
      seriesCallback();
    }
function(seriesCallback) {
      var subscriptions = [];
      if (apicCfg && apicCfg.plans && apicCfg.applications) {
        //add the configured plans
        var idx = 0;
        for (var k in apicCfg.applications) {
          var theApp = apicCfg.applications[k];
          //An application can subscribe only one plan in a given product. Since
          //we have only one product defined for local data, the subscription of
          //an app should be a string instead of array!
          if (theApp && (!theApp.subscription || typeof theApp.subscription !== 'string')) {
            logger.warn('The app "%s" does not subscribe a plan?', k);
          } else if (typeof theApp === 'object') {
            subscriptions[idx] = {
              'snapshot-id': uid,
              organization: defaultOrg,
              'developer-organization': defaultOrg,
              catalog: defaultCatalog,
              id: 'defaultSubsID-' + k + '-static-product',
              application: {
                id: 'defaultAppID-' + k,
                title: 'defaultAppTitle-' + idx,
                'oauth-redirection-uri': (theApp['oauth-redirection-uri'] || 'https://localhost'),
                'app-credentials': [ {
                  'client-id': k,
                  'client-secret': (theApp['client-secret'] || 'dummy') } ] },
              'plan-registration': {
                id: ('static-product:1.0.0:' + theApp.subscription) } };
          }
          idx++;
        }
      } else {
        //the default subscription
        subscriptions[0] = {
          'snapshot-id': uid,
          organization: defaultOrg,
          'developer-organization': defaultOrg,
          catalog: defaultCatalog,
          id: 'defaultSubsID',
          application: {
            id: 'defaultAppID',
            title: 'defaultAppTitle',
            'oauth-redirection-uri': 'https://localhost',
            'app-credentials': [ {
              'client-id': 'default',
              'client-secret': 'CRexOpCRkV1UtjNvRZCVOczkUrNmGyHzhkGKJXiDswo=' } ] },
          'plan-registration': {
            id: 'ALLPLANS' } };
      }

      async.forEach(
        subscriptions,
        function(subscription, subsCallback) {
          var modelname = 'subscription';
          app.models[modelname].create(
            subscription,
            function(err, mymodel) {
              if (err) {
                logger.error(err);
                subsCallback(err);
                return;
              }
              logger.debug('%s created: %j', modelname, mymodel);
              subsCallback();
            });
        });
      seriesCallback();
    }
function ( seriesCallback ) { var subscriptions = [ ] ; if ( apicCfg && apicCfg . plans && apicCfg . applications ) { //add the configured plans var idx = 0 ; for ( var k in apicCfg . applications ) { var theApp = apicCfg . applications [ k ] ; //An application can subscribe only one plan in a given product. Since //we have only one product defined for local data, the subscription of //an app should be a string instead of array! if ( theApp && ( ! theApp . subscription || typeof theApp . subscription !== 'string' ) ) { logger . warn ( 'The app "%s" does not subscribe a plan?' , k ) ; } else if ( typeof theApp === 'object' ) { subscriptions [ idx ] = { 'snapshot-id' : uid , organization : defaultOrg , 'developer-organization' : defaultOrg , catalog : defaultCatalog , id : 'defaultSubsID-' + k + '-static-product' , application : { id : 'defaultAppID-' + k , title : 'defaultAppTitle-' + idx , 'oauth-redirection-uri' : ( theApp [ 'oauth-redirection-uri' ] || 'https://localhost' ) , 'app-credentials' : [ { 'client-id' : k , 'client-secret' : ( theApp [ 'client-secret' ] || 'dummy' ) } ] } , 'plan-registration' : { id : ( 'static-product:1.0.0:' + theApp . subscription ) } } ; } idx ++ ; } } else { //the default subscription subscriptions [ 0 ] = { 'snapshot-id' : uid , organization : defaultOrg , 'developer-organization' : defaultOrg , catalog : defaultCatalog , id : 'defaultSubsID' , application : { id : 'defaultAppID' , title : 'defaultAppTitle' , 'oauth-redirection-uri' : 'https://localhost' , 'app-credentials' : [ { 'client-id' : 'default' , 'client-secret' : 'CRexOpCRkV1UtjNvRZCVOczkUrNmGyHzhkGKJXiDswo=' } ] } , 'plan-registration' : { id : 'ALLPLANS' } } ; } async . forEach ( subscriptions , function ( subscription , subsCallback ) { var modelname = 'subscription' ; app . models [ modelname ] . create ( subscription , function ( err , mymodel ) { if ( err ) { logger . error ( err ) ; subsCallback ( err ) ; return ; } logger . debug ( '%s created: %j' , modelname , mymodel ) ; subsCallback ( ) ; } ) ; } ) ; seriesCallback ( ) ; }
4. create the "subscriptions" instances
4 . create the subscriptions instances