Пример #1
0
  @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;
    }
  }
Пример #2
0
 @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";
 }
Пример #3
0
 private AccessToken createAccessToken(AuthorizationRequest request, boolean isImplicitGrant) {
   Client client = request.getClient();
   long expireDuration = client.getExpireDuration();
   long expires =
       (expireDuration == 0L ? 0L : (System.currentTimeMillis() + (1000 * expireDuration)));
   String refreshToken =
       (client.isUseRefreshTokens() && !isImplicitGrant) ? getTokenValue(true) : null;
   AuthenticatedPrincipal principal = request.getPrincipal();
   AccessToken token =
       new AccessToken(
           getTokenValue(false),
           principal,
           client,
           expires,
           request.getGrantedScopes(),
           refreshToken);
   return accessTokenRepository.save(token);
 }
Пример #4
0
 @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;
 }
Пример #5
0
 @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";
 }