/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package service;

import be.luckycode.projetawebservice.Client;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;

/**
 *
 * @author michael
 */
@Stateless
@Path("clients")
public class ClientFacadeREST extends AbstractFacade<Client> {
    @PersistenceContext(unitName = "be.luckycode_projeta-webservice_war_1.0-SNAPSHOTPU")
    private EntityManager em;

    public ClientFacadeREST() {
        super(Client.class);
    }

    @POST
    @Override
    @Consumes({"application/xml", "application/json"})
    public void create(Client entity) {
        super.create(entity);
    }

    @PUT
    @Override
    @Consumes({"application/xml", "application/json"})
    public void edit(Client entity) {
        super.edit(entity);
    }

    @DELETE
    @Path("{id}")
    public void remove(@PathParam("id") Integer id) {
        super.remove(super.find(id));
    }

    @GET
    @Path("{id}")
    @Produces({"application/xml", "application/json"})
    public Client find(@PathParam("id") Integer id) {
        return super.find(id);
    }

    @GET
    @Override
    @Path("all")
    @Produces("application/json")
    public List<Client> findAll() {
        return super.findAll();
    }

    @GET
    @Path("{from}/{to}")
    @Produces({"application/xml", "application/json"})
    public List<Client> findRange(@PathParam("from") Integer from, @PathParam("to") Integer to) {
        return super.findRange(new int[]{from, to});
    }

    @GET
    @Path("count")
    @Produces("text/plain")
    public String countREST() {
        return String.valueOf(super.count());
    }

    @java.lang.Override
    protected EntityManager getEntityManager() {
        return em;
    }
    
}

@@ -173,17 +173,186 @@
 ava.
-util.List
+io.IOException;%0Aimport java.util.ArrayList;%0Aimport java.util.HashMap;%0Aimport java.util.List;%0Aimport java.util.Map;%0Aimport java.util.logging.Level;%0Aimport java.util.logging.Logger
 ;%0Aim
@@ -674,16 +674,62 @@
 roduces;
+%0Aimport org.codehaus.jackson.map.ObjectMapper;
 %0A%0A/**%0A *
@@ -2280,11 +2280,1577 @@
   %7D%0A
-
     %0A
+    %0A    @GET%0A    @Path(%22names%22)%0A    @Produces(%22application/json%22)%0A    public String getClientNames() %7B%0A        List%3CClient%3E clients = super.findAll();%0A%0A        String retVal = %22%22;%0A        %0A        ObjectMapper mapper = new ObjectMapper();%0A        %0A        List%3CMap%3E clientList = new ArrayList%3CMap%3E();%0A                %0A        for (Client cli : clients) %7B%0A            %0A            Map%3CString, Object%3E clientData = generateClientJSON(cli);%0A            %0A            clientList.add(clientData);%0A        %7D%0A        %0A        HashMap%3CString, Object%3E retClients = new HashMap%3CString, Object%3E();%0A        retClients.put(%22clients%22, clientList);%0A        %0A        try %7B%0A            retVal = mapper.writeValueAsString(retClients);%0A        %7D catch (IOException ex) %7B%0A            Logger.getLogger(UserFacadeREST.class.getName()).log(Level.SEVERE, null, ex);%0A        %7D%0A        %0A        return retVal;%0A    %7D%0A    %0A    private Map%3CString, Object%3E generateClientJSON(Client client) %7B%0A        %0A        Map%3CString, Object%3E clientData = new HashMap%3CString, Object%3E();%0A        %0A        clientData.put(%22clientId%22, client.getClientId().toString());%0A        clientData.put(%22clientName%22, client.getClientName());%0A        %0A        /*if (client.getFirstName() != null)%0A            clientData.put(%22firstName%22, client.getFirstName());%0A        if (client.getLastName() != null)%0A            clientData.put(%22lastName%22, client.getLastName());%0A        if (client.getEmailAddress() != null)%0A            clientData.put(%22emailAddress%22, client.getEmailAddress());*/%0A        %0A        return clientData;%0A    %7D%0A
 %7D%0A

Add /clients/names (getClientNames).