Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package WebService;
- import Model.Cliente;
- import Model.Usuario;
- import com.google.maps.GeoApiContext;
- import com.google.maps.GeocodingApi;
- import com.google.maps.model.GeocodingResult;
- import java.util.ArrayList;
- import java.util.Date;
- import javax.jws.WebService;
- @WebService(endpointInterface = "WebService.WSServerInterface")
- public class WSServerImpl implements WSServerInterface
- {
- ArrayList<Usuario> usuarios = new ArrayList();
- ArrayList<Cliente> clientes = new ArrayList();
- public boolean login(String usuario, String senha)
- {
- for (Usuario u : usuarios)
- {
- if (u.getUsuairo().equals(usuario))
- {
- if (u.getSenha().equals(senha))
- {
- System.out.println("Usuario " + usuario + " logado");
- return true;
- } else
- {
- System.out.println("Usuario " + usuario + " digitou a senha invalida");
- return false;
- }
- }
- }
- System.out.println("Usuario " + usuario + " nao encontrado");
- return false;
- }
- public String setUsuario(String nome, String usuario, String senha)
- {
- for (Usuario u : usuarios)
- {
- if (u.getUsuairo().equals(usuario))
- {
- System.out.println("Usuario " + usuario + " ja existente");
- return "Usuario " + usuario + " ja existente.";
- }
- }
- usuarios.add(new Usuario(nome, usuario, senha));
- System.out.println("Inserindo usuario " + nome);
- return "Usuario " + nome + " inserido com sucesso.";
- }
- public String setCliente(String nome, String cpfCnpj, String data)
- {
- this.clientes.add(new Cliente(nome, cpfCnpj, data));
- System.out.println("Inserindo cliente " + nome);
- return "Cliente " + nome + " inserido com sucesso.";
- }
- public String[] getClientes()
- {
- String[] s = new String[clientes.size()];
- int i = 0;
- for (Cliente c : clientes)
- {
- s[i] = c.getNome();
- i++;
- }
- System.out.println("Retornando clientes");
- return s;
- }
- //Algoritmo de Christian(relógio)
- public Date corrigeData(Date dataCliente)
- {
- Date dataServidor = new Date();
- if(dataCliente.equals(dataServidor))
- return dataCliente;
- else
- return dataServidor;
- }
- /* Algoritmo de Christian
- //instancia a data no cliente
- Date dataCliente = new Date();
- //Corrige data setando a data do cliente como a data do servidor
- dataCliente = calc.corrigeData(dataCliente);
- */
- //Integração com a Google API
- //Informa um endereço e retorna a latitude e longitude deste endereço.
- public String GoogleMaps(String endereco) throws Exception
- {
- String minhaKey = "AIzaSyCr6z7GSCGTe6moIY6d9OhM0gAWx_hDMoo";
- GeoApiContext context = new GeoApiContext().setApiKey(minhaKey);
- GeocodingResult[] results = GeocodingApi.geocode(context, endereco).await();
- return "Latitude: " + results[0].geometry.location.lat
- + "\n" + "Longitude: " + results[0].geometry.location.lng;
- }
- /*
- CHAMAR MÉTODO DO GOOGLE MAPS PASSANDO O ENDEREÇO. VAI RETORNAR A LAT E LONG
- System.out.println("\n" + "Maps: " + "\n"
- + calc.GoogleMaps("R. Antônio da Veiga, 140 - Itoupava Seca,Blumenau"));
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement