Example #1
0
class Generate(pycamunda.base.CamundaRequest):

    source_process_definition_id = BodyParameter('sourceProcessDefinitionId')
    target_process_definition_id = BodyParameter('targetProcessDefinitionId')
    update_event_triggers = BodyParameter('updateEventTriggers')

    def __init__(
        self,
        url: str,
        source_process_definition_id: str,
        target_process_definition_id: str,
        update_event_triggers: bool = False
    ):
        """Generates a migration plan for 2 process definitions. The generated plan contains
        instructions that map equal activities between the process definitions.

        :param url: Camunda Rest engine URL.
        :param source_process_definition_id: Id of the source process definition for the migration.
        :param target_process_definition_id: Id of the target process definition for the migration.
        :param update_event_triggers: Whether instructions between events should be configured to
                                      update the event triggers.
        """
        super().__init__(url=url + URL_SUFFIX + '/generate')
        self.source_process_definition_id = source_process_definition_id
        self.target_process_definition_id = target_process_definition_id
        self.update_event_triggers = update_event_triggers

    def __call__(self, *args, **kwargs) -> MigrationPlan:
        """Send the request."""
        response = super().__call__(pycamunda.base.RequestMethod.POST, *args, **kwargs)

        return MigrationPlan.load(data=response.json())
Example #2
0
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)
Example #3
0
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)
Example #4
0
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)
Example #5
0
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)
Example #6
0
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)
Example #7
0
class Evaluate(pycamunda.base.CamundaRequest):

    variables = BodyParameter('variables')
    business_key = BodyParameter('businessKey')
    tenant_id = BodyParameter('tenantId')
    without_tenant_id = BodyParameter('withoutTenantId',
                                      provide=pycamunda.base.value_is_true)
    process_definition_id = BodyParameter('processDefinitionId')

    def __init__(self,
                 url: str,
                 business_key: str = None,
                 tenant_id: str = None,
                 without_tenant_id: bool = False,
                 process_definition_id: str = None):
        """Trigger the evaluation of conditional start events.

        :param url: Camunda Rest engine URL.
        :param business_key: Business key for the process instances that might be started.
        :param tenant_id: Tenant id of the conditions to evaluate.
        :param without_tenant_id: Whether evaluate only conditions that have no tenant.
        :param process_definition_id: Process definition id of the conditions to evaluate.
        """
        super().__init__(url=url + URL_SUFFIX)
        self.business_key = business_key
        self.tenant_id = tenant_id
        self.without_tenant_id = without_tenant_id
        self.process_definition_id = process_definition_id

        self.variables = {}

    def add_variable(self,
                     name: str,
                     value: typing.Any,
                     type_: str = None,
                     value_info: typing.Mapping = None) -> None:
        """Add a variable for the evaluation of the conditions.

        :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[pycamunda.processinst.ProcessInstance]:
        """Send the request."""
        response = super().__call__(pycamunda.base.RequestMethod.POST, *args,
                                    **kwargs)

        return tuple(
            pycamunda.processinst.ProcessInstance.load(data=result_json)
            for result_json in response.json())
Example #8
0
class _Event(pycamunda.base.CamundaRequest):

    name = BodyParameter('name')
    execution_id = BodyParameter('executionId')
    variables = BodyParameter('variables')
    tenant_id = BodyParameter('tenantId')
    without_tenant_id = BodyParameter('withoutTenantId',
                                      provide=pycamunda.base.value_is_true)

    def __init__(self,
                 url: str,
                 name: str,
                 execution_id: str = None,
                 tenant_id: str = None,
                 without_tenant_id: bool = False):
        """Deliver a signal to all process definitions and executions with the specific signal
        handler.

        :param url: Camunda Rest engine URL.
        :param name: Name of the signal.
        :param execution_id: Id of the execution to deliver the signal to.
        :param tenant_id: Id of the tenant. Signal will only be delivered to process definitions or
                          executions that belong to this tenant.
        :param without_tenant_id: Whether to deliver the signal only to process definitions or
                                  executions without tenant.
        """
        super().__init__(url=url + URL_SUFFIX)
        self.name = name
        self.execution_id = execution_id
        self.tenant_id = tenant_id
        self.without_tenant_id = without_tenant_id

        self.variables = {}

    def add_variable(self,
                     name: str,
                     value: typing.Any,
                     type_: str = None,
                     value_info: typing.Mapping = None):
        """Add variables to the process after correlating the message.

        :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
        }

        return self

    def __call__(self, *args, **kwargs) -> None:
        """Send the request."""
        super().__call__(pycamunda.base.RequestMethod.POST, *args, **kwargs)
Example #9
0
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)
Example #10
0
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())
Example #11
0
class Create(pycamunda.base.CamundaRequest):

    name = BodyParameter('deployment-name')
    enable_duplicate_filtering = BodyParameter('enable-duplicate-filtering')
    deploy_changed_only = BodyParameter('deploy-changed-only')
    source = BodyParameter('deployment-source')
    tenant_id = BodyParameter('tenant-id')

    def __init__(self,
                 url: str,
                 name: str,
                 source: str = None,
                 enable_duplicate_filtering: bool = False,
                 deploy_changed_only: bool = False,
                 tenant_id: str = None):
        """Create a deployment with one or multiple resources (e.g. bpmn diagrams).

        :param url: Camunda Rest engine url
        :param name: Name of the deployment.
        :param source: Source of the deployment.
        :param enable_duplicate_filtering: Whether to check if a deployment with the same name
                                           already exists. If one does, no new deployment is done.
        :param deploy_changed_only: Whether to check if already deployed resources that are also
                                    contained in this deployment have changed. The ones that do not
                                    will not created again.
        :param tenant_id: Id of the tenant to create the deployment for.
        """
        super().__init__(url=url + URL_SUFFIX + '/create')
        self.name = name
        self.source = source
        self.enable_duplicate_filtering = enable_duplicate_filtering
        self.deploy_changed_only = deploy_changed_only
        self.tenant_id = tenant_id

        self._files = []

    def add_resource(self, file) -> None:
        """Add a resource to the deployment.

        :param file: Binary data of the resource.
        """
        self._files.append(file)

    @property
    def files(self):
        return {
            f'resource-{i}': resource
            for i, resource in enumerate(self._files)
        }

    def __call__(self, *args, **kwargs) -> None:
        """Send the request."""
        assert bool(self.files), 'Cannot create deployment without resources.'
        super().__call__(pycamunda.base.RequestMethod.POST, *args, **kwargs)
Example #12
0
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)
Example #13
0
class Complete(pycamunda.base.CamundaRequest):

    id_ = PathParameter('id')
    worker_id = BodyParameter('workerId')
    variables = BodyParameter('variables')
    local_variables = BodyParameter('localVariables')

    def __init__(self, url: str, id_: str, worker_id: str):
        """Complete an external task that is locked for a worker.

        :param url: Camunda Rest engine URL.
        :param id_: Id of the external task.
        :param worker_id: Id of the worker the external tasks was locked for.
        """
        super().__init__(url=url + URL_SUFFIX + '/{id}/complete')
        self.id_ = id_
        self.worker_id = worker_id
        self.variables = {}
        self.local_variables = {}

    def add_variable(
        self, name: str, value: str, type_: str = None, value_info: typing.Mapping = 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 add_local_variable(
        self, name: str, value: str, type_: str = None, value_info: typing.Mapping = None
    ) -> None:
        """Add a local variable to send to Camunda. Local variables are set only in the scope of an
        external task.

        :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.local_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)
Example #14
0
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)
Example #15
0
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)
Example #16
0
class HandleBPMNError(pycamunda.base.CamundaRequest):

    id_ = PathParameter('id')
    worker_id = BodyParameter('workerId')
    error_code = BodyParameter('errorCode')
    error_message = BodyParameter('errorMessage')
    variables = BodyParameter('variables')

    def __init__(
        self,
        url: str,
        id_: str,
        worker_id: str,
        error_code: str,
        error_message: str = None
    ):
        """Report a business error for a running external task.

        :param url: Camunda Rest engine URL.
        :param id_: Id of the external task.
        :param worker_id: Id of the worker that locked the external task.
        :param error_code: Error code that identifies the predefined error.
        :param error_message: Error message that describes the error.
        """
        super().__init__(url=url + URL_SUFFIX + '/{id}/bpmnError')
        self.id_ = id_
        self.worker_id = worker_id
        self.error_code = error_code
        self.error_message = error_message
        self.variables = {}

    def add_variable(
        self, name: str, value: str, type_: str = None, value_info: typing.Mapping = 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)
Example #17
0
class HandleFailure(pycamunda.base.CamundaRequest):

    id_ = PathParameter('id')
    worker_id = BodyParameter('workerId')
    error_message = BodyParameter('errorMessage')
    error_details = BodyParameter('errorDetails')
    retries = BodyParameter('retries', validate=lambda val: val >= 0)
    retry_timeout = BodyParameter('retryTimeout', validate=lambda val: val >= 0)

    def __init__(
        self,
        url: str,
        id_: str,
        worker_id: str,
        error_message: str,
        error_details: str,
        retries: int,
        retry_timeout: int
    ):
        """Report a failure to execute a running external task.

        A number of retries and a timeout until the external task can be tried can be specified.
        If retries are set to 0, the external task cannot be fetched anymore and an incident is
        created. The message of the incident is set to the value of `error_message`.

        :param url: Camunda Rest engine URL.
        :param id_: Id of the external task.
        :param worker_id: Id of the worker that locked the external task.
        :param error_message: Error message that describes the reason of the failure.
        :param error_details: Error description.
        :param retries: How often the external task can be retried.
        :param retry_timeout: Timeout in milliseconds until the external task becomes available
        again for fetching.
        """
        super().__init__(url=url + URL_SUFFIX + '/{id}/failure')
        self.id_ = id_
        self.worker_id = worker_id
        self.error_message = error_message
        self.error_details = error_details
        self.retries = retries
        self.retry_timeout = retry_timeout

    def __call__(self, *args, **kwargs) -> None:
        """Send the request"""
        super().__call__(pycamunda.base.RequestMethod.POST, *args, **kwargs)
Example #18
0
class Create(pycamunda.base.CamundaRequest):

    id_ = BodyParameter('id')
    name = BodyParameter('name')

    def __init__(self, url: str, id_: str, name: str):
        """Create a new tenant.

        :param url: Camunda Rest engine URL.
        :param id_: Id of the tenant.
        :param name: Name of the tenant.
        """
        super().__init__(url=url + URL_SUFFIX + '/create')
        self.id_ = id_
        self.name = name

    def __call__(self, *args, **kwargs) -> None:
        """Send the request"""
        super().__call__(pycamunda.base.RequestMethod.POST, *args, **kwargs)
Example #19
0
class Update(pycamunda.base.CamundaRequest):

    id_ = PathParameter('id')
    permissions = BodyParameter('permissions')
    user_id = BodyParameter('userId')
    group_id = BodyParameter('groupId')
    resource_type = BodyParameter('resourceType')
    resource_id = BodyParameter('resourceId')

    def __init__(self,
                 url: str,
                 id_: str,
                 permissions: typing.Iterable[str],
                 resource_type: typing.Union[str,
                                             pycamunda.resource.ResourceType],
                 resource_id: str,
                 user_id: str = None,
                 group_id: str = None):
        """Update an auth.

        :param url: Camunda Rest engine URL.
        :param id_: Id of the authorization.
        :param permissions: Permissions provided by this authorization. A permission be 'READ' or
                            'CREATE' for example.
        :param user_id: Id of the user this authorization is for. The value '*' means all users.
        :param group_id: Id of the group this authorization is for.
        :param resource_type: Resource type this authorization is for.
        :param resource_id: Id of the resource. The value '*' means all instances of a resource.
        """
        super().__init__(url=url + URL_SUFFIX + '/{id}')
        self.id_ = id_
        self.permissions = permissions
        self.user_id = user_id
        self.group_id = group_id
        self.resource_type = resource_type
        self.resource_id = resource_id

    def __call__(self, *args, **kwargs) -> None:
        """Send the request."""
        assert (self.user_id is not None) != (self.group_id is not None), (
            'Either \'user_id\' or \'group_id\' has to be provided, not both.')
        super().__call__(pycamunda.base.RequestMethod.PUT, *args, **kwargs)
Example #20
0
class Complete(pycamunda.base.CamundaRequest):

    id_ = PathParameter('id')
    variables = BodyParameter('variables')
    with_variables_in_return = BodyParameter('withVariablesInReturn')

    def __init__(self, url: str, id_: str, with_variables_in_return: bool = False):
        """Complete an user task.

        :param url: Camunda Rest engine URL.
        :param id_: Id of the user task.
        """
        super().__init__(url=url + URL_SUFFIX + '/{id}/complete')
        self.id_ = id_
        self.with_variables_in_return = with_variables_in_return

        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
    ) -> typing.Optional[typing.Dict[str, pycamunda.variable.Variable]]:
        """Send the request."""
        response = super().__call__(pycamunda.base.RequestMethod.POST, *args, **kwargs)

        if self.with_variables_in_return:
            return {
                name: pycamunda.variable.Variable.load(var_json)
                for name, var_json in response.json().items()
            }
Example #21
0
class SetRetriesSync(pycamunda.base.CamundaRequest):

    retries = BodyParameter('retries', validate=lambda val: val >= 0)
    external_task_ids = BodyParameter('externalTaskIds')
    process_instance_ids = BodyParameter('processInstanceIds')
    external_task_query = BodyParameter('externalTaskQuery')
    process_instance_query = BodyParameter('processInstanceQuery')
    historic_process_instance_query = BodyParameter('historicProcessInstanceQuery')

    def __init__(self, url: str, retries: int, external_task_ids: typing.Iterable[str]):
        """Sets the number of retries of external tasks synchronously.

        :param url: Camunda Rest engine URL.
        :param retries: New number of retries of the external tasks.
        :param external_task_ids: Ids of the external tasks.
        """
        super().__init__(url=url + URL_SUFFIX + '/retries')
        self.retries = retries
        self.external_task_ids = external_task_ids
        self.process_instance_ids = None  # TODO
        self.external_task_query = None  # TODO
        self.process_instance_query = None  # TODO
        self.historic_process_instance_query = None  # TODO

    def __call__(self, *args, **kwargs) -> None:
        """Send the request"""
        super().__call__(pycamunda.base.RequestMethod.PUT, *args, **kwargs)
Example #22
0
class Update(pycamunda.base.CamundaRequest):

    id_ = PathParameter('id')
    new_id = BodyParameter('id')
    new_name = BodyParameter('name')

    def __init__(self, url: str, id_: str, new_id: str, new_name: str):
        """Update a tenant.

        :param url: Camunda Rest engine URL.
        :param id_: Id of the tenant.
        :param new_id: New id of the tenant.
        :param new_name: New name of the tenant.
        """
        super().__init__(url=url + URL_SUFFIX + '/{id}')
        self.id_ = id_
        self.new_id = new_id
        self.new_name = new_name

    def __call__(self, *args, **kwargs) -> None:
        """Send the request"""
        super().__call__(pycamunda.base.RequestMethod.PUT, *args, **kwargs)
Example #23
0
class Create(pycamunda.base.CamundaRequest):

    id_ = BodyParameter('id')
    first_name = BodyParameter('firstName')
    last_name = BodyParameter('lastName')
    email = BodyParameter('email')
    profile = BodyParameterContainer('profile', id_, first_name, last_name,
                                     email)

    password = BodyParameter('password')
    credentials = BodyParameterContainer('credentials', password)

    def __init__(self,
                 url: str,
                 id_: str = None,
                 first_name: str = None,
                 last_name: str = None,
                 email: str = None,
                 password: str = None):
        """Create a new user.

        :param url: Camunda Rest engine URL.
        :param id_: Id of the user.
        :param first_name: First name of the user.
        :param last_name: Last name of the user.
        :param email: Email of the user.
        :param password: Password of the user.
        """
        super().__init__(url=url + URL_SUFFIX + '/create')
        self.id_ = id_
        self.first_name = first_name
        self.last_name = last_name
        self.email = email
        self.password = password

    def __call__(self, *args, **kwargs) -> None:
        """Send the request"""
        super().__call__(pycamunda.base.RequestMethod.POST, *args, **kwargs)
Example #24
0
class Create(_Criteria):

    resource_type = BodyParameter('resourceType')
    name = BodyParameter('name')
    owner = BodyParameter('owner')

    def __init__(self, url: str, name: str, owner: str = None):
        """Create a new filter.

        :param url: Camunda Rest engine URL.
        :param name: Name of the filter.
        :param owner: User id of the owner of the filter.
        """
        super().__init__(url=url + URL_SUFFIX + '/create')
        self.resource_type = 'Task'
        self.name = name
        self.owner = owner

    def __call__(self, *args, **kwargs) -> Filter:
        """Send the request"""
        response = super().__call__(pycamunda.base.RequestMethod.POST, *args, **kwargs)

        return Filter.load(response.json())
Example #25
0
class ExtendLock(pycamunda.base.CamundaRequest):

    id_ = PathParameter('id')
    new_duration = BodyParameter('newDuration')
    worker_id = BodyParameter('workerId')

    def __init__(self, url: str, id_: str, new_duration: int, worker_id: str):
        """Unlock an external task.

        :param url: Camunda Rest engine URL.
        :param id_: Id of the external task.
        :param new_duration: New duration in milliseconds how long the external task wants to be
                             locked.
        :param worker_id: Id of the worker that locked this external task.
        """
        super().__init__(url=url + URL_SUFFIX + '/{id}/extendLock')
        self.id_ = id_
        self.new_duration = new_duration
        self.worker_id = worker_id

    def __call__(self, *args, **kwargs) -> None:
        """Send the request"""
        super().__call__(pycamunda.base.RequestMethod.POST, *args, **kwargs)
Example #26
0
class UpdateCredentials(pycamunda.base.CamundaRequest):

    id_ = PathParameter('id')
    password = BodyParameter('password')
    authenticated_user_password = BodyParameter('authenticatedUserPassword')

    def __init__(self, url: str, id_: str, password: str,
                 authenticated_user_password: str):
        """Update a user's credentials (password).

        :param url: Camunda Rest engine URL.
        :param id_: Id of the user.
        :param password: New password of the user.
        :param authenticated_user_password: Password of the authenticated user who changes the
                                            password.
        """
        super().__init__(url=url + URL_SUFFIX + '/{id}/credentials')
        self.id_ = id_
        self.password = password
        self.authenticated_user_password = authenticated_user_password

    def __call__(self, *args, **kwargs) -> None:
        """Send the request"""
        super().__call__(pycamunda.base.RequestMethod.PUT, *args, **kwargs)
Example #27
0
class Configure(pycamunda.base.CamundaRequest):

    enable_telemetry = BodyParameter('enableTelemetry')

    def __init__(self, url: str, enable_telemetry: bool):
        """Modify the telemetry configuration.

        :param url: Camunda Rest engine URL.
        :param enable_telemetry: Whether to enable telemetry configuration.
        """
        super().__init__(url=url + URL_SUFFIX)
        self.enable_telemetry = enable_telemetry

    def __call__(self, *args, **kwargs) -> None:
        """Send the request."""
        super().__call__(pycamunda.base.RequestMethod.POST, *args, **kwargs)
Example #28
0
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()
        )
Example #29
0
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)
Example #30
0
class _ActivateSuspend(pycamunda.base.CamundaRequest):

    id_ = PathParameter('id')
    suspended = BodyParameter('suspended')

    def __init__(self, url: str, id_: str, suspended: bool):
        """Activate or Suspend a process definition.

        :param url: Camunda Rest engine URL.
        :param id_: Id of the process instance.
        :param suspended: Whether to suspend or activate the process instance.
        """
        super().__init__(url=url + URL_SUFFIX + '/{id}/suspended')
        self.id_ = id_
        self.suspended = suspended

    def __call__(self, *args, **kwargs) -> None:
        """Send the request."""
        super().__call__(pycamunda.base.RequestMethod.PUT, *args, **kwargs)