annotate src/main/java/de/intevation/rest/LProbeRESTService.java @ 26:47728bab8cb1

Fixed persistence.xml
author Torsten Irländer <torsten.irlaender@intevation.de>
date Tue, 30 Apr 2013 14:47:59 +0200
parents dc3bfcc5f717
children
rev   line source
8
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
1 package de.intevation.rest;
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
2
15
624611a29348 Provide GET method to load a list of proben.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 8
diff changeset
3 import java.util.List;
17
4ed66a87c0c4 Added missing import.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 15
diff changeset
4 import java.util.logging.Logger;
15
624611a29348 Provide GET method to load a list of proben.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 8
diff changeset
5
8
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
6 import javax.enterprise.context.RequestScoped;
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
7 import javax.inject.Inject;
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
8 import javax.ws.rs.GET;
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
9 import javax.ws.rs.Path;
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
10 import javax.ws.rs.Produces;
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
11
15
624611a29348 Provide GET method to load a list of proben.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 8
diff changeset
12 import de.intevation.data.LProbeRepository;
624611a29348 Provide GET method to load a list of proben.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 8
diff changeset
13 import de.intevation.model.LProbe;
24
dc3bfcc5f717 Added functions to delete and create (stub) proben items. Currently are not working
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 23
diff changeset
14 import de.intevation.service.LProbeService;
15
624611a29348 Provide GET method to load a list of proben.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 8
diff changeset
15
8
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
16 /**
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
17 * JAX-RS Example
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
18 *
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
19 * This class produces a RESTful service to read the contents of the members table.
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
20 */
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
21
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
22 @Path("/proben")
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
23 @RequestScoped
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
24 public class LProbeRESTService {
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
25
15
624611a29348 Provide GET method to load a list of proben.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 8
diff changeset
26 @Inject
624611a29348 Provide GET method to load a list of proben.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 8
diff changeset
27 private LProbeRepository repository;
624611a29348 Provide GET method to load a list of proben.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 8
diff changeset
28
624611a29348 Provide GET method to load a list of proben.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 8
diff changeset
29 @Inject
624611a29348 Provide GET method to load a list of proben.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 8
diff changeset
30 private Logger log;
8
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
31
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
32 @GET
20
7a9e22e7e8af Change return type to JSON
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 17
diff changeset
33 @Produces("text/json")
7a9e22e7e8af Change return type to JSON
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 17
diff changeset
34 public List<LProbe> listAllMembers() {
15
624611a29348 Provide GET method to load a list of proben.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 8
diff changeset
35 final List<LProbe> result = repository.findAll();
20
7a9e22e7e8af Change return type to JSON
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 17
diff changeset
36 return result;
8
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
37 }
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
38
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
39 @GET
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
40 @Path("/{id:[0-9][0-9]*}")
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
41 @Produces("text/plain")
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
42 public String loadById() {
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
43 return "Eine Probe!";
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
44 }
23
00ed8e5b05b6 Added functions to Rest-Service to add and delete a item
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 20
diff changeset
45
00ed8e5b05b6 Added functions to Rest-Service to add and delete a item
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 20
diff changeset
46 @GET
00ed8e5b05b6 Added functions to Rest-Service to add and delete a item
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 20
diff changeset
47 @Path("/deleteLast")
00ed8e5b05b6 Added functions to Rest-Service to add and delete a item
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 20
diff changeset
48 @Produces("text/plain")
00ed8e5b05b6 Added functions to Rest-Service to add and delete a item
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 20
diff changeset
49 public String deleteLast() {
00ed8e5b05b6 Added functions to Rest-Service to add and delete a item
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 20
diff changeset
50 final List<LProbe> result = repository.findAll();
00ed8e5b05b6 Added functions to Rest-Service to add and delete a item
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 20
diff changeset
51 LProbe last_element = result.get(result.size()-1);
00ed8e5b05b6 Added functions to Rest-Service to add and delete a item
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 20
diff changeset
52 repository.delete(last_element);
00ed8e5b05b6 Added functions to Rest-Service to add and delete a item
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 20
diff changeset
53 return "Gelöscht id" + last_element.getProbeId();
00ed8e5b05b6 Added functions to Rest-Service to add and delete a item
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 20
diff changeset
54 }
8
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
55
23
00ed8e5b05b6 Added functions to Rest-Service to add and delete a item
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 20
diff changeset
56 @GET
00ed8e5b05b6 Added functions to Rest-Service to add and delete a item
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 20
diff changeset
57 @Path("/new")
00ed8e5b05b6 Added functions to Rest-Service to add and delete a item
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 20
diff changeset
58 @Produces("text/plain")
00ed8e5b05b6 Added functions to Rest-Service to add and delete a item
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 20
diff changeset
59 public String create() {
00ed8e5b05b6 Added functions to Rest-Service to add and delete a item
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 20
diff changeset
60 return "Neu";
00ed8e5b05b6 Added functions to Rest-Service to add and delete a item
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 20
diff changeset
61 }
8
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
62 //@GET
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
63 //@Produces("text/xml")
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
64 //public List<Member> listAllMembers() {
15
624611a29348 Provide GET method to load a list of proben.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 8
diff changeset
65 // // Us @SupressWarnings to force IDE to ignore warnings about "genericizing" the results of
8
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
66 // // this query
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
67 // @SuppressWarnings("unchecked")
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
68 // // We recommend centralizing inline queries such as this one into @NamedQuery annotations on
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
69 // // the @Entity class
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
70 // // as described in the named query blueprint:
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
71 // // https://blueprints.dev.java.net/bpcatalog/ee5/persistence/namedquery.html
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
72 // final List<Member> results = em.createQuery("select m from Member m order by m.name").getResultList();
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
73 // return results;
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
74 //}
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
75
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
76 //@GET
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
77 //@Path("/{id:[0-9][0-9]*}")
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
78 //@Produces("text/xml")
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
79 //public Member lookupMemberById(@PathParam("id") long id) {
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
80 // return em.find(Member.class, id);
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
81 //}
1016bcc08bb3 Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
82 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)