Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
No results found
Show changes
package com.informatika.ojek.webservice;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
//Service Endpoint Interface
@WebService
@SOAPBinding(style = Style.RPC)
public interface IProfile {
@WebMethod public Account getActiveUser(String accessToken);
@WebMethod public String[] getLocation(String accessToken);
@WebMethod public boolean addPreferredLocation(String accessToken, String location);
@WebMethod public boolean delPreferredLocation(String accessToken, String location);
@WebMethod public boolean updatePreferredLocation(String accessToken, String old_location, String new_location);
@WebMethod public boolean updateProfile(String accessToken, String name, String phone, Boolean is_driver, String photo);
}
\ No newline at end of file
package com.informatika.ojek.webservice;
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());
Endpoint.publish("http://localhost:9999/ws/history", new History());
}
}
\ No newline at end of file
package com.informatika.ojek.webservice;
import java.sql.*;
import javax.jws.WebService;
//Service Implementation
@WebService(endpointInterface = "com.informatika.ojek.webservice.IOrder")
public class Order implements IOrder {
@Override
public Account[] getPrefferedDriver(String access_token, String preffered_driver, String picking_point, String destination){
boolean valid = true;
//cek akses token
int id_active;
if(valid){
id_active = 1;
} else {
return null;
}
try
{
// create our mysql database connection
String myDriver = "org.gjt.mm.mysql.Driver";
String myUrl = "jdbc:mysql://localhost/";
Class.forName(myDriver);
Connection conn = DriverManager.getConnection(myUrl, "root", "");
// our SQL SELECT query.
// if you only need a few columns, specify them by name instead of using "*"
String query = "SELECT distinct pref_loc.IDDriver, rating,totalvote FROM (pref_loc join rating_driver) where pref_loc.IDDriver != "+id_active+" and isdriver = 1 and (Location = '"+picking_point+"' or Location = '"+destination+"')";
// create the java statement
Statement st = conn.createStatement();
// execute the query, and get a java resultset
ResultSet rs = st.executeQuery(query);
ResultSetMetaData rsmd = rs.getMetaData();
int columnsNumber = rsmd.getColumnCount();
int n= 0;
// iterate through the java resultset
Account[] accounts = new Account[columnsNumber];
while (rs.next())
{
//dapetin detail akun dari user id
String name = "aa";
if(name == preffered_driver){
Account baru = new Account(1, "aaa", "aaa", "aaa@", "sss", "0808" , "ssss",false);
accounts[n] = baru;
n++;
}
// print the results
}
st.close();
return accounts;
}
catch (Exception e)
{
System.err.println("Got an exception! ");
System.err.println(e.getMessage());
return null;
}
}
@Override
public Account[] getNonPrefferedDriver(String access_token, String preffered_driver, String picking_point, String destination){
boolean valid = true;
int id_active;
//cek akses token
if(valid){
id_active = 1;
} else {
return null;
}
try
{
// create our mysql database connection
String myDriver = "org.gjt.mm.mysql.Driver";
String myUrl = "jdbc:mysql://localhost/";
Class.forName(myDriver);
Connection conn = DriverManager.getConnection(myUrl, "root", "");
// our SQL SELECT query.
// if you only need a few columns, specify them by name instead of using "*"
String query = "SELECT distinct pref_loc.IDDriver, rating,totalvote FROM (pref_loc join rating_driver) where pref_loc.IDDriver != "+id_active+" and isdriver = 1 and (Location = '"+picking_point+"' or Location = '"+destination+"')";
// create the java statement
Statement st = conn.createStatement();
// execute the query, and get a java resultset
ResultSet rs = st.executeQuery(query);
ResultSetMetaData rsmd = rs.getMetaData();
int columnsNumber = rsmd.getColumnCount();
int n= 0;
// iterate through the java resultset
Account[] accounts = new Account[columnsNumber];
while (rs.next())
{
//dapetin detail akun dari user id
String name = "aa";
if(name != preffered_driver){
Account baru = new Account(1, "aaa", "aaa", "aaa@", "sss", "0808" , "ssss",false);
accounts[n] = baru;
n++;
}
// print the results
}
st.close();
return accounts;
}
catch (Exception e)
{
System.err.println("Got an exception! ");
System.err.println(e.getMessage());
return null;
}
}
@Override public boolean PuttransactionDetails(String access_token, int id_driver, String picking_point, String destination, int rating, String comment){
boolean valid = true;
int id_active;
//cek akses token
if(valid){
id_active = 1;
} else {
return false;
}
try
{
// create our mysql database connection
String myDriver = "org.gjt.mm.mysql.Driver";
String myUrl = "jdbc:mysql://localhost/";
Class.forName(myDriver);
Connection conn = DriverManager.getConnection(myUrl, "root", "");
// our SQL SELECT query.
// if you only need a few columns, specify them by name instead of using "*"
// create the java statement
Statement st = conn.createStatement();
String query1 = "SELECT * FROM transaction";
ResultSet rs = st.executeQuery(query1);
ResultSetMetaData rsmd = rs.getMetaData();
int columnsNumber = rsmd.getColumnCount();
int id_transaksi = columnsNumber +1;
String query2 = "INSERT INTO transaction (IDTransaksi, IDDriver,IDPenumpang,LokasiAwal,LokasiTujuan,Rating,Comment,IsHide, DatePosted) VALUES ('"+id_transaksi+"','"+id_driver+"','"+id_active+"','"+picking_point+"','"+destination+"','"+rating+"','"+comment+"',"+0+",'"+id_transaksi+"')";
st.executeQuery(query2);
String query3 = "SELECT IDTransaksi from transaction where IDDriver = '"+id_driver+"'";
rs = st.executeQuery(query3);
rsmd = rs.getMetaData();
int totalvote = rsmd.getColumnCount();
String query4 = "SELECT sum(rating) from transaction where IDDriver = '"+id_driver+"' group by IDDriver";
rs = st.executeQuery(query4);
int totalrating = rs.getInt("sum(rating)");
float driverrating = totalrating/totalvote;
String query5 = "UPDATE rating_driver SET rating='"+driverrating+"', totalvote='"+totalvote+"' WHERE IDDriver='"+id_driver+"'";
st.close();
return true;
}
catch (Exception e)
{
System.err.println("Got an exception! ");
System.err.println(e.getMessage());
return false;
}
}
}
\ No newline at end of file
package com.informatika.ojek.webservice;
import javax.jws.WebService;
//Service Implementation
@WebService(endpointInterface = "com.informatika.ojek.webservice.IProfile")
public class Profile implements IProfile {
@Override public Account getActiveUser(String accessToken){
boolean isTokenValid = true; //request identity service
int id = 1; //request identity service
if (isTokenValid) {
//QUERY getAccount
String name = "Diki Ardian";
String username = "dikiardian";
String email = "diki@gmail.com";
String password = "12345";
String phone = "081234";
String photo = "photo.jpg";
boolean isDriver = true;
return new Account(id, name, username, email, password, phone, photo, isDriver);
} else {
return null;
}
}
@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"};
} else {
return null;
}
}
@Override public boolean addPreferredLocation(String accessToken, String location){
boolean isTokenValid = true; //request identity service;
int id = 1; //request identity service
if (isTokenValid) {
//QUERY addLocation
return true;
} else {
return false;
}
}
@Override public boolean delPreferredLocation(String accessToken, String location){
boolean isTokenValid = true; //request identity service;
int id = 1; //request identity service
if (isTokenValid) {
//QUERY delLocation
return true;
} else {
return false;
}
}
@Override public boolean updatePreferredLocation(String accessToken, String oldLocation, String newLocation){
boolean isTokenValid = true; //request identity service;
int id = 1; //request identity service
if (isTokenValid) {
//QUERY updateLocation
return true;
} else {
return false;
}
}
@Override public boolean updateProfile(String accessToken, String name, String phone, Boolean isDriver, String photo){
boolean isTokenValid = true; //request identity service;
int id = 1; //request identity service
if (isTokenValid) {
//QUERY updateProfile
return true;
} else {
return false;
}
}
}
\ No newline at end of file
package com.informatika.ojek.webservice;
import java.util.Date;
public class Transaction {
private int idTransaction;
private int idDriver;
private int idPenumpang;
private String lokasiAwal;
private String lokasiTujuan;
private int rating;
private String comment;
private boolean isHide;
private Date datePosted;
public Transaction(int idTransaction, int idDriver, int idPenumpang, String lokasiAwal, String lokasiTujuan, int rating, String comment, boolean isHide, Date datePosted) {
this.idTransaction = idTransaction;
this.idDriver = idDriver;
this.idPenumpang = idPenumpang;
this.lokasiAwal = lokasiAwal;
this.lokasiTujuan = lokasiTujuan;
this.rating = rating;
this.comment = comment;
this.isHide = isHide;
this.datePosted = datePosted;
}
public int getIdTransaction() {
return idTransaction;
}
public void setIdTransaction(int idTransaction) {
this.idTransaction = idTransaction;
}
public int getIdDriver() {
return idDriver;
}
public void setIdDriver(int idDriver) {
this.idDriver = idDriver;
}
public int getIdPenumpang() {
return idPenumpang;
}
public void setIdPenumpang(int idPenumpang) {
this.idPenumpang = idPenumpang;
}
public String getLokasiAwal() {
return lokasiAwal;
}
public void setLokasiAwal(String lokasiAwal) {
this.lokasiAwal = lokasiAwal;
}
public String getLokasiTujuan() {
return lokasiTujuan;
}
public void setLokasiTujuan(String lokasiTujuan) {
this.lokasiTujuan = lokasiTujuan;
}
public int getRating() {
return rating;
}
public void setRating(int rating) {
this.rating = rating;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
public boolean isHide() {
return isHide;
}
public void setHide(boolean hide) {
isHide = hide;
}
public Date getDatePosted() {
return datePosted;
}
public void setDatePosted(Date datePosted) {
this.datePosted = datePosted;
}
}