def searchConsumer(builder):
     service = ConsumerService()
     m_converter = ConvertJSONToPb()
     builder = m_converter.converjsontoPBProper(
         response=builder,
         instanceType=consumersearch_pb2.ConsumerSearchRequestPb())
     return service.search(builder=builder)
 def snedNotification(builder):
     service = SendPushNotificationService()
     m_converter = ConvertJSONToPb()
     m_convertPbtoJson = ConvertPbToJSON()
     builder = m_converter.converjsontoPBProper(response=builder,
                                                instanceType=pushnotification_pb2.PushNotificationRequestPb())
     return m_convertPbtoJson.converPbtojson(service.sendNotification(pushNotificationRequestPb=builder))
 def getLogin(builder):
     service = LoginModuleService()
     m_converter = ConvertJSONToPb()
     m_convertPbtoJson = ConvertPbToJSON()
     builder = m_converter.converjsontoPBProper(
         response=builder, instanceType=login_pb2.LoginRequestPb())
     return m_convertPbtoJson.converPbtojson(
         service.login(loginRequestPb=builder))
    def countConsumer(builder):
        if (builder != None):
            m_converter = ConvertJSONToPb()
            builder = m_converter.converjsontoPBProper(
                response=builder,
                instanceType=consumersearch_pb2.ConsumerSearchRequestPb())

        service = ConsumerService()
        return service.count(builder=builder)
 def createRegistrationworker(builder):
     service = RegistrationWorkerService()
     m_converter = ConvertJSONToPb()
     m_convertPbtoJson = ConvertPbToJSON()
     builder = m_converter.converjsontoPBProper(
         response=builder,
         instanceType=registration_pb2.RegistrationRequestPb())
     return m_convertPbtoJson.converPbtojson(
         service.registration(registrationRequestPb=builder))
Exemple #6
0
class VerificationGetEntity:
    m_firebase = FirebaseDatabaseService()
    m_convertor = ConvertJSONToPb()

    id = None
    response = None

    def start(self, id):
        self.id = id
        self.controlFlow(currentState=States.GET_ENTITY)

    def done(self):
        return self.response

    def getEntity(self):
        resp = self.m_firebase.get(
            firebaseEnum=FirebaseEntityEnum.VERIFICATIONCODE.name, id=self.id)
        if (resp != None):
            self.response = resp
        self.controlFlow(currentState=States.CONVERT_TO_PB)

    def convertPb(self):
        resp = self.m_convertor.converjsontoPBProper(
            response=self.response, instanceType=VerificationPb())
        if (resp != None):
            self.response = resp
        self.controlFlow(currentState=States.DONE)

    def controlFlow(self, currentState):
        if (currentState == States.GET_ENTITY):
            self.getEntity()
        elif (currentState == States.CONVERT_TO_PB):
            self.convertPb()
        elif (currentState == States.DONE):
            self.done()
class GetWorkerTypeEntity:
    m_helper = EntityHelper()
    m_queryExecutor = QueryExecuter()
    m_converterPbToJson = ConvertPbToJSON()
    m_converterJsonToPb = ConvertJSONToPb()
    builder = None
    id = None

    def start(self, id):
        self.id = id
        self.controlFlow(currentState=States.GET_ENTITY_ID)

    def done(self):
        return self.builder

    def getEntityId(self):
        workerPb = self.m_queryExecutor.get(id=self.id,
                                            table=Tables.WORKER_TYPE.name)
        if (workerPb != None):
            self.builder = self.m_converterJsonToPb.converjsontoPBProper(
                response=workerPb, instanceType=workertype_pb2.WorkertypePb())
        self.controlFlow(currentState=States.DONE)

    def controlFlow(self, currentState):
        if (currentState == States.GET_ENTITY_ID):
            self.getEntityId()
        elif (currentState == States.DONE):
            self.done()
class GetPushNotificationEntity:
    m_helper = EntityHelper()
    m_queryExecutor = QueryExecuter()
    m_converterPbToJson = ConvertPbToJSON()
    m_converterJsonToPb = ConvertJSONToPb()
    builder = None
    id = None

    def start(self, id):
        self.id = id
        self.controlFlow(currentState=States.GET_ENTITY_ID)

    def done(self):
        return self.builder

    def getEntityId(self):
        pushNotificationPb = self.m_queryExecutor.get(
            id=self.id, table=Tables.PUSH_NOTIFICATON.name)
        if (pushNotificationPb != None):
            self.builder = self.m_converterJsonToPb.converjsontoPBProper(
                response=pushNotificationPb,
                instanceType=pushnotification_pb2.PushNotificationPb())
        self.controlFlow(currentState=States.DONE)

    def controlFlow(self, currentState):
        if (currentState == States.GET_ENTITY_ID):
            self.getEntityId()
        elif (currentState == States.DONE):
            self.done()
class CountConsumerEntity:
    m_queryExecutor = QueryExecuter()
    m_consumerserchreqPb = ConsumerSearchRequestPb()
    m_converterJsonToPb = ConvertJSONToPb()
    m_consumerserchresPb = ConsumerSearchResponsePb()
    m_countHandler = ConsumerCounter()

    builder = None

    def start(self, consumerSearchPb):
        self.builder = consumerSearchPb
        self.controlFlow(currentState=States.GET_COUNT)

    def done(self):
        return self.m_consumerserchresPb

    def getCount(self):
        consumerPb = self.m_countHandler.handle(consumerpb=self.builder)
        if (consumerPb != None):
            self.m_consumerserchresPb.summary.totalHits = consumerPb
        # self.m_queryExecutor.count(table, subquery)
        self.controlFlow(currentState=States.DONE)

    def controlFlow(self, currentState):
        if (currentState == States.GET_COUNT):
            self.getCount()
        elif (currentState == States.DONE):
            self.done()
Exemple #10
0
class ConsumerSearchEntity:
    m_helper = EntityHelper()
    m_query = QueryExecuter()
    m_searchHandler = ConsumerSearcher()
    m_converterPbtoJson = ConvertPbToJSON()
    m_converterJsonToPb = ConvertJSONToPb()
    builder = None
    id = None
    consumerResp = None
    consumerSearchResponse = ConsumerSearchResponsePb()

    def start(self, consumersearchreqPb):
        self.builder = consumersearchreqPb
        self.controlFlow(currentState=States.GET_SEARCH)

    def getSearch(self):
        consumerResp = self.m_searchHandler.handle(consumerpb=self.builder)
        if (consumerResp != None):
            self.consumerResp = consumerResp
        self.controlFlow(currentState=States.FORM_RESPONSE)

    def getFormResponse(self):
        if (self.consumerResp != None):
            self.consumerSearchResponse = self.m_helper.consumerRespose(
                consumerResp=self.consumerResp)
        self.controlFlow(currentState=States.DONE)

    def controlFlow(self, currentState):
        if (currentState == States.GET_SEARCH):
            self.getSearch()
        elif (currentState == States.FORM_RESPONSE):
            self.getFormResponse()
        elif (currentState == States.DONE):
            self.done()
Exemple #11
0
class UpdateLoginEntity:
    m_helper = EntityHelper()
    m_getEntity = GetLoginEntity()
    m_queryExecutor = QueryExecuter()
    m_converterPbToJson = ConvertPbToJSON()
    m_converterJsonToPb = ConvertJSONToPb()
    oldPb = None
    builder = None
    id = None

    def start(self, id, builder):
        self.id = id
        self.builder = builder
        self.controlFlow(currentState=States.GET_ENTITY_ID)

    def done(self):
        return self.builder

    def getEntityId(self):
        self.m_getEntity.start(id=self.id)
        self.oldPb = self.m_getEntity.done()
        self.controlFlow(currentState=States.UPDATE_ENTITY_ID)

    def updateEntity(self):
        newPb = self.m_queryExecutor.update(id=self.id,builder=self.builder,table=Tables.LOGIN.name)
        self.builder = newPb
        self.controlFlow(currentState=States.DONE)

    def controlFlow(self, currentState):
        if (currentState == States.GET_ENTITY_ID):
            self.getEntityId()
        elif (currentState == States.UPDATE_ENTITY_ID):
            self.updateEntity()
        elif (currentState == States.DONE):
            self.done()
Exemple #12
0
class GetQueryCF():
    m_id = None
    m_pb = None
    m_response = None
    m_table = None
    m_instance = None

    def __init__(self, instance, table):
        self.m_table = table
        self.m_instance = instance

    m_convertToPb = ConvertJSONToPb()
    m_getQueryExecutor = GetQueryExecutor()

    def start(self, id):
        self.m_id = id
        self.controlFlow(currentState=State.CHECK_ID_IS_EMPTY)

    def done(self):
        return self.m_pb

    def checkIdIsEmpty(self):
        if (self.m_id == None):
            assert True, "id Cannot be Empty"
        else:
            self.controlFlow(currentState=State.GET_FROM_DB)

    def getFromDb(self):
        resp = self.m_getQueryExecutor.get(id=self.m_id,
                                           table=self.m_table.tableName())
        if (resp != None):
            self.m_response = resp
            self.controlFlow(currentState=State.CONVERT_TO_PB)
        else:
            # self.controlFlow(currentState=State.DONE)
            raise Exception('id NOT_FOUND ' + self.m_id)

    def convertJsonToPb(self):
        self.m_pb = self.m_convertToPb.converjsontoPBProper(
            response=self.m_response, instanceType=self.m_instance)
        if (self.m_pb == None):
            raise Exception('Error while Converting to Pb' + self.m_response)
        else:
            self.controlFlow(currentState=State.DONE)

    def controlFlow(self, currentState):
        if (currentState == State.CHECK_ID_IS_EMPTY):
            self.checkIdIsEmpty()
        elif (currentState == State.GET_FROM_DB):
            self.getFromDb()
        elif (currentState == State.CONVERT_TO_PB):
            self.convertJsonToPb()
        elif (currentState == State.DONE):
            self.done()
class WorkerCache(BasicCache):
    m_workerService = WorkerService()
    m_convertorJsonToPb = ConvertJSONToPb()
    m_convertorPbToJson = ConvertPbToJSON()

    def getUnchecked(self, key):
        if (self.get(key=key) != None):
            return self.m_convertorJsonToPb.converjsontoPBProper(
                response=self.get(key=key), instanceType=worker_pb2.WorkerPb())
        else:
            self.set(key=key,
                     value=self.m_convertorPbToJson.converPbtojsonString(
                         builder=self.m_workerService.get(id=key)))
        return self.m_convertorJsonToPb.converjsontoPBProper(
            response=self.get(key=key), instanceType=worker_pb2.WorkerPb())
