Commit bb5657a3 authored by Matija Obreza's avatar Matija Obreza

Fix: DatasetTable repository required for Mongo

parent da96708b
......@@ -21,7 +21,6 @@ import java.util.List;
import java.util.Optional;
import java.util.UUID;
import org.bson.Document;
import org.genesys.amphibian.api.Constants;
import org.genesys.amphibian.api.NoSuchThingException;
import org.genesys.amphibian.model.Preview;
......
......@@ -37,7 +37,7 @@ import io.swagger.annotations.ApiParam;
//@RestController
//@RequestMapping(TablesApi.CONTROLLER_URL)
//@Api(tags = { "tables" })
public abstract class TablesApi<T extends Table<?>> {
public abstract class TablesApi<T extends Table> {
public static final String CONTROLLER_URL = Constants.API_V0_BASE + "/table";
protected final Logger LOG = LoggerFactory.getLogger(getClass());
......@@ -67,8 +67,8 @@ public abstract class TablesApi<T extends 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) {
Table<?> table = databaseService.getTable(tableKey);
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);
}
......@@ -81,7 +81,7 @@ public abstract class TablesApi<T extends Table<?>> {
@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) {
Table<?> table = databaseService.getTable(tableKey);
Table table = databaseService.getTable(tableKey);
if (table == null) {
throw new NoSuchThingException("No table for name=" + tableKey);
}
......
......@@ -23,8 +23,6 @@ import org.genesys.amphibian.api.v0.TablesApi;
import org.genesys.amphibian.model.DatasetTable;
import org.genesys.amphibian.model.Table;
import org.genesys.amphibian.model.genesys.AccessionObservations;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
......@@ -50,7 +48,7 @@ public class DatasetTableApi extends TablesApi<DatasetTable> {
@Override
@ApiOperation(nickname = "getDataset", notes = "Get dataset information", value = "...")
@ApiResponses({ @ApiResponse(code = 200, message = "OK", response = DatasetTable.class) })
public Table<?> get(@ApiParam(value = "Table key", required = true, format="uuid") @PathVariable(name = "name") String tableKey) {
public Table get(@ApiParam(value = "Table key", required = true, format="uuid") @PathVariable(name = "name") String tableKey) {
return super.get(tableKey);
}
......
package org.genesys.amphibian.model;
public class DatasetTable extends Table<DatasetTableExtras> {
import org.springframework.data.mongodb.core.mapping.Document;
@Document(collection = "table")
public class DatasetTable extends Table {
private DatasetTableExtras extras;
public DatasetTableExtras getExtras() {
return extras;
}
public void setExtras(DatasetTableExtras extras) {
this.extras = extras;
}
}
......@@ -26,7 +26,7 @@ import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
@Document
public abstract class Table<T> {
public class Table {
@Id
private String id;
@Version
......@@ -49,8 +49,6 @@ public abstract class Table<T> {
/** A generic configuration of columns in this table */
private Map<String, Map<String, Object>> columns;
private T extras;
public String getId() {
return id;
}
......@@ -128,12 +126,4 @@ public abstract class Table<T> {
public Date getModifiedDate() {
return modifiedDate;
}
public T getExtras() {
return extras;
}
public void setExtras(T extras) {
this.extras = extras;
}
}
/*
* Copyright 2019 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.genesys.amphibian.repositories.mongo;
import org.genesys.amphibian.model.DatasetTable;
import org.springframework.data.mongodb.repository.MongoRepository;
public interface DatasetTableRepository extends MongoRepository<DatasetTable, String> {
DatasetTable findByKey(String name);
}
......@@ -24,23 +24,23 @@ import com.mongodb.client.ListIndexesIterable;
public interface DatabaseService {
<T extends Table<?>> T createTable(T table);
<T extends Table> T createTable(T table);
<T extends Table<?>> T updateTable(T table);
<T extends Table> T updateTable(T table);
Table<?> getTable(String tableName);
Table getTable(String tableName);
<T extends Table<?>> T dropTable(T table);
<T extends Table> T dropTable(T table);
Table<?> documentColumn(String tableName, int column, Map<String, Object> columnDef);
Table documentColumn(String tableName, int column, Map<String, Object> columnDef);
Table<?> createIndex(String tableName, String[] column, int direction);
Table createIndex(String tableName, String[] column, int direction);
Table<?> createUniqueIndex(String tableName, String[] columns, int direction);
Table createUniqueIndex(String tableName, String[] columns, int direction);
ListIndexesIterable<?> listIndices(String tableName);
<T extends Table<?>> List<?> getData(T table, long startRow, int count);
<T extends Table> List<?> getData(T table, long startRow, int count);
}
......@@ -54,7 +54,7 @@ public class DatabaseServiceImpl implements DatabaseService {
@Override
@Transactional
public <T extends Table<?>> T createTable(T table) {
public <T extends Table> T createTable(T table) {
table.setCollection(toCollectionName(table));
table = tableRepository.save(table);
......@@ -65,7 +65,7 @@ public class DatabaseServiceImpl implements DatabaseService {
}
@Override
public <T extends Table<?>> T updateTable(T table) {
public <T extends Table> T updateTable(T table) {
table.setCollection(toCollectionName(table));
table = tableRepository.save(table);
......@@ -75,13 +75,13 @@ public class DatabaseServiceImpl implements DatabaseService {
@Override
@Transactional(readOnly = true)
public Table<?> getTable(String tableKey) {
public Table getTable(String tableKey) {
return tableRepository.findByKey(tableKey);
}
@Override
@Transactional
public <T extends Table<?>> T dropTable(T table) {
public <T extends Table> T dropTable(T table) {
tableRepository.delete(table);
mongoTemplate.dropCollection(toCollectionName(table));
......@@ -92,8 +92,8 @@ public class DatabaseServiceImpl implements DatabaseService {
@Override
@Transactional
public Table<?> documentColumn(String tableKey, int column, Map<String, Object> columnDef) {
Table<?> table = tableRepository.findByKey(tableKey);
public Table documentColumn(String tableKey, int column, Map<String, Object> columnDef) {
Table table = tableRepository.findByKey(tableKey);
if (table == null) {
throw new NoSuchThingException("No table with key=" + tableKey);
}
......@@ -108,8 +108,8 @@ public class DatabaseServiceImpl implements DatabaseService {
@Override
@Transactional
public Table<?> createIndex(String tableKey, String[] columns, int direction) {
Table<?> table = tableRepository.findByKey(tableKey);
public Table createIndex(String tableKey, String[] columns, int direction) {
Table table = tableRepository.findByKey(tableKey);
if (table == null) {
throw new NoSuchThingException("No table with key=" + tableKey);
}
......@@ -127,8 +127,8 @@ public class DatabaseServiceImpl implements DatabaseService {
@Override
@Transactional
public Table<?> createUniqueIndex(String tableKey, String[] columns, int direction) {
Table<?> table = tableRepository.findByKey(tableKey);
public Table createUniqueIndex(String tableKey, String[] columns, int direction) {
Table table = tableRepository.findByKey(tableKey);
if (table == null) {
throw new NoSuchThingException("No table with key=" + tableKey);
}
......@@ -146,7 +146,7 @@ public class DatabaseServiceImpl implements DatabaseService {
@Override
public ListIndexesIterable<Document> listIndices(String tableKey) {
Table<?> table = tableRepository.findByKey(tableKey);
Table table = tableRepository.findByKey(tableKey);
if (table == null) {
throw new NoSuchThingException("No table with key=" + tableKey);
}
......@@ -155,12 +155,12 @@ public class DatabaseServiceImpl implements DatabaseService {
return collection.listIndexes();
}
private String toCollectionName(Table<?> table) {
private String toCollectionName(Table table) {
return AMPHIBIAN_TABLE_PREFIX + table.getKey();
}
@Override
public <T extends Table<?>> List<Document> getData(T table, long startRow, int count) {
public <T extends Table> List<Document> getData(T table, long startRow, int count) {
Query q = new Query().with(Sort.by("_id"));
q.skip(startRow); // skip
q.limit(count); // limit rows
......
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