示例#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
 /**
  * Löscht ein bestimmtes Spiel
  *
  * @param id ID des Spiels
  * @throws JAXBException
  * @throws FileNotFoundException
  */
 @DELETE
 @Path("/{id}")
 public void deleteSpiel(@PathParam("id") int id) throws JAXBException, FileNotFoundException {
   Spiele spiele = (Spiele) XmlTools.unmarshal(Spiele.class);
   for (Spiel s : spiele.getSpiel()) {
     if (s.getId().intValue() == id) {
       spiele.getSpiel().remove(s);
       XmlTools.marshal(Spiele.class, spiele);
       throw new WebApplicationException(Response.Status.NO_CONTENT);
     }
   }
   throw new WebApplicationException(Response.Status.NOT_FOUND);
 }
示例#3
0
 /**
  * Erstellt ein neues Spiel
  *
  * @param src Spiel
  * @throws JAXBException
  * @throws FileNotFoundException
  */
 @POST
 @Consumes(MediaType.APPLICATION_XML)
 public void createSpiel(Spiel src) throws JAXBException, FileNotFoundException {
   Spiele spiele = (Spiele) XmlTools.unmarshal(Spiele.class);
   // Check ob bereits vorhanden
   for (Spiel s : spiele.getSpiel()) {
     if (s.getName().equals(src.getName())) {
       throw new WebApplicationException(Response.Status.CONFLICT);
     }
   }
   // nicht vorhanden, hinzufügen
   src.setId(XmlTools.getNextSpielId());
   spiele.getSpiel().add(src);
   XmlTools.marshal(Spiele.class, spiele);
   throw new WebApplicationException(Response.Status.CREATED);
 }
示例#4
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);
 }
示例#5
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);
  }
示例#6
0
 /**
  * Liefert alle oder eine Auswahl an Spielen
  *
  * @param search Suchwort für eine Auswahl
  * @return Spiele
  * @throws JAXBException
  */
 @GET
 @Produces(MediaType.APPLICATION_XML)
 public Spiele getSpiele(
     @QueryParam("search") String search, @QueryParam("namesonly") boolean namesonly)
     throws JAXBException {
   Spiele spiele = (Spiele) XmlTools.unmarshal(Spiele.class);
   Spiele spieleNew;
   // kein Filter angegeben, alle ausgeben
   if (search == null || search.equals("")) {
     spieleNew = spiele;
     // Filter, nur bestimmte ausgeben
   } else {
     spieleNew = new Spiele();
     for (Spiel s : spiele.getSpiel()) {
       if (s.getName().contains(search)) {
         spieleNew.getSpiel().add(s);
       }
     }
   }
   if (namesonly) {
     Spiele spieleNamesonly = new Spiele();
     for (Spiel s : spieleNew.getSpiel()) {
       Spiel sp = new Spiel();
       sp.setName(s.getName());
       spieleNamesonly.getSpiel().add(sp);
     }
     spieleNew = spieleNamesonly;
   }
   return spieleNew;
 }
示例#7
0
 /**
  * Aktualisiert oder erstellt ein bestimmtes Spiel
  *
  * @param id ID des Spiels
  * @param src zu aktualisierendes oder erstellendes Spiel
  * @throws JAXBException
  * @throws FileNotFoundException
  */
 @PUT
 @Path("/{id}")
 @Consumes(MediaType.APPLICATION_XML)
 public void setSpiel(@PathParam("id") int id, Spiel src)
     throws JAXBException, FileNotFoundException {
   src.setId(BigInteger.valueOf(id));
   Spiele spiele = (Spiele) XmlTools.unmarshal(Spiele.class);
   // Check ob Name bereits vorhanden
   for (Spiel s : spiele.getSpiel()) {
     if (s.getName().equals(src.getName())) {
       throw new WebApplicationException(Response.Status.CONFLICT);
     }
   }
   // überschreiben da bereits vorhanden
   for (Spiel s : spiele.getSpiel()) {
     if (s.getId().intValue() == id) {
       spiele.getSpiel().set(spiele.getSpiel().indexOf(s), src);
       XmlTools.marshal(Spiele.class, spiele);
       throw new WebApplicationException(Response.Status.NO_CONTENT);
     }
   }
   // einfügen da nicht vorhanden
   Spiele spieleNew = new Spiele();
   int lastId = 0;
   for (Spiel s : spiele.getSpiel()) {
     if (id < s.getId().intValue() && id > lastId) {
       spieleNew.getSpiel().add(src);
     }
     spieleNew.getSpiel().add(s);
     lastId = s.getId().intValue();
   }
   if (id > lastId) {
     spieleNew.getSpiel().add(src);
   }
   XmlTools.marshal(Spiele.class, spieleNew);
   throw new WebApplicationException(Response.Status.CREATED);
 }
示例#8
0
 private void initComponentsModify(Spiel spiel) {
   setTitle("Genre bearbeiten");
   buttonModify.setText("Speichern");
   inputName.setText(spiel.getName());
   inputBeschreibung.setText(spiel.getBeschreibung());
 }