class UpdateConsumerEntity:
    m_helper = EntityHelper()
    m_getEntity = GetConsumerEntity()
    m_queryExecutor = QueryExecuter()
    m_converterPbToJson = ConvertPbToJSON()
    m_converterJsonToPb = ConvertJSONToPb()
    m_compareConsumerPb = ConsumerComparetor()
    oldPb = None
    builder = None
    id = None

    def start(self, id, builder):
        self.id = id
        self.builder = builder
        self.controlFlow(currentState=States.GET_ENTITY_ID)

    def done(self):
        return self.builder

    def getEntityId(self):
        self.m_getEntity.start(id=self.id)
        self.oldPb = self.m_getEntity.done()
        if (self.oldPb == None):
            self.controlFlow(currentState=States.DONE)
        self.controlFlow(currentState=States.COMPARE_PB)

    def comaprePb(self):
        self.m_compareConsumerPb.compareConsumerPb(oldPb=self.oldPb,
                                                   newPb=self.builder)
        self.controlFlow(currentState=States.UPDATE_ENTITY_ID)

    def updateEntity(self):
        newPb = self.m_queryExecutor.update(id=self.id,
                                            builder=self.builder,
                                            table=Tables.CONSUMER_DATA.name)
        self.builder = newPb
        self.controlFlow(currentState=States.DONE)

    def controlFlow(self, currentState):
        if (currentState == States.GET_ENTITY_ID):
            self.getEntityId()
        elif (currentState == States.COMPARE_PB):
            self.comaprePb()
        elif (currentState == States.UPDATE_ENTITY_ID):
            self.updateEntity()
        elif (currentState == States.DONE):
            self.done()
class PushNotificationSearchEntity:
    m_helper = EntityHelper()
    m_queryExecutor = QueryExecuter()
    m_searchHandler = PushNotificationSearcher()
    m_converterPbToJson = ConvertPbToJSON()
    m_converterJsonToPb = ConvertJSONToPb()
    builder = None
    id = None
    Resp = None
    pushNotificationSearchResponse = PushNotificationSearchResponsePb()

    def start(self, pushNotificationSearchReqPb):
        self.builder = pushNotificationSearchReqPb
        self.controlFlow(currentState=States.GET_SEARCH)

    def done(self):
        return self.Resp

    def getSearch(self):
        pushNotificatonResp = self.m_searchHandler.handle(
            pushNotificationSearchPb=self.builder)
        if (pushNotificatonResp != None):
            self.Resp = pushNotificatonResp
        self.controlFlow(currentState=States.FORM_RESPONSE)

    def getFormResponse(self):
        if (self.Resp != None):
            self.Resp = self.m_helper.pushNotificationResponse(
                pushNotificationResp=self.Resp)
        self.controlFlow(currentState=States.DONE)

    def controlFlow(self, currentState):
        if (currentState == States.GET_SEARCH):
            self.getSearch()
        elif (currentState == States.FORM_RESPONSE):
            self.getFormResponse()
        elif (currentState == States.DONE):
            self.done()
class WorkerTypeSearchEntity:
    m_helper = EntityHelper()
    m_queryExecutor = QueryExecuter()
    m_searchHandler = WorkerTypeSearcher()
    m_converterPbToJson = ConvertPbToJSON()
    m_converterJsonToPb = ConvertJSONToPb()
    builder = None
    id = None
    workerTypeResp = None
    workerTypeSearchResponse = WorkerTypeSearchResponsePb()

    def start(self, workerTypePb):
        self.builder = workerTypePb
        self.controlFlow(currentState=States.GET_SEARCH)

    def done(self):
        return self.workerTypeSearchResponse

    def getSearch(self):
        workerTypeResp = self.m_searchHandler.handle(workerTypepb=self.builder)
        if (workerTypeResp != None):
            self.workerTypeResp = workerTypeResp
        self.controlFlow(currentState=States.FORM_RESPONSE)

    def getFormResponse(self):
        if (self.workerTypeResp != None):
            self.workerTypeSearchResponse = self.m_helper.workerTypeResponse(
                workerTpeResp=self.workerTypeResp)
        self.controlFlow(currentState=States.DONE)

    def controlFlow(self, currentState):
        if (currentState == States.GET_SEARCH):
            self.getSearch()
        elif (currentState == States.FORM_RESPONSE):
            self.getFormResponse()
        elif (currentState == States.DONE):
            self.done()
Exemple #17
0
class SearchQueryResultFormatter:
    m_responseUipb = None
    m_uipb = None
    m_list = list()
    m_converterJsonToPb = ConvertJSONToPb()

    def __init__(self, responseUipb, uiPb):
        self.m_responseUipb = responseUipb
        self.m_uipb = uiPb
        self.m_list.clear()

    def formResponse(self, response):
        self.m_responseUipb.summary.totalHits = len(response)
        responseuipb = None
        for index, resp in enumerate(response):
            try:
                self.m_list.append(
                    copy.copy(
                        self.m_converterJsonToPb.converjsontoPBProper(
                            response=resp[0], instanceType=self.m_uipb)))
            except ValueError:
                pass
        self.m_responseUipb.results.extend(self.m_list)
        return self.m_responseUipb
 def searchWorkerType(builder):
     service = WorkerTypeService()
     m_converter = ConvertJSONToPb()
     builder = m_converter.converjsontoPBProper(response=builder,instanceType=workertype_pb2.WorkerTypeSearchRequestPb())
     return service.search(builder=builder)
