Пример #1
0
function getParentTag(tag,vm,baseLink) {
	var def = new defer();
	if (tag && tag.parent && tag.parent.tag && tag.parent.tag.id){
		var def = new defer();
		//console.log("Get Parent: ", api_host + "/api/tags/" + tag.parent.tag.id);
		request({
			url: baseLink + "/" + tag.parent.tag.id,
			auth: auth,
			headers: {
				accept: "application/json"
	                },
			strictSSL: false,
			json: true
		}, function(err,response,ptag){
	                if (response.statusCode>=400){
				def.resove(null);
				//def.reject(response.statusCode);
               		}
			if (err) {
				console.log("Err: ", err);
				def.resolve(null);
			}
			def.resolve(ptag);

		});	
	}else{
		def.resolve(null);		
	}
	return def.promise;
}
Пример #2
0
	MongoClient.connect(this.opts.url, function(err, db) {
		if (err) { console.log("Error connecting to ", _self.id, " Data Store", err);def.reject(err);return}
		_self.db = db;	
		_self.collection = db.collection(_self.id);
		console.log("MongoDB Store Collection: ", _self.id);	
		def.resolve(true);
	});
Пример #3
0
 request.get({url: signer, json: true}, function (err, response, body) {
   if (err) { return def.reject(err) }
   if (!body) { return def.reject('Empty Signature') }
   // console.log("body: ", body);
   // console.log("Signature: ", body.pubkey);
   ssCache[signer] = body.pubkey
   def.resolve(body.pubkey)
 })
Пример #4
0
		fs.outputJson(fn, data, function(err){
			if(err){
				def.reject(err);
				return;
			}

			def.resolve(true);
		});
Пример #5
0
			fs.readJson(fn, function(err, data){
				if(err){
					return def.reject(err);
				}

				def.resolve(data);

				touch(fn);
			});
Пример #6
0
	}, function(err, r, body){
		//debug("Distribute RESULTS: ", body);
		debug("r.headers: ", r.headers);
		if(err){
			return def.reject(err);
		}

		if(body && typeof body == "string"){
			body = JSON.parse(body)
		}
		def.resolve(body);
	});
Пример #7
0
  }, function (err, r, body) {
    // debug("Distribute RESULTS: ", body);
    debug('r.headers: ', r.headers)
    if (err) {
      return def.reject(err)
    }

    if (body && typeof body === 'string') {
      body = JSON.parse(body)
    }
    def.resolve(body)
  })
Пример #8
0
Файл: html.js Проект: dmachi/dme
	fs.exists(search, function(exists){
		if (exists) { return def.resolve(Path.join(templateId,objId)+(templateStyle?("-"+templateStyle):"")); }
		debug("Failed to find: ", search);
		if (objId) {
			search = Path.join("views", templateId)+(templateStyle?("-"+templateStyle):"") + ".ejs";
			console.log("Searching for ", search);
			fs.exists(search, function(exists){
				if (exists) { return def.resolve(templateId + (templateStyle?("-"+templateStyle):"")); }
				def.reject(new Error("Unable to Resolve Template " + templateId));
			});
		}else{
			def.reject(new Error("Unable to Resolve Template " + search));
		}
	});
Пример #9
0
var getSigner = function (signer) {
  var def = new Defer()
  if (ssCache[signer]) {
    def.resolve(ssCache[signer])
    return def.promise
  }
  request.get({url: signer, json: true}, function (err, response, body) {
    if (err) { return def.reject(err) }
    if (!body) { return def.reject('Empty Signature') }
    // console.log("body: ", body);
    // console.log("Signature: ", body.pubkey);
    ssCache[signer] = body.pubkey
    def.resolve(body.pubkey)
  })
  return def.promise
}
Пример #10
0
module.exports = function query (dataType, query, opts) {
  debug('Query: ', query)
  var def = new Defer()
  opts = opts || {}

  debug('Send Request to distributeURL: ', distributeURL + dataType)
  debug('runQuery: ', dataType, query, opts)
  request.post({
    url: distributeURL + dataType + '/',
    headers: {
      'content-type': 'application/rqlquery+x-www-form-urlencoded',
      accept: opts.accept || 'application/json',
      authorization: opts.authorization || ''
    },
    body: query
  }, function (err, r, body) {
    // debug("Distribute RESULTS: ", body);
    debug('r.headers: ', r.headers)
    if (err) {
      return def.reject(err)
    }

    if (body && typeof body === 'string') {
      body = JSON.parse(body)
    }
    def.resolve(body)
  })

  return def.promise
}
Пример #11
0
IntentsResolver.prototype._getIntentComponentView = function(intent, testTagFactory) {   
    var moduleId = intent.provider.module.id;
    var moduleVersion = intent.provider.module.version;
    var viewPath = intent.provider.view; 
    
    var componentId =  moduleId + ";" + moduleVersion;

    if(!testTagFactory) {
        testTagFactory = modTagFactory;
    }
        
    var tagFactory = new testTagFactory.TagFactory(this._componentContainer);
       
    var component = this._componentContainer.createComponent(componentId);
    
    var defer = new modPromise.defer();
    
    var req = {"session": intent.intentContext.session};
            
    component.initialize(viewPath, "html", {},  
                req, undefined, undefined, 
                tagFactory);
                    
    component.once("rendered", function(component) {
        var renderer = component.renderer;       
        
        defer.resolve(renderer.renderresult);
    });         
    
    return defer.promise;
}
Пример #12
0
	get: function(key, options){
		var def = new Deferred();
		options = options || {};

		if(!options.user){
			options.user = 'public'
		}

		var fn = Path.join(cacheDir, options.user, key);
		debug("Check for Cached Data in: ", fn);
		fs.exists(fn, function(exists){
			if(!exists){
				def.reject(false);
				return;
			}

			fs.readJson(fn, function(err, data){
				if(err){
					return def.reject(err);
				}

				def.resolve(data);

				touch(fn);
			});

		});

		return def.promise;
	},
