def getVariantStatusByMessageId(self, messageId, version): listOfActiveStatus = list() for _ in range(10): query = { "messageId": messageId, 'messageVersion': version, 'type': 'VARIANT_CREATION' } try: result = MongoHelper.findDocuments( 'campaigns', 'messageJobDetails', constant.config['CAMPAIGNS_DB_MONGO_MASTER'], query)[0]['jobContext']['messageVariantIds'] Logger.log( 'MessageVariant Ids for Message :{} with version :{} are :{}' .format(messageId, version, result)) for eachVariant in result: variantInfo = MongoHelper.findDocuments( 'campaigns', 'messageVariant', constant.config['CAMPAIGNS_DB_MONGO_MASTER'], {'_id': ObjectId(eachVariant)})[0] listOfActiveStatus.append(variantInfo) break except Exception, exp: Logger.log( 'Exception fetching getVariantStatusByMessageId :{}'. format(exp)) time.sleep(10)
def getCampaignSettings(self): query = { '_id': constant.config['orgId'] } result = MongoHelper.findDocuments('campaigns', 'campaignSettings', constant.config['CAMPAIGNS_DB_MONGO_MASTER'], query) if len(result) == 0: raise Exception('NoSettingsException:{}'.format(query)) return result[0]
def getCampaignMessageStats(self,eachCampaignId): query = { 'campaignId' : eachCampaignId } result = MongoHelper.findDocuments('campaigns', 'message', constant.config['CAMPAIGNS_DB_MONGO_MASTER'], query,limit=99) return result
def getCampaignEndDate(self,campaignId): query = {'campaignId': campaignId } result = MongoHelper.findDocuments('campaigns', 'campaign', constant.config['CAMPAIGNS_DB_MONGO_MASTER'], query, limit=1) return result[0]['endDate']
def messageJobDetailsCollection(self): self.messageDbDetail['messageJobDetails_collection'] = dict() jobType = [ 'MESSAGE_TARGET_AUDIENCE', 'VARIANT_CREATION' ] if not self.personalize else [ 'MESSAGE_TARGET_AUDIENCE', 'PERSONALIZE_TARGET_AUDIENCE', 'PERSONALIZED_TARGET_AUDIENCE_POLLER', 'PERSONALIZED_AUDIENCE_GROUP_CREATION', 'PERSONALIZED_AUDIENCE_GROUPS_POLLER', 'PERSONALIZED_VARIANT_CREATION' ] for eachType in jobType: if message_calls().waitForJobDetailsStatusToClose( self.messageId, eachType, version=self.version): query = { "messageId": self.messageId, 'type': eachType, 'messageVersion': self.version } result = MongoHelper.findDocuments( 'campaigns', 'messageJobDetails', constant.config['CAMPAIGNS_DB_MONGO_MASTER'], query, sort='messageVersion') self.messageDbDetail['messageJobDetails_collection'].update( {eachType: result}) else: raise Exception( 'Job Details Status For :{} is not yet Closed , check time :{}' .format(eachType, str(int(time.time()))))
def getCampaignIdAsPerQueryParam(self, limit, offset, search): query = {'name': {'$regex': '{}'.format(search)}, 'orgId': constant.config['orgId']} result = MongoHelper.findDocuments('campaigns', 'campaign', constant.config['CAMPAIGNS_DB_MONGO_MASTER'], query, limit=limit, sort='startDate', skip=offset) listOfCampaignIds = list() for eachEntity in result: listOfCampaignIds.append(eachEntity['campaignId']) return listOfCampaignIds
def checkCampaignHaveMessage(self, campaignId): query = {'orgId': constant.config['orgId'], 'campaignId': campaignId} result = MongoHelper.findDocuments( 'campaigns', 'message', constant.config['CAMPAIGNS_DB_MONGO_MASTER'], query) if len(result) > 0: return True else: return False
def getNUmberOfInactiveVariantForMessage(self, messageId): query = {"messageId": messageId, 'active': False} result = MongoHelper.findDocuments( 'campaigns', 'messageVariant', constant.config['CAMPAIGNS_DB_MONGO_MASTER'], query, limit=10) return len(result)
def messageCollection(self): query = {'_id': ObjectId(self.messageId)} result = MongoHelper.findDocuments( 'campaigns', 'message', constant.config['CAMPAIGNS_DB_MONGO_MASTER'], query) self.messageDbDetail.update({'message_collection': result[0]}) if 'version' in self.messageDbDetail['message_collection']: self.version = self.messageDbDetail['message_collection'][ 'version'] else: self.version = 0
def getTargetAudienceForTestAndPreview(self, messageId): try: query = {'_id': ObjectId(messageId)} result = MongoHelper.findDocuments( 'campaigns', 'message', constant.config['CAMPAIGNS_DB_MONGO_MASTER'], query)[0] listId = result['targetAudience']['include'][0] campaignId = result['campaignId'] except Exception, exp: raise Exception( 'Exception While Getting Target Audience of test&Preview , exp:{}' .format(exp))
def getVariantIdByMessageId(self, messageId, numberOfTries=10): for _ in range(numberOfTries): query = {"messageId": messageId} result = MongoHelper.findDocuments( 'campaigns', 'messageVariant', constant.config['CAMPAIGNS_DB_MONGO_MASTER'], query) if len(result) == 0: time.sleep(10) else: break if len(result) == 0: raise Exception('VariantNotCreatedException') return result[0]['_id']
def getNumberOfMessagesInCampaign(self, campaignId): query = { 'orgId': constant.config['orgId'], 'campaignId': campaignId, 'test': False } return len( MongoHelper.findDocuments( 'campaigns', 'message', constant.config['CAMPAIGNS_DB_MONGO_MASTER'], query, limit=50))
def messageVariantsCollection(self): variant_detail = list() variant_creation_key = 'VARIANT_CREATION' if not self.personalize else 'PERSONALIZED_VARIANT_CREATION' for eachVariant in self.messageDbDetail[ 'messageJobDetails_collection'][variant_creation_key]: for eachVariantId in eachVariant['jobContext'][ 'messageVariantIds']: query = {'_id': ObjectId(eachVariantId)} variant_detail.append( MongoHelper.findDocuments( 'campaigns', 'messageVariant', constant.config['CAMPAIGNS_DB_MONGO_MASTER'], query)[0]) eachVariant.update({'variant_detail': variant_detail})
def waitForJobDetailsStatusToClose(self, messageId, jodDetailsType, maxNumberOfAttempts=25, version=0, sleepTime=20): Logger.log( 'Waiting For MessageId :{} with JobDetail :{} for MaxAttempts :{} and version :{}' .format(messageId, jodDetailsType, maxNumberOfAttempts, version)) if jodDetailsType == 'PERSONALIZED_VARIANT_CREATION': maxNumberOfAttempts = 50 version = \ message_info(messageId, messageJobDetailsCollection=False, messageVariantsCollection=False).messageDbDetail[ 'message_collection']['version'] query = { "messageId": messageId, 'type': jodDetailsType, 'messageVersion': version } while (True): result = MongoHelper.findDocuments( 'campaigns', 'messageJobDetails', constant.config['CAMPAIGNS_DB_MONGO_MASTER'], query) if len(result) != 0: for eachJobDetailOfTypeTargetAudience in result: status = True if eachJobDetailOfTypeTargetAudience[ 'status'] == 'CLOSED' else False else: status = False Logger.log('Variant Entry Not Yet Created') if status or maxNumberOfAttempts == 0: Logger.log('Status :{} and MaxAttempts :{}'.format( status, maxNumberOfAttempts)) if status == False: raise Exception( 'VariantNotClosedExceptionWithStatus:{}'.format( status)) break else: time.sleep(sleepTime) maxNumberOfAttempts = maxNumberOfAttempts - 1 return status
def getExistingUsers(self, numberOfusers, offset=0, mobilePush=False, commChannels=None): if mobilePush: listOfMobilePushUsers = list() commChannels = constant.config['mobilepush'][ 'channels'] if commChannels is None else commChannels for commChannelType in commChannels: port = constant.config['INTOUCH_DB_MONGO_MASTER'] query = { 'orgId': constant.config['orgId'], 'source': 'WEB_ENGAGE', 'commChannels.type': commChannelType } userIds = MongoHelper.findDocuments('multi_profile', 'profileV2', port, query, limit=1)[0]['userId'] listOfMobilePushUsers.append([userIds]) if constant.config['cluster'] in [ 'nightly' ] and 'android' in constant.config['mobilepush']['channels']: try: query = "select id from users where org_id = {} and mobile = '{}'".format( constant.config['orgId'], constant.config['mobilepush']['androidE2E_User']) android_id = dbHelper.queryDB(query, 'user_management')[0] if android_id is not None: listOfMobilePushUsers[0] = android_id except Exception, exp: Logger.log( "Tried Adding Number :{} as Android User in List but failed due to Exception :{}" .format( constant.config['mobilepush'] ['androidE2E_User'], exp)) Logger.log( 'List Of Existing Users :{}'.format(listOfMobilePushUsers)) return listOfMobilePushUsers
def getMapOfVersions(self, messageId, numberOfVersions): query = {"messageId": messageId} for eachTry in range(10): result = MongoHelper.findDocuments( 'campaigns', 'messageVariant', constant.config['CAMPAIGNS_DB_MONGO_MASTER'], query, limit=10) if len(result) == numberOfVersions: break time.sleep(10) if len(result) != numberOfVersions + 1: raise Exception('NumberOfVersionRequired:{}AndInMongo:{}'.format( numberOfVersions, len(result))) mapOfVesions = dict() idx = 0 for each in result: mapOfVesions.update({idx: each['messageVersion']}) idx = idx + 1 return mapOfVesions
def getTemplateDetails(channel, templateName): port = constant.config['INTOUCH_DB_MONGO_MASTER'] if channel.lower() == 'wechat': query = { 'name': { '$regex': '.*' + templateName + '.*' }, 'isActive': True, 'type': channel.upper() } else: query = { 'name': templateName, 'isActive': True, 'type': channel.upper() } return MongoHelper.findDocuments('creatives_mongo', 'templates', port, query, limit=2)
def getCampaignId(self, campaignType, testControlType): query = { 'orgId': constant.config['orgId'], 'testControl.testControlType': testControlType } if campaignType == 'LIVE': query.update({ 'startDate': {'$lt': datetime.datetime.fromtimestamp(time.time() - 1000, None)}, 'endDate': {'$gt': datetime.datetime.fromtimestamp(time.time() + 1000,None)} }) elif campaignType == 'UPCOMING': query.update({ 'startDate': {'$gt': datetime.datetime.fromtimestamp(time.time() + 1000, None)}, }) elif campaignType == 'LAPSED': query.update({ 'endDate': {'$lt': datetime.datetime.fromtimestamp(time.time() - 1000, None)} }) result = MongoHelper.findDocuments('campaigns', 'campaign', constant.config['CAMPAIGNS_DB_MONGO_MASTER'], query, limit=20,sort='_id') if len(result) == 0: raise Exception('NoListFoundException, Query :{}'.format(query)) return result
def getUserForMobilePush(commChannelType): port = constant.config['INTOUCH_DB_MONGO_MASTER'] query = {'orgId': constant.config['orgId'], 'source': 'WEB_ENGAGE', 'commChannels.type': commChannelType} return MongoHelper.findDocuments('multi_profile', 'profileV2', port, query, limit=2)
def getCampaignObjective(self): result = MongoHelper.findDocuments('campaigns', 'campaignObjectives', constant.config['CAMPAIGNS_DB_MONGO_MASTER'], {},limit=10) if len(result) == 0: raise Exception('NoSettingsException') return result
def getExistingMessageNameAndCampaignId(self): result = MongoHelper.findDocuments( 'campaigns', 'message', constant.config['CAMPAIGNS_DB_MONGO_MASTER'], {'orgId': constant.config['orgId']}) return result[0]['name'], result[0]['campaignId']
def getApproveStatus(self, messageId): query = {'_id': ObjectId(messageId)} return MongoHelper.findDocuments( 'campaigns', 'message', constant.config['CAMPAIGNS_DB_MONGO_MASTER'], query)[0]['state']
def getCampaignDetails(self): query = {'campaignId': self.campaignId} result = MongoHelper.findDocuments('campaigns', 'campaign', constant.config['CAMPAIGNS_DB_MONGO_MASTER'], query, limit=1) self.campaignInfo.update(result[0])
def getMongoConnection(database, collection): port = constant.config['INTOUCH_DB_MONGO_MASTER'] m = MongoHelper(database, collection, port) constant.config['mongoConn'] = m.mongodb