Ejemplo n.º 1
0
    def list_shared_methods(kbxMethodId,
                            language=AppInfo.DEFAULT_API_LANGUAGE,
                            limit=100,
                            **kwargs):
        '''
        limit - This will be override no matter what. Do not pass any argument for it.
        '''
        KBXLang.set_preferred_lang(language)

        kbxMethodIds = set(kbxMethodId)
        publicMethodIds, privateMethodIds = [
            mId for mId in kbxMethodIds if mId > 0
        ], (mId for mId in kbxMethodIds if mId < 0)
        finalMethodList = deque()

        publicMethodIdsLen = len(publicMethodIds)
        if publicMethodIdsLen > 0:
            result = SharedMethod.list_shared_methods(
                kbxMethodId=publicMethodIds,
                limit=publicMethodIdsLen,
                language=language,
                **kwargs)
            finalMethodList.extend(result["methodList"])

        for privateMethodId in privateMethodIds:
            privateMethod = SharedMethodWrapper.PRIVATE_METHODS.get(
                privateMethodId)
            if privateMethod is not None:
                privateMethod["kbxMethodLabel"] = str(
                    privateMethod["kbxMethodLabel"])
                finalMethodList.append(privateMethod)

        return finalMethodList
Ejemplo n.º 2
0
 def update_kbx_method(self):
     '''
     Update information of kbxMethod.
     Add and remove group ID if kbxGroupId is updated.
     Add listener if necessary.
     '''
     result = self.__db.execute_and_fetch_all('SELECT "kbxMethodId" FROM "kbx_method" WHERE "kbxMethodId" > 0')
     
     if len(result) == 0:
         return
     
     kbxMethodIds = set([])
     
     for row in result:
         kbxMethodId = row["kbxMethodId"]
         kbxMethodIds.add(kbxMethodId)
     
     result = SharedMethod.list_shared_methods(kbxMethodId=list(kbxMethodIds), 
                                               kbxMethodStatus=[SharedMethod.METHOD_STATUS_ACTIVE, SharedMethod.METHOD_STATUS_INACTIVE], 
                                               limit=len(kbxMethodIds))
     kbxMethods = result["methodList"]
     for kbxMethod in kbxMethods:
         # Variables
         kbxMethodId = kbxMethod["kbxMethodId"]
         
         kbxMethodIds.remove(kbxMethodId) # For each kbxMethod which has result when listing from system, pop it out from kbxMethodsFromDB
         self.__methodController.update(kbxMethod)
         
     # The kbxMethodIds left here are all removed methods.
     for kbxMethodId in kbxMethodIds:
         self.__methodController.delete(kbxMethodId)
Ejemplo n.º 3
0
    def list_shared_methods(kbxMethodId, language=AppInfo.DEFAULT_API_LANGUAGE, limit=100, **kwargs):
        '''
        limit - This will be override no matter what. Do not pass any argument for it.
        '''
        KBXLang.set_preferred_lang(language)
        
        kbxMethodIds = set(kbxMethodId)
        publicMethodIds, privateMethodIds = [mId for mId in kbxMethodIds if mId > 0], (mId for mId in kbxMethodIds if mId < 0)
        finalMethodList = deque()
        
        publicMethodIdsLen = len(publicMethodIds)
        if publicMethodIdsLen > 0:
            result = SharedMethod.list_shared_methods(kbxMethodId=publicMethodIds, 
                                                      limit=publicMethodIdsLen, 
                                                      language=language, 
                                                      **kwargs)
            finalMethodList.extend(result["methodList"])

        for privateMethodId in privateMethodIds:
            privateMethod = SharedMethodWrapper.PRIVATE_METHODS.get(privateMethodId)
            if privateMethod is not None:
                privateMethod["kbxMethodLabel"] = str(privateMethod["kbxMethodLabel"])
                finalMethodList.append(privateMethod)
                
        return finalMethodList
Ejemplo n.º 4
0
    def update_kbx_method(self):
        '''
        Update information of kbxMethod.
        Add and remove group ID if kbxGroupId is updated.
        Add listener if necessary.
        '''
        result = self.__db.execute_and_fetch_all(
            'SELECT "kbxMethodId" FROM "kbx_method" WHERE "kbxMethodId" > 0')

        if len(result) == 0:
            return

        kbxMethodIds = set([])

        for row in result:
            kbxMethodId = row["kbxMethodId"]
            kbxMethodIds.add(kbxMethodId)

        result = SharedMethod.list_shared_methods(
            kbxMethodId=list(kbxMethodIds),
            kbxMethodStatus=[
                SharedMethod.METHOD_STATUS_ACTIVE,
                SharedMethod.METHOD_STATUS_INACTIVE
            ],
            limit=len(kbxMethodIds))
        kbxMethods = result["methodList"]
        for kbxMethod in kbxMethods:
            # Variables
            kbxMethodId = kbxMethod["kbxMethodId"]

            kbxMethodIds.remove(
                kbxMethodId
            )  # For each kbxMethod which has result when listing from system, pop it out from kbxMethodsFromDB
            self.__methodController.update(kbxMethod)

        # The kbxMethodIds left here are all removed methods.
        for kbxMethodId in kbxMethodIds:
            self.__methodController.delete(kbxMethodId)
Ejemplo n.º 5
0
    def list_methods(self, language, section, groupId):
        try:
            result = SharedMethod.list_shared_methods(kbxGroupId=groupId,
                                                      kbxMethodTag=section,
                                                      kbxMethodStatus=[SharedMethod.METHOD_STATUS_ACTIVE, SharedMethod.METHOD_STATUS_INACTIVE],
                                                      language=language)

            methodList = result["methodList"]

            #===================================================================
            # Get group information
            #===================================================================
            groupDict = SharedMethod.get_shared_method_group_by_id(kbxGroupId=groupId, language=language)
            
            # Append "kbxMethodHasEvent" indicator.
            for kbxMethod in methodList:
                kbxMethodEvent = kbxMethod.get("kbxMethodEvent")
                kbxMethodIdentifier = kbxMethod.get("kbxMethodIdentifier")
                kbxMethod["kbxMethodHasEvent"] = not Util.is_empty(kbxMethodEvent) and not Util.is_empty(kbxMethodIdentifier)

            return methodList, groupDict
        except Exception as e:
            Logger.log_error("APIService.list_methods ex:", e)
            raise AutomationException(11601, "Unexpected error - " + str(e))