class Get(pycamunda.base.CamundaRequest): id_ = PathParameter('id') key = PathParameter('key') tenant_id = PathParameter('tenant-id') def __init__(self, url: str, id_: str = None, key: str = None, tenant_id: str = None): """Get a process definition. :param url: Camunda Rest engine URL. :param id_: Id of the process definition. :param key: Key of the process definition. :param tenant_id: Id of the tenant the process definition belongs to. """ super().__init__(url=url + URL_SUFFIX + '/{path}') self.id_ = id_ self.key = key self.tenant_id = tenant_id @property def url(self): if self.id_ is not None: return self._url.format(path=self.id_) if self.tenant_id is not None: return self._url.format(path=f'key/{self.key}/tenant-id/{self.tenant_id}') return self._url.format(path=f'key/{self.key}') def __call__(self, *args, **kwargs) -> ProcessDefinition: """Send the request.""" response = super().__call__(pycamunda.base.RequestMethod.GET, *args, **kwargs) return ProcessDefinition.load(response.json())
class Get(pycamunda.base._PathMixin, pycamunda.base.CamundaRequest): id_ = PathParameter('id') key = PathParameter('key') tenant_id = PathParameter('tenant-id') def __init__(self, url: str, id_: str = None, key: str = None, tenant_id: str = None): """Get a decision definition. :param url: Camunda Rest engine URL. :param id_: Id of the decision definition. :param key: Key of the decision definition. :param tenant_id: Id of the tenant the decision definition belongs to. """ super().__init__(url=url + URL_SUFFIX + '/{path}') self.id_ = id_ self.key = key self.tenant_id = tenant_id def __call__(self, *args, **kwargs) -> DecisionDefinition: """Send the request.""" response = super().__call__(pycamunda.base.RequestMethod.GET, *args, **kwargs) return DecisionDefinition.load(response.json())
class GetXML(pycamunda.base._PathMixin, pycamunda.base.CamundaRequest): id_ = PathParameter('id') key = PathParameter('key') tenant_id = PathParameter('tenant-id') def __init__(self, url: str, id_: str = None, key: str = None, tenant_id: str = None): """Retrieve the CMMN XML of a case definition. :param url: Camunda Rest engine URL. :param id_: Id of the case definition. :param key: Key of the case definition. :param tenant_id: Id of the tenant the case definition belongs to. """ super().__init__(url=url + URL_SUFFIX + '/{path}/xml') self.id_ = id_ self.key = key self.tenant_id = tenant_id def __call__(self, *args, **kwargs) -> str: """Send the request.""" response = super().__call__(pycamunda.base.RequestMethod.GET, *args, **kwargs) return response.json()['cmmnXml']
class UpdateHistoryTimeToLive(pycamunda.base._PathMixin, pycamunda.base.CamundaRequest): id_ = PathParameter('id') key = PathParameter('key') tenant_id = PathParameter('tenant-id') history_time_to_live = BodyParameter( 'historyTimeToLive', validate=lambda val: val is None or val >= 0) def __init__(self, url: str, history_time_to_live: int, id_: str = None, key: str = None, tenant_id: str = None): """Update the history time to live of a case definition. :param url: Camunda Rest engine URL. :param history_time_to_live: New history time to live. Can be set to 'None'. :param id_: Id of the case definition. :param key: Key of the case definition. :param tenant_id: Id of the tenant the case definition belongs to. """ super().__init__(url=url + URL_SUFFIX + '/{path}/history-time-to-live') self.history_time_to_live = history_time_to_live self.id_ = id_ self.key = key self.tenant_id = tenant_id def __call__(self, *args, **kwargs) -> None: """Send the request.""" super().__call__(pycamunda.base.RequestMethod.PUT, *args, **kwargs)
class GetDiagram(pycamunda.base._PathMixin, pycamunda.base.CamundaRequest): id_ = PathParameter('id') key = PathParameter('key') tenant_id = PathParameter('tenant-id') def __init__(self, url: str, id_: str = None, key: str = None, tenant_id: str = None): """Get the diagram of a case definition. :param url: Camunda Rest engine URL. :param id_: Id of the case definition. :param key: Key of the case definition. """ super().__init__(url=url + URL_SUFFIX + '/{path}/diagram') self.id_ = id_ self.key = key self.tenant_id = tenant_id def __call__(self, *args, **kwargs): """Send the request.""" response = super().__call__(pycamunda.base.RequestMethod.GET, *args, **kwargs) return response.content
class GetResource(pycamunda.base.CamundaRequest): id_ = PathParameter('id') resource_id = PathParameter('resourceId') def __init__(self, url: str, id_: str, resource_id: str, binary: bool = False): """Get a resource of a deployment. :param url: Camunda Rest engine URL. :param id_: Id of the the deployment. :param resource_id: Id of the resource. :param binary: Whether to request binary content of the resource. """ super().__init__(url=url + URL_SUFFIX + '/{id}/resources/{resourceId}') self.id_ = id_ self.resource_id = resource_id self.binary = binary @property def url(self): return super().url + ('/data' if self.binary else '') def __call__(self, *args, **kwargs) -> typing.Union[Resource, typing.ByteString]: """Send the request.""" response = super().__call__(pycamunda.base.RequestMethod.GET, *args, **kwargs) if self.binary: return response.content return Resource.load(response.json())
class GetActivityInstanceStats(pycamunda.base.CamundaRequest): id_ = PathParameter('id') key = PathParameter('key') tenant_id = PathParameter('tenant-id') failed_jobs = QueryParameter('failedJobs') incidents = QueryParameter('incidents', provide=pycamunda.base.value_is_true) incidents_for_type = QueryParameter('incidentsForType') def __init__( self, url: str, id_: str = None, key: str = None, tenant_id: str = None, failed_jobs: bool = None, incidents: bool = False, incidents_for_type: typing.Union[str, pycamunda.incident.IncidentType] = None ): """Get runtime statistics for a process definition. Does not include historic data. :param url: Camunda Rest engine URL. :param id_: Id of the process definition. :param key: Key of the process definition. :param tenant_id: Id of the tenant the process definition belongs to. :param failed_jobs: Whether the number of failed jobs should be included. :param incidents: Whether to include the number of incidents. :param incidents_for_type: Include only incidents of a specific type. """ if incidents and incidents_for_type is not None: raise pycamunda.PyCamundaException( 'Either \'incidents\' or \'incidents_for_type\' can be provided, not both.' ) super().__init__(url=url + URL_SUFFIX + '/{path}/statistics') self.id_ = id_ self.key = key self.tenant_id = tenant_id self.failed_jobs = failed_jobs self.incidents = incidents self.incident_type = None if incidents_for_type is not None: self.incidents_for_type = pycamunda.incident.IncidentType(incidents_for_type) @property def url(self): if self.id_ is not None: return self._url.format(path=self.id_) if self.tenant_id is not None: return self._url.format(path=f'key/{self.key}/tenant-id/{self.tenant_id}') return self._url.format(path=f'key/{self.key}') def __call__(self, *args, **kwargs) -> typing.Tuple[ActivityStats]: """Send the request.""" response = super().__call__(pycamunda.base.RequestMethod.GET, *args, **kwargs) return tuple(ActivityStats.load(activity_json) for activity_json in response.json())
class CreateInstance(pycamunda.base._PathMixin, pycamunda.base.CamundaRequest): id_ = PathParameter('id') key = PathParameter('key') tenant_id = PathParameter('tenant-id') variables = BodyParameter('variables') business_key = BodyParameter('businessKey') def __init__(self, url: str, id_: str = None, key: str = None, tenant_id: str = None, business_key: str = None): """Create a case instance. :param url: Camunda Rest engine URL. :param id_: Id of the case definition. :param key: Key of the case definition. :param tenant_id: Id of the tenant the case definition belongs to. :param business_key: The business key to initialize the case instance with. """ super().__init__(url=url + URL_SUFFIX + '/{path}/create') self.id_ = id_ self.key = key self.tenant_id = tenant_id self.business_key = business_key self.variables = {} def add_variable(self, name: str, value: typing.Any, type_: str = None, value_info: str = None) -> None: """Add a variable to initialize the case instance with. :param name: Name of the variable. :param value: Value of the variable. :param type_: Value type of the variable. :param value_info: Additional information regarding the value type. """ self.variables[name] = { 'value': value, 'type': type_, 'valueInfo': value_info } def __call__(self, *args, **kwargs) -> pycamunda.caseinst.CaseInstance: """Send the request.""" response = super().__call__(pycamunda.base.RequestMethod.POST, *args, **kwargs) return pycamunda.caseinst.CaseInstance.load(response.json())
class _ActivateSuspend(pycamunda.base.CamundaRequest): id_ = PathParameter('id') key = PathParameter('key') tenant_id = PathParameter('tenant-id') suspended = BodyParameter('suspended') include_process_instances = BodyParameter('includeProcessInstances') execution_datetime = BodyParameter('executionDate') def __init__( self, url: str, suspended: bool, id_: str = None, key: str = None, tenant_id: str = None, include_process_instances: bool = None, execution_datetime: dt.datetime = None ): """Activate or Suspend a process definition. :param url: Camunda Rest engine URL. :param suspended: Whether to suspend or activate the process definition. :param id_: Id of the process definition. :param key: Key of the process definition. :param tenant_id: Id of the tenant the process definition belongs to. :param include_process_instances: Whether to cascade the action to process instances. :param execution_datetime: When to execute the action. If 'None' the action is immediately. """ super().__init__(url=url + URL_SUFFIX + '/{path}/suspended') self.suspended = suspended self.id_ = id_ self.key = key self.tenant_id = tenant_id self.include_process_instances = include_process_instances self.execution_datetime = execution_datetime @property def url(self): if self.id_ is not None: return self._url.format(path=self.id_) if self.tenant_id is not None: return self._url.format(path=f'key/{self.key}/tenant-id/{self.tenant_id}') return self._url.format(path=f'key/{self.key}') def __call__(self, *args, **kwargs) -> None: """Send the request.""" super().__call__(pycamunda.base.RequestMethod.PUT, *args, **kwargs)
class Delete(pycamunda.base.CamundaRequest): id_ = PathParameter('id') key = PathParameter('key') tenant_id = PathParameter('tenant-id') cascade = QueryParameter('cascade') skip_custom_listeners = QueryParameter('skipCustomListeners') skip_io_mappings = QueryParameter('skipIoMappings') def __init__( self, url: str, id_: str = None, key: str = None, tenant_id: str = None, cascade: bool = False, skip_custom_listeners: bool = False, skip_io_mappings: bool = False ): """Delete a process definition. :param url: Camunda Rest engine URL. :param id_: Id of the process definition. :param key: Key of the process definition. :param tenant_id: Id of the tenant the process definition belongs to. :param cascade: Whether to cascade the deletion to process instances of the definition. :param skip_custom_listeners: Whether to skip custom listeners and notify only builtin ones. :param skip_io_mappings: Whether to skip input/output mappings. """ super().__init__(url=url + URL_SUFFIX + '/{path}') self.id_ = id_ self.key = key self.tenant_id = tenant_id self.cascade = cascade self.skip_custom_listeners = skip_custom_listeners self.skip_io_mappings = skip_io_mappings @property def url(self): if self.id_ is not None: return self._url.format(path=self.id_) if self.tenant_id is not None: return self._url.format(path=f'key/{self.key}/tenant-id/{self.tenant_id}') return self._url.format(path=f'key/{self.key}') def __call__(self, *args, **kwargs) -> None: """Send the request.""" super().__call__(pycamunda.base.RequestMethod.DELETE, *args, **kwargs)
class IdentityLinksDelete(pycamunda.base.CamundaRequest): task_id = PathParameter('id') user_id = BodyParameter('userId') group_id = BodyParameter('groupId') type_ = BodyParameter('type') def __init__( self, url: str, task_id: str, type_: str, user_id: str = None, group_id: str = None ): """Delete an identity link of an user task. An identity link is a relationship between an user task and an user or a group. E.g. when the user is the assignee / owner or one of the candidate users of the task. :param url: Camunda Rest engine URL. :param task_id: Id of the task. :param user_id: Id of the user. Can not be provided if group_id is provided. :param group_id: Id of the groupt. Can not be provided if user_id is provided. :param type_: Type of the identity link. Can be any custom string. Pre-defined types are 'assignee' (user), 'owner' (user) and 'candidate' (user / group). """ assert (user_id is None) != (group_id is None), ( 'Either \'user_id\' or \'group_id\' has to be provided, not both.' ) super().__init__(url=url + URL_SUFFIX + '/{id}/identity-links/delete') self.task_id = task_id self.user_id = user_id self.group_id = group_id self.type_ = type_ def __call__(self, *args, **kwargs) -> None: """Send the request.""" super().__call__(pycamunda.base.RequestMethod.POST, *args, **kwargs)
class Delete(pycamunda.base.CamundaRequest): id_ = PathParameter('id') cascade = QueryParameter('cascade') skip_custom_listeners = QueryParameter('skipCustomListeners') skip_io_mappings = QueryParameter('skipIoMappings') def __init__(self, url: str, id_: str, cascade: bool = False, skip_custom_listeners: bool = False, skip_io_mappings: bool = False): """Delete a deployment. :param url: Camunda Rest engine URL. :param id_: Id of the the deployment. :param cascade: Whether to cascade the action to all process instances (including historic). :param skip_custom_listeners: Whether to skip custom listeners and notify only builtin ones. :param skip_io_mappings: Whether to skip input/output mappings. """ super().__init__(url=url + URL_SUFFIX + '/{id}') self.id_ = id_ self.cascade = cascade self.skip_custom_listeners = skip_custom_listeners self.skip_io_mappings = skip_io_mappings def __call__(self, *args, **kwargs) -> None: """Send the request.""" super().__call__(pycamunda.base.RequestMethod.DELETE, *args, **kwargs)
class LocalVariablesGetList(pycamunda.base.CamundaRequest): task_id = PathParameter('id') deserialize_values = QueryParameter('deserializeValues') def __init__( self, url: str, task_id: str, deserialize_values: bool = False ): """Get local variables of an user task. Local variables are variables that do only exist in the context of a task. :param url: Camunda Rest engine URL. :param task_id: Id of the task. :param deserialize_values: Whether serializable variable values are deserialized on server side. """ super().__init__(url=url + URL_SUFFIX + '/{id}/localVariables') self.task_id = task_id self.deserialize_values = deserialize_values def __call__(self, *args, **kwargs) -> typing.Dict[str, pycamunda.variable.Variable]: """Send the request.""" response = super().__call__(pycamunda.base.RequestMethod.GET, *args, **kwargs) return { name: pycamunda.variable.Variable.load(data=var_json) for name, var_json in response.json().items() }
class IdentityLinksGetList(pycamunda.base.CamundaRequest): task_id = PathParameter('id') type_ = QueryParameter('type') def __init__(self, url: str, task_id: str = None, type_: str = None) -> None: """Get the identity links of an user task. An identity link is a relationship between an user task and an user or a group. E.g. when the user is the assignee / owner or one of the candidate users of the task. :param url: Camunda Rest engine URL. :param task_id: Id of the task. :param type_: Type of the identity link. Can be any custom string. Pre-defined types are 'assignee' (user), 'owner' (user) and 'candidate' (user / group). """ super().__init__(url=url + URL_SUFFIX + '/{id}/identity-links') self.task_id = task_id self.type_ = type_ def __call__(self, *args, **kwargs) -> typing.Tuple[IdentityLink]: """Send the request.""" response = super().__call__(pycamunda.base.RequestMethod.GET, *args, **kwargs) return tuple(IdentityLink.load(link_json) for link_json in response.json())
class Get(pycamunda.base.CamundaRequest): id_ = PathParameter('id') def __init__(self, url: str, id_: str, request_error_details: bool = True): """Query for an external task. :param url: Camunda Rest engine URL. :param id_: Id of the external task. :param request_error_details: Whether to request error details for tasks. Requires an additional request. """ super().__init__(url=url + URL_SUFFIX + '/{id}') self.id_ = id_ self.request_error_details = request_error_details def __call__(self, *args, **kwargs) -> ExternalTask: """Send the request.""" response = super().__call__(pycamunda.base.RequestMethod.GET, *args, **kwargs) external_task = ExternalTask.load(response.json()) if self.request_error_details: if external_task.error_details is None: try: response = requests.get(self.url + '/errorDetails') except requests.exceptions.RequestException: raise pycamunda.PyCamundaException() if not response: pycamunda.base._raise_for_status(response) external_task.error_details = response.text return external_task
class Options(pycamunda.base.CamundaRequest): id_ = PathParameter('id') def __init__(self, url: str, id_: str = None): """Get a list of options the currently authenticated user can perform on the authorization resource. :param url: Camunda Rest engine URL. :param id_: Id of the authorization """ super().__init__(url=url + URL_SUFFIX + '{path}') self.id_ = id_ @property def url(self): return self._url.format(path='/{id}'.format( id=self.id_) if self.id_ is not None else '') def __call__(self, *args, **kwargs) -> pycamunda.resource.ResourceOptions: """Send the request.""" response = super().__call__(pycamunda.base.RequestMethod.OPTIONS, *args, **kwargs) return pycamunda.resource.ResourceOptions.load(data=response.json())
class Execute(_Criteria): id_ = PathParameter('id') def __init__(self, url: str, id_: str, single_result: bool = False): """Execute a filter. :param url: Camunda Rest engine URL. :param id_: Id of the filter. """ super().__init__(url=url + URL_SUFFIX + '/{id}') self.id_ = id_ self.single_result = single_result @property def url(self) -> str: return super().url + ('/singleResult' if self.single_result else '/list') def body_parameters(self, apply: typing.Callable = ...) -> typing.Dict[str, typing.Any]: return super().body_parameters(apply=apply)['query'] def __call__( self, *args, **kwargs ) -> typing.Union[pycamunda.task.Task, typing.Tuple[pycamunda.task.Task]]: """Send the request.""" if self.body_parameters(): response = super().__call__(pycamunda.base.RequestMethod.POST, *args, **kwargs) else: response = super().__call__(pycamunda.base.RequestMethod.GET, *args, **kwargs) if self.single_result: return pycamunda.task.Task.load(response.json()) return tuple(pycamunda.task.Task.load(task_json) for task_json in response.json())
class Update(_Criteria): id_ = PathParameter('id') resource_type = BodyParameter('resourceType') name = BodyParameter('name') owner = BodyParameter('owner') def __init__(self, url: str, id_: str, name: str = None, owner: str = None): """Update a filter. :param url: Camunda Rest engine URL. :param id_: Id of the filter. :param name: Name of the filter. :param owner: User id of the owner of the filter. """ super().__init__(url=url + URL_SUFFIX + '/{id}') self.id_ = id_ self.resource_type = 'Task' self.name = name self.owner = owner def __call__(self, *args, **kwargs) -> None: """Send the request""" super().__call__(pycamunda.base.RequestMethod.PUT, *args, **kwargs)
class UpdateProfile(pycamunda.base.CamundaRequest): id_ = PathParameter('id') new_user_id = BodyParameter('id') first_name = BodyParameter('firstName') last_name = BodyParameter('lastName') email = BodyParameter('email') def __init__(self, url: str, id_: str, new_user_id: str = None, first_name: str = None, last_name: str = None, email: str = None): """Update the profile information of an already existing user. :param url: Camunda Rest engine URL. :param id_: Id of the user. :param new_user_id: New user id of the user. :param first_name: New first name of the user. :param last_name: New last name of the user. :param email: New email of the user. """ super().__init__(url=url + URL_SUFFIX + '/{id}/profile') self.id_ = id_ self.new_user_id = new_user_id self.first_name = first_name self.last_name = last_name self.email = email def __call__(self, *args, **kwargs) -> None: """Send the request""" super().__call__(pycamunda.base.RequestMethod.PUT, *args, **kwargs)
class Terminate(_VariableDeletionMixin, pycamunda.base.CamundaRequest): id_ = PathParameter('id') variables = BodyParameter('variables') deletions = BodyParameter('deletions') def __init__(self, url: str, id_: str, deletions: typing.Iterable[str] = None): """Performs a transition from ACTIVE state to TERMINATED state. In addition to that, case instance variables can be updated and deleted. :param url: Camunda Rest engine URL. :param id_: Id of the case instance. :param deletions: Variables to delete. Is executed for creating or updating variables. """ super().__init__(url=url + URL_SUFFIX + '/{id}/terminate') self.id_ = id_ self.deletions = deletions self.variables = {} def __call__(self, *args, **kwargs) -> None: """Send the request.""" super().__call__(pycamunda.base.RequestMethod.POST, *args, **kwargs)
class Resolve(pycamunda.base.CamundaRequest): id_ = PathParameter('id') variables = BodyParameter('variables') def __init__(self, url: str, id_: str): """Resolve an user task that was delegated to the current assignee and send it back to the original owner. It is necessary that the task was delegated. The assignee of the user task will be set back to the owner of the task. :param url: Camunda Rest engine URL. :param id_: Id of the user task. """ super().__init__(url=url + URL_SUFFIX + '/{id}/resolve') self.id_ = id_ self.variables = {} def add_variable( self, name: str, value: typing.Any, type_: str = None, value_info: typing.Any = None ) -> None: """Add a variable to send to the Camunda process instance. :param name: Name of the variable. :param value: Value of the variable. :param type_: Value type of the variable. :param value_info: Additional information regarding the value type. """ self.variables[name] = {'value': value, 'type': type_, 'valueInfo': value_info} def __call__(self, *args, **kwargs) -> None: """Send the request.""" super().__call__(pycamunda.base.RequestMethod.POST, *args, **kwargs)
class Update(pycamunda.base.CamundaRequest): id_ = PathParameter('id') name = BodyParameter('name') type_ = BodyParameter('type') def __init__(self, url: str, id_: str, name: str, type_: str): """Update a group. :param url: Camunda Rest engine URL. :param id_: Id of the group. :param name: New name of the group. :param type_: New zype of the group. """ super().__init__(url=url + URL_SUFFIX + '/{id}') self.id_ = id_ self.name = name self.type_ = type_ def body_parameters(self, apply: typing.Callable = ...): params = super().body_parameters(apply=apply) params['id'] = self.id_ return params def __call__(self, *args, **kwargs) -> None: """Send the request.""" super().__call__(pycamunda.base.RequestMethod.PUT, *args, **kwargs)
class Delete(pycamunda.base.CamundaRequest): id_ = PathParameter('id') skip_custom_listeners = QueryParameter('skipCustomListeners') skip_io_mappings = QueryParameter('skipIoMappings') skip_subprocesses = QueryParameter('skipSubprocesses') fail_if_not_exists = QueryParameter('failIfNotExists') def __init__(self, url: str, id_: str, skip_custom_listeners: bool = False, skip_io_mappings: bool = False, skip_subprocesses: bool = False, fail_if_not_exists: bool = True): """Delete a process instance. :param url: Camunda Rest engine URL. :param id_: Id of the process instance. :param skip_custom_listeners: Whether to skip custom listeners and notify only builtin ones. :param skip_io_mappings: Whether to skip input/output mappings. :param skip_subprocesses: Whether to skip subprocesses. :param fail_if_not_exists: Whether to fail if the provided process instance id is not found. """ super().__init__(url=url + URL_SUFFIX + '/{id}') self.id_ = id_ self.skip_custom_listeners = skip_custom_listeners self.skip_io_mappings = skip_io_mappings self.skip_subprocesses = skip_subprocesses self.fail_if_not_exists = fail_if_not_exists def __call__(self, *args, **kwargs): """Send the request.""" super().__call__(pycamunda.base.RequestMethod.DELETE, *args, **kwargs)
class VariablesGetList(pycamunda.base.CamundaRequest): process_instance_id = PathParameter('id') deserialize_values = QueryParameter('deserializeValues') def __init__(self, url: str, process_instance_id: str, deserialize_values: bool = False): """Get variables of a process instance. :param url: Camunda Rest engine URL. :param process_instance_id: Id of the process instance. :param deserialize_values: Whether serializable variable values are deserialized on server side. """ super().__init__(url=url + URL_SUFFIX + '/{id}/variables') self.process_instance_id = process_instance_id self.deserialize_values = deserialize_values def __call__(self, *args, **kwargs) -> typing.Dict[str, pycamunda.variable.Variable]: """Send the request.""" response = super().__call__(pycamunda.base.RequestMethod.GET, *args, **kwargs) return { name: pycamunda.variable.Variable.load(data=var_json) for name, var_json in response.json().items() }
class Evaluate(pycamunda.base._PathMixin, pycamunda.base.CamundaRequest): id_ = PathParameter('id') key = PathParameter('key') tenant_id = PathParameter('tenant-id') variables = BodyParameter('variables') def __init__(self, url: str, id_: str = None, key: str = None, tenant_id: str = None): """Evaluate the result of a decision definition. :param url: Camunda Rest engine URL. :param id_: Id of the decision definition. :param key: Key of the decision definition. :param tenant_id: Id of the tenant the decision definition belongs to. """ super().__init__(url=url + URL_SUFFIX + '/{path}/evaluate') self.id_ = id_ self.key = key self.tenant_id = tenant_id self.variables = {} def add_variable( self, name: str, value: typing.Any, type_: str = None, value_info: str = None ) -> None: """Add a variable for the evaluation of the decision definition. :param name: Name of the variable. :param value: Value of the variable. :param type_: Value type of the variable. :param value_info: Additional information regarding the value type. """ self.variables[name] = {'value': value, 'type': type_, 'valueInfo': value_info} def __call__(self, *args, **kwargs) -> typing.Tuple[typing.Dict]: """Send the request.""" response = super().__call__(pycamunda.base.RequestMethod.POST, *args, **kwargs) return tuple( { name: pycamunda.variable.Variable.load(var_json) for name, var_json in rule.items() } for rule in response.json() )
class UpdateHistoryTimeToLive(pycamunda.base.CamundaRequest): id_ = PathParameter('id') key = PathParameter('key') tenant_id = PathParameter('tenant-id') history_time_to_live = BodyParameter( 'historyTimeToLive', validate=lambda val: val is None or val >= 0 ) def __init__( self, url: str, history_time_to_live: int, id_: str = None, key: str = None, tenant_id: str = None ): """Update the history time to live of a process definition. :param url: Camunda Rest engine URL. :param history_time_to_live: New history time to live. Can be set to 'None'. :param id_: Id of the process definition. :param key: Key of the process definition. :param tenant_id: Id of the tenant the process definition belongs to. """ super().__init__(url=url + URL_SUFFIX + '/{path}/history-time-to-live') self.history_time_to_live = history_time_to_live self.id_ = id_ self.key = key self.tenant_id = tenant_id @property def url(self): if self.id_ is not None: return self._url.format(path=self.id_) if self.tenant_id is not None: return self._url.format(path=f'key/{self.key}/tenant-id/{self.tenant_id}') return self._url.format(path=f'key/{self.key}') def __call__(self, *args, **kwargs) -> None: """Send the request.""" response = super().__call__(pycamunda.base.RequestMethod.PUT, *args, **kwargs)
class VariablesDelete(pycamunda.base.CamundaRequest): process_instance_id = PathParameter('id') var_name = PathParameter('varName') def __init__(self, url: str, process_instance_id: str, var_name: str): """Delete a process instance variable. :param url: Camunda Rest engine URL. :param process_instance_id: Id of the process instance. :param var_name: Name of the variable. """ super().__init__(url=url + URL_SUFFIX + '/{id}/variables/{varName}') self.process_instance_id = process_instance_id self.var_name = var_name def __call__(self, *args, **kwargs) -> None: """Send the request.""" super().__call__(pycamunda.base.RequestMethod.DELETE, *args, **kwargs)
class VariablesModify(pycamunda.base.CamundaRequest): process_instance_id = PathParameter('id') modifications = BodyParameter('modifications') deletions = BodyParameter('deletions') def __init__(self, url: str, process_instance_id: str, deletions: typing.Iterable[str] = None): """Modify variables of a process instance. This can be either updating or deleting variables. :param url: Camunda Rest engine URL. :param process_instance_id: Id of the process instance. :param deletions: Variables to delete. """ super().__init__(url=url + URL_SUFFIX + '/{id}/variables') self.process_instance_id = process_instance_id self.deletions = deletions self.modifications = {} def add_variable(self, name: str, value: typing.Any, type_: str = None, value_info: typing.Any = None) -> None: """Add a variable to modify. :param name: Name of the variable. :param value: Value of the variable. :param type_: Value type of the variable. :param value_info: Additional information regarding the value type. """ self.modifications[name] = { 'value': value, 'type': type_, 'valueInfo': value_info } def body_parameters( self, apply: typing.Callable = ...) -> typing.Dict[str, typing.Any]: params = super().body_parameters(apply=apply) deletions = params.get('deletions', []) if isinstance(deletions, str): params['deletions'] = [deletions] else: params['deletions'] = list(deletions) return params def __call__(self, *args, **kwargs) -> None: """Send the request.""" super().__call__(pycamunda.base.RequestMethod.POST, *args, **kwargs)
class LocalVariablesGet(pycamunda.base.CamundaRequest): task_id = PathParameter('id') var_name = PathParameter('varName') deserialize_value = QueryParameter('deserializeValue') def __init__( self, url: str, task_id: str, var_name: str, deserialize_value: bool = False, binary: bool = False ): """Get a local variable of an user task. Local variables are variables that do only exist in the context of a task. :param url: Camunda Rest engine URL. :param task_id: Id of the task. :param var_name: Name of the variable. :param deserialize_value: Whether serializable variable values are deserialized on server side. :param binary: Whether the requested variable is a binary array or file variable. """ super().__init__(url=url + URL_SUFFIX + '/{id}/localVariables/{varName}') self.task_id = task_id self.var_name = var_name self.deserialize_value = deserialize_value self.binary = binary @property def url(self): return super().url + ('/data' if self.binary else '') def __call__(self, *args, **kwargs) -> pycamunda.variable.Variable: """Send the request.""" response = super().__call__(pycamunda.base.RequestMethod.GET, *args, **kwargs) if self.binary: return response.content return pycamunda.variable.Variable.load(data=response.json())
class MemberDelete(pycamunda.base.CamundaRequest): id_ = PathParameter('id') user_id = PathParameter('userId') def __init__(self, url: str, id_: str, user_id: str): """Delete a member from a group. :param url: Camunda Rest engine URL. :param id_: Id of the group. :param user_id: Id of the user. """ super().__init__(url=url + URL_SUFFIX + '/{id}' + URL_SUFFIX_MEMBERS + '/{userId}') self.id_ = id_ self.user_id = user_id def __call__(self, *args, **kwargs) -> None: """Send the request.""" super().__call__(pycamunda.base.RequestMethod.DELETE, *args, **kwargs)