예제 #1
0
    def create_successor_task(self, dossier):
        # we need all task field values from the forwarding
        fielddata = {}
        for fieldname in ITask.names():
            value = ITask.get(fieldname).get(self.context)
            fielddata[fieldname] = value

        # Reset issuer to the current inbox
        fielddata['issuer'] = get_current_org_unit().inbox().id()

        # Predefine the task_type to avoid tasks with an invalid task_type
        fielddata['task_type'] = FORWARDING_SUCCESSOR_TYPE

        # lets create a new task - the successor task
        task = createContentInContainer(
            dossier, 'opengever.task.task', **fielddata)

        # Add issuer and responsible to the watchers of the newly created task
        center = notification_center()
        center.add_task_responsible(task, task.responsible)
        center.add_task_issuer(task, task.issuer)

        # copy documents and map the intids
        intids_mapping = _copy_documents_from_forwarding(self.context, task)

        # copy the responses
        response_transporter = IResponseTransporter(task)
        response_transporter.get_responses(
            get_current_admin_unit().id(),
            '/'.join(self.context.getPhysicalPath()),
            intids_mapping=intids_mapping)

        return task
    def test_encode(self):

        values = [
            'hello'
            'hell\xc3\xb6', u'helllo',
            datetime(2012, 1, 1),
            DateTime(2012, 1, 1),
            RelationValue(1111), ['hello', u'hello', 'hell\xc3\xb6'],
            PersistentList(['hello', u'hello']),
            [RelationValue(1111),
             RelationValue(3333),
             RelationValue(5555)]
        ]

        task = self.providing_stub([ITask])

        self.replay()

        transporter = IResponseTransporter(task)
        transporter.intids_mapping = {1111: 2222, 3333: 5555, 5555: 3333}

        for value in values:
            encoded_value = json.dumps(transporter._encode(value))
            decoded_value = transporter._decode(json.loads(encoded_value))

            # compare the value with the de- and encoded value
            if isinstance(value, list):
                for i in range(len(value)):
                    self._compare(value[i], decoded_value[i],
                                  transporter.intids_mapping)
            else:
                self._compare(value, decoded_value, transporter.intids_mapping)
예제 #3
0
    def store_copy_in_remote_yearfolder(self, refusing_unit_id):
        transporter = Transporter()
        jsondata = json.dumps(transporter.extract(self.context))
        request_data = {REQUEST_KEY: jsondata, }

        response = dispatch_json_request(
            refusing_unit_id, '@@store_refused_forwarding',
            data=request_data)

        if response.get('status') not in [
                STATUS_SUCCESSFULL, STATUS_ALLREADY_DONE]:
            raise Exception(
                'Storing the forwarding on remote yearfolder failed')

        remote_task = response.get('remote_task')
        if response.get('status') != STATUS_ALLREADY_DONE:
            # transport responses
            response_transporter = IResponseTransporter(self.context)
            response_transporter.send_responses(
                refusing_unit_id, remote_task)

            # transport documents
            for document in get_documents_of_task(self.context):
                transporter.transport_to(
                    document, refusing_unit_id, remote_task)

        return self.get_remote_task_url(refusing_unit_id, remote_task)
예제 #4
0
    def store_copy_in_remote_yearfolder(self, refusing_client_id):
        transporter = getUtility(ITransporter)
        jsondata = json.dumps(transporter._extract_data(self.context))
        request_data = {
            REQUEST_KEY: jsondata,
        }

        response = remote_json_request(refusing_client_id,
                                       '@@store_refused_forwarding',
                                       data=request_data)

        if response.get('status') not in [
                STATUS_SUCCESSFULL, STATUS_ALLREADY_DONE
        ]:
            raise Exception(
                'Storing the forwarding on remote yearfolder failed')

        remote_task = response.get('remote_task')
        if response.get('status') != STATUS_ALLREADY_DONE:
            # transport responses
            response_transporter = IResponseTransporter(self.context)
            response_transporter.send_responses(refusing_client_id,
                                                remote_task)

            # transport documents
            for document in get_documents_of_task(self.context):
                transporter.transport_to(document, refusing_client_id,
                                         remote_task)

        return self.get_remote_task_url(refusing_client_id, remote_task)
    def test_encode(self):

        values = [
            'hello'
            'hell\xc3\xb6',
            u'helllo',
            datetime(2012, 1, 1),
            DateTime(2012, 1, 1),
            RelationValue(1111),
            ['hello', u'hello', 'hell\xc3\xb6'],
            PersistentList(['hello', u'hello']),
            [RelationValue(1111), RelationValue(3333), RelationValue(5555)]
            ]

        task = self.providing_stub([ITask])

        self.replay()

        transporter = IResponseTransporter(task)
        transporter.intids_mapping = {1111: 2222, 3333: 5555, 5555: 3333}

        for value in values:
            encoded_value = json.dumps(transporter._encode(value))
            decoded_value = transporter._decode(json.loads(encoded_value))

            # compare the value with the de- and encoded value
            if isinstance(value, list):
                for i in range(len(value)):
                    self._compare(
                        value[i], decoded_value[i], transporter.intids_mapping)
            else:
                self._compare(value, decoded_value, transporter.intids_mapping)
예제 #6
0
def accept_task_with_successor(dossier, predecessor_oguid, response_text):
    predecessor = Task.query.by_oguid(predecessor_oguid)

    # Transport the original task (predecessor) to this dossier. The new
    # response and task change is not yet done and will be done later. This
    # is necessary for beeing as transaction aware as possible.
    transporter = Transporter()
    successor = transporter.transport_from(dossier, predecessor.admin_unit_id,
                                           predecessor.physical_path)
    successor_tc = ISuccessorTaskController(successor)

    # Set the "X-CREATING-SUCCESSOR" flag for preventing the event handler
    # from creating additional responses per added document.
    successor.REQUEST.set('X-CREATING-SUCCESSOR', True)

    # copy documents and map the intids
    doc_transporter = getUtility(ITaskDocumentsTransporter)

    comment = _(u'version_message_accept_task',
                default=u'Document copied from task (task accepted)')
    intids_mapping = doc_transporter.copy_documents_from_remote_task(
        predecessor, successor, comment=comment)

    # copy the responses
    response_transporter = IResponseTransporter(successor)
    response_transporter.get_responses(predecessor.admin_unit_id,
                                       predecessor.physical_path,
                                       intids_mapping=intids_mapping)

    # Move current responsible from predecessor task to successor
    center = notification_center()
    center.add_task_responsible(successor, successor.responsible)

    # First "accept" the successor task..
    accept_task_with_response(successor, response_text)

    transaction.savepoint()
    response_text = response_text or ''
    request_data = {
        'text': response_text.encode('utf-8'),
        'successor_oguid': successor_tc.get_oguid()
    }

    response = dispatch_request(predecessor.admin_unit_id,
                                '@@accept_task_workflow_transition',
                                path=predecessor.physical_path,
                                data=request_data)

    response_body = response.read()
    if response_body.strip() != 'OK':
        raise TaskRemoteRequestError(
            'Adding the response and changing the workflow state on the '
            'predecessor task failed.')

    # Connect the predecessor and the successor task. This needs to be done
    # that late for preventing a deadlock because of the locked tasks table.
    successor_tc.set_predecessor(predecessor_oguid)

    return successor
예제 #7
0
    def setUp(self):
        super(TestResponseTransporterSerialization, self).setUp()
        grok('opengever.task.transporter')

        task = self.providing_stub([ITask])
        self.replay()
        self.transporter = IResponseTransporter(task)
        self.transporter.intids_mapping = {}
    def test_encoder_raise_valueerror_when_intid_not_in_mapping(self):
        with self.login(self.regular_user):
            transporter = IResponseTransporter(self.task)
            transporter.intids_mapping = {}

        value = RelationValue(111)
        with self.assertRaises(ValueError):
            transporter._encode(value)
    def test_unicode_encoding_decoding(self):
        with self.login(self.regular_user):
            transporter = IResponseTransporter(self.task)

        self.assertEquals([u'unicode', u'hello'],
                          transporter._encode(u'hello'))
        self.assertEquals(u'hello',
                          transporter._decode([u'string:utf8', u'hello']))
    def test_unicode_encoding_decoding(self):
        with self.login(self.regular_user):
            transporter = IResponseTransporter(self.task)

        self.assertEquals([u'unicode', u'hello'],
                          transporter._encode(u'hello'))
        self.assertEquals(u'hello',
                          transporter._decode([u'string:utf8', u'hello']))
    def test_encoder_raise_valueerror_when_intid_not_in_mapping(self):
        with self.login(self.regular_user):
            transporter = IResponseTransporter(self.task)
            transporter.intids_mapping = {}

        value = RelationValue(111)
        with self.assertRaises(ValueError):
            transporter._encode(value)
예제 #12
0
class TestResponseTransporterSerialization(MockTestCase):

    def setUp(self):
        super(TestResponseTransporterSerialization, self).setUp()
        grok('opengever.task.transporter')

        task = self.providing_stub([ITask])
        self.replay()
        self.transporter = IResponseTransporter(task)
        self.transporter.intids_mapping = {}

    def assert_serialization(self, value):
        encoded = json.dumps(self.transporter._encode(value))
        self.assertEquals(value, self.transporter._decode(json.loads(encoded)))

    def test_string_encoding_decoding(self):
        self.assertEquals([u'string:utf8', u'hello'],
                          self.transporter._encode('hello'))
        self.assertEquals('hello',
                          self.transporter._decode([u'string:utf8', u'hello']))

    def test_unicode_encoding_decoding(self):
        self.assertEquals([u'unicode', u'hello'],
                          self.transporter._encode(u'hello'))
        self.assertEquals(u'hello',
                          self.transporter._decode([u'string:utf8', u'hello']))

    def test_handles_non_ascii_strings(self):
        self.assert_serialization('hell\xc3\xb6')

    def test_datetime_encoding_decoding(self):
        self.assert_serialization(datetime(2015, 11, 6, 13, 30))

    def test_list_encoding_decoding(self):
        self.assert_serialization(
            ['hell\xc3\xb6', u'hello', datetime(2015, 11, 6, 13, 30)])

    def test_dict_encoding_decoding(self):
        self.assert_serialization(
            {'key1': 'hell\xc3\xb6',
             'key2': u'hello',
             'key3': date(2015, 11, 6)})

    def test_relationvalue_encoding_decoding(self):
        self.transporter.intids_mapping = {111:222}
        value = RelationValue(111)
        self.assertEquals(
            RelationValue(222).to_id,
            self.transporter._decode(self.transporter._encode(value)).to_id)

    def test_encoder_raise_valueerror_when_intid_not_in_mapping(self):
        value = RelationValue(111)
        with self.assertRaises(ValueError):
            self.transporter._encode(value)

    def test_DateTime_encoding_decoding(self):
        self.assert_serialization(DateTime(2015, 11, 6, 13, 30))
    def test_relationvalue_encoding_decoding(self):
        with self.login(self.regular_user):
            transporter = IResponseTransporter(self.task)

        transporter.intids_mapping = {111:222}
        value = RelationValue(111)
        self.assertEquals(
            RelationValue(222).to_id,
            transporter._decode(transporter._encode(value)).to_id)
    def test_relationvalue_encoding_decoding(self):
        with self.login(self.regular_user):
            transporter = IResponseTransporter(self.task)

        transporter.intids_mapping = {111: 222}
        value = RelationValue(111)
        self.assertEquals(
            RelationValue(222).to_id,
            transporter._decode(transporter._encode(value)).to_id)
예제 #15
0
def accept_task_with_successor(dossier, predecessor_oguid, response_text):
    predecessor = Task.query.by_oguid(predecessor_oguid)

    # Set the "X-CREATING-SUCCESSOR" flag for preventing the event handler
    # from creating additional responses per added document.
    getRequest().set('X-CREATING-SUCCESSOR', True)

    # Transport the original task (predecessor) to this dossier. The new
    # response and task change is not yet done and will be done later. This
    # is necessary for beeing as transaction aware as possible.
    transporter = Transporter()
    successor = transporter.transport_from(
        dossier, predecessor.admin_unit_id, predecessor.physical_path)
    successor_tc = ISuccessorTaskController(successor)

    # copy documents and map the intids
    doc_transporter = getUtility(ITaskDocumentsTransporter)

    comment = _(u'version_message_accept_task',
               default=u'Document copied from task (task accepted)')
    intids_mapping = doc_transporter.copy_documents_from_remote_task(
        predecessor, successor, comment=comment)

    # copy the responses
    response_transporter = IResponseTransporter(successor)
    response_transporter.get_responses(predecessor.admin_unit_id,
                                       predecessor.physical_path,
                                       intids_mapping=intids_mapping)

    # Move current responsible from predecessor task to successor
    center = notification_center()
    center.add_task_responsible(successor, successor.responsible)

    # First "accept" the successor task..
    accept_task_with_response(successor, response_text)

    transaction.savepoint()
    response_text = response_text or ''
    request_data = {'text': response_text.encode('utf-8'),
                    'successor_oguid': successor_tc.get_oguid()}

    response = dispatch_request(predecessor.admin_unit_id,
                                '@@accept_task_workflow_transition',
                                path=predecessor.physical_path,
                                data=request_data)

    response_body = response.read()
    if response_body.strip() != 'OK':
        raise TaskRemoteRequestError(
            'Adding the response and changing the workflow state on the '
            'predecessor task failed.')

    # Connect the predecessor and the successor task. This needs to be done
    # that late for preventing a deadlock because of the locked tasks table.
    successor_tc.set_predecessor(predecessor_oguid)

    return successor
예제 #16
0
def assign_forwarding_to_dossier(
        context, forwarding_oguid, dossier, response_text):

    forwarding = Task.query.by_oguid(forwarding_oguid)

    forwarding_obj = context.unrestrictedTraverse(
        forwarding.physical_path.encode('utf-8'))

    # we need all task field values from the forwarding
    fielddata = {}
    for fieldname in ITask.names():
        value = ITask.get(fieldname).get(forwarding_obj)
        fielddata[fieldname] = value

    # Reset issuer to the current inbox
    fielddata['issuer'] = get_current_org_unit().inbox().id()

    # Predefine the task_type to avoid tasks with an invalid task_type
    fielddata['task_type'] = FORWARDING_SUCCESSOR_TYPE

    # lets create a new task - the successor task
    task = createContentInContainer(
        dossier, 'opengever.task.task', **fielddata)

    successor_tc_task = ISuccessorTaskController(task)

    # Add issuer and responsible to the watchers of the newly created task
    center = notification_center()
    center.add_task_responsible(task, task.responsible)
    center.add_task_issuer(task, task.issuer)

    # copy documents and map the intids
    intids_mapping = _copy_documents_from_forwarding(forwarding_obj, task)

    # copy the responses
    response_transporter = IResponseTransporter(task)
    response_transporter.get_responses(
        get_current_admin_unit().id(),
        '/'.join(forwarding_obj.getPhysicalPath()),
        intids_mapping=intids_mapping)

    # close and store the forwarding in yearfolder
    change_task_workflow_state(
        forwarding_obj,
        'forwarding-transition-assign-to-dossier',
        text=response_text,
        successor_oguid=successor_tc_task.get_oguid())

    IYearfolderStorer(forwarding_obj).store_in_yearfolder()

    # successor
    successor_tc_task.set_predecessor(forwarding_oguid)

    return task
예제 #17
0
def accept_task_with_successor(dossier, predecessor_oguid, response_text):

    predecessor = getUtility(ITaskQuery).get_task_by_oguid(predecessor_oguid)

    # Transport the original task (predecessor) to this dossier. The new
    # response and task change is not yet done and will be done later. This
    # is necessary for beeing as transaction aware as possible.
    transporter = getUtility(ITransporter)
    successor = transporter.transport_from(
        dossier, predecessor.client_id, predecessor.physical_path)
    successor_tc = ISuccessorTaskController(successor)

    # Set the "X-CREATING-SUCCESSOR" flag for preventing the event handler
    # from creating additional responses per added document.
    successor.REQUEST.set('X-CREATING-SUCCESSOR', True)

    # copy documents and map the intids
    doc_transporter = getUtility(ITaskDocumentsTransporter)
    with CustomInitialVersionMessage(
        _(u'version_message_accept_task',
          default=u'Document copied from task (task accepted)'),
        dossier.REQUEST):
        intids_mapping = doc_transporter.copy_documents_from_remote_task(
            predecessor, successor)

    # copy the responses
    response_transporter = IResponseTransporter(successor)
    response_transporter.get_responses(predecessor.client_id,
                                       predecessor.physical_path,
                                       intids_mapping=intids_mapping)

    # First "accept" the successor task..
    accept_task_with_response(successor, response_text)

    transaction.savepoint()
    response_text = response_text or ''
    request_data = {'text': response_text.encode('utf-8'),
                    'successor_oguid': successor_tc.get_oguid()}

    response = remote_request(predecessor.client_id,
                              '@@accept_task_workflow_transition',
                              path=predecessor.physical_path,
                              data=request_data)

    if response.read().strip() != 'OK':
        raise Exception('Adding the response and changing the '
                        'workflow state on the predecessor task '
                        'failed.')

    # Connect the predecessor and the successor task. This needs to be done
    # that late for preventing a deadlock because of the locked tasks table.
    successor_tc.set_predecessor(predecessor_oguid)

    return successor
예제 #18
0
def assign_forwarding_to_dossier(context, forwarding_oguid, dossier,
                                 response_text):

    forwarding = Task.query.by_oguid(forwarding_oguid)

    forwarding_obj = context.unrestrictedTraverse(
        forwarding.physical_path.encode('utf-8'))

    # we need all task field values from the forwarding
    fielddata = {}
    for fieldname in ITask.names():
        value = ITask.get(fieldname).get(forwarding_obj)
        fielddata[fieldname] = value

    # Reset issuer to the current inbox
    fielddata['issuer'] = get_current_org_unit().inbox().id()

    # Predefine the task_type to avoid tasks with an invalid task_type
    fielddata['task_type'] = FORWARDING_SUCCESSOR_TYPE

    # lets create a new task - the successor task
    task = createContentInContainer(dossier, 'opengever.task.task',
                                    **fielddata)

    successor_tc_task = ISuccessorTaskController(task)

    # Add issuer and responsible to the watchers of the newly created task
    center = notification_center()
    center.add_task_responsible(task, task.responsible)
    center.add_task_issuer(task, task.issuer)

    # copy documents and map the intids
    intids_mapping = _copy_documents_from_forwarding(forwarding_obj, task)

    # copy the responses
    response_transporter = IResponseTransporter(task)
    response_transporter.get_responses(get_current_admin_unit().id(),
                                       '/'.join(
                                           forwarding_obj.getPhysicalPath()),
                                       intids_mapping=intids_mapping)

    # close and store the forwarding in yearfolder
    change_task_workflow_state(forwarding_obj,
                               'forwarding-transition-assign-to-dossier',
                               text=response_text,
                               successor_oguid=successor_tc_task.get_oguid())

    IYearfolderStorer(forwarding_obj).store_in_yearfolder()

    # successor
    successor_tc_task.set_predecessor(forwarding_oguid)

    return task
예제 #19
0
    def test_syncing_response_changes(self):
        add_simple_response(
            self.task,
            text=u'Neu zugewiesen',
            field_changes=[(ITask['responsible'], 'peter.mueller'),
                           (ITask['responsible_client'], 'client2')],
            transition='task-transition-reassign',
        )

        copy = create(Builder('task').in_state('task-state-in-progress'))
        IResponseTransporter(self.task).send_responses(
            'client1', copy.get_physical_path())

        self.assertEquals([{
            u'after': u'peter.mueller',
            u'id': u'responsible',
            u'name': u'label_responsible',
            u'before': u'hugo.boss'
        }, {
            u'after': u'client2',
            u'id': u'responsible_client',
            u'name': u'label_resonsible_client',
            u'before': u'client1'
        }],
                          IResponseContainer(copy)[1].changes)
    def test_list_encoding_decoding(self):
        with self.login(self.regular_user):
            transporter = IResponseTransporter(self.task)

        self.assert_serialization(
            ['hell\xc3\xb6', u'hello',
             datetime(2015, 11, 6, 13, 30)], transporter)
예제 #21
0
def assign_forwarding_to_dossier(
    context, forwarding_oguid, dossier, response_text):

    forwarding = getUtility(ITaskQuery).get_task_by_oguid(forwarding_oguid)

    forwarding_obj = context.unrestrictedTraverse(
        forwarding.physical_path.encode('utf-8'))

    # we need all task field values from the forwarding
    fielddata = {}
    for fieldname in ITask.names():
        value = ITask.get(fieldname).get(forwarding_obj)
        fielddata[fieldname] = value

    # lets create a new task - the successor task
    task = createContentInContainer(
        dossier, 'opengever.task.task', **fielddata)

    successor_tc_task = ISuccessorTaskController(task)

    # copy documents and map the intids
    intids_mapping = _copy_documents_from_forwarding(forwarding_obj, task)

    # copy the responses
    response_transporter = IResponseTransporter(task)
    response_transporter.get_responses(
        get_client_id(),
        '/'.join(forwarding_obj.getPhysicalPath()),
        intids_mapping=intids_mapping)

    # close and store the forwarding in yearfolder
    change_task_workflow_state(
        forwarding_obj,
        'forwarding-transition-assign-to-dossier',
        text=response_text,
        successor_oguid=successor_tc_task.get_oguid())

    inbox = aq_parent(aq_inner(forwarding_obj))
    yearfolder = _get_yearfolder(inbox)
    clipboard = inbox.manage_cutObjects((forwarding_obj.getId(),))
    yearfolder.manage_pasteObjects(clipboard)

    # successor
    successor_tc_task.set_predecessor(forwarding_oguid)

    return task
예제 #22
0
def assign_forwarding_to_dossier(context, forwarding_oguid, dossier,
                                 response_text):

    forwarding = getUtility(ITaskQuery).get_task_by_oguid(forwarding_oguid)

    forwarding_obj = context.unrestrictedTraverse(
        forwarding.physical_path.encode('utf-8'))

    # we need all task field values from the forwarding
    fielddata = {}
    for fieldname in ITask.names():
        value = ITask.get(fieldname).get(forwarding_obj)
        fielddata[fieldname] = value

    # lets create a new task - the successor task
    task = createContentInContainer(dossier, 'opengever.task.task',
                                    **fielddata)

    successor_tc_task = ISuccessorTaskController(task)

    # copy documents and map the intids
    intids_mapping = _copy_documents_from_forwarding(forwarding_obj, task)

    # copy the responses
    response_transporter = IResponseTransporter(task)
    response_transporter.get_responses(get_client_id(),
                                       '/'.join(
                                           forwarding_obj.getPhysicalPath()),
                                       intids_mapping=intids_mapping)

    # close and store the forwarding in yearfolder
    change_task_workflow_state(forwarding_obj,
                               'forwarding-transition-assign-to-dossier',
                               text=response_text,
                               successor_oguid=successor_tc_task.get_oguid())

    inbox = aq_parent(aq_inner(forwarding_obj))
    yearfolder = _get_yearfolder(inbox)
    clipboard = inbox.manage_cutObjects((forwarding_obj.getId(), ))
    yearfolder.manage_pasteObjects(clipboard)

    # successor
    successor_tc_task.set_predecessor(forwarding_oguid)

    return task
    def test_dict_encoding_decoding(self):
        with self.login(self.regular_user):
            transporter = IResponseTransporter(self.task)

        self.assert_serialization(
            {
                'key1': 'hell\xc3\xb6',
                'key2': u'hello',
                'key3': date(2015, 11, 6)
            }, transporter)
예제 #24
0
    def test_send_responses(self):
        copy = create(Builder('task').in_state('task-state-in-progress'))
        IResponseTransporter(self.task).send_responses(
            'client1', copy.get_physical_path())

        responses = IResponseContainer(copy)
        self.assertEquals(1, len(responses))
        self.assertEquals('task-transition-open-in-progress',
                          responses[0].transition)
        self.assertEquals(u'Ich \xfcbernehme diese Aufgabe', responses[0].text)
        self.assertEquals(TEST_USER_ID, responses[0].creator)
예제 #25
0
    def test_get_responses(self):
        copy = create(Builder('task')
                      .in_state('task-state-in-progress')
                      .having(responsible_client=u'org-unit-1'))
        IResponseTransporter(copy).get_responses(
            'admin-unit-1', self.task.get_physical_path(), {})

        responses = IResponseContainer(copy)
        self.assertEquals(1, len(responses))
        self.assertEquals('task-transition-open-in-progress', responses.list()[0].transition)
        self.assertEquals(u'Ich \xfcbernehme diese Aufgabe', responses.list()[0].text)
        self.assertEquals(TEST_USER_ID, responses.list()[0].creator)
예제 #26
0
    def test_deadline_change_synchronisation(self):
        IDeadlineModifier(self.task).modify_deadline(
            date(2016, 03, 29), u'Frist wurde verschoben.',
            u'task-transition-modify-deadline')

        copy = create(Builder('task').in_state('task-state-in-progress'))
        IResponseTransporter(self.task).send_responses(
            'client1', copy.get_physical_path())

        self.assertEquals([{
            u'after': date(2016, 03, 29),
            u'id': u'deadline',
            u'name': u'label_deadline',
            u'before': date(2016, 03, 27)
        }],
                          IResponseContainer(copy)[1].changes)
예제 #27
0
def accept_forwarding_with_successor(
    context, predecessor_oguid, response_text, dossier=None):

    # the predessecor (the forwarding on the remote client)
    predecessor = getUtility(ITaskQuery).get_task_by_oguid(predecessor_oguid)

    # get the inbox
    cat = getToolByName(context, 'portal_catalog')
    inboxes = cat(portal_type="opengever.inbox.inbox")

    if len(inboxes) == 0:
        raise Unauthorized()
    else:
        inbox = inboxes[0].getObject()

    # transport the remote forwarding to the inbox or actual yearfolder
    transporter = getUtility(ITransporter)
    if dossier:
        yearfolder = _get_yearfolder(inbox, )
        successor_forwarding = transporter.transport_from(
            yearfolder, predecessor.client_id, predecessor.physical_path)
    else:
        successor_forwarding = transporter.transport_from(
            inbox, predecessor.client_id, predecessor.physical_path)

    # Replace the issuer with the current inbox
    successor_forwarding.issuer = u'inbox:%s' % get_client_id()

    # Set the "X-CREATING-SUCCESSOR" flag for preventing the event handler
    # from creating additional responses per added document.
    successor_forwarding.REQUEST.set('X-CREATING-SUCCESSOR', True)

    successor_tc = ISuccessorTaskController(successor_forwarding)

    # copy documents and map the intids
    doc_transporter = getUtility(ITaskDocumentsTransporter)
    with CustomInitialVersionMessage(
        _(u'version_message_accept_forwarding',
          default=u'Document copied from forwarding (forwarding accepted)'),
        context.REQUEST):
        intids_mapping = doc_transporter.copy_documents_from_remote_task(
            predecessor, successor_forwarding)

    # copy the responses
    response_transporter = IResponseTransporter(successor_forwarding)
    response_transporter.get_responses(predecessor.client_id,
                                       predecessor.physical_path,
                                       intids_mapping=intids_mapping)

    # if a dossier is given means that a successor task must
    # be created in a new or a existing dossier
    if dossier:
        # we need all task field values from the forwarding
        fielddata = {}
        for fieldname in ITask.names():
            value = ITask.get(fieldname).get(successor_forwarding)
            fielddata[fieldname] = value

        # lets create a new task - the successor task
        task = createContentInContainer(
            dossier, 'opengever.task.task', **fielddata)

        # copy documents and map the intids

        intids_mapping = _copy_documents_from_forwarding(
            successor_forwarding, task)

        # copy the responses
        response_transporter = IResponseTransporter(task)
        response_transporter.get_responses(
            get_client_id(),
            '/'.join(successor_forwarding.getPhysicalPath()),
            intids_mapping=intids_mapping)

        # successor
        successor_tc_task = ISuccessorTaskController(task)

    transaction.savepoint()

    # Close the predessecor forwarding
    response_text = response_text or ''
    request_data = {'response_text': response_text.encode('utf-8'),
                    'successor_oguid': successor_tc.get_oguid(),
                    'transition': 'forwarding-transition-accept'}

    response = remote_request(predecessor.client_id,
                              '@@store_forwarding_in_yearfolder',
                              path=predecessor.physical_path,
                              data=request_data)

    if response.read().strip() != 'OK':
        raise Exception('Adding the response and changing the '
                        'workflow state on the predecessor forwarding '
                        'failed.')

    if dossier:
        # when a successor task exists, we close also the successor forwarding
        change_task_workflow_state(
            successor_forwarding,
            'forwarding-transition-accept',
            text=response_text,
            successor_oguid=successor_tc_task.get_oguid())

    # create the succssor relations
    successor_tc.set_predecessor(predecessor_oguid)
    if dossier:
        successor_tc_task.set_predecessor(successor_tc.get_oguid())
        return task
    return successor_forwarding
예제 #28
0
def accept_forwarding_with_successor(context,
                                     predecessor_oguid,
                                     response_text,
                                     dossier=None):

    # the predessecor (the forwarding on the remote client)
    predecessor = getUtility(ITaskQuery).get_task_by_oguid(predecessor_oguid)

    # get the inbox
    cat = getToolByName(context, 'portal_catalog')
    inboxes = cat(portal_type="opengever.inbox.inbox")

    if len(inboxes) == 0:
        raise Unauthorized()
    else:
        inbox = inboxes[0].getObject()

    # transport the remote forwarding to the inbox or actual yearfolder
    transporter = getUtility(ITransporter)
    if dossier:
        yearfolder = _get_yearfolder(inbox, )
        successor_forwarding = transporter.transport_from(
            yearfolder, predecessor.client_id, predecessor.physical_path)
    else:
        successor_forwarding = transporter.transport_from(
            inbox, predecessor.client_id, predecessor.physical_path)

    # Replace the issuer with the current inbox
    successor_forwarding.issuer = u'inbox:%s' % get_client_id()

    # Set the "X-CREATING-SUCCESSOR" flag for preventing the event handler
    # from creating additional responses per added document.
    successor_forwarding.REQUEST.set('X-CREATING-SUCCESSOR', True)

    successor_tc = ISuccessorTaskController(successor_forwarding)

    # copy documents and map the intids
    doc_transporter = getUtility(ITaskDocumentsTransporter)
    with CustomInitialVersionMessage(
            _(u'version_message_accept_forwarding',
              default=u'Document copied from forwarding (forwarding accepted)'
              ), context.REQUEST):
        intids_mapping = doc_transporter.copy_documents_from_remote_task(
            predecessor, successor_forwarding)

    # copy the responses
    response_transporter = IResponseTransporter(successor_forwarding)
    response_transporter.get_responses(predecessor.client_id,
                                       predecessor.physical_path,
                                       intids_mapping=intids_mapping)

    # if a dossier is given means that a successor task must
    # be created in a new or a existing dossier
    if dossier:
        # we need all task field values from the forwarding
        fielddata = {}
        for fieldname in ITask.names():
            value = ITask.get(fieldname).get(successor_forwarding)
            fielddata[fieldname] = value

        # lets create a new task - the successor task
        task = createContentInContainer(dossier, 'opengever.task.task',
                                        **fielddata)

        # copy documents and map the intids

        intids_mapping = _copy_documents_from_forwarding(
            successor_forwarding, task)

        # copy the responses
        response_transporter = IResponseTransporter(task)
        response_transporter.get_responses(
            get_client_id(),
            '/'.join(successor_forwarding.getPhysicalPath()),
            intids_mapping=intids_mapping)

        # successor
        successor_tc_task = ISuccessorTaskController(task)

    transaction.savepoint()

    # Close the predessecor forwarding
    response_text = response_text or ''
    request_data = {
        'response_text': response_text.encode('utf-8'),
        'successor_oguid': successor_tc.get_oguid(),
        'transition': 'forwarding-transition-accept'
    }

    response = remote_request(predecessor.client_id,
                              '@@store_forwarding_in_yearfolder',
                              path=predecessor.physical_path,
                              data=request_data)

    if response.read().strip() != 'OK':
        raise Exception('Adding the response and changing the '
                        'workflow state on the predecessor forwarding '
                        'failed.')

    if dossier:
        # when a successor task exists, we close also the successor forwarding
        change_task_workflow_state(
            successor_forwarding,
            'forwarding-transition-accept',
            text=response_text,
            successor_oguid=successor_tc_task.get_oguid())

    # create the succssor relations
    successor_tc.set_predecessor(predecessor_oguid)
    if dossier:
        successor_tc_task.set_predecessor(successor_tc.get_oguid())
        return task
    return successor_forwarding
예제 #29
0
    def test_encoding_decoding(self):
        task = self.providing_stub([ITask])
        # rel_value = self.mocker.replace(RelationValue)
        # rel_value = self.expect(rel_value('hans')).result('RELATION VALUE')

        # relation = self.stub()
        # self.expect(relation.to_id).result('123')
        self.replay()

        trans = IResponseTransporter(task)

        self.assertEquals(trans._decode('hans'), 'hans')
        self.assertEquals(trans._decode(None), None)
        self.assertEquals(trans._decode([111, 'hans']), [111, 'hans'])

        #string
        self.assertEquals('hans', trans._decode(trans._encode('hans')))
        # unicode
        self.assertEquals(u'hans', trans._decode(trans._encode(u'hans')))
        self.assertEquals(u'h\xe4ns', trans._decode(trans._encode(u'h\xe4ns')))
        # datetime
        self.assertEquals(
            datetime(2012, 1, 1, 2, 2),
            trans._decode(trans._encode(datetime(2012, 1, 1, 2, 2))))
        # DateTime
        self.assertEquals(
            DateTime(2012, 1, 1, 2, 2),
            trans._decode(trans._encode(DateTime(2012, 1, 1, 2, 2))))
        # RelationValue
        trans.intids_mapping = {'123': '321'}
        value = RelationValue('123')
        self.assertEquals(trans._decode(trans._encode(value)).to_id, '321')
        #special type
        self.assertEquals(['special_type', 'special value'],
                          trans._decode(['special_type', 'special value']))
    def test_encoding_decoding(self):
        task = self.providing_stub([ITask])
        # rel_value = self.mocker.replace(RelationValue)
        # rel_value = self.expect(rel_value('hans')).result('RELATION VALUE')

        # relation = self.stub()
        # self.expect(relation.to_id).result('123')
        self.replay()

        trans = IResponseTransporter(task)

        self.assertEquals(trans._decode('hans'), 'hans')
        self.assertEquals(trans._decode(None), None)
        self.assertEquals(trans._decode([111, 'hans']), [111, 'hans'])

        #string
        self.assertEquals('hans', trans._decode(trans._encode('hans')))
        # unicode
        self.assertEquals(u'hans', trans._decode(trans._encode(u'hans')))
        self.assertEquals(u'h\xe4ns', trans._decode(trans._encode(u'h\xe4ns')))
        # datetime
        self.assertEquals(
            datetime(2012, 1, 1, 2, 2),
            trans._decode(trans._encode(datetime(2012, 1, 1, 2, 2))))
        # DateTime
        self.assertEquals(
            DateTime(2012, 1, 1, 2, 2),
            trans._decode(trans._encode(DateTime(2012, 1, 1, 2, 2))))
        # RelationValue
        trans.intids_mapping = {'123': '321'}
        value = RelationValue('123')
        self.assertEquals(trans._decode(trans._encode(value)).to_id, '321')
        #special type
        self.assertEquals(['special_type', 'special value'],
            trans._decode(['special_type', 'special value']))
    def test_handles_non_ascii_strings(self):
        with self.login(self.regular_user):
            transporter = IResponseTransporter(self.task)

        self.assert_serialization('hell\xc3\xb6', transporter)
    def test_DateTime_encoding_decoding(self):
        with self.login(self.regular_user):
            transporter = IResponseTransporter(self.task)

        self.assert_serialization(DateTime(2015, 11, 6, 13, 30), transporter)
예제 #33
0
def accept_forwarding_with_successor(context,
                                     predecessor_oguid,
                                     response_text,
                                     dossier=None):

    # the predessecor (the forwarding on the remote client)
    predecessor = Task.query.by_oguid(predecessor_oguid)

    # transport the remote forwarding to the inbox or actual yearfolder
    transporter = Transporter()
    inbox = get_current_inbox(context)
    if dossier:
        yearfolder = get_current_yearfolder(inbox=inbox)
        successor_forwarding = transporter.transport_from(
            yearfolder, predecessor.admin_unit_id, predecessor.physical_path)
    else:
        successor_forwarding = transporter.transport_from(
            inbox, predecessor.admin_unit_id, predecessor.physical_path)

    # Replace the issuer with the current inbox
    successor_forwarding.issuer = get_current_org_unit().inbox().id()

    # Set the "X-CREATING-SUCCESSOR" flag for preventing the event handler
    # from creating additional responses per added document.
    successor_forwarding.REQUEST.set('X-CREATING-SUCCESSOR', True)

    successor_tc = ISuccessorTaskController(successor_forwarding)

    # copy documents and map the intids
    doc_transporter = getUtility(ITaskDocumentsTransporter)

    comment = _(
        u'version_message_accept_forwarding',
        default=u'Document copied from forwarding (forwarding accepted)')
    intids_mapping = doc_transporter.copy_documents_from_remote_task(
        predecessor, successor_forwarding, comment=comment)

    # copy the responses
    response_transporter = IResponseTransporter(successor_forwarding)
    response_transporter.get_responses(predecessor.admin_unit_id,
                                       predecessor.physical_path,
                                       intids_mapping=intids_mapping)

    # Remove current responsible from predecessor and add issuer
    # and responsible to successor's watcher.
    center = notification_center()
    center.remove_task_responsible(Oguid.parse(predecessor_oguid),
                                   successor_forwarding.responsible)
    center.add_task_responsible(successor_forwarding,
                                successor_forwarding.responsible)
    center.add_task_issuer(successor_forwarding, successor_forwarding.issuer)

    # if a dossier is given means that a successor task must
    # be created in a new or a existing dossier
    if dossier:
        # we need all task field values from the forwarding
        fielddata = {}
        for fieldname in ITask.names():
            value = ITask.get(fieldname).get(successor_forwarding)
            fielddata[fieldname] = value

        # Predefine the task_type to avoid tasks with an invalid task_type
        fielddata['task_type'] = FORWARDING_SUCCESSOR_TYPE

        # lets create a new task - the successor task
        task = createContentInContainer(dossier, 'opengever.task.task',
                                        **fielddata)

        # copy documents and map the intids
        intids_mapping = _copy_documents_from_forwarding(
            successor_forwarding, task)

        # copy the responses
        response_transporter = IResponseTransporter(task)
        response_transporter.get_responses(
            get_current_admin_unit().id(),
            '/'.join(successor_forwarding.getPhysicalPath()),
            intids_mapping=intids_mapping)

        # successor
        successor_tc_task = ISuccessorTaskController(task)

    transaction.savepoint()

    # Close the predessecor forwarding
    response_text = response_text or ''
    request_data = {
        'response_text': response_text.encode('utf-8'),
        'successor_oguid': successor_tc.get_oguid(),
        'transition': 'forwarding-transition-accept'
    }

    response = dispatch_request(predecessor.admin_unit_id,
                                '@@store_forwarding_in_yearfolder',
                                path=predecessor.physical_path,
                                data=request_data)

    response_body = response.read()
    if response_body.strip() != 'OK':
        raise TaskRemoteRequestError(
            'Adding the response and changing the workflow state on the '
            'predecessor forwarding failed.')

    if dossier:
        # Update watchers for created successor forwarding and task
        center = notification_center()
        center.remove_task_responsible(successor_forwarding, task.responsible)
        center.add_task_responsible(task, task.responsible)

        # When a successor task exists, we close also the successor forwarding
        change_task_workflow_state(
            successor_forwarding,
            'forwarding-transition-accept',
            text=response_text,
            successor_oguid=successor_tc_task.get_oguid())

    # create the succssor relations
    successor_tc.set_predecessor(predecessor_oguid)
    if dossier:
        successor_tc_task.set_predecessor(successor_tc.get_oguid())
        return task
    return successor_forwarding
예제 #34
0
def accept_forwarding_with_successor(
    context, predecessor_oguid, response_text, dossier=None):

    # the predessecor (the forwarding on the remote client)
    predecessor = Task.query.by_oguid(predecessor_oguid)

    # Set the "X-CREATING-SUCCESSOR" flag for preventing the event handler
    # from creating additional responses per added document.
    context.REQUEST.set('X-CREATING-SUCCESSOR', True)

    # transport the remote forwarding to the inbox or actual yearfolder
    transporter = Transporter()
    inbox = get_current_inbox(context)
    if dossier:
        yearfolder = get_current_yearfolder(inbox=inbox)
        successor_forwarding = transporter.transport_from(
            yearfolder, predecessor.admin_unit_id, predecessor.physical_path)
    else:
        successor_forwarding = transporter.transport_from(
            inbox, predecessor.admin_unit_id, predecessor.physical_path)

    # Replace the issuer with the current inbox
    successor_forwarding.issuer = get_current_org_unit().inbox().id()

    successor_tc = ISuccessorTaskController(successor_forwarding)

    # copy documents and map the intids
    doc_transporter = getUtility(ITaskDocumentsTransporter)

    comment = _(
        u'version_message_accept_forwarding',
        default=u'Document copied from forwarding (forwarding accepted)')
    intids_mapping = doc_transporter.copy_documents_from_remote_task(
        predecessor, successor_forwarding, comment=comment)

    # copy the responses
    response_transporter = IResponseTransporter(successor_forwarding)
    response_transporter.get_responses(predecessor.admin_unit_id,
                                       predecessor.physical_path,
                                       intids_mapping=intids_mapping)

    # Remove current responsible from predecessor and add issuer
    # and responsible to successor's watcher.
    center = notification_center()
    center.remove_task_responsible(Oguid.parse(predecessor_oguid),
                                   successor_forwarding.responsible)
    center.add_task_responsible(successor_forwarding,
                                successor_forwarding.responsible)
    center.add_task_issuer(successor_forwarding, successor_forwarding.issuer)

    # if a dossier is given means that a successor task must
    # be created in a new or a existing dossier
    if dossier:
        # we need all task field values from the forwarding
        fielddata = {}
        for fieldname in ITask.names():
            value = ITask.get(fieldname).get(successor_forwarding)
            fielddata[fieldname] = value

        # Predefine the task_type to avoid tasks with an invalid task_type
        fielddata['task_type'] = FORWARDING_SUCCESSOR_TYPE

        # lets create a new task - the successor task
        task = createContentInContainer(
            dossier, 'opengever.task.task', **fielddata)

        # copy documents and map the intids
        intids_mapping = _copy_documents_from_forwarding(
            successor_forwarding, task)

        # copy the responses
        response_transporter = IResponseTransporter(task)
        response_transporter.get_responses(
            get_current_admin_unit().id(),
            '/'.join(successor_forwarding.getPhysicalPath()),
            intids_mapping=intids_mapping)

        # successor
        successor_tc_task = ISuccessorTaskController(task)

    transaction.savepoint()

    # Close the predessecor forwarding
    response_text = response_text or ''
    request_data = {'response_text': response_text.encode('utf-8'),
                    'successor_oguid': successor_tc.get_oguid(),
                    'transition': 'forwarding-transition-accept'}

    response = dispatch_request(predecessor.admin_unit_id,
                                '@@store_forwarding_in_yearfolder',
                                path=predecessor.physical_path,
                                data=request_data)

    response_body = response.read()
    if response_body.strip() != 'OK':
        raise TaskRemoteRequestError(
            'Adding the response and changing the workflow state on the '
            'predecessor forwarding failed.')

    if dossier:
        # Update watchers for created successor forwarding and task
        center = notification_center()
        center.remove_task_responsible(successor_forwarding, task.responsible)
        center.add_task_responsible(task, task.responsible)

        # When a successor task exists, we close also the successor forwarding
        change_task_workflow_state(
            successor_forwarding,
            'forwarding-transition-accept',
            text=response_text,
            successor_oguid=successor_tc_task.get_oguid())

    # create the succssor relations
    successor_tc.set_predecessor(predecessor_oguid)
    if dossier:
        successor_tc_task.set_predecessor(successor_tc.get_oguid())
        return task
    return successor_forwarding