Exemple #19
0
class GetOpreationInSimpleDbCF:
    m_domain_name = None
    m_id = None
    m_decodedData = None
    m_response = None
    m_pbInstance = None

    m_getAttribute = GetAttributeInSimpleDb()
    m_simpleDbOpreationHeper = SimpleDbOpreaTionHelper()
    m_decoder = EncryptorAndDecryptor()
    m_convertorPb = ConvertJSONToPb()

    def __init__(self, domain, pb):
        self.m_domain_name = domain
        self.m_pbInstance = pb

    def start(self, id):
        self.m_id = id
        self.controlFlow(currentState=State.CHECK_DOMAIN_IS_EMPTY)

    def done(self):
        return self.m_response

    def checkDominNameIsEmpty(self):
        if (Strings.isEmpty(self.m_domain_name)):
            raise Exception("domain name is Empty")
        else:
            self.controlFlow(currentState=State.ID_IS_EMPTY)

    def idIsEmpty(self):
        if (Strings.isEmpty(self.m_id)):
            raise Exception("Entity id is Empty")
        else:
            self.controlFlow(currentState=State.GET_ATTRIBUTES)

    def getAttribute(self):
        resp = self.m_getAttribute.getAttributes(
            domainName=self.m_domain_name.tableName(), id=self.m_id)
        if (resp == None):
            self.controlFlow(currentState=State.DONE)
        else:
            self.m_response = self.m_simpleDbOpreationHeper.getRawData(resp)
            self.controlFlow(currentState=State.DECODE_DATA)

    def decodeData(self):
        self.m_decodedData = self.m_decoder.decode(chiperText=self.m_response)
        self.controlFlow(currentState=State.GENREATE_PB)

    def genreatePb(self):
        self.m_response = self.m_convertorPb.converjsontoPB(
            response=self.m_decodedData, instanceType=self.m_pbInstance)
        self.controlFlow(currentState=State.DONE)

    def controlFlow(self, currentState):
        with switch(currentState) as s:
            s.case(State.CHECK_DOMAIN_IS_EMPTY, self.checkDominNameIsEmpty)
            s.case(State.ID_IS_EMPTY, self.idIsEmpty)
            s.case(State.GET_ATTRIBUTES, self.getAttribute)
            s.case(State.DECODE_DATA, self.decodeData)
            s.case(State.GENREATE_PB, self.genreatePb)
            s.case(State.DONE, self.done)
            s.default(self.done)
class UpdateQueryCF():
    m_id = None
    m_pb = None
    m_response = None
    m_pbFromDb = None
    m_json = None
    m_table = None
    m_instance = None
    m_convertor = None
    m_comparetor = None
    m_check = False

    def __init__(self, comparetor, convertor, instance, table):
        self.m_convertor = convertor
        self.m_comparetor = comparetor
        self.m_table = table
        self.m_instance = instance

    m_convertToPb = ConvertJSONToPb()
    m_convertToJson = ConvertPbToJSON()
    m_getQueryExecutor = GetQueryExecutor()
    m_updateQueryExecutor = UpdateQueryExecutor()

    def start(self, id, pb):
        self.m_id = id
        self.m_pb = pb
        self.controlFlow(currentState=State.CHECK_ID_IS_EMPTY)

    def done(self):
        return self.m_pbFromDb

    def checkIdIsEmpty(self):
        if (self.m_id == None):
            assert True, "id Cannot be Empty"
        else:
            self.controlFlow(currentState=State.CHECK_PB_IS_EMPTY)

    def checkPbIsEmpty(self):
        if (self.m_pb == None):
            assert True, "Pb Cannot be Empty"
        else:
            self.controlFlow(currentState=State.GET_FROM_DB)

    def getFromDb(self):
        resp = self.m_getQueryExecutor.get(id=self.m_id,
                                           table=self.m_table.tableName())
        if (resp != None):
            self.m_response = resp
            self.controlFlow(currentState=State.CONVERT_TO_PB)
        elif (self.m_pb.dbInfo.id != self.m_pbFromDb.dbInfo.id):
            raise Exception('id NOT_MATCHED you are updating wrong Entity ' +
                            MessageToJson(self.m_pb))
        else:
            # self.controlFlow(currentState=State.DONE)
            raise Exception('id NOT_FOUND or UNEXPECTED ERROR' + self.m_id)

    def convertJsonToPb(self):
        self.m_pbFromDb = self.m_convertToPb.converjsontoPBProper(
            response=self.m_response, instanceType=self.m_instance)
        if (self.m_pbFromDb == None):
            raise Exception('Error while Converting to Pb' + self.m_response)
        else:
            if (self.m_check):
                self.controlFlow(currentState=State.DONE)
            else:
                self.m_check = True
                self.controlFlow(currentState=State.COMPARE_BOTH_PBS)

    def comapreBothPbs(self):
        resp = self.m_comparetor.compare(newPb=self.m_pb,
                                         oldPb=self.m_pbFromDb)
        if (resp != None):
            self.m_pb = resp
            self.controlFlow(currentState=State.CONVERT_TO_JSON)
        else:
            raise Exception('UPDATE FAILED due to improper UiPb' +
                            MessageToJson(self.m_pb))

    def convertToJson(self):
        self.m_json = self.m_convertToJson.converPbtojsonString(
            builder=self.m_pb)
        if (self.m_json == None):
            raise Exception('Convert to json Failed' +
                            MessageToJson(self.m_pb))
        else:
            self.controlFlow(currentState=State.UPDATE_TO_DB)

    def updateToDb(self):
        resp = self.m_updateQueryExecutor.update(
            id=self.m_id, json=self.m_json, table=self.m_table.tableName())
        if (resp == None):
            raise Exception('Update to database Failed' +
                            MessageToJson(self.m_pb))
        else:
            self.controlFlow(currentState=State.GET_FROM_DB)

    def controlFlow(self, currentState):
        if (currentState == State.CHECK_ID_IS_EMPTY):
            self.checkIdIsEmpty()
        elif (currentState == State.CHECK_PB_IS_EMPTY):
            self.checkPbIsEmpty()
        elif (currentState == State.GET_FROM_DB):
            self.getFromDb()
        elif (currentState == State.CONVERT_TO_PB):
            self.convertJsonToPb()
        elif (currentState == State.COMPARE_BOTH_PBS):
            self.comapreBothPbs()
        elif (currentState == State.CONVERT_TO_JSON):
            self.convertToJson()
        elif (currentState == State.UPDATE_TO_DB):
            self.updateToDb()
        elif (currentState == State.DONE):
            self.done()
 def createWorker(builder):
     service = WorkerService()
     m_converter = ConvertJSONToPb()
     builder = m_converter.converjsontoPBProper(
         response=builder, instanceType=worker_pb2.WorkerPb())
     return service.create(builder=builder)
 def updateConsumer(builder):
     service = ConsumerService()
     m_converter = ConvertJSONToPb()
     builder = m_converter.converjsontoPBProper(
         response=builder, instanceType=consumer_pb2.ConsumerPb())
     return service.update(id=builder.dbInfo.id, builder=builder)
