Exemple #1
0
 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)
Exemple #2
0
 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]
Exemple #3
0
    def getCampaignMessageStats(self,eachCampaignId):
        query = {
                'campaignId' : eachCampaignId
            }
        result = MongoHelper.findDocuments('campaigns', 'message', constant.config['CAMPAIGNS_DB_MONGO_MASTER'], query,limit=99)

        return result
Exemple #4
0
    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']
Exemple #5
0
 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()))))
Exemple #6
0
 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
Exemple #7
0
 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
Exemple #8
0
 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)
Exemple #9
0
 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
Exemple #10
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))
Exemple #11
0
 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']
Exemple #12
0
 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))
Exemple #13
0
    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})
Exemple #14
0
    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
Exemple #15
0
 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
Exemple #16
0
 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
Exemple #17
0
 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)
Exemple #18
0
 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
Exemple #19
0
 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)
Exemple #20
0
 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
Exemple #21
0
 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']
Exemple #22
0
 def getApproveStatus(self, messageId):
     query = {'_id': ObjectId(messageId)}
     return MongoHelper.findDocuments(
         'campaigns', 'message',
         constant.config['CAMPAIGNS_DB_MONGO_MASTER'], query)[0]['state']
Exemple #23
0
 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])
Exemple #24
0
 def getMongoConnection(database, collection):
     port = constant.config['INTOUCH_DB_MONGO_MASTER']
     m = MongoHelper(database, collection, port)
     constant.config['mongoConn'] = m.mongodb