def _init_variables(self, project_id, **kwargs): super()._init_variables(**kwargs) self.subscription_id = kwargs.get('id') self.editable = kwargs.get('editable') self.allow_delivery_changes = kwargs.get('allow_delivery_changes') self.allow_personalization_changes = kwargs.get( 'allow_personalization_changes') self.allow_unsubscribe = kwargs.get('allow_unsubscribe') self.date_created = time_helper.map_str_to_datetime( "date_created", kwargs.get("date_created"), self._FROM_DICT_MAP) self.date_modified = time_helper.map_str_to_datetime( "date_modified", kwargs.get("date_modified"), self._FROM_DICT_MAP) self.owner = User.from_dict( kwargs.get('owner'), self.connection) if kwargs.get('owner') else None self.schedules = [ Schedule.from_dict(schedule, self._connection) for schedule in kwargs.get('schedules') ] if kwargs.get('schedules') else None self.contents = [ Content.from_dict(content, self._connection) for content in kwargs.get('contents') ] if kwargs.get('contents') else None self.recipients = kwargs.get('recipients', None) self.delivery = Delivery.from_dict( kwargs.get('delivery')) if kwargs.get('delivery') else None self.project_id = project_id
def __change_delivery_properties( self, mode=None, expiration=None, contact_security=None, subject: str = None, message: str = None, filename: str = None, compress: bool = None, zip_settings: ZipSettings = None, password: str = None, password_protect: bool = None, space_delimiter: str = None, send_content_as: SendContentAs = None, overwrite_older_version: bool = None, burst_sub_folder: str = None, copies: int = None, range_start: int = None, range_end: int = None, collated: bool = None, orientation: Orientation = None, use_print_range: bool = None, cache_type: CacheType = None, shortcut_cache_format: ShortcutCacheFormat = None, client_type: ClientType = None, device_id: str = None, do_not_create_update_caches: bool = None, re_run_hl: bool = None): func = self.__change_delivery_properties args = func.__code__.co_varnames[:func.__code__.co_argcount] defaults = func.__defaults__ default_dict = dict(zip(args[-len(defaults):], defaults)) if defaults else {} local = locals() # create dict of properties to be changed properties = {} for property_key in default_dict.keys(): if local[property_key] is not None: properties[property_key] = local[property_key] temp_delivery = self.delivery not_changed = {} obj_dict = self._delivery.VALIDATION_DICT obj_mode_dict = self._delivery.__dict__[temp_delivery['mode'].lower()].VALIDATION_DICT obj_mode_zip_dict = { "filename": str, "password": str, "password_protect": bool, } # if any not None values if properties: # check if key is in delivery dict for key, value in properties.items(): if temp_delivery.get(key) != value and key in obj_dict.keys(): temp_delivery[key] = value elif key in obj_mode_dict.keys(): check = temp_delivery[temp_delivery['mode'].lower()] if check.get(key) and check.get( key) != value: # if we have key and value is different check[key] = value elif not check.get(key): # if we don't have key but it can be here # if key == 'filename' and compress == False: check[key] = value elif temp_delivery[temp_delivery['mode'].lower()].get('zip'): if temp_delivery[temp_delivery['mode'].lower()].get('zip').get( key) != value and key in obj_mode_zip_dict.keys(): temp_delivery[temp_delivery['mode'].lower()]['zip'][key] = value elif key in obj_mode_zip_dict.keys(): temp_delivery[temp_delivery['mode'].lower()]['zip'] = {} temp_delivery[temp_delivery['mode'].lower()]['zip'][key] = value return Delivery.from_dict(temp_delivery)
def __fetch(self): """Retrieve object metadata.""" response = subscriptions.get_subscription(self.connection, self.id, self.application_id) if response.ok: response = response.json() response = helper.camel_to_snake(response) for key, value in response.items(): self._AVAILABLE_ATTRIBUTES.update({key: type(value)}) self.__setattr__(key, value) if key == "delivery": self._delivery = Delivery.from_dict(value)
def from_dict(cls, connection, dictionary, application_id=None, application_name=None): """Initialize Subscription object from dictionary. Specify either `application_id` or `application_name`. When `application_id` is provided (not `None`), `application_name` is omitted.""" obj = cls.__new__(cls) super(Subscription, obj).__init__() obj.connection = connection obj.application_id = Subscription._app_id_check(connection, application_id, application_name) dictionary = helper.camel_to_snake(dictionary) for key, value in dictionary.items(): obj._AVAILABLE_ATTRIBUTES.update({key: type(value)}) obj.__setattr__(key, value) if key == 'delivery': obj._delivery = Delivery.from_dict(value) return obj
def alter( self, name: str = None, allow_delivery_changes: bool = None, allow_personalization_changes: bool = None, allow_unsubscribe: bool = None, send_now: bool = False, owner_id: str = None, schedules_ids: Union[str, List[str]] = None, contents: Content = None, recipients: Union[List[str], List[dict]] = None, delivery: Union[Delivery, dict] = None, delivery_mode: str = None, custom_msg=None, delivery_expiration_date: str = None, contact_security: bool = None, filename: str = None, compress: bool = None, space_delimiter: str = None, email_subject: str = None, email_message: str = None, email_send_content_as: str = None, overwrite_older_version: bool = None, zip_filename: str = None, zip_password_protect: bool = None, zip_password: str = None, file_burst_sub_folder: str = None, printer_copies: int = None, printer_range_start: int = None, printer_range_end: int = None, printer_collated: bool = None, printer_orientation: str = None, printer_use_print_range: bool = None, cache_type: str = None, shortcut_cache_format: str = None, mobile_client_type: str = None, device_id: str = None, do_not_create_update_caches: bool = None, re_run_hl: bool = None, ): """ Alter subscription. Args: connection(Connection): a MicroStrategy connection object name(str): name of the subscription, application_id(str): application ID, allow_delivery_changes(bool): whether the recipients can change the delivery of the subscription, allow_personalization_changes(bool): whether the recipients can personalize the subscription, allow_unsubscribe(bool): whether the recipients can unsubscribe from the subscription, send_now(bool): indicates whether to execute the subscription immediately, owner_id(str): ID of the subscription owner, by default logged in user ID, schedules_ids (Union[str, List[str]]) = Schedules IDs, contents (Content): The content of the subscription. recipients (Union[List[str], List[dict]]): list of recipients IDs or dicts, delivery_mode(str, enum): the subscription delivery mode [EMAIL, FILE, PRINTER, HISTORY_LIST, CACHE, MOBILE, FTP, SNAPSHOT, PERSONAL_VIEW, SHARED_LINK, UNSUPPORTED], delivery_expiration_date(str): expiration date of the subscription, format should be yyyy-MM-dd, contact_security(bool): whether to use contact security for each contact group member, filename(str): the filename that will be delivered when the subscription is executed, compress(bool): whether to compress the file space_delimiter(str): space delimiter, email_subject(str): email subject associated with the subscription, email_message(str): email body of subscription, email_send_content_as(str,enum): [data, data_and_history_list, data_and_link_and_history_list, link_and_history_list], overwrite_older_version(bool): whether the current subscription will overwrite earlier versions of the same report or document in the history list, zip_filename(str): filename of the compressed content, zip_password_protect(bool): whether to password protect zip file, zip_password(str): optional password for the compressed file file_burst_sub_folder(str): burst sub folder, printer_copies(int): the number of copies that should be printed, printer_range_start(int): the number indicating the first report page that should be printed, printer_range_end(int): the number indicating the last report page that should be printed, printer_collated(bool): whether the printing should be collated, printer_orientation(str,enum): [ PORTRAIT, LANDSCAPE ] printer_use_print_range(bool): whether print range should be used, cache_type(str,enum): [RESERVED, SHORTCUT, BOOKMARK, SHORTCUTWITHBOOKMARK] shortcut_cache_format(str,enum): [RESERVED, JSON, BINARY, BOTH] mobile_client_type(str,enum): [RESERVED, BLACKBERRY, PHONE, TABLET, ANDROID] device_id(str): the mobile target application, do_not_create_update_caches(bool): whether the current subscription will overwrite earlier versions of the same report or document in the history list, re_run_hl(bool): whether subscription will re-run against warehouse """ def validate(body): for key, value in body.items(): if key == 'send_now': pass elif type(value) is not self._AVAILABLE_ATTRIBUTES.get(key): helper.exception_handler( "{} is not a valid type of {}, valid type is {}".format( type(value), key, self._AVAILABLE_ATTRIBUTES.get(key)), TypeError) def is_changed(nested=None, **kwargs): for key, value in kwargs.items(): if nested: return value if value != nested and value is not None else nested else: current_val = self.__dict__.get(key) # if not current_val: we need to get return value if value != current_val and value is not None else current_val # Schedules logic schedules_ids = schedules_ids if isinstance(schedules_ids, list) else [schedules_ids] schedules_ids = [s for s in schedules_ids if s is not None] schedules = [{ 'id': sch_id } for sch_id in schedules_ids] if schedules_ids else [{ 'id': trig['id'] } for trig in self.schedules] # Content logic if contents: contents = contents if isinstance(contents, list) else [contents] content_type_msg = "Contents must be dictionaries or Content objects." contents = [ content.to_dict( camel_case=True) if isinstance(content, Content) else content if isinstance( content, dict) else helper.exception_handler(content_type_msg, TypeError) for content in contents ] else: contents = self.contents # Delivery logic if delivery: temp_delivery = (Delivery.from_dict(delivery) if isinstance(delivery, dict) else delivery) else: temp_delivery = self.__change_delivery_properties( delivery_mode, delivery_expiration_date, contact_security, email_subject, email_message, filename, compress, None, zip_password, zip_password_protect, space_delimiter, email_send_content_as, overwrite_older_version, file_burst_sub_folder, printer_copies, printer_range_start, printer_range_end, printer_collated, printer_orientation, printer_use_print_range, cache_type, shortcut_cache_format, mobile_client_type, device_id, do_not_create_update_caches, re_run_hl) delivery = temp_delivery.to_dict(camel_case=True) # Recipients logic recipients = is_changed(recipients=recipients) recipients = Subscription._validate_recipients(self.connection, contents, recipients, self.application_id, delivery['mode']) body = { "name": is_changed(name=name), "allowDeliveryChanges": is_changed(allow_delivery_changes=allow_delivery_changes), "allowPersonalizationChanges": is_changed(allow_personalization_changes=allow_personalization_changes), "allowUnsubscribe": is_changed(allow_unsubscribe=allow_unsubscribe), "sendNow": send_now, 'owner': { 'id': is_changed(nested=self.owner['id'], owner_id=owner_id) }, "schedules": schedules, "contents": contents, "recipients": recipients, "delivery": delivery, } validate(helper.camel_to_snake(body)) body = helper.delete_none_values(body) response = subscriptions.update_subscription(self.connection, self.id, self.application_id, body) if response.ok: response = response.json() response = helper.camel_to_snake(response) for key, value in response.items(): self.__setattr__(key, value) if config.verbose: print(custom_msg if custom_msg else "Updated subscription '{}' with ID: {}." .format(self.name, self.id))
def __create( cls, connection: Connection, name: str, application_id: str = None, application_name: str = None, allow_delivery_changes: bool = None, allow_personalization_changes: bool = None, allow_unsubscribe: bool = None, send_now: bool = None, owner_id: str = None, schedules_ids: Union[str, List[str]] = None, contents: Content = None, recipients: Union[List[dict], List[str]] = None, delivery: Union[Delivery, dict] = None, delivery_mode: str = 'EMAIL', delivery_expiration_date: str = None, contact_security: bool = True, filename: str = None, compress: bool = False, space_delimiter: str = None, email_subject: str = None, email_message: str = None, email_send_content_as: str = 'data', overwrite_older_version: bool = False, zip_filename: str = None, zip_password_protect: bool = None, zip_password: str = None, file_burst_sub_folder: str = None, printer_copies: int = 1, printer_range_start: int = 0, printer_range_end: int = 0, printer_collated: bool = True, printer_orientation: str = "PORTRAIT", printer_use_print_range: bool = False, cache_type: str = "RESERVED", shortcut_cache_format: str = "RESERVED", mobile_client_type: str = "RESERVED", device_id: str = None, do_not_create_update_caches: bool = True, re_run_hl: bool = True, ): """Creates a subscription Create_Subscription_Outline. Args: connection(Connection): a MicroStrategy connection object name(str): name of the subscription, application_id(str): application ID, application_name(str): application name, allow_delivery_changes(bool): whether the recipients can change the delivery of the subscription, allow_personalization_changes(bool): whether the recipients can personalize the subscription, allow_unsubscribe(bool): whether the recipients can unsubscribe from the subscription, send_now(bool): indicates whether to execute the subscription immediately, owner_id(str): ID of the subscription owner, by default logged in user ID, schedules_ids (Union[str, List[str]]) = Schedules IDs, contents (Content): The content settings. recipients (List[dict],List[str]): list of recipients IDs or dicts, delivery(Union[Delivery,dict]): delivery object or dict delivery_mode(str, enum): the subscription delivery mode [EMAIL, FILE, PRINTER, HISTORY_LIST, CACHE, MOBILE, FTP, SNAPSHOT, PERSONAL_VIEW, SHARED_LINK, UNSUPPORTED], delivery_expiration_date(str): expiration date of the subscription, format should be yyyy-MM-dd, contact_security(bool): whether to use contact security for each contact group member, filename(str): the filename that will be delivered when the subscription is executed, compress(bool): whether to compress the file, space_delimiter(str): space delimiter, email_subject(str): email subject associated with the subscription, email_message(str): email body of subscription, email_send_content_as(str,enum): [data, data_and_history_list, data_and_link_and_history_list, link_and_history_list], overwrite_older_version(bool): whether the current subscription will overwrite earlier versions of the same report or document in the history list, zip_filename(str): filename of the compressed content, zip_password_protect(bool): whether to password protect zip file, zip_password(str): optional password for the compressed file, file_burst_sub_folder(str): burst sub folder, printer_copies(int): the number of copies that should be printed, printer_range_start(int): the number indicating the first report page that should be printed, printer_range_end(int): the number indicating the last report page that should be printed, printer_collated(bool): whether the printing should be collated, printer_orientation(str,enum): [ PORTRAIT, LANDSCAPE ] printer_use_print_range(bool): whether print range should be used, cache_type(str,enum): [RESERVED, SHORTCUT, BOOKMARK, SHORTCUTWITHBOOKMARK] shortcut_cache_format(str,enum): [RESERVED, JSON, BINARY, BOTH] mobile_client_type(str,enum): [RESERVED, BLACKBERRY, PHONE, TABLET, ANDROID] device_id(str): the mobile target application, do_not_create_update_caches(bool): whether the current subscription will overwrite earlier versions of the same report or document in the history list, re_run_hl(bool): whether subscription will re-run against warehouse """ name = name if len(name) <= 255 else helper.exception_handler( "Name too long. Max name length is 255 characters.") application_id = Subscription._app_id_check(connection, application_id, application_name) # Schedules logic schedules_ids = schedules_ids if isinstance(schedules_ids, list) else [schedules_ids] schedules = [{'id': sch_id} for sch_id in schedules_ids] # Content logic contents = contents if isinstance(contents, list) else [contents] content_type_msg = "Contents must be dictionaries or Content objects." contents = [ content.to_dict(camel_case=True) if isinstance(content, Content) else content if isinstance(content, dict) else helper.exception_handler(content_type_msg, TypeError) for content in contents ] # Delivery logic if delivery: temp_delivery = Delivery.from_dict(delivery) if isinstance(delivery, dict) else delivery else: temp_delivery = Delivery(delivery_mode, delivery_expiration_date, contact_security, email_subject, email_message, filename, compress, None, zip_password, zip_password_protect, space_delimiter, email_send_content_as, overwrite_older_version, file_burst_sub_folder, printer_copies, printer_range_start, printer_range_end, printer_collated, printer_orientation, printer_use_print_range, cache_type, shortcut_cache_format, mobile_client_type, device_id, do_not_create_update_caches, re_run_hl) delivery = temp_delivery.to_dict(camel_case=True) # Recipients logic recipients = Subscription._validate_recipients(connection, contents, recipients, application_id, delivery['mode']) schedules_ids = schedules_ids if isinstance(schedules_ids, list) else [schedules_ids] # Create body body = { "name": name, "allowDeliveryChanges": allow_delivery_changes, "allowPersonalizationChanges": allow_personalization_changes, "allowUnsubscribe": allow_unsubscribe, "sendNow": send_now, "owner": { "id": owner_id }, "schedules": schedules, "contents": contents, "recipients": recipients, "delivery": delivery } body = helper.delete_none_values(body) response = subscriptions.create_subscription(connection, application_id, body) if config.verbose: unpacked_response = response.json() print("Created subscription '{}' with ID: '{}'.".format(name, unpacked_response['id'])) return Subscription.from_dict(connection, response.json(), application_id)
def __create( # NOSONAR cls, # NOSONAR connection: Connection, name: str, project_id: Optional[str] = None, project_name: Optional[str] = None, allow_delivery_changes: Optional[bool] = None, allow_personalization_changes: Optional[bool] = None, allow_unsubscribe: Optional[bool] = None, send_now: Optional[bool] = None, owner_id: Optional[str] = None, schedules: Optional[Union[str, List[str], Schedule, List[Schedule]]] = None, contents: Content = None, recipients: Union[List[dict], List[str]] = None, delivery: Union[Delivery, dict] = None, delivery_mode: str = Delivery.DeliveryMode.EMAIL, delivery_expiration_date: Optional[str] = None, contact_security: bool = True, filename: Optional[str] = None, compress: bool = False, space_delimiter: Optional[str] = None, email_subject: Optional[str] = None, email_message: Optional[str] = None, email_send_content_as: str = SendContentAs.DATA, overwrite_older_version: bool = False, zip_filename: Optional[str] = None, zip_password_protect: Optional[bool] = None, zip_password: Optional[str] = None, file_burst_sub_folder: Optional[str] = None, printer_copies: int = 1, printer_range_start: int = 0, printer_range_end: int = 0, printer_collated: bool = True, printer_orientation: str = Orientation.PORTRAIT, printer_use_print_range: bool = False, cache_cache_type: Union[CacheType, str] = CacheType.RESERVED, cache_shortcut_cache_format: Union[ ShortcutCacheFormat, str] = ShortcutCacheFormat.RESERVED, mobile_client_type: str = ClientType.RESERVED, device_id: Optional[str] = None, do_not_create_update_caches: bool = True, re_run_hl: bool = True, cache_library_cache_types: List[Union[LibraryCacheTypes, str]] = [ LibraryCacheTypes.WEB ], cache_reuse_dataset_cache: bool = False, cache_is_all_library_users: bool = False, delivery_notification_enabled: bool = False, delivery_personal_notification_address_id: Optional[str] = None): """Creates a subscription Create_Subscription_Outline. Args: connection(Connection): a MicroStrategy connection object name(str): name of the subscription, project_id(str): project ID, project_name(str): project name, allow_delivery_changes(bool): whether the recipients can change the delivery of the subscription, allow_personalization_changes(bool): whether the recipients can personalize the subscription, allow_unsubscribe(bool): whether the recipients can unsubscribe from the subscription, send_now(bool): indicates whether to execute the subscription immediately, owner_id(str): ID of the subscription owner, by default logged in user ID, schedules (Union[str, List[str], Schedule, List[Schedule]]): Schedules IDs or Schedule objects, contents (Content): The content settings. recipients (List[dict],List[str]): list of recipients IDs or dicts, delivery(Union[Delivery,dict]): delivery object or dict delivery_mode(str, enum): the subscription delivery mode [EMAIL, FILE, PRINTER, HISTORY_LIST, CACHE, MOBILE, FTP, SNAPSHOT, PERSONAL_VIEW, SHARED_LINK, UNSUPPORTED], delivery_expiration_date(str): expiration date of the subscription, format should be yyyy-MM-dd, contact_security(bool): whether to use contact security for each contact group member, filename(str): the filename that will be delivered when the subscription is executed, compress(bool): whether to compress the file, space_delimiter(str): space delimiter, email_subject(str): email subject associated with the subscription, email_message(str): email body of subscription, email_send_content_as(str,enum): [data, data_and_history_list, data_and_link_and_history_list, link_and_history_list], overwrite_older_version(bool): whether the current subscription will overwrite earlier versions of the same report or document in the history list, zip_filename(str): filename of the compressed content, zip_password_protect(bool): whether to password protect zip file, zip_password(str): optional password for the compressed file, file_burst_sub_folder(str): burst sub folder, printer_copies(int): the number of copies that should be printed, printer_range_start(int): the number indicating the first report page that should be printed, printer_range_end(int): the number indicating the last report page that should be printed, printer_collated(bool): whether the printing should be collated, printer_orientation(str,enum): [ PORTRAIT, LANDSCAPE ] printer_use_print_range(bool): whether print range should be used, cache_cache_type(str,enum): [RESERVED, SHORTCUT, SHORTCUTWITHBOOKMARK] cache_shortcut_cache_format(str,enum):[RESERVED, JSON, BINARY, BOTH] mobile_client_type(str,enum): [RESERVED, BLACKBERRY, PHONE, TABLET, ANDROID] device_id(str): the mobile target project, do_not_create_update_caches(bool): whether the current subscription will overwrite earlier versions of the same report or document in the history list, re_run_hl(bool): whether subscription will re-run against warehouse cache_library_cache_types: Set of library cache types, available types can be web, android, ios cache_reuse_dataset_cache: Whether to reuse dataset cache cache_is_all_library_users: Whether for all library users delivery_notification_enabled: Whether notification is enabled, notification applies to cache delivery_personal_notification_address_id: Notification details """ name = name if len(name) <= 255 else helper.exception_handler( "Name too long. Max name length is 255 characters.") project_id = cls._project_id_check(connection, project_id, project_name) if not schedules: msg = ("Please specify 'schedules' parameter.") helper.exception_handler(msg) schedules = cls.__validate_schedules(schedules=schedules) # Content logic contents = contents if isinstance(contents, list) else [contents] content_type_msg = "Contents must be dictionaries or Content objects." contents = [ content.to_dict(camel_case=True) if isinstance( content, Content) else content if isinstance(content, dict) else helper.exception_handler(content_type_msg, TypeError) for content in contents ] # Delivery logic if delivery: temp_delivery = Delivery.from_dict(delivery) if isinstance( delivery, dict) else delivery else: temp_delivery = Delivery( delivery_mode, delivery_expiration_date, contact_security, email_subject, email_message, filename, compress, None, zip_password, zip_password_protect, space_delimiter, email_send_content_as, overwrite_older_version, file_burst_sub_folder, printer_copies, printer_range_start, printer_range_end, printer_collated, printer_orientation, printer_use_print_range, mobile_client_type, device_id, do_not_create_update_caches, re_run_hl, cache_type=cache_cache_type, shortcut_cache_format=cache_shortcut_cache_format, library_cache_types=cache_library_cache_types, reuse_dataset_cache=cache_reuse_dataset_cache, is_all_library_users=cache_is_all_library_users, notification_enabled=delivery_notification_enabled, personal_notification_address_id= delivery_personal_notification_address_id) delivery = temp_delivery.to_dict(camel_case=True) # Recipients logic recipients = cls._validate_recipients(connection, contents, recipients, project_id, delivery['mode']) # Create body body = { "name": name, "allowDeliveryChanges": allow_delivery_changes, "allowPersonalizationChanges": allow_personalization_changes, "allowUnsubscribe": allow_unsubscribe, "sendNow": send_now, "owner": { "id": owner_id }, "schedules": schedules, "contents": contents, "recipients": recipients, "delivery": delivery } body = helper.delete_none_values(body) response = subscriptions.create_subscription(connection, project_id, body) if config.verbose: unpacked_response = response.json() logger.info( f"Created subscription '{name}' with ID: '{unpacked_response['id']}'." ) return cls.from_dict(response.json(), connection, project_id)
def alter( self, # NOSONAR name: Optional[str] = None, allow_delivery_changes: Optional[bool] = None, allow_personalization_changes: Optional[bool] = None, allow_unsubscribe: Optional[bool] = None, send_now: bool = False, owner_id: Optional[str] = None, schedules: Optional[Union[str, List[str], Schedule, List[Schedule]]] = None, contents: Optional[Content] = None, recipients: Optional[Union[List[str], List[dict]]] = None, delivery: Optional[Union[Delivery, dict]] = None, delivery_mode: Optional[str] = None, custom_msg: Optional[str] = None, delivery_expiration_date: Optional[str] = None, contact_security: Optional[bool] = None, filename: Optional[str] = None, compress: Optional[bool] = None, space_delimiter: Optional[str] = None, email_subject: Optional[str] = None, email_message: Optional[str] = None, email_send_content_as: Optional[str] = None, overwrite_older_version: Optional[bool] = None, zip_filename: Optional[str] = None, zip_password_protect: Optional[bool] = None, zip_password: Optional[str] = None, file_burst_sub_folder: Optional[str] = None, printer_copies: Optional[int] = None, printer_range_start: Optional[int] = None, printer_range_end: Optional[int] = None, printer_collated: Optional[bool] = None, printer_orientation: Optional[str] = None, printer_use_print_range: Optional[bool] = None, cache_cache_type: Optional[str] = None, cache_shortcut_cache_format: Optional[str] = None, mobile_client_type: Optional[str] = None, device_id: Optional[str] = None, do_not_create_update_caches: Optional[bool] = None, re_run_hl: Optional[bool] = None, cache_library_cache_types: List[Union[LibraryCacheTypes, str]] = [ LibraryCacheTypes.WEB ], cache_reuse_dataset_cache: bool = False, cache_is_all_library_users: bool = False, delivery_notification_enabled: bool = False, delivery_personal_notification_address_id: Optional[str] = None): """ Alter subscription. Args: connection(Connection): a MicroStrategy connection object name(str): name of the subscription, project_id(str): project ID, allow_delivery_changes(bool): whether the recipients can change the delivery of the subscription, allow_personalization_changes(bool): whether the recipients can personalize the subscription, allow_unsubscribe(bool): whether the recipients can unsubscribe from the subscription, send_now(bool): indicates whether to execute the subscription immediately, owner_id(str): ID of the subscription owner, by default logged in user ID, schedules (Union[str, List[str], Schedule, List[Schedule]]): Schedules IDs or Schedule objects, contents (Content): The content of the subscription. recipients (Union[List[str], List[dict]]): list of recipients IDs or dicts, delivery_mode(str, enum): the subscription delivery mode [EMAIL, FILE, PRINTER, HISTORY_LIST, CACHE, MOBILE, FTP, SNAPSHOT, PERSONAL_VIEW, SHARED_LINK, UNSUPPORTED], delivery_expiration_date(str): expiration date of the subscription, format should be yyyy-MM-dd, contact_security(bool): whether to use contact security for each contact group member, filename(str): the filename that will be delivered when the subscription is executed, compress(bool): whether to compress the file space_delimiter(str): space delimiter, email_subject(str): email subject associated with the subscription, email_message(str): email body of subscription, email_send_content_as(str,enum): [data, data_and_history_list, data_and_link_and_history_list, link_and_history_list], overwrite_older_version(bool): whether the current subscription will overwrite earlier versions of the same report or document in the history list, zip_filename(str): filename of the compressed content, zip_password_protect(bool): whether to password protect zip file, zip_password(str): optional password for the compressed file file_burst_sub_folder(str): burst sub folder, printer_copies(int): the number of copies that should be printed, printer_range_start(int): the number indicating the first report page that should be printed, printer_range_end(int): the number indicating the last report page that should be printed, printer_collated(bool): whether the printing should be collated, printer_orientation(str,enum): [ PORTRAIT, LANDSCAPE ] printer_use_print_range(bool): whether print range should be used, cache_cache_type(str,enum): [RESERVED, SHORTCUT, SHORTCUTWITHBOOKMARK] cache_shortcut_cache_format(str,enum): [RESERVED, JSON, BINARY, BOTH] mobile_client_type(str,enum): [RESERVED, BLACKBERRY, PHONE, TABLET, ANDROID] device_id(str): the mobile target project, do_not_create_update_caches(bool): whether the current subscription will overwrite earlier versions of the same report or document in the history list, re_run_hl(bool): whether subscription will re-run against warehouse cache_library_cache_types: Set of library cache types, available types can be web, android, ios cache_reuse_dataset_cache: Whether to reuse dataset cache cache_is_all_library_users: Whether for all library users delivery_notification_enabled: Whether notification is enabled, notification applies to cache delivery_personal_notification_address_id: Notification details """ # Schedules logic schedules = self.__validate_schedules(schedules=schedules) if not schedules: schedules = [{'id': sch.id} for sch in self.schedules] # Content logic if contents: contents = self.__validate_contents(contents) else: contents = [cont.to_dict() for cont in self.contents] # Delivery logic if delivery: temp_delivery = (Delivery.from_dict(delivery) if isinstance( delivery, dict) else delivery) else: temp_delivery = self.__change_delivery_properties( delivery_mode, delivery_expiration_date, contact_security, email_subject, email_message, filename, compress, None, zip_filename, zip_password, zip_password_protect, space_delimiter, email_send_content_as, overwrite_older_version, file_burst_sub_folder, printer_copies, printer_range_start, printer_range_end, printer_collated, printer_orientation, printer_use_print_range, client_type=mobile_client_type, device_id=device_id, do_not_create_update_caches=do_not_create_update_caches, re_run_hl=re_run_hl, cache_type=cache_cache_type, shortcut_cache_format=cache_shortcut_cache_format, library_cache_types=cache_library_cache_types, reuse_dataset_cache=cache_reuse_dataset_cache, is_all_library_users=cache_is_all_library_users, notification_enabled=delivery_notification_enabled, personal_notification_address_id= delivery_personal_notification_address_id) delivery = temp_delivery.to_dict(camel_case=True) # Recipients logic recipients = self.__is_val_changed(recipients=recipients) recipients = Subscription._validate_recipients(self.connection, contents, recipients, self.project_id, delivery['mode']) body = { "name": self.__is_val_changed(name=name), "allowDeliveryChanges": self.__is_val_changed( allow_delivery_changes=allow_delivery_changes), "allowPersonalizationChanges": self.__is_val_changed( allow_personalization_changes=allow_personalization_changes), "allowUnsubscribe": self.__is_val_changed(allow_unsubscribe=allow_unsubscribe), "sendNow": send_now, 'owner': { 'id': self.__is_val_changed(nested=self.owner.id, owner_id=owner_id) }, "schedules": schedules, "contents": contents, "recipients": recipients, "delivery": delivery, } body = helper.delete_none_values(body) response = subscriptions.update_subscription(self.connection, self.id, self.project_id, body) if response.ok: response = response.json() response = helper.camel_to_snake(response) self._set_object_attributes(**response) if config.verbose: msg = f"Updated subscription '{self.name}' with ID: {self.id}." msg = custom_msg if custom_msg else msg logger.info(msg)