blob: d64e5bdd8efb39f6a805b4dad2ffdead7f9baac6 [file] [log] [blame]
margarethad3c0fc92017-10-25 15:03:32 +02001package de.ids_mannheim.korap.web.controller;
margaretha38d530e2017-07-11 19:06:50 +02002
3import javax.ws.rs.GET;
margaretha38d530e2017-07-11 19:06:50 +02004import javax.ws.rs.Path;
5import javax.ws.rs.Produces;
margaretha38d530e2017-07-11 19:06:50 +02006import javax.ws.rs.core.MediaType;
7import javax.ws.rs.core.Response;
8
margaretha543f2002017-07-14 00:27:15 +02009import org.springframework.beans.factory.annotation.Autowired;
margarethae353dfa2017-07-18 19:23:29 +020010import org.springframework.stereotype.Controller;
margaretha38d530e2017-07-11 19:06:50 +020011
12import com.sun.jersey.spi.container.ResourceFilters;
13
margarethad4796662017-11-09 16:11:40 +010014import de.ids_mannheim.korap.exceptions.KustvaktException;
margarethad3c0fc92017-10-25 15:03:32 +020015import de.ids_mannheim.korap.service.ResourceService;
margaretha543f2002017-07-14 00:27:15 +020016import de.ids_mannheim.korap.utils.JsonUtils;
margaretha38d530e2017-07-11 19:06:50 +020017import de.ids_mannheim.korap.web.filter.PiwikFilter;
18
19/**
20 * Provides information about free resources.
21 *
22 * @author margaretha
23 *
24 */
margarethae353dfa2017-07-18 19:23:29 +020025@Controller
margaretha543f2002017-07-14 00:27:15 +020026@Path("resource/")
margarethad3c0fc92017-10-25 15:03:32 +020027@ResourceFilters({ PiwikFilter.class })
margaretha38d530e2017-07-11 19:06:50 +020028@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
margarethad3c0fc92017-10-25 15:03:32 +020029public class ResourceController {
margarethae353dfa2017-07-18 19:23:29 +020030
margaretha543f2002017-07-14 00:27:15 +020031 @Autowired
margarethad3c0fc92017-10-25 15:03:32 +020032 private ResourceService resourceService;
margarethaa14f1c22017-07-19 18:51:04 +020033
margarethae353dfa2017-07-18 19:23:29 +020034
margaretha54134902017-09-27 18:43:11 +020035 /** Returns descriptions of all free resources stored in
36 * the database.
37 *
38 * @return a json description of all free resources stored in
39 * the database.
40 */
margaretha38d530e2017-07-11 19:06:50 +020041 @GET
42 @Path("info")
margaretha543f2002017-07-14 00:27:15 +020043 public Response getAllResourceInfo () {
margarethad4796662017-11-09 16:11:40 +010044 String result = "";
45 try {
46 result = JsonUtils.toJSON(resourceService.getResourceDtos());
47 }
48 catch (KustvaktException e) {
49 // TODO Auto-generated catch block
50 e.printStackTrace();
51 }
margaretha543f2002017-07-14 00:27:15 +020052 return Response.ok(result).build();
margaretha38d530e2017-07-11 19:06:50 +020053 }
margaretha38d530e2017-07-11 19:06:50 +020054}