示例#1
0
 @GET
 @Produces(MediaType.APPLICATION_XML)
 @Path("/{id}/kommentare")
 public Kommentare getKommentare(@PathParam("id") int id) throws JAXBException {
   Spiele spiele = (Spiele) XmlTools.unmarshal(Spiele.class);
   for (Spiel s : spiele.getSpiel()) {
     if (s.getId().intValue() == id) {
       return s.getKommentare();
     }
   }
   throw new WebApplicationException(Response.Status.NOT_FOUND);
 }
示例#2
0
 @POST
 @Consumes(MediaType.APPLICATION_XML)
 @Path("/{id}/kommentare")
 public void createKommentar(@PathParam("id") int id, Kommentar src)
     throws JAXBException, FileNotFoundException {
   Spiele spiele = (Spiele) XmlTools.unmarshal(Spiele.class);
   src.setId(XmlTools.getNextKommentarId(id));
   for (Spiel s : spiele.getSpiel()) {
     // Spiel, zu dem der Kommentar gehört
     if (s.getId().intValue() == id) {
       s.getKommentare().getKommentar().add(src);
       XmlTools.marshal(Spiele.class, spiele);
       throw new WebApplicationException(Response.Status.CREATED);
     }
   }
   throw new WebApplicationException(Response.Status.NOT_FOUND);
 }
示例#3
0
  @DELETE
  @Path("/{id}/kommentare/{comment_id}")
  public void deleteKommentar(@PathParam("id") int id, @PathParam("comment_id") int cid)
      throws JAXBException, FileNotFoundException {
    Spiele spiele = (Spiele) XmlTools.unmarshal(Spiele.class);

    for (Spiel s : spiele.getSpiel()) {
      if (s.getId().intValue() == id) {
        Kommentare kommentare = s.getKommentare();
        for (Kommentar k : kommentare.getKommentar()) {
          if (k.getId().intValue() == cid) {
            kommentare.getKommentar().remove(k);
            XmlTools.marshal(Spiele.class, spiele);
            throw new WebApplicationException(Response.Status.NO_CONTENT);
          }
        }
      }
    }
    throw new WebApplicationException(Response.Status.NOT_FOUND);
  }