@GET
  @Path("/getclient")
  @Produces("application/json; charset=utf-8")
  // http://localhost:8080/ProjetRestFull/eources/getjson
  public JResponse getEtudiant(@QueryParam("numcli") int numCli) throws ParseException {
    try {
      EntityManager em = HibUtil.getEntityManager();
      em.getTransaction().begin();
      Client c = em.find(Client.class, numCli);
      Hibernate.initialize(c);

      // On met le séjour à null, sinon il y a des références circulaires.
      em.detach(c);
      c.setSejours(null);

      GenericEntity<Client> entity = new GenericEntity<Client>(c) {};
      JResponse r = JResponse.ok(entity).build();
      em.getTransaction().commit();
      HibUtil.closeEntityManager();
      return r;
    } catch (Exception e) {
      // em.getTransaction().commit();
      HibUtil.closeEntityManager();
      return null;
    }
  }
 @GET
 @Path("/deleteclient")
 @Produces("text/plain")
 public String deleteClient(@QueryParam("numCli") int numCli) throws ParseException {
   EntityManager em = HibUtil.getEntityManager();
   em.getTransaction().begin();
   Client cli = em.find(Client.class, numCli);
   List<Sejour> sejs = cli.getSejours();
   for (Sejour s : sejs) {
     s.removeAllActivites();
     em.remove(s);
   }
   em.remove(cli);
   em.getTransaction().commit();
   HibUtil.closeEntityManager();
   return "ok";
 }
 @GET
 @Path("/getclients")
 @Produces("application/json; charset=utf-8")
 // http://localhost:8080/ProjetRestFull/eources/getjson
 public JResponse getEtudiantToJSONText() throws ParseException {
   EntityManager em = HibUtil.getEntityManager();
   em.getTransaction().begin();
   List<Client> clis = em.createQuery("from Client").getResultList();
   Hibernate.initialize(clis);
   for (Client c : clis) {
     // On met le séjour à null, sinon il y a des références circulaires.
     em.detach(c);
     c.setSejours(null);
   }
   GenericEntity<List<Client>> entity = new GenericEntity<List<Client>>(clis) {};
   JResponse r = JResponse.ok(entity).build();
   em.getTransaction().commit();
   HibUtil.closeEntityManager();
   return r;
 }
 @POST
 @Path("updateclient")
 @Consumes({MediaType.APPLICATION_JSON})
 @Produces("text/plain")
 public String updateClient(Client cliParam) {
   EntityManager em = HibUtil.getEntityManager();
   em.getTransaction().begin();
   Client cli = em.find(Client.class, cliParam.getNumCli());
   if (cliParam.getAdrRueCli() != null) {
     cli.setAdrRueCli(cliParam.getAdrRueCli());
   }
   if (cliParam.getNomCli() != null) {
     cli.setNomCli(cliParam.getNomCli());
   }
   if (cliParam.getVilleCli() != null) {
     cli.setVilleCli(cliParam.getVilleCli());
   }
   if (cliParam.getAdrRueCli() != null) {
     cli.setAdrRueCli(cliParam.getAdrRueCli());
   }
   if (cliParam.getCpCli() != null) {
     cli.setCpCli(cliParam.getCpCli());
   }
   if (cliParam.getNumPieceCli() != null) {
     cli.setNumPieceCli(cliParam.getNumPieceCli());
   }
   if (cliParam.getPieceCli() != null) {
     cli.setPieceCli(cliParam.getPieceCli());
   }
   em.getTransaction().commit();
   HibUtil.closeEntityManager();
   return "ok";
 }
Exemple #5
0
 /** Copies the contents of the specified bean into this bean. */
 public void copy(Client that) {
   setClientId(that.getClientId());
   setClientType(that.getClientType());
   setClientName(that.getClientName());
   setClientPhoneNum(that.getClientPhoneNum());
   setClientExt(that.getClientExt());
   setClientEmail(that.getClientEmail());
   setClientAddress(that.getClientAddress());
   setClientCity(that.getClientCity());
   setPostalCode(that.getPostalCode());
   setClientComment(that.getClientComment());
   setWorkOrders(new java.util.LinkedHashSet<axi.source.domain.WorkOrder>(that.getWorkOrders()));
   setInventories(new java.util.LinkedHashSet<axi.source.domain.Inventory>(that.getInventories()));
   setPurchaseOrders(
       new java.util.LinkedHashSet<axi.source.domain.PurchaseOrder>(that.getPurchaseOrders()));
   setQuotes(new java.util.LinkedHashSet<axi.source.domain.Quote>(that.getQuotes()));
 }