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
Showing
with 1096 additions and 0 deletions
<component name="libraryTable">
<library name="mysql-connector-java-5.0.8-bin">
<CLASSES>
<root url="jar://$PROJECT_DIR$/lib/mysql-connector-java-5.0.8-bin.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectKey">
<option name="state" value="project://e2804f05-5315-4fc6-a121-c522a6c26470" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="false" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
<component name="WebServicesPlugin" addRequiredLibraries="true" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/intellij.iml" filepath="$PROJECT_DIR$/intellij.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<template>
<input-field default="com.company">IJ_BASE_PACKAGE</input-field>
</template>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>
\ No newline at end of file
-- MySQL dump 10.16 Distrib 10.1.19-MariaDB, for Win32 (AMD64)
--
-- Host: localhost Database: localhost
-- ------------------------------------------------------
-- Server version 10.1.19-MariaDB
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table `pref_loc`
--
DROP TABLE IF EXISTS `pref_loc`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `pref_loc` (
`IDDriver` int COLLATE utf8_unicode_ci NOT NULL,
`Location` varchar(30) COLLATE utf8_unicode_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `pref_loc`
--
LOCK TABLES `pref_loc` WRITE;
/*!40000 ALTER TABLE `pref_loc` DISABLE KEYS */;
INSERT INTO `pref_loc` VALUES ('1','Bandung'),('1','Jakarta'),('2','Bandung'),('1','kucing'),('1',''),('1','hhdhdhdhd'),('1','wwww'),('1','wwww'),('1','singapur'),('1','mmmmmmmmmmmmmmmmmmmmmmmmmmmm');
/*!40000 ALTER TABLE `pref_loc` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `transaction`
--
DROP TABLE IF EXISTS `transaction`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `transaction` (
`IDTransaksi` int COLLATE utf8_unicode_ci NOT NULL,
`IDDriver` int COLLATE utf8_unicode_ci NOT NULL,
`IDPenumpang` int(10) COLLATE utf8_unicode_ci NOT NULL,
`LokasiAwal` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
`LokasiTujuan` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
`Rating` int(11) NOT NULL,
`Comment` varchar(120) COLLATE utf8_unicode_ci NOT NULL,
`IsHide` tinyint(1) NOT NULL,
`DatePosted` date NOT NULL,
PRIMARY KEY (`IDTransaksi`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `transaction`
--
LOCK TABLES `transaction` WRITE;
/*!40000 ALTER TABLE `transaction` DISABLE KEYS */;
/*!40000 ALTER TABLE `transaction` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `user`
--
DROP TABLE IF EXISTS `rating_driver`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `rating_driver` (
`IDDriver` int COLLATE utf8_unicode_ci NOT NULL,
`rating` float NOT NULL,
`totalvote` int(11) NOT NULL,
PRIMARY KEY (`IDDriver`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `user`
--
LOCK TABLES `rating_driver` WRITE;
/*!40000 ALTER TABLE `rating_driver` DISABLE KEYS */;
INSERT INTO `rating_driver` VALUES (0,0,0),(1,4.10526,19),(2,4.66667,3);
/*!40000 ALTER TABLE `rating_driver` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2017-10-06 13:44:39
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="mysql-connector-java-5.0.8-bin" level="project" />
<orderEntry type="library" name="json-20171018" level="project" />
</component>
</module>
\ No newline at end of file
File added
package com.informatika.ojek.webservice;
public class Account {
private int id;
private String name;
private String username;
private String email;
private String password;
private String phone;
private String photo;
private boolean isDriver;
public Account(int _id, String _name, String _username, String _email, String _password, String _phone, String _photo, Boolean _isDriver){
id = _id;
name = _name;
username = _username;
email = _email;
password = _password;
phone = _phone;
photo = _photo;
isDriver = _isDriver;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getPhoto() {
return photo;
}
public void setPhoto(String photo) {
this.photo = photo;
}
public boolean isIsDriver() {
return isDriver;
}
public void setIsDriver(boolean isDriver) {
this.isDriver = isDriver;
}
}
package com.informatika.ojek.webservice;
import javax.jws.WebService;
import java.sql.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@WebService(endpointInterface = "com.informatika.ojek.webservice.IHistory")
public class History implements IHistory {
@Override
public Transaction[] getDriverHistory(String accessToken) {
boolean isTokenValid = true; //request identity service
int id = 1; //request identity service
if (isTokenValid) {
List<Transaction> result = new ArrayList<>();
try {
String query = "SELECT * FROM transaction 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()) {
boolean isHide;
if (rs.getInt("IsHide") == 1) {
isHide = true;
} else {
isHide = false;
}
Transaction trx = new Transaction(rs.getInt("IDTransaksi"),
rs.getInt("IDDriver"),
rs.getInt("IDPenumpang"),
rs.getString("LokasiAwal"),
rs.getString("LokasiTujuan"),
rs.getInt("Rating"),
rs.getString("Comment"),
isHide,
rs.getDate("DatePosted"));
result.add(trx);
}
conn.close();
} catch (IllegalAccessException | InstantiationException | SQLException | ClassNotFoundException e) {
e.printStackTrace();
}
return result.toArray(new Transaction[0]);
} else {
return null;
}
}
@Override
public Transaction[] getPenumpangHistory(String accessToken) {
boolean isTokenValid = true; //request identity service
int id = 2; //request identity service
if (isTokenValid) {
List<Transaction> result = new ArrayList<>();
try {
String query = "SELECT * FROM transaction WHERE IDPenumpang=" + 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()) {
boolean isHide;
if (rs.getInt("IsHide") == 1) {
isHide = true;
} else {
isHide = false;
}
Transaction trx = new Transaction(rs.getInt("IDTransaksi"),
rs.getInt("IDDriver"),
rs.getInt("IDPenumpang"),
rs.getString("LokasiAwal"),
rs.getString("LokasiTujuan"),
rs.getInt("Rating"),
rs.getString("Comment"),
isHide,
rs.getDate("DatePosted"));
result.add(trx);
}
conn.close();
} catch (IllegalAccessException | InstantiationException | SQLException | ClassNotFoundException e) {
e.printStackTrace();
}
return result.toArray(new Transaction[0]);
} else {
return null;
}
}
@Override
public boolean hideHistory(String accessToken, int idTransaction) {
boolean isTokenValid = true; //request identity service
int id = 1; //request identity service
if (isTokenValid) {
try {
String query = "UPDATE transaction SET IsHide = 0 WHERE IDTransaksi=" + idTransaction + ";";
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;
}
}
}
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 (name = "HistoryService", portName = "HistoryPort")
@SOAPBinding(style = Style.RPC)
public interface IHistory {
@WebMethod public Transaction[] getDriverHistory(String accessToken);
@WebMethod public Transaction[] getPenumpangHistory(String accessToken);
@WebMethod public boolean hideHistory(String accessToken, int idTransaction);
}
\ No newline at end of file
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 IOrder {
@WebMethod public Account[] getPrefferedDriver(String access_token, String preffered_driver, String picking_point, String destination);
@WebMethod public Account[] getNonPrefferedDriver(String access_token, String preffered_driver, String picking_point, String destination);
@WebMethod public boolean PuttransactionDetails(String access_token, int id_driver, String picking_point, String Destination, int rating, String comment);
}
\ No newline at end of file
package com.informatika.ojek.webservice;
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 (name = "ProfileService", portName = "ProfilePort")
@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) {
Order order = new Order();
// order.PuttransactionDetails("a", 2, "jakarta", "bandung", 4, "mantep gaans");
Account [] dd = order.getPrefferedDriver("a","a","a", "a");
// 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.io.*;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.sql.*;
import javax.jws.WebService;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.json.*;
//Service Implementation
@WebService(endpointInterface = "com.informatika.ojek.webservice.IOrder")
public class Order implements IOrder {
final public static String IDENTITY_SERVICE_SERVER = "http://localhost:8083";
@Override
public Account[] getPrefferedDriver(String access_token, String preffered_driver, String picking_point, String destination){
boolean valid = validateToken(access_token);
//cek akses token
int id_active;
if(valid){
id_active = 1;
} else {
System.err.println("data invalid");
return null;
}
try
{
// create our mysql database connection
String myDriver = "com.mysql.jdbc.Driver";
String myUrl = "jdbc:mysql://localhost/db_ojek";
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);
rs.last();
int rowsNumber = rs.getRow();
int n= 0;
rs.beforeFirst();
// iterate through the java resultset
Account[] accounts = new Account[rowsNumber];
while (rs.next())
{
//dapetin detail akun dari user id
String name = "aa";
if(name.equals(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 = validateToken(access_token);
//cek akses token
int id_active;
if(valid){
id_active = 1;
} else {
System.err.println("data invalid");
return null;
}
try
{
// create our mysql database connection
String myDriver = "com.mysql.jdbc.Driver";
String myUrl = "jdbc:mysql://localhost/db_ojek";
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);
rs.last();
int rowsNumber = rs.getRow();
int n= 0;
rs.beforeFirst();
// iterate through the java resultset
Account[] accounts = new Account[rowsNumber];
while (rs.next())
{
//dapetin detail akun dari user id
String name = "aa";
if(!name.equals(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 = validateToken(access_token);
//cek akses token
int id_active;
if(valid){
id_active = 1;
} else {
System.err.println("data invalid");
return false;
}
try
{
// create our mysql database connection
String myDriver = "com.mysql.jdbc.Driver";
String myUrl = "jdbc:mysql://localhost/db_ojek";
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);
rs.last();
int rowsNumber = rs.getRow();
System.out.write(rowsNumber);
int id_transaksi = rowsNumber +1;
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
Date date = new Date();
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+",'"+dateFormat.format(date)+"')";
st.executeUpdate(query2);
String query3 = "SELECT IDTransaksi from transaction where IDDriver = '"+id_driver+"'";
rs = st.executeQuery(query3);
rs.last();
int totalvote = rs.getRow();
String query4 = "SELECT sum(rating) as a from transaction where IDDriver = '"+id_driver+"' group by IDDriver";
rs = st.executeQuery(query4);
rs.next();
float totalrating = rs.getFloat("a");
float driverrating = totalrating/totalvote;
String query5 = "UPDATE rating_driver SET rating='"+driverrating+"', totalvote='"+totalvote+"' WHERE IDDriver='"+id_driver+"'";
st.executeUpdate(query5);
st.close();
return true;
}
catch (Exception e)
{
System.err.println("Got an exception! ");
System.err.println(e.getMessage());
e.printStackTrace();
return false;
}
}
public boolean validateToken(String token){
String urlParameters = "token="+token;
byte[] postData = urlParameters.getBytes( StandardCharsets.UTF_8 );
int postDataLength = postData.length;
String request = IDENTITY_SERVICE_SERVER + "/validate";
URL url = null;
try {
url = new URL(request);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput( true );
conn.setInstanceFollowRedirects( false );
conn.setRequestMethod("POST");
conn.setRequestProperty( "Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty( "charset", "utf-8");
conn.setRequestProperty( "Content-Length", Integer.toString( postDataLength ));
conn.setUseCaches( false );
DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
wr.write(postData);
wr.flush();
wr.close();
int responseCode = conn.getResponseCode();
System.out.println("\nSending 'POST' request to URL : " + url);
System.out.println("Post parameters : " + urlParameters);
System.out.println("Response Code : " + responseCode);
BufferedReader in = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
//print result
System.out.println(response.toString());
JSONObject obj = new JSONObject(response.toString());
String data = obj.getString("data");
if(data.equals("valid")){
return true;
} else
{
return false;
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
}
\ No newline at end of file
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")
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 ke identity service
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) {
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;
}
}
@Override public boolean addPreferredLocation(String accessToken, String location){
boolean isTokenValid = true; //request identity service;
int id = 1; //request identity service
if (isTokenValid) {
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;
}
}
@Override public boolean delPreferredLocation(String accessToken, String location){
boolean isTokenValid = true; //request identity service;
int id = 1; //request identity service
if (isTokenValid) {
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;
}
}
@Override public boolean updatePreferredLocation(String accessToken, String oldLocation, String newLocation){
boolean isTokenValid = true; //request identity service;
int id = 1; //request identity service
if (isTokenValid) {
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;
}
}
@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 dari identity service
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 Transaction() {
}
@Override
public String toString() {
return "Transaction{" +
"idTransaction=" + idTransaction +
", idDriver=" + idDriver +
", idPenumpang=" + idPenumpang +
", lokasiAwal='" + lokasiAwal + '\'' +
", lokasiTujuan='" + lokasiTujuan + '\'' +
", rating=" + rating +
", comment='" + comment + '\'' +
", isHide=" + isHide +
", 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;
}
}
package com.informatika.ojek.webservice;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
public class test {
public static void main(String[] args) {
try {
String url = "http://localhost:9999/ws/history?wsdl";
String namespace = "http://webservice.ojek.informatika.com/";
QName serviceQN = new QName(namespace, "HistoryService");
Service service = Service.create(new URL(url), serviceQN);
String portName = "HistoryPort";
QName portQN = new QName(namespace, portName);
IHistory sample = service.getPort(portQN, IHistory.class);
// Transaction[] hasil = sample.getPenumpangHistory("blabla");
// if (hasil != null) {
// System.out.println(hasil[0]);
// System.out.println(hasil[1]);
// }
if (sample.hideHistory("bbbbb", 1)) {
System.out.println("Sukses Hide");
} else {
System.out.println("Gagal");
}
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
}