コード例 #1
0
ファイル: party_resource.py プロジェクト: parc-jason/mds
    def put(self, party_guid):
        data = PartyResource.parser.parse_args()
        existing_party = Party.find_by_party_guid(party_guid)
        if not existing_party:
            raise NotFound('Party not found.')

        current_app.logger.info(f'Updating {existing_party} with {data}')
        for key, value in data.items():
            if key in ['party_type_code']:
                continue     # non-editable fields from put
            setattr(existing_party, key, value)

        # We are now allowing parties to be created without an address
        if (data.get('suite_no') or data.get('address_line_1') or data.get('address_line_2')
                or data.get('city') or data.get('sub_division_code')
                or data.get('post_code')):                                                   # and check that we are changing the address
            if len(existing_party.address) == 0:
                address = Address.create()
                existing_party.address.append(address)

            for key, value in data.items():
                setattr(existing_party.address[0], key, value)

        existing_party.save()

        return existing_party
コード例 #2
0
ファイル: variance.py プロジェクト: popkinj/mds
    def put(self, mine_guid, variance_guid):
        variance = Variance.find_by_mine_guid_and_variance_guid(
            mine_guid, variance_guid)
        if variance is None:
            raise NotFound('Unable to fetch variance')

        data = self.parser.parse_args()

        inspector_party_guid = data.get('inspector_party_guid')
        if inspector_party_guid:
            inspector = Party.find_by_party_guid(inspector_party_guid)
            if not inspector:
                raise BadRequest('Unable to find new inspector.')
            if not 'INS' in inspector.business_roles_codes:
                raise BadRequest('Party is not an inspector.')

            variance.inspector_party_guid = inspector_party_guid

        for key, value in data.items():
            if key in ['inspector_party_guid']:
                continue
            setattr(variance, key, value)

        # A manual check to prevent a stack trace dump on a foreign key /
        # constraint error because global error handling doesn't currently work
        # with these errors
        Variance.validate_status_with_other_values(
            status=variance.variance_application_status_code,
            issue=variance.issue_date,
            expiry=variance.expiry_date,
            inspector=variance.inspector_party_guid)

        variance.save()
        return variance
コード例 #3
0
    def post(self, mine_guid, permit_guid, permit_amendment_guid=None):
        if permit_amendment_guid:
            raise BadRequest('Unexpected permit_amendement_guid.')

        permit = Permit.find_by_permit_guid(permit_guid)
        if not permit:
            raise NotFound('Permit does not exist.')

        if not str(permit.mine_guid) == mine_guid:
            raise BadRequest(
                'Permits mine_guid and provided mine_guid mismatch.')

        data = self.parser.parse_args()
        current_app.logger.info(f'creating permit_amendment with >> {data}')

        party = Party.find_by_party_guid(data.get('permittee_party_guid'))
        if not party:
            raise NotFound('Party not found')

        party_is_active_permittee = False

        permittees = MinePartyAppointment.find_by_permit_guid(permit_guid)

        for permittee in permittees:
            if permittee.end_date is None:
                if permittee.party_guid == party.party_guid:
                    party_is_active_permittee = True
                else:  # inactive old permittees
                    permittee.end_date = datetime.utcnow()
                    permittee.save()

        if not party_is_active_permittee:
            new_permittee = MinePartyAppointment.create(permit.mine_guid,
                                                        data.get(
                                                            'permittee_party_guid'), 'PMT',
                                                        datetime.utcnow(), None,
                                                        self.get_user_info(), permit_guid, True)
            new_permittee.save()

        new_pa = PermitAmendment.create(
            permit,
            data.get('received_date'),
            data.get('issue_date'),
            data.get('authorization_end_date'),
            data.get('permit_amendment_type_code', 'AMD'),
            description=data.get('description'))

        uploadedFiles = data.get('uploadedFiles', [])
        for newFile in uploadedFiles:
            new_pa_doc = PermitAmendmentDocument(
                document_name=newFile['fileName'],
                document_manager_guid=newFile['document_manager_guid'],
                mine_guid=permit.mine_guid,
            )
            new_pa.related_documents.append(new_pa_doc)
        new_pa.save()
        return new_pa
コード例 #4
0
ファイル: permit.py プロジェクト: parc-jason/mds
    def post(self, mine_guid):
        data = self.parser.parse_args()

        mine = Mine.find_by_mine_guid(mine_guid)
        if not mine:
            raise NotFound(
                'There was no mine found with the provided mine_guid.')

        party = Party.find_by_party_guid(data.get('permittee_party_guid'))
        if not party:
            raise NotFound('Party not found')

        permit = Permit.find_by_permit_no(data.get('permit_no'))
        if permit:
            raise BadRequest("That permit number is already in use.")

        uploadedFiles = data.get('uploadedFiles', [])

        permit = Permit.create(mine.mine_guid, data.get('permit_no'),
                               data.get('permit_status_code'))

        amendment = PermitAmendment.create(
            permit,
            data.get('received_date'),
            data.get('issue_date'),
            data.get('authorization_end_date'),
            'OGP',
            description='Initial permit issued.')

        db.session.add(permit)
        db.session.add(amendment)

        for newFile in uploadedFiles:
            new_pa_doc = PermitAmendmentDocument(
                document_name=newFile['fileName'],
                document_manager_guid=newFile['document_manager_guid'],
                mine_guid=permit.mine_guid,
            )
            amendment.related_documents.append(new_pa_doc)
        db.session.commit()

        permittee_start_date = data.get('issue_date'),
        permittee = MinePartyAppointment.create(
            mine.mine_guid,
            data.get('permittee_party_guid'),
            'PMT',
            start_date=permittee_start_date,
            processed_by=self.get_user_info(),
            permit_guid=permit.permit_guid)
        db.session.add(permittee)
        db.session.commit()

        return permit
コード例 #5
0
ファイル: party_resource.py プロジェクト: parc-jason/mds
    def delete(self, party_guid):
        party = Party.find_by_party_guid(party_guid)
        if not party:
            raise NotFound(f'Party guid with "{party_guid}" not found.')

        mine_party_appts = MinePartyAppointment.find_by_party_guid(party_guid)
        for mine_party_appt in mine_party_appts:
            mine_party_appt.deleted_ind = True
            mine_party_appt.save()

        party.deleted_ind = True
        party.save()
        return ('', 204)
コード例 #6
0
    def post(self, party_guid):
        party = Party.find_by_party_guid(party_guid)
        if party is None:
            raise NotFound('Party not found.')

        if PartyOrgBookEntity.find_by_party_guid(party_guid) is not None:
            raise BadRequest(
                'This party is already associated with an OrgBook entity.')

        data = PartyOrgBookEntityListResource.parser.parse_args()
        credential_id = data.get('credential_id')

        if PartyOrgBookEntity.find_by_credential_id(credential_id) is not None:
            raise BadRequest(
                'An OrgBook entity with the provided credential ID already exists.'
            )

        resp = OrgBookService.get_credential(credential_id)
        if resp.status_code != requests.codes.ok:
            raise BadGateway(
                f'OrgBook API responded with {resp.status_code}: {resp.reason}'
            )

        try:
            credential = json.loads(resp.text)
            registration_id = credential['topic']['source_id']
            registration_status = not (credential['inactive'])
            registration_date = credential['effective_date']
            name_id = credential['names'][0]['id']
            name_text = credential['names'][0]['text']
        except:
            raise BadGateway('OrgBook API responded with unexpected data.')

        party_orgbook_entity = PartyOrgBookEntity.create(
            registration_id, registration_status, registration_date, name_id,
            name_text, credential_id, party_guid)
        if not party_orgbook_entity:
            raise InternalServerError(
                'Failed to create the Party OrgBook Entity.')

        party_orgbook_entity.save()

        party.party_name = name_text
        party.save()

        return party_orgbook_entity, 201
コード例 #7
0
ファイル: party_resource.py プロジェクト: parc-jason/mds
    def get(self, party_guid):
        party = Party.find_by_party_guid(party_guid)
        if not party:
            raise NotFound('Party not found')

        return party
コード例 #8
0
ファイル: test_party_model.py プロジェクト: jeznorth/mds
def test_party_model_find_by_person_guid(test_client, auth_headers):
    party = Party.find_by_party_guid(TEST_PARTY_PER_GUID_1)
    assert str(party.party_guid) == TEST_PARTY_PER_GUID_1
コード例 #9
0
    def post(self, permit_guid=None, permit_amendment_guid=None):
        if not permit_guid:
            return self.create_error_payload(
                400, 'Permit_guid must be provided'), 400
        if permit_amendment_guid:
            return self.create_error_payload(
                400, 'unexpected permit_amendement_id'), 400

        permit = Permit.find_by_permit_guid(permit_guid)
        if not permit:
            return self.create_error_payload(404, 'permit does not exist'), 404

        data = self.parser.parse_args()
        current_app.logger.info(f'creating permit_amendment with >> {data}')

        received_date = data.get('received_date')
        issue_date = data.get('issue_date')
        authorization_end_date = data.get('authorization_end_date')
        permit_amendment_type_code = data.get('permit_amendment_type_code',
                                              'AMD')
        description = data.get('description')
        uploadedFiles = data.get('uploadedFiles', [])

        party = Party.find_by_party_guid(data.get('permittee_party_guid'))
        if not party:
            raise NotFound('Party not found')

        party_is_active_permittee = False

        permittees = MinePartyAppointment.find_by_permit_guid(permit_guid)

        for permittee in permittees:
            if permittee.end_date is None:
                if permittee.party_guid == party.party_guid:
                    party_is_active_permittee = True
                else:  # inactive old permittees
                    permittee.end_date = datetime.utcnow()
                    permittee.save()

        if not party_is_active_permittee:
            new_permittee = MinePartyAppointment.create(
                permit.mine_guid, data.get('permittee_party_guid'), 'PMT',
                datetime.utcnow(), None, self.get_user_info(), permit_guid,
                True)
            new_permittee.save()

        try:
            new_pa = PermitAmendment.create(permit,
                                            received_date,
                                            issue_date,
                                            authorization_end_date,
                                            permit_amendment_type_code,
                                            description=description)

            for newFile in uploadedFiles:
                new_pa_doc = PermitAmendmentDocument(
                    document_name=newFile['fileName'],
                    document_manager_guid=newFile['document_manager_guid'],
                    mine_guid=permit.mine_guid,
                )
                new_pa.documents.append(new_pa_doc)
            new_pa.save()
        except Exception as e:
            return self.create_error_payload(500, 'Error: {}'.format(e)), 500
        return new_pa.json()
コード例 #10
0
ファイル: permit_amendment.py プロジェクト: alexjoybc/mds
    def post(self, mine_guid, permit_guid, permit_amendment_guid=None):
        if permit_amendment_guid:
            raise BadRequest('Unexpected permit_amendement_guid.')

        permit = Permit.find_by_permit_guid(permit_guid)
        if not permit:
            raise NotFound('Permit does not exist.')

        if not str(permit.mine_guid) == mine_guid:
            raise BadRequest('Permits mine_guid and provided mine_guid mismatch.')

        data = self.parser.parse_args()
        current_app.logger.info(f'creating permit_amendment with >> {data}')

        party = Party.find_by_party_guid(data.get('permittee_party_guid'))
        if not party:
            raise NotFound('Party not found')

        permittees = MinePartyAppointment.find_by_permit_guid(permit_guid)
        if not permittees:
            raise NotFound('Party appointments not found')

        permit_issue_datetime = data.get('issue_date')
        # convert permit_issue_date to a date object to compare with permittee start_date,
        #Both dates are stored in the DB as Dates, and are being converted to SQLAlchemy dateTimes in the modals, but for some reason being returned as Python Dates.
        permit_issue_date = datetime.date(permit_issue_datetime)
        is_historical_permit = False

        new_end_dates = MinePartyAppointment.find_appointment_end_dates(
            permit_guid, permit_issue_date)

        for permittee in permittees:
            # check if the new appointment is older than the current appointment, if so create a new permittee appointment
            if permittee.start_date > permit_issue_date:
                is_historical_permit = True
            else:
                # if the amendment is the newest, change the end dates of the other appointments
                position = new_end_dates.index(permittee.start_date)
                if new_end_dates.index(permittee.start_date) == 0:
                    permittee.save()
                else:
                    permittee.end_date = new_end_dates[position - 1]
                    permittee.save()

        permittee_start_date = permit_issue_date
        position = new_end_dates.index(permit_issue_date)
        permittee_end_date = new_end_dates[position - 1] if is_historical_permit else None

        # create a new appointment, so every amendment is associated with a permittee
        new_permittee = MinePartyAppointment.create(
            permit.mine_guid,
            data.get('permittee_party_guid'),
            'PMT',
            self.get_user_info(),
            start_date=permittee_start_date,
            end_date=permittee_end_date,
            permit_guid=permit_guid)

        new_permittee.save()
        new_pa = PermitAmendment.create(
            permit,
            data.get('received_date'),
            data.get('issue_date'),
            data.get('authorization_end_date'),
            data.get('permit_amendment_type_code', 'AMD'),
            description=data.get('description'))

        uploadedFiles = data.get('uploadedFiles', [])
        for newFile in uploadedFiles:
            new_pa_doc = PermitAmendmentDocument(
                document_name=newFile['fileName'],
                document_manager_guid=newFile['document_manager_guid'],
                mine_guid=permit.mine_guid,
            )
            new_pa.related_documents.append(new_pa_doc)

        new_pa.save()
        return new_pa
コード例 #11
0
def test_party_model_find_by_person_guid(db_session):
    party_guid = PartyFactory(person=True).party_guid

    party = Party.find_by_party_guid(str(party_guid))
    assert party.party_guid == party_guid