lib/ckan-importer.js
function getVocabId(name, callback) {
	if( vocabMap[name] ) return callback(vocabMap[name]);

	ckan.exec("vocabulary_show", {id: name}, function(err, resp) {
		if( err && JSON.parse(err.body).error.__type == 'Not Found Error' ) {
			create("vocabulary", {name: name, tags: []}, function(err, resp){
					if( err ) error("Unable to create vocabulary: "+name);
					vocabMap[name] = resp.result.id;
					callback(resp.result.id);
			});
			return;
		} else if( err ) {
			error("Unable to access vocabulary 'id:"+name+"'");
		}

		if( !resp.success ) {
			if( name.match(/.*-.*-.*-.*-.*/) ) {
				if( err ) error("No vocabulary found for passed id");

				create("vocabulary", {name: name, tags: []}, function(err, resp){
					if( err ) error("Unable to create vocabulary: "+name);
					vocabMap[name] = resp.result.id;
					callback(resp.result.id);
				});
			}
		} else {
			vocabMap[name] = resp.result.id;
			callback(resp.result.id);
		}
	});
}
function getVocabId(name, callback) {
	if( vocabMap[name] ) return callback(vocabMap[name]);

	ckan.exec("vocabulary_show", {id: name}, function(err, resp) {
		if( err && JSON.parse(err.body).error.__type == 'Not Found Error' ) {
			create("vocabulary", {name: name, tags: []}, function(err, resp){
					if( err ) error("Unable to create vocabulary: "+name);
					vocabMap[name] = resp.result.id;
					callback(resp.result.id);
			});
			return;
		} else if( err ) {
			error("Unable to access vocabulary 'id:"+name+"'");
		}

		if( !resp.success ) {
			if( name.match(/.*-.*-.*-.*-.*/) ) {
				if( err ) error("No vocabulary found for passed id");

				create("vocabulary", {name: name, tags: []}, function(err, resp){
					if( err ) error("Unable to create vocabulary: "+name);
					vocabMap[name] = resp.result.id;
					callback(resp.result.id);
				});
			}
		} else {
			vocabMap[name] = resp.result.id;
			callback(resp.result.id);
		}
	});
}
function getVocabId ( name , callback ) { if ( vocabMap [ name ] ) return callback ( vocabMap [ name ] ) ; ckan . exec ( "vocabulary_show" , { id : name } , function ( err , resp ) { if ( err && JSON . parse ( err . body ) . error . __type == 'Not Found Error' ) { create ( "vocabulary" , { name : name , tags : [ ] } , function ( err , resp ) { if ( err ) error ( "Unable to create vocabulary: " + name ) ; vocabMap [ name ] = resp . result . id ; callback ( resp . result . id ) ; } ) ; return ; } else if ( err ) { error ( "Unable to access vocabulary 'id:" + name + "'" ) ; } if ( ! resp . success ) { if ( name . match ( / .*-.*-.*-.*-.* / ) ) { if ( err ) error ( "No vocabulary found for passed id" ) ; create ( "vocabulary" , { name : name , tags : [ ] } , function ( err , resp ) { if ( err ) error ( "Unable to create vocabulary: " + name ) ; vocabMap [ name ] = resp . result . id ; callback ( resp . result . id ) ; } ) ; } } else { vocabMap [ name ] = resp . result . id ; callback ( resp . result . id ) ; } } ) ; }
if the id doesn't exist, create it
if the id doesn t exist create it