Commit 88791fe1 authored by Nastuzzi Samy's avatar Nastuzzi Samy
Browse files

Merge branch 'release/v0.8.0'

parents 1a2bc510 07bb74d7
package fr.utc.simde.jessy;
import android.os.Bundle;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import java.util.HashMap;
/**
* Created by Samy on 27/10/2017.
*/
public class ArticleCategoryActivity extends ArticleGroupActivity {
private static final String LOG_TAG = "_ArticleCategoryActivit";
@Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
protected void createGroups(final JsonNode categoryList, final JsonNode articleList) throws Exception {
HashMap<Integer, ArrayNode> articlesPerCategory = new HashMap<Integer, ArrayNode>();
final int foundationId = nemopaySession.getFoundationId();
final JsonNode authorizedList = config.getGroupList();
for (final JsonNode article : articleList) {
if (!article.has("id") || !article.has("price") || !article.has("name") || !article.has("active") || !article.has("cotisant") || !article.has("alcool") || !article.has("categorie_id") || !article.has("image_url") || !article.has("fundation_id") || article.get("fundation_id").intValue() != foundationId)
throw new Exception("Unexpected JSON");
if (!article.get("active").booleanValue())
continue;
if (articlesPerCategory.containsKey(article.get("categorie_id").intValue()))
articlesPerCategory.get(article.get("categorie_id").intValue()).add(article);
else
articlesPerCategory.put(article.get("categorie_id").intValue(), new ObjectMapper().createArrayNode().add(article));
}
for (JsonNode category : categoryList) {
if (!category.has("id") || !category.has("name") || !category.has("fundation_id") || category.get("fundation_id").intValue() != foundationId)
throw new Exception("Unexpected JSON");
ArrayNode articlesForThisCategory = articlesPerCategory.get(category.get("id").intValue());
if (config.getFoundationId() != -1) {
if (!authorizedList.has(Integer.toString(category.get("id").intValue())) || articlesForThisCategory == null)
continue;
}
else if (articlesForThisCategory == null || articlesForThisCategory.size() == 0)
continue;
createNewGroup(category.get("name").textValue(), articlesForThisCategory);
}
}
}
......@@ -20,7 +20,6 @@ import android.widget.Toast;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.util.ArrayList;
import java.util.HashMap;
......@@ -214,78 +213,6 @@ public class ArticleGroupActivity extends BaseActivity {
pay(badgeId);
}
protected void createCategories(final JsonNode categoryList, final List<Integer> authorizedList, final JsonNode articleList) throws Exception {
HashMap<Integer, ArrayNode> articlesPerCategory = new HashMap<Integer, ArrayNode>();
final int foundationId = nemopaySession.getFoundationId();
for (final JsonNode article : articleList) {
if (!article.has("id") || !article.has("price") || !article.has("name") || !article.has("active") || !article.has("cotisant") || !article.has("alcool") || !article.has("categorie_id") || !article.has("image_url") || !article.has("fundation_id") || article.get("fundation_id").intValue() != foundationId)
throw new Exception("Unexpected JSON");
if (!article.get("active").booleanValue())
continue;
if (articlesPerCategory.containsKey(article.get("categorie_id").intValue()))
articlesPerCategory.get(article.get("categorie_id").intValue()).add(article);
else
articlesPerCategory.put(article.get("categorie_id").intValue(), new ObjectMapper().createArrayNode().add(article));
}
for (JsonNode category : categoryList) {
if (!category.has("id") || !category.has("name") || !category.has("fundation_id") || category.get("fundation_id").intValue() != foundationId)
throw new Exception("Unexpected JSON");
ArrayNode articlesForThisCategory = articlesPerCategory.get(category.get("id").intValue());
if (config.getFoundationId() != -1) if (!authorizedList.contains(category.get("id").intValue()) || articlesForThisCategory == null)
continue;
else if (articlesForThisCategory == null || articlesForThisCategory.size() == 0)
continue;
createNewGroup(category.get("name").textValue(), articlesForThisCategory);
}
}
protected void createKeyboards(final JsonNode keyboardList, final List<Integer> authorizedList, final JsonNode articleList) throws Exception {
final int foundationId = nemopaySession.getFoundationId();
for (final JsonNode article : articleList) {
if (!article.has("id") || !article.has("price") || !article.has("name") || !article.has("active") || !article.has("cotisant") || !article.has("alcool") || !article.has("categorie_id") || !article.has("image_url") || !article.has("fundation_id") || article.get("fundation_id").intValue() != foundationId)
throw new Exception("Unexpected JSON");
}
for (JsonNode keyboard : keyboardList) {
ArrayNode articlesForThisKeyboard = new ObjectMapper().createArrayNode();
if (!keyboard.has("id") || !keyboard.has("name") || !keyboard.has("fun_id") || keyboard.get("fun_id").intValue() != foundationId || !keyboard.has("data") || !keyboard.get("data").has("items") || !keyboard.get("data").get("items").isArray() || !keyboard.get("data").has("nbColumns"))
throw new Exception("Unexpected JSON");
if (config.getFoundationId() != -1) if (!authorizedList.contains(keyboard.get("id").intValue()) || articlesForThisKeyboard == null)
continue;
else if (keyboard.get("data").get("items") == null || keyboard.get("data").get("items").size() == 0)
continue;
for (JsonNode article : keyboard.get("data").get("items")) {
if (article.has("itm_id")) {
boolean in = false;
for (JsonNode articleInList : articleList) {
if (articleInList.get("id").intValue() == article.get("itm_id").intValue()) {
articlesForThisKeyboard.add(articleInList);
in = true;
break;
}
}
if (!in && config.getInGrid())
articlesForThisKeyboard.add(new ObjectMapper().createObjectNode());
}
else if (config.getInGrid())
articlesForThisKeyboard.add(new ObjectMapper().createObjectNode());
}
createNewGroup(keyboard.get("name").textValue(), articlesForThisKeyboard, keyboard.get("data").get("nbColumns").isInt() ? keyboard.get("data").get("nbColumns").intValue() : Integer.valueOf(keyboard.get("data").get("nbColumns").textValue()));
}
}
protected void configDialog() {
dialog.startLoading(ArticleGroupActivity.this, getResources().getString(R.string.information_collection), getString(config.getInCategory() ? R.string.category_list_collecting : R.string.keyboard_list_collecting));
......@@ -354,6 +281,7 @@ public class ArticleGroupActivity extends BaseActivity {
listView.setOnItemClickListener(new ListView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
config.setCanCancel(canCancelSwitch.isChecked());
config.setFoundation(nemopaySession.getFoundationId(), nemopaySession.getFoundationName());
config.setLocation(locationAdapter.getLocationId(position), locationAdapter.getLocationName(position));
startMainActivity(ArticleGroupActivity.this);
......@@ -470,6 +398,85 @@ public class ArticleGroupActivity extends BaseActivity {
}.start();
}
protected void createCategories(final JsonNode categoryList, final List<Integer> authorizedList, final JsonNode articleList) throws Exception {
HashMap<Integer, ArrayNode> articlesPerCategory = new HashMap<Integer, ArrayNode>();
final int foundationId = nemopaySession.getFoundationId();
for (final JsonNode article : articleList) {
if (!article.has("id") || !article.has("price") || !article.has("name") || !article.has("active") || !article.has("cotisant") || !article.has("alcool") || !article.has("categorie_id") || !article.has("image_url") || !article.has("fundation_id") || article.get("fundation_id").intValue() != foundationId)
throw new Exception("Unexpected JSON");
if (!article.get("active").booleanValue())
continue;
if (articlesPerCategory.containsKey(article.get("categorie_id").intValue()))
articlesPerCategory.get(article.get("categorie_id").intValue()).add(article);
else
articlesPerCategory.put(article.get("categorie_id").intValue(), new ObjectMapper().createArrayNode().add(article));
}
for (JsonNode category : categoryList) {
if (!category.has("id") || !category.has("name") || !category.has("fundation_id") || category.get("fundation_id").intValue() != foundationId)
throw new Exception("Unexpected JSON");
ArrayNode articlesForThisCategory = articlesPerCategory.get(category.get("id").intValue());
if (config.getFoundationId() != -1) if (!authorizedList.contains(category.get("id").intValue()))
continue;
else if (articlesForThisCategory.size() == 0)
continue;
if (articlesForThisCategory == null)
continue;
createNewGroup(category.get("name").textValue(), articlesForThisCategory);
}
}
protected void createKeyboards(final JsonNode keyboardList, final List<Integer> authorizedList, final JsonNode articleList) throws Exception {
final int foundationId = nemopaySession.getFoundationId();
for (final JsonNode article : articleList) {
if (!article.has("id") || !article.has("price") || !article.has("name") || !article.has("active") || !article.has("cotisant") || !article.has("alcool") || !article.has("categorie_id") || !article.has("image_url") || !article.has("fundation_id") || article.get("fundation_id").intValue() != foundationId)
throw new Exception("Unexpected JSON");
}
for (JsonNode keyboard : keyboardList) {
ArrayNode articlesForThisKeyboard = new ObjectMapper().createArrayNode();
if (!keyboard.has("id") || !keyboard.has("name") || !keyboard.has("fun_id") || keyboard.get("fun_id").intValue() != foundationId || !keyboard.has("data") || !keyboard.get("data").has("items") || !keyboard.get("data").get("items").isArray() || !keyboard.get("data").has("nbColumns"))
throw new Exception("Unexpected JSON");
if (config.getFoundationId() != -1) if (!authorizedList.contains(keyboard.get("id").intValue()))
continue;
else if (articlesForThisKeyboard.size() == 0)
continue;
if (articlesForThisKeyboard == null)
continue;
for (JsonNode article : keyboard.get("data").get("items")) {
if (article.has("itm_id")) {
boolean in = false;
for (JsonNode articleInList : articleList) {
if (articleInList.get("id").intValue() == article.get("itm_id").intValue()) {
articlesForThisKeyboard.add(articleInList);
in = true;
break;
}
}
if (!in && config.getInGrid())
articlesForThisKeyboard.add(new ObjectMapper().createObjectNode());
}
else if (config.getInGrid())
articlesForThisKeyboard.add(new ObjectMapper().createObjectNode());
}
createNewGroup(keyboard.get("name").textValue(), articlesForThisKeyboard, keyboard.get("data").get("nbColumns").isInt() ? keyboard.get("data").get("nbColumns").intValue() : Integer.valueOf(keyboard.get("data").get("nbColumns").textValue()));
}
}
protected void createNewGroup(final String name, final ArrayNode articleList) throws Exception { createNewGroup(name, articleList, 3); }
protected void createNewGroup(final String name, final ArrayNode articleList, int gridColumns) throws Exception {
GroupFragment articleGroupFragment = new GroupFragment(ArticleGroupActivity.this, articleList, this.panier, this.config, gridColumns);
......
package fr.utc.simde.jessy;
import android.os.Bundle;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
/**
* Created by Samy on 27/10/2017.
*/
public class ArticleKeyboardActivity extends ArticleGroupActivity {
private static final String LOG_TAG = "_ArticleKeyboardActivit";
@Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
protected void createGroups(final JsonNode keyboardList, final JsonNode articleList) throws Exception {
final int foundationId = nemopaySession.getFoundationId();
final JsonNode authorizedList = config.getGroupList();
for (final JsonNode article : articleList) {
if (!article.has("id") || !article.has("price") || !article.has("name") || !article.has("active") || !article.has("cotisant") || !article.has("alcool") || !article.has("categorie_id") || !article.has("image_url") || !article.has("fundation_id") || article.get("fundation_id").intValue() != foundationId)
throw new Exception("Unexpected JSON");
}
for (JsonNode keyboard : keyboardList) {
ArrayNode articlesForThisKeyboard = new ObjectMapper().createArrayNode();
if (!keyboard.has("id") || !keyboard.has("name") || !keyboard.has("fun_id") || keyboard.get("fun_id").intValue() != foundationId || !keyboard.has("data") || !keyboard.get("data").has("items") || !keyboard.get("data").get("items").isArray() || !keyboard.get("data").has("nbColumns"))
throw new Exception("Unexpected JSON");
if (config.getFoundationId() != -1) if (!authorizedList.has(Integer.toString(keyboard.get("id").intValue())))
continue;
else if (keyboard.get("data").get("items").size() == 0)
continue;
for (JsonNode article : keyboard.get("data").get("items")) {
if (article.has("itm_id")) {
boolean in = false;
for (JsonNode articleInList : articleList) {
if (articleInList.get("id").intValue() == article.get("itm_id").intValue()) {
articlesForThisKeyboard.add(articleInList);
in = true;
break;
}
}
if (!in && config.getInGrid())
articlesForThisKeyboard.add(new ObjectMapper().createObjectNode());
}
else if (config.getInGrid())
articlesForThisKeyboard.add(new ObjectMapper().createObjectNode());
}
createNewGroup(keyboard.get("name").textValue(), articlesForThisKeyboard, keyboard.get("data").get("nbColumns").isInt() ? keyboard.get("data").get("nbColumns").intValue() : Integer.valueOf(keyboard.get("data").get("nbColumns").textValue()));
}
}
}
......@@ -73,7 +73,8 @@ public abstract class BaseActivity extends NFCActivity {
});
}
protected void hasRights(final String titre, final String[] rightList, final Runnable runnable) {
protected void hasRights(final String title, final String[] rightList, final Runnable runnable) { hasRights(title, rightList, false, runnable);}
protected void hasRights(final String title, final String[] rightList, final boolean needToBeSuper, final Runnable runnable) {
dialog.startLoading(BaseActivity.this, getString(R.string.information_collection), getString(R.string.user_rights_list_collecting));
new Thread() {
@Override
......@@ -93,14 +94,16 @@ public abstract class BaseActivity extends NFCActivity {
}
}
if (myRightList.has(String.valueOf(nemopaySession.getFoundationId()))) {
for (JsonNode myRight : myRightList.get(String.valueOf(nemopaySession.getFoundationId()))) {
if (rights.contains(myRight.textValue()))
sameRights.add(myRight.textValue());
if (!needToBeSuper) {
for (JsonNode foundation : myRightList) {
for (JsonNode myRight : foundation) {
if (rights.contains(myRight.textValue()) && !sameRights.contains(myRight.textValue()))
sameRights.add(myRight.textValue());
}
}
}
if ((rights.size() == sameRights.size()) || (rights.size() == 0 && myRightList.has("0") && myRightList.get("0").size() > 75)) // Si on a plus de 75 droits sur toutes les fondations, on estime qu'on a le full access
if ((rights.size() == sameRights.size() && rights.size() != 0) || (rights.size() == 0 && myRightList.has("0") && myRightList.get("0").size() > 75)) // Si on a plus de 75 droits sur toutes les fondations, on estime qu'on a le full access
runOnUiThread(new Runnable() {
@Override
public void run() {
......@@ -113,7 +116,7 @@ public abstract class BaseActivity extends NFCActivity {
@Override
public void run() {
dialog.stopLoading();
dialog.errorDialog(BaseActivity.this, titre, nemopaySession.forbidden(rightList));
dialog.errorDialog(BaseActivity.this, title, nemopaySession.forbidden(rightList, needToBeSuper));
}
});
}
......@@ -164,42 +167,18 @@ public abstract class BaseActivity extends NFCActivity {
if (!request.isJSONResponse() || !foundationList.isArray())
throw new Exception("Malformed JSON");
if (foundationList.size() == 0) {
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.stopLoading();
fatal(activity, getString(R.string.information_collection), nemopaySession.getUsername() + " " + getString(R.string.user_no_rights));
}
});
return;
}
for (final JsonNode foundation : foundationList) {
if (!foundation.has("name") || !foundation.has("fun_id"))
throw new Exception("Unexpected JSON");
}
if (foundationList.size() == 1) {
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.stopLoading();
startArticlesActivity(activity, foundationList.get(0).get("fun_id").intValue(), foundationList.get(0).get("name").textValue());
}
});
return;
}
intent.putExtra("foundationList", request.getResponse());
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.stopLoading();
if (activity.getClass().getSimpleName().equals("FoundationsOptionsActivity"))
if (activity instanceof FoundationsOptionsActivity)
finish();
activity.startActivity(intent);
......@@ -371,7 +350,7 @@ public abstract class BaseActivity extends NFCActivity {
public void run() {
dialog.stopLoading();
if (activity.getClass().getSimpleName().equals("ArticleKeyboardActivity") || activity.getClass().getSimpleName().equals("ArticleCategoryActivity"))
if (activity instanceof ArticleGroupActivity)
finish();
activity.startActivity(intent);
......@@ -391,13 +370,6 @@ public abstract class BaseActivity extends NFCActivity {
}.start();
}
protected void startArticlesActivity(final Activity activity, final int foundationId, final String foundationName) {
nemopaySession.setFoundation(foundationId, foundationName);
Log.d(LOG_TAG, String.valueOf(foundationId));
startArticleGroupActivity(activity);
}
protected void startBuyerInfoActivity(final Activity activity, final String badgeId) {
dialog.startLoading(activity, activity.getResources().getString(R.string.information_collection), activity.getResources().getString(R.string.buyer_info_collecting));
final Intent intent = new Intent(activity, BuyerInfoActivity.class);
......@@ -426,7 +398,7 @@ public abstract class BaseActivity extends NFCActivity {
public void run() {
dialog.stopLoading();
if (activity.getClass().getSimpleName().equals("BuyerInfoActivity"))
if (activity instanceof BuyerInfoActivity)
finish();
activity.startActivity(intent);
......@@ -459,7 +431,7 @@ public abstract class BaseActivity extends NFCActivity {
}
protected void startCardManagementActivity(final Activity activity) {
hasRights(getString(R.string.user_rights_list_collecting), new String[]{"STAFF", "POSS3", "GESUSERS"}, new Runnable() {
hasRights(getString(R.string.user_rights_list_collecting), new String[]{"GESUSERS"}, true, new Runnable() {
@Override
public void run() {
activity.startActivity(new Intent(activity, CardManagementActivity.class));
......
......@@ -23,7 +23,7 @@ import java.util.Date;
*/
public class CardManagementActivity extends BaseActivity {
private static final String LOG_TAG = "CardManagementActivity";
private static final String LOG_TAG = "_CardManagementActivity";
TextView textUserId;
TextView textUsername;
......@@ -120,45 +120,50 @@ public class CardManagementActivity extends BaseActivity {
}.start();
}
else if (toRun == 2) {
dialog.dismiss();
final View view = getLayoutInflater().inflate(R.layout.dialog_contribute, null);
final RadioGroup radioGroup = view.findViewById(R.id.radio_type);
final RadioButton radioButton = view.findViewById(R.id.radio_student);
final EditText editText = view.findViewById(R.id.nbr_days);
radioButton.setChecked(true);
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(CardManagementActivity.this);
alertDialogBuilder
.setTitle(R.string.contribute)
.setView(view)
.setCancelable(false)
.setPositiveButton(R.string.contribute, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int id) {
dialog.startLoading(CardManagementActivity.this, getString(R.string.information_collection), getString(R.string.buyer_info_collecting));
new Thread(){
@Override
public void run() {
int id = radioGroup.indexOfChild(radioGroup.findViewById(radioGroup.getCheckedRadioButtonId()));
if (contributeCard(id == 3 ? new SimpleDateFormat("yyyy-MM-dd").format(new Date(new Date().getTime() + (Long.parseLong(String.valueOf(editText.getText())) * 86400000L))) : (Integer.parseInt(new SimpleDateFormat("MM").format(new Date())) > 8 ? Integer.toString(Integer.parseInt(new SimpleDateFormat("yyyy").format(new Date())) + 1) : new SimpleDateFormat("yyyy").format(new Date())) + "-08-31", id < 2 ? 20 : 1))
runOnUiThread(new Runnable() {
hasRights(getString(R.string.contribute), new String[]{"GESUSERS"}, true, new Runnable() {
@Override
public void run() {
dialog.dismiss();
final View view = getLayoutInflater().inflate(R.layout.dialog_contribute, null);
final RadioGroup radioGroup = view.findViewById(R.id.radio_type);
final RadioButton radioButton = view.findViewById(R.id.radio_student);
final EditText editText = view.findViewById(R.id.nbr_days);
radioButton.setChecked(true);
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(CardManagementActivity.this);
alertDialogBuilder
.setTitle(R.string.contribute)
.setView(view)
.setCancelable(false)
.setPositiveButton(R.string.contribute, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int id) {
dialog.startLoading(CardManagementActivity.this, getString(R.string.information_collection), getString(R.string.buyer_info_collecting));
new Thread(){
@Override
public void run() {
Toast.makeText(CardManagementActivity.this, R.string.contribute_now, Toast.LENGTH_LONG).show();
}
});
int id = radioGroup.indexOfChild(radioGroup.findViewById(radioGroup.getCheckedRadioButtonId()));
readCard();
}
}.start();
}
})
.setNegativeButton(R.string.cancel, null);
if (contributeCard(id == 3 ? new SimpleDateFormat("yyyy-MM-dd").format(new Date(new Date().getTime() + (Long.parseLong(String.valueOf(editText.getText())) * 86400000L))) : (Integer.parseInt(new SimpleDateFormat("MM").format(new Date())) > 8 ? Integer.toString(Integer.parseInt(new SimpleDateFormat("yyyy").format(new Date())) + 1) : new SimpleDateFormat("yyyy").format(new Date())) + "-08-31", id < 2 ? 20 : 1))
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(CardManagementActivity.this, R.string.contribute_now, Toast.LENGTH_LONG).show();
}
});
readCard();
}
}.start();
}
})
.setNegativeButton(R.string.cancel, null);
dialog.createDialog(alertDialogBuilder, editText);
dialog.createDialog(alertDialogBuilder, editText);
}
});
}
this.toRun = null;
......@@ -180,8 +185,8 @@ public class CardManagementActivity extends BaseActivity {
this.textTagId.setText(Integer.toString(tagInfo.get("id").intValue()));
this.textTag.setText(tagInfo.get("tag").textValue());
this.textShortTag.setText(tagInfo.get("short_tag").textValue() == null ? getString(R.string.none) : tagInfo.get("short_tag").textValue());
this.textSolde.setText(String.format("%.2f", new Float(this.solde) / 100.00f) + "€");
this.textCotisantGinger.setTextColor(this.solde == 0 ? Color.RED : Color.BLUE);
this.textSolde.setText(this.solde == null ? nemopaySession.forbidden(new String[]{"POSS3"}, false) : String.format("%.2f", new Float(this.solde) / 100.00f) + "€");
this.textSolde.setTextColor(this.solde == null || this.solde == 0 ? Color.RED : Color.BLUE);
this.textUsernameGinger.setText(gingerInfo.get("login").textValue());
this.textFirstnameGinger.setText(gingerInfo.get("prenom").textValue());
......@@ -205,49 +210,6 @@ public class CardManagementActivity extends BaseActivity {
}
protected Boolean contributeCard(final String fin, final Integer paid) {
try {
nemopaySession.getBuyerInfo(badgeId);
Thread.sleep(100);
// Toute une série de vérifications avant de lancer l'activité
final JsonNode buyerInfo = nemopaySession.getRequest().getJSONResponse();
if (!buyerInfo.has("lastname") || !buyerInfo.has("username") || !buyerInfo.has("firstname") || !buyerInfo.has("solde") || !buyerInfo.has("last_purchases") || !buyerInfo.get("last_purchases").isArray())
throw new Exception("Unexpected JSON");