Exemple #23
0
class UpdatePushNotificationEntity:
    m_helper = EntityHelper()
    m_workerService = WorkerService()
    m_getEntity = GetPushNotificationEntity()
    m_queryExecutor = QueryExecuter()
    m_converterPbToJson = ConvertPbToJSON()
    m_converterJsonToPb = ConvertJSONToPb()
    m_comparePushNotificationPb = PushNotificationComparetor()
    oldPb = None
    builder = None
    id = None
    m_worker = None

    def start(self, id, builder):
        self.id = id
        self.builder = builder
        self.controlFlow(currentState=States.GET_ENTITY_ID)

    def done(self):
        return self.builder

    def getEntityId(self):
        self.m_getEntity.start(id=self.id)
        self.oldPb = self.m_getEntity.done()
        if (self.oldPb == None):
            self.controlFlow(currentState=States.DONE)
        self.controlFlow(currentState=States.COMPARE_PB)

    def comaprePb(self):
        self.m_comparePushNotificationPb.comaprePushNotifiactionPb(
            oldPb=self.oldPb, newPb=self.builder)
        self.controlFlow(currentState=States.UPDATE_ENTITY_ID)

    def updateEntity(self):
        newPb = self.m_queryExecutor.update(id=self.id,
                                            builder=self.builder,
                                            table=Tables.PUSH_NOTIFICATON.name)
        self.builder = newPb
        self.controlFlow(currentState=States.GET_WORKER)

    def getWorker(self):
        worker = self.m_workerService.get(id=self.builder.workerRef.dbInfo.id)
        if (worker != None):
            self.m_worker = worker
        self.controlFlow(currentState=States.UPDATE_PUSHNOTIFICATION_IN_WORKER)

    def updateWorker(self):
        self.m_worker.pushNotificationRef.name.canonicalName = self.builder.tokenId
        worker = self.m_workerService.update(id=self.m_worker.dbInfo.id,
                                             builder=self.m_worker)
        if (worker != None):
            self.m_worker = worker
        self.controlFlow(currentState=States.DONE)

    def controlFlow(self, currentState):
        if (currentState == States.GET_ENTITY_ID):
            self.getEntityId()
        elif (currentState == States.COMPARE_PB):
            self.comaprePb()
        elif (currentState == States.UPDATE_ENTITY_ID):
            self.updateEntity()
        elif (currentState == States.GET_WORKER):
            self.getWorker()
        elif (currentState == States.UPDATE_PUSHNOTIFICATION_IN_WORKER):
            self.updateWorker()
        elif (currentState == States.DONE):
            self.done()
class GetItemOpreationInDynamoDbCF:
    m_table_name = None
    m_id = None
    m_decodedData = None
    m_response = None
    m_pbInstance = None

    m_getAttribute = GetItemInDynamodb()
    m_dynamoDbOpreationHelper = DynamoDbOpreationHelper()
    m_decoder = EncryptorAndDecryptor()
    m_convertorPb = ConvertJSONToPb()
    m_keyMapper = GetKeyMapper()

    def __init__(self, table, pb):
        self.m_table_name = table
        self.m_pbInstance = pb

    def start(self, id):
        self.m_id = id
        self.controlFlow(currentState=State.CHECK_TABLE_IS_EMPTY)

    def done(self):
        return self.m_response

    def checkDominNameIsEmpty(self):
        if (Strings.isEmpty(self.m_table_name)):
            raise Exception("table name is Empty")
        else:
            self.controlFlow(currentState=State.ID_IS_EMPTY)

    def idIsEmpty(self):
        if (Strings.isEmpty(self.m_id)):
            raise Exception("Entity id is Empty")
        else:
            self.controlFlow(currentState=State.GET_ATTRIBUTES)

    def getAttribute(self):
        resp = self.m_getAttribute.get_item(
            tableName=self.m_table_name.tableName(),
            key=self.m_keyMapper.getKey(
                id=self.m_id, keyType=self.m_table_name.tableKeySchemaType()))
        if (resp == None):
            self.controlFlow(currentState=State.DONE)
        else:
            self.m_response = self.m_dynamoDbOpreationHelper.getRawData(resp)
            self.controlFlow(currentState=State.DECODE_DATA)

    def decodeData(self):
        self.m_decodedData = self.m_decoder.decode(chiperText=self.m_response)
        self.controlFlow(currentState=State.GENREATE_PB)

    def genreatePb(self):
        self.m_response = self.m_convertorPb.converjsontoPB(
            response=self.m_decodedData, instanceType=self.m_pbInstance)
        self.controlFlow(currentState=State.DONE)

    def controlFlow(self, currentState):
        with switch(currentState) as s:
            s.case(State.CHECK_TABLE_IS_EMPTY, self.checkDominNameIsEmpty)
            s.case(State.ID_IS_EMPTY, self.idIsEmpty)
            s.case(State.GET_ATTRIBUTES, self.getAttribute)
            s.case(State.DECODE_DATA, self.decodeData)
            s.case(State.GENREATE_PB, self.genreatePb)
            s.case(State.DONE, self.done)
            s.default(self.done)
Exemple #25
0
import bcrypt

from CommonCode.convertJSONTOPb import ConvertJSONToPb
from Services.loginModuleService import LoginModuleService
from protobuff.login_pb2 import LoginRequestPb
from protobuff.persontypeenum_pb2 import WORKER

#'$2b$12$uJFeZ8ZldnTETF6C8tTMteLGrOi0DEsDsQB.xVvZBzZJO5vErm3sa'
m_loginService = LoginModuleService()
m_loginReq = LoginRequestPb()
m_loginReq.login.contactDetails.email.localPart = "e";
m_loginReq.login.contactDetails.email.domain = "e.e";
m_loginReq.login.password = "******";
m_loginReq.login.personType.personType = WORKER;
m_converter = ConvertJSONToPb()
print(m_loginReq)
Exemple #26
0
class EntityHelper:
    m_converterJsonToPb = ConvertJSONToPb()
    workerlist = list()
    pushNotificationList = list()
    consumerlist = list()
    loginlist = list()
    workerTypelist = list()

    def createEntity(self, id, builder):
        builder.dbInfo.id = id
        builder.dbInfo.lifeTime = ACTIVE
        return builder

    def comapreIds(self, id1, id2):
        if (id1 == id2):
            return False
        else:
            return True

    def workerResponse(self, workerResp):
        self.workerlist.clear()
        workerSearchResponse = WorkerSearchResponsePb()
        workerSearchResponse.summary.totalHits = len(workerResp)
        for index, worker in enumerate(workerResp):
            # workerSearchResponse.results.add()
            try:
                self.workerlist.append(
                    self.m_converterJsonToPb.converjsontoPBProper(
                        response=worker[0],
                        instanceType=worker_pb2.WorkerPb()))
            except ValueError:
                pass
        workerSearchResponse.results.extend(self.workerlist)
        return workerSearchResponse

    def consumerRespose(self, consumerResp):
        self.consumerlist.clear()
        consumerSerchResponse = ConsumerSearchResponsePb()
        consumerSerchResponse.summary.totalHits = len(consumerResp)
        for index, consumer in enumerate(consumerResp):
            # ConumerSearchResponse.results.add()
            try:
                self.workerlist.append(
                    self.m_converterJsonToPb.converjsontoPBProper(
                        response=consumer[0],
                        instanceType=consumer_pb2.ConsumerPb()))
            except ValueError:
                pass
        consumerSerchResponse.results.extend(self.workerlist)
        return consumerSerchResponse

    def workerTypeResponse(self, workerTpeResp):
        self.workerTypelist.clear()
        workerTyepSearchResponse = WorkerTypeSearchResponsePb()
        workerTyepSearchResponse.summary.totalHits = len(workerTpeResp)
        for index, worker in enumerate(workerTpeResp):
            # workerSearchResponse.results.add()
            try:
                self.workerTypelist.append(
                    self.m_converterJsonToPb.converjsontoPBProper(
                        response=worker[0],
                        instanceType=workertype_pb2.WorkerTypePb()))
            except ValueError:
                pass
        workerTyepSearchResponse.results.extend(self.workerTypelist)
        return workerTyepSearchResponse

    def loginResponse(self, loginResp):
        self.pushNotificationList.clear()
        loginSearchResponse = LoginSearchRespsonsePb()
        loginSearchResponse.summary.totalHits = len(loginResp)
        for index, login in enumerate(loginResp):
            # workerSearchResponse.results.add()
            try:
                self.pushNotificationList.append(
                    self.m_converterJsonToPb.converjsontoPBProper(
                        response=login[0], instanceType=login_pb2.LoginPb()))
            except ValueError:
                pass
        loginSearchResponse.results.extend(self.pushNotificationList)
        return loginSearchResponse

    def pushNotificationResponse(self, pushNotificationResp):
        self.pushNotificationList.clear()
        pushNotificationSearchResponse = PushNotificationSearchResponsePb()
        pushNotificationSearchResponse.summary.totalHits = len(
            pushNotificationResp)
        for index, pushNotification in enumerate(pushNotificationResp):
            # workerSearchResponse.results.add()
            try:
                self.pushNotificationList.append(
                    self.m_converterJsonToPb.converjsontoPBProper(
                        response=pushNotification[0],
                        instanceType=pushnotification_pb2.PushNotificationPb())
                )
            except ValueError:
                pass
        pushNotificationSearchResponse.results.extend(
            self.pushNotificationList)
        return pushNotificationSearchResponse
Exemple #27
0
class RequestHandlerCF(ErrorResponder):
    m_request = None
    m_service = None
    m_response = None
    m_finalresponse = None
    m_searchRequest = None
    m_uipb = None;
    m_method = None
    m_requestType = None
    m_requestData = None
    m_error = None
    m_requestUiPb = None

    m_requestHandlerHelper = ResponseHandlerHelper()
    m_convertToUipb = ConvertJSONToPb()

    def __init__(self, service, uipb, searchRequestUipb):
        self.m_service = service
        self.m_uipb = uipb
        self.m_searchRequest = searchRequestUipb

    def start(self, request):
        self.m_request = request
        self.controlFlow(currentState=State.CHECK_TYPE_OF_REQ_METHOD)

    def done(self):
        if (self.m_finalresponse == None):
            return self.m_error
        else:
            return self.m_finalresponse

    def checkReqEmpty(self):
        if (Strings.isEmpty(self.m_request.full_path)):
            self.m_error = self.throw(errorTypeEnum=INPUT_ERROR, errorString="Input cannot be Empty or Wrong")
            self.controlFlow(currentState=State.DONE)
        else:
            self.m_requestData = self.m_requestHandlerHelper.getRequestData(request=self.m_request)
            self.controlFlow(currentState=State.IF_GET_CHECK_REQ_JSON)

    def checkTypeOfMethod(self):
        self.m_method = self.m_request.method
        if (Strings.areEquals(self.m_method, RequestMethodTypeEnum.PUT.name)):
            self.m_requestType = RequestTypeEnum.UPDATE
            self.controlFlow(currentState=State.COVERT_TO_UIPB)
        elif (Strings.areEquals(self.m_method, RequestMethodTypeEnum.POST.name)):
            self.m_requestType = RequestTypeEnum.CREATE
            self.controlFlow(currentState=State.COVERT_TO_UIPB)
        self.controlFlow(currentState=State.CHECK_IS_REQ_EMPTY)

    def checkIsJsonAndValid(self):
        data = self.m_requestHandlerHelper.isJson(json=self.m_requestData)
        if (data == None):
            self.m_error = self.throw(errorTypeEnum=INPUT_VALIDATION_ERROR,
                                      errorString="Input cannot be Empty or Wrong")
            self.controlFlow(currentState=State.DONE)
        elif (data == True):
            self.m_requestType = RequestTypeEnum.SEARCH
            self.controlFlow(currentState=State.COVERT_TO_UIPB)
        elif (data == JSON_VALIDATION_ERROR):
            self.m_error = self.throw(errorTypeEnum=JSON_VALIDATION_ERROR,
                                      errorString="Wrong Json")
            self.controlFlow(currentState=State.DONE)
        elif (data == False):
            self.m_requestType = RequestTypeEnum.GET
            self.controlFlow(currentState=State.DO_WORK)

    def convertToUipb(self):
        if (self.m_requestType == RequestTypeEnum.SEARCH):
            self.m_requestUiPb = self.m_convertToUipb.converjsontoPBProper(response=self.m_requestData,
                                                                           instanceType=self.m_searchRequest)
        elif (self.m_requestType == RequestTypeEnum.UPDATE):
            self.m_requestUiPb = self.m_convertToUipb.converjsontoPBProper(response=self.m_request.json,
                                                                           instanceType=self.m_uipb)
        elif (self.m_requestType == RequestTypeEnum.CREATE):
            self.m_requestUiPb = self.m_convertToUipb.converjsontoPBProper(response=self.m_request.json,
                                                                           instanceType=self.m_uipb)
        else:
            self.m_requestUiPb = self.m_convertToUipb.converjsontoPBProper(response=self.m_requestData,
                                                                           instanceType=self.m_uipb)
        self.controlFlow(currentState=State.DO_WORK)

    def doWork(self):
        if (self.m_requestType == RequestTypeEnum.GET):
            self.m_response = self.m_service.get(id=self.m_requestData)
            self.controlFlow(currentState=State.RETURN_RESPONSE)
        elif (self.m_requestType == RequestTypeEnum.UPDATE):
            self.m_response = self.m_service.update(self.m_requestUiPb.dbInfo.id, self.m_requestUiPb)
            self.controlFlow(currentState=State.RETURN_RESPONSE)
        elif (self.m_requestType == RequestTypeEnum.CREATE):
            self.m_response = self.m_service.create(self.m_requestUiPb)
            self.controlFlow(currentState=State.RETURN_RESPONSE)
        elif (self.m_requestType == RequestTypeEnum.SEARCH):
            self.m_response = self.m_service.search(self.m_requestUiPb)
            self.controlFlow(currentState=State.RETURN_RESPONSE)
        else:
            self.m_error = self.throw(errorTypeEnum=UN_EXPECTED_ERROR,
                                      errorString="No such type of service")
            self.controlFlow(currentState=State.DONE)

    def returnResponse(self):
        if (self.m_response != None):
            self.m_finalresponse = self.m_requestHandlerHelper.sendValidResponse(uipb=self.m_response)
        else:
            self.m_error = self.throw(errorTypeEnum=INVALID_RESPONSE,
                                      errorString="Invalid response formed");
        self.controlFlow(currentState=State.DONE)

    def controlFlow(self, currentState):
        with switch(currentState) as s:
            s.case(State.CHECK_IS_REQ_EMPTY, self.checkReqEmpty)
            s.case(State.CHECK_TYPE_OF_REQ_METHOD, self.checkTypeOfMethod)
            s.case(State.IF_GET_CHECK_REQ_JSON, self.checkIsJsonAndValid)
            s.case(State.COVERT_TO_UIPB, self.convertToUipb)
            s.case(State.DO_WORK, self.doWork)
            s.case(State.RETURN_RESPONSE, self.returnResponse)
            s.default(self.done)
 def updateWorkerType(builder):
     service = WorkerTypeService()
     m_converter = ConvertJSONToPb()
     builder = m_converter.converjsontoPBProper(response=builder,instanceType=workertype_pb2.WorkertypePb())
     return service.update(id=builder.dbInfo.id,builder=builder)
