Package sample.hello.resources

Source Code of sample.hello.resources.HelloResource

package sample.hello.resources;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.orm.PersistentException;

import com.google.gson.Gson;

import sample.hello.bean.*;
import java.util.ArrayList;
import java.util.Collection;

@Path("/hello")
public class HelloResource {
  @GET
  @Produces(MediaType.TEXT_PLAIN)
  public String sayHello(String filtro) {
   
   
   
    String json = "";
    int length2=0;
    int length3=0;
    orm.DAOFactory lDAOFactory = orm.DAOFactory.getDAOFactory();
//        Collection<orm.Persona> ormPersonas = Arrays.asList(lDAOFactory.getPersonaDAO().listPersonaByQuery(null, null));
    Collection<PersonaSOAPVO> colecionPersonaSOAPVO= new ArrayList<PersonaSOAPVO>();
    orm.Tcp_persona[] ormPersonas;
          if ( (filtro == null) || (filtro.equals("")) ) {//si no se ingresa ningun filtro por el cual buscar
                ormPersonas = lDAOFactory.getTcp_personaDAO().listTcp_personaByQuery(null, null);
                //busqueda de todos los registros existentes
            }
          else{//si se ingresa un filtro por el cual buscar
              ormPersonas = lDAOFactory.getTcp_personaDAO().listTcp_personaByQuery("pers_rut='"+filtro+"'", null);
          //primera busqueda por defecto, segun el rut
              length2 = ormPersonas.length;
         
                  if(length2==0){//si no se encuentran datos coincidentes con el rut
         
                    ormPersonas = lDAOFactory.getTcp_personaDAO().listTcp_personaByQuery("pers_nombre='"+filtro+"'", null);
                    //segunda busqeuda por nombre
                    length3 = ormPersonas.length;
                  }
         
                  if(length2==0&&length3==0){//si no se han encontrado coincidencias ni por nombre ni por rut
           
                    ormPersonas = lDAOFactory.getTcp_personaDAO().listTcp_personaByQuery("pers_id='"+filtro+"'", null);
                      //tercera busqueda por identidad
                  }
         
                }//fin busqueda segun filtro
               
          int length = ormPersonas.length;
         
            if(length==0){//si no se encontraron registros
             
              json="No se ha encontrado ningun registro";
            }
           
            else{//si  se encontraron registros
         
          for (int i = 0; i < length; i++) {
            System.out.println(ormPersonas[i].getPers_nombre());
            PersonaSOAPVO objeto = PersonaSOAPVO.crearPersonaSOAPVO(ormPersonas[i]);
            colecionPersonaSOAPVO.add(objeto);

          }//fin guardando resultados
          Gson gson = new Gson();
          json = gson.toJson(colecionPersonaSOAPVO);
           
        }

    return json;
}//fin metodo buscar todos
 
}//fin clase
TOP

Related Classes of sample.hello.resources.HelloResource

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.