Commit 2f4793f2 authored by redmitry@list.ru's avatar redmitry@list.ru

get list of ids endpoint

parent 098a8a4c
......@@ -43,7 +43,7 @@ public class CorsResponseFilter implements ContainerResponseFilter {
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
throws IOException {
responseContext.getHeaders().add("Access-Control-Allow-Origin","*");
responseContext.getHeaders().add("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT, PATCH, OPTIONS");
responseContext.getHeaders().add("Access-Control-Allow-Methods", "GET, HEAD, POST, DELETE, PUT, PATCH, OPTIONS");
responseContext.getHeaders().add("Access-Control-Allow-Headers", "X-Requested-With");
}
}
\ No newline at end of file
......@@ -29,6 +29,7 @@ import es.bsc.inb.elixir.openebench.rest.dao.Database;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import java.io.BufferedWriter;
import java.io.OutputStream;
......@@ -89,6 +90,31 @@ public class OpenEBenchService {
return Response.ok(ctx.getResourceAsStream("/index.html"), MediaType.TEXT_HTML).build();
}
@GET
@Operation(summary = "Lists the collection data identifiers",
responses = {
@ApiResponse(content = @Content(
mediaType = "text/uri-list"
))
}
)
@Path("/{collection}")
@Produces("text/uri-list")
public Response getIds(@PathParam("collection")
@Parameter(description = "data collection",
example = "BenchmarkingEvent")
final String collection) {
StreamingOutput stream = (OutputStream out) -> {
try (Writer writer = new BufferedWriter(new OutputStreamWriter(out, "UTF-8"))) {
dao.writeIDs(writer, collection);
} catch(Exception ex) {
Logger.getLogger(OpenEBenchService.class.getName()).log(Level.SEVERE, null, ex);
}
};
return Response.ok(stream).build();
}
@GET
@Path("/{collection}")
@PermitAll
......
......@@ -128,6 +128,25 @@ public class Database {
}
}
public void writeIDs(Writer writer, String collection) {
try {
MongoDatabase db = mc.getDatabase(uri.getDatabase());
MongoCollection<Document> col = db.getCollection(collection);
FindIterable<Document> iterator = col.find()
.projection(Projections.include(DBCollection.ID_FIELD_NAME));
try (MongoCursor<Document> cursor = iterator.iterator()) {
while (cursor.hasNext()) {
final Document doc = cursor.next();
writer.write(doc.get("_id", ""));
writer.write('\n');
}
}
} catch(Exception ex) {
Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void findContactsByEmail(Writer writer, String email) {
try {
MongoDatabase db = mc.getDatabase(uri.getDatabase());
......@@ -176,7 +195,8 @@ public class Database {
final Map<String, String> contact_ids = new HashMap();
final MongoCollection<Document> contacts = mdb.getCollection("Contact");
final FindIterable<Document> iterator = contacts.find(Filters.eq("email", email)).projection(Projections.include("community_id"));
final FindIterable<Document> iterator = contacts.find(Filters.eq("email", email))
.projection(Projections.include("community_id"));
try (MongoCursor<Document> cursor = iterator.iterator()) {
while (cursor.hasNext()) {
......
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