Пример #13
0
module.exports = function query(dataType, query, opts){
	debug("Query: ", query);
	var def = new defer();
	opts = opts || {};

	debug("Send Request to distributeURL: ", distributeURL + dataType);
	debug("runQuery: ", dataType, query, opts);
	request.post({
		url: distributeURL + dataType + "/",
		headers: {
			"content-type": "application/rqlquery+x-www-form-urlencoded",
			accept: opts.accept || "application/json",
			authorization: opts.authorization || ""
		},
		body: query
	}, function(err, r, body){
		//debug("Distribute RESULTS: ", body);
		debug("r.headers: ", r.headers);
		if(err){
			return def.reject(err);
		}

		if(body && typeof body == "string"){
			body = JSON.parse(body)
		}
		def.resolve(body);
	});

	return def.promise;
};
Пример #14
0
IntentsResolver.prototype.resolveIntent = function(category, action, intentContext, preferences) {
    logger.debug("Resolve intent " + category + "," + action);
    
    var handlers = this._getIntentProviders(category, action);
    
    if(handlers.length == 0) {
        return [];
    }
            
    if(handlers.length > 1) {
        // multiple potential handlers: the platform will ask user for the preference.
        
        return handlers;
    }
    
    var renderPromise = new modPromise.defer();
    
    var handler = handlers[0];
    handler.intentContext = intentContext;
    
    this._renderIntent(handler, function(renderResult) {
       renderPromise.resolve(renderResult); 
    });
        
    return renderPromise.promise;
}
Пример #15
0
var getNodeIndex= exports.getNodeIndex= function(indexFile, options) {
	var def = new defer();
	console.log("\tLooking for Array Index in " + indexFile + ".array.json ....");
	fs.exists(indexFile + ".array.json", function(exists){
		if (exists){
			console.log("\t\tRead Array Index from Disk: ", indexFile + ".array.json");
			fs.readJson(indexFile + ".array.json", function(err, data){
				var nodeIdx = {rows: data};
				data.forEach(function(row){
					nodeIdx[row.taxon_id]=row;
				});
				console.log("\t\t\tArray Index Loaded from disk");
				def.resolve(nodeIdx);
			});
		}else{
			console.log("\tBuild Node Index");
			buildNodeIndex(options.dumpdir,options.output).then(function(nodeIdx){
				console.log("\t\tNode Index Loaded: ", typeof nodeIdx);
				buildNameIndex(options.dumpdir,options.output, nodeIdx).then(function(nameIdx){
					console.log("\t\t\tNew Node Index Build Completed");
					def.resolve(nodeIdx);	
				});
			});
		}
	});
	return def.promise;
}
Пример #16
0
Файл: html.js Проект: dmachi/dme
	serialize: function(obj,opts){
		var def = new defer();
		console.log("Attempt to Resolve Template for: ", opts.req.template, ((obj&&obj.id)?obj.id:""),opts.req.templateStyle||"");
		var resolvedTemplate = resolveTemplate(opts.req.templateId,((obj&&obj.id)?obj.id:"") ,opts.req.templateStyle||"")
		debug("Resolved Template: ", resolvedTemplate);
		when(resolvedTemplate, function(resolvedTemplate){
			opts.res.render(resolvedTemplate,{results: obj,request:opts.req},function(err,html){
				if (err) {
					debug("Error Rendering HTML Template: ", err);
					debug("Rendering Template as: ", opts.req.templateId + (opts.req.templateStyle?("-"+opts.req.templateStyle):""));
					opts.res.render(opts.req.templateId + (opts.req.templateStyle?("-"+opts.req.templateStyle):""), {results: obj, request: opts.req}, function(err,html){
						if (err) { 
							opts.res.render('default' + (opts.req.templateStyle?("-"+opts.req.templateStyle):""), {results: obj, request: opts.req}, function(err,html){
								if (err) { 
									return def.reject(err); 
								}
								return def.resolve(html);
							});
							return;
						}
						return def.resolve(html);
					});
					return;
				}
				def.resolve(html);	
			});	
		}, function(err){
			console.log("Unable to Resolve template");
			def.reject("Unable To Resolve Template");
		});	

		return def.promise;
	}
