Ejemplo n.º 1
0
def test_create_nro_transaction_with_type(app):
    con = nro.connection
    cursor = con.cursor()

    eid = _get_event_id(cursor)

    fake_request = FakeRequest()
    fake_request.requestId = 884047

    _create_nro_transaction(cursor, fake_request, eid, 'CORRT')

    cursor.execute("select event_id, transaction_type_cd from transaction where request_id = {} order by event_id desc".format(fake_request.requestId))
    (value, transaction_type_cd) = cursor.fetchone()

    assert eid == value
    assert transaction_type_cd == 'CORRT'
Ejemplo n.º 2
0
    def cancel_nr(self, nr, examiner_username):
        """Sets the status of the Request in NRO to "C" (Cancelled)

        :param nr: (obj) NR Object
        :param examiner_username: (str) any valid string will work, but it should be the username from Keycloak
        :return: naked
        :raise: (NROServicesError) with the error information set
        """

        try:
            con = self.connection
            con.begin(
            )  # explicit transaction in case we need to do other things than just call the stored proc
            try:
                cursor = con.cursor()

                event_id = _get_event_id(cursor)
                current_app.logger.debug('got to cancel_nr() for NR:{}'.format(
                    nr.nrNum))
                current_app.logger.debug('event ID for NR:{}'.format(event_id))
                _create_nro_transaction(cursor, nr, event_id, 'CANCL')

                # get request_state record, with all fields
                cursor.execute("""
                SELECT *
                FROM request_state
                WHERE request_id = :request_id
                AND end_event_id IS NULL
                FOR UPDATE
                """,
                               request_id=nr.requestId)
                row = cursor.fetchone()
                req_state_id = int(row[0])

                # set the end event for the existing record
                cursor.execute("""
                UPDATE request_state
                SET end_event_id = :event_id
                WHERE request_state_id = :req_state_id
                """,
                               event_id=event_id,
                               req_state_id=req_state_id)

                # create new request_state record
                cursor.execute(
                    """
                INSERT INTO request_state (request_state_id, request_id, state_type_cd, 
                    start_event_id, end_event_id, examiner_idir, examiner_comment, state_comment, 
                    batch_id)
                VALUES (request_state_seq.nextval, :request_id, :state, :event_id, NULL, 
                          :examiner_id, NULL, NULL, NULL)
                """,
                    request_id=nr.requestId,
                    state='C',
                    event_id=event_id,
                    examiner_id=nro_examiner_name(examiner_username))

                con.commit()

            except cx_Oracle.DatabaseError as exc:
                err, = exc.args
                current_app.logger.error(err)
                if con:
                    con.rollback()
                raise NROServicesError(
                    {
                        "code": "unable_to_set_state",
                        "description":
                        "Unable to set the state of the NR in NRO"
                    }, 500)
            except Exception as err:
                current_app.logger.error(err.with_traceback(None))
                if con:
                    con.rollback()
                raise NROServicesError(
                    {
                        "code": "unable_to_set_state",
                        "description":
                        "Unable to set the state of the NR in NRO"
                    }, 500)

        except Exception as err:
            # something went wrong, roll it all back
            current_app.logger.error(err.with_traceback(None))
            if con:
                con.rollback()
            raise NROServicesError(
                {
                    "code": "unable_to_set_state",
                    "description": "Unable to set the state of the NR in NRO"
                }, 500)

        return None
Ejemplo n.º 3
0
def new_nr(nr, ora_cursor, con):
    """Add the Name Request in NRO
    :raises Exception: what ever error we get, let our caller handle, this is here in case we want to wrap it - future
    """

    nr_num_list = _generate_nr_num(ora_cursor)
    nr_num = nr_num_list.values[0]
    # Set postgres to real NR #
    nr.nrNum = nr_num

    #set the oracle version of the priority code
    priority = None
    if nr.priorityCd == 'Y':
        priority = 'PQ'
    else:
        priority = 'RQ'

    request_id = _create_request(ora_cursor, nr_num)
    nr.requestId = request_id
    current_app.logger.debug('got to new_nr() for NR:{}'.format(nr_num))

    eid = _get_event_id(ora_cursor)
    current_app.logger.debug('event ID for NR:{1}. event id:{0}'.format(
        eid, nr_num))

    nr.requestId = request_id
    _create_nro_transaction(ora_cursor, nr, eid, transaction_type='NRREQ')
    con.commit()
    current_app.logger.debug(
        'Created the transaction for new_nr() for NR:{}'.format(nr_num))

    _create_request_instance(ora_cursor, nr, eid, priority)
    con.commit()
    applicantInfo = nr.applicants.one_or_none()
    if not applicantInfo:
        current_app.logger.error("Error on getting applicant info.")
        return jsonify({"Message": "No applicant info"}), 404

    _create_request_party(ora_cursor, applicantInfo, eid,
                          request_id)  #includes address
    con.commit()
    current_app.logger.debug(
        'Created Request Party and Address in new_nr() for NR:{}'.format(
            nr_num))

    _create_request_state(ora_cursor, 'D', eid, request_id)
    con.commit()

    _create_names(ora_cursor, nr, eid)  #name, name_instace and name state
    con.commit()
    current_app.logger.debug(
        'Created Names in new_nr() for NR:{}'.format(nr_num))

    # for completed NRs waiting for the updater set the state to H so no one can change it in NRO
    # for Name request Rserved and conditionally Reersved NRs.
    if nr.stateCd in [State.RESERVED, State.COND_RESERVE]:
        eid = _get_event_id(ora_cursor)
        set_request_on_hold(ora_cursor, request_id, eid)
        con.commit()
        current_app.logger.debug(
            'Set State to ONHOLD for Updater to Run in new_nr() for NR:{}'.
            format(nr_num))

    current_app.logger.debug(
        'got to the end of new_nr() for NR:{}'.format(nr_num))