Search in sources :

Example 1 with Uri

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);
    }
}
Also used : SqlPlaceholdersWrapper(com.github.mgramin.sqlboot.model.uri.wrappers.SqlPlaceholdersWrapper) DbUri(com.github.mgramin.sqlboot.model.uri.impl.DbUri) ResponseEntity(org.springframework.http.ResponseEntity) FsResourceTypes(com.github.mgramin.sqlboot.model.resource_type.impl.composite.FsResourceTypes) DbResource(com.github.mgramin.sqlboot.model.resource.DbResource) ResourceType(com.github.mgramin.sqlboot.model.resource_type.ResourceType) DbUri(com.github.mgramin.sqlboot.model.uri.impl.DbUri) Uri(com.github.mgramin.sqlboot.model.uri.Uri)

Example 2 with Uri

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);
    }
}
Also used : SqlPlaceholdersWrapper(com.github.mgramin.sqlboot.model.uri.wrappers.SqlPlaceholdersWrapper) DbUri(com.github.mgramin.sqlboot.model.uri.impl.DbUri) ResponseEntity(org.springframework.http.ResponseEntity) FsResourceTypes(com.github.mgramin.sqlboot.model.resource_type.impl.composite.FsResourceTypes) ResourceType(com.github.mgramin.sqlboot.model.resource_type.ResourceType) DbUri(com.github.mgramin.sqlboot.model.uri.impl.DbUri) Uri(com.github.mgramin.sqlboot.model.uri.Uri) Map(java.util.Map)

Example 3 with Uri

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);
    });
}
Also used : Optional.ofNullable(java.util.Optional.ofNullable) DbUri(com.github.mgramin.sqlboot.model.uri.impl.DbUri) SqlQuery(com.github.mgramin.sqlboot.sql.SqlQuery) HashMap(java.util.HashMap) BootException(com.github.mgramin.sqlboot.exceptions.BootException) DbResourceImpl(com.github.mgramin.sqlboot.model.resource.impl.DbResourceImpl) LinkedHashMap(java.util.LinkedHashMap) ResourceType(com.github.mgramin.sqlboot.model.resource_type.ResourceType) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Stream(java.util.stream.Stream) Collectors.toMap(java.util.stream.Collectors.toMap) Uri(com.github.mgramin.sqlboot.model.uri.Uri) Map(java.util.Map) DbResource(com.github.mgramin.sqlboot.model.resource.DbResource) Entry(java.util.Map.Entry) ToString(lombok.ToString) StringUtils.strip(org.apache.commons.lang3.StringUtils.strip) DbUri(com.github.mgramin.sqlboot.model.uri.impl.DbUri) DbResourceImpl(com.github.mgramin.sqlboot.model.resource.impl.DbResourceImpl) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ToString(lombok.ToString)

Example 4 with Uri

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);
}
Also used : DbUri(com.github.mgramin.sqlboot.model.uri.impl.DbUri) JsonWrapper(com.github.mgramin.sqlboot.model.uri.wrappers.JsonWrapper) Uri(com.github.mgramin.sqlboot.model.uri.Uri) DbUri(com.github.mgramin.sqlboot.model.uri.impl.DbUri)

Aggregations

Uri (com.github.mgramin.sqlboot.model.uri.Uri)4 DbUri (com.github.mgramin.sqlboot.model.uri.impl.DbUri)4 ResourceType (com.github.mgramin.sqlboot.model.resource_type.ResourceType)3 DbResource (com.github.mgramin.sqlboot.model.resource.DbResource)2 FsResourceTypes (com.github.mgramin.sqlboot.model.resource_type.impl.composite.FsResourceTypes)2 SqlPlaceholdersWrapper (com.github.mgramin.sqlboot.model.uri.wrappers.SqlPlaceholdersWrapper)2 Map (java.util.Map)2 ResponseEntity (org.springframework.http.ResponseEntity)2 BootException (com.github.mgramin.sqlboot.exceptions.BootException)1 DbResourceImpl (com.github.mgramin.sqlboot.model.resource.impl.DbResourceImpl)1 JsonWrapper (com.github.mgramin.sqlboot.model.uri.wrappers.JsonWrapper)1 SqlQuery (com.github.mgramin.sqlboot.sql.SqlQuery)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 Optional.ofNullable (java.util.Optional.ofNullable)1 Collectors.toList (java.util.stream.Collectors.toList)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 Stream (java.util.stream.Stream)1