Commit 13fddbe0 authored by Akhmad Fakhoni Listiyan Dede's avatar Akhmad Fakhoni Listiyan Dede
Browse files

fixing return value find offer if no content

parent 58a2420c
......@@ -470,27 +470,27 @@ public class Database {
try{
allOffer = new ArrayList<>();
if(cursor.hasNext())
while(cursor.hasNext())
{
while(cursor.hasNext())
String oneOfferString = cursor.next().toJson();
JSONObject jsonObj = new JSONObject(oneOfferString);
if(jsonObj.getInt("offered_item") == itemIdx)
{
String oneOfferString = cursor.next().toJson();
JSONObject jsonObj = new JSONObject(oneOfferString);
if(jsonObj.getInt("offered_item") == itemIdx)
{
oneoffer = new ArrayList<>();
oneoffer.add(jsonObj.getInt("offered_item"));
oneoffer.add(jsonObj.getInt("n1"));
oneoffer.add(jsonObj.getInt("demanded_item"));
oneoffer.add(jsonObj.getInt("n2"));
oneoffer.add(jsonObj.getBoolean("availability"));
oneoffer.add(getJsonObjId(jsonObj.toString()));
allOffer.add(oneoffer);
}
oneoffer = new ArrayList<>();
oneoffer.add(jsonObj.getInt("offered_item"));
oneoffer.add(jsonObj.getInt("n1"));
oneoffer.add(jsonObj.getInt("demanded_item"));
oneoffer.add(jsonObj.getInt("n2"));
oneoffer.add(jsonObj.getBoolean("availability"));
oneoffer.add(getJsonObjId(jsonObj.toString()));
allOffer.add(oneoffer);
}
if(allOffer.isEmpty())
{
return null;
}
}
else
return null;
} catch (JSONException | NullPointerException ex) {
return null;
}
......
......@@ -72,9 +72,10 @@ public class Message {
// getTradeBox("553b64d23c892b2d5b772c74");
// sendFind("553b64d23c892b2d5b772c74", 4);
System.out.println("Mix item: " + mixItem("553b6adc3c892b2edffa877c", 4, 5));
System.out.println("Get inventory: " + getInventory("553b6adc3c892b2edffa877c"));
System.out.println("Get tradebox: " + getTradeBox("553a1674179bf4356b7198d5"));
// System.out.println("Mix item: " + mixItem("553b6adc3c892b2edffa877c", 4, 5));
// System.out.println("Get inventory: " + getInventory("553b6adc3c892b2edffa877c"));
// System.out.println("Get tradebox: " + getTradeBox("553a1674179bf4356b7198d5"));
System.out.println(receive("{\"item\": 0, \"method\": \"findoffer\"}"));
}
public static String callURL(String myURL) {
......@@ -684,8 +685,8 @@ public class Message {
JSONObject jsonObj = null;
JSONObject jsonAllOffers = null;
try{
if(Database.isExist())
ArrayList<ArrayList<Object>> allOffers = Database.getTradebox(offer_token);
// if(Database.isExist())
// ArrayList<ArrayList<Object>> allOffers = Database.getTradebox(offer_token);
jsonObj = new JSONObject();
jsonObj.put("method", "accept");
jsonObj.put("offer_token", offer_token);
......@@ -722,14 +723,24 @@ public class Message {
{
String response;
JSONObject jsonObj = new JSONObject();
Object result;
try
{
jsonObj.put("status", "ok");
jsonObj.put("offers", Database.getTradebox(itemIdx));
response = jsonObj.toString();
}catch(Exception ex)
result = Database.getTradebox(itemIdx);
if(result == null)
{
response = error();
}
else
{
jsonObj.put("status", "ok");
jsonObj.put("offers", Database.getTradebox(itemIdx));
response = jsonObj.toString();
}
}catch(JSONException ex)
{
System.out.println("getFindOffer() Error: " + jsonObj.toString());
System.out.println("[EXEPTION findOffer]: Error JSON Parsing");
response = error();
}
return response;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment