package com.megatim.apifdxweb.service.impl.administration; import javax.ws.rs.Path; /** * REST Web Service * * @author ABEGA */ //@SecuredClass(module = "application", path = "role", description = "Roles") @Path("role") public class RoleRSImpl {//implements RoleRS { // // @Inject // protected RoleManager manager; // // @Dependent // protected NoeudManager userManager; // // @Inject // protected ActionManager actionManager; // // @Context // private UriInfo context; // // @Inject // private MapStructMapper mapstructMapper; // // public RoleRSImpl() { // super(); // } // // public RoleDto mapToDto(Role entity) { // return mapstructMapper.roleToRoleDto(entity); // } // // /** // * Permet de retourne les parametres de la requete sous forme de d'entité // * // * @param searchEntity // * @param typeOperation // * @return // */ // @Override // public RestrictionsContainer construireRequete(Role searchEntity, TypeOperation typeOperation) { // // //Variables // RestrictionsContainer requeteur = RestrictionsContainer.newInstance(); // // //On ajoute le code // if (searchEntity.getLibelle() != null && !searchEntity.getLibelle().isEmpty()) { // requeteur.addLike("libelle", "%" + searchEntity.getLibelle()); // } // // //On ajoute le description du role // if (searchEntity.getDescription() != null && !searchEntity.getDescription().isEmpty()) { // requeteur.addLike("description", "%" + searchEntity.getDescription()); // } // // //On ajoute l'etat operation // if (searchEntity.getEtatOperation() != null) { // requeteur.addEq("etatOperation", searchEntity.getEtatOperation()); // } // // //On ajoute le type opération // requeteur.addEq("typeOperation", typeOperation); // // return requeteur; // } // // @Override // public void validate(@Context HttpHeaders headers, @PathParam("id") Long id) { // // //Variables // Role entity = getManager().find(getIdPropertyName(), id); // if (entity == null) { // throw new CommonRessourceNotFoundException("Role introuvable pour l'identifiant " + id); // } // //On change l'etat // entity.setEtatOperation(EtatOperation.ACTIF); // // //On update ne bd // manager.update(entity.getId(), entity); // // } // // @Override // public void reject(@Context HttpHeaders headers, @PathParam("id") Long id) { // // //Variables // Role entity = getManager().find(getIdPropertyName(), id); // if (entity == null) { // throw new CommonRessourceNotFoundException("Role introuvable pour l'identifiant " + id); // } // //On change l'etat // entity.setEtatOperation(EtatOperation.INNACTIF); // // //On marque comme supprimé // entity.setTypeOperation(TypeOperation.SUPPRIMER); // // //On update ne bd // manager.update(entity.getId(), entity); // // } // // @Override // public void performDelete(Role entity) { // // //On marque comme supprimé // entity.setTypeOperation(TypeOperation.SUPPRIMER); // // //On set les informations supplementaires // entity.setDateSuppression(new Date()); // // //On update ne bd // manager.update(entity.getId(), entity); // } // // @Override // public void performUpdate(Role actualEntity, Role requestEntity) { // // if (actualEntity == null) { // throw new CommonRessourceNotFoundException("Role introuvable pour l'identifiant "); // } // // //Si ce libelle existe dejà // if (requestEntity.getLibelle() != null && !requestEntity.getLibelle().isEmpty() && !getManager().findByUniqueProperty("libelle", requestEntity.getLibelle(), null).isEmpty()) { // //On retourne le message d'erreur // if (!getManager().findByUniqueProperty("libelle", requestEntity.getLibelle(), null).get(0).getLibelle().equals(actualEntity.getLibelle())) { // throw new CommonAlredyExistException("libelle", "Ce Libelle Existe déjà."); // } // } // // //On copie les nouvelles valeurs // actualEntity.setLibelle(requestEntity.getLibelle()); // actualEntity.setDescription(requestEntity.getDescription()); // // //On set les informations supplementaires // actualEntity.setDateDerniereModification(new Date()); // // //On update ne bd // getManager().update(actualEntity.getId(), actualEntity); // // } // // @Override // public String getIdPropertyName() { // return "id"; // } // // @Override // public GenericManager getManager() { // return manager; // } // // @Override // public Response findByEtatOperation(@Context HttpHeaders headers, @PathParam("property") String propertyName, @PathParam("value") String propertyValue) { // // //Variables // List datas = null; // RestrictionsContainer requeteur = RestrictionsContainer.newInstance(); // // //On ajoute les criteres // requeteur.addEq(propertyName, EtatOperation.fromValeur(propertyValue)); // requeteur.addEq("typeOperation", TypeOperation.AJOUTER); // // //On on recherche l'entité // datas = getManager().filter(requeteur.getPredicats(), null, null, 0, -1); // // //Si non vide // if (datas == null || datas.isEmpty()) { // // //Liste vide // datas = new ArrayList<>(); // // } // // return Response.ok(mapstructMapper.roleSlimDtos(datas)).build(); // } // // @Override // public void beforeSave(Role entity) { // //Si ce libelle existe dejà // if (entity.getLibelle() != null && !entity.getLibelle().isEmpty() && !getManager().findByUniqueProperty("libelle", entity.getLibelle(), null).isEmpty()) { // //On retourne le message d'erreur // throw new CommonAlredyExistException("libelle", "Ce Libelle Existe déjà."); // } // entity.setDateCreation(new Date()); // entity.setEtatOperation(EtatOperation.NOUVEAU); // // } // // @Override // public void afterSave(Role entity) { // // } // // @Override // public Response getFormModel(@Context HttpHeaders headers) { // RoleFormModel formModel = new RoleFormModel(); // formModel.setActions(mapstructMapper.actionSlimDtos(actionManager.findAll())); // return Response.ok(formModel).build(); // } // // @Override // public Response getFormModelUpdate(@Context HttpHeaders headers) { // RoleFormModel formModel = new RoleFormModel(); // formModel.setActions(mapstructMapper.actionSlimDtos(actionManager.findAll())); // return Response.ok(formModel).build(); // } // // @Override // public Response save(HttpHeaders headers, Role entity) { // //Pre-traitements // beforeSave(entity); // // //On save // Role newEntity = getManager().save(entity); // // //Post-traitements // afterSave(entity); // logAfterSave(entity); // return Response.ok(mapToDto(newEntity)).build(); // } // // @Override // public Response update(HttpHeaders headers, Long id, Role entity) { // //Variables // Role actualEntity = getManager().find(getIdPropertyName(), id); // // //On copie les nouvelles valeurs // performUpdate(actualEntity, entity); // logAfterUpdate(actualEntity); // return Response.ok(mapToDto(actualEntity)).build(); // } // // @Override // public void delete(HttpHeaders headers, Long id) { // //Variables // Role entity = getManager().find(getIdPropertyName(), id); // // performDelete(entity); // logAfterDelete(entity); // } // // @Override // public Response findById(HttpHeaders headers, Long id) { // //Variables // Role entity = getManager().find(getIdPropertyName(), id); // logAfterGetRessource(); // return Response.ok(mapToDto(entity)).build(); // } // // @Override // public Response findByOneProperty(HttpHeaders headers, String propertyName, String propertyValue) { // //Variables // List datas = null; // // List dtos = new ArrayList<>(); // // //On on recherche l'entité // datas = getManager().findByUniqueProperty(propertyName, propertyValue, null); // // //Si non vide // if (datas != null) { // for (Role data : datas) { // dtos.add(mapToDto(data)); // } // } // // logAfterGetRessource(); // // return Response.ok(dtos).build(); // } // // @Override // public Response findWithPagination(HttpHeaders headers, Integer pageNumber, Integer pagesize, Role searchEntity) { // //Variables // List datas = null; // List dtos = new ArrayList<>(); // // Map orders = new HashMap<>(); // // //On trie par id // orders.put("id", OrderType.DESC); // //On construit la requete // RestrictionsContainer requeteur = construireRequete(searchEntity, TypeOperation.AJOUTER); // // //Construction de l'index // int index = (pageNumber - 1) * pagesize; // // //On on recherche l'entité // datas = getManager().filter(requeteur.getPredicats(), orders, null, index, pagesize); // // //Si non vide // if (datas != null) { // for (Role data : datas) { // dtos.add(mapToDto(data)); // } // } // // logAfterGetRessource(); // // return Response.ok(dtos).build(); // } // // @Override // public Response findAll(HttpHeaders headers, Role searchEntity) { // //Variables // List datas = null; // List dtos = new ArrayList<>(); // // //On construit la requete // RestrictionsContainer requeteur = construireRequete(searchEntity, TypeOperation.AJOUTER); // Map orders = new HashMap<>(); // // //On trie par id // orders.put("id", OrderType.DESC); // // //On on recherche l'entité // datas = getManager().filter(requeteur.getPredicats(), orders, null, 0, -1); // // //Si non vide // if (datas != null) { // for (Role data : datas) { // dtos.add(mapToDto(data)); // } // } // // logAfterGetRessource(); // // return Response.ok(dtos).build(); // } // // @Override // public Long count(HttpHeaders headers, Role searchEntity) { // //Variables // Long count = 0l; // // //On construit la requete // RestrictionsContainer requeteur = construireRequete(searchEntity, TypeOperation.AJOUTER); // // //On on recherche l'entité // count = getManager().count(requeteur.getPredicats()); // // return count; // } // // @Override // public void logAfterSave(Role entity) { //// journalActionUtilisateurManager.logAction("Enregistrement du groupe d'utilisateur : " + entity.getLibelle(), Gravite.INFO, utilisateurConnecte); // } // // @Override // public void logAfterUpdate(Role entity) { //// journalActionUtilisateurManager.logAction("Mise à jour du groupe d'utilisateur : " + entity.getLibelle(), Gravite.INFO, utilisateurConnecte); // } // // @Override // public void logAfterDelete(Role entity) { //// journalActionUtilisateurManager.logAction("Suppression du groupe d'utilisateur : " + entity.getLibelle(), Gravite.INFO, utilisateurConnecte); // } // // @Override // public void logAfterGetRessource() { //// journalActionUtilisateurManager.logAction("Consultation de la liste des groupes d'utilisateur : ", Gravite.INFO, utilisateurConnecte); // } }