| margaretha | d3c0fc9 | 2017-10-25 15:03:32 +0200 | [diff] [blame] | 1 | package de.ids_mannheim.korap.web.controller; |
| margaretha | 38d530e | 2017-07-11 19:06:50 +0200 | [diff] [blame] | 2 | |
| 3 | import javax.ws.rs.GET; |
| margaretha | 38d530e | 2017-07-11 19:06:50 +0200 | [diff] [blame] | 4 | import javax.ws.rs.Path; |
| 5 | import javax.ws.rs.Produces; |
| margaretha | 38d530e | 2017-07-11 19:06:50 +0200 | [diff] [blame] | 6 | import javax.ws.rs.core.MediaType; |
| 7 | import javax.ws.rs.core.Response; |
| 8 | |
| margaretha | 543f200 | 2017-07-14 00:27:15 +0200 | [diff] [blame] | 9 | import org.springframework.beans.factory.annotation.Autowired; |
| margaretha | e353dfa | 2017-07-18 19:23:29 +0200 | [diff] [blame] | 10 | import org.springframework.stereotype.Controller; |
| margaretha | 38d530e | 2017-07-11 19:06:50 +0200 | [diff] [blame] | 11 | |
| 12 | import com.sun.jersey.spi.container.ResourceFilters; |
| 13 | |
| margaretha | d479666 | 2017-11-09 16:11:40 +0100 | [diff] [blame^] | 14 | import de.ids_mannheim.korap.exceptions.KustvaktException; |
| margaretha | d3c0fc9 | 2017-10-25 15:03:32 +0200 | [diff] [blame] | 15 | import de.ids_mannheim.korap.service.ResourceService; |
| margaretha | 543f200 | 2017-07-14 00:27:15 +0200 | [diff] [blame] | 16 | import de.ids_mannheim.korap.utils.JsonUtils; |
| margaretha | 38d530e | 2017-07-11 19:06:50 +0200 | [diff] [blame] | 17 | import de.ids_mannheim.korap.web.filter.PiwikFilter; |
| 18 | |
| 19 | /** |
| 20 | * Provides information about free resources. |
| 21 | * |
| 22 | * @author margaretha |
| 23 | * |
| 24 | */ |
| margaretha | e353dfa | 2017-07-18 19:23:29 +0200 | [diff] [blame] | 25 | @Controller |
| margaretha | 543f200 | 2017-07-14 00:27:15 +0200 | [diff] [blame] | 26 | @Path("resource/") |
| margaretha | d3c0fc9 | 2017-10-25 15:03:32 +0200 | [diff] [blame] | 27 | @ResourceFilters({ PiwikFilter.class }) |
| margaretha | 38d530e | 2017-07-11 19:06:50 +0200 | [diff] [blame] | 28 | @Produces(MediaType.APPLICATION_JSON + ";charset=utf-8") |
| margaretha | d3c0fc9 | 2017-10-25 15:03:32 +0200 | [diff] [blame] | 29 | public class ResourceController { |
| margaretha | e353dfa | 2017-07-18 19:23:29 +0200 | [diff] [blame] | 30 | |
| margaretha | 543f200 | 2017-07-14 00:27:15 +0200 | [diff] [blame] | 31 | @Autowired |
| margaretha | d3c0fc9 | 2017-10-25 15:03:32 +0200 | [diff] [blame] | 32 | private ResourceService resourceService; |
| margaretha | a14f1c2 | 2017-07-19 18:51:04 +0200 | [diff] [blame] | 33 | |
| margaretha | e353dfa | 2017-07-18 19:23:29 +0200 | [diff] [blame] | 34 | |
| margaretha | 5413490 | 2017-09-27 18:43:11 +0200 | [diff] [blame] | 35 | /** 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 | */ |
| margaretha | 38d530e | 2017-07-11 19:06:50 +0200 | [diff] [blame] | 41 | @GET |
| 42 | @Path("info") |
| margaretha | 543f200 | 2017-07-14 00:27:15 +0200 | [diff] [blame] | 43 | public Response getAllResourceInfo () { |
| margaretha | d479666 | 2017-11-09 16:11:40 +0100 | [diff] [blame^] | 44 | 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 | } |
| margaretha | 543f200 | 2017-07-14 00:27:15 +0200 | [diff] [blame] | 52 | return Response.ok(result).build(); |
| margaretha | 38d530e | 2017-07-11 19:06:50 +0200 | [diff] [blame] | 53 | } |
| margaretha | 38d530e | 2017-07-11 19:06:50 +0200 | [diff] [blame] | 54 | } |