示例#1
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);
 }
示例#2
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);
 }