Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
sister-kering
IF3230-Tugas-Besar-Sister-2015
Commits
ed8ae8a7
Commit
ed8ae8a7
authored
Apr 30, 2015
by
Fahmi Dumadi
Browse files
Merge branch 'master' of
http://gitlab.informatika.org/sister-kering/IF3230-Tugas-Besar-Sister-2015
parents
b446e93b
95df3b25
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/server/GrandQuestServer/src/grandquestserver/ClientHandler.java
View file @
ed8ae8a7
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
package
grandquestserver
;
package
grandquestserver
;
import
static
grandquestserver
.
MethodHandler
.
session
;
import
java.io.BufferedReader
;
import
java.io.BufferedReader
;
import
java.io.DataInputStream
;
import
java.io.DataInputStream
;
import
java.io.DataOutputStream
;
import
java.io.DataOutputStream
;
...
@@ -117,6 +118,11 @@ public class ClientHandler extends Thread {
...
@@ -117,6 +118,11 @@ public class ClientHandler extends Thread {
resultlocal
.
append
(
"offers"
,
apa
[
i
]);
resultlocal
.
append
(
"offers"
,
apa
[
i
]);
}
}
System
.
out
.
println
(
"hasil sendfind: "
+
JSONValue
.
toJSONString
(
resultlocal
));
System
.
out
.
println
(
"hasil sendfind: "
+
JSONValue
.
toJSONString
(
resultlocal
));
//simpan di var
DBHandler
db
=
new
DBHandler
();
String
token
=
parse
.
parseJSON
(
response
,
"token"
);
String
username
=
session
.
get
(
handler
.
searchToken
(
token
)).
getUsername
();
db
.
saveOfferFound
(
username
,
resultlocal
.
toString
());
out
.
writeUTF
(
JSONValue
.
toJSONString
(
resultlocal
));
out
.
writeUTF
(
JSONValue
.
toJSONString
(
resultlocal
));
break
;
break
;
case
"findoffer"
:
case
"findoffer"
:
...
@@ -124,8 +130,12 @@ public class ClientHandler extends Thread {
...
@@ -124,8 +130,12 @@ public class ClientHandler extends Thread {
break
;
break
;
case
"sendaccept"
:
case
"sendaccept"
:
String
offer_token
=
parse
.
parseJSON
(
response
,
"offer_token"
);
String
offer_token
=
parse
.
parseJSON
(
response
,
"offer_token"
);
token
=
parse
.
parseJSON
(
response
,
"token"
);
JSONObject
ceklocal
=
new
JSONObject
(
handler
.
Accept
(
response
));
JSONObject
ceklocal
=
new
JSONObject
(
handler
.
Accept
(
response
));
System
.
out
.
println
(
"respon dari lokal: "
+
ceklocal
.
toString
());
boolean
offer_found
=
ceklocal
.
getString
(
"status"
).
equals
(
"ok"
);
boolean
offer_found
=
ceklocal
.
getString
(
"status"
).
equals
(
"ok"
);
db
=
new
DBHandler
();
Offer
item
=
new
Offer
();
if
(!
offer_found
)
{
if
(!
offer_found
)
{
JSONObject
requestAccept
=
new
JSONObject
();
JSONObject
requestAccept
=
new
JSONObject
();
requestAccept
.
put
(
"method"
,
"accept"
);
requestAccept
.
put
(
"method"
,
"accept"
);
...
@@ -153,6 +163,35 @@ public class ClientHandler extends Thread {
...
@@ -153,6 +163,35 @@ public class ClientHandler extends Thread {
JSONObject
acceptok
=
new
JSONObject
();
JSONObject
acceptok
=
new
JSONObject
();
acceptok
.
put
(
"status"
,
"ok"
);
acceptok
.
put
(
"status"
,
"ok"
);
out
.
writeUTF
(
acceptok
.
toString
());
out
.
writeUTF
(
acceptok
.
toString
());
// nanganin perpindahan item di database;
username
=
session
.
get
(
handler
.
searchToken
(
token
)).
getUsername
();
JSONObject
offersfound_whole
=
new
JSONObject
(
db
.
loadOfferFound
(
username
));
JSONArray
offersfound
=
offersfound_whole
.
getJSONArray
(
"offers"
);
boolean
found
=
false
;
int
j
=
0
;
while
(!
found
&&
j
<
offersfound
.
length
()){
if
(
offersfound
.
getJSONArray
(
j
).
get
(
5
).
equals
(
token
)){
found
=
true
;
}
else
{
j
++;
}
}
if
(
found
){
//kurangin item dari offer yang ketemu punyanya si username yang ada di token
JSONArray
offermatched
=
offersfound
.
getJSONArray
(
j
);
int
offer_itemid
=
offermatched
.
getInt
(
0
);
int
offer_item_qty
=
offermatched
.
getInt
(
1
);
int
demand_itemid
=
offermatched
.
getInt
(
2
);
int
demand_item_qty
=
offermatched
.
getInt
(
3
);
boolean
availability
=
offermatched
.
getBoolean
(
4
);
//TODO: cekdemand item kuantitinya si user yang ada di token, punya ga dia, kalo punya kurangin demand, tambahin offer
}
System
.
out
.
println
(
username
);
System
.
out
.
println
(
item
.
getOffered
().
intValue
());
handler
.
pullItem
(
username
,
item
.
getOffered
().
intValue
(),
item
.
getOffered_num
().
intValue
());
}
}
else
{
else
{
JSONObject
acceptok
=
new
JSONObject
();
JSONObject
acceptok
=
new
JSONObject
();
...
@@ -162,7 +201,16 @@ public class ClientHandler extends Thread {
...
@@ -162,7 +201,16 @@ public class ClientHandler extends Thread {
}
}
}
}
else
{
else
{
username
=
session
.
get
(
handler
.
searchToken
(
token
)).
getUsername
();
item
=
db
.
pullOffer
(
offer_token
);
System
.
out
.
println
(
username
);
System
.
out
.
println
(
item
.
getOffered
().
intValue
());
//TODO: cek demand quantity dan kurangin kalo >= stok dia punya di inventory
handler
.
pullItem
(
username
,
item
.
getOffered
().
intValue
(),
item
.
getOffered_num
().
intValue
());
out
.
writeUTF
(
handler
.
sendAccept
(
response
));
out
.
writeUTF
(
handler
.
sendAccept
(
response
));
// nanganin perpindahan item di database
}
}
break
;
break
;
case
"accept"
:
case
"accept"
:
...
...
src/server/GrandQuestServer/src/grandquestserver/DBHandler.java
View file @
ed8ae8a7
...
@@ -200,6 +200,27 @@ public class DBHandler {
...
@@ -200,6 +200,27 @@ public class DBHandler {
return
offer
;
return
offer
;
}
}
public
void
saveOfferFound
(
String
user_name
,
String
offers_found
)
{
try
{
statement
.
executeUpdate
(
"update user set offers_found='"
+
offers_found
+
"' where username='"
+
user_name
+
"'"
);
}
catch
(
SQLException
ex
)
{
Logger
.
getLogger
(
DBHandler
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
}
public
String
loadOfferFound
(
String
user_name
)
{
String
offers_found
=
null
;
try
{
ResultSet
result
=
statement
.
executeQuery
(
"select offers_found from user where username='"
+
user_name
+
"'"
);
while
(
result
.
next
())
{
offers_found
=
result
.
getString
(
"offers_found"
);
}
}
catch
(
SQLException
ex
)
{
Logger
.
getLogger
(
DBHandler
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
return
offers_found
;
}
//menampilkan seluruh isi tradebox
//menampilkan seluruh isi tradebox
public
List
<
Offer
>
getOffer
(
String
username
)
throws
SQLException
{
public
List
<
Offer
>
getOffer
(
String
username
)
throws
SQLException
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment