diff --git a/WebService/src/com/informatika/ojek/webservice/IProfile.java b/WebService/src/com/informatika/ojek/webservice/IProfile.java index 810429441b63c674cef6ff13ef55250d84704697..52c4f95bec4dc6787f80f97e0491774022755677 100644 --- a/WebService/src/com/informatika/ojek/webservice/IProfile.java +++ b/WebService/src/com/informatika/ojek/webservice/IProfile.java @@ -4,9 +4,10 @@ import javax.jws.WebMethod; import javax.jws.WebService; import javax.jws.soap.SOAPBinding; import javax.jws.soap.SOAPBinding.Style; +import java.util.List; //Service Endpoint Interface -@WebService +@WebService (name = "ProfileService", portName = "ProfilePort") @SOAPBinding(style = Style.RPC) public interface IProfile { @WebMethod public Account getActiveUser(String accessToken); diff --git a/WebService/src/com/informatika/ojek/webservice/Main.java b/WebService/src/com/informatika/ojek/webservice/Main.java index b766ae062421cbf72787c2c647909fc2d8c4be32..15fb250862e2aee7ee8b7d0a3b6d565dc59df15f 100644 --- a/WebService/src/com/informatika/ojek/webservice/Main.java +++ b/WebService/src/com/informatika/ojek/webservice/Main.java @@ -4,7 +4,6 @@ import javax.xml.ws.Endpoint; //Endpoint publisher public class Main{ - public static void main(String[] args) { Endpoint.publish("http://localhost:9999/ws/profile", new Profile()); Endpoint.publish("http://localhost:9999/ws/order", new Order()); diff --git a/WebService/src/com/informatika/ojek/webservice/Profile.java b/WebService/src/com/informatika/ojek/webservice/Profile.java index ed60e10e1a520ca28047938c23bd9141bbb02af5..1c1a7b91ac62e400e31cff34d199eb4c63be3bc6 100644 --- a/WebService/src/com/informatika/ojek/webservice/Profile.java +++ b/WebService/src/com/informatika/ojek/webservice/Profile.java @@ -1,6 +1,9 @@ package com.informatika.ojek.webservice; import javax.jws.WebService; +import java.sql.*; +import java.util.ArrayList; +import java.util.List; //Service Implementation @WebService(endpointInterface = "com.informatika.ojek.webservice.IProfile") @@ -9,7 +12,7 @@ public class Profile implements IProfile { boolean isTokenValid = true; //request identity service int id = 1; //request identity service if (isTokenValid) { - //QUERY getAccount + //QUERY getAccount ke identity service String name = "Diki Ardian"; String username = "dikiardian"; String email = "diki@gmail.com"; @@ -22,12 +25,29 @@ public class Profile implements IProfile { return null; } } - @Override public String[] getLocation(String accessToken) { + @Override public String[] getLocation(String accessToken){ boolean isTokenValid = true; //request identity service; int id = 1; //request identity service if (isTokenValid) { - //QUERY getLocation - return new String[]{"a", "b"}; + List<String> result = new ArrayList<>(); + try { + String query = "SELECT * FROM pref_loc WHERE IDDriver=" + id + ";"; + Class.forName("com.mysql.jdbc.Driver").newInstance(); + String url = "jdbc:mysql://localhost:3306/projek"; + Connection conn = DriverManager.getConnection(url, "root", ""); + Statement stmt = conn.createStatement(); + ResultSet rs; + rs = stmt.executeQuery(query); + while (rs.next()) { + result.add(rs.getString("Location")); + } + conn.close(); + + } catch (IllegalAccessException | InstantiationException | SQLException | ClassNotFoundException e) { + e.printStackTrace(); + } + + return result.toArray(new String[0]); } else { return null; } @@ -36,8 +56,20 @@ public class Profile implements IProfile { boolean isTokenValid = true; //request identity service; int id = 1; //request identity service if (isTokenValid) { - //QUERY addLocation - return true; + try { + String query = "INSERT INTO pref_loc (IDDriver, Location) VALUES (" + id + ", '" + location + "');"; + Class.forName("com.mysql.jdbc.Driver").newInstance(); + String url = "jdbc:mysql://localhost:3306/projek"; + Connection conn = DriverManager.getConnection(url, "root", ""); + Statement stmt = conn.createStatement(); + stmt.executeUpdate(query); + conn.close(); + return true; + + } catch (IllegalAccessException | InstantiationException | SQLException | ClassNotFoundException e) { + e.printStackTrace(); + return false; + } } else { return false; } @@ -46,8 +78,20 @@ public class Profile implements IProfile { boolean isTokenValid = true; //request identity service; int id = 1; //request identity service if (isTokenValid) { - //QUERY delLocation - return true; + try { + String query = "DELETE FROM pref_loc WHERE IDDriver=" + id + " AND Location='" + location + "';"; + Class.forName("com.mysql.jdbc.Driver").newInstance(); + String url = "jdbc:mysql://localhost:3306/projek"; + Connection conn = DriverManager.getConnection(url, "root", ""); + Statement stmt = conn.createStatement(); + stmt.executeUpdate(query); + conn.close(); + return true; + + } catch (IllegalAccessException | InstantiationException | SQLException | ClassNotFoundException e) { + e.printStackTrace(); + return false; + } } else { return false; } @@ -56,8 +100,20 @@ public class Profile implements IProfile { boolean isTokenValid = true; //request identity service; int id = 1; //request identity service if (isTokenValid) { - //QUERY updateLocation - return true; + try { + String query = "UPDATE pref_loc SET Location = '" + newLocation + "' WHERE IDDriver=" + id + " AND Location='" + oldLocation + "';"; + Class.forName("com.mysql.jdbc.Driver").newInstance(); + String url = "jdbc:mysql://localhost:3306/projek"; + Connection conn = DriverManager.getConnection(url, "root", ""); + Statement stmt = conn.createStatement(); + stmt.executeUpdate(query); + conn.close(); + return true; + + } catch (IllegalAccessException | InstantiationException | SQLException | ClassNotFoundException e) { + e.printStackTrace(); + return false; + } } else { return false; } @@ -66,7 +122,7 @@ public class Profile implements IProfile { boolean isTokenValid = true; //request identity service; int id = 1; //request identity service if (isTokenValid) { - //QUERY updateProfile + //QUERY updateProfile dari identity service return true; } else { return false;