Commit 40b944b5 authored by Matija Obreza's avatar Matija Obreza

Code cleanup

parent ea700787
......@@ -142,13 +142,14 @@ paths:
'404':
description: Not Found
deprecated: false
'/api/v0/datasets/{name}/{startRow}':
get:
'/api/v0/datasets/{name}/get':
post:
tags:
- datasets
summary: Retrieve the list of accession observations in this table
description: Get accession observations
summary: Get accession observations from this dataset
operationId: getObservations
consumes:
- application/json
produces:
- '*/*'
parameters:
......@@ -158,18 +159,29 @@ paths:
required: true
type: string
format: uuid
- name: startRow
in: path
- name: skip
in: query
description: Index of the first row
required: true
type: integer
format: int64
- name: count
allowEmptyValue: false
- name: limit
in: query
description: Number of rows to return
required: false
type: integer
format: int64
format: int32
allowEmptyValue: false
- name: fields
in: query
description: Specify fields to return
required: false
type: array
items:
type: string
collectionFormat: multi
allowEmptyValue: false
responses:
'200':
description: OK
......@@ -177,6 +189,8 @@ paths:
type: array
items:
$ref: '#/definitions/AccessionObservations'
'201':
description: Created
'401':
description: Unauthorized
'403':
......@@ -356,7 +370,7 @@ paths:
required: true
type: integer
format: int64
- name: count
- name: limit
in: query
description: Number of rows to return
required: false
......@@ -371,7 +385,7 @@ paths:
items:
type: string
collectionFormat: multi
allowEmptyValue: true
allowEmptyValue: false
responses:
'200':
description: OK
......
......@@ -101,7 +101,7 @@ public class PreviewApi {
public List<?> getData(@ApiParam(value = "Your reference UUID", required = true) @PathVariable UUID uuid, // uuid
@ApiParam(value = "Sheet index", required = true) @PathVariable long sheet, // sheet index
@ApiParam(value = "Index of the first row", required = true) @PathVariable long startRow, // start row
@ApiParam(value = "Number of rows to return", required = false, format="int32", type="integer") @RequestParam(name = "count", required = false, defaultValue = "50") Optional<Integer> count, // max rows
@ApiParam(value = "Number of rows to return", required = false, format="int32", type="integer") @RequestParam(name = "limit", required = false, defaultValue = "50") Optional<Integer> limit, // max rows
@ApiParam(value = "Specify fields to return", required = false) @RequestParam(required=false) String[] fields // selected fields
) {
......@@ -109,7 +109,7 @@ public class PreviewApi {
if (preview == null) {
throw new NoSuchThingException("No preview for reference UUID=" + uuid);
}
return previewService.getData(uuid, sheet, startRow, count.orElse(50), fields);
return previewService.getData(uuid, sheet, startRow, limit.orElse(50), fields);
}
}
......@@ -45,29 +45,29 @@ public abstract class TablesApi<T extends Table> {
protected DatabaseService databaseService;
@PostMapping(path = "/create")
@ApiOperation(nickname="createTable", value = "Create a new table", notes = "")
@ApiOperation(nickname = "createTable", value = "Create a new table", notes = "")
public T create(@ApiParam(value = "Table definition", required = true) @RequestBody T table) {
LOG.debug("Creating new table!");
return databaseService.createTable(table);
}
@PostMapping(path = "/update")
@ApiOperation(nickname="updateTable", value = "Update table", notes = "")
@ApiOperation(nickname = "updateTable", value = "Update table", notes = "")
public T update(@ApiParam(value = "Table definition", required = true) @RequestBody T table) {
return databaseService.updateTable(table);
}
@PostMapping(path = "/drop")
@ApiOperation(nickname="dropTable", value = "Drop a table", notes = "")
@ApiOperation(nickname = "dropTable", value = "Drop a table", notes = "")
public T drop(@ApiParam(value = "Table data", required = true) @RequestBody T table) {
return databaseService.dropTable(table);
}
@GetMapping(path = "/{name}")
@ApiOperation(nickname="getTable", value = "Get the table information", notes = "Use the table name")
public Table get(@ApiParam(value = "Table key", required = true) @PathVariable(name="name") String tableKey) {
@ApiOperation(nickname = "getTable", value = "Get the table information", notes = "Use the table name")
public Table get(@ApiParam(value = "Table key", required = true) @PathVariable(name = "name") String tableKey) {
Table table = databaseService.getTable(tableKey);
if (table == null) {
throw new NoSuchThingException("No table for name=" + tableKey);
......@@ -75,23 +75,19 @@ public abstract class TablesApi<T extends Table> {
return table;
}
@GetMapping(path = { "/{name}/{startRow}" })
@ApiOperation(nickname="getData", value = "Get table data", notes = "")
public List<?> getData(@ApiParam(value = "Table name", required = true) @PathVariable(name="name") String tableKey, // tableKey
@ApiParam(value = "Index of the first row", required = true) @PathVariable long startRow, // start row
@ApiParam(value = "Number of rows to return", required = false) @RequestParam(name = "count", required = false, defaultValue = "50") Optional<Integer> count) {
@PostMapping(path = { "/{name}/get" })
@ApiOperation(nickname = "getData", value = "Get table data", notes = "")
public List<?> getData(@ApiParam(value = "Table name", required = true) @PathVariable(name = "name") String tableKey, // tableKey
@ApiParam(value = "Index of the first row", required = true) @RequestParam(name = "skip", required = true) long skip, // start row
@ApiParam(value = "Number of rows to return", required = false) @RequestParam(name = "limit", required = false, defaultValue = "50") Optional<Integer> limit, // limit
@ApiParam(value = "Specify fields to return", required = false) @RequestParam(required = false) String[] fields) {
Table table = databaseService.getTable(tableKey);
if (table == null) {
throw new NoSuchThingException("No table for name=" + tableKey);
}
List<?> data = databaseService.getData(table, startRow, count.orElse(50));
if (data == null || data.isEmpty()) {
throw new NoSuchThingException("No data in this table for startRow=" + startRow);
} else {
return data;
}
return databaseService.getData(table, skip, limit.orElse(50), fields);
}
}
......@@ -63,16 +63,6 @@ public class DatasetTableApi extends TablesApi<DatasetTable> {
return super.get(tableKey);
}
@Override
@ApiOperation(nickname = "getObservations", notes = "Get accession observations", value = "Retrieve the list of accession observations in this table")
@ApiResponses({ @ApiResponse(code = 200, message = "OK", response = AccessionObservations.class, responseContainer = "List") })
public List<?> getData(@ApiParam(value = "Table name", required = true, format = "uuid") @PathVariable(name = "name") String tableKey, // tableKey
@ApiParam(value = "Index of the first row", required = true) @PathVariable long startRow, // start row
@ApiParam(value = "Number of rows to return", required = false, type = "integer") @RequestParam(name = "count", required = false, defaultValue = "50") Optional<Integer> count) {
return super.getData(tableKey, startRow, count);
}
@PostMapping(path = { "{uuid}/add" })
@ApiOperation(nickname = "addObservations", notes = "Add accession observations", value = "Add observations, returns result of update")
@ApiResponses({ @ApiResponse(code = 200, message = "OK", response = AccessionObservations.class, responseContainer = "List") })
......@@ -89,4 +79,18 @@ public class DatasetTableApi extends TablesApi<DatasetTable> {
LOG.warn("Update result {}", updateResult);
return databaseService.getData(table, query);
}
@Override
@ApiOperation(nickname = "getObservations", value = "Get accession observations from this dataset")
@ApiResponses({ @ApiResponse(code = 200, message = "OK", response = AccessionObservations.class, responseContainer = "List") })
public List<?> getData(@ApiParam(value = "Table name", required = true, format="uuid") @PathVariable(name="name") String tableKey, // tableKey
@ApiParam(value = "Index of the first row", required = true) @RequestParam(name = "skip", required = true) long skip, // skip rows
@ApiParam(value = "Number of rows to return", required = false) @RequestParam(name = "limit", required = false) Optional<Integer> limit, // limit
@ApiParam(value = "Specify fields to return", required = false) @RequestParam(required = false) String[] fields // selected fields
) {
Table table = get(tableKey);
return databaseService.getData(table, skip, limit.orElse(50), fields);
}
}
......@@ -44,7 +44,7 @@ public interface DatabaseService {
ListIndexesIterable<?> listIndices(String tableName);
<T extends Table> List<?> getData(T table, long startRow, int count);
<T extends Table> List<?> getData(T table, long skip, int limit, String ...selectedFields);
<T extends Table> UpdateResult appendData(T table, Query query, Update update);
......
......@@ -32,7 +32,7 @@ public interface PreviewService {
Preview getPreview(UUID referenceUuid);
List<Document> getData(UUID referenceUuid, long sheet, long startRow, int count, String... selectedColumns);
List<Document> getData(UUID referenceUuid, long sheet, long startRow, int limit, String... selectedColumns);
Preview updateState(String id, State reading, String error);
......
......@@ -162,22 +162,29 @@ public class DatabaseServiceImpl implements DatabaseService {
}
@Override
public <T extends Table> List<Document> getData(T table, long startRow, int count) {
public <T extends Table> List<Document> getData(T table, long skip, int limit, String... selectedFields) {
Query q = new Query().with(Sort.by("_id"));
q.skip(startRow); // skip
q.limit(count); // limit rows
// q.fields().exclude(RAWDATA_DATASET).exclude(RAWDATA_SHEET).exclude(MONGO_ID);
// // don't send back reference UUID or sheet (they are passed in)
q.skip(skip); // skip
q.limit(limit); // limit rows
if (selectedFields == null || selectedFields.length == 0) {
q.fields().exclude(MONGO_ID);
} else {
for (String selectedColumn : selectedFields) {
q.fields().include(selectedColumn);
}
q.fields().exclude(MONGO_ID);
}
return mongoTemplate.find(q, Document.class, table.getCollection());
}
@Override
@Transactional
public <T extends Table> UpdateResult appendData(T table, Query query, Update update) {
return mongoTemplate.upsert(query, update, table.getCollection());
}
@Override
public <T extends Table> List<Document> getData(Table table, Query query) {
query.fields().exclude(MONGO_ID);
......
......@@ -146,17 +146,18 @@ public class PreviewServiceImpl implements PreviewService, InitializingBean {
}
@Override
public List<Document> getData(UUID referenceUuid, long sheet, long startRow, int count, String... selectedFields) {
public List<Document> getData(UUID referenceUuid, long sheet, long startRow, int limit, String... selectedFields) {
Query q = query(where(RAWDATA_DATASET).is(referenceUuid).and(RAWDATA_SHEET).is(sheet).and(RAWDATA_ROW).gte(startRow)).with(Sort.by(RAWDATA_ROW));
q.limit(count); // limit rows
q.limit(limit); // limit rows
if (selectedFields == null || selectedFields.length == 0) {
// don't send back reference UUID or sheet (they are passed in)
q.fields().exclude(RAWDATA_DATASET).exclude(RAWDATA_SHEET).exclude(MONGO_ID);
} else {
for (String selectedColumn : selectedFields) {
q.fields().include(selectedColumn).exclude(MONGO_ID);
q.fields().include(selectedColumn);
}
q.fields().exclude(MONGO_ID);
}
return mongoTemplate.find(q, Document.class, MONGO_RAWDATA);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment