Database db = req.getDatabase();
try
{
AuthStatus authStatus = MolgenisServiceAuthenticationHelper.handleAuthentication(req, out);
if (!authStatus.isShowApi())
{
out.println("<html><body>");
out.println(authStatus.getPrintMe());
out.println("</body></html>");
}
else
{
String entityName = req.getRequest().getPathInfo().substring(req.getServicePath().length());
if (entityName.startsWith("/"))
{
entityName = entityName.substring(1);
}
if (entityName.equals(""))
{
out.println("<html><body>");
out.println(authStatus.getPrintMe());
if (req.getDatabase().getLogin().isAuthenticated())
{
out.println(MolgenisServiceAuthenticationHelper.displayLogoutForm());
}
showAvailableDownloads(out, db, req);
out.println("</body></html>");
}
else
{
// Check if this entity exists and is downloadable
List<org.molgenis.model.elements.Entity> downloadableEntities = getDownloadableEntities(db);
boolean found = false;
for (int i = 0; i < downloadableEntities.size() && !found; i++)
{
String name = downloadableEntities.get(i).getName();
if ((name != null) && name.equals(entityName))
{
found = true;
}
}
if (!found)
{
res.getResponse().sendError(404);// NOT FOUND
return;
}
if (req.getRequest().getQueryString() != null
&& req.getRequest().getQueryString().equals("__showQueryDialogue=true"))
{
out.println("<html><body>");
out.println(authStatus.getPrintMe());
if (req.getDatabase().getLogin().isAuthenticated())
{
out.println(MolgenisServiceAuthenticationHelper.displayLogoutForm());
}
showFilterableDownload(out, entityName, db);