Exemple #29
0
class CreateQueryCF():
    m_pb = None
    m_pbFromDb = None
    m_response = None
    m_instance = None
    m_table = None

    def __init__(self, instance, table):
        self.m_table = table
        self.m_instance = instance

    m_convertToPb = ConvertJSONToPb()
    m_convertToJson = ConvertPbToJSON()
    m_getQueryExecutor = GetQueryExecutor()
    m_createQueryExecutor = CreateQueryExecuter()

    def start(self, m_pb):
        self.m_pb = m_pb
        self.controlFlow(currentState=State.CHECK_UIPB_IS_EMPTY)

    def done(self):
        return self.m_pbFromDb

    def checkUiPbIsEmpty(self):
        if (self.m_pb == None):
            assert True, "table Name Cannot be Empty"
        else:
            self.controlFlow(currentState=State.CONVERT_TO_JSON)

    def convertToJson(self):
        self.m_response = self.m_convertToJson.converPbtojsonString(
            builder=self.m_pb)
        if (self.m_response != None):
            self.controlFlow(currentState=State.INSERT_TO_DB)
        else:
            # self.controlFlow(currentState=State.DONE)
            raise Exception('Convert to json Failed' +
                            MessageToJson(self.m_pb))

    def insertInDb(self):
        resp = self.m_createQueryExecutor.create(
            id=self.m_pb.dbInfo.id,
            json=self.m_response,
            table=self.m_table.tableName())
        if (resp == None):
            # self.controlFlow(currentState=State.DONE)
            raise Exception('Insert to json Failed' + MessageToJson(self.m_pb))
        else:
            self.m_response = resp
            self.controlFlow(currentState=State.GET_FROM_DB)

    def getFromDb(self):
        resp = self.m_getQueryExecutor.get(id=self.m_pb.dbInfo.id,
                                           table=self.m_table.tableName())
        if (resp != None):
            self.m_response = resp
            self.controlFlow(currentState=State.CONVERT_TO_PB)
        else:
            # self.controlFlow(currentState=State.DONE)
            raise Exception('id NOT_FOUND or UNEXPECTED ERROR' +
                            self.m_pb.dbInfo.id)

    def convertJsonToPb(self):
        self.m_pbFromDb = self.m_convertToPb.converjsontoPBProper(
            response=self.m_response, instanceType=self.m_instance)
        if (self.m_pbFromDb == None):
            raise Exception('Error while Converting to Pb' + self.m_response)
        else:
            self.controlFlow(currentState=State.DONE)

    def controlFlow(self, currentState):
        if (currentState == State.CHECK_UIPB_IS_EMPTY):
            self.checkUiPbIsEmpty()
        elif (currentState == State.CONVERT_TO_JSON):
            self.convertToJson()
        elif (currentState == State.INSERT_TO_DB):
            self.insertInDb()
        elif (currentState == State.GET_FROM_DB):
            self.getFromDb()
        elif (currentState == State.CONVERT_TO_PB):
            self.convertJsonToPb()
        elif (currentState == State.DONE):
            self.done()
Exemple #30
0
 def searchPushNotification(builder):
     service = PushNotificationService()
     m_converter = ConvertJSONToPb()
     builder = m_converter.converjsontoPBProper(response=builder,
                                                instanceType=pushnotification_pb2.PushNotificationSearchRequestPb())
     return service.search(builder=builder)