def list_shared_method_groups(kbxGroupId, 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) kbxGroupIds = set(kbxGroupId) publicGroupIds, privateGroupIds = [ gId for gId in kbxGroupIds if gId > 0 ], (gId for gId in kbxGroupIds if gId < 0) finalGroupList = deque() publicGroupIdsLen = len(publicGroupIds) if publicGroupIdsLen > 0: result = SharedMethod.list_shared_method_groups( kbxGroupId=publicGroupIds, limit=publicGroupIdsLen, language=language, **kwargs) finalGroupList.extend(result["groupList"]) for privateGroupId in privateGroupIds: privateGroup = SharedMethodWrapper.PRIVATE_GROUPS.get( privateGroupId) if privateGroup is not None: privateGroup["kbxGroupLabel"] = str( privateGroup["kbxGroupLabel"]) finalGroupList.append(privateGroup) return finalGroupList
def update_kbx_group(self): ''' Updates information where necessary only. ''' result = self.__db.execute_and_fetch_all( 'SELECT "kbxGroupId" FROM "kbx_group" WHERE "kbxGroupId" > 0') if len(result) == 0: return kbxGroupIds = set([]) for row in result: kbxGroupId = row["kbxGroupId"] kbxGroupIds.add(kbxGroupId) result = SharedMethod.list_shared_method_groups( kbxGroupId=list(kbxGroupIds), enableTagCount=False, limit=len(kbxGroupIds)) kbxGroups = result["groupList"] for kbxGroup in kbxGroups: # Variables kbxGroupId = kbxGroup["kbxGroupId"] kbxGroupIds.remove(kbxGroupId) self.__groupController.update(kbxGroup) for kbxGroupId in kbxGroupIds: self.__groupController.delete(kbxGroupId)
def update_kbx_group(self): ''' Updates information where necessary only. ''' result = self.__db.execute_and_fetch_all('SELECT "kbxGroupId" FROM "kbx_group" WHERE "kbxGroupId" > 0') if len(result) == 0: return kbxGroupIds = set([]) for row in result: kbxGroupId = row["kbxGroupId"] kbxGroupIds.add(kbxGroupId) result = SharedMethod.list_shared_method_groups(kbxGroupId=list(kbxGroupIds), enableTagCount=False, limit=len(kbxGroupIds)) kbxGroups = result["groupList"] for kbxGroup in kbxGroups: # Variables kbxGroupId = kbxGroup["kbxGroupId"] kbxGroupIds.remove(kbxGroupId) self.__groupController.update(kbxGroup) for kbxGroupId in kbxGroupIds: self.__groupController.delete(kbxGroupId)
def list_shared_method_groups(kbxGroupId, 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) kbxGroupIds = set(kbxGroupId) publicGroupIds, privateGroupIds = [gId for gId in kbxGroupIds if gId > 0], (gId for gId in kbxGroupIds if gId < 0) finalGroupList = deque() publicGroupIdsLen = len(publicGroupIds) if publicGroupIdsLen > 0: result = SharedMethod.list_shared_method_groups(kbxGroupId=publicGroupIds, limit=publicGroupIdsLen, language=language, **kwargs) finalGroupList.extend(result["groupList"]) for privateGroupId in privateGroupIds: privateGroup = SharedMethodWrapper.PRIVATE_GROUPS.get(privateGroupId) if privateGroup is not None: privateGroup["kbxGroupLabel"] = str(privateGroup["kbxGroupLabel"]) finalGroupList.append(privateGroup) return finalGroupList
def list_groups(self, language, section, parentId=None): try: def sort_group_list(value): name = value.get("kbxGroupLabel") if name is None: return "" else: return str(name).lower() unknownGroupDict = {} unknownGroupId = self.__get_group_ids() parentId = AppConstants.GROUP_ID_AUTOMATION if parentId is None else parentId result = SharedMethod.list_shared_method_groups(kbxGroupParentId=parentId, kbxMethodTag=section, enableTagCount=True, language=language) groupList = result["groupList"] # Level 1 groups which contain of SERVICES and LOCATIONS. if parentId == AppConstants.GROUP_ID_AUTOMATION: services = deque() groups = deque() for groupDict in groupList: kbxGroupId = groupDict["kbxGroupId"] # Add indicator for UI groupDict["kbxGroupHasChild"] = True # Reordering if kbxGroupId == AppConstants.GROUP_ID_NOTIFICATION: groupDict["kbxGroupDesc"] = KBXLang("group_notification_" + section) services.appendleft(groupDict) elif kbxGroupId == AppConstants.GROUP_ID_SERVICE: groupDict["kbxGroupDesc"] = KBXLang("group_service_" + section) services.append(groupDict) elif kbxGroupId == unknownGroupId: #append the group dict unknownGroupDict = groupDict else: groups.append(groupDict) groups = sorted(groups, key=sort_group_list) if len(unknownGroupDict) > 0: groups.append(unknownGroupDict) services.extend(groups) groupList = services parentGroup = None # Level 2 groups which are DEVICES or SERVICES. else: parentGroup = SharedMethod.get_shared_method_group_by_id(kbxGroupId=parentId, language=language) return parentGroup, groupList except Exception as e: Logger.log_error("APIService.list_groups ex:", e) raise AutomationException(11601, "Unexpected error - " + str(e))
def __get_group_ids(self): try: if AppConstants.GROUP_ID_UNKNOWN_LOCATION is None: systemId = SharedMethod.get_system_id() results = SharedMethod.list_shared_method_groups(kbxGroupAppId=[systemId], kbxGroupParentId=AppConstants.GROUP_ID_AUTOMATION) #groups = {group.get("kbxGroupName", "_"):group.get("kbxGroupId") for group in results["groupList"]} for group in results["groupList"]: if group.get("otherLocation") == True: AppConstants.GROUP_ID_UNKNOWN_LOCATION = group.get("kbxGroupId") break return AppConstants.GROUP_ID_UNKNOWN_LOCATION except Exception as e: raise e
def __get_default_group_ids(self): try: systemId = SharedMethod.get_system_id() results = SharedMethod.list_shared_method_groups(kbxGroupAppId=[systemId], kbxGroupName=["automation_app", "notification", "service"]) groups = {group.get("kbxGroupName", "_"):group.get("kbxGroupId") for group in results["groupList"]} AppConstants.GROUP_ID_AUTOMATION = groups["automation_app"] AppConstants.GROUP_ID_NOTIFICATION = groups["notification"] AppConstants.GROUP_ID_SERVICE = groups["service"] except Exception as e: Logger.log_error("AutomationApp on_system_connected retrying __get_default_group_ids, ex:", e) traceback.print_exc() raise e
def __get_default_group_ids(self): try: systemId = SharedMethod.get_system_id() results = SharedMethod.list_shared_method_groups( kbxGroupAppId=[systemId], kbxGroupName=["automation_app", "notification", "service"]) groups = { group.get("kbxGroupName", "_"): group.get("kbxGroupId") for group in results["groupList"] } AppConstants.GROUP_ID_AUTOMATION = groups["automation_app"] AppConstants.GROUP_ID_NOTIFICATION = groups["notification"] AppConstants.GROUP_ID_SERVICE = groups["service"] except Exception as e: Logger.log_error( "AutomationApp on_system_connected retrying __get_default_group_ids, ex:", e) traceback.print_exc() raise e