# ----------------------------------------------------------------------- # Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved. # ----------------------------------------------------------------------- require 'App42_Ruby_API/App42Response' require 'storage/Query' require 'storage/OrderByType' require 'util/util' module App42 module Storage class QueryBuilder class Operator < App42Response attr_accessor :value @value unless (const_defined?(:EQUALS)) EQUALS = "\$eq" end unless (const_defined?(:NOT_EQUALS)) NOT_EQUALS = "\$ne" end unless (const_defined?(:GREATER_THAN)) GREATER_THAN = "\$gt" end unless (const_defined?(:LESS_THAN)) LESS_THAN = "\$lt" end unless (const_defined?(:GREATER_THAN_EQUALTO)) GREATER_THAN_EQUALTO = "\$gte" end unless (const_defined?(:LESS_THAN_EQUALTO)) LESS_THAN_EQUALTO = "\$lte" end unless (const_defined?(:LIKE)) LIKE = "\$lk" end unless (const_defined?(:AND)) AND = "\$and" end unless (const_defined?(:OR)) OR = "\$or" end def enum(string) return Operator.const_get(string) end def isAvailable(string) if(string == "\$eq") return "EQUALS" elsif(string == "\$ne") return "NOT_EQUALS"; elsif(string == "\$gt") return "GREATER_THAN" elsif(string == "\$lt") return "LESS_THAN" elsif(string == "\$gte") return "GREATER_THAN_EQUALTO" elsif(string == "\$lte") return "LESS_THAN_EQUALTO" elsif(string == "\$lk") return "LIKE" elsif(string == "\$and") return "AND" elsif(string == "\$or") return "OR"; else return nil end end end def build(key, value, op) query = nil begin jsonObj = Hash.new() jsonObj.store("key", key); jsonObj.store("value", value); jsonObj.store("operator", op); query = Query.new(jsonObj); rescue Exception => ex raise App42Exception.new(ex) end return query end def compoundOperator(q1, op, q2) util = Util.new() util.throwExceptionIfNullOrBlank(q1, "q1"); util.throwExceptionIfNullOrBlank(q2, "q2"); jsonArray = Array.new() query = Query.new(jsonArray) begin if q1.getType().instance_of?(Hash) jsonArray.push(q1.getType()); else jsonArray.push(q1.getType()); end jsonObj = Hash.new() jsonObj.store("compoundOpt", op); jsonArray.push(jsonObj); if q2.getType().instance_of?(Hash) jsonArray.push(q2.getType()); else jsonArray.push(q2.getType()); end rescue Exception => ex raise App42Exception.new(ex) end return query end end end end