def view(collection_id, mapping_id): """Return the mapping with id `mapping_id`. --- get: summary: Fetch a mapping parameters: - description: The collection id. in: path name: collection_id required: true schema: minimum: 1 type: integer example: 2 - description: The mapping id. in: path name: mapping_id required: true schema: minimum: 1 type: integer example: 2 responses: '200': content: application/json: schema: $ref: '#/components/schemas/Mapping' description: OK tags: - Collection """ get_db_collection(collection_id, request.authz.WRITE) mapping = obj_or_404(Mapping.by_id(mapping_id)) return MappingSerializer.jsonify(mapping)
def update(collection_id, mapping_id): """Update the mapping with id `mapping_id`. --- post: summary: Update a mapping parameters: - description: The collection id. in: path name: collection_id required: true schema: minimum: 1 type: integer example: 2 - description: The mapping id. in: path name: mapping_id required: true schema: minimum: 1 type: integer example: 2 requestBody: content: application/json: schema: $ref: '#/components/schemas/MappingCreate' responses: '200': content: application/json: schema: $ref: '#/components/schemas/Mapping' description: OK tags: - Collection - Mapping """ get_db_collection(collection_id, request.authz.WRITE) mapping = obj_or_404(Mapping.by_id(mapping_id)) data = parse_request("MappingCreate") mapping.update( query=load_query(), table_id=get_table_id(data), entityset_id=get_entityset_id(data), ) db.session.commit() return MappingSerializer.jsonify(mapping)
def update(collection_id, mapping_id): """Update the mapping with id `mapping_id`. --- post: summary: Update a mapping parameters: - description: The collection id. in: path name: collection_id required: true schema: minimum: 1 type: integer example: 2 - description: The mapping id. in: path name: mapping_id required: true schema: minimum: 1 type: integer example: 2 requestBody: content: application/json: schema: $ref: '#/components/schemas/MappingCreate' responses: '200': content: application/json: schema: $ref: '#/components/schemas/Mapping' description: OK tags: - Collection """ get_db_collection(collection_id, request.authz.WRITE) mapping = obj_or_404(Mapping.by_id(mapping_id)) data = parse_request('MappingCreate') entity_id = data.get('table_id') query = load_query() entity = get_index_entity(entity_id, request.authz.READ) mapping.update(query=query, table_id=entity.get('id')) return MappingSerializer.jsonify(mapping)
def trigger(collection_id, mapping_id): """Load entities by running the mapping with id `mapping_id`. Flushes previously loaded entities before loading new entities. --- post: summary: Load entities from a mapping parameters: - description: The collection id. in: path name: collection_id required: true schema: minimum: 1 type: integer example: 2 - description: The mapping id. in: path name: mapping_id required: true schema: minimum: 1 type: integer example: 2 responses: '202': description: No Content tags: - Collection - Mapping """ collection = get_db_collection(collection_id, request.authz.WRITE) mapping = obj_or_404(Mapping.by_id(mapping_id)) mapping.disabled = False mapping.set_status(Status.PENDING) db.session.commit() job_id = get_session_id() queue_task(collection, OP_LOAD_MAPPING, job_id=job_id, mapping_id=mapping.id) mapping = obj_or_404(Mapping.by_id(mapping_id)) return MappingSerializer.jsonify(mapping, status=202)
def create(collection_id): """Create a mapping. --- post: summary: Create a mapping parameters: - description: The collection id. in: path name: collection_id required: true schema: minimum: 1 type: integer example: 2 requestBody: content: application/json: schema: $ref: '#/components/schemas/MappingCreate' responses: '200': content: application/json: schema: $ref: '#/components/schemas/Mapping' description: OK tags: - Collection - Mapping """ collection = get_db_collection(collection_id, request.authz.WRITE) data = parse_request("MappingCreate") mapping = Mapping.create( load_query(), get_table_id(data), collection, request.authz.id, entityset_id=get_entityset_id(data), ) db.session.commit() return MappingSerializer.jsonify(mapping)
def create(collection_id): """Create a mapping. --- post: summary: Create a mapping parameters: - description: The collection id. in: path name: collection_id required: true schema: minimum: 1 type: integer example: 2 requestBody: content: application/json: schema: $ref: '#/components/schemas/MappingCreate' responses: '200': content: application/json: schema: $ref: '#/components/schemas/Mapping' description: OK tags: - Collection - Mapping """ collection = get_db_collection(collection_id, request.authz.WRITE) data = parse_request('MappingCreate') entity_id = data.get('table_id') query = load_query() entity = get_index_entity(entity_id, request.authz.READ) mapping = Mapping.create(query, entity.get('id'), collection, request.authz.id) # noqa return MappingSerializer.jsonify(mapping)