Exemple #1
0
    async def _send_and_wait_for_commit(self, batch):
        print('=== send and wate for commit a batch ===')
        # Send transaction to validator
        submit_request = client_batch_submit_pb2.ClientBatchSubmitRequest(
            batches=[batch])
        await self._connection.send(
            validator_pb2.Message.CLIENT_BATCH_SUBMIT_REQUEST,
            submit_request.SerializeToString())

        # Send status request to validator
        batch_id = batch.header_signature
        status_request = client_batch_submit_pb2.ClientBatchStatusRequest(
            batch_ids=[batch_id], wait=True)
        validator_response = await self._connection.send(
            validator_pb2.Message.CLIENT_BATCH_STATUS_REQUEST,
            status_request.SerializeToString())

        # Parse response
        status_response = client_batch_submit_pb2.ClientBatchStatusResponse()
        status_response.ParseFromString(validator_response.content)
        status = status_response.batch_statuses[0].status
        if status == client_batch_submit_pb2.ClientBatchStatus.INVALID:
            error = status_response.batch_statuses[0].invalid_transactions[0]
            raise ApiBadRequest(error.message)
        elif status == client_batch_submit_pb2.ClientBatchStatus.PENDING:
            raise ApiInternalError('Transaction submitted but timed out')
        elif status == client_batch_submit_pb2.ClientBatchStatus.UNKNOWN:
            raise ApiInternalError('Something went wrong. Try again later')
 async def wrapper(*args, **kwargs):
     try:
         request_json = await args[1].json()
         args = (args[0], args[1], request_json)
         return await f(*args, **kwargs)
     except JSONDecodeError:
         raise ApiBadRequest('JSON is required!!!')
Exemple #3
0
def validate_fields(required_fields, body):
    for field in required_fields:
        if body.get(field) is None:
            raise ApiBadRequest("'{}' parameter is required".format(field))
Exemple #4
0
async def decode_request(request):
    try:
        return await request.json()
    except JSONDecodeError:
        raise ApiBadRequest('Improper JSON format')
Exemple #5
0
    async def fetch_fields(self, request):
        private_key = await self._authorize(request)

        fields = ['description', 'quantity', 'parent_id']

        role = request.match_info.get('role', '')
        if role == 'tool':
            add_fields = [
                'type', 'Haematite level', 'Ore qualifications',
                'Certifying authority', 'Key results'
            ]

        elif role == 'raw_material':
            add_fields = [
                'type', 'Haematite level', 'Ore qualifications',
                'Certifying authority', 'Key results'
            ]

        elif role == 'liquids':
            add_fields = [
                'type', 'Alloy Composition', 'Tests employed',
                'Key Test Results', 'Test conducted by'
            ]

        elif role == 'safety':
            add_fields = [
                'type', 'Process plan steps', 'Finishing', 'Dimension #1',
                'Tolerance #1', 'Dimension #2', 'Tolerance #2', 'Dimension #3',
                'Tolerance #3', 'Dimension #4', 'Tolerance #4',
                'qualification tests', 'Standard used', 'Agency',
                'Key Results', 'NDE tests employed'
            ]

        elif role == 'measurement':
            add_fields = [
                'type', 'Feature #1', 'Count #1', 'Standard #1', 'Result #1',
                'Feature #2', 'Count #2', 'Standard used #2', 'Result #2',
                'Feature #3', 'Count #3', 'Standard used #3', 'Result #3',
                'Feature #4', 'Count #4', 'Standard used #4', 'Result #4',
                'Agency'
            ]

        elif role == 'cleaning':
            add_fields = [
                'type', 'Feature #1', 'Count #1', 'Standard #1', 'Result #1',
                'Feature #2', 'Count #2', 'Standard used #2', 'Result #2',
                'Feature #3', 'Count #3', 'Standard used #3', 'Result #3',
                'Feature #4', 'Count #4', 'Standard used #4', 'Result #4',
                'Agency'
            ]

        elif role == 'infrastructure':
            add_fields = [
                'type', 'Feature #1', 'Count #1', 'Standard #1', 'Result #1',
                'Feature #2', 'Count #2', 'Standard used #2', 'Result #2',
                'Feature #3', 'Count #3', 'Standard used #3', 'Result #3',
                'Feature #4', 'Count #4', 'Standard used #4', 'Result #4',
                'Agency'
            ]

        elif role == 'wastage':
            add_fields = [
                'type', 'Feature #1', 'Count #1', 'Standard #1', 'Result #1',
                'Feature #2', 'Count #2', 'Standard used #2', 'Result #2',
                'Feature #3', 'Count #3', 'Standard used #3', 'Result #3',
                'Feature #4', 'Count #4', 'Standard used #4', 'Result #4',
                'Agency'
            ]

        elif role == 'toolstaff':
            add_fields = [
                'Name', 'Date of return committed', 'Shop', 'Details'
            ]

        elif role == 'toolstudents':
            add_fields = [
                'Name', 'Roll No.', 'Date of return committed', 'Department',
                'Phone', 'Details', 'Guide-HOD approval'
            ]

        elif role == 'toolbreakage':
            add_fields = [
                'Work order No.', 'Location', 'Reason', 'Details',
                'Guide-HOD approval'
            ]

        elif role == 'materialreq':
            add_fields = ['Purpose', 'Shop', 'Year', 'Semester', 'Details']

        elif role == 'inspection':
            add_fields = [
                'Purchase order No.', 'Supplier', 'Details', 'Certifications',
                'Key results'
            ]

        elif role == 'project':
            add_fields = ['Student', 'Supervisor', 'Details']

        else:
            raise ApiBadRequest('Invalid role specified')

        fields.extend(add_fields)

        #await self._database.edit_fields_entry(role, add_fields=add_fields)

        return json_response({'other_fields': fields})