use of com.github.mgramin.sqlboot.model.uri.Uri in project sql-boot by sql-boot.
the class ApiController method getListResponseEntity.
private ResponseEntity<List<DbResource>> getListResponseEntity(final HttpServletRequest request, final String connectionName, final String type) {
final Uri uri = new SqlPlaceholdersWrapper(new DbUri(parseUri(type, request)));
final ResourceType fsResourceTypes = new FsResourceTypes(dbConnectionList.getConnectionByName(connectionName));
final List<DbResource> collect = fsResourceTypes.read(uri).collect(toList());
if (collect.isEmpty()) {
return new ResponseEntity<>(collect, HttpStatus.NO_CONTENT);
} else {
return new ResponseEntity<>(collect, HttpStatus.OK);
}
}
use of com.github.mgramin.sqlboot.model.uri.Uri in project sql-boot by sql-boot.
the class ApiController method getListResponseEntityHeaders.
private ResponseEntity<List<Map<String, Object>>> getListResponseEntityHeaders(final HttpServletRequest request, final String connectionName, final String path) {
final Uri uri = new SqlPlaceholdersWrapper(new DbUri(parseUri(path, request)));
ResourceType fsResourceTypes = new FsResourceTypes(dbConnectionList.getConnectionByName(connectionName));
final List<Map<String, Object>> headers = fsResourceTypes.read(uri).map(DbResource::headers).collect(toList());
if (headers.isEmpty()) {
return new ResponseEntity<>(headers, HttpStatus.NO_CONTENT);
} else {
return new ResponseEntity<>(headers, HttpStatus.OK);
}
}
use of com.github.mgramin.sqlboot.model.uri.Uri in project sql-boot by sql-boot.
the class SqlResourceType method read.
@Override
public Stream<DbResource> read(final Uri uri) throws BootException {
final Map<String, Object> variables = new HashMap<>();
variables.put("uri", uri);
return sqlQuery.select(variables).map(o -> {
final List<Object> path = o.entrySet().stream().filter(v -> (v.getKey().startsWith("@") || v.getKey().startsWith("_"))).map(Entry::getValue).collect(toList());
final String name = path.get(path.size() - 1).toString();
final Map<String, Object> headers = o.entrySet().stream().collect(toMap(k -> strip(strip(k.getKey(), "@"), "_"), v -> ofNullable(v.getValue()).orElse(""), (a, b) -> a, LinkedHashMap::new));
return new DbResourceImpl(name, this, new DbUri(this.name(), path.stream().map(Object::toString).collect(toList())), headers);
});
}
use of com.github.mgramin.sqlboot.model.uri.Uri in project sql-boot by sql-boot.
the class DbUriTest method test.
private void test(String uriString, String jsonExpected) throws BootException {
Uri uri = new DbUri(uriString);
assertEquals(uriString, uri.toString());
assertEquals(new JsonWrapper(new DbUri(uriString)).toString(), jsonExpected);
}
Aggregations