Пример #17
0
			fs.readJson(indexFile + ".names.json", function(err,data){
				if (nodeIndex) {
				data.forEach(function(rowObj) {
				//	console.log("rowObj.taxon_id:", rowObj.taxon_id, nodeIndex[rowObj.taxon_id]);	
					if (nodeIndex && nodeIndex[rowObj.taxon_id]){
						Object.keys(rowObj).filter(function(key){ return key!="taxon_id" }).forEach(function(key){
							if (rowObj[key]) {
//								console.log("tid: ", rowObj.taxon_id, "rowObj[key]:", rowObj[key]);
//								console.log("Indexed: ", nodeIndex[rowObj.taxon_id]);
//								console.log("key: ", key);
								nodeIndex[rowObj.taxon_id][key]=rowObj[key];
							}
						});
					}
				});

					console.log("\twriteArrayIndex: ", indexFile + ".array.json");
					fs.writeJson(indexFile + ".array.json",nodeIndex.rows, function(err) {
						console.log("\t\tBuild Tree");
						def.resolve(nodeIndex);
					});
				}else{
					return def.resolve(data);
				}
			});
Пример #18
0
var buildTree = exports.buildTree = function(indexFile, nodeIndex){
	var def = new defer();
	var treeIndex = {}
	var retry=[]
	if (!nodeIndex) { throw new Error("NodeIndex required to build tree index"); }
	nodeIndex.rows.forEach(function(row){
		if (row && row.parent_id){
			if (nodeIndex[row.parent_id]) {
				if (!nodeIndex[row.parent_id].children){
					nodeIndex[row.parent_id].children=[row]
				}else{
				
					if (nodeIndex[row.parent_id].children.some(function(child){
						return child===row;
					})){
						return;
					}else{
						nodeIndex[row.parent_id].children.push(row);
					}
				}
			}
		}
	});

	treeIndex = nodeIndex["2"];
	console.log("\t\t\tWrite Reference Tree Index to disk: ", indexFile + ".tree.json");
	
	fs.writeJson(indexFile + ".tree.json",treeIndex, function(err) {
		console.log("\t\t\tTree Write Complete");
		def.resolve(treeIndex);
	});

	return def.promise;
}
Пример #19
0
			fs.readJson(indexFile + ".array.json", function(err, data){
				var nodeIdx = {rows: data};
				data.forEach(function(row){
					nodeIdx[row.taxon_id]=row;
				});
				console.log("\t\t\tArray Index Loaded from disk");
				def.resolve(nodeIdx);
			});
Пример #20
0
			fs.readJson(indexFile + ".nodes.json", function(error, data){
				index.rows=data;

				index.rows.forEach(function(row,i){
					index[row.taxon_id]=row;
				});

				def.resolve(index);
			});
Пример #21
0
Store.prototype.get = function(id, options){
	var def = new defer();
	var cursor = this.collection.find({id: id}).limit(1).toArray(function(err,docs){
		var obj = docs[0];
		if (err) { console.log("MONGO DB GET ERROR: ", err); def.reject(err);return; }
		if (obj && obj._id) { delete obj._id; }
		def.resolve(obj);	
	});
	return def.promise;
}
Пример #22
0
	this.collection.findAndModify({id: obj.id},[],{$set:upd},{multi:false,safe:true}, function(err, resp){
		console.log("findAndModify Results: ", arguments);		
		if (err){
			console.log("MONGO UPDATE ERROR: ", err);
			def.reject(err);
		}
		_self.get(obj.id).then(function(o){
			def.resolve(o);
		});
	});
Пример #23
0
	this.collection.count(search, function(err,totalCount){
		//console.log("totalCount: ", totalCount);
		totalCount -= meta.lastSkip;
		if (totalCount < 0)
			totalCount = 0;
		if (meta.lastLimit < totalCount)
			totalCount = meta.lastLimit;
		// N.B. just like in rql/js-array
		totalCountPromise.resolve(Math.min(totalCount, typeof meta.totalCount === "number" ? meta.totalCount : Infinity));
	})
Пример #24
0
IntentsResolver.prototype._getIntentComponentServer = function(intent, testRequire) {
    var moduleId = intent.provider.module.id;
    var moduleVersion = intent.provider.module.version;
    
    var serverController = intent.provider.path;
    var method = intent.provider.method;
    
    var fnRequire = testRequire || require;
    
    var controller = fnRequire(serverController);

    var intentCtx = intent.intentContext;
    var session = intentCtx.session;

    var defer = new modPromise.defer();
    
    defer.resolve(controller[method](intentCtx, session));
    
    return defer.promise;
}
Пример #25
0
Store.prototype.delete = function(id, options){
	var def = new defer();
	if (typeof id=="object"){
		id=id.id;
	}	
	this.collection.delete({id:id},{safe:true}, function(err, count){
		if (err) { def.reject(err); }
		def.resolve(count);
	});
	return def.promise;
}
Пример #26
0
Файл: html.js Проект: dmachi/dme
					opts.res.render(opts.req.templateId + (opts.req.templateStyle?("-"+opts.req.templateStyle):""), {results: obj, request: opts.req}, function(err,html){
						if (err) { 
							opts.res.render('default' + (opts.req.templateStyle?("-"+opts.req.templateStyle):""), {results: obj, request: opts.req}, function(err,html){
								if (err) { 
									return def.reject(err); 
								}
								return def.resolve(html);
							});
							return;
						}
						return def.resolve(html);
					});
Пример #27
0
	stream.on('end', function(){
		if (bufferedRows.length>0) {                                                
			wstream.write(((writtenRows>0)?",":"")+bufferedRows.map(function(o){
				return JSON.stringify(o)
			}).join(",") + "]");
			writtenRows += bufferedRows.length;
		}	

		wstream.end();
		console.log("Loaded ", rows, " rows");
		def.resolve(index);
	});
Пример #28
0
Store.prototype.put = function(obj, options){
	var def = new defer();
//	this.db.collection(this.id).update({id: obj.id || options.id},{$set: obj},{multi:false,upsert:true}, function(err){
	var obj = this.normalizeObject(obj);

	console.log("Collection.save()");
	this.collection.save(obj, {safe: true}, function(err,obj){
		console.log("Final Object: ", obj);
		if (err) {def.reject(err); return;}
		def.resolve(obj);	
	});	
	return def.promise;
};
Пример #29
0
	execute: function(params,req,res){
		var def = new defer()
		// console.log("Execute MSA: ", params)
		var query = params[0];
        var alignType = "protein";
        if (params.length > 1){
            alignType = params[1];
        }
		var opts = {req: req, user: req.user, token:req.headers.authorization, alignType:alignType}


		when(runQuery(query,opts), function(sequences){
			when(buildFasta(sequences,opts), function(fasta){
				when(runMuscle(fasta,opts), function(alignment){
					when(runGBlocks(alignment,opts), function(gblocksOut){
						when(runFastTree(gblocksOut,opts),function(fastTree){
							var map = {}
							sequences.forEach(function(seq){
								map[seq.feature_id] = {
                                    "genome_name":seq.genome_name,
                                    "feature_id":seq.feature_id,
                                    "genome_id":seq.genome_id,
                                    "patric_id":seq.patric_id,
                                    "aa_length":seq.aa_length,
                                    "refseq_locus_tag": seq.refseq_locus_tag
                                };
							})

							def.resolve({
								map: map,
								alignment: alignment,
								// gblocks: gblocksOut,
								tree: fastTree
							})
						}, function(err){
							def.reject("Unable to Complete FastTree: " + err);
						});
					}, function(err){
						def.reject("Unable to Complete GBLocks for Alignment: " + err);
					})
				}, function(err){
					def.reject("Unable to Complete Alignement: " + err);
				})
			});
		}, function(err){
			def.reject("Unable To Retreive Feature Data for MSA: " + err);
		})
		return def.promise;
	}
Пример #30
0
		fs.exists(fn, function(exists){
			if(!exists){
				def.reject(false);
				return;
			}

			fs.readJson(fn, function(err, data){
				if(err){
					return def.reject(err);
				}

				def.resolve(data);

				touch(fn);
			});

		});