Commit b19d840d authored by Nastuzzi Samy's avatar Nastuzzi Samy

API Response final fix

Jackson has two differents comportments in debug and normal mode
parent 58d12f7a
......@@ -54,7 +54,6 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
protected List<Boolean> apiNeedKey;
protected List<Boolean> apiNeedGinger;
protected List<Class> apiResponseClass;
protected Object apiResponse;
@Override
public void onCreate(final Bundle savedInstanceState) {
......@@ -198,18 +197,13 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
if (apiNeedKey.get(apiIndex))
api.setKey(sharedPreferences.getString("key_" + apiName.get(apiIndex), ""));
Object apiResponse;
try {
api.getInfosFromId(qrCodeResponse.getId());
Thread.sleep(100);
apiResponse = new ObjectMapper().readValue(api.getRequest().getResponse(), apiResponseClass.get(apiIndex));
if (nemopaySession.getFoundationId() != -1 && ((APIResponse) apiResponse).getFoundationId() != null && ((APIResponse) apiResponse).getFoundationId() != nemopaySession.getFoundationId())
throw new Exception(getString(R.string.can_not_sell_other_foundation));
if (((APIResponse) apiResponse).isValidated())
throw new Exception(getString(R.string.already_validated));
if (api.getRequest().getJSONResponse().has("type") && api.getRequest().getJSONResponse().get("type").textValue().equals("error") && api.getRequest().getJSONResponse().has("message"))
throw new Exception(api.getRequest().getJSONResponse().get("message").textValue());
}
......@@ -232,7 +226,7 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
}
if (apiIndex == 0)
payWithBottomatik(api, (BottomatikResponse) apiResponse, gingerResponse.getBadgeId());
payWithBottomatik(api, (BottomatikResponse) apiResponse, gingerResponse.getBadge_uid());
else if (apiIndex == 1) {
checkReservation(api, (ComedmusResponse) apiResponse);
}
......@@ -252,6 +246,12 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
List<List<Integer>> articleIdList = bottomatikResponse.getArticleList();
final ArrayNode purchaseList = new ObjectMapper().createArrayNode();
try {
if (nemopaySession.getFoundationId() != -1 && bottomatikResponse.getFun_id() != nemopaySession.getFoundationId())
throw new Exception(getString(R.string.can_not_sell_other_foundation));
if (bottomatikResponse.isValidated())
throw new Exception(getString(R.string.already_validated));
nemopaySession.getArticles();
Thread.sleep(100);
......@@ -304,7 +304,7 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
try {
if (!bottomatikResponse.isPaid()) {
nemopaySession.setTransaction(badgeId, bottomatikResponse.getArticleList(), bottomatikResponse.getFoundationId());
nemopaySession.setTransaction(badgeId, bottomatikResponse.getArticleList(), bottomatikResponse.getFun_id());
Thread.sleep(100);
}
......@@ -476,13 +476,13 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
long currentTimestamp = (System.currentTimeMillis() / 1000);
Log.d(LOG_TAG, "Current time: " + currentTimestamp);
if (currentTimestamp < comedmusResponse.getCreatedAt()) {
if (currentTimestamp < comedmusResponse.getCreation_date()) {
runOnUiThread(new Runnable() {
@Override
public void run() {
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(QRCodeReaderActivity.this);
alertDialogBuilder
.setTitle(getString(R.string.reservation_number) + comedmusResponse.getReservationId())
.setTitle(getString(R.string.reservation_number) + comedmusResponse.getReservation_id())
.setMessage(getString(R.string.ticket_not_created_yet))
.setCancelable(false)
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
......@@ -506,13 +506,13 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
return;
}
if (currentTimestamp > comedmusResponse.getExpiresAt()) {
if (currentTimestamp > comedmusResponse.getExpires_at()) {
runOnUiThread(new Runnable() {
@Override
public void run() {
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(QRCodeReaderActivity.this);
alertDialogBuilder
.setTitle(getString(R.string.reservation_number) + comedmusResponse.getReservationId())
.setTitle(getString(R.string.reservation_number) + comedmusResponse.getReservation_id())
.setMessage(getString(R.string.ticket_expired))
.setCancelable(false)
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
......@@ -556,7 +556,7 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(QRCodeReaderActivity.this);
alertDialogBuilder
.setTitle(getString(R.string.reservation_number) + comedmusResponse.getReservationId())
.setTitle(getString(R.string.reservation_number) + comedmusResponse.getReservation_id())
.setView(keyView)
.setCancelable(false)
.setPositiveButton(R.string.register, new DialogInterface.OnClickListener() {
......
package fr.utc.simde.jessy.responses;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.util.ArrayList;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* Created by Samy on 10/11/2017.
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class APIResponse {
protected String id;
protected String username;
protected String type;
protected Integer fun_id;
protected long expires_at;
protected long creation_date;
protected boolean paid;
protected boolean validated;
protected long expires_at;
public String getId() { return this.id; }
public String getUsername() { return this.username; }
public String getType() { return this.type; }
public Integer getFoundationId() { return this.fun_id; }
public long getExpiresAt() { return this.expires_at; }
public long getCreatedAt() { return this.creation_date; }
public boolean isPaid() { return this.paid; }
public boolean isValidated() { return this.validated; }
public long getCreation_date() { return this.creation_date; }
public long getExpires_at() { return this.expires_at; }
}
package fr.utc.simde.jessy.responses;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.ArrayList;
import java.util.List;
......@@ -10,10 +10,19 @@ import java.util.List;
* Created by Samy on 10/11/2017.
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class BottomatikResponse extends APIResponse {
protected String _id;
protected Integer fun_id;
protected boolean paid;
protected boolean validated;
protected List<List<String>> articles;
public String get_id() { return this._id; }
public Integer getFun_id() { return this.fun_id; }
public boolean isPaid() { return this.paid; }
public boolean isValidated() { return this.validated; }
public List<List<String>> getArticles() { return this.articles; }
public List<List<Integer>> getArticleList() {
List<List<Integer>> articleList = new ArrayList<List<Integer>>();
......
package fr.utc.simde.jessy.responses;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* Created by Samy on 10/11/2017.
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class ComedmusResponse extends APIResponse {
protected Integer reservation_id;
protected String seance;
public Integer getReservationId() { return this.reservation_id; }
public Integer getReservation_id() { return this.reservation_id; }
public String getSeance() { return this.seance; }
}
......@@ -17,12 +17,12 @@ public class GingerResponse {
protected boolean is_cotisant;
protected String badge_uid;
public String getUsername() { return login; }
public String getLastname() { return nom; }
public String getFirstname() { return prenom; }
public String getEmail() { return mail; }
public String getLogin() { return login; }
public String getNom() { return nom; }
public String getPrenom() { return prenom; }
public String getMail() { return mail; }
public String getType() { return type; }
public boolean getIsAdult() { return is_adulte; }
public boolean getIsContributer() { return is_cotisant; }
public String getBadgeId() { return badge_uid; }
public boolean getIs_adulte() { return is_adulte; }
public boolean getIs_cotisant() { return is_cotisant; }
public String getBadge_uid() { return badge_uid; }
}
Markdown is supported
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