Advertisement
Guest User

ImplementaçãoRestante

a guest
May 25th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.57 KB | None | 0 0
  1. package WebService;
  2.  
  3. import Model.Cliente;
  4. import Model.Usuario;
  5. import com.google.maps.GeoApiContext;
  6. import com.google.maps.GeocodingApi;
  7. import com.google.maps.model.GeocodingResult;
  8. import java.util.ArrayList;
  9. import java.util.Date;
  10. import javax.jws.WebService;
  11.  
  12. @WebService(endpointInterface = "WebService.WSServerInterface")
  13. public class WSServerImpl implements WSServerInterface
  14. {
  15.  
  16.     ArrayList<Usuario> usuarios = new ArrayList();
  17.     ArrayList<Cliente> clientes = new ArrayList();
  18.  
  19.     public boolean login(String usuario, String senha)
  20.     {
  21.         for (Usuario u : usuarios)
  22.         {
  23.             if (u.getUsuairo().equals(usuario))
  24.             {
  25.                 if (u.getSenha().equals(senha))
  26.                 {
  27.                     System.out.println("Usuario " + usuario + " logado");
  28.                     return true;
  29.                 } else
  30.                 {
  31.                     System.out.println("Usuario " + usuario + " digitou a senha invalida");
  32.                     return false;
  33.                 }
  34.             }
  35.         }
  36.         System.out.println("Usuario " + usuario + " nao encontrado");
  37.         return false;
  38.     }
  39.  
  40.     public String setUsuario(String nome, String usuario, String senha)
  41.     {
  42.         for (Usuario u : usuarios)
  43.         {
  44.             if (u.getUsuairo().equals(usuario))
  45.             {
  46.                 System.out.println("Usuario " + usuario + " ja existente");
  47.                 return "Usuario " + usuario + " ja existente.";
  48.             }
  49.         }
  50.         usuarios.add(new Usuario(nome, usuario, senha));
  51.         System.out.println("Inserindo usuario " + nome);
  52.         return "Usuario " + nome + " inserido com sucesso.";
  53.     }
  54.  
  55.     public String setCliente(String nome, String cpfCnpj, String data)
  56.     {
  57.         this.clientes.add(new Cliente(nome, cpfCnpj, data));
  58.         System.out.println("Inserindo cliente " + nome);
  59.         return "Cliente " + nome + " inserido com sucesso.";
  60.     }
  61.  
  62.     public String[] getClientes()
  63.     {
  64.         String[] s = new String[clientes.size()];
  65.         int i = 0;
  66.         for (Cliente c : clientes)
  67.         {
  68.             s[i] = c.getNome();
  69.             i++;
  70.         }
  71.         System.out.println("Retornando clientes");
  72.         return s;
  73.     }
  74.    
  75.     //Algoritmo de Christian(relógio)
  76.     public Date corrigeData(Date dataCliente)
  77.     {
  78.         Date dataServidor = new Date();
  79.        
  80.         if(dataCliente.equals(dataServidor))
  81.             return dataCliente;
  82.         else
  83.             return dataServidor;
  84.     }
  85.    
  86.      /* Algoritmo de Christian
  87.     //instancia a data no cliente
  88.     Date dataCliente = new Date();
  89.  
  90.      //Corrige data setando a data do cliente como a data do servidor
  91.      dataCliente = calc.corrigeData(dataCliente);
  92.     */
  93.  
  94.    
  95.     //Integração com a Google API
  96.     //Informa um endereço e retorna a latitude e longitude deste endereço.
  97.     public String GoogleMaps(String endereco) throws Exception
  98.     {
  99.         String minhaKey = "AIzaSyCr6z7GSCGTe6moIY6d9OhM0gAWx_hDMoo";
  100.        
  101.         GeoApiContext context = new GeoApiContext().setApiKey(minhaKey);
  102.         GeocodingResult[] results =  GeocodingApi.geocode(context, endereco).await();
  103.  
  104.         return "Latitude: " + results[0].geometry.location.lat
  105.              + "\n" + "Longitude: " + results[0].geometry.location.lng;
  106.     }
  107.  
  108.     /*      
  109.         CHAMAR MÉTODO DO GOOGLE MAPS PASSANDO O ENDEREÇO. VAI RETORNAR A LAT E LONG
  110.         System.out.println("\n" + "Maps: " + "\n"
  111.         + calc.GoogleMaps("R. Antônio da Veiga, 140 - Itoupava Seca,Blumenau"));
  112